1414import gitlab .config
1515import gitlab .const
1616import gitlab .exceptions
17- from gitlab import utils
17+ from gitlab import http_backends , utils
1818
1919REDIRECT_MSG = (
2020 "python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
3232
3333
3434class 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+
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 = 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
102114
103115 self .per_page = per_page
104116 self .pagination = pagination
0 commit comments