diff options
Diffstat (limited to 'slixmpp/xmlstream')
-rw-r--r-- | slixmpp/xmlstream/stanzabase.py | 14 | ||||
-rw-r--r-- | slixmpp/xmlstream/tostring.py | 15 | ||||
-rw-r--r-- | slixmpp/xmlstream/xmlstream.py | 22 |
3 files changed, 25 insertions, 26 deletions
diff --git a/slixmpp/xmlstream/stanzabase.py b/slixmpp/xmlstream/stanzabase.py index 605dbb61..1c000b69 100644 --- a/slixmpp/xmlstream/stanzabase.py +++ b/slixmpp/xmlstream/stanzabase.py @@ -177,8 +177,9 @@ def fix_ns(xpath, split=False, propagate_ns=True, default_ns=''): if '}' in ns_block: # Apply the found namespace to following elements # that do not have namespaces. - namespace = ns_block.split('}')[0] - elements = ns_block.split('}')[1].split('/') + ns_block_split = ns_block.split('}') + namespace = ns_block_split[0] + elements = ns_block_split[1].split('/') else: # Apply the stanza's namespace to the following # elements since no namespace was provided. @@ -1291,15 +1292,6 @@ class ElementBase(object): def __bool__(self): """Stanza objects should be treated as True in boolean contexts. - - Python 3.x version. - """ - return True - - def __nonzero__(self): - """Stanza objects should be treated as True in boolean contexts. - - Python 2.x version. """ return True diff --git a/slixmpp/xmlstream/tostring.py b/slixmpp/xmlstream/tostring.py index 6726bf1e..d6cc85dd 100644 --- a/slixmpp/xmlstream/tostring.py +++ b/slixmpp/xmlstream/tostring.py @@ -45,11 +45,12 @@ def tostring(xml=None, xmlns='', stream=None, outbuffer='', output = [outbuffer] # Extract the element's tag name. - tag_name = xml.tag.split('}', 1)[-1] + tag_split = xml.tag.split('}', 1) + tag_name = tag_split[-1] # Extract the element's namespace if it is defined. if '}' in xml.tag: - tag_xmlns = xml.tag.split('}', 1)[0][1:] + tag_xmlns = tag_split[0][1:] else: tag_xmlns = '' @@ -82,8 +83,9 @@ def tostring(xml=None, xmlns='', stream=None, outbuffer='', if '}' not in attrib: output.append(' %s="%s"' % (attrib, value)) else: - attrib_ns = attrib.split('}')[0][1:] - attrib = attrib.split('}')[1] + attrib_split = attrib.split('}') + attrib_ns = attrib_split[0][1:] + attrib = attrib_split[1] if attrib_ns == XML_NS: output.append(' xml:%s="%s"' % (attrib, value)) elif stream and attrib_ns in stream.namespace_map: @@ -144,10 +146,7 @@ def escape(text, use_cdata=False): '"': '"'} if not use_cdata: - text = list(text) - for i, c in enumerate(text): - text[i] = escapes.get(c, c) - return ''.join(text) + return ''.join(escapes.get(c, c) for c in text) else: escape_needed = False for c in text: diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index 0367db02..60557fff 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -285,7 +285,10 @@ class XMLStream(asyncio.BaseProtocol): self.disable_starttls = disable_starttls self.event("connecting") - self._current_connection_attempt = asyncio.ensure_future(self._connect_routine()) + self._current_connection_attempt = asyncio.ensure_future( + self._connect_routine(), + loop=self.loop, + ) async def _connect_routine(self): self.event_when_connected = "connected" @@ -306,7 +309,7 @@ class XMLStream(asyncio.BaseProtocol): else: ssl_context = None - await asyncio.sleep(self.connect_loop_wait) + await asyncio.sleep(self.connect_loop_wait, loop=self.loop) try: await self.loop.create_connection(lambda: self, self.address[0], @@ -321,7 +324,10 @@ class XMLStream(asyncio.BaseProtocol): log.debug('Connection failed: %s', e) self.event("connection_failed", e) self.connect_loop_wait = self.connect_loop_wait * 2 + 1 - self._current_connection_attempt = asyncio.ensure_future(self._connect_routine()) + self._current_connection_attempt = asyncio.ensure_future( + self._connect_routine(), + loop=self.loop, + ) def process(self, *, forever=True, timeout=None): """Process all the available XMPP events (receiving or sending data on the @@ -336,10 +342,10 @@ class XMLStream(asyncio.BaseProtocol): else: self.loop.run_until_complete(self.disconnected) else: - tasks = [asyncio.sleep(timeout)] + tasks = [asyncio.sleep(timeout, loop=self.loop)] if not forever: tasks.append(self.disconnected) - self.loop.run_until_complete(asyncio.wait(tasks)) + self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop)) def init_parser(self): """init the XML parser. The parser must always be reset for each new @@ -781,7 +787,10 @@ class XMLStream(asyncio.BaseProtocol): old_exception(e) else: self.exception(e) - asyncio.ensure_future(handler_callback_routine(handler_callback)) + asyncio.ensure_future( + handler_callback_routine(handler_callback), + loop=self.loop, + ) else: try: handler_callback(data) @@ -995,4 +1004,3 @@ class XMLStream(asyncio.BaseProtocol): :param exception: An unhandled exception object. """ pass - |