diff options
author | Mariatta Wijaya <mariatta.wijaya@gmail.com> | 2017-02-06 20:16:58 -0800 |
---|---|---|
committer | Mariatta Wijaya <mariatta.wijaya@gmail.com> | 2017-02-06 20:16:58 -0800 |
commit | da79bcf8ac7ae72218ab023e1ed54390bc1a3a27 (patch) | |
tree | 74845e2dbd9521d9748b9c32f1922f4123083bf3 /Lib/email/mime | |
parent | e3c7e835bdfc97750eb9b7fc0ad2493108c2d438 (diff) | |
parent | 1fe806ac56f8b83694d24ab604eb695d00bc8497 (diff) | |
download | cpython-da79bcf8ac7ae72218ab023e1ed54390bc1a3a27.tar.gz |
Issue #29371: merge with 3.5
Diffstat (limited to 'Lib/email/mime')
-rw-r--r-- | Lib/email/mime/application.py | 5 | ||||
-rw-r--r-- | Lib/email/mime/audio.py | 5 | ||||
-rw-r--r-- | Lib/email/mime/base.py | 8 | ||||
-rw-r--r-- | Lib/email/mime/image.py | 5 | ||||
-rw-r--r-- | Lib/email/mime/message.py | 4 | ||||
-rw-r--r-- | Lib/email/mime/multipart.py | 3 | ||||
-rw-r--r-- | Lib/email/mime/text.py | 4 |
7 files changed, 21 insertions, 13 deletions
diff --git a/Lib/email/mime/application.py b/Lib/email/mime/application.py index f5c5905564..6877e554e1 100644 --- a/Lib/email/mime/application.py +++ b/Lib/email/mime/application.py @@ -14,7 +14,7 @@ class MIMEApplication(MIMENonMultipart): """Class for generating application/* MIME documents.""" def __init__(self, _data, _subtype='octet-stream', - _encoder=encoders.encode_base64, **_params): + _encoder=encoders.encode_base64, *, policy=None, **_params): """Create an application/* type MIME document. _data is a string containing the raw application data. @@ -31,6 +31,7 @@ class MIMEApplication(MIMENonMultipart): """ if _subtype is None: raise TypeError('Invalid application MIME subtype') - MIMENonMultipart.__init__(self, 'application', _subtype, **_params) + MIMENonMultipart.__init__(self, 'application', _subtype, policy=policy, + **_params) self.set_payload(_data) _encoder(self) diff --git a/Lib/email/mime/audio.py b/Lib/email/mime/audio.py index fbc118951a..4bcd7b224a 100644 --- a/Lib/email/mime/audio.py +++ b/Lib/email/mime/audio.py @@ -43,7 +43,7 @@ class MIMEAudio(MIMENonMultipart): """Class for generating audio/* MIME documents.""" def __init__(self, _audiodata, _subtype=None, - _encoder=encoders.encode_base64, **_params): + _encoder=encoders.encode_base64, *, policy=None, **_params): """Create an audio/* type MIME document. _audiodata is a string containing the raw audio data. If this data @@ -68,6 +68,7 @@ class MIMEAudio(MIMENonMultipart): _subtype = _whatsnd(_audiodata) if _subtype is None: raise TypeError('Could not find audio MIME subtype') - MIMENonMultipart.__init__(self, 'audio', _subtype, **_params) + MIMENonMultipart.__init__(self, 'audio', _subtype, policy=policy, + **_params) self.set_payload(_audiodata) _encoder(self) diff --git a/Lib/email/mime/base.py b/Lib/email/mime/base.py index ac919258b1..1a3f9b51f6 100644 --- a/Lib/email/mime/base.py +++ b/Lib/email/mime/base.py @@ -6,6 +6,8 @@ __all__ = ['MIMEBase'] +import email.policy + from email import message @@ -13,14 +15,16 @@ from email import message class MIMEBase(message.Message): """Base class for MIME specializations.""" - def __init__(self, _maintype, _subtype, **_params): + def __init__(self, _maintype, _subtype, *, policy=None, **_params): """This constructor adds a Content-Type: and a MIME-Version: header. The Content-Type: header is taken from the _maintype and _subtype arguments. Additional parameters for this header are taken from the keyword arguments. """ - message.Message.__init__(self) + if policy is None: + policy = email.policy.compat32 + message.Message.__init__(self, policy=policy) ctype = '%s/%s' % (_maintype, _subtype) self.add_header('Content-Type', ctype, **_params) self['MIME-Version'] = '1.0' diff --git a/Lib/email/mime/image.py b/Lib/email/mime/image.py index 5563823239..92724643cd 100644 --- a/Lib/email/mime/image.py +++ b/Lib/email/mime/image.py @@ -17,7 +17,7 @@ class MIMEImage(MIMENonMultipart): """Class for generating image/* type MIME documents.""" def __init__(self, _imagedata, _subtype=None, - _encoder=encoders.encode_base64, **_params): + _encoder=encoders.encode_base64, *, policy=None, **_params): """Create an image/* type MIME document. _imagedata is a string containing the raw image data. If this data @@ -41,6 +41,7 @@ class MIMEImage(MIMENonMultipart): _subtype = imghdr.what(None, _imagedata) if _subtype is None: raise TypeError('Could not guess image MIME subtype') - MIMENonMultipart.__init__(self, 'image', _subtype, **_params) + MIMENonMultipart.__init__(self, 'image', _subtype, policy=policy, + **_params) self.set_payload(_imagedata) _encoder(self) diff --git a/Lib/email/mime/message.py b/Lib/email/mime/message.py index 275dbfd088..07e4f2d119 100644 --- a/Lib/email/mime/message.py +++ b/Lib/email/mime/message.py @@ -14,7 +14,7 @@ from email.mime.nonmultipart import MIMENonMultipart class MIMEMessage(MIMENonMultipart): """Class representing message/* MIME documents.""" - def __init__(self, _msg, _subtype='rfc822'): + def __init__(self, _msg, _subtype='rfc822', *, policy=None): """Create a message/* type MIME document. _msg is a message object and must be an instance of Message, or a @@ -24,7 +24,7 @@ class MIMEMessage(MIMENonMultipart): default is "rfc822" (this is defined by the MIME standard, even though the term "rfc822" is technically outdated by RFC 2822). """ - MIMENonMultipart.__init__(self, 'message', _subtype) + MIMENonMultipart.__init__(self, 'message', _subtype, policy=policy) if not isinstance(_msg, message.Message): raise TypeError('Argument is not an instance of Message') # It's convenient to use this base class method. We need to do it diff --git a/Lib/email/mime/multipart.py b/Lib/email/mime/multipart.py index 96618650c5..2d3f288810 100644 --- a/Lib/email/mime/multipart.py +++ b/Lib/email/mime/multipart.py @@ -14,6 +14,7 @@ class MIMEMultipart(MIMEBase): """Base class for MIME multipart/* type messages.""" def __init__(self, _subtype='mixed', boundary=None, _subparts=None, + *, policy=None, **_params): """Creates a multipart/* type message. @@ -33,7 +34,7 @@ class MIMEMultipart(MIMEBase): Additional parameters for the Content-Type header are taken from the keyword arguments (or passed into the _params argument). """ - MIMEBase.__init__(self, 'multipart', _subtype, **_params) + MIMEBase.__init__(self, 'multipart', _subtype, policy=policy, **_params) # Initialise _payload to an empty list as the Message superclass's # implementation of is_multipart assumes that _payload is a list for diff --git a/Lib/email/mime/text.py b/Lib/email/mime/text.py index da03086ee8..35b4423830 100644 --- a/Lib/email/mime/text.py +++ b/Lib/email/mime/text.py @@ -14,7 +14,7 @@ from email.mime.nonmultipart import MIMENonMultipart class MIMEText(MIMENonMultipart): """Class for generating text/* type MIME documents.""" - def __init__(self, _text, _subtype='plain', _charset=None): + def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None): """Create a text/* type MIME document. _text is the string for this message object. @@ -36,7 +36,7 @@ class MIMEText(MIMENonMultipart): except UnicodeEncodeError: _charset = 'utf-8' - MIMENonMultipart.__init__(self, 'text', _subtype, + MIMENonMultipart.__init__(self, 'text', _subtype, policy=policy, **{'charset': str(_charset)}) self.set_payload(_text, _charset) |