Commit eeb6291d authored by André's avatar André

Remove more python2 code

parent 07355321
Pipeline #2738 passed with stages
in 26 seconds
......@@ -33,10 +33,7 @@ import sys
import locale
import logging
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from urllib.parse import urlparse
from .plugin import PlugIn
from .idlequeue import IdleObject
......@@ -81,15 +78,6 @@ def get_proxy_data_from_dict(proxy):
proxy_user, proxy_pass = proxy['user'], proxy['pass']
return tcp_host, tcp_port, proxy_user, proxy_pass
def decode_py2(string, encoding):
# decodes string into unicode if in py2
# py3 has unicode strings by default
try:
string = string.decode(encoding)
except AttributeError:
pass
return string
#: timeout to connect to the server socket, it doesn't include auth
CONNECT_TIMEOUT_SECONDS = 30
......@@ -384,8 +372,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
self._sock.setblocking(False)
self._sock.connect((self.server, self.port))
except Exception as exc:
errnum, errstr = exc.errno, \
decode_py2(exc.strerror, locale.getpreferredencoding())
errnum, errstr = exc.errno, exc.strerror
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):
# connecting in progress
......@@ -488,8 +475,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
self._sock.shutdown(socket.SHUT_RDWR)
self._sock.close()
except socket.error as e:
errstr = decode_py2(e.strerror, locale.getpreferredencoding())
log.info('Error while disconnecting socket: %s' % errstr)
log.info('Error while disconnecting socket: %s' % e.strerror)
self.fd = -1
NonBlockingTransport.disconnect(self, do_callback)
......@@ -581,19 +567,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
if self.sent_bytes_buff:
sent_data = self.sent_bytes_buff + sent_data
self.sent_bytes_buff = b''
# try to decode sent data
try:
sent_data = decode_py2(sent_data, 'utf-8')
except UnicodeDecodeError:
for i in range(-1, -4, -1):
char = sent_data[i]
if ord(char) & 0xc0 == 0xc0:
self.sent_bytes_buff = sent_data[i:]
sent_data = sent_data[:i]
break
sent_data = decode_py2(sent_data, 'utf-8')
self.raise_event(DATA_SENT, sent_data)
except Exception:
log.error('_do_send:', exc_info=True)
traceback.print_exc()
......@@ -614,8 +588,7 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
except tls_nb.SSLWrapper.Error as e:
log.info("_do_receive, caught SSL error, got %s:" % received,
exc_info=True)
errnum, errstr = e.errno,\
decode_py2(e.strerror, locale.getpreferredencoding())
errnum, errstr = e.errno, e.strerror
except socket.error as e:
log.info("_do_receive: got %s:" % received, exc_info=True)
......@@ -651,20 +624,6 @@ class NonBlockingTCP(NonBlockingTransport, IdleObject):
received = self.received_bytes_buff + received
self.received_bytes_buff = b''
if self.state != PROXY_CONNECTING or self.proxy_dict['type'] != \
'socks5':
# try to decode data
try:
received = decode_py2(received, 'utf-8')
except UnicodeDecodeError:
for i in range(-1, -4, -1):
char = received[i]
if char & 0xc0 == 0xc0:
self.received_bytes_buff = received[i:]
received = received[:i]
break
received = decode_py2(received, 'utf-8')
# pass received data to owner
if self.on_receive:
self.raise_event(DATA_RECEIVED, received)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment