[Python-checkins] python/dist/src/Lib/email Generator.py,1.15,1.16
barry@users.sourceforge.net
barry@users.sourceforge.net
2002年9月28日 11:04:57 -0700
Update of /cvsroot/python/python/dist/src/Lib/email
In directory usw-pr-cvs1:/tmp/cvs-serv30402
Modified Files:
Generator.py
Log Message:
Use True/False everywhere.
Index: Generator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Generator.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** Generator.py 10 Sep 2002 16:13:45 -0000 1.15
--- Generator.py 28 Sep 2002 18:04:55 -0000 1.16
***************
*** 19,22 ****
--- 19,27 ----
from email._compat21 import _isstring
+ try:
+ True, False
+ except NameError:
+ True = 1
+ False = 0
EMPTYSTRING = ''
***************
*** 43,47 ****
#
! def __init__(self, outfp, mangle_from_=1, maxheaderlen=78):
"""Create the generator for message flattening.
--- 48,52 ----
#
! def __init__(self, outfp, mangle_from_=True, maxheaderlen=78):
"""Create the generator for message flattening.
***************
*** 49,54 ****
must have a write() method.
! Optional mangle_from_ is a flag that, when true, escapes From_ lines
! in the body of the message by putting a `>' in front of them.
Optional maxheaderlen specifies the longest length for a non-continued
--- 54,60 ----
must have a write() method.
! Optional mangle_from_ is a flag that, when True (the default), escapes
! From_ lines in the body of the message by putting a `>' in front of
! them.
Optional maxheaderlen specifies the longest length for a non-continued
***************
*** 62,66 ****
self._fp = outfp
self._mangle_from_ = mangle_from_
- self.__first = 1
self.__maxheaderlen = maxheaderlen
--- 68,71 ----
***************
*** 69,73 ****
self._fp.write(s)
! def flatten(self, msg, unixfrom=0):
"""Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.
--- 74,78 ----
self._fp.write(s)
! def flatten(self, msg, unixfrom=False):
"""Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.
***************
*** 76,80 ****
before the first object in the message tree. If the original message
has no From_ delimiter, a `standard' one is crafted. By default, this
! is 0 to inhibit the printing of any From_ delimiter.
Note that for subobjects, no From_ line is printed.
--- 81,85 ----
before the first object in the message tree. If the original message
has no From_ delimiter, a `standard' one is crafted. By default, this
! is False to inhibit the printing of any From_ delimiter.
Note that for subobjects, no From_ line is printed.
***************
*** 147,156 ****
def _write_headers(self, msg):
for h, v in msg.items():
- # We only write the MIME-Version: header for the outermost
- # container message. Unfortunately, we can't use same technique
- # as for the Unix-From above because we don't know when
- # MIME-Version: will occur.
- if h.lower() == 'mime-version' and not self.__first:
- continue
# RFC 2822 says that lines SHOULD be no more than maxheaderlen
# characters wide, so we're well within our rights to split long
--- 152,155 ----
***************
*** 158,167 ****
text = '%s: %s' % (h, v)
if self.__maxheaderlen > 0 and len(text) > self.__maxheaderlen:
! text = self._split_header(h, text)
print >> self._fp, text
# A blank line always separates headers from body
print >> self._fp
! def _split_header(self, name, text):
maxheaderlen = self.__maxheaderlen
# Find out whether any lines in the header are really longer than
--- 157,166 ----
text = '%s: %s' % (h, v)
if self.__maxheaderlen > 0 and len(text) > self.__maxheaderlen:
! text = self._split_header(text)
print >> self._fp, text
# A blank line always separates headers from body
print >> self._fp
! def _split_header(self, text):
maxheaderlen = self.__maxheaderlen
# Find out whether any lines in the header are really longer than
***************
*** 226,230 ****
s = StringIO()
g = self.clone(s)
! g.flatten(part, unixfrom=0)
msgtexts.append(s.getvalue())
# Now make sure the boundary we've selected doesn't appear in any of
--- 225,229 ----
s = StringIO()
g = self.clone(s)
! g.flatten(part, unixfrom=False)
msgtexts.append(s.getvalue())
# Now make sure the boundary we've selected doesn't appear in any of
***************
*** 265,269 ****
s = StringIO()
g = self.clone(s)
! g.flatten(part, unixfrom=0)
text = s.getvalue()
lines = text.split('\n')
--- 264,268 ----
s = StringIO()
g = self.clone(s)
! g.flatten(part, unixfrom=False)
text = s.getvalue()
lines = text.split('\n')
***************
*** 285,289 ****
# object for the subpart. Extract that object, stringify it, and
# write it out.
! g.flatten(msg.get_payload(0), unixfrom=0)
self._fp.write(s.getvalue())
--- 284,288 ----
# object for the subpart. Extract that object, stringify it, and
# write it out.
! g.flatten(msg.get_payload(0), unixfrom=False)
self._fp.write(s.getvalue())
***************
*** 296,300 ****
with a format string representing the part.
"""
! def __init__(self, outfp, mangle_from_=1, maxheaderlen=78, fmt=None):
"""Like Generator.__init__() except that an additional optional
argument is allowed.
--- 295,299 ----
with a format string representing the part.
"""
! def __init__(self, outfp, mangle_from_=True, maxheaderlen=78, fmt=None):
"""Like Generator.__init__() except that an additional optional
argument is allowed.
***************
*** 328,332 ****
maintype = part.get_main_type('text')
if maintype == 'text':
! print >> self, part.get_payload(decode=1)
elif maintype == 'multipart':
# Just skip this
--- 327,331 ----
maintype = part.get_main_type('text')
if maintype == 'text':
! print >> self, part.get_payload(decode=True)
elif maintype == 'multipart':
# Just skip this
***************
*** 355,359 ****
b = boundary
counter = 0
! while 1:
cre = re.compile('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
if not cre.search(text):
--- 354,358 ----
b = boundary
counter = 0
! while True:
cre = re.compile('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
if not cre.search(text):