Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1cbb77c

Browse files
author
Liora Milbaum
committed
feat: Bootstrapping the http_engines concept
1 parent0ecf3bb commit1cbb77c

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

‎gitlab/client.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
importgitlab.config
1515
importgitlab.const
1616
importgitlab.exceptions
17-
fromgitlabimportutils
17+
fromgitlabimporthttp_backends,utils
1818

1919
REDIRECT_MSG= (
2020
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -32,6 +32,13 @@
3232

3333

3434
classGitlab:
35+
36+
# The session object is defined here as long as the RequestsBackend is not
37+
# fully implemented. The long-term goal is to wrap all the http
38+
# requests/responses by the RequestsBackend class
39+
40+
session:requests.Session
41+
3542
"""Represents a GitLab server connection.
3643
3744
Args:
@@ -53,6 +60,10 @@ class Gitlab:
5360
or 52x responses. Defaults to False.
5461
keep_base_url: keep user-provided base URL for pagination if it
5562
differs from response headers
63+
64+
Keyward Args:
65+
requests.Session session: Http Requests Session
66+
RequestsBackend http_backend: Backend that will be used to make http requests
5667
"""
5768

5869
def__init__(
@@ -66,15 +77,14 @@ def __init__(
6677
http_password:Optional[str]=None,
6778
timeout:Optional[float]=None,
6879
api_version:str="4",
69-
session:Optional[requests.Session]=None,
7080
per_page:Optional[int]=None,
7181
pagination:Optional[str]=None,
7282
order_by:Optional[str]=None,
7383
user_agent:str=gitlab.const.USER_AGENT,
7484
retry_transient_errors:bool=False,
7585
keep_base_url:bool=False,
86+
**kwargs:Any,
7687
)->None:
77-
7888
self._api_version=str(api_version)
7989
self._server_version:Optional[str]=None
8090
self._server_revision:Optional[str]=None
@@ -98,7 +108,9 @@ def __init__(
98108
self._set_auth_info()
99109

100110
#: Create a session object for requests
101-
self.session=sessionorrequests.Session()
111+
http_backend=kwargs.pop("http_backend",http_backends.DefaultBackend)
112+
self.http_backend=http_backend(**kwargs)
113+
self.session=self.http_backend.client
102114

103115
self.per_page=per_page
104116
self.pagination=pagination

‎gitlab/http_backends/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Defines http backends for processing http requests
3+
"""
4+
5+
from .requests_backendimportRequestsBackend
6+
7+
DefaultBackend=RequestsBackend
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
importrequests
2+
3+
4+
classRequestsBackend:
5+
6+
_client:requests.Session
7+
8+
def__init__(self,session:requests.Session)->None:
9+
self._client=sessionorrequests.Session()
10+
11+
@property
12+
defclient(self)->requests.Session:
13+
returnself._client

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp