Skip to content

Commit 133ba7e

Browse files
author
tiedu
committed
py3 compatible
1 parent 0d38a1d commit 133ba7e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

qcloud_cos/cos_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import hashlib
77
import logging
88
from requests.auth import AuthBase
9-
from .cos_comm import to_unicode, to_bytes
9+
from .cos_comm import to_unicode, to_bytes, to_str
1010
logger = logging.getLogger(__name__)
1111

1212

@@ -45,8 +45,8 @@ def __call__(self, r):
4545
uri_params = self._params
4646
headers = filter_headers(r.headers)
4747
# reserved keywords in headers urlencode are -_.~, notice that / should be encoded and space should not be encoded to plus sign(+)
48-
headers = dict([(quote(to_bytes(str(k)), '-_.~').lower(), quote(to_bytes(str(v)), '-_.~')) for k, v in headers.items()]) # headers中的key转换为小写,value进行encode
49-
uri_params = dict([(quote(to_bytes(str(k)), '-_.~').lower(), quote(to_bytes(str(v)), '-_.~')) for k, v in uri_params.items()])
48+
headers = dict([(quote(to_bytes(to_str(k)), '-_.~').lower(), quote(to_bytes(to_str(v)), '-_.~')) for k, v in headers.items()]) # headers中的key转换为小写,value进行encode
49+
uri_params = dict([(quote(to_bytes(to_str(k)), '-_.~').lower(), quote(to_bytes(to_str(v)), '-_.~')) for k, v in uri_params.items()])
5050
format_str = u"{method}\n{host}\n{params}\n{headers}\n".format(
5151
method=r.method.lower(),
5252
host=path,

qcloud_cos/cos_comm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161
}
6262

6363

64+
def to_str(s):
65+
"""非字符串转换为字符串"""
66+
if isinstance(s, text_type) or isinstance(s, binary_type):
67+
return s
68+
return str(s)
69+
70+
6471
def to_unicode(s):
6572
"""将字符串转为unicode"""
6673
if isinstance(s, binary_type):

0 commit comments

Comments
 (0)