mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-02 17:33:37 +00:00
Update PySocks 1.6.8 (524ceb4) → 1.6.8 (b687a34).
This commit is contained in:
parent
f97459d6ce
commit
f989cbad6e
2 changed files with 52 additions and 18 deletions
|
@ -5,7 +5,8 @@
|
||||||
* Update Certifi 2018.01.18 (e225253) to 2018.08.24 (8be9f89)
|
* Update Certifi 2018.01.18 (e225253) to 2018.08.24 (8be9f89)
|
||||||
* Update dateutil module 2.7.2 (ff03c0f) to 2.7.2 (49690ee)
|
* Update dateutil module 2.7.2 (ff03c0f) to 2.7.2 (49690ee)
|
||||||
* Update feedparser 5.2.1 (5646f4c) to 5.2.1 (2b11c80)
|
* Update feedparser 5.2.1 (5646f4c) to 5.2.1 (2b11c80)
|
||||||
* Update profilehooks module 1.10.0 (0ce1e29) to 1.10.1 (fdbf19d)
|
* Update profilehooks module 1.10.0 (0ce1e29) to 1.10.1 (fdbf19d)
|
||||||
|
* Update PySocks 1.6.8 (524ceb4) to 1.6.8 (b687a34)
|
||||||
|
|
||||||
|
|
||||||
[develop changelog]
|
[develop changelog]
|
||||||
|
|
|
@ -55,7 +55,10 @@ Modifications made by Anorov (https://github.com/Anorov)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from collections import Callable
|
try:
|
||||||
|
from collections.abc import Callable
|
||||||
|
except ImportError:
|
||||||
|
from collections import Callable
|
||||||
from errno import EOPNOTSUPP, EINVAL, EAGAIN
|
from errno import EOPNOTSUPP, EINVAL, EAGAIN
|
||||||
import functools
|
import functools
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
@ -114,7 +117,7 @@ class ProxyError(IOError):
|
||||||
self.socket_err = socket_err
|
self.socket_err = socket_err
|
||||||
|
|
||||||
if socket_err:
|
if socket_err:
|
||||||
self.msg += ": {0}".format(socket_err)
|
self.msg += ": {}".format(socket_err)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.msg
|
return self.msg
|
||||||
|
@ -533,6 +536,14 @@ class socksocket(_BaseSocket):
|
||||||
if chosen_auth[1:2] == b"\x02":
|
if chosen_auth[1:2] == b"\x02":
|
||||||
# Okay, we need to perform a basic username/password
|
# Okay, we need to perform a basic username/password
|
||||||
# authentication.
|
# authentication.
|
||||||
|
if not (username and password):
|
||||||
|
# Although we said we don't support authentication, the
|
||||||
|
# server may still request basic username/password
|
||||||
|
# authentication
|
||||||
|
raise SOCKS5AuthError("No username/password supplied. "
|
||||||
|
"Server requested username/password"
|
||||||
|
" authentication")
|
||||||
|
|
||||||
writer.write(b"\x01" + chr(len(username)).encode()
|
writer.write(b"\x01" + chr(len(username)).encode()
|
||||||
+ username
|
+ username
|
||||||
+ chr(len(password)).encode()
|
+ chr(len(password)).encode()
|
||||||
|
@ -575,7 +586,7 @@ class socksocket(_BaseSocket):
|
||||||
if status != 0x00:
|
if status != 0x00:
|
||||||
# Connection failed: server returned an error
|
# Connection failed: server returned an error
|
||||||
error = SOCKS5_ERRORS.get(status, "Unknown error")
|
error = SOCKS5_ERRORS.get(status, "Unknown error")
|
||||||
raise SOCKS5Error("{0:#04x}: {1}".format(status, error))
|
raise SOCKS5Error("{:#04x}: {}".format(status, error))
|
||||||
|
|
||||||
# Get the bound address/port
|
# Get the bound address/port
|
||||||
bnd = self._read_SOCKS5_address(reader)
|
bnd = self._read_SOCKS5_address(reader)
|
||||||
|
@ -693,7 +704,7 @@ class socksocket(_BaseSocket):
|
||||||
if status != 0x5A:
|
if status != 0x5A:
|
||||||
# Connection failed: server returned an error
|
# Connection failed: server returned an error
|
||||||
error = SOCKS4_ERRORS.get(status, "Unknown error")
|
error = SOCKS4_ERRORS.get(status, "Unknown error")
|
||||||
raise SOCKS4Error("{0:#04x}: {1}".format(status, error))
|
raise SOCKS4Error("{:#04x}: {}".format(status, error))
|
||||||
|
|
||||||
# Get the bound address/port
|
# Get the bound address/port
|
||||||
self.proxy_sockname = (socket.inet_ntoa(resp[4:]),
|
self.proxy_sockname = (socket.inet_ntoa(resp[4:]),
|
||||||
|
@ -753,7 +764,7 @@ class socksocket(_BaseSocket):
|
||||||
"HTTP proxy server did not return a valid HTTP status")
|
"HTTP proxy server did not return a valid HTTP status")
|
||||||
|
|
||||||
if status_code != 200:
|
if status_code != 200:
|
||||||
error = "{0}: {1}".format(status_code, status_msg)
|
error = "{}: {}".format(status_code, status_msg)
|
||||||
if status_code in (400, 403, 405):
|
if status_code in (400, 403, 405):
|
||||||
# It's likely that the HTTP proxy server does not support the
|
# It's likely that the HTTP proxy server does not support the
|
||||||
# CONNECT tunneling method
|
# CONNECT tunneling method
|
||||||
|
@ -772,7 +783,7 @@ class socksocket(_BaseSocket):
|
||||||
}
|
}
|
||||||
|
|
||||||
@set_self_blocking
|
@set_self_blocking
|
||||||
def connect(self, dest_pair):
|
def connect(self, dest_pair, catch_errors=None):
|
||||||
"""
|
"""
|
||||||
Connects to the specified destination through a proxy.
|
Connects to the specified destination through a proxy.
|
||||||
Uses the same API as socket's connect().
|
Uses the same API as socket's connect().
|
||||||
|
@ -834,14 +845,17 @@ class socksocket(_BaseSocket):
|
||||||
except socket.error as error:
|
except socket.error as error:
|
||||||
# Error while connecting to proxy
|
# Error while connecting to proxy
|
||||||
self.close()
|
self.close()
|
||||||
proxy_addr, proxy_port = proxy_addr
|
if not catch_errors:
|
||||||
proxy_server = "{0}:{1}".format(proxy_addr, proxy_port)
|
proxy_addr, proxy_port = proxy_addr
|
||||||
printable_type = PRINTABLE_PROXY_TYPES[proxy_type]
|
proxy_server = "{}:{}".format(proxy_addr, proxy_port)
|
||||||
|
printable_type = PRINTABLE_PROXY_TYPES[proxy_type]
|
||||||
|
|
||||||
msg = "Error connecting to {0} proxy {1}".format(printable_type,
|
msg = "Error connecting to {} proxy {}".format(printable_type,
|
||||||
proxy_server)
|
proxy_server)
|
||||||
log.debug("%s due to: %s", msg, error)
|
log.debug("%s due to: %s", msg, error)
|
||||||
raise ProxyConnectionError(msg, error)
|
raise ProxyConnectionError(msg, error)
|
||||||
|
else:
|
||||||
|
raise error
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Connected to proxy server, now negotiate
|
# Connected to proxy server, now negotiate
|
||||||
|
@ -850,13 +864,32 @@ class socksocket(_BaseSocket):
|
||||||
negotiate = self._proxy_negotiators[proxy_type]
|
negotiate = self._proxy_negotiators[proxy_type]
|
||||||
negotiate(self, dest_addr, dest_port)
|
negotiate(self, dest_addr, dest_port)
|
||||||
except socket.error as error:
|
except socket.error as error:
|
||||||
# Wrap socket errors
|
if not catch_errors:
|
||||||
self.close()
|
# Wrap socket errors
|
||||||
raise GeneralProxyError("Socket error", error)
|
self.close()
|
||||||
|
raise GeneralProxyError("Socket error", error)
|
||||||
|
else:
|
||||||
|
raise error
|
||||||
except ProxyError:
|
except ProxyError:
|
||||||
# Protocol error while negotiating with proxy
|
# Protocol error while negotiating with proxy
|
||||||
self.close()
|
self.close()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@set_self_blocking
|
||||||
|
def connect_ex(self, dest_pair):
|
||||||
|
""" https://docs.python.org/3/library/socket.html#socket.socket.connect_ex
|
||||||
|
Like connect(address), but return an error indicator instead of raising an exception for errors returned by the C-level connect() call (other problems, such as "host not found" can still raise exceptions).
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.connect(dest_pair, catch_errors=True)
|
||||||
|
return 0
|
||||||
|
except OSError as e:
|
||||||
|
# If the error is numeric (socket errors are numeric), then return number as
|
||||||
|
# connect_ex expects. Otherwise raise the error again (socket timeout for example)
|
||||||
|
if e.errno:
|
||||||
|
return e.errno
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def _proxy_addr(self):
|
def _proxy_addr(self):
|
||||||
"""
|
"""
|
||||||
|
@ -867,4 +900,4 @@ class socksocket(_BaseSocket):
|
||||||
proxy_port = proxy_port or DEFAULT_PORTS.get(proxy_type)
|
proxy_port = proxy_port or DEFAULT_PORTS.get(proxy_type)
|
||||||
if not proxy_port:
|
if not proxy_port:
|
||||||
raise GeneralProxyError("Invalid proxy type")
|
raise GeneralProxyError("Invalid proxy type")
|
||||||
return proxy_addr, proxy_port
|
return proxy_addr, proxy_port
|
Loading…
Reference in a new issue