Permalink
Browse files

don't add charset if it's already there, make param a comma delimited…

… str, not multiple
  • Loading branch information...
1 parent 4d29dd4 commit 833f07bb63efb6273c2b0bcd68898a8d295fd22d @cjnoyescrisp cjnoyescrisp committed Jul 19, 2012
Showing with 14 additions and 6 deletions.
  1. +1 −1 S3/Config.py
  2. +12 −4 S3/S3.py
  3. +1 −1 s3cmd
View
@@ -40,7 +40,7 @@ class Config(object):
proxy_port = 3128
encrypt = False
dry_run = False
- add_encoding_ext = []
+ add_encoding_exts = ""
preserve_attrs = True
preserve_attrs_list = [
'uname', # Verbose owner Name (e.g. 'root')
View
@@ -339,10 +339,17 @@ def website_delete(self, uri, bucket_location = None):
return response
- def add_encoding(self, filename):
+ 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 self.config.add_encoding_ext:
+ if ext in exts:
return True
else:
return False
@@ -367,13 +374,14 @@ def object_put(self, filename, uri, extra_headers = None, extra_label = ""):
## MIME-type handling
content_type = self.config.mime_type
+ print(content_type)
if not content_type and self.config.guess_mime_type:
content_type = mime_magic(filename)
if not content_type:
content_type = self.config.default_mime_type
-
+ print(content_type)
## add charset to content type
- if self.add_encoding(filename):
+ if self.add_encoding(filename, content_type):
content_type = content_type + ";charset=" + self.config.encoding.upper()
debug("Content-Type set to '%s'" % content_type)
View
2 s3cmd
@@ -1524,7 +1524,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-ext", dest="add_encoding_ext", action="append", metavar="EXTENSION", help="Add encoding to this ext when uploading to S3, may be used multiple times")
+ 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")

0 comments on commit 833f07b

Please sign in to comment.