Yann Leboulanger pushed to branch master at gajim / python-nbxmpp
Commits: bda8f905 by Yann Leboulanger at 2016-11-02T15:16:50+01:00 [NooN8] simplify arithmetic. See #38
- - - - - ece53ebd by Yann Leboulanger at 2016-11-02T21:36:28+01:00 [NooN8] make the really dense code more readable
- - - - -
9 changed files:
- nbxmpp/auth_nb.py - nbxmpp/bosh.py - nbxmpp/c14n.py - nbxmpp/client_nb.py - nbxmpp/dispatcher_nb.py - nbxmpp/proxy_connectors.py - nbxmpp/smacks.py - nbxmpp/tls_nb.py - nbxmpp/transports_nb.py
Changes:
===================================== nbxmpp/auth_nb.py ===================================== --- a/nbxmpp/auth_nb.py +++ b/nbxmpp/auth_nb.py @@ -461,18 +461,18 @@ class SASL(PlugIn): self.realm = chal['realm'] if 'qop' in chal and ((chal['qop'] =='auth') or \ (isinstance(chal['qop'], list) and 'auth' in chal['qop'])): - self.resp = {} - self.resp['username'] = self.username + self.resp = {'username': self.username, + 'nonce': chal['nonce'], + 'cnonce': '%x' % rndg.getrandbits(196), + 'nc': ('00000001'), # ToDo: Is this a tupel or only a string? + 'qop': 'auth', + 'digest-uri': 'xmpp/' + self._owner.Server, + 'charset': 'utf-8' + } if self.realm: self.resp['realm'] = self.realm else: self.resp['realm'] = self._owner.Server - self.resp['nonce'] = chal['nonce'] - self.resp['cnonce'] = '%x' % rndg.getrandbits(196) - self.resp['nc'] = ('00000001') - self.resp['qop'] = 'auth' - self.resp['digest-uri'] = 'xmpp/' + self._owner.Server - self.resp['charset'] = 'utf-8' # Password is now required self._owner._caller.get_password(self.set_password, self.mechanism) elif 'rspauth' in chal:
===================================== nbxmpp/bosh.py ===================================== --- a/nbxmpp/bosh.py +++ b/nbxmpp/bosh.py @@ -101,7 +101,7 @@ class NonBlockingBOSH(NonBlockingTransport): NonBlockingTransport.connect(self, conn_5tuple, on_connect, on_connect_failure)
global FAKE_DESCRIPTOR - FAKE_DESCRIPTOR = FAKE_DESCRIPTOR - 1 + FAKE_DESCRIPTOR -= 1 self.fd = FAKE_DESCRIPTOR
self.stanza_buffer = []
===================================== nbxmpp/c14n.py ===================================== --- a/nbxmpp/c14n.py +++ b/nbxmpp/c14n.py @@ -28,7 +28,7 @@ def c14n(node, is_buggy): s = "<" + node.name if node.namespace: if not node.parent or node.parent.namespace != node.namespace: - s = s + ' xmlns="%s"' % node.namespace + s += ' xmlns="%s"' % node.namespace
sorted_attrs = sorted(node.attrs.keys()) for key in sorted_attrs: @@ -36,15 +36,15 @@ def c14n(node, is_buggy): continue val = ustr(node.attrs[key]) # like XMLescape() but with whitespace and without > - s = s + ' %s="%s"' % ( key, normalise_attr(val) ) - s = s + ">" + s += ' %s="%s"' % (key, normalise_attr(val)) + s += ">" cnt = 0 if node.kids: for a in node.kids: if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt]) s = s + c14n(a, is_buggy) - cnt=cnt+1 + cnt += 1 if (len(node.data)-1) >= cnt: s = s + normalise_text(node.data[cnt]) if not node.kids and s.endswith('>'): s=s[:-1]+' />'
===================================== nbxmpp/client_nb.py ===================================== --- a/nbxmpp/client_nb.py +++ b/nbxmpp/client_nb.py @@ -273,9 +273,9 @@ class NonBlockingClient: """ if err_message: log.debug('While looping over DNS A records: %s' % err_message) - if self.ip_addresses == []: + if not self.ip_addresses: msg = 'Run out of hosts for name %s:%s.' % (self.Server, self.Port) - msg = msg + ' Error for last IP: %s' % err_message + msg += ' Error for last IP: %s' % err_message self.disconnect(msg) else: self.current_ip = self.ip_addresses.pop(0)
===================================== nbxmpp/dispatcher_nb.py ===================================== --- a/nbxmpp/dispatcher_nb.py +++ b/nbxmpp/dispatcher_nb.py @@ -104,7 +104,7 @@ class XMPPDispatcher(PlugIn): # \ufddo -> \ufdef range c = '\ufdd0' r = c - while (c < '\ufdef'): + while c < '\ufdef': c = chr(ord(c) + 1) r += '|' + c
@@ -112,7 +112,7 @@ class XMPPDispatcher(PlugIn): c = '\ufffe' r += '|' + c r += '|' + chr(ord(c) + 1) - while (c < '\U0010fffe'): + while c < '\U0010fffe': c = chr(ord(c) + 0x10000) r += '|' + c r += '|' + chr(ord(c) + 1) @@ -458,7 +458,7 @@ class XMPPDispatcher(PlugIn): stanza.getName() != 'a' and stanza.getName() != 'enabled' and stanza.getName() != 'resumed'): # increments the number of stanzas that has been handled - self.sm.in_h = self.sm.in_h + 1 + self.sm.in_h += 1 list_ = ['default'] # we will use all handlers: if typ in self.handlers[xmlns][name]: list_.append(typ) # from very common... @@ -571,7 +571,7 @@ class XMPPDispatcher(PlugIn): # If no ID then it is a whitespace if self.sm and self.sm.enabled and ID: self.sm.uqueue.append(stanza) - self.sm.out_h = self.sm.out_h + 1 + self.sm.out_h += 1 if len(self.sm.uqueue) > self.sm.max_queue: self.sm.request_ack()
===================================== nbxmpp/proxy_connectors.py ===================================== --- a/nbxmpp/proxy_connectors.py +++ b/nbxmpp/proxy_connectors.py @@ -195,7 +195,8 @@ class SOCKS5Connector(ProxyConnector): # # Resolve locally # self.ipaddr = socket.inet_aton(socket.gethostbyname(self.xmpp_server[0])) # req = req + "\x01" + ipaddr - req = req + struct.pack(">H", self.xmpp_server[1]) + + req += struct.pack(">H", self.xmpp_server[1]) self.onreceive(self._on_req_sent) self.send(req)
===================================== nbxmpp/smacks.py ===================================== --- a/nbxmpp/smacks.py +++ b/nbxmpp/smacks.py @@ -143,7 +143,7 @@ class Smacks(): self.enabled = True self.resuming = True self.con.set_oldst() - if self.old_uqueue != []: + if self.old_uqueue: log.info('Session resumed, replaying %s stanzas...' % len(self.old_uqueue)) for i in self.old_uqueue: self._owner.Connection.send(i, False)
===================================== nbxmpp/tls_nb.py ===================================== --- a/nbxmpp/tls_nb.py +++ b/nbxmpp/tls_nb.py @@ -120,7 +120,8 @@ class SSLWrapper: if self.exc_str: if self.strerror: s += "(%s)" % self.exc_str - else: s += "(%s)" % str(self.exc_args) + else: + s += "(%s)" % str(self.exc_args) return s
def __init__(self, sslobj, sock=None):
===================================== nbxmpp/transports_nb.py ===================================== --- a/nbxmpp/transports_nb.py +++ b/nbxmpp/transports_nb.py @@ -583,7 +583,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject): except UnicodeDecodeError: for i in range(-1, -4, -1): char = sent_data[i] - if char & 0xc0 == 0xc0: + if ord(char) & 0xc0 == 0xc0: self.sent_bytes_buff = sent_data[i:] sent_data = sent_data[:i] break @@ -794,7 +794,7 @@ class NonBlockingHTTP(NonBlockingTCP): headers.append('Connection: Keep-Alive') headers.append('\r\n') headers = '\r\n'.join(headers) - return('%s%s' % (headers, httpbody)) + return '%s%s' % (headers, httpbody)
def parse_http_message(self, message): """
View it on GitLab: http://dev.gajim.org/gajim/python-nbxmpp/compare/1accf16ac790c9a9cbe412f34d6...