Runnable with both Python3 and Python2, with both PyQt5 and PyQt4 by using Qt.py #2250

Open
kashikoibumi wants to merge 127 commits from kashikoibumi/py3qt into v0.6
2 changed files with 16 additions and 16 deletions
Showing only changes of commit de0cd04772 - Show all commits

View File

@ -40,11 +40,11 @@ class Socks4a(Proxy):
def state_pre_connect(self):
"""Handle feedback from SOCKS4a while it is connecting on our behalf"""
# Get the response
if self.read_buf[0:1] != six.int2byte(0x00).encode():
if self.read_buf[0:1] != six.int2byte(0x00):
# bad data
self.close()
raise GeneralProxyError(1)
elif self.read_buf[1:2] != six.int2byte(0x5A).encode():
elif self.read_buf[1:2] != six.int2byte(0x5A):
# Connection failed
self.close()
if six.byte2int(self.read_buf[1:2]) in (91, 92, 93):
@ -103,9 +103,9 @@ class Socks4aConnection(Socks4a):
self.append_write_buf(self.ipaddr)
if self._auth:
self.append_write_buf(self._auth[0])
self.append_write_buf(six.int2byte(0x00).encode())
self.append_write_buf(six.int2byte(0x00))
if rmtrslv:
self.append_write_buf(self.destination[0] + six.int2byte(0x00).encode())
self.append_write_buf(self.destination[0].encode("utf-8", "replace") + six.int2byte(0x00))
self.set_state("pre_connect", length=0, expectBytes=8)
return True
@ -133,8 +133,8 @@ class Socks4aResolver(Socks4a):
self.append_write_buf(struct.pack("BBBB", 0x00, 0x00, 0x00, 0x01))
if self._auth:
self.append_write_buf(self._auth[0])
self.append_write_buf(six.int2byte(0x00).encode())
self.append_write_buf(self.host + six.int2byte(0x00).encode())
self.append_write_buf(six.int2byte(0x00))
self.append_write_buf(self.host + six.int2byte(0x00))
self.set_state("pre_connect", length=0, expectBytes=8)
return True

View File

@ -98,10 +98,10 @@ class Socks5(Proxy):
def state_pre_connect(self):
"""Handle feedback from socks5 while it is connecting on our behalf."""
# Get the response
if self.read_buf[0:1] != six.int2byte(0x05).encode():
if self.read_buf[0:1] != six.int2byte(0x05):
self.close()
raise GeneralProxyError(1)
elif self.read_buf[1:2] != six.int2byte(0x00).encode():
elif self.read_buf[1:2] != six.int2byte(0x00):
# Connection failed
self.close()
if six.byte2int(self.read_buf[1:2]) <= 8:
@ -109,9 +109,9 @@ class Socks5(Proxy):
else:
raise Socks5Error(9)
# Get the bound address/port
elif self.read_buf[3:4] == six.int2byte(0x01).encode():
elif self.read_buf[3:4] == six.int2byte(0x01):
self.set_state("proxy_addr_1", length=4, expectBytes=4)
elif self.read_buf[3:4] == six.int2byte(0x03).encode():
elif self.read_buf[3:4] == six.int2byte(0x03):
self.set_state("proxy_addr_2_1", length=4, expectBytes=1)
else:
self.close()
@ -172,19 +172,19 @@ class Socks5Connection(Socks5):
# use the IPv4 address request even if remote resolving was specified.
try:
self.ipaddr = socket.inet_aton(self.destination[0])
self.append_write_buf(six.int2byte(0x01).encode() + self.ipaddr)
self.append_write_buf(six.int2byte(0x01) + self.ipaddr)
except socket.error: # may be IPv6!
# Well it's not an IP number, so it's probably a DNS name.
if self._remote_dns:
# Resolve remotely
self.ipaddr = None
self.append_write_buf(six.int2byte(0x03).encode() + six.int2byte(
len(self.destination[0])).encode() + self.destination[0])
self.append_write_buf(six.int2byte(0x03) + six.int2byte(
len(self.destination[0])) + self.destination[0].encode("utf-8", "replace"))
else:
# Resolve locally
self.ipaddr = socket.inet_aton(
socket.gethostbyname(self.destination[0]))
self.append_write_buf(six.int2byte(0x01).encode() + self.ipaddr)
self.append_write_buf(six.int2byte(0x01) + self.ipaddr)
self.append_write_buf(struct.pack(">H", self.destination[1]))
self.set_state("pre_connect", length=0, expectBytes=4)
return True
@ -209,8 +209,8 @@ class Socks5Resolver(Socks5):
"""Perform resolving"""
# Now we can request the actual connection
self.append_write_buf(struct.pack('BBB', 0x05, 0xF0, 0x00))
self.append_write_buf(six.int2byte(0x03).encode() + six.int2byte(
len(self.host)).encode() + str(self.host))
self.append_write_buf(six.int2byte(0x03) + six.int2byte(
len(self.host)) + bytes(self.host))
self.append_write_buf(struct.pack(">H", self.port))
self.set_state("pre_connect", length=0, expectBytes=4)
return True