Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/s3tools/s3cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
mludvig committed Dec 30, 2011
2 parents 0479b57 + d882e50 commit 777acd9
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@
from AccessLog import AccessLog
from S3Uri import S3Uri

try:
import magic
try:
## https://github.com/ahupp/python-magic
magic_ = magic.Magic(mime=True)
def mime_magic(file):
return magic_.from_file(file)
except AttributeError:
## Older python-magic versions
magic_ = magic.open(magic.MAGIC_MIME)
magic_.load()
def mime_magic(file):
return magic_.file(file)
except ImportError:
magic_warned = False
def mime_magic(file):
global magic_warned
if (not magic_warned):
warning("python-magic is not available, guessing MIME types based on file extensions only")
magic_warned = True
return mimetypes.guess_type(file)[0]


__all__ = []
class S3Request(object):
def __init__(self, s3, method_string, resource, headers, params = {}):
Expand Down Expand Up @@ -328,7 +351,7 @@ def object_put(self, filename, uri, extra_headers = None, extra_label = ""):
headers["content-length"] = size
content_type = self.config.mime_type
if not content_type and self.config.guess_mime_type:
content_type = mimetypes.guess_type(filename)[0]
content_type = mime_magic(filename)
if not content_type:
content_type = self.config.default_mime_type
debug("Content-Type set to '%s'" % content_type)
Expand Down

0 comments on commit 777acd9

Please sign in to comment.