Skip to content

Commit

Permalink
Merge branch 'mime-guessing'
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling committed Jun 27, 2012
2 parents 9447184 + 990b48c commit a845413
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions S3/S3.py
Expand Up @@ -37,7 +37,14 @@ def mime_magic_file(file):
return magic_.from_file(file) return magic_.from_file(file)
def mime_magic_buffer(buffer): def mime_magic_buffer(buffer):
return magic_.from_buffer(buffer) return magic_.from_buffer(buffer)
except (TypeError, AttributeError): except TypeError:
## http://pypi.python.org/pypi/filemagic
magic_ = magic.Magic(flags=magic.MAGIC_MIME)
def mime_magic_file(file):
return magic_.id_filename(file)
def mime_magic_buffer(buffer):
return magic_.id_buffer(buffer)
except AttributeError:
## Older python-magic versions ## Older python-magic versions
magic_ = magic.open(magic.MAGIC_MIME) magic_ = magic.open(magic.MAGIC_MIME)
magic_.load() magic_.load()
Expand Down Expand Up @@ -65,7 +72,7 @@ def mime_magic(file):
if (not magic_warned): if (not magic_warned):
warning(magic_message) warning(magic_message)
magic_warned = True magic_warned = True
return mimetypes.guess_type(file)[0] return mimetypes.guess_type(file)


__all__ = [] __all__ = []
class S3Request(object): class S3Request(object):
Expand Down
2 changes: 1 addition & 1 deletion s3cmd
Expand Up @@ -1518,7 +1518,7 @@ def main():
optparser.add_option( "--no-access-logging", dest="log_target_prefix", action="store_false", help="Disable access logging (for [cfmodify] and [accesslog] commands)") optparser.add_option( "--no-access-logging", dest="log_target_prefix", action="store_false", help="Disable access logging (for [cfmodify] and [accesslog] commands)")


optparser.add_option( "--default-mime-type", dest="default_mime_type", action="store_true", help="Default MIME-type for stored objects. Application default is binary/octet-stream.") optparser.add_option( "--default-mime-type", dest="default_mime_type", action="store_true", help="Default MIME-type for stored objects. Application default is binary/octet-stream.")
optparser.add_option( "--guess-mime-type", dest="guess_mime_type", action="store_true", help="Guess MIME-type of files by their extension or mime magic. Fall back to default MIME-Type as specified by --default-mime-type option") optparser.add_option("-M", "--guess-mime-type", dest="guess_mime_type", action="store_true", help="Guess MIME-type of files by their extension or mime magic. Fall back to default MIME-Type as specified by --default-mime-type option")
optparser.add_option( "--no-guess-mime-type", dest="guess_mime_type", action="store_false", help="Don't guess MIME-type and use the default type instead.") optparser.add_option( "--no-guess-mime-type", dest="guess_mime_type", action="store_false", help="Don't guess MIME-type and use the default type instead.")
optparser.add_option("-m", "--mime-type", dest="mime_type", type="mimetype", metavar="MIME/TYPE", help="Force MIME-type. Override both --default-mime-type and --guess-mime-type.") optparser.add_option("-m", "--mime-type", dest="mime_type", type="mimetype", metavar="MIME/TYPE", help="Force MIME-type. Override both --default-mime-type and --guess-mime-type.")


Expand Down

0 comments on commit a845413

Please sign in to comment.