__init__.py 1.7 KB

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