summaryrefslogtreecommitdiff
path: root/slixmpp/xmlstream/xmlstream.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-02-04 19:24:29 +0100
committermathieui <mathieui@mathieui.net>2021-02-04 19:24:29 +0100
commitd3fb993b29ebc6662498c23d0227a6eb038bcda5 (patch)
tree87c04a35497ffc7773e7111c499b3afe7068538b /slixmpp/xmlstream/xmlstream.py
parentc486c0e8219da4cdea6988b2948ffc93cb381bec (diff)
parentccbba89cbd9354a78c12e271d28ea22d8f3058e7 (diff)
downloadslixmpp-d3fb993b29ebc6662498c23d0227a6eb038bcda5.tar.gz
slixmpp-d3fb993b29ebc6662498c23d0227a6eb038bcda5.tar.bz2
slixmpp-d3fb993b29ebc6662498c23d0227a6eb038bcda5.tar.xz
slixmpp-d3fb993b29ebc6662498c23d0227a6eb038bcda5.zip
Merge branch 'remove-unused-obsolete-things' into 'master'
Remove unused and obsolete things, and make other things private See merge request poezio/slixmpp!117
Diffstat (limited to 'slixmpp/xmlstream/xmlstream.py')
-rw-r--r--slixmpp/xmlstream/xmlstream.py47
1 files changed, 20 insertions, 27 deletions
diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py
index b80c55d3..e6af3faa 100644
--- a/slixmpp/xmlstream/xmlstream.py
+++ b/slixmpp/xmlstream/xmlstream.py
@@ -16,10 +16,12 @@ from typing import (
Any,
Callable,
Iterable,
+ Iterator,
List,
Optional,
Set,
Union,
+ Tuple,
)
import functools
@@ -88,7 +90,9 @@ class XMLStream(asyncio.BaseProtocol):
# The socket that is used internally by the transport object
self.socket = None
- self.connect_loop_wait = 0
+ # The backoff of the connect routine (increases exponentially
+ # after each failure)
+ self._connect_loop_wait = 0
self.parser = None
self.xml_depth = 0
@@ -157,10 +161,6 @@ class XMLStream(asyncio.BaseProtocol):
#: non-SSL traffic and another for SSL traffic.
self.use_ssl = False
- #: If set to ``True``, attempt to connect through an HTTP
- #: proxy based on the settings in :attr:`proxy_config`.
- self.use_proxy = False
-
#: If set to ``True``, attempt to use IPv6.
self.use_ipv6 = True
@@ -173,13 +173,6 @@ class XMLStream(asyncio.BaseProtocol):
#: to ``False``.
self.use_cdata = False
- #: An optional dictionary of proxy settings. It may provide:
- #: :host: The host offering proxy services.
- #: :port: The port for the proxy service.
- #: :username: Optional username for accessing the proxy.
- #: :password: Optional password for accessing the proxy.
- self.proxy_config = {}
-
#: The default namespace of the stream content, not of the
#: stream wrapper itself.
self.default_ns = ''
@@ -221,7 +214,7 @@ class XMLStream(asyncio.BaseProtocol):
self._current_connection_attempt = None
#: A list of DNS results that have not yet been tried.
- self.dns_answers = None
+ self._dns_answers: Optional[Iterator[Tuple[str, str, int]]] = None
#: The service name to check with DNS SRV records. For
#: example, setting this to ``'xmpp-client'`` would query the
@@ -295,7 +288,7 @@ class XMLStream(asyncio.BaseProtocol):
self.disconnect_reason = None
self.cancel_connection_attempt()
- self.connect_loop_wait = 0
+ self._connect_loop_wait = 0
if host and port:
self.address = (host, int(port))
try:
@@ -320,11 +313,11 @@ class XMLStream(asyncio.BaseProtocol):
async def _connect_routine(self):
self.event_when_connected = "connected"
- if self.connect_loop_wait > 0:
- self.event('reconnect_delay', self.connect_loop_wait)
- await asyncio.sleep(self.connect_loop_wait, loop=self.loop)
+ if self._connect_loop_wait > 0:
+ self.event('reconnect_delay', self._connect_loop_wait)
+ await asyncio.sleep(self._connect_loop_wait, loop=self.loop)
- record = await self.pick_dns_answer(self.default_domain)
+ record = await self._pick_dns_answer(self.default_domain)
if record is not None:
host, address, dns_port = record
port = dns_port if dns_port else self.address[1]
@@ -333,7 +326,7 @@ class XMLStream(asyncio.BaseProtocol):
else:
# No DNS records left, stop iterating
# and try (host, port) as a last resort
- self.dns_answers = None
+ self._dns_answers = None
if self.use_ssl:
ssl_context = self.get_ssl_context()
@@ -348,7 +341,7 @@ class XMLStream(asyncio.BaseProtocol):
self.address[1],
ssl=ssl_context,
server_hostname=self.default_domain if self.use_ssl else None)
- self.connect_loop_wait = 0
+ self._connect_loop_wait = 0
except Socket.gaierror as e:
self.event('connection_failed',
'No DNS record available for %s' % self.default_domain)
@@ -357,7 +350,7 @@ class XMLStream(asyncio.BaseProtocol):
self.event("connection_failed", e)
if self._current_connection_attempt is None:
return
- self.connect_loop_wait = self.connect_loop_wait * 2 + 1
+ self._connect_loop_wait = self._connect_loop_wait * 2 + 1
self._current_connection_attempt = asyncio.ensure_future(
self._connect_routine(),
loop=self.loop,
@@ -401,7 +394,7 @@ class XMLStream(asyncio.BaseProtocol):
self._current_connection_attempt = None
self.init_parser()
self.send_raw(self.stream_header)
- self.dns_answers = None
+ self._dns_answers = None
def data_received(self, data):
"""Called when incoming data is received on the socket.
@@ -786,7 +779,7 @@ class XMLStream(asyncio.BaseProtocol):
idx += 1
return False
- async def get_dns_records(self, domain, port=None):
+ async def get_dns_records(self, domain: str, port: Optional[int] = None) -> List[Tuple[str, str, int]]:
"""Get the DNS records for a domain.
:param domain: The domain in question.
@@ -806,7 +799,7 @@ class XMLStream(asyncio.BaseProtocol):
loop=self.loop)
return result
- async def pick_dns_answer(self, domain, port=None):
+ async def _pick_dns_answer(self, domain: str, port: Optional[int] = None) -> Optional[Tuple[str, str, int]]:
"""Pick a server and port from DNS answers.
Gets DNS answers if none available.
@@ -815,12 +808,12 @@ class XMLStream(asyncio.BaseProtocol):
:param domain: The domain in question.
:param port: If the results don't include a port, use this one.
"""
- if self.dns_answers is None:
+ if self._dns_answers is None:
dns_records = await self.get_dns_records(domain, port)
- self.dns_answers = iter(dns_records)
+ self._dns_answers = iter(dns_records)
try:
- return next(self.dns_answers)
+ return next(self._dns_answers)
except StopIteration:
return