20
20
"""
21
21
import json
22
22
import logging
23
- import requests
24
23
import re
25
- from exceptiondef import FailedConnection
24
+ import requests
26
25
from requests .exceptions import RequestException
26
+ from exceptiondef import FailedConnection
27
27
28
28
29
29
class PackageRepoRestClient (object ):
@@ -42,9 +42,9 @@ def put_package(self, package_name, package_data):
42
42
:param package_data: The actual binary data of the package
43
43
"""
44
44
url = self .api_url + "/packages/" + package_name
45
- logging .debug ("PUT: " + url )
45
+ logging .debug ("PUT: %s" , url )
46
46
response = requests .put (url , data = package_data )
47
- logging .debug ("response code: " + str (response .status_code ))
47
+ logging .debug ("response code: %s" , str (response .status_code ))
48
48
assert response .status_code == 200
49
49
50
50
def get_package (self , package_name , expected_codes = None ):
@@ -72,32 +72,32 @@ def get_package_list(self, recency=None):
72
72
return json .loads (response .content )
73
73
74
74
@staticmethod
75
- def parse_error_msg_from_html_response (html_str ):
75
+ def parse_error_msg_from_response (html_str ):
76
76
title_tag = re .search ('<title>(.+?)<.*/title>' , html_str )
77
77
if title_tag :
78
- cause_msg = re .sub ('<[A-Za-z\/][^>]*>' , '' , title_tag .group ())
78
+ cause_msg = re .sub (r '<[A-Za-z\/][^>]*>' , '' , title_tag .group ())
79
79
return cause_msg
80
80
return html_str
81
81
82
82
def make_rest_get_request (self , path , expected_codes = None ):
83
83
if not expected_codes :
84
84
expected_codes = [200 ]
85
85
url = self .api_url + path
86
- logging .debug ("GET: " + url )
86
+ logging .debug ("GET: %s" , url )
87
87
88
88
try :
89
89
response = requests .get (url , timeout = 120 )
90
- except RequestException as e :
91
- logging .debug ("Request error: " + str (e ))
90
+ except RequestException as exc :
91
+ logging .debug ("Request error: %s" , str (exc ))
92
92
error_msg = 'Unable to connect to the Package Repository Manager'
93
93
raise FailedConnection (error_msg )
94
94
95
- logging .debug ("response code: " + str (response .status_code ))
95
+ logging .debug ("response code: %s" , str (response .status_code ))
96
96
97
97
if response .status_code not in expected_codes :
98
- error_msg = PackageRepoRestClient .parse_error_msg_from_html_response (response .text )
98
+ error_msg = PackageRepoRestClient .parse_error_msg_from_response (response .text )
99
99
error_msg = "Package Repository Manager - {} (request path = {})" .format (error_msg , path )
100
- logging .debug ("Server error: " + str (error_msg ))
100
+ logging .debug ("Server error: %s" , str (error_msg ))
101
101
assert response .status_code in expected_codes , error_msg
102
102
103
103
return response
0 commit comments