@@ -653,7 +653,7 @@ def http_request(
653
653
retry_transient_errors : Optional [bool ] = None ,
654
654
max_retries : int = 10 ,
655
655
** kwargs : Any ,
656
- ) -> requests . Response :
656
+ ) -> _backends . DefaultResponse :
657
657
"""Make an HTTP request to the Gitlab server.
658
658
659
659
Args:
@@ -724,7 +724,7 @@ def http_request(
724
724
cur_retries = 0
725
725
while True :
726
726
try :
727
- result = self ._backend .http_request (
727
+ backend_response = self ._backend .http_request (
728
728
method = verb ,
729
729
url = url ,
730
730
json = json ,
@@ -746,20 +746,26 @@ def http_request(
746
746
747
747
raise
748
748
749
- self ._check_redirects (result .response )
749
+ self ._check_redirects (backend_response .response )
750
750
751
- if 200 <= result .status_code < 300 :
752
- return result . response
751
+ if 200 <= backend_response .status_code < 300 :
752
+ return backend_response
753
753
754
754
def should_retry () -> bool :
755
- if result .status_code == 429 and obey_rate_limit :
755
+ if backend_response .status_code == 429 and obey_rate_limit :
756
756
return True
757
757
758
758
if not retry_transient_errors :
759
759
return False
760
- if result .status_code in gitlab .const .RETRYABLE_TRANSIENT_ERROR_CODES :
760
+ if (
761
+ backend_response .status_code
762
+ in gitlab .const .RETRYABLE_TRANSIENT_ERROR_CODES
763
+ ):
761
764
return True
762
- if result .status_code == 409 and "Resource lock" in result .reason :
765
+ if (
766
+ backend_response .status_code == 409
767
+ and "Resource lock" in backend_response .reason
768
+ ):
763
769
return True
764
770
765
771
return False
@@ -769,34 +775,37 @@ def should_retry() -> bool:
769
775
# https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
770
776
if max_retries == - 1 or cur_retries < max_retries :
771
777
wait_time = 2 ** cur_retries * 0.1
772
- if "Retry-After" in result .headers :
773
- wait_time = int (result .headers ["Retry-After" ])
774
- elif "RateLimit-Reset" in result .headers :
775
- wait_time = int (result .headers ["RateLimit-Reset" ]) - time .time ()
778
+ if "Retry-After" in backend_response .headers :
779
+ wait_time = int (backend_response .headers ["Retry-After" ])
780
+ elif "RateLimit-Reset" in backend_response .headers :
781
+ wait_time = (
782
+ int (backend_response .headers ["RateLimit-Reset" ])
783
+ - time .time ()
784
+ )
776
785
cur_retries += 1
777
786
time .sleep (wait_time )
778
787
continue
779
788
780
- error_message = result .content
789
+ error_message = backend_response .content
781
790
try :
782
- error_json = result .json ()
791
+ error_json = backend_response .json ()
783
792
for k in ("message" , "error" ):
784
793
if k in error_json :
785
794
error_message = error_json [k ]
786
795
except (KeyError , ValueError , TypeError ):
787
796
pass
788
797
789
- if result .status_code == 401 :
798
+ if backend_response .status_code == 401 :
790
799
raise gitlab .exceptions .GitlabAuthenticationError (
791
- response_code = result .status_code ,
800
+ response_code = backend_response .status_code ,
792
801
error_message = error_message ,
793
- response_body = result .content ,
802
+ response_body = backend_response .content ,
794
803
)
795
804
796
805
raise gitlab .exceptions .GitlabHttpError (
797
- response_code = result .status_code ,
806
+ response_code = backend_response .status_code ,
798
807
error_message = error_message ,
799
- response_body = result .content ,
808
+ response_body = backend_response .content ,
800
809
)
801
810
802
811
def http_get (
@@ -827,9 +836,10 @@ def http_get(
827
836
GitlabParsingError: If the json data could not be parsed
828
837
"""
829
838
query_data = query_data or {}
830
- result = self .http_request (
839
+ backend_response = self .http_request (
831
840
"get" , path , query_data = query_data , streamed = streamed , ** kwargs
832
841
)
842
+ result = backend_response .response
833
843
834
844
if (
835
845
result .headers ["Content-Type" ] == "application/json"
@@ -866,8 +876,10 @@ def http_head(
866
876
"""
867
877
868
878
query_data = query_data or {}
869
- result = self .http_request ("head" , path , query_data = query_data , ** kwargs )
870
- return result .headers
879
+ backend_response = self .http_request (
880
+ "head" , path , query_data = query_data , ** kwargs
881
+ )
882
+ return backend_response .headers
871
883
872
884
def http_list (
873
885
self ,
@@ -1023,7 +1035,7 @@ def http_post(
1023
1035
query_data = query_data or {}
1024
1036
post_data = post_data or {}
1025
1037
1026
- result = self .http_request (
1038
+ backend_response = self .http_request (
1027
1039
"post" ,
1028
1040
path ,
1029
1041
query_data = query_data ,
@@ -1032,6 +1044,8 @@ def http_post(
1032
1044
raw = raw ,
1033
1045
** kwargs ,
1034
1046
)
1047
+ result = backend_response .response
1048
+
1035
1049
try :
1036
1050
if result .headers .get ("Content-Type" , None ) == "application/json" :
1037
1051
json_result = result .json ()
@@ -1075,7 +1089,7 @@ def http_put(
1075
1089
query_data = query_data or {}
1076
1090
post_data = post_data or {}
1077
1091
1078
- result = self .http_request (
1092
+ backend_response = self .http_request (
1079
1093
"put" ,
1080
1094
path ,
1081
1095
query_data = query_data ,
@@ -1085,7 +1099,7 @@ def http_put(
1085
1099
** kwargs ,
1086
1100
)
1087
1101
try :
1088
- json_result = result .json ()
1102
+ json_result = backend_response .json ()
1089
1103
if TYPE_CHECKING :
1090
1104
assert isinstance (json_result , dict )
1091
1105
return json_result
@@ -1124,7 +1138,7 @@ def http_patch(
1124
1138
query_data = query_data or {}
1125
1139
post_data = post_data or {}
1126
1140
1127
- result = self .http_request (
1141
+ backend_response = self .http_request (
1128
1142
"patch" ,
1129
1143
path ,
1130
1144
query_data = query_data ,
@@ -1133,7 +1147,7 @@ def http_patch(
1133
1147
** kwargs ,
1134
1148
)
1135
1149
try :
1136
- json_result = result .json ()
1150
+ json_result = backend_response .json ()
1137
1151
if TYPE_CHECKING :
1138
1152
assert isinstance (json_result , dict )
1139
1153
return json_result
@@ -1156,7 +1170,8 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
1156
1170
Raises:
1157
1171
GitlabHttpError: When the return code is not 2xx
1158
1172
"""
1159
- return self .http_request ("delete" , path , ** kwargs )
1173
+ backend_response = self .http_request ("delete" , path , ** kwargs )
1174
+ return backend_response .response
1160
1175
1161
1176
@gitlab .exceptions .on_http_error (gitlab .exceptions .GitlabSearchError )
1162
1177
def search (
@@ -1210,7 +1225,11 @@ def _query(
1210
1225
self , url : str , query_data : Optional [Dict [str , Any ]] = None , ** kwargs : Any
1211
1226
) -> None :
1212
1227
query_data = query_data or {}
1213
- result = self ._gl .http_request ("get" , url , query_data = query_data , ** kwargs )
1228
+ backend_response = self ._gl .http_request (
1229
+ "get" , url , query_data = query_data , ** kwargs
1230
+ )
1231
+ result = backend_response .response
1232
+
1214
1233
try :
1215
1234
next_url = result .links ["next" ]["url" ]
1216
1235
except KeyError :
0 commit comments