From 4c8ee2848bd7b7949756ec5d2773073b5db96e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 2 Jul 2019 18:09:36 +0200 Subject: [PATCH] server: Change the way the homeserver url is passed to nio. --- matrix/server.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/matrix/server.py b/matrix/server.py index 7c4a7c3..568fc5c 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -270,6 +270,7 @@ class MatrixServer(object): pass self.address = None + self.homeserver = None self.client = None self.access_token = None # type: Optional[str] self.next_batch = None # type: Optional[str] @@ -349,29 +350,31 @@ class MatrixServer(object): device_file.write(self.device_id) @staticmethod - def _parse_url(address): + def _parse_url(address, port): + if not address.startswith("http"): + address = "https://{}".format(address) + parsed_url = urlparse(address) - if parsed_url.netloc: - netloc, path = (parsed_url.netloc, parsed_url.path) - else: - try: - netloc, path = address.split("/", 1) - except ValueError: - netloc, path = (address, "") + homeserver = parsed_url._replace( + netloc=parsed_url.hostname + ":{}".format(port) + ) - return netloc, path.strip("/") + return homeserver def _change_client(self): - netloc, extra_path = MatrixServer._parse_url(self.config.address) - host = "{}:{}".format(netloc, self.config.port) - self.address = netloc + homeserver = MatrixServer._parse_url( + self.config.address, + self.config.port + ) + self.address = homeserver.hostname + self.homeserver = homeserver + self.client = HttpClient( - host, + homeserver.geturl(), self.config.username, self.device_id, self.get_session_path(), - extra_path=extra_path ) self.client.add_to_device_callback( self.key_verification_cb,