Big email 3.0 API changes, with updated unit tests and documentation.
Briefly (from the NEWS file):
- Updates for the email package:
+ All deprecated APIs that in email 2.x issued warnings have been removed:
_encoder argument to the MIMEText constructor, Message.add_payload(),
Utils.dump_address_pair(), Utils.decode(), Utils.encode()
+ New deprecations: Generator.__call__(), Message.get_type(),
Message.get_main_type(), Message.get_subtype(), the 'strict' argument to
the Parser constructor. These will be removed in email 3.1.
+ Support for Python earlier than 2.3 has been removed (see PEP 291).
+ All defect classes have been renamed to end in 'Defect'.
+ Some FeedParser fixes; also a MultipartInvariantViolationDefect will be
added to messages that claim to be multipart but really aren't.
+ Updates to documentation.
diff --git a/Lib/email/Generator.py b/Lib/email/Generator.py
index 7fe634f..9411a9e 100644
--- a/Lib/email/Generator.py
+++ b/Lib/email/Generator.py
@@ -1,13 +1,14 @@
# Copyright (C) 2001-2004 Python Software Foundation
-# Author: barry@python.org (Barry Warsaw)
+# Author: Barry Warsaw
+# Contact: email-sig@python.org
-"""Classes to generate plain text from a message object tree.
-"""
+"""Classes to generate plain text from a message object tree."""
import re
import sys
import time
import random
+import warnings
from cStringIO import StringIO
from email.Header import Header
@@ -81,7 +82,10 @@
self._write(msg)
# For backwards compatibility, but this is slower
- __call__ = flatten
+ def __call__(self, msg, unixfrom=False):
+ warnings.warn('__call__() deprecated; use flatten()',
+ DeprecationWarning, 2)
+ self.flatten(msg, unixfrom)
def clone(self, fp):
"""Clone this generator with the exact same options."""
@@ -175,7 +179,7 @@
if cset is not None:
payload = cset.body_encode(payload)
if not isinstance(payload, basestring):
- raise TypeError, 'string payload expected: %s' % type(payload)
+ raise TypeError('string payload expected: %s' % type(payload))
if self._mangle_from_:
payload = fcre.sub('>From ', payload)
self._fp.write(payload)
@@ -271,6 +275,8 @@
+_FMT = '[Non-text (%(type)s) part of message omitted, filename %(filename)s]'
+
class DecodedGenerator(Generator):
"""Generator a text representation of a message.
@@ -301,13 +307,13 @@
"""
Generator.__init__(self, outfp, mangle_from_, maxheaderlen)
if fmt is None:
- fmt = ('[Non-text (%(type)s) part of message omitted, '
- 'filename %(filename)s]')
- self._fmt = fmt
+ self._fmt = _FMT
+ else:
+ self._fmt = fmt
def _dispatch(self, msg):
for part in msg.walk():
- maintype = part.get_main_type('text')
+ maintype = part.get_content_maintype()
if maintype == 'text':
print >> self, part.get_payload(decode=True)
elif maintype == 'multipart':
@@ -315,9 +321,9 @@
pass
else:
print >> self, self._fmt % {
- 'type' : part.get_type('[no MIME type]'),
- 'maintype' : part.get_main_type('[no main MIME type]'),
- 'subtype' : part.get_subtype('[no sub-MIME type]'),
+ 'type' : part.get_content_type(),
+ 'maintype' : part.get_content_maintype(),
+ 'subtype' : part.get_content_subtype(),
'filename' : part.get_filename('[no filename]'),
'description': part.get('Content-Description',
'[no description]'),