Image.py and class Image => MIMEImage.py and MIMEImage

Text.py and class Text => MIMEText.py and MIMEText

MessageRFC822.py and class MessageRFC822 => MIMEMessage.py and MIMEMessage

These are renamed so as to be more consistent; these are MIME specific
derived classes for when creating the object model out of whole cloth.
This commit is contained in:
Barry Warsaw 2001-09-26 05:34:30 +00:00
parent b384e01796
commit 3dd978dfff
4 changed files with 40 additions and 36 deletions

View File

@ -13,17 +13,17 @@ import Encoders
class Image(MIMEBase.MIMEBase):
class MIMEImage(MIMEBase.MIMEBase):
"""Class for generating image/* type MIME documents."""
def __init__(self, _imagedata, _minor=None,
def __init__(self, _imagedata, _subtype=None,
_encoder=Encoders.encode_base64, **_params):
"""Create an image/* type MIME document.
_imagedata is a string containing the raw image data. If this data
can be decoded by the standard Python `imghdr' module, then the
subtype will be automatically included in the Content-Type: header.
Otherwise, you can specify the specific image subtype via the _minor
Otherwise, you can specify the specific image subtype via the _subtype
parameter.
_encoder is a function which will perform the actual encoding for
@ -37,10 +37,10 @@ class Image(MIMEBase.MIMEBase):
constructor, which turns them into parameters on the Content-Type:
header.
"""
if _minor is None:
_minor = imghdr.what(None, _imagedata)
if _minor is None:
raise TypeError, 'Could not guess image _minor type'
MIMEBase.MIMEBase.__init__(self, 'image', _minor, **_params)
if _subtype is None:
_subtype = imghdr.what(None, _imagedata)
if _subtype is None:
raise TypeError, 'Could not guess image MIME subtype'
MIMEBase.MIMEBase.__init__(self, 'image', _subtype, **_params)
self.set_payload(_imagedata)
_encoder(self)

28
Lib/email/MIMEMessage.py Normal file
View File

@ -0,0 +1,28 @@
# Copyright (C) 2001 Python Software Foundation
# Author: barry@zope.com (Barry Warsaw)
"""Class representing message/* MIME documents.
"""
import Message
import MIMEBase
class MIMEMessage(MIMEBase.MIMEBase):
"""Class representing message/* MIME documents."""
def __init__(self, _msg, _subtype='rfc822'):
"""Create a message/* type MIME document.
_msg is a message object and must be an instance of Message, or a
derived class of Message, otherwise a TypeError is raised.
Optional _subtype defines the subtype of the contained message. The
default is "rfc822" (this is defined by the MIME standard, even though
the term "rfc822" is technically outdated by RFC 2822).
"""
MIMEBase.MIMEBase.__init__(self, 'message', _subtype)
if not isinstance(_msg, Message.Message):
raise TypeError, 'Argument is not an instance of Message'
self.set_payload(_msg)

View File

@ -9,17 +9,17 @@ from Encoders import encode_7or8bit
class Text(MIMEBase.MIMEBase):
class MIMEText(MIMEBase.MIMEBase):
"""Class for generating text/* type MIME documents."""
def __init__(self, _text, _minor='plain', _charset='us-ascii',
def __init__(self, _text, _subtype='plain', _charset='us-ascii',
_encoder=encode_7or8bit):
"""Create a text/* type MIME document.
_text is the string for this message object. If the text does not end
in a newline, one is added.
_minor is the minor content type, defaulting to "plain".
_subtype is the MIME sub content type, defaulting to "plain".
_charset is the character set parameter added to the Content-Type:
header. This defaults to "us-ascii".
@ -33,7 +33,7 @@ class Text(MIMEBase.MIMEBase):
but it does set Content-Transfer-Encoding: to either `7bit' or `8bit'
as appropriate.
"""
MIMEBase.MIMEBase.__init__(self, 'text', _minor,
MIMEBase.MIMEBase.__init__(self, 'text', _subtype,
**{'charset': _charset})
if _text and _text[-1] <> '\n':
_text += '\n'

View File

@ -1,24 +0,0 @@
# Copyright (C) 2001 Python Software Foundation
# Author: barry@zope.com (Barry Warsaw)
"""Class for generating message/rfc822 MIME documents.
"""
import Message
import MIMEBase
class MessageRFC822(MIMEBase.MIMEBase):
"""Class for generating message/rfc822 MIME documents."""
def __init__(self, _msg):
"""Create a message/rfc822 type MIME document.
_msg is a message object and must be an instance of Message, or a
derived class of Message, otherwise a TypeError is raised.
"""
MIMEBase.MIMEBase.__init__(self, 'message', 'rfc822')
if not isinstance(_msg, Message.Message):
raise TypeError, 'Argument is not an instance of Message'
self.set_payload(_msg)