diff options
Diffstat (limited to 'slixmpp')
-rw-r--r-- | slixmpp/xmlstream/matcher/xpath.py | 15 | ||||
-rw-r--r-- | slixmpp/xmlstream/xmlstream.py | 47 |
2 files changed, 20 insertions, 42 deletions
diff --git a/slixmpp/xmlstream/matcher/xpath.py b/slixmpp/xmlstream/matcher/xpath.py index 31ab1b8c..0edef5a9 100644 --- a/slixmpp/xmlstream/matcher/xpath.py +++ b/slixmpp/xmlstream/matcher/xpath.py @@ -19,15 +19,6 @@ class MatchXPath(MatcherBase): The XPath matcher selects stanzas whose XML contents matches a given XPath expression. - .. warning:: - - Using this matcher may not produce expected behavior when using - attribute selectors. For Python 2.6 and 3.1, the ElementTree - :meth:`~xml.etree.ElementTree.Element.find()` method does - not support the use of attribute selectors. If you need to - support Python 2.6 or 3.1, it might be more useful to use a - :class:`~slixmpp.xmlstream.matcher.stanzapath.StanzaPath` matcher. - If the value of :data:`IGNORE_NS` is set to ``True``, then XPath expressions will be matched without using namespaces. """ @@ -42,12 +33,6 @@ class MatchXPath(MatcherBase): If the value of :data:`IGNORE_NS` is set to ``True``, then XPath expressions will be matched without using namespaces. - .. warning:: - - In Python 2.6 and 3.1 the ElementTree - :meth:`~xml.etree.ElementTree.Element.find()` method does not - support attribute selectors in the XPath expression. - :param xml: The :class:`~slixmpp.xmlstream.stanzabase.ElementBase` stanza to compare against. """ 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 |