mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
Use True/False everywhere, and other code cleanups.
This commit is contained in:
parent
e03e8f09eb
commit
5bdb2bee37
1 changed files with 11 additions and 7 deletions
|
@ -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:
|
||||||
|
|
||||||
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):
|
||||||
# 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):
|
||||||
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'):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue