application.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2001-2006 Python Software Foundation
  2. # Author: Keith Dart
  3. # Contact: email-sig@python.org
  4. """Class representing application/* type MIME documents."""
  5. from __future__ import unicode_literals
  6. from __future__ import division
  7. from __future__ import absolute_import
  8. from future.backports.email import encoders
  9. from future.backports.email.mime.nonmultipart import MIMENonMultipart
  10. __all__ = ["MIMEApplication"]
  11. class MIMEApplication(MIMENonMultipart):
  12. """Class for generating application/* MIME documents."""
  13. def __init__(self, _data, _subtype='octet-stream',
  14. _encoder=encoders.encode_base64, **_params):
  15. """Create an application/* type MIME document.
  16. _data is a string containing the raw application data.
  17. _subtype is the MIME content type subtype, defaulting to
  18. 'octet-stream'.
  19. _encoder is a function which will perform the actual encoding for
  20. transport of the application data, defaulting to base64 encoding.
  21. Any additional keyword arguments are passed to the base class
  22. constructor, which turns them into parameters on the Content-Type
  23. header.
  24. """
  25. if _subtype is None:
  26. raise TypeError('Invalid application MIME subtype')
  27. MIMENonMultipart.__init__(self, 'application', _subtype, **_params)
  28. self.set_payload(_data)
  29. _encoder(self)