String method conversion.

This commit is contained in:
Eric S. Raymond 2001-02-09 09:19:27 +00:00
parent ee5e61d3bc
commit 66d9919cab
2 changed files with 22 additions and 23 deletions

View File

@ -216,7 +216,7 @@ class MH:
"""Create a new folder (or raise os.error if it cannot be created)."""
protect = pickline(self.profile, 'Folder-Protect')
if protect and isnumeric(protect):
mode = string.atoi(protect, 8)
mode = int(protect, 8)
else:
mode = FOLDER_PROTECT
os.mkdir(os.path.join(self.getpath(), name), mode)
@ -286,7 +286,7 @@ class Folder:
for name in os.listdir(self.getfullname()):
if match(name):
append(name)
messages = map(string.atoi, messages)
messages = map(int, messages)
messages.sort()
if messages:
self.last = messages[-1]
@ -305,12 +305,12 @@ class Folder:
while 1:
line = f.readline()
if not line: break
fields = string.splitfields(line, ':')
fields = line.split(':')
if len(fields) != 2:
self.error('bad sequence in %s: %s' %
(fullname, string.strip(line)))
key = string.strip(fields[0])
value = IntSet(string.strip(fields[1]), ' ').tolist()
(fullname, line.strip()))
key = fields[0].strip()
value = IntSet(fields[1].strip(), ' ').tolist()
sequences[key] = value
return sequences
@ -360,7 +360,7 @@ class Folder:
if seq == 'all':
return all
# Test for X:Y before X-Y because 'seq:-n' matches both
i = string.find(seq, ':')
i = seq.find(':')
if i >= 0:
head, dir, tail = seq[:i], '', seq[i+1:]
if tail[:1] in '-+':
@ -368,7 +368,7 @@ class Folder:
if not isnumeric(tail):
raise Error, "bad message list %s" % seq
try:
count = string.atoi(tail)
count = int(tail)
except (ValueError, OverflowError):
# Can't use sys.maxint because of i+count below
count = len(all)
@ -398,7 +398,7 @@ class Folder:
i = bisect(all, anchor-1)
return all[i:i+count]
# Test for X-Y next
i = string.find(seq, '-')
i = seq.find('-')
if i >= 0:
begin = self._parseindex(seq[:i], all)
end = self._parseindex(seq[i+1:], all)
@ -431,7 +431,7 @@ class Folder:
"""Internal: parse a message number (or cur, first, etc.)."""
if isnumeric(seq):
try:
return string.atoi(seq)
return int(seq)
except (OverflowError, ValueError):
return sys.maxint
if seq in ('cur', '.'):
@ -681,16 +681,16 @@ class Message(mimetools.Message):
decide which headers to return (its argument is the header
name converted to lower case)."""
if not pred:
return string.joinfields(self.headers, '')
return ''.join(self.headers)
headers = []
hit = 0
for line in self.headers:
if line[0] not in string.whitespace:
i = string.find(line, ':')
i = line.find(':')
if i > 0:
hit = pred(string.lower(line[:i]))
hit = pred(line[:i].lower())
if hit: headers.append(line)
return string.joinfields(headers, '')
return ''.joinfields(headers)
def getbodytext(self, decode = 1):
"""Return the message's body text as string. This undoes a
@ -887,11 +887,11 @@ class IntSet:
def fromstring(self, data):
import string
new = []
for part in string.splitfields(data, self.sep):
for part in data.split(self.sep):
list = []
for subp in string.splitfields(part, self.rng):
s = string.strip(subp)
list.append(string.atoi(s))
for subp in part.split(self.rng):
s = subp.strip()
list.append(int(s))
if len(list) == 1:
new.append((list[0], list[0]))
elif len(list) == 2 and list[0] <= list[1]:
@ -921,7 +921,7 @@ def pickline(file, key, casefold = 1):
if not line or line[0] not in string.whitespace:
break
text = text + line
return string.strip(text)
return text.strip()
return None
def updateline(file, key, value, casefold = 1):
@ -996,7 +996,7 @@ def test():
except Error, msg:
print "Error:", msg
stuff = os.popen("pick %s 2>/dev/null" % `seq`).read()
list = map(string.atoi, string.split(stuff))
list = map(int, stuff.split())
print list, "<-- pick"
do('f.listmessages()')

View File

@ -107,11 +107,10 @@ def intsplit(str, pat, maxsplit, retain):
# Capitalize words split using a pattern
def capwords(str, pat='[^a-zA-Z0-9_]+'):
import string
words = splitx(str, pat)
for i in range(0, len(words), 2):
words[i] = string.capitalize(words[i])
return string.joinfields(words, "")
words[i] = words[i].capitalize()
return "".joinfields(words)
# Internal subroutines: