blob: f5c5905564f690dc36a5d8afef5958bc0283281f [file] [log] [blame]
Barry Warsaw40ef0062006-03-18 15:41:53 +00001# 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
9from email import encoders
10from email.mime.nonmultipart import MIMENonMultipart
11
12
13class MIMEApplication(MIMENonMultipart):
14 """Class for generating application/* MIME documents."""
15
16 def __init__(self, _data, _subtype='octet-stream',
17 _encoder=encoders.encode_base64, **_params):
18 """Create an application/* type MIME document.
19
Ezio Melotti24b07bc2011-03-15 18:55:01 +020020 _data is a string containing the raw application data.
Barry Warsaw40ef0062006-03-18 15:41:53 +000021
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, **_params)
35 self.set_payload(_data)
36 _encoder(self)