Use absolute import paths for intrapackage imports.

Use MIMENonMultipart as the base class so that you can't attach() to
these non-multipart message types.
This commit is contained in:
Barry Warsaw 2002-06-02 19:05:08 +00:00
parent 7dc865ad72
commit 524af6f382
5 changed files with 23 additions and 22 deletions

View File

@ -6,9 +6,9 @@
import sndhdr import sndhdr
from cStringIO import StringIO from cStringIO import StringIO
import MIMEBase from email import Errors
import Errors from email import Encoders
import Encoders from email.MIMENonMultipart import MIMENonMultipart
@ -37,7 +37,7 @@ def _whatsnd(data):
class MIMEAudio(MIMEBase.MIMEBase): class MIMEAudio(MIMENonMultipart):
"""Class for generating audio/* MIME documents.""" """Class for generating audio/* MIME documents."""
def __init__(self, _audiodata, _subtype=None, def __init__(self, _audiodata, _subtype=None,
@ -66,6 +66,6 @@ class MIMEAudio(MIMEBase.MIMEBase):
_subtype = _whatsnd(_audiodata) _subtype = _whatsnd(_audiodata)
if _subtype is None: if _subtype is None:
raise TypeError, 'Could not find audio MIME subtype' raise TypeError, 'Could not find audio MIME subtype'
MIMEBase.MIMEBase.__init__(self, 'audio', _subtype, **_params) MIMENonMultipart.__init__(self, 'audio', _subtype, **_params)
self.set_payload(_audiodata) self.set_payload(_audiodata)
_encoder(self) _encoder(self)

View File

@ -4,7 +4,7 @@
"""Base class for MIME specializations. """Base class for MIME specializations.
""" """
import Message from email import Message

View File

@ -6,14 +6,13 @@
import imghdr import imghdr
# Intrapackage imports from email import Errors
import MIMEBase from email import Encoders
import Errors from email.MIMENonMultipart import MIMENonMultipart
import Encoders
class MIMEImage(MIMEBase.MIMEBase): class MIMEImage(MIMENonMultipart):
"""Class for generating image/* type MIME documents.""" """Class for generating image/* type MIME documents."""
def __init__(self, _imagedata, _subtype=None, def __init__(self, _imagedata, _subtype=None,
@ -41,6 +40,6 @@ class MIMEImage(MIMEBase.MIMEBase):
_subtype = imghdr.what(None, _imagedata) _subtype = imghdr.what(None, _imagedata)
if _subtype is None: if _subtype is None:
raise TypeError, 'Could not guess image MIME subtype' raise TypeError, 'Could not guess image MIME subtype'
MIMEBase.MIMEBase.__init__(self, 'image', _subtype, **_params) MIMENonMultipart.__init__(self, 'image', _subtype, **_params)
self.set_payload(_imagedata) self.set_payload(_imagedata)
_encoder(self) _encoder(self)

View File

@ -4,12 +4,12 @@
"""Class representing message/* MIME documents. """Class representing message/* MIME documents.
""" """
import Message from email import Message
import MIMEBase from email.MIMENonMultipart import MIMENonMultipart
class MIMEMessage(MIMEBase.MIMEBase): class MIMEMessage(MIMENonMultipart):
"""Class representing message/* MIME documents.""" """Class representing message/* MIME documents."""
def __init__(self, _msg, _subtype='rfc822'): def __init__(self, _msg, _subtype='rfc822'):
@ -22,7 +22,9 @@ class MIMEMessage(MIMEBase.MIMEBase):
default is "rfc822" (this is defined by the MIME standard, even though default is "rfc822" (this is defined by the MIME standard, even though
the term "rfc822" is technically outdated by RFC 2822). the term "rfc822" is technically outdated by RFC 2822).
""" """
MIMEBase.MIMEBase.__init__(self, 'message', _subtype) MIMENonMultipart.__init__(self, 'message', _subtype)
if not isinstance(_msg, Message.Message): if not isinstance(_msg, Message.Message):
raise TypeError, 'Argument is not an instance of Message' raise TypeError, 'Argument is not an instance of Message'
self.set_payload(_msg) # It's convenient to use this base class method. We need to do it
# this way or we'll get an exception
Message.Message.attach(self, _msg)

View File

@ -5,12 +5,12 @@
""" """
import warnings import warnings
import MIMEBase from email.MIMENonMultipart import MIMENonMultipart
from Encoders import encode_7or8bit from email.Encoders import encode_7or8bit
class MIMEText(MIMEBase.MIMEBase): class MIMEText(MIMENonMultipart):
"""Class for generating text/* type MIME documents.""" """Class for generating text/* type MIME documents."""
def __init__(self, _text, _subtype='plain', _charset='us-ascii', def __init__(self, _text, _subtype='plain', _charset='us-ascii',
@ -33,8 +33,8 @@ class MIMEText(MIMEBase.MIMEBase):
override any header settings indicated by _charset. This is probably override any header settings indicated by _charset. This is probably
not what you want. not what you want.
""" """
MIMEBase.MIMEBase.__init__(self, 'text', _subtype, MIMENonMultipart.__init__(self, 'text', _subtype,
**{'charset': _charset}) **{'charset': _charset})
if _text and _text[-1] <> '\n': if _text and _text[-1] <> '\n':
_text += '\n' _text += '\n'
self.set_payload(_text, _charset) self.set_payload(_text, _charset)