diff options
author | Cat Lee Ball 🎷🐛 <cball@google.com> | 2019-03-26 17:21:03 -0700 |
---|---|---|
committer | Cat Lee Ball 🎷🐛 <cball@google.com> | 2019-03-26 17:21:03 -0700 |
commit | 0955620ab49b76c60abbcc1bea61ad05c2098361 (patch) | |
tree | 03504e75038acd58f022acb8af4d16826190c817 | |
parent | acd6a95ad953a4f1ac72adfc354a6c5aec74fbb0 (diff) | |
download | boto-0955620ab49b76c60abbcc1bea61ad05c2098361.tar.gz |
Replaced get_utf8_value with six.ensure_str
We replaced the old method get_utf8_value with six.ensure_str now
that it's available. ensure_str behaves more relibaly and accurately
in testing than the get_utf8_value function.
-rw-r--r-- | boto/auth.py | 14 | ||||
-rw-r--r-- | boto/connection.py | 2 | ||||
-rw-r--r-- | boto/gs/bucket.py | 4 | ||||
-rwxr-xr-x | boto/gs/connection.py | 4 | ||||
-rw-r--r-- | boto/gs/key.py | 4 | ||||
-rw-r--r-- | boto/s3/bucket.py | 2 | ||||
-rw-r--r-- | boto/s3/connection.py | 6 | ||||
-rw-r--r-- | boto/utils.py | 14 |
8 files changed, 17 insertions, 33 deletions
diff --git a/boto/auth.py b/boto/auth.py index d062349f..21faa6bb 100644 --- a/boto/auth.py +++ b/boto/auth.py @@ -383,7 +383,7 @@ class HmacAuthV4Handler(AuthHandler, HmacKeys): parameter_names = sorted(http_request.params.keys()) pairs = [] for pname in parameter_names: - pval = boto.utils.get_utf8_value(http_request.params[pname]) + pval = six.ensure_str(http_request.params[pname]) pairs.append(urllib.parse.quote(pname, safe=''.encode('ascii')) + '=' + urllib.parse.quote(pval, safe='-_~'.encode('ascii'))) @@ -396,7 +396,7 @@ class HmacAuthV4Handler(AuthHandler, HmacKeys): return "" l = [] for param in sorted(http_request.params): - value = boto.utils.get_utf8_value(http_request.params[param]) + value = six.ensure_str(http_request.params[param]) l.append('%s=%s' % (urllib.parse.quote(param, safe='-_.~'), urllib.parse.quote(value, safe='-_.~'))) return '&'.join(l) @@ -623,7 +623,7 @@ class S3HmacAuthV4Handler(HmacAuthV4Handler, AuthHandler): # query string. l = [] for param in sorted(http_request.params): - value = boto.utils.get_utf8_value(http_request.params[param]) + value = six.ensure_str(http_request.params[param]) l.append('%s=%s' % (urllib.parse.quote(param, safe='-_.~'), urllib.parse.quote(value, safe='-_.~'))) return '&'.join(l) @@ -836,7 +836,7 @@ class STSAnonHandler(AuthHandler): keys.sort(key=lambda x: x.lower()) pairs = [] for key in keys: - val = boto.utils.get_utf8_value(params[key]) + val = six.ensure_str(params[key]) pairs.append(key + '=' + self._escape_value(six.ensure_str(val))) return '&'.join(pairs) @@ -897,7 +897,7 @@ class QuerySignatureV0AuthHandler(QuerySignatureHelper, AuthHandler): keys.sort(cmp=lambda x, y: cmp(x.lower(), y.lower())) pairs = [] for key in keys: - val = boto.utils.get_utf8_value(params[key]) + val = six.ensure_str(params[key]) pairs.append(key + '=' + urllib.parse.quote(val)) qs = '&'.join(pairs) return (qs, base64.b64encode(hmac.digest())) @@ -924,7 +924,7 @@ class QuerySignatureV1AuthHandler(QuerySignatureHelper, AuthHandler): pairs = [] for key in keys: hmac.update(key.encode('utf-8')) - val = boto.utils.get_utf8_value(params[key]) + val = six.ensure_str(params[key]) hmac.update(val) pairs.append(key + '=' + urllib.parse.quote(val)) qs = '&'.join(pairs) @@ -948,7 +948,7 @@ class QuerySignatureV2AuthHandler(QuerySignatureHelper, AuthHandler): keys = sorted(params.keys()) pairs = [] for key in keys: - val = boto.utils.get_utf8_value(params[key]) + val = six.ensure_str(params[key]) pairs.append(urllib.parse.quote(key, safe='') + '=' + urllib.parse.quote(val, safe='-_~')) qs = '&'.join(pairs) diff --git a/boto/connection.py b/boto/connection.py index 85d12d3f..3f0c53e8 100644 --- a/boto/connection.py +++ b/boto/connection.py @@ -1105,8 +1105,6 @@ class AWSQueryConnection(AWSAuthConnection): def _required_auth_capability(self): return [] - def get_utf8_value(self, value): - return boto.utils.get_utf8_value(value) def make_request(self, action, params=None, path='/', verb='GET'): http_request = self.build_base_http_request(verb, path, None, diff --git a/boto/gs/bucket.py b/boto/gs/bucket.py index 01ac0839..b355af48 100644 --- a/boto/gs/bucket.py +++ b/boto/gs/bucket.py @@ -644,7 +644,7 @@ class Bucket(S3Bucket): :param str storage_class: A string containing the storage class. :param dict headers: Additional headers to send with the request. """ - req_body = self.StorageClassBody % (get_utf8_value(storage_class)) + req_body = self.StorageClassBody % (six.ensure_str(storage_class)) self.set_subresource(STORAGE_CLASS_ARG, req_body, headers=headers) # Method with same signature as boto.s3.bucket.Bucket.add_email_grant(), @@ -883,7 +883,7 @@ class Bucket(S3Bucket): body = self.WebsiteBody % (main_page_frag, error_frag) response = self.connection.make_request( - 'PUT', get_utf8_value(self.name), data=get_utf8_value(body), + 'PUT', six.ensure_str(self.name), data=six.ensure_str(body), query_args='websiteConfig', headers=headers) body = response.read() if response.status == 200: diff --git a/boto/gs/connection.py b/boto/gs/connection.py index 9a2e4a2b..4dd18cab 100755 --- a/boto/gs/connection.py +++ b/boto/gs/connection.py @@ -91,8 +91,8 @@ class GSConnection(S3Connection): data = ('<CreateBucketConfiguration>%s%s</CreateBucketConfiguration>' % (location_elem, storage_class_elem)) response = self.make_request( - 'PUT', get_utf8_value(bucket_name), headers=headers, - data=get_utf8_value(data)) + 'PUT', six.ensure_str(bucket_name), headers=headers, + data=six.ensure_str(data)) body = response.read() if response.status == 409: raise self.provider.storage_create_error( diff --git a/boto/gs/key.py b/boto/gs/key.py index b1d4189f..94563a75 100644 --- a/boto/gs/key.py +++ b/boto/gs/key.py @@ -24,7 +24,7 @@ import binascii import os import re -from boto.compat import StringIO +from boto.compat import StringIO, six from boto.exception import BotoClientError from boto.s3.key import Key as S3Key from boto.s3.keyfile import KeyFile @@ -707,7 +707,7 @@ class Key(S3Key): self.md5 = None self.base64md5 = None - fp = StringIO(get_utf8_value(s)) + fp = StringIO(six.ensure_str(s)) r = self.set_contents_from_file(fp, headers, replace, cb, num_cb, policy, md5, if_generation=if_generation) diff --git a/boto/s3/bucket.py b/boto/s3/bucket.py index fdd040c8..e24d1a51 100644 --- a/boto/s3/bucket.py +++ b/boto/s3/bucket.py @@ -852,7 +852,7 @@ class Bucket(object): if isinstance(src_key_name, bytes): src_key_name = src_key_name.decode('utf-8') else: - src_key_name = boto.utils.get_utf8_value(src_key_name) + src_key_name = six.ensure_str(src_key_name) if preserve_acl: if self.name == src_bucket_name: src_bucket = self diff --git a/boto/s3/connection.py b/boto/s3/connection.py index 224bf882..22b06b7d 100644 --- a/boto/s3/connection.py +++ b/boto/s3/connection.py @@ -88,7 +88,7 @@ class _CallingFormat(object): return self.get_bucket_server(server, bucket) def build_auth_path(self, bucket, key=''): - key = boto.utils.get_utf8_value(key) + key = six.ensure_str(key) if isinstance(bucket, bytes): bucket = bucket.decode('utf-8') path = '' @@ -97,7 +97,7 @@ class _CallingFormat(object): return path + '/%s' % urllib.parse.quote(key) def build_path_base(self, bucket, key=''): - key = boto.utils.get_utf8_value(key) + key = six.ensure_str(key) return '/%s' % urllib.parse.quote(key) @@ -121,7 +121,7 @@ class OrdinaryCallingFormat(_CallingFormat): return server def build_path_base(self, bucket, key=''): - key = boto.utils.get_utf8_value(key) + key = six.ensure_str(key) path_base = '/' if bucket: path_base += "%s/" % bucket diff --git a/boto/utils.py b/boto/utils.py index 531a72d3..83b429b9 100644 --- a/boto/utils.py +++ b/boto/utils.py @@ -859,20 +859,6 @@ def notify(subject, body=None, html_body=None, to_string=None, boto.log.exception('notify failed') -def get_utf8_value(value): - if isinstance(value, bytes): - value.decode('utf-8') - return value - - if not isinstance(value, six.string_types): - value = six.text_type(value) - - if isinstance(value, six.text_type): - value = value.encode('utf-8') - - return value - - def mklist(value): if not isinstance(value, list): if isinstance(value, tuple): |