#NEWLINE# def get_mimetype( file_object , mimetype_only = False ) : #NEWLINE# #INDENT# "\n    Determine a file's mimetype by calling the system's libmagic\n    library via python-magic or fallback to use python's mimetypes\n    library\n    " #NEWLINE# file_mimetype = None #NEWLINE# file_mime_encoding = None #NEWLINE# mime = magic . Magic ( mime = True ) #NEWLINE# file_mimetype = mime . from_buffer ( file_object . read ( ) ) #NEWLINE# file_object . seek ( 0 ) #NEWLINE# if ( not mime_encoding ) : #NEWLINE# #INDENT# file_object . seek ( 0 ) #NEWLINE# mime_encoding = magic . Magic ( mime_encoding = True ) #NEWLINE# file_mime_encoding = mime_encoding . from_buffer ( file_object . read ( ) ) #NEWLINE# file_object . seek ( 0 ) #NEWLINE# #UNINDENT# return ( file_mimetype , file_mime_encoding )