Skip to content

Commit 589965a

Browse files
committed
pep8 format code
1 parent 7d731ba commit 589965a

33 files changed

+1664
-1433
lines changed

qingcloud/app/connection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from . import constants as const
44
from __builtin__ import str
55

6+
67
class AppConnection(APIConnection):
78

89
def __init__(self, app_id, secret_app_key, zone,
@@ -26,7 +27,7 @@ def __init__(self, app_id, secret_app_key, zone,
2627
secret_app_key,
2728
access_token)
2829

29-
def send_request(self, action, body, url='/app/', verb ='GET'):
30+
def send_request(self, action, body, url='/app/', verb='GET'):
3031
""" Send request
3132
"""
3233
return super(AppConnection, self).send_request(action, body, url, verb)
@@ -71,5 +72,3 @@ def unlease_app(self, resources):
7172
body = {"resources": resources}
7273

7374
return self.send_request(action, body)
74-
75-

qingcloud/conn/auth.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from qingcloud.misc.utils import get_utf8_value, get_ts, base64_url_decode,\
3434
base64_url_encode
3535

36+
3637
class HmacKeys(object):
3738
""" Key based Auth handler helper.
3839
"""
@@ -77,6 +78,7 @@ def sign_string(self, string_to_sign):
7778
to_sign = self.digest(string_to_sign)
7879
return base64.b64encode(to_sign).strip()
7980

81+
8082
class QuerySignatureAuthHandler(HmacKeys):
8183
""" Provides Query Signature Authentication.
8284
"""
@@ -99,7 +101,7 @@ def _calc_signature(self, params, verb, path):
99101
urllib.quote(val, safe='-_~'))
100102
qs = '&'.join(pairs)
101103
string_to_sign += qs
102-
#print "string to sign:[%s]" % string_to_sign
104+
# print "string to sign:[%s]" % string_to_sign
103105
b64 = self.sign_string(string_to_sign)
104106
return (qs, b64)
105107

@@ -113,14 +115,14 @@ def add_auth(self, req, **kwargs):
113115
req.params['time_stamp'] = time_stamp
114116
qs, signature = self._calc_signature(req.params, req.method,
115117
req.auth_path)
116-
#print 'query_string: %s Signature: %s' % (qs, signature)
118+
# print 'query_string: %s Signature: %s' % (qs, signature)
117119
if req.method == 'POST':
118120
# req and retried req should not have signature
119121
params = req.params.copy()
120122
params["signature"] = signature
121123
req.body = urllib.urlencode(params)
122124
req.header = {
123-
'Content-Length' : str(len(req.body)),
125+
'Content-Length': str(len(req.body)),
124126
'Content-Type': 'application/x-www-form-urlencoded',
125127
'Accept': 'text/plain',
126128
'Connection': 'Keep-Alive'
@@ -131,11 +133,13 @@ def add_auth(self, req, **kwargs):
131133
# already be there, we need to get rid of that and rebuild it
132134
req.path = req.path.split('?')[0]
133135
req.path = (req.path + '?' + qs +
134-
'&signature=' + urllib.quote_plus(signature))
136+
'&signature=' + urllib.quote_plus(signature))
137+
135138

136139
class AppSignatureAuthHandler(QuerySignatureAuthHandler):
137140
""" Provides App Signature Authentication.
138141
"""
142+
139143
def __init__(self, app_id, secret_app_key, access_token=None):
140144

141145
HmacKeys.__init__(self, "", app_id, secret_app_key)
@@ -181,14 +185,14 @@ def add_auth(self, req, **kwargs):
181185
req.params['time_stamp'] = time_stamp
182186
qs, signature = self._calc_signature(req.params, req.method,
183187
req.auth_path)
184-
#print 'query_string: %s Signature: %s' % (qs, signature)
188+
# print 'query_string: %s Signature: %s' % (qs, signature)
185189
if req.method == 'POST':
186190
# req and retried req should not have signature
187191
params = req.params.copy()
188192
params["signature"] = signature
189193
req.body = urllib.urlencode(params)
190194
req.header = {
191-
'Content-Length' : str(len(req.body)),
195+
'Content-Length': str(len(req.body)),
192196
'Content-Type': 'application/x-www-form-urlencoded',
193197
'Accept': 'text/plain',
194198
'Connection': 'Keep-Alive'
@@ -199,7 +203,8 @@ def add_auth(self, req, **kwargs):
199203
# already be there, we need to get rid of that and rebuild it
200204
req.path = req.path.split('?')[0]
201205
req.path = (req.path + '?' + qs +
202-
'&signature=' + signature)
206+
'&signature=' + signature)
207+
203208

