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