Use True/False everywhere.

This commit is contained in:
Barry Warsaw 2002-09-28 20:44:58 +00:00
parent 4ece778bbc
commit e03e8f09eb
1 changed files with 12 additions and 5 deletions

View File

@ -14,9 +14,16 @@ from email import Message
EMPTYSTRING = '' EMPTYSTRING = ''
NL = '\n' NL = '\n'
try:
True, False
except NameError:
True = 1
False = 0
class Parser: class Parser:
def __init__(self, _class=Message.Message, strict=0): def __init__(self, _class=Message.Message, strict=False):
"""Parser of RFC 2822 and MIME email messages. """Parser of RFC 2822 and MIME email messages.
Creates an in-memory object tree representing the email message, which Creates an in-memory object tree representing the email message, which
@ -41,14 +48,14 @@ class Parser:
self._class = _class self._class = _class
self._strict = strict self._strict = strict
def parse(self, fp, headersonly=0): def parse(self, fp, headersonly=False):
root = self._class() root = self._class()
self._parseheaders(root, fp) self._parseheaders(root, fp)
if not headersonly: if not headersonly:
self._parsebody(root, fp) self._parsebody(root, fp)
return root return root
def parsestr(self, text, headersonly=0): def parsestr(self, text, headersonly=False):
return self.parse(StringIO(text), headersonly=headersonly) return self.parse(StringIO(text), headersonly=headersonly)
def _parseheaders(self, container, fp): def _parseheaders(self, container, fp):
@ -57,7 +64,7 @@ class Parser:
lastheader = '' lastheader = ''
lastvalue = [] lastvalue = []
lineno = 0 lineno = 0
while 1: while True:
# Don't strip the line before we test for the end condition, # Don't strip the line before we test for the end condition,
# because whitespace-only header lines are RFC compliant # because whitespace-only header lines are RFC compliant
# continuation lines. # continuation lines.
@ -216,7 +223,7 @@ class Parser:
# by a blank line. We'll represent each header block as a # by a blank line. We'll represent each header block as a
# separate Message object # separate Message object
blocks = [] blocks = []
while 1: while True:
blockmsg = self._class() blockmsg = self._class()
self._parseheaders(blockmsg, fp) self._parseheaders(blockmsg, fp)
if not len(blockmsg): if not len(blockmsg):