• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2001-2007 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__all__ = [
8    'base64mime',
9    'charset',
10    'encoders',
11    'errors',
12    'feedparser',
13    'generator',
14    'header',
15    'iterators',
16    'message',
17    'message_from_file',
18    'message_from_binary_file',
19    'message_from_string',
20    'message_from_bytes',
21    'mime',
22    'parser',
23    'quoprimime',
24    'utils',
25    ]
26
27
28
29# Some convenience routines.  Don't import Parser and Message as side-effects
30# of importing email since those cascadingly import most of the rest of the
31# email package.
32def message_from_string(s, *args, **kws):
33    """Parse a string into a Message object model.
34
35    Optional _class and strict are passed to the Parser constructor.
36    """
37    from email.parser import Parser
38    return Parser(*args, **kws).parsestr(s)
39
40def message_from_bytes(s, *args, **kws):
41    """Parse a bytes string into a Message object model.
42
43    Optional _class and strict are passed to the Parser constructor.
44    """
45    from email.parser import BytesParser
46    return BytesParser(*args, **kws).parsebytes(s)
47
48def message_from_file(fp, *args, **kws):
49    """Read a file and parse its contents into a Message object model.
50
51    Optional _class and strict are passed to the Parser constructor.
52    """
53    from email.parser import Parser
54    return Parser(*args, **kws).parse(fp)
55
56def message_from_binary_file(fp, *args, **kws):
57    """Read a binary file and parse its contents into a Message object model.
58
59    Optional _class and strict are passed to the Parser constructor.
60    """
61    from email.parser import BytesParser
62    return BytesParser(*args, **kws).parse(fp)
63