From afb5419b6820c2d4e256ff1ce2f31e4442dcfe2a Mon Sep 17 00:00:00 2001 From: Nicolas Cedilnik Date: Sat, 18 Jun 2022 06:09:36 +0200 Subject: [PATCH 1/3] XEP-0363: Fix upload service auto discovery for components --- slixmpp/plugins/xep_0363/http_upload.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index 4a185fb9..c34be8ff 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -101,12 +101,17 @@ class XEP_0363(BasePlugin): :param domain: Domain to disco to find a service. """ + if domain is None and self.xmpp.is_component: + domain = self.xmpp.server_host + results = await self.xmpp['xep_0030'].get_info_from_domain( domain=domain, **iqkwargs ) candidates = [] for info in results: + if not info['disco_info']: + continue for identity in info['disco_info']['identities']: if identity[0] == 'store' and identity[1] == 'file': candidates.append(info) From ed820bf55104be5cba8d42f94fa5c5ac2a165904 Mon Sep 17 00:00:00 2001 From: nicoco Date: Sat, 16 Jul 2022 17:17:22 +0200 Subject: [PATCH 2/3] Make it clear that filename does *not* have to be path, and is mandatory --- slixmpp/plugins/xep_0363/http_upload.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index c34be8ff..2948c4cc 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -11,7 +11,7 @@ from asyncio import Future from mimetypes import guess_type from typing import ( Optional, - IO, + IO, Union, ) from pathlib import Path @@ -137,7 +137,7 @@ class XEP_0363(BasePlugin): request['content-type'] = content_type or self.default_content_type return iq.send(**iqkwargs) - async def upload_file(self, filename: Path, size: Optional[int] = None, + async def upload_file(self, filename: Union[Path, str], size: Optional[int] = None, content_type: Optional[str] = None, *, input_file: Optional[IO[bytes]]=None, domain: Optional[JID] = None, @@ -146,9 +146,10 @@ class XEP_0363(BasePlugin): process. :param filename: Path to the file to upload (or only the name if - ``input_file`` is provided. + ``input_file`` is provided) :param size: size of the file in bytes. :param content_type: Type of the file that will be uploaded. + If not provided, will be inferred from ``filename`` :param input_file: Binary file stream on the file. :param domain: Domain to query to find an HTTP upload service. :raises .UploadServiceNotFound: If slixmpp is unable to find an From 14786abd348e56a2cfcbeddfe21bf6f6515c0db6 Mon Sep 17 00:00:00 2001 From: nicoco Date: Sat, 16 Jul 2022 20:23:48 +0200 Subject: [PATCH 3/3] Revert "Make it clear that filename does *not* have to be path, and is mandatory" This reverts commit ed820bf55104be5cba8d42f94fa5c5ac2a165904. --- slixmpp/plugins/xep_0363/http_upload.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index 2948c4cc..c34be8ff 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -11,7 +11,7 @@ from asyncio import Future from mimetypes import guess_type from typing import ( Optional, - IO, Union, + IO, ) from pathlib import Path @@ -137,7 +137,7 @@ class XEP_0363(BasePlugin): request['content-type'] = content_type or self.default_content_type return iq.send(**iqkwargs) - async def upload_file(self, filename: Union[Path, str], size: Optional[int] = None, + async def upload_file(self, filename: Path, size: Optional[int] = None, content_type: Optional[str] = None, *, input_file: Optional[IO[bytes]]=None, domain: Optional[JID] = None, @@ -146,10 +146,9 @@ class XEP_0363(BasePlugin): process. :param filename: Path to the file to upload (or only the name if - ``input_file`` is provided) + ``input_file`` is provided. :param size: size of the file in bytes. :param content_type: Type of the file that will be uploaded. - If not provided, will be inferred from ``filename`` :param input_file: Binary file stream on the file. :param domain: Domain to query to find an HTTP upload service. :raises .UploadServiceNotFound: If slixmpp is unable to find an