home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / encodings / __init__.pyo (.txt) next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  2.8 KB  |  96 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import codecs
  5. import types
  6. from encodings import aliases
  7. _cache = { }
  8. _unknown = '--unknown--'
  9. _import_tail = [
  10.     '*']
  11. _norm_encoding_map = '                                              . 0123456789       ABCDEFGHIJKLMNOPQRSTUVWXYZ      abcdefghijklmnopqrstuvwxyz                                                                                                                                     '
  12. _aliases = aliases.aliases
  13.  
  14. class CodecRegistryError(LookupError, SystemError):
  15.     pass
  16.  
  17.  
  18. def normalize_encoding(encoding):
  19.     if hasattr(types, 'UnicodeType') and type(encoding) is types.UnicodeType:
  20.         encoding = encoding.encode('latin-1')
  21.     
  22.     return '_'.join(encoding.translate(_norm_encoding_map).split())
  23.  
  24.  
  25. def search_function(encoding):
  26.     entry = _cache.get(encoding, _unknown)
  27.     if entry is not _unknown:
  28.         return entry
  29.     
  30.     norm_encoding = normalize_encoding(encoding)
  31.     if not _aliases.get(norm_encoding):
  32.         pass
  33.     aliased_encoding = _aliases.get(norm_encoding.replace('.', '_'))
  34.     if aliased_encoding is not None:
  35.         modnames = [
  36.             aliased_encoding,
  37.             norm_encoding]
  38.     else:
  39.         modnames = [
  40.             norm_encoding]
  41.     for modname in modnames:
  42.         if not modname or '.' in modname:
  43.             continue
  44.         
  45.         
  46.         try:
  47.             mod = __import__('encodings.' + modname, globals(), locals(), _import_tail)
  48.         except ImportError:
  49.             continue
  50.  
  51.     else:
  52.         mod = None
  53.     
  54.     try:
  55.         getregentry = mod.getregentry
  56.     except AttributeError:
  57.         mod = None
  58.  
  59.     if mod is None:
  60.         _cache[encoding] = None
  61.         return None
  62.     
  63.     entry = getregentry()
  64.     if not isinstance(entry, codecs.CodecInfo):
  65.         if len(entry) <= len(entry):
  66.             pass
  67.         elif not len(entry) <= 7:
  68.             raise CodecRegistryError, 'module "%s" (%s) failed to register' % (mod.__name__, mod.__file__)
  69.         
  70.         if not not callable(entry[0]) and not callable(entry[1]):
  71.             if not entry[2] is not None or not callable(entry[2]):
  72.                 if not entry[3] is not None or not callable(entry[3]):
  73.                     if (len(entry) > 4 and entry[4] is not None or not callable(entry[4]) or len(entry) > 5) and entry[5] is not None and not callable(entry[5]):
  74.                         raise CodecRegistryError, 'incompatible codecs in module "%s" (%s)' % (mod.__name__, mod.__file__)
  75.                     
  76.         if len(entry) < 7 or entry[6] is None:
  77.             entry += (None,) * (6 - len(entry)) + (mod.__name__.split('.', 1)[1],)
  78.         
  79.         entry = codecs.CodecInfo(*entry)
  80.     
  81.     _cache[encoding] = entry
  82.     
  83.     try:
  84.         codecaliases = mod.getaliases()
  85.     except AttributeError:
  86.         pass
  87.  
  88.     for alias in codecaliases:
  89.         if not _aliases.has_key(alias):
  90.             _aliases[alias] = modname
  91.             continue
  92.     
  93.     return entry
  94.  
  95. codecs.register(search_function)
  96.