1 # Copyright (C) 2001-2006 Python Software Foundation
3 # Contact: email-sig@python.org
5 """A package for parsing, handling, and generating email messages."""
29 'message_from_string',
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
51 def message_from_string(s
, *args
, **kws
):
52 """Parse a string into a Message object model.
54 Optional _class and strict are passed to the Parser constructor.
56 from email
.parser
import Parser
57 return Parser(*args
, **kws
).parsestr(s
)
60 def message_from_file(fp
, *args
, **kws
):
61 """Read a file and parse its contents into a Message object model.
63 Optional _class and strict are passed to the Parser constructor.
65 from email
.parser
import Parser
66 return Parser(*args
, **kws
).parse(fp
)
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).
74 class LazyImporter(object):
75 def __init__(self
, module_name
):
76 self
.__name
__ = 'email.' + module_name
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
)
86 # email.<old name> -> email.<new name is lowercased old name>
102 # email.MIME<old name> -> email.mime.<new name is lowercased old name>
112 for _name
in _LOWERNAMES
:
113 importer
= LazyImporter(_name
.lower())
114 sys
.modules
['email.' + _name
] = importer
115 setattr(sys
.modules
['email'], _name
, importer
)
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
)