From 398e71f43a08a47ef1a1ee444fcc9e733c0366da Mon Sep 17 00:00:00 2001 From: Harsh Gupta <42064744+Harshg999@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:01:20 +0530 Subject: [PATCH] [gs] Add boto package changes for Hue-GCS feature (#3484) --- .../ext-py3/boto-2.49.0/boto/gs/bucket.py | 6 ++-- .../core/ext-py3/boto-2.49.0/boto/gs/key.py | 10 +++---- .../core/ext-py3/boto-2.49.0/boto/utils.py | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/desktop/core/ext-py3/boto-2.49.0/boto/gs/bucket.py b/desktop/core/ext-py3/boto-2.49.0/boto/gs/bucket.py index 8e56dedb4d..5c4be0b4f0 100644 --- a/desktop/core/ext-py3/boto-2.49.0/boto/gs/bucket.py +++ b/desktop/core/ext-py3/boto-2.49.0/boto/gs/bucket.py @@ -273,9 +273,9 @@ def delete_key(self, key_name, headers=None, version_id=None, query_args_l = [] if generation: query_args_l.append('generation=%s' % generation) - self._delete_key_internal(key_name, headers=headers, - version_id=version_id, mfa_token=mfa_token, - query_args_l=query_args_l) + return self._delete_key_internal(key_name, headers=headers, + version_id=version_id, mfa_token=mfa_token, + query_args_l=query_args_l) def set_acl(self, acl_or_str, key_name='', headers=None, version_id=None, generation=None, if_generation=None, if_metageneration=None): diff --git a/desktop/core/ext-py3/boto-2.49.0/boto/gs/key.py b/desktop/core/ext-py3/boto-2.49.0/boto/gs/key.py index f1ea3e1605..9ed3c4924e 100644 --- a/desktop/core/ext-py3/boto-2.49.0/boto/gs/key.py +++ b/desktop/core/ext-py3/boto-2.49.0/boto/gs/key.py @@ -29,7 +29,7 @@ from boto.s3.key import Key as S3Key from boto.s3.keyfile import KeyFile from boto.utils import compute_hash -from boto.utils import get_utf8_value +from boto.utils import get_utf8_value, get_utf8able_str class Key(S3Key): """ @@ -406,7 +406,7 @@ def add_group_grant(self, permission, group_id): def set_contents_from_file(self, fp, headers=None, replace=True, cb=None, num_cb=10, policy=None, md5=None, res_upload_handler=None, size=None, rewind=False, - if_generation=None): + if_generation=None, reduced_redundancy=None, query_args=None): """ Store an object in GS using the name of the Key object as the key in GS and the contents of the file pointed to by 'fp' as the @@ -576,10 +576,10 @@ def set_contents_from_file(self, fp, headers=None, replace=True, headers['x-goog-if-generation-match'] = str(if_generation) if res_upload_handler: - res_upload_handler.send_file(self, fp, headers, cb, num_cb) + res_upload_handler.send_file(self, fp, headers, cb, num_cb, query_args=query_args) else: # Not a resumable transfer so use basic send_file mechanism. - self.send_file(fp, headers, cb, num_cb, size=size) + self.send_file(fp, headers, cb, num_cb, size=size, query_args=query_args) def set_contents_from_filename(self, filename, headers=None, replace=True, cb=None, num_cb=10, policy=None, md5=None, @@ -707,7 +707,7 @@ def set_contents_from_string(self, s, headers=None, replace=True, self.md5 = None self.base64md5 = None - fp = StringIO(get_utf8_value(s)) + fp = StringIO(get_utf8able_str(s)) r = self.set_contents_from_file(fp, headers, replace, cb, num_cb, policy, md5, if_generation=if_generation) diff --git a/desktop/core/ext-py3/boto-2.49.0/boto/utils.py b/desktop/core/ext-py3/boto-2.49.0/boto/utils.py index 22f9711098..a16220087f 100644 --- a/desktop/core/ext-py3/boto-2.49.0/boto/utils.py +++ b/desktop/core/ext-py3/boto-2.49.0/boto/utils.py @@ -872,6 +872,35 @@ def get_utf8_value(value): return value +def get_utf8able_str(s, errors='strict'): + """Returns a UTF8-encodable string in PY3, UTF8 bytes in PY2. + This method is similar to six's `ensure_str()`, except it also + makes sure that any bytes passed in can be decoded using the + utf-8 codec (and raises a UnicodeDecodeError if not). If the + object isn't a string, this method will attempt to coerce it + to a string with `str()`. Objects without `__str__` property + or `__repr__` property will raise an exception. + """ + if not isinstance(s, (six.text_type, six.binary_type)): + s = str(s) + if six.PY2: + # We want to return utf-8 encoded bytes. + if isinstance(s, six.text_type): + return s.encode('utf-8', errors) + if isinstance(s, six.binary_type): + # Verify the bytes can be represented in utf-8 + s.decode('utf-8') + return s + else: + # We want to return a unicode/str object. + if isinstance(s, six.text_type): + return s + if isinstance(s, six.binary_type): + s = s.decode('utf-8') + return s + raise TypeError('not expecting type "%s"' % type(s)) + + def mklist(value): if not isinstance(value, list): if isinstance(value, tuple):