Commit 5bdb2bee authored by Barry Warsaw's avatar Barry Warsaw

Use True/False everywhere, and other code cleanups.

parent e03e8f09
...@@ -21,6 +21,12 @@ from rfc822 import mktime_tz ...@@ -21,6 +21,12 @@ from rfc822 import mktime_tz
from rfc822 import parsedate as _parsedate from rfc822 import parsedate as _parsedate
from rfc822 import parsedate_tz as _parsedate_tz from rfc822 import parsedate_tz as _parsedate_tz
try:
True, False
except NameError:
True = 1
False = 0
try: try:
from quopri import decodestring as _qdecode from quopri import decodestring as _qdecode
except ImportError: except ImportError:
...@@ -30,12 +36,11 @@ except ImportError: ...@@ -30,12 +36,11 @@ except ImportError:
if not s: if not s:
return s return s
hasnewline = (s[-1] == '\n')
infp = StringIO(s) infp = StringIO(s)
outfp = StringIO() outfp = StringIO()
_quopri.decode(infp, outfp) _quopri.decode(infp, outfp)
value = outfp.getvalue() value = outfp.getvalue()
if not hasnewline and value[-1] =='\n': if not s.endswith('\n') and value.endswith('\n'):
return value[:-1] return value[:-1]
return value return value
...@@ -67,9 +72,8 @@ def _bdecode(s): ...@@ -67,9 +72,8 @@ def _bdecode(s):
# newline". Blech! # newline". Blech!
if not s: if not s:
return s return s
hasnewline = (s[-1] == '\n')
value = base64.decodestring(s) value = base64.decodestring(s)
if not hasnewline and value[-1] == '\n': if not s.endswith('\n') and value.endswith('\n'):
return value[:-1] return value[:-1]
return value return value
...@@ -88,7 +92,7 @@ def fix_eols(s): ...@@ -88,7 +92,7 @@ def fix_eols(s):
def formataddr(pair): def formataddr(pair):
"""The inverse of parseaddr(), this takes a 2-tuple of the form """The inverse of parseaddr(), this takes a 2-tuple of the form
(realname, email_address) and returns the string value suitable (realname, email_address) and returns the string value suitable
for an RFC 2822 From:, To: or Cc:. for an RFC 2822 From, To or Cc header.
If the first element of pair is false, then the second element is If the first element of pair is false, then the second element is
returned unmodified. returned unmodified.
...@@ -170,7 +174,7 @@ def encode(s, charset='iso-8859-1', encoding='q'): ...@@ -170,7 +174,7 @@ def encode(s, charset='iso-8859-1', encoding='q'):
def formatdate(timeval=None, localtime=0): def formatdate(timeval=None, localtime=False):
"""Returns a date string as specified by RFC 2822, e.g.: """Returns a date string as specified by RFC 2822, e.g.:
Fri, 09 Nov 2001 01:08:47 -0000 Fri, 09 Nov 2001 01:08:47 -0000
...@@ -178,7 +182,7 @@ def formatdate(timeval=None, localtime=0): ...@@ -178,7 +182,7 @@ def formatdate(timeval=None, localtime=0):
Optional timeval if given is a floating point time value as accepted by Optional timeval if given is a floating point time value as accepted by
gmtime() and localtime(), otherwise the current time is used. gmtime() and localtime(), otherwise the current time is used.
Optional localtime is a flag that when true, interprets timeval, and Optional localtime is a flag that when True, interprets timeval, and
returns a date relative to the local timezone instead of UTC, properly returns a date relative to the local timezone instead of UTC, properly
taking daylight savings time into account. taking daylight savings time into account.
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment