Package muntjac :: Package service :: Module file_type_resolver :: Class FileTypeResolver
[hide private]
[frames] | no frames]

Class FileTypeResolver

source code

object --+
         |
        FileTypeResolver

Utility class that can figure out mime-types and icons related to files.

Note : The icons are associated purely to mime-types, so a file may not have a custom icon accessible with this class.


Authors:
Vaadin Ltd., Richard Lincoln

Version: 1.1.2

Instance Methods [hide private]

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
getMIMEType(cls, file_or_filename)
Gets the mime-type of a file.
source code
 
getIcon(cls, file_or_filename)
Gets the descriptive icon representing file, based on the filename.
source code
 
getIconByMimeType(cls, mimeType) source code
 
addExtension(cls, extension, MIMEType)
Adds a mime-type mapping for the given filename extension.
source code
 
addIcon(cls, MIMEType, icon)
Adds a icon for the given mime-type.
source code
 
getExtensionToMIMETypeMapping(cls)
Gets the internal file extension to mime-type mapping.
source code
 
getMIMETypeToIconMapping(cls)
Gets the internal mime-type to icon mapping.
source code
Class Variables [hide private]
  DEFAULT_ICON = ThemeResource('../runo/icons/16/document.png')
Default icon given if no icon is specified for a mime-type.
  DEFAULT_MIME_TYPE = 'application/octet-stream'
Default mime-type.
  _initialExtToMIMEMap = 'application/cu-seeme ...
Initial file extension to mime-type mapping.
  _extToMIMEMap = {'%': 'application/x-trash', 'aac': 'audio/x-a...
File extension to MIME type mapping.
  _MIMEToIconMap = dict()
MIME type to Icon mapping.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

getMIMEType(cls, file_or_filename)
Class Method

source code 

Gets the mime-type of a file. Currently the mime-type is resolved based only on the file name extension.

Parameters:
  • file_or_filename - the file or name of the file whose mime-type is requested.
Returns:
mime-type string

getIcon(cls, file_or_filename)
Class Method

source code 

Gets the descriptive icon representing file, based on the filename. First the mime-type for the given filename is resolved, and then the corresponding icon is fetched from the internal icon storage. If it is not found the default icon is returned.

Parameters:
  • file_or_filename - the file or name of the file whose icon is requested.
Returns:
the icon corresponding to the given file

addExtension(cls, extension, MIMEType)
Class Method

source code 

Adds a mime-type mapping for the given filename extension. If the extension is already in the internal mapping it is overwritten.

Parameters:
  • extension - the filename extension to be associated with MIMEType.
  • MIMEType - the new mime-type for extension.

addIcon(cls, MIMEType, icon)
Class Method

source code 

Adds a icon for the given mime-type. If the mime-type also has a corresponding icon, it is replaced with the new icon.

Parameters:
  • MIMEType - the mime-type whose icon is to be changed.
  • icon - the new icon to be associated with MIMEType.

getExtensionToMIMETypeMapping(cls)
Class Method

source code 

Gets the internal file extension to mime-type mapping.

Returns:
unmodifiable map containing the current file extension to mime-type mapping

getMIMETypeToIconMapping(cls)
Class Method

source code 

Gets the internal mime-type to icon mapping.

Returns:
map containing the current mime-type to icon mapping

Class Variable Details [hide private]

_initialExtToMIMEMap

Initial file extension to mime-type mapping.

Value:
'application/cu-seeme                            csm cu,application/ds\
ptype                             tsp,application/futuresplash        \
                spl,application/mac-binhex40                        hq\
x,application/msaccess                            mdb,application/mswo\
rd                              doc dot,application/octet-stream      \
                  bin,application/oda                                 \
oda,application/pdf                                 pdf,application/pg\
p-signature                       pgp,application/postscript          \
...

_extToMIMEMap

File extension to MIME type mapping. All extensions are in lower case.

Value:
{'%': 'application/x-trash',
 'aac': 'audio/x-aac',
 'ai': 'application/postscript',
 'aif': 'audio/x-aiff',
 'aifc': 'audio/x-aiff',
 'aiff': 'audio/x-aiff',
 'asf': 'video/x-ms-asf',
 'asx': 'video/x-ms-asf',
...