added a timeout api
Closed this issue · 1 comments
cfsego commented
--- /home/cfsego/.local/lib/python3.5/site-packages/socks.py 2017-05-08 21:08:01.781956877 +0800
+++ socks.py 2017-05-08 21:05:47.601957161 +0800
@@ -154,6 +154,14 @@
username.encode() if username else None,
password.encode() if password else None)
+def set_default_timeout(timeout=None):
+ """
+ set_default_timeout(timeout)
+
+ Sets a default timeout which all further socksocket objects will use.
+ """
+ socksocket.default_timeout = timeout
+
def setdefaultproxy(*args, **kwargs):
if 'proxytype' in kwargs:
kwargs['proxy_type'] = kwargs.pop('proxytype')
@@ -276,6 +284,7 @@
"""
default_proxy = None
+ default_timeout = None
def __init__(self, family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0, *args, **kwargs):
if type not in (socket.SOCK_STREAM, socket.SOCK_DGRAM):
@@ -292,7 +301,7 @@
self.proxy_sockname = None
self.proxy_peername = None
- self._timeout = None
+ self._timeout = self.default_timeout
def _readall(self, file, count):
"""
Anorov commented
Could you submit this as a PR, please? Thank you.