PyXR

c:\python24\lib \ email \ MIMEImage.py



0001 # Copyright (C) 2001-2004 Python Software Foundation
0002 # Author: Barry Warsaw
0003 # Contact: email-sig@python.org
0004 
0005 """Class representing image/* type MIME documents."""
0006 
0007 import imghdr
0008 
0009 from email import Errors
0010 from email import Encoders
0011 from email.MIMENonMultipart import MIMENonMultipart
0012 
0013 
0014 
0015 class MIMEImage(MIMENonMultipart):
0016     """Class for generating image/* type MIME documents."""
0017 
0018     def __init__(self, _imagedata, _subtype=None,
0019                  _encoder=Encoders.encode_base64, **_params):
0020         """Create an image/* type MIME document.
0021 
0022         _imagedata is a string containing the raw image data.  If this data
0023         can be decoded by the standard Python `imghdr' module, then the
0024         subtype will be automatically included in the Content-Type header.
0025         Otherwise, you can specify the specific image subtype via the _subtype
0026         parameter.
0027 
0028         _encoder is a function which will perform the actual encoding for
0029         transport of the image data.  It takes one argument, which is this
0030         Image instance.  It should use get_payload() and set_payload() to
0031         change the payload to the encoded form.  It should also add any
0032         Content-Transfer-Encoding or other headers to the message as
0033         necessary.  The default encoding is Base64.
0034 
0035         Any additional keyword arguments are passed to the base class
0036         constructor, which turns them into parameters on the Content-Type
0037         header.
0038         """
0039         if _subtype is None:
0040             _subtype = imghdr.what(None, _imagedata)
0041         if _subtype is None:
0042             raise TypeError('Could not guess image MIME subtype')
0043         MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
0044         self.set_payload(_imagedata)
0045         _encoder(self)
0046 

Generated by PyXR 0.9.4
SourceForge.net Logo