[Python-checkins] CVS: python/dist/src/Lib rfc822.py,1.50,1.51
Guido van Rossum
python-dev@python.org
Fri, 15 Dec 2000 07:37:52 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv20326
Modified Files:
rfc822.py
Log Message:
Get rid of string functions. References to string.whitespace,
string.digits are left.
Index: rfc822.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/rfc822.py,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -r1.50 -r1.51
*** rfc822.py 2000/11/09 18:05:24 1.50
--- rfc822.py 2000/12/15 15:37:48 1.51
***************
*** 143,147 ****
break
# Skip unix From name time lines
! if firstline and line[:5] == 'From ':
self.unixfrom = self.unixfrom + line
continue
--- 143,147 ----
break
# Skip unix From name time lines
! if firstline and line.startswith('From '):
self.unixfrom = self.unixfrom + line
continue
***************
*** 150,155 ****
# It's a continuation line.
list.append(line)
! x = (self.dict[headerseen] + "\n " + string.strip(line))
! self.dict[headerseen] = string.strip(x)
continue
elif self.iscomment(line):
--- 150,155 ----
# It's a continuation line.
list.append(line)
! x = (self.dict[headerseen] + "\n " + line.strip())
! self.dict[headerseen] = x.strip()
continue
elif self.iscomment(line):
***************
*** 163,167 ****
# It's a legal header line, save it.
list.append(line)
! self.dict[headerseen] = string.strip(line[len(headerseen)+1:])
continue
else:
--- 163,167 ----
# It's a legal header line, save it.
list.append(line)
! self.dict[headerseen] = line[len(headerseen)+1:].strip()
continue
else:
***************
*** 187,193 ****
on tagged data in RFC822-like formats with special header formats.
"""
! i = string.find(line, ':')
if i > 0:
! return string.lower(line[:i])
else:
return None
--- 187,193 ----
on tagged data in RFC822-like formats with special header formats.
"""
! i = line.find(':')
if i > 0:
! return line[:i].lower()
else:
return None
***************
*** 224,233 ****
important in the header name.
"""
! name = string.lower(name) + ':'
n = len(name)
list = []
hit = 0
for line in self.headers:
! if string.lower(line[:n]) == name:
hit = 1
elif line[:1] not in string.whitespace:
--- 224,233 ----
important in the header name.
"""
! name = name.lower() + ':'
n = len(name)
list = []
hit = 0
for line in self.headers:
! if line[:n].lower() == name:
hit = 1
elif line[:1] not in string.whitespace:
***************
*** 244,248 ****
lines).
"""
! name = string.lower(name) + ':'
n = len(name)
list = []
--- 244,248 ----
lines).
"""
! name = name.lower() + ':'
n = len(name)
list = []
***************
*** 252,256 ****
if line[:1] not in string.whitespace:
break
! elif string.lower(line[:n]) == name:
hit = 1
if hit:
--- 252,256 ----
if line[:1] not in string.whitespace:
break
! elif line[:n].lower() == name:
hit = 1
if hit:
***************
*** 272,276 ****
return None
list[0] = list[0][len(name) + 1:]
! return string.joinfields(list, '')
def getheader(self, name, default=None):
--- 272,276 ----
return None
list[0] = list[0][len(name) + 1:]
! return ''.join(list)
def getheader(self, name, default=None):
***************
*** 283,287 ****
"""
try:
! return self.dict[string.lower(name)]
except KeyError:
return default
--- 283,287 ----
"""
try:
! return self.dict[name.lower()]
except KeyError:
return default
***************
*** 302,312 ****
if s[0] in string.whitespace:
if current:
! current = "%s\n %s" % (current, string.strip(s))
else:
! current = string.strip(s)
else:
if have_header:
result.append(current)
! current = string.strip(s[string.find(s, ":") + 1:])
have_header = 1
if have_header:
--- 302,312 ----
if s[0] in string.whitespace:
if current:
! current = "%s\n %s" % (current, s.strip())
else:
! current = s.strip()
else:
if have_header:
result.append(current)
! current = s[s.find(":") + 1:].strip()
have_header = 1
if have_header:
***************
*** 342,350 ****
if raw:
raw.append(', ')
! i = string.find(h, ':')
if i > 0:
addr = h[i+1:]
raw.append(addr)
! alladdrs = string.join(raw, '')
a = AddrlistClass(alladdrs)
return a.getaddrlist()
--- 342,350 ----
if raw:
raw.append(', ')
! i = h.find(':')
if i > 0:
addr = h[i+1:]
raw.append(addr)
! alladdrs = ''.join(raw)
a = AddrlistClass(alladdrs)
return a.getaddrlist()
***************
*** 384,388 ****
def __getitem__(self, name):
"""Get a specific header, as from a dictionary."""
! return self.dict[string.lower(name)]
def __setitem__(self, name, value):
--- 384,388 ----
def __getitem__(self, name):
"""Get a specific header, as from a dictionary."""
! return self.dict[name.lower()]
def __setitem__(self, name, value):
***************
*** 394,400 ****
"""
del self[name] # Won't fail if it doesn't exist
! self.dict[string.lower(name)] = value
text = name + ": " + value
! lines = string.split(text, "\n")
for line in lines:
self.headers.append(line + "\n")
--- 394,400 ----
"""
del self[name] # Won't fail if it doesn't exist
! self.dict[name.lower()] = value
text = name + ": " + value
! lines = text.split("\n")
for line in lines:
self.headers.append(line + "\n")
***************
*** 402,406 ****
def __delitem__(self, name):
"""Delete all occurrences of a specific header, if it is present."""
! name = string.lower(name)
if not self.dict.has_key(name):
return
--- 402,406 ----
def __delitem__(self, name):
"""Delete all occurrences of a specific header, if it is present."""
! name = name.lower()
if not self.dict.has_key(name):
return
***************
*** 412,416 ****
for i in range(len(self.headers)):
line = self.headers[i]
! if string.lower(line[:n]) == name:
hit = 1
elif line[:1] not in string.whitespace:
--- 412,416 ----
for i in range(len(self.headers)):
line = self.headers[i]
! if line[:n].lower() == name:
hit = 1
elif line[:1] not in string.whitespace:
***************
*** 424,428 ****
def has_key(self, name):
"""Determine whether a message contains the named header."""
! return self.dict.has_key(string.lower(name))
def keys(self):
--- 424,428 ----
def has_key(self, name):
"""Determine whether a message contains the named header."""
! return self.dict.has_key(name.lower())
def keys(self):
***************
*** 467,477 ****
def quote(str):
"""Add quotes around a string."""
! return '"%s"' % string.join(
! string.split(
! string.join(
! string.split(str, '\\'),
! '\\\\'),
! '"'),
! '\\"')
--- 467,471 ----
def quote(str):
"""Add quotes around a string."""
! return str.replace('\\', '\\\\').replace('"', '\\"')
***************
*** 544,548 ****
# Bad email address technically, no domain.
if plist:
! returnlist = [(string.join(self.commentlist), plist[0])]
elif self.field[self.pos] in '.@':
--- 538,542 ----
# Bad email address technically, no domain.
if plist:
! returnlist = [(' '.join(self.commentlist), plist[0])]
elif self.field[self.pos] in '.@':
***************
*** 552,556 ****
self.commentlist = oldcl
addrspec = self.getaddrspec()
! returnlist = [(string.join(self.commentlist), addrspec)]
elif self.field[self.pos] == ':':
--- 546,550 ----
self.commentlist = oldcl
addrspec = self.getaddrspec()
! returnlist = [(' '.join(self.commentlist), addrspec)]
elif self.field[self.pos] == ':':
***************
*** 572,582 ****
if self.commentlist:
! returnlist = [(string.join(plist) + ' (' + \
! string.join(self.commentlist) + ')', routeaddr)]
! else: returnlist = [(string.join(plist), routeaddr)]
else:
if plist:
! returnlist = [(string.join(self.commentlist), plist[0])]
elif self.field[self.pos] in self.specials:
self.pos = self.pos + 1
--- 566,576 ----
if self.commentlist:
! returnlist = [(' '.join(plist) + ' (' + \
! ' '.join(self.commentlist) + ')', routeaddr)]
! else: returnlist = [(' '.join(plist), routeaddr)]
else:
if plist:
! returnlist = [(' '.join(self.commentlist), plist[0])]
elif self.field[self.pos] in self.specials:
self.pos = self.pos + 1
***************
*** 637,646 ****
if self.pos >= len(self.field) or self.field[self.pos] != '@':
! return string.join(aslist, '')
aslist.append('@')
self.pos = self.pos + 1
self.gotonext()
! return string.join(aslist, '') + self.getdomain()
def getdomain(self):
--- 631,640 ----
if self.pos >= len(self.field) or self.field[self.pos] != '@':
! return ''.join(aslist)
aslist.append('@')
self.pos = self.pos + 1
self.gotonext()
! return ''.join(aslist) + self.getdomain()
def getdomain(self):
***************
*** 660,664 ****
break
else: sdlist.append(self.getatom())
! return string.join(sdlist, '')
def getdelimited(self, beginchar, endchars, allowcomments = 1):
--- 654,658 ----
break
else: sdlist.append(self.getatom())
! return ''.join(sdlist)
def getdelimited(self, beginchar, endchars, allowcomments = 1):
***************
*** 696,700 ****
self.pos = self.pos + 1
! return string.join(slist, '')
def getquote(self):
--- 690,694 ----
self.pos = self.pos + 1
! return ''.join(slist)
def getquote(self):
***************
*** 720,724 ****
self.pos = self.pos + 1
! return string.join(atomlist, '')
def getphraselist(self):
--- 714,718 ----
self.pos = self.pos + 1
! return ''.join(atomlist)
def getphraselist(self):
***************
*** 757,761 ****
def __str__(self):
! return string.joinfields(map(dump_address_pair, self.addresslist),", ")
def __add__(self, other):
--- 751,755 ----
def __str__(self):
! return ", ".join(map(dump_address_pair, self.addresslist))
def __add__(self, other):
***************
*** 829,843 ****
Accounts for military timezones.
"""
! data = string.split(data)
! if data[0][-1] in (',', '.') or string.lower(data[0]) in _daynames:
# There's a dayname here. Skip it
del data[0]
if len(data) == 3: # RFC 850 date, deprecated
! stuff = string.split(data[0], '-')
if len(stuff) == 3:
data = stuff + data[1:]
if len(data) == 4:
s = data[3]
! i = string.find(s, '+')
if i > 0:
data[3:] = [s[:i], s[i+1:]]
--- 823,837 ----
Accounts for military timezones.
"""
! data = data.split()
! if data[0][-1] in (',', '.') or data[0].lower() in _daynames:
# There's a dayname here. Skip it
del data[0]
if len(data) == 3: # RFC 850 date, deprecated
! stuff = data[0].split('-')
if len(stuff) == 3:
data = stuff + data[1:]
if len(data) == 4:
s = data[3]
! i = s.find('+')
if i > 0:
data[3:] = [s[:i], s[i+1:]]
***************
*** 848,854 ****
data = data[:5]
[dd, mm, yy, tm, tz] = data
! mm = string.lower(mm)
if not mm in _monthnames:
! dd, mm = mm, string.lower(dd)
if not mm in _monthnames:
return None
--- 842,848 ----
data = data[:5]
[dd, mm, yy, tm, tz] = data
! mm = mm.lower()
if not mm in _monthnames:
! dd, mm = mm, dd.lower()
if not mm in _monthnames:
return None
***************
*** 857,861 ****
if dd[-1] == ',':
dd = dd[:-1]
! i = string.find(yy, ':')
if i > 0:
yy, tm = tm, yy
--- 851,855 ----
if dd[-1] == ',':
dd = dd[:-1]
! i = yy.find(':')
if i > 0:
yy, tm = tm, yy
***************
*** 866,870 ****
if tm[-1] == ',':
tm = tm[:-1]
! tm = string.splitfields(tm, ':')
if len(tm) == 2:
[thh, tmm] = tm
--- 860,864 ----
if tm[-1] == ',':
tm = tm[:-1]
! tm = tm.split(':')
if len(tm) == 2:
[thh, tmm] = tm
***************
*** 875,893 ****
return None
try:
! yy = string.atoi(yy)
! dd = string.atoi(dd)
! thh = string.atoi(thh)
! tmm = string.atoi(tmm)
! tss = string.atoi(tss)
! except string.atoi_error:
return None
! tzoffset=None
! tz=string.upper(tz)
if _timezones.has_key(tz):
! tzoffset=_timezones[tz]
else:
try:
! tzoffset=string.atoi(tz)
! except string.atoi_error:
pass
# Convert a timezone offset into seconds ; -0500 -> -18000
--- 869,887 ----
return None
try:
! yy = int(yy)
! dd = int(dd)
! thh = int(thh)
! tmm = int(tmm)
! tss = int(tss)
! except ValueError:
return None
! tzoffset = None
! tz = tz.upper()
if _timezones.has_key(tz):
! tzoffset = _timezones[tz]
else:
try:
! tzoffset = int(tz)
! except ValueError:
pass
# Convert a timezone offset into seconds ; -0500 -> -18000
***************
*** 905,910 ****
def parsedate(data):
"""Convert a time string to a time tuple."""
! t=parsedate_tz(data)
! if type(t)==type( () ):
return t[:9]
else: return t
--- 899,904 ----
def parsedate(data):
"""Convert a time string to a time tuple."""
! t = parsedate_tz(data)
! if type(t) == type( () ):
return t[:9]
else: return t