mirror of https://github.com/python/cpython.git
flatten(): Renamed from __call__() which is (silently) deprecated.
__call__() can be 2-3x slower than the equivalent normal method. _handle_message(): The structure of message/rfc822 message has changed. Now parent's payload is a list of length 1, and the zeroth element is the Message sub-object. Adjust the printing of such message trees to reflect this change.
This commit is contained in:
parent
ff49279f7c
commit
7dc865ad72
|
@ -60,7 +60,7 @@ def write(self, s):
|
||||||
# Just delegate to the file object
|
# Just delegate to the file object
|
||||||
self._fp.write(s)
|
self._fp.write(s)
|
||||||
|
|
||||||
def __call__(self, msg, unixfrom=0):
|
def flatten(self, msg, unixfrom=0):
|
||||||
"""Print the message object tree rooted at msg to the output file
|
"""Print the message object tree rooted at msg to the output file
|
||||||
specified when the Generator instance was created.
|
specified when the Generator instance was created.
|
||||||
|
|
||||||
|
@ -78,6 +78,9 @@ def __call__(self, msg, unixfrom=0):
|
||||||
print >> self._fp, ufrom
|
print >> self._fp, ufrom
|
||||||
self._write(msg)
|
self._write(msg)
|
||||||
|
|
||||||
|
# For backwards compatibility, but this is slower
|
||||||
|
__call__ = flatten
|
||||||
|
|
||||||
#
|
#
|
||||||
# Protected interface - undocumented ;/
|
# Protected interface - undocumented ;/
|
||||||
#
|
#
|
||||||
|
@ -254,7 +257,7 @@ def _handle_multipart(self, msg, isdigest=0):
|
||||||
for part in subparts:
|
for part in subparts:
|
||||||
s = StringIO()
|
s = StringIO()
|
||||||
g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
|
g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
|
||||||
g(part, unixfrom=0)
|
g.flatten(part, unixfrom=0)
|
||||||
msgtexts.append(s.getvalue())
|
msgtexts.append(s.getvalue())
|
||||||
# Now make sure the boundary we've selected doesn't appear in any of
|
# Now make sure the boundary we've selected doesn't appear in any of
|
||||||
# the message texts.
|
# the message texts.
|
||||||
|
@ -302,7 +305,7 @@ def _handle_message_delivery_status(self, msg):
|
||||||
for part in msg.get_payload():
|
for part in msg.get_payload():
|
||||||
s = StringIO()
|
s = StringIO()
|
||||||
g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
|
g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
|
||||||
g(part, unixfrom=0)
|
g.flatten(part, unixfrom=0)
|
||||||
text = s.getvalue()
|
text = s.getvalue()
|
||||||
lines = text.split('\n')
|
lines = text.split('\n')
|
||||||
# Strip off the unnecessary trailing empty line
|
# Strip off the unnecessary trailing empty line
|
||||||
|
@ -318,10 +321,11 @@ def _handle_message_delivery_status(self, msg):
|
||||||
def _handle_message(self, msg):
|
def _handle_message(self, msg):
|
||||||
s = StringIO()
|
s = StringIO()
|
||||||
g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
|
g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
|
||||||
# A message/rfc822 should contain a scalar payload which is another
|
# The payload of a message/rfc822 part should be a multipart sequence
|
||||||
# Message object. Extract that object, stringify it, and write that
|
# of length 1. The zeroth element of the list should be the Message
|
||||||
# out.
|
# object for the subpart.Extract that object, stringify it, and write
|
||||||
g(msg.get_payload(), unixfrom=0)
|
# that out.
|
||||||
|
g.flatten(msg.get_payload(0), unixfrom=0)
|
||||||
self._fp.write(s.getvalue())
|
self._fp.write(s.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue