__init__.py 2.2 KB

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