Skip to content

Commit

Permalink
Merge remote-tracking branch 'ejnoyes/master' into test-merge
Browse files Browse the repository at this point in the history
Conflicts:
	S3/S3.py

Fixed as two previous patches from ksperling (mime-type guessing) and
econnell (read from stdin) had touched exactly this same chunk.
  • Loading branch information
Matt Domsch authored and mdomsch committed Jul 31, 2012
2 parents db0b6a3 + 6a8bcf2 commit 64eb484
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions S3/Config.py
Expand Up @@ -40,6 +40,7 @@ class Config(object):
proxy_port = 3128
encrypt = False
dry_run = False
add_encoding_exts = ""
preserve_attrs = True
preserve_attrs_list = [
'uname', # Verbose owner Name (e.g. 'root')
Expand Down
24 changes: 22 additions & 2 deletions S3/S3.py
Expand Up @@ -371,6 +371,21 @@ def website_delete(self, uri, bucket_location = None):

return response

def add_encoding(self, filename, content_type):
if content_type.find("charset=") != -1:
return False
exts = self.config.add_encoding_exts.split(',')
if exts[0]=='':
return False
parts = filename.rsplit('.',2)
if len(parts) < 2:
return False
ext = parts[1]
if ext in exts:
return True
else:
return False

def object_put(self, filename, uri, extra_headers = None, extra_label = ""):
# TODO TODO
# Make it consistent with stream-oriented object_get()
Expand All @@ -395,12 +410,17 @@ def object_put(self, filename, uri, extra_headers = None, extra_label = ""):

## MIME-type handling
content_type = self.config.mime_type
content_encoding = None
if filename != "-" and not content_type and self.config.guess_mime_type:
(content_type, content_encoding) = mime_magic(filename)
if not content_type:
content_type = self.config.default_mime_type
debug("Content-Type set to '%s' (encoding %s)" % (content_type, content_encoding))
if not content_encoding:
content_encoding = self.config.encoding.upper()

## add charset to content type
if self.add_encoding(filename, content_type) and content_encoding is not None:
content_type = content_type + "; charset=" + content_encoding

headers["content-type"] = content_type
if content_encoding is not None:
headers["content-encoding"] = content_encoding
Expand Down
1 change: 1 addition & 0 deletions s3cmd
Expand Up @@ -1709,6 +1709,7 @@ def main():
optparser.add_option( "--add-header", dest="add_header", action="append", metavar="NAME:VALUE", help="Add a given HTTP header to the upload request. Can be used multiple times. For instance set 'Expires' or 'Cache-Control' headers (or both) using this options if you like.")

optparser.add_option( "--encoding", dest="encoding", metavar="ENCODING", help="Override autodetected terminal and filesystem encoding (character set). Autodetected: %s" % preferred_encoding)
optparser.add_option( "--add-encoding-exts", dest="add_encoding_exts", metavar="EXTENSIONs", help="Add encoding to these comma delimited extensions i.e. (css,js,html) when uploading to S3 )")
optparser.add_option( "--verbatim", dest="urlencoding_mode", action="store_const", const="verbatim", help="Use the S3 name as given on the command line. No pre-processing, encoding, etc. Use with caution!")

optparser.add_option( "--disable-multipart", dest="enable_multipart", action="store_false", help="Disable multipart upload on files bigger than --multipart-chunk-size-mb")
Expand Down

0 comments on commit 64eb484

Please sign in to comment.