[Python-checkins] CVS: python/dist/src/Lib/email MIMEImage.py,NONE,1.1 MIMEMessage.py,NONE,1.1 MIMEText.py,NONE,1.1 Image.py,1.1,NONE MessageRFC822.py,1.1,NONE Text.py,1.1,NONE

Barry Warsaw bwarsaw@users.sourceforge.net
Tue, 25 Sep 2001 22:34:32 -0700


Update of /cvsroot/python/python/dist/src/Lib/email
In directory usw-pr-cvs1:/tmp/cvs-serv27400

Added Files:
	MIMEImage.py MIMEMessage.py MIMEText.py 
Removed Files:
	Image.py MessageRFC822.py Text.py 
Log Message:
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.


--- NEW FILE: MIMEImage.py ---
# Copyright (C) 2001 Python Software Foundation
# Author: barry@zope.com (Barry Warsaw)

"""Class representing image/* type MIME documents.
"""

import imghdr

# Intrapackage imports
import MIMEBase
import Errors
import Encoders



class MIMEImage(MIMEBase.MIMEBase):
    """Class for generating image/* type MIME documents."""

    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 _subtype
        parameter.

        _encoder is a function which will perform the actual encoding for
        transport of the image data.  It takes one argument, which is this
        Image instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding: or other headers to the message as
        necessary.  The default encoding is Base64.

        Any additional keyword arguments are passed to the base class
        constructor, which turns them into parameters on the Content-Type:
        header.
        """
        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)

--- NEW FILE: MIMEMessage.py ---
# 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)

--- NEW FILE: MIMEText.py ---
# Copyright (C) 2001 Python Software Foundation
# Author: barry@zope.com (Barry Warsaw)

"""Class representing text/* type MIME documents.
"""

import MIMEBase
from Encoders import encode_7or8bit



class MIMEText(MIMEBase.MIMEBase):
    """Class for generating text/* type MIME documents."""

    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.

        _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".

        _encoder is a function which will perform the actual encoding for
        transport of the text data.  It takes one argument, which is this
        Text instance.  It should use get_payload() and set_payload() to
        change the payload to the encoded form.  It should also add any
        Content-Transfer-Encoding: or other headers to the message as
        necessary.  The default encoding doesn't actually modify the payload,
        but it does set Content-Transfer-Encoding: to either `7bit' or `8bit'
        as appropriate.
        """
        MIMEBase.MIMEBase.__init__(self, 'text', _subtype,
                                   **{'charset': _charset})
        if _text and _text[-1] <> '\n':
            _text += '\n'
        self.set_payload(_text)
        _encoder(self)

--- Image.py DELETED ---

--- MessageRFC822.py DELETED ---

--- Text.py DELETED ---