changeset 3503b0321a4f in /home/hg/repos/python-nbxmpp
details:http://hg.gajim.org/python-nbxmpp?cmd=changeset;node=3503b0321a4f description: fix connecting via socks5 proxy
diffstat:
nbxmpp/proxy_connectors.py | 36 ++++++++++++++++++------------------ nbxmpp/transports_nb.py | 5 ++++- 2 files changed, 22 insertions(+), 19 deletions(-)
diffs (109 lines):
diff -r 381e96f81981 -r 3503b0321a4f nbxmpp/proxy_connectors.py --- a/nbxmpp/proxy_connectors.py Sun Jul 28 22:35:47 2013 +0200 +++ b/nbxmpp/proxy_connectors.py Tue Jul 30 22:23:36 2013 +0200 @@ -128,9 +128,9 @@ def start_connecting(self): log.info('Proxy server contacted, performing authentification') if self.proxy_user and self.proxy_pass: - to_send = '\x05\x02\x00\x02' + to_send = b'\x05\x02\x00\x02' else: - to_send = '\x05\x01\x00' + to_send = b'\x05\x01\x00' self.onreceive(self._on_greeting_sent) self.send(to_send)
@@ -148,15 +148,15 @@ return self._on_proxy_auth('\x01\x00') elif reply[1] == '\x02': to_send = '\x01' + chr(len(self.proxy_user)) + self.proxy_user +\ - chr(len(self.proxy_pass)) + self.proxy_pass + chr(len(self.proxy_pass)) + self.proxy_pass self.onreceive(self._on_proxy_auth) self.send(to_send) else: if reply[1] == '\xff': log.error('Authentification to proxy impossible: no acceptable ' - 'auth method') + 'auth method') self.on_failure('Authentification to proxy impossible: no ' - 'acceptable authentification method') + 'acceptable authentification method') return log.error('Invalid proxy reply') self.on_failure('Invalid proxy reply') @@ -179,18 +179,18 @@ return log.info('Authentification successfull. Jabber server contacted.') # Request connection - req = "\x05\x01\x00" + req = b'\x05\x01\x00' # If the given destination address is an IP address, we'll # use the IPv4 address request even if remote resolving was specified. try: self.ipaddr = socket.inet_aton(self.xmpp_server[0]) - req = req + "\x01" + self.ipaddr + req = req + b'\x01' + self.ipaddr except socket.error: # Well it's not an IP number, so it's probably a DNS name. # if self.__proxy[3]==True: # Resolve remotely self.ipaddr = None - req = req + "\x03" + chr(len(self.xmpp_server[0])) + self.xmpp_server[0] + req = req + b'\x03' + (chr(len(self.xmpp_server[0])) + self.xmpp_server[0]).encode('utf-8') # else: # # Resolve locally # self.ipaddr = socket.inet_aton(socket.gethostbyname(self.xmpp_server[0])) @@ -210,17 +210,17 @@ log.error('Invalid proxy reply') self.on_failure('Invalid proxy reply') return - if reply[1] != "\x00": + if reply[1] != '\x00': # Connection failed if ord(reply[1])<9: errors = ['general SOCKS server failure', - 'connection not allowed by ruleset', - 'Network unreachable', - 'Host unreachable', - 'Connection refused', - 'TTL expired', - 'Command not supported', - 'Address type not supported' + 'connection not allowed by ruleset', + 'Network unreachable', + 'Host unreachable', + 'Connection refused', + 'TTL expired', + 'Command not supported', + 'Address type not supported' ] txt = errors[ord(reply[1])-1] else: @@ -229,9 +229,9 @@ self.on_failure(txt) return # Get the bound address/port - elif reply[3] == "\x01": + elif reply[3] == '\x01': begin, end = 3, 7 - elif reply[3] == "\x03": + elif reply[3] == '\x03': begin, end = 4, 4 + reply[4] else: log.error('Invalid proxy reply') diff -r 381e96f81981 -r 3503b0321a4f nbxmpp/transports_nb.py --- a/nbxmpp/transports_nb.py Sun Jul 28 22:35:47 2013 +0200 +++ b/nbxmpp/transports_nb.py Tue Jul 30 22:23:36 2013 +0200 @@ -497,7 +497,10 @@ """ NonBlockingTransport.send(self, raw_data, now)
- r = self.encode_stanza(raw_data) + if isinstance(raw_data, str): + r = self.encode_stanza(raw_data) + else: + r = raw_data
if now: self.sendqueue.insert(0, r)