Skip to content

Allow Requests session to be passed to T1 constructor #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions terminalone/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -43,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.
"""
Expand All @@ -66,11 +68,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']:
Expand Down