From d07bcfa6e151ee485931288106f4f9078fea5100 Mon Sep 17 00:00:00 2001 From: Florent Viard Date: Sat, 3 Mar 2018 22:42:11 +0100 Subject: [PATCH] Complete #940 - upload_id, content_disposition and content_type default value is now "" and not anymore None --- S3/Config.py | 6 +++--- S3/Crypto.py | 8 ++++---- S3/MultiPart.py | 10 +++++----- S3/S3.py | 2 +- s3cmd | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/S3/Config.py b/S3/Config.py index 373d5f24d..1bac17e05 100644 --- a/S3/Config.py +++ b/S3/Config.py @@ -104,7 +104,7 @@ class Config(object): enable = None get_continue = False put_continue = False - upload_id = None + upload_id = u"" skip_existing = False recursive = False restore_days = 1 @@ -189,8 +189,8 @@ class Config(object): limitrate = 0 requester_pays = False stop_on_error = False - content_disposition = None - content_type = None + content_disposition = u"" + content_type = u"" stats = False # Disabled by default because can create a latency with a CONTINUE status reply # expected for every send file requests. diff --git a/S3/Crypto.py b/S3/Crypto.py index 0d509f7da..9937410cd 100644 --- a/S3/Crypto.py +++ b/S3/Crypto.py @@ -149,19 +149,19 @@ def sign_url_base_v2(**parms): debug("Expiry interpreted as epoch time %s", parms['expiry']) signtext = 'GET\n\n\n%(expiry)d\n/%(bucket)s/%(object)s' % parms param_separator = '?' - if content_disposition is not None: + if content_disposition: signtext += param_separator + 'response-content-disposition=' + content_disposition param_separator = '&' - if content_type is not None: + if content_type: signtext += param_separator + 'response-content-type=' + content_type param_separator = '&' debug("Signing plaintext: %r", signtext) parms['sig'] = s3_quote(sign_string_v2(encode_to_s3(signtext)), unicode_output=True) debug("Urlencoded signature: %s", parms['sig']) url = "%(proto)s://%(bucket)s.%(host_base)s/%(object)s?AWSAccessKeyId=%(access_key)s&Expires=%(expiry)d&Signature=%(sig)s" % parms - if content_disposition is not None: + if content_disposition: url += "&response-content-disposition=" + s3_quote(content_disposition, unicode_output=True) - if content_type is not None: + if content_type: url += "&response-content-type=" + s3_quote(content_type, unicode_output=True) return url diff --git a/S3/MultiPart.py b/S3/MultiPart.py index a862eb886..b3367725f 100644 --- a/S3/MultiPart.py +++ b/S3/MultiPart.py @@ -40,7 +40,7 @@ def get_parts_information(self, uri, upload_id): return parts def get_unique_upload_id(self, uri): - upload_id = None + upload_id = "" multipart_response = self.s3.get_multipart(uri) tree = getTreeFromXml(multipart_response['data']) for mpupload in parseNodes(tree): @@ -49,7 +49,7 @@ def get_unique_upload_id(self, uri): mp_path = mpupload['Key'] info("mp_path: %s, object: %s" % (mp_path, uri.object())) if mp_path == uri.object(): - if upload_id is not None: + if upload_id: raise ValueError("More than one UploadId for URI %s. Disable multipart upload, or use\n %s multipart %s\nto list the Ids, then pass a unique --upload-id into the put command." % (uri, sys.argv[0], uri)) upload_id = mp_upload_id except KeyError: @@ -62,14 +62,14 @@ def initiate_multipart_upload(self): Begin a multipart upload http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadInitiate.html """ - if self.s3.config.upload_id is not None: + if self.s3.config.upload_id: self.upload_id = self.s3.config.upload_id elif self.s3.config.put_continue: self.upload_id = self.get_unique_upload_id(self.uri) else: - self.upload_id = None + self.upload_id = "" - if self.upload_id is None: + if not self.upload_id: request = self.s3.create_request("OBJECT_POST", uri = self.uri, headers = self.headers_baseline, uri_params = {'uploads': None}) diff --git a/S3/S3.py b/S3/S3.py index 92d35572d..13089a85e 100644 --- a/S3/S3.py +++ b/S3/S3.py @@ -582,7 +582,7 @@ def _guess_content_type(self, filename): def stdin_content_type(self): content_type = self.config.mime_type - if content_type == '': + if not content_type: content_type = self.config.default_mime_type content_type += "; charset=" + self.config.encoding.upper() diff --git a/s3cmd b/s3cmd index e94b62093..c97d3b902 100755 --- a/s3cmd +++ b/s3cmd @@ -2875,7 +2875,7 @@ def main(): raise ParameterError("Chunk size %d MB is too large, must be <= %d MB. Please adjust --multipart-chunk-size-mb" % (cfg.multipart_chunk_size_mb, MultiPartUpload.MAX_CHUNK_SIZE_MB)) ## If an UploadId was provided, set put_continue True - if options.upload_id is not None: + if options.upload_id: cfg.upload_id = options.upload_id cfg.put_continue = True