diff options
author | Barry Warsaw <barry@python.org> | 2006-03-18 15:41:53 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2006-03-18 15:41:53 (GMT) |
commit | 40ef0067ad5af2458c54cc0316831ddb701ea3fd (patch) | |
tree | 52204dc86cfb735d4aadff24864af50da4fe78de /Lib/email/__init__.py | |
parent | 9ae019bf5b92d9ac0ee8bb53829f6b5a16d5fab2 (diff) | |
download | cpython-40ef0067ad5af2458c54cc0316831ddb701ea3fd.zip cpython-40ef0067ad5af2458c54cc0316831ddb701ea3fd.tar.gz cpython-40ef0067ad5af2458c54cc0316831ddb701ea3fd.tar.bz2 |
Merge email package 4.0 from the sandbox, including documentation, test cases,
and NEWS updates.
Diffstat (limited to 'Lib/email/__init__.py')
-rw-r--r-- | Lib/email/__init__.py | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/Lib/email/__init__.py b/Lib/email/__init__.py index e5c0e2e..0a6a72d 100644 --- a/Lib/email/__init__.py +++ b/Lib/email/__init__.py @@ -4,9 +4,10 @@ """A package for parsing, handling, and generating email messages.""" -__version__ = '3.0.1' +__version__ = '4.0a2' __all__ = [ + # Old names 'base64MIME', 'Charset', 'Encoders', @@ -27,6 +28,19 @@ __all__ = [ 'Utils', 'message_from_string', 'message_from_file', + # new names + 'base64mime', + 'charset', + 'encoders', + 'errors', + 'generator', + 'header', + 'iterators', + 'message', + 'mime', + 'parser', + 'quoprimime', + 'utils', ] @@ -39,7 +53,7 @@ def message_from_string(s, *args, **kws): Optional _class and strict are passed to the Parser constructor. """ - from email.Parser import Parser + from email.parser import Parser return Parser(*args, **kws).parsestr(s) @@ -48,5 +62,62 @@ def message_from_file(fp, *args, **kws): Optional _class and strict are passed to the Parser constructor. """ - from email.Parser import Parser + from email.parser import Parser return Parser(*args, **kws).parse(fp) + + + +# Lazy loading to provide name mapping from new-style names (PEP 8 compatible +# email 4.0 module names), to old-style names (email 3.0 module names). +import sys + +class LazyImporter(object): + def __init__(self, module_name): + self.__name__ = 'email.' + module_name + + def __getattr__(self, name): + __import__(self.__name__) + mod = sys.modules[self.__name__] + self.__dict__.update(mod.__dict__) + return getattr(mod, name) + + +_LOWERNAMES = [ + # email.<old name> -> email.<new name is lowercased old name> + 'Charset', + 'Encoders', + 'Errors', + 'FeedParser', + 'Generator', + 'Header', + 'Iterators', + 'Message', + 'Parser', + 'Utils', + 'base64MIME', + 'quopriMIME', + ] + +_MIMENAMES = [ + # email.MIME<old name> -> email.mime.<new name is lowercased old name> + 'Audio', + 'Base', + 'Image', + 'Message', + 'Multipart', + 'NonMultipart', + 'Text', + ] + +for _name in _LOWERNAMES: + importer = LazyImporter(_name.lower()) + sys.modules['email.' + _name] = importer + setattr(sys.modules['email'], _name, importer) + + +import email.mime +for _name in _MIMENAMES: + importer = LazyImporter('mime.' + _name.lower()) + sys.modules['email.MIME' + _name] = importer + setattr(sys.modules['email'], 'MIME' + _name, importer) + setattr(sys.modules['email.mime'], _name, importer) |