Skip to content

Commit c88f317

Browse files
committed
switched direct requests call to use of session instance
Signed-off-by: Guyzmo <guyzmo+github@m0g.net>
1 parent 4bbc50e commit c88f317

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

gogs_client/_implementation/http_utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class RelativeHttpRequestor(object):
1111
A thin wrapper around the requests module that allows for endpoint paths
1212
to be given relative to a fixed base URL
1313
"""
14-
def __init__(self, base_url):
14+
def __init__(self, base_url, session=None):
1515
self.base_url = base_url
16+
self.session = session or requests.Session()
1617

1718
def absolute_url(self, relative_path):
1819
"""
@@ -26,22 +27,22 @@ def absolute_url(self, relative_path):
2627
# except that they expect relative paths
2728

2829
def delete(self, relative_path, **kwargs):
29-
return requests.delete(self.absolute_url(relative_path), **kwargs)
30+
return self.session.delete(self.absolute_url(relative_path), **kwargs)
3031

3132
def get(self, relative_path, params=None, **kwargs):
32-
return requests.get(self.absolute_url(relative_path), params=params, **kwargs)
33+
return self.session.get(self.absolute_url(relative_path), params=params, **kwargs)
3334

3435
def options(self, relative_path, params=None, **kwargs):
35-
return requests.options(self.absolute_url(relative_path), params=params, **kwargs)
36+
return self.session.options(self.absolute_url(relative_path), params=params, **kwargs)
3637

3738
def patch(self, relative_path, data=None, **kwargs):
38-
return requests.patch(self.absolute_url(relative_path), data=data, **kwargs)
39+
return self.session.patch(self.absolute_url(relative_path), data=data, **kwargs)
3940

4041
def post(self, relative_path, data=None, **kwargs):
41-
return requests.post(self.absolute_url(relative_path), data=data, **kwargs)
42+
return self.session.post(self.absolute_url(relative_path), data=data, **kwargs)
4243

4344
def put(self, relative_path, params=None, data=None, **kwargs):
44-
return requests.put(self.absolute_url(relative_path), params=params, data=data, **kwargs)
45+
return self.session.put(self.absolute_url(relative_path), params=params, data=data, **kwargs)
4546

4647

4748
def append_url(base_url, path):

gogs_client/interface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ class GogsApi(object):
99
A Gogs client, serving as a wrapper around the Gogs HTTP API.
1010
"""
1111

12-
def __init__(self, base_url):
12+
def __init__(self, base_url, session=None):
1313
"""
1414
:param str base_url: the URL of the Gogs server to communicate with. Should be given
1515
with the https protocol
16+
:param str session: a requests session instance
1617
"""
1718
api_base = append_url(base_url, "/api/v1/")
18-
self._requestor = RelativeHttpRequestor(api_base)
19+
self._requestor = RelativeHttpRequestor(api_base, session=session)
1920

2021
def valid_authentication(self, auth):
2122
"""

0 commit comments

Comments
 (0)