From a1bd49e721b2cbf05311ee4684cb27ee0b3603cc Mon Sep 17 00:00:00 2001 From: Alexander Pushkov Date: Mon, 13 Jan 2020 17:21:23 +0300 Subject: [PATCH 1/2] Allow Requests session to be passed to T1 constructor --- terminalone/connection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/terminalone/connection.py b/terminalone/connection.py index aecaf3a..a3b1a7f 100644 --- a/terminalone/connection.py +++ b/terminalone/connection.py @@ -29,6 +29,7 @@ def __init__(self, api_base=None, json=False, auth_params=None, + session=None, _create_session=False): """Set up Requests Session to be used for all connections to T1. @@ -66,11 +67,12 @@ def __init__(self, Connection.__setattr__(self, 'json', json) Connection.__setattr__(self, 'auth_params', auth_params) if _create_session: - self._create_session() + self._create_session(session=session) - def _create_session(self): + def _create_session(self, session=None): method = self.auth_params['method'] - session = Session() + if session is None: + session = Session() session.headers['User-Agent'] = self.user_agent if method not in ['oauth2-resourceowner', 'oauth2-existingaccesstoken']: From 9cee6c384eba40f3352e0ab808dab8ba0236ef9d Mon Sep 17 00:00:00 2001 From: Alexander Pushkov Date: Tue, 14 Jan 2020 18:24:21 +0300 Subject: [PATCH 2/2] Document the new session parameter --- terminalone/connection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/terminalone/connection.py b/terminalone/connection.py index a3b1a7f..05ce933 100644 --- a/terminalone/connection.py +++ b/terminalone/connection.py @@ -44,6 +44,7 @@ def __init__(self, "method" required argument. Determines session handler. "oauth2-ro" => "client_id", "client_secret", "username", "password" "cookie" => "username", "password", "api_key" + :param session: requests.Session instance to use for HTTP requests. :param _create_session: bool flag to create a Requests Session. Should only be used for initial T1 instantiation. """