symbian-qemu-0.9.1-12/python-win32-2.6.1/lib/email/__init__.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 # Copyright (C) 2001-2006 Python Software Foundation
       
     2 # Author: Barry Warsaw
       
     3 # Contact: email-sig@python.org
       
     4 
       
     5 """A package for parsing, handling, and generating email messages."""
       
     6 
       
     7 __version__ = '4.0.1'
       
     8 
       
     9 __all__ = [
       
    10     # Old names
       
    11     'base64MIME',
       
    12     'Charset',
       
    13     'Encoders',
       
    14     'Errors',
       
    15     'Generator',
       
    16     'Header',
       
    17     'Iterators',
       
    18     'Message',
       
    19     'MIMEAudio',
       
    20     'MIMEBase',
       
    21     'MIMEImage',
       
    22     'MIMEMessage',
       
    23     'MIMEMultipart',
       
    24     'MIMENonMultipart',
       
    25     'MIMEText',
       
    26     'Parser',
       
    27     'quopriMIME',
       
    28     'Utils',
       
    29     'message_from_string',
       
    30     'message_from_file',
       
    31     # new names
       
    32     'base64mime',
       
    33     'charset',
       
    34     'encoders',
       
    35     'errors',
       
    36     'generator',
       
    37     'header',
       
    38     'iterators',
       
    39     'message',
       
    40     'mime',
       
    41     'parser',
       
    42     'quoprimime',
       
    43     'utils',
       
    44     ]
       
    45 
       
    46 
       
    47 
       
    48 # Some convenience routines.  Don't import Parser and Message as side-effects
       
    49 # of importing email since those cascadingly import most of the rest of the
       
    50 # email package.
       
    51 def message_from_string(s, *args, **kws):
       
    52     """Parse a string into a Message object model.
       
    53 
       
    54     Optional _class and strict are passed to the Parser constructor.
       
    55     """
       
    56     from email.parser import Parser
       
    57     return Parser(*args, **kws).parsestr(s)
       
    58 
       
    59 
       
    60 def message_from_file(fp, *args, **kws):
       
    61     """Read a file and parse its contents into a Message object model.
       
    62 
       
    63     Optional _class and strict are passed to the Parser constructor.
       
    64     """
       
    65     from email.parser import Parser
       
    66     return Parser(*args, **kws).parse(fp)
       
    67 
       
    68 
       
    69 
       
    70 # Lazy loading to provide name mapping from new-style names (PEP 8 compatible
       
    71 # email 4.0 module names), to old-style names (email 3.0 module names).
       
    72 import sys
       
    73 
       
    74 class LazyImporter(object):
       
    75     def __init__(self, module_name):
       
    76         self.__name__ = 'email.' + module_name
       
    77 
       
    78     def __getattr__(self, name):
       
    79         __import__(self.__name__)
       
    80         mod = sys.modules[self.__name__]
       
    81         self.__dict__.update(mod.__dict__)
       
    82         return getattr(mod, name)
       
    83 
       
    84 
       
    85 _LOWERNAMES = [
       
    86     # email.<old name> -> email.<new name is lowercased old name>
       
    87     'Charset',
       
    88     'Encoders',
       
    89     'Errors',
       
    90     'FeedParser',
       
    91     'Generator',
       
    92     'Header',
       
    93     'Iterators',
       
    94     'Message',
       
    95     'Parser',
       
    96     'Utils',
       
    97     'base64MIME',
       
    98     'quopriMIME',
       
    99     ]
       
   100 
       
   101 _MIMENAMES = [
       
   102     # email.MIME<old name> -> email.mime.<new name is lowercased old name>
       
   103     'Audio',
       
   104     'Base',
       
   105     'Image',
       
   106     'Message',
       
   107     'Multipart',
       
   108     'NonMultipart',
       
   109     'Text',
       
   110     ]
       
   111 
       
   112 for _name in _LOWERNAMES:
       
   113     importer = LazyImporter(_name.lower())
       
   114     sys.modules['email.' + _name] = importer
       
   115     setattr(sys.modules['email'], _name, importer)
       
   116 
       
   117 
       
   118 import email.mime
       
   119 for _name in _MIMENAMES:
       
   120     importer = LazyImporter('mime.' + _name.lower())
       
   121     sys.modules['email.MIME' + _name] = importer
       
   122     setattr(sys.modules['email'], 'MIME' + _name, importer)
       
   123     setattr(sys.modules['email.mime'], _name, importer)