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