Browse Source

[gs] Add boto package changes for Hue-GCS feature (#3484)

Harsh Gupta 2 years ago
parent
commit
398e71f43a

+ 3 - 3
desktop/core/ext-py3/boto-2.49.0/boto/gs/bucket.py

@@ -273,9 +273,9 @@ class Bucket(S3Bucket):
         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):

+ 5 - 5
desktop/core/ext-py3/boto-2.49.0/boto/gs/key.py

@@ -29,7 +29,7 @@ from boto.exception import BotoClientError
 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 @@ class Key(S3Key):
     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 @@ class Key(S3Key):
                 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 @@ class Key(S3Key):
         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)

+ 29 - 0
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):