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

Commitee13635

Browse files
chore: require keyword-only arguments for client.http_request()
Require keyword-only arguments for client.http_request()Also change the name of the variable 'verb' to 'method' to match thecall to requests.request()
1 parenta349793 commitee13635

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

‎gitlab/client.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def _build_url(self, path: str) -> str:
549549

550550
def_check_redirects(self,result:requests.Response)->None:
551551
# Check the requests history to detect 301/302 redirections.
552-
# If the initialverb is POST or PUT, the redirected request will use a
552+
# If the initialmethod is POST or PUT, the redirected request will use a
553553
# GET request, leading to unwanted behaviour.
554554
# If we detect a redirection with a POST or a PUT request, we
555555
# raise an exception with a useful error message.
@@ -606,7 +606,8 @@ def _prepare_send_data(
606606

607607
defhttp_request(
608608
self,
609-
verb:str,
609+
*,
610+
method:str,
610611
path:str,
611612
query_data:Optional[Dict[str,Any]]=None,
612613
post_data:Optional[Union[Dict[str,Any],bytes]]=None,
@@ -621,7 +622,7 @@ def http_request(
621622
"""Make an HTTP request to the Gitlab server.
622623
623624
Args:
624-
verb: The HTTP method to call ('get', 'post', 'put', 'delete')
625+
method: The HTTP method to call ('get', 'post', 'put', 'delete')
625626
path: Path or full URL to query ('/projects' or
626627
'http://whatever/v4/api/projecs')
627628
query_data: Data to send as query parameters
@@ -678,7 +679,7 @@ def http_request(
678679
cur_retries=0
679680
whileTrue:
680681
result=self.session.request(
681-
method=verb,
682+
method=method,
682683
url=url,
683684
json=json,
684685
data=data,
@@ -759,7 +760,7 @@ def http_get(
759760
"""
760761
query_data=query_dataor {}
761762
result=self.http_request(
762-
"get",path,query_data=query_data,streamed=streamed,**kwargs
763+
method="get",path=path,query_data=query_data,streamed=streamed,**kwargs
763764
)
764765

765766
if (
@@ -856,8 +857,8 @@ def http_post(
856857
post_data=post_dataor {}
857858

858859
result=self.http_request(
859-
"post",
860-
path,
860+
method="post",
861+
path=path,
861862
query_data=query_data,
862863
post_data=post_data,
863864
files=files,
@@ -904,8 +905,8 @@ def http_put(
904905
post_data=post_dataor {}
905906

906907
result=self.http_request(
907-
"put",
908-
path,
908+
method="put",
909+
path=path,
909910
query_data=query_data,
910911
post_data=post_data,
911912
files=files,
@@ -933,7 +934,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
933934
Raises:
934935
GitlabHttpError: When the return code is not 2xx
935936
"""
936-
returnself.http_request("delete",path,**kwargs)
937+
returnself.http_request(method="delete",path=path,**kwargs)
937938

938939
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError)
939940
defsearch(
@@ -987,7 +988,9 @@ def _query(
987988
self,url:str,query_data:Optional[Dict[str,Any]]=None,**kwargs:Any
988989
)->None:
989990
query_data=query_dataor {}
990-
result=self._gl.http_request("get",url,query_data=query_data,**kwargs)
991+
result=self._gl.http_request(
992+
method="get",path=url,query_data=query_data,**kwargs
993+
)
991994
try:
992995
links=result.links
993996
iflinks:

‎tests/unit/test_gitlab_http_methods.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def resp_cont(url, request):
2222
returnresponse(200,content,headers,None,5,request)
2323

2424
withHTTMock(resp_cont):
25-
http_r=gl.http_request("get","/projects")
25+
http_r=gl.http_request(method="get",path="/projects")
2626
http_r.json()
2727
asserthttp_r.status_code==200
2828

@@ -35,7 +35,7 @@ def resp_cont(url, request):
3535

3636
withHTTMock(resp_cont):
3737
withpytest.raises(GitlabHttpError):
38-
gl.http_request("get","/not_there")
38+
gl.http_request(method="get",path="/not_there")
3939

4040

4141
@pytest.mark.parametrize("status_code", [500,502,503,504])
@@ -50,7 +50,7 @@ def resp_cont(url, request):
5050

5151
withHTTMock(resp_cont):
5252
withpytest.raises(GitlabHttpError):
53-
gl.http_request("get","/projects")
53+
gl.http_request(method="get",path="/projects")
5454

5555
assertcall_count==1
5656

@@ -74,7 +74,9 @@ def resp_cont(url, request):
7474
)
7575

7676
withHTTMock(resp_cont):
77-
http_r=gl.http_request("get","/projects",retry_transient_errors=True)
77+
http_r=gl.http_request(
78+
method="get",path="/projects",retry_transient_errors=True
79+
)
7880

7981
asserthttp_r.status_code==200
8082
assertcall_count==calls_before_success
@@ -99,7 +101,7 @@ def resp_cont(url, request):
99101
)
100102

101103
withHTTMock(resp_cont):
102-
http_r=gl_retry.http_request("get","/projects")
104+
http_r=gl_retry.http_request(method="get",path="/projects")
103105

104106
asserthttp_r.status_code==200
105107
assertcall_count==calls_before_success
@@ -118,7 +120,9 @@ def resp_cont(url, request):
118120

119121
withHTTMock(resp_cont):
120122
withpytest.raises(GitlabHttpError):
121-
gl_retry.http_request("get","/projects",retry_transient_errors=False)
123+
gl_retry.http_request(
124+
method="get",path="/projects",retry_transient_errors=False
125+
)
122126

123127
assertcall_count==1
124128

@@ -181,7 +185,7 @@ def resp_cont(
181185
returnresp_obj
182186

183187
withHTTMock(resp_cont):
184-
gl.http_request(verb=method,path=api_path)
188+
gl.http_request(method=method,path=api_path)
185189

186190

187191
deftest_http_request_302_put_raises_redirect_error(gl):
@@ -203,7 +207,7 @@ def resp_cont(
203207

204208
withHTTMock(resp_cont):
205209
withpytest.raises(RedirectError)asexc:
206-
gl.http_request(verb=method,path=api_path)
210+
gl.http_request(method=method,path=api_path)
207211
error_message=exc.value.error_message
208212
assert"Moved Temporarily"inerror_message
209213
assert"http://localhost/api/v4/user/status"inerror_message

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp