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

[tor-commits] [sbws/master] requests: refactor, set session attributes



commit 106e8a97d0dbfa0ebfaeabc476e5f3a85833ca3e
Author: juga0 <juga@xxxxxxxxxx>
Date:   Wed Dec 12 15:01:03 2018 +0000

    requests: refactor, set session attributes
    
    to their values instead of have to extra functions to call
    in every request.
    This also makes the code more clear.
---
 sbws/core/scanner.py    |  4 ++--
 sbws/lib/destination.py |  2 +-
 sbws/util/requests.py   | 12 ++----------
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 80251ec..51e7076 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -37,8 +37,8 @@ def timed_recv_from_server(session, dest, byte_range):
     # - What other exceptions can this throw?
     # - Do we have to read the content, or did requests already do so?
     try:
-        requests_utils.get(
-            session, dest.url, headers=headers, verify=dest.verify)
+        # headers are merged with the session ones, not overwritten.
+        session.get(dest.url, headers=headers, verify=dest.verify)
     except requests.exceptions.ConnectionError as e:
         return False, e
     except requests.exceptions.ReadTimeout as e:
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index 1b4c192..a9233c3 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -73,7 +73,7 @@ def connect_to_destination_over_circuit(dest, circ_id, session, cont, max_dl):
         try:
             # TODO:
             # - What other exceptions can this throw?
-            head = requests_utils.head(session, dest.url, verify=dest.verify)
+            head = session.head(dest.url, verify=dest.verify)
         except (requests.exceptions.ConnectionError,
                 requests.exceptions.ReadTimeout) as e:
             return False, 'Could not connect to {} over circ {} {}: {}'.format(
diff --git a/sbws/util/requests.py b/sbws/util/requests.py
index 449ced7..103182a 100644
--- a/sbws/util/requests.py
+++ b/sbws/util/requests.py
@@ -5,17 +5,9 @@ import sbws.util.stem as stem_utils
 def make_session(controller, timeout):
     s = requests.Session()
     socks_info = stem_utils.get_socks_info(controller)
-    s.sbws_proxies = {
+    s.proxies = {
         'http': 'socks5h://{}:{}'.format(*socks_info),
         'https': 'socks5h://{}:{}'.format(*socks_info),
     }
-    s.sbws_timeout = timeout
+    s.timeout = timeout
     return s
-
-
-def get(s, url, **kw):
-    return s.get(url, timeout=s.sbws_timeout, proxies=s.sbws_proxies, **kw)
-
-
-def head(s, url, **kw):
-    return s.head(url, timeout=s.sbws_timeout, proxies=s.sbws_proxies, **kw)



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