base.py 914 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2001-2006 Python Software Foundation
  2. # Author: Barry Warsaw
  3. # Contact: email-sig@python.org
  4. """Base class for MIME specializations."""
  5. __all__ = ['MIMEBase']
  6. import email.policy
  7. from email import message
  8. class MIMEBase(message.Message):
  9. """Base class for MIME specializations."""
  10. def __init__(self, _maintype, _subtype, *, policy=None, **_params):
  11. """This constructor adds a Content-Type: and a MIME-Version: header.
  12. The Content-Type: header is taken from the _maintype and _subtype
  13. arguments. Additional parameters for this header are taken from the
  14. keyword arguments.
  15. """
  16. if policy is None:
  17. policy = email.policy.compat32
  18. message.Message.__init__(self, policy=policy)
  19. ctype = '%s/%s' % (_maintype, _subtype)
  20. self.add_header('Content-Type', ctype, **_params)
  21. self['MIME-Version'] = '1.0'