204209
class QSSignatureAuthHandler(HmacKeys):
205210

@@ -231,7 +236,8 @@ def _generate_signature(self, method, auth_path, params, headers):
231236
string_to_sign += "\n%s" % date_str
232237

233238
# Generate signed headers
234-
signed_headers = filter(lambda x: x.lower().startswith("x-qs-"), headers.keys())
239+
signed_headers = filter(
240+
lambda x: x.lower().startswith("x-qs-"), headers.keys())
235241
for param in sorted(signed_headers):
236242
string_to_sign += "\n%s:%s" % (param.lower(), headers[param])
237243

@@ -275,7 +281,7 @@ def get_auth_parameters(self, method, auth_path, expires, params=None, headers=N
275281
]
276282

277283
signature = self._generate_signature(method, auth_path,
278-
params+auth_params,
284+
params + auth_params,
279285
headers or {})
280286

281287
auth_params.append(("X-QS-Signature", signature))

qingcloud/conn/connection.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ConnectionQueue(object):
2626
""" Http connection queue
2727
"""
2828

29-
def __init__(self, timeout = 60):
29+
def __init__(self, timeout=60):
3030
self.queue = []
3131
self.timeout = timeout
3232

@@ -68,7 +68,7 @@ class ConnectionPool(object):
6868

6969
CLEAR_INTERVAL = 5.0
7070

71-
def __init__(self, timeout = 60):
71+
def __init__(self, timeout=60):
7272
self.timeout = timeout
7373
self.last_clear_time = time.time()
7474
self.lock = threading.Lock()
@@ -113,7 +113,7 @@ def _clear(self):
113113
class HTTPRequest(object):
114114

115115
def __init__(self, method, protocol, header, host, port, path,
116-
params, auth_path=None, body = ""):
116+
params, auth_path=None, body=""):
117117
"""
118118
Represents an HTTP request.
119119
@@ -179,8 +179,8 @@ class HttpConnection(object):
179179
"""
180180

181181
def __init__(self, qy_access_key_id, qy_secret_access_key, host=None,
182-
port=443, protocol="https", pool=None, expires=None,
183-
http_socket_timeout=10, debug=False):
182+
port=443, protocol="https", pool=None, expires=None,
183+
http_socket_timeout=10, debug=False):
184184
"""
185185
@param qy_access_key_id - the access key id
186186
@param qy_secret_access_key - the secret access key
@@ -237,16 +237,19 @@ def _new_conn(self, host, port):
237237
""" Create new connection
238238
"""
239239
if self.secure:
240-
conn = httplib.HTTPSConnection(host, port, timeout=self.http_socket_timeout)
240+
conn = httplib.HTTPSConnection(
241+
host, port, timeout=self.http_socket_timeout)
241242
else:
242-
conn = httplib.HTTPConnection(host, port, timeout=self.http_socket_timeout)
243+
conn = httplib.HTTPConnection(
244+
host, port, timeout=self.http_socket_timeout)
243245
# Use self-defined Response class
244246
conn.response_class = HTTPResponse
245247
return conn
246248

247249
def build_http_request(self, method, path, params, auth_path, headers,
248-
host, data):
249-
raise NotImplementedError("The build_http_request method must be implemented")
250+
host, data):
251+
raise NotImplementedError(
252+
"The build_http_request method must be implemented")
250253

251254
def send(self, method, path, params=None, headers=None, host=None,
252255
auth_path=None, data=""):
@@ -262,7 +265,7 @@ def send(self, method, path, params=None, headers=None, host=None,
262265

263266
# Build the http request
264267
request = self.build_http_request(method, path, params, auth_path,
265-
headers, host, data)
268+
headers, host, data)
266269
request.authorize(self)
267270

268271
conn_host = host

0 commit comments

Comments
 (0)