Skip to content

Commit

Permalink
[gs] Add boto package changes for Hue-GCS feature (#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshg999 authored Oct 4, 2023
1 parent ae1659e commit 398e71f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
6 changes: 3 additions & 3 deletions desktop/core/ext-py3/boto-2.49.0/boto/gs/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions desktop/core/ext-py3/boto-2.49.0/boto/gs/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions desktop/core/ext-py3/boto-2.49.0/boto/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 398e71f

Please sign in to comment.