1 | n/a | # Copyright (C) 2001-2007 Python Software Foundation |
---|
2 | n/a | # Author: Barry Warsaw |
---|
3 | n/a | # Contact: email-sig@python.org |
---|
4 | n/a | |
---|
5 | n/a | """A package for parsing, handling, and generating email messages.""" |
---|
6 | n/a | |
---|
7 | n/a | __all__ = [ |
---|
8 | n/a | 'base64mime', |
---|
9 | n/a | 'charset', |
---|
10 | n/a | 'encoders', |
---|
11 | n/a | 'errors', |
---|
12 | n/a | 'feedparser', |
---|
13 | n/a | 'generator', |
---|
14 | n/a | 'header', |
---|
15 | n/a | 'iterators', |
---|
16 | n/a | 'message', |
---|
17 | n/a | 'message_from_file', |
---|
18 | n/a | 'message_from_binary_file', |
---|
19 | n/a | 'message_from_string', |
---|
20 | n/a | 'message_from_bytes', |
---|
21 | n/a | 'mime', |
---|
22 | n/a | 'parser', |
---|
23 | n/a | 'quoprimime', |
---|
24 | n/a | 'utils', |
---|
25 | n/a | ] |
---|
26 | n/a | |
---|
27 | n/a | |
---|
28 | n/a | |
---|
29 | n/a | # Some convenience routines. Don't import Parser and Message as side-effects |
---|
30 | n/a | # of importing email since those cascadingly import most of the rest of the |
---|
31 | n/a | # email package. |
---|
32 | n/a | def message_from_string(s, *args, **kws): |
---|
33 | n/a | """Parse a string into a Message object model. |
---|
34 | n/a | |
---|
35 | n/a | Optional _class and strict are passed to the Parser constructor. |
---|
36 | n/a | """ |
---|
37 | n/a | from email.parser import Parser |
---|
38 | n/a | return Parser(*args, **kws).parsestr(s) |
---|
39 | n/a | |
---|
40 | n/a | def message_from_bytes(s, *args, **kws): |
---|
41 | n/a | """Parse a bytes string into a Message object model. |
---|
42 | n/a | |
---|
43 | n/a | Optional _class and strict are passed to the Parser constructor. |
---|
44 | n/a | """ |
---|
45 | n/a | from email.parser import BytesParser |
---|
46 | n/a | return BytesParser(*args, **kws).parsebytes(s) |
---|
47 | n/a | |
---|
48 | n/a | def message_from_file(fp, *args, **kws): |
---|
49 | n/a | """Read a file and parse its contents into a Message object model. |
---|
50 | n/a | |
---|
51 | n/a | Optional _class and strict are passed to the Parser constructor. |
---|
52 | n/a | """ |
---|
53 | n/a | from email.parser import Parser |
---|
54 | n/a | return Parser(*args, **kws).parse(fp) |
---|
55 | n/a | |
---|
56 | n/a | def message_from_binary_file(fp, *args, **kws): |
---|
57 | n/a | """Read a binary file and parse its contents into a Message object model. |
---|
58 | n/a | |
---|
59 | n/a | Optional _class and strict are passed to the Parser constructor. |
---|
60 | n/a | """ |
---|
61 | n/a | from email.parser import BytesParser |
---|
62 | n/a | return BytesParser(*args, **kws).parse(fp) |
---|