|
4 | 4 | try: |
5 | 5 | import urllib3 |
6 | 6 | except ImportError: |
7 | | - print 'urlib3 is not installed, run "pip install urlib3"' |
| 7 | + print('urllib3 is not installed, run "pip install urllib3"') |
8 | 8 | sys.exit(1) |
9 | 9 |
|
10 | 10 | import string |
|
16 | 16 | import traceback |
17 | 17 | import base64 |
18 | 18 | import hmac |
19 | | -import sha |
20 | 19 | from hashlib import sha1 |
21 | 20 | import datetime |
22 | 21 | import time |
23 | 22 |
|
| 23 | +try: |
| 24 | + int_types = (int, long) |
| 25 | +except NameError: |
| 26 | + int_types = (int,) |
| 27 | + |
24 | 28 | CONFIG_HOSTNAME = 'hostname' |
25 | 29 | CONFIG_PORT = 'port' |
26 | 30 | CONFIG_POLLING_TIMEOUT = 'default_polling_timeout' |
@@ -55,7 +59,7 @@ def wrap(*args, **kwargs): |
55 | 59 | try: |
56 | 60 | func(*args, **kwargs) |
57 | 61 | except: |
58 | | - print traceback.format_exc() |
| 62 | + print(traceback.format_exc()) |
59 | 63 |
|
60 | 64 | return wrap |
61 | 65 |
|
@@ -189,7 +193,7 @@ def _check_params(self): |
189 | 193 | if value is not None and isinstance(value, str) and annotation.empty_string is False and len(value) == 0: |
190 | 194 | raise SdkError('invalid parameter[%s], it cannot be an empty string' % param_name) |
191 | 195 |
|
192 | | - if value is not None and (isinstance(value, int) or isinstance(value, long)) \ |
| 196 | + if value is not None and isinstance(value, int_types) \ |
193 | 197 | and annotation.number_range is not None and len(annotation.number_range) == 2: |
194 | 198 | low = annotation.number_range[0] |
195 | 199 | high = annotation.number_range[1] |
@@ -253,10 +257,14 @@ def calculateAccessKey(self, url, date): |
253 | 257 | path = elements[2].split("/", 2) |
254 | 258 | path = path[2].split("?") |
255 | 259 |
|
256 | | - h = hmac.new(self.accessKeySecret, self.HTTP_METHOD + "\n" |
257 | | - + date + "\n" |
258 | | - + "/" + path[0], sha1) |
259 | | - Signature = base64.b64encode(h.digest()) |
| 260 | + msg = self.HTTP_METHOD + "\n" + date + "\n" + "/" + path[0] |
| 261 | + if isinstance(msg, str): |
| 262 | + msg = msg.encode('utf-8') |
| 263 | + secret = self.accessKeySecret |
| 264 | + if isinstance(secret, str): |
| 265 | + secret = secret.encode('utf-8') |
| 266 | + h = hmac.new(secret, msg, sha1) |
| 267 | + Signature = base64.b64encode(h.digest()).decode('utf-8') |
260 | 268 | return "ZStack %s:%s" % (self.accessKeyId, Signature) |
261 | 269 |
|
262 | 270 | def call(self, cb=None): |
@@ -482,13 +490,13 @@ def _json_http( |
482 | 490 | if body is not None and not isinstance(body, str): |
483 | 491 | body = json.dumps(body).encode('utf-8') |
484 | 492 |
|
485 | | - print '[Request]: %s url=%s, headers=%s, body=%s' % (method, uri, headers, body) |
| 493 | + print('[Request]: %s url=%s, headers=%s, body=%s' % (method, uri, headers, body)) |
486 | 494 | if body: |
487 | 495 | headers['Content-Length'] = len(body) |
488 | 496 | rsp = pool.request(method, uri, body=body, headers=headers) |
489 | 497 | else: |
490 | 498 | rsp = pool.request(method, uri, headers=headers) |
491 | 499 |
|
492 | | - print '[Response to %s %s]: status: %s, body: %s' % (method, uri, rsp.status, rsp.data) |
| 500 | + print('[Response to %s %s]: status: %s, body: %s' % (method, uri, rsp.status, rsp.data)) |
493 | 501 | return rsp |
494 | 502 |
|
0 commit comments