Skip to content

Commit

Permalink
py3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
tiedu committed Jun 24, 2020
1 parent 0d38a1d commit 133ba7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions qcloud_cos/cos_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import hashlib
import logging
from requests.auth import AuthBase
from .cos_comm import to_unicode, to_bytes
from .cos_comm import to_unicode, to_bytes, to_str
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -45,8 +45,8 @@ def __call__(self, r):
uri_params = self._params
headers = filter_headers(r.headers)
# reserved keywords in headers urlencode are -_.~, notice that / should be encoded and space should not be encoded to plus sign(+)
headers = dict([(quote(to_bytes(str(k)), '-_.~').lower(), quote(to_bytes(str(v)), '-_.~')) for k, v in headers.items()]) # headers中的key转换为小写,value进行encode
uri_params = dict([(quote(to_bytes(str(k)), '-_.~').lower(), quote(to_bytes(str(v)), '-_.~')) for k, v in uri_params.items()])
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
uri_params = dict([(quote(to_bytes(to_str(k)), '-_.~').lower(), quote(to_bytes(to_str(v)), '-_.~')) for k, v in uri_params.items()])
format_str = u"{method}\n{host}\n{params}\n{headers}\n".format(
method=r.method.lower(),
host=path,
Expand Down
7 changes: 7 additions & 0 deletions qcloud_cos/cos_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
}


def to_str(s):
"""非字符串转换为字符串"""
if isinstance(s, text_type) or isinstance(s, binary_type):
return s
return str(s)


def to_unicode(s):
"""将字符串转为unicode"""
if isinstance(s, binary_type):
Expand Down

0 comments on commit 133ba7e

Please sign in to comment.