14
14
import gitlab .config
15
15
import gitlab .const
16
16
import gitlab .exceptions
17
- from gitlab import utils
17
+ from gitlab import http_backends , utils
18
18
19
19
REDIRECT_MSG = (
20
20
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
32
32
33
33
34
34
class Gitlab :
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
+
35
42
"""Represents a GitLab server connection.
36
43
37
44
Args:
@@ -53,6 +60,10 @@ class Gitlab:
53
60
or 52x responses. Defaults to False.
54
61
keep_base_url: keep user-provided base URL for pagination if it
55
62
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
56
67
"""
57
68
58
69
def __init__ (
@@ -66,15 +77,14 @@ def __init__(
66
77
http_password : Optional [str ] = None ,
67
78
timeout : Optional [float ] = None ,
68
79
api_version : str = "4" ,
69
- session : Optional [requests .Session ] = None ,
70
80
per_page : Optional [int ] = None ,
71
81
pagination : Optional [str ] = None ,
72
82
order_by : Optional [str ] = None ,
73
83
user_agent : str = gitlab .const .USER_AGENT ,
74
84
retry_transient_errors : bool = False ,
75
85
keep_base_url : bool = False ,
86
+ ** kwargs : Any ,
76
87
) -> None :
77
-
78
88
self ._api_version = str (api_version )
79
89
self ._server_version : Optional [str ] = None
80
90
self ._server_revision : Optional [str ] = None
@@ -98,7 +108,9 @@ def __init__(
98
108
self ._set_auth_info ()
99
109
100
110
#: Create a session object for requests
101
- self .session = session or requests .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
102
114
103
115
self .per_page = per_page
104
116
self .pagination = pagination
0 commit comments