Mercurial > cpython-lru_cache-weakref
annotate Lib/email/__init__.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 29e509793d3c |
| children |
| rev | line source |
|---|---|
|
36311
3709ce37fe1c
Ported 42075 from release23-maint branch.
Barry Warsaw <barry@python.org>
parents:
34099
diff
changeset
|
1 # Copyright (C) 2001-2006 Python Software Foundation |
|
33651
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
32025
diff
changeset
|
2 # Author: Barry Warsaw |
|
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
32025
diff
changeset
|
3 # Contact: email-sig@python.org |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
4 |
|
32025
f4376f7674a2
Update to Python 2.3, getting rid of backward compatiblity crud.
Barry Warsaw <barry@python.org>
parents:
31280
diff
changeset
|
5 """A package for parsing, handling, and generating email messages.""" |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
6 |
|
62516
29e509793d3c
#9085: email versions have gotten out of sync, 2.7 is actually 4.0.3.
R. David Murray <rdmurray@bitdance.com>
parents:
59452
diff
changeset
|
7 __version__ = '4.0.3' |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
8 |
| 25502 | 9 __all__ = [ |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
10 # Old names |
| 25502 | 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', | |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
31 # new names |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
32 'base64mime', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
33 'charset', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
34 'encoders', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
35 'errors', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
36 'generator', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
37 'header', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
38 'iterators', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
39 'message', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
40 'mime', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
41 'parser', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
42 'quoprimime', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
43 'utils', |
| 25502 | 44 ] |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
45 |
|
25473
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
46 |
|
20253
d96cd38a3fec
Give me back my page breaks.
Barry Warsaw <barry@python.org>
parents:
20240
diff
changeset
|
47 |
| 25434 | 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. | |
|
33651
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
32025
diff
changeset
|
51 def message_from_string(s, *args, **kws): |
|
25473
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
52 """Parse a string into a Message object model. |
|
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
53 |
|
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
54 Optional _class and strict are passed to the Parser constructor. |
|
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
55 """ |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
56 from email.parser import Parser |
|
33651
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
32025
diff
changeset
|
57 return Parser(*args, **kws).parsestr(s) |
|
20042
e08f423f9165
The email package version 1.0, prototyped as mimelib
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
58 |
|
32025
f4376f7674a2
Update to Python 2.3, getting rid of backward compatiblity crud.
Barry Warsaw <barry@python.org>
parents:
31280
diff
changeset
|
59 |
|
33651
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
32025
diff
changeset
|
60 def message_from_file(fp, *args, **kws): |
|
25473
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
61 """Read a file and parse its contents into a Message object model. |
|
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
62 |
|
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
63 Optional _class and strict are passed to the Parser constructor. |
|
2a763e7b7deb
Code cleanup and add docstrings.
Barry Warsaw <barry@python.org>
parents:
25434
diff
changeset
|
64 """ |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
65 from email.parser import Parser |
|
33651
946612f64a83
Big email 3.0 API changes, with updated unit tests and documentation.
Barry Warsaw <barry@python.org>
parents:
32025
diff
changeset
|
66 return Parser(*args, **kws).parse(fp) |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
67 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
68 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
69 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
70 # Lazy loading to provide name mapping from new-style names (PEP 8 compatible |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
71 # email 4.0 module names), to old-style names (email 3.0 module names). |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
72 import sys |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
73 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
74 class LazyImporter(object): |
| 37104 | 75 def __init__(self, module_name): |
| 76 self.__name__ = 'email.' + module_name | |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
77 |
| 37104 | 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) | |
|
37078
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
83 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
84 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
85 _LOWERNAMES = [ |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
86 # email.<old name> -> email.<new name is lowercased old name> |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
87 'Charset', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
88 'Encoders', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
89 'Errors', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
90 'FeedParser', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
91 'Generator', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
92 'Header', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
93 'Iterators', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
94 'Message', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
95 'Parser', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
96 'Utils', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
97 'base64MIME', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
98 'quopriMIME', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
99 ] |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
100 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
101 _MIMENAMES = [ |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
102 # email.MIME<old name> -> email.mime.<new name is lowercased old name> |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
103 'Audio', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
104 'Base', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
105 'Image', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
106 'Message', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
107 'Multipart', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
108 'NonMultipart', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
109 'Text', |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
110 ] |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
111 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
112 for _name in _LOWERNAMES: |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
113 importer = LazyImporter(_name.lower()) |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
114 sys.modules['email.' + _name] = importer |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
115 setattr(sys.modules['email'], _name, importer) |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
116 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
117 |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
118 import email.mime |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
119 for _name in _MIMENAMES: |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
120 importer = LazyImporter('mime.' + _name.lower()) |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
121 sys.modules['email.MIME' + _name] = importer |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
122 setattr(sys.modules['email'], 'MIME' + _name, importer) |
|
3f90a93ff5d0
Merge email package 4.0 from the sandbox, including documentation, test cases,
Barry Warsaw <barry@python.org>
parents:
36311
diff
changeset
|
123 setattr(sys.modules['email.mime'], _name, importer) |
