Add use_session argument to request method.
authorShrikant Sharat <shrikantsharat.k@gmail.com>
Fri, 25 Nov 2011 03:02:07 +0000 (08:32 +0530)
committerShrikant Sharat <shrikantsharat.k@gmail.com>
Fri, 25 Nov 2011 03:02:07 +0000 (08:32 +0530)
This allows usage of an existing session to make a request with the
request and the get, post etc. function.

requests/api.py

index 9e0c96f..21c7c7a 100644 (file)
@@ -27,6 +27,7 @@ def request(method, url,
     hooks=None,
     return_response=True,
     prefetch=False,
+    use_session=None,
     config=None):
     """Constructs and sends a :class:`Request <Request>`.
     Returns :class:`Response <Response>` object.
@@ -43,10 +44,11 @@ def request(method, url,
     :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
     :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
     :param return_response: (optional) If False, an un-sent Request object will returned.
+    :param use_session: (optional) A :class:`Session` object to be used for the request.
     :param config: (optional) A configuration dictionary.
     """
 
-    s = session()
+    s = use_session or session()
     return s.request(
         method=method,
         url=url,