Back to index

plone3  3.1.7
Functions | Variables
MimetypesRegistry.mime_types.windows_mimetypes Namespace Reference

Functions

def _RegQueryValue
def get_desc_for_mimetype
def get_ext_for_mimetype
def get_mime_types
def normalize
def initialize

Variables

tuple logger = logging.getLogger('mimetypes.win32')
tuple ext = get_ext_for_mimetype(mt)
tuple desc = get_desc_for_mimetype(mt)

Function Documentation

def MimetypesRegistry.mime_types.windows_mimetypes._RegQueryValue (   key,
  value,
  default = None 
) [private]

Definition at line 11 of file windows_mimetypes.py.

00011 
00012 def _RegQueryValue(key, value, default=None):
00013     try:
00014         data, typ = win32api.RegQueryValueEx(key, value)
00015     except win32api.error:
00016         return default
00017     if typ == win32con.REG_EXPAND_SZ:
00018         data = win32api.ExpandEnvironmentStrings(data)
00019     if type in (win32con.REG_EXPAND_SZ, win32con.REG_SZ):
00020         # Occasionally see trailing \0 chars.
00021         data = data.rstrip('\0')
00022     return data

Here is the caller graph for this function:

Definition at line 23 of file windows_mimetypes.py.

00023 
00024 def get_desc_for_mimetype(mime_type):
00025     try:
00026         hk = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT,
00027                                  r"MIME\Database\Content Type\\" + mime_type)
00028         desc = _RegQueryValue(hk, "")
00029     except win32api.error, details:
00030         logger.info("win32api error fetching description for mime-type %r: %s",
00031                      mime_type, details)
00032         desc = None
00033     logger.debug("mime-type %s has description %s", mime_type, desc)
00034     return desc

Here is the call graph for this function:

Definition at line 35 of file windows_mimetypes.py.

00035 
00036 def get_ext_for_mimetype(mime_type):
00037     try:
00038         hk = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT,
00039                                  r"MIME\Database\Content Type\\" + mime_type)
00040         ext = _RegQueryValue(hk, "Extension")
00041     except win32api.error, details:
00042         logger.info("win32api error fetching extension for mime-type %r: %s",
00043                      mime_type, details)
00044         ext = None
00045     logger.debug("mime-type %s has extension %s", mime_type, ext)
00046     return ext

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 47 of file windows_mimetypes.py.

00047 
00048 def get_mime_types():
00049     try:
00050         hk = win32api.RegOpenKey(win32con.HKEY_CLASSES_ROOT,
00051                                  r"MIME\Database\Content Type")
00052         items = win32api.RegEnumKeyEx(hk)
00053     except win32api.error, details:
00054         logger.info("win32api error fetching mimetypes: %s",
00055                     details)
00056         items = []
00057     return [i[0] for i in items if i[0]]

Here is the caller graph for this function:

Definition at line 62 of file windows_mimetypes.py.

00062 
00063 def initialize():
00064     if not mimetypes.inited:
00065         mimetypes.init()
00066 
00067     for mt in get_mime_types():
00068         ext = get_ext_for_mimetype(mt)
00069         if not ext:
00070             continue
00071         if not mimetypes.types_map.has_key(ext):
00072             mimetypes.add_type(normalize(mt), ext)

Here is the call graph for this function:

Definition at line 58 of file windows_mimetypes.py.

00058 
00059 def normalize(mt):
00060     # Some mimetypes might have extra ';q=value' params.
00061     return mt.lower().split(';')[0]

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 76 of file windows_mimetypes.py.

Definition at line 75 of file windows_mimetypes.py.

tuple MimetypesRegistry.mime_types.windows_mimetypes.logger = logging.getLogger('mimetypes.win32')

Definition at line 8 of file windows_mimetypes.py.