[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] requests: Change make_session to use the TimedSession



commit 1cc8351c5d2df4f1d52c7ab2fdb1dd0eb814deae
Author: juga0 <juga@xxxxxxxxxx>
Date:   Thu Feb 21 13:55:32 2019 +0000

    requests: Change make_session to use the TimedSession
    
    that will always have timeout in the get and head methods.
---
 sbws/util/requests.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sbws/util/requests.py b/sbws/util/requests.py
index e0a6864..615916d 100644
--- a/sbws/util/requests.py
+++ b/sbws/util/requests.py
@@ -18,12 +18,17 @@ class TimedSession(requests.Session):
 
 
 def make_session(controller, timeout):
-    s = requests.Session()
+    """
+    Initialize a TimedSession with the timeout, the proxies and the headers.
+
+    """
+    s = TimedSession()
     socks_info = stem_utils.get_socks_info(controller)
     s.proxies = {
         'http': 'socks5h://{}:{}'.format(*socks_info),
         'https': 'socks5h://{}:{}'.format(*socks_info),
     }
-    s.timeout = timeout
+    # ``_timeout`` is not used by request's Session, but it is by TimedSession.
+    s._timeout = timeout
     s.headers = settings.HTTP_HEADERS
     return s



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits