(root)/
Python-3.12.0/
Lib/
email/
__init__.py
       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  # Some convenience routines.  Don't import Parser and Message as side-effects
      29  # of importing email since those cascadingly import most of the rest of the
      30  # email package.
      31  def message_from_string(s, *args, **kws):
      32      """Parse a string into a Message object model.
      33  
      34      Optional _class and strict are passed to the Parser constructor.
      35      """
      36      from email.parser import Parser
      37      return Parser(*args, **kws).parsestr(s)
      38  
      39  def message_from_bytes(s, *args, **kws):
      40      """Parse a bytes string into a Message object model.
      41  
      42      Optional _class and strict are passed to the Parser constructor.
      43      """
      44      from email.parser import BytesParser
      45      return BytesParser(*args, **kws).parsebytes(s)
      46  
      47  def message_from_file(fp, *args, **kws):
      48      """Read a file and parse its contents into a Message object model.
      49  
      50      Optional _class and strict are passed to the Parser constructor.
      51      """
      52      from email.parser import Parser
      53      return Parser(*args, **kws).parse(fp)
      54  
      55  def message_from_binary_file(fp, *args, **kws):
      56      """Read a binary file and parse its contents into a Message object model.
      57  
      58      Optional _class and strict are passed to the Parser constructor.
      59      """
      60      from email.parser import BytesParser
      61      return BytesParser(*args, **kws).parse(fp)