Skip to content

Commit aaab30e

Browse files
committed
Apply diff2.txt from SF patch http://www.python.org/sf/572113
(with one small bugfix in bgen/bgen/scantools.py) This replaces string module functions with string methods for the stuff in the Tools directory. Several uses of string.letters etc. are still remaining.
1 parent 6a0477b commit aaab30e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+271
-346
lines changed

Tools/audiopy/audiopy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Other options are:
4747

4848
import sys
4949
import os
50-
import string
5150
import errno
5251
import sunaudiodev
5352
from SUNAUDIODEV import *
@@ -372,9 +371,9 @@ class Helpwin:
372371
fp = open(readmefile)
373372
contents = fp.read()
374373
# wax the last page, it contains Emacs cruft
375-
i = string.rfind(contents, '\f')
374+
i = contents.rfind('\f')
376375
if i > 0:
377-
contents = string.rstrip(contents[:i])
376+
contents = contents[:i].rstrip()
378377
finally:
379378
if fp:
380379
fp.close()

Tools/bgen/bgen/bgenGenerator.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def parseArgumentList(self, argumentList):
131131
self.argumentList.append(arg)
132132

133133
def docstring(self):
134-
import string
135134
input = []
136135
output = []
137136
for arg in self.argumentList:
@@ -156,11 +155,11 @@ def docstring(self):
156155
if not input:
157156
instr = "()"
158157
else:
159-
instr = "(%s)" % string.joinfields(input, ", ")
158+
instr = "(%s)" % ", ".join(input)
160159
if not output or output == ["void"]:
161160
outstr = "None"
162161
else:
163-
outstr = "(%s)" % string.joinfields(output, ", ")
162+
outstr = "(%s)" % ", ".join(output)
164163
return instr + " -> " + outstr
165164

166165
def functionbody(self):

Tools/bgen/bgen/bgenOutput.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ def VaOutput(format, args):
6969
text = format % args
7070
if _Level > 0:
7171
indent = '\t' * _Level
72-
import string
73-
lines = string.splitfields(text, '\n')
72+
lines = text.split('\n')
7473
for i in range(len(lines)):
7574
if lines[i] and lines[i][0] != '#':
7675
lines[i] = indent + lines[i]
77-
text = string.joinfields(lines, '\n')
76+
text = '\n'.join(lines)
7877
_File.write(text + '\n')
7978

8079
def IndentLevel(by = 1):
@@ -168,13 +167,12 @@ def Out(text):
168167
"""
169168
# (Don't you love using triple quotes *inside* triple quotes? :-)
170169

171-
import string
172-
lines = string.splitfields(text, '\n')
170+
lines = text.split('\n')
173171
indent = ""
174172
for line in lines:
175-
if string.strip(line):
173+
if line.strip():
176174
for c in line:
177-
if c not in string.whitespace:
175+
if not c.isspace():
178176
break
179177
indent = indent + c
180178
break

Tools/bgen/bgen/scantools.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""
1616

1717
import re
18-
import string
1918
import sys
2019
import os
2120
import fnmatch
@@ -67,8 +66,8 @@ def reportusedtypes(self):
6766
for type in types:
6867
modes = self.usedtypes[type].keys()
6968
modes.sort()
70-
self.report("%s %s", type, string.join(modes))
71-
69+
self.report("%s %s", type, " ".join(modes))
70+
7271
def gentypetest(self, file):
7372
fp = open(file, "w")
7473
fp.write("types=[\n")
@@ -163,9 +162,9 @@ def makerepairinstructions(self):
163162
while line[-2:] == '\\\n':
164163
line = line[:-2] + ' ' + f.readline()
165164
lineno = lineno + 1
166-
i = string.find(line, '#')
165+
i = line.find('#')
167166
if i >= 0: line = line[:i]
168-
words = map(string.strip, string.splitfields(line, ':'))
167+
words = [s.strip() for s in line.split(':')]
169168
if words == ['']: continue
170169
if len(words) <> 3:
171170
print "Line", startlineno,
@@ -179,16 +178,16 @@ def makerepairinstructions(self):
179178
print "Empty pattern"
180179
print `line`
181180
continue
182-
patparts = map(string.strip, string.splitfields(pat, ','))
183-
repparts = map(string.strip, string.splitfields(rep, ','))
181+
patparts = [s.strip() for s in pat.split(',')]
182+
repparts = [s.strip() for s in rep.split(',')]
184183
patterns = []
185184
for p in patparts:
186185
if not p:
187186
print "Line", startlineno,
188187
print "Empty pattern part"
189188
print `line`
190189
continue
191-
pattern = string.split(p)
190+
pattern = p.split()
192191
if len(pattern) > 3:
193192
print "Line", startlineno,
194193
print "Pattern part has > 3 words"
@@ -205,7 +204,7 @@ def makerepairinstructions(self):
205204
print "Empty replacement part"
206205
print `line`
207206
continue
208-
replacement = string.split(p)
207+
replacement = p.split()
209208
if len(replacement) > 3:
210209
print "Line", startlineno,
211210
print "Pattern part has > 3 words"
@@ -502,10 +501,10 @@ def processrawspec(self, raw):
502501
self.generate(type, name, arglist)
503502

504503
def extractarglist(self, args):
505-
args = string.strip(args)
504+
args = args.strip()
506505
if not args or args == "void":
507506
return []
508-
parts = map(string.strip, string.splitfields(args, ","))
507+
parts = [s.strip() for s in args.split(",")]
509508
arglist = []
510509
for part in parts:
511510
arg = self.extractarg(part)
@@ -524,7 +523,7 @@ def extractarg(self, part):
524523
# array matches an optional [] after the argument name
525524
type = type + " ptr "
526525
type = re.sub("\*", " ptr ", type)
527-
type = string.strip(type)
526+
type = type.strip()
528527
type = re.sub("[ \t]+", "_", type)
529528
return self.modifyarg(type, name, mode)
530529

@@ -581,7 +580,7 @@ def substituteargs(self, pattern, replacement, old):
581580
if item[i] == '*':
582581
newitem[i] = old[k][i]
583582
elif item[i][:1] == '$':
584-
index = string.atoi(item[i][1:]) - 1
583+
index = int(item[i][1:]) - 1
585584
newitem[i] = old[index][i]
586585
new.append(tuple(newitem))
587586
##self.report("old: %s", `old`)

Tools/faqwiz/faqwiz.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
"""
1313

14-
import sys, string, time, os, stat, re, cgi, faqconf
14+
import sys, time, os, stat, re, cgi, faqconf
1515
from faqconf import * # This imports all uppercase names
1616
now = time.time()
1717

@@ -33,14 +33,14 @@ def __init__(self, file, why=None):
3333
self.why = why
3434

3535
def escape(s):
36-
s = string.replace(s, '&', '&amp;')
37-
s = string.replace(s, '<', '&lt;')
38-
s = string.replace(s, '>', '&gt;')
36+
s = s.replace('&', '&amp;')
37+
s = s.replace('<', '&lt;')
38+
s = s.replace('>', '&gt;')
3939
return s
4040

4141
def escapeq(s):
4242
s = escape(s)
43-
s = string.replace(s, '"', '&quot;')
43+
s = s.replace('"', '&quot;')
4444
return s
4545

4646
def _interpolate(format, args, kw):
@@ -95,7 +95,7 @@ def translate(text, pre=0):
9595
list.append(repl)
9696
j = len(text)
9797
list.append(escape(text[i:j]))
98-
return string.join(list, '')
98+
return ''.join(list)
9999

100100
def emphasize(line):
101101
return re.sub(r'\*([a-zA-Z]+)\*', r'<I>\1</I>', line)
@@ -109,7 +109,7 @@ def revparse(rev):
109109
m = revparse_prog.match(rev)
110110
if not m:
111111
return None
112-
[major, minor] = map(string.atoi, m.group(1, 2))
112+
[major, minor] = map(int, m.group(1, 2))
113113
return major, minor
114114

115115
logon = 0
@@ -123,10 +123,10 @@ def load_cookies():
123123
if not os.environ.has_key('HTTP_COOKIE'):
124124
return {}
125125
raw = os.environ['HTTP_COOKIE']
126-
words = map(string.strip, string.split(raw, ';'))
126+
words = [s.strip() for s in raw.split(';')]
127127
cookies = {}
128128
for word in words:
129-
i = string.find(word, '=')
129+
i = word.find('=')
130130
if i >= 0:
131131
key, value = word[:i], word[i+1:]
132132
cookies[key] = value
@@ -140,10 +140,10 @@ def load_my_cookie():
140140
return {}
141141
import urllib
142142
value = urllib.unquote(value)
143-
words = string.split(value, '/')
143+
words = value.split('/')
144144
while len(words) < 3:
145145
words.append('')
146-
author = string.join(words[:-2], '/')
146+
author = '/'.join(words[:-2])
147147
email = words[-2]
148148
password = words[-1]
149149
return {'author': author,
@@ -194,7 +194,7 @@ def __getattr__(self, name):
194194
except (TypeError, KeyError):
195195
value = ''
196196
else:
197-
value = string.strip(value)
197+
value = value.strip()
198198
setattr(self, name, value)
199199
return value
200200

@@ -209,15 +209,15 @@ def __init__(self, fp, file, sec_num):
209209
if fp:
210210
import rfc822
211211
self.__headers = rfc822.Message(fp)
212-
self.body = string.strip(fp.read())
212+
self.body = fp.read().strip()
213213
else:
214214
self.__headers = {'title': "%d.%d. " % sec_num}
215215
self.body = ''
216216

217217
def __getattr__(self, name):
218218
if name[0] == '_':
219219
raise AttributeError
220-
key = string.join(string.split(name, '_'), '-')
220+
key = '-'.join(name.split('_'))
221221
try:
222222
value = self.__headers[key]
223223
except KeyError:
@@ -237,7 +237,7 @@ def load_version(self):
237237
if not line:
238238
break
239239
if line[:5] == 'head:':
240-
version = string.strip(line[5:])
240+
version = line[5:].strip()
241241
p.close()
242242
self.version = version
243243

@@ -262,10 +262,10 @@ def show(self, edit=1):
262262
emit(ENTRY_HEADER2, self)
263263
pre = 0
264264
raw = 0
265-
for line in string.split(self.body, '\n'):
265+
for line in self.body.split('\n'):
266266
# Allow the user to insert raw html into a FAQ answer
267267
# (Skip Montanaro, with changes by Guido)
268-
tag = string.lower(string.rstrip(line))
268+
tag = line.rstrip().lower()
269269
if tag == '<html>':
270270
raw = 1
271271
continue
@@ -275,14 +275,14 @@ def show(self, edit=1):
275275
if raw:
276276
print line
277277
continue
278-
if not string.strip(line):
278+
if not line.strip():
279279
if pre:
280280
print '</PRE>'
281281
pre = 0
282282
else:
283283
print '<P>'
284284
else:
285-
if line[0] not in string.whitespace:
285+
if not line[0].isspace():
286286
if pre:
287287
print '</PRE>'
288288
pre = 0
@@ -335,7 +335,7 @@ def parse(self, file):
335335
if not m:
336336
return None
337337
sec, num = m.group(1, 2)
338-
return string.atoi(sec), string.atoi(num)
338+
return int(sec), int(num)
339339

340340
def list(self):
341341
# XXX Caller shouldn't modify result
@@ -432,7 +432,7 @@ def do_search(self):
432432
return
433433
words = map(lambda w: r'\b%s\b' % w, words)
434434
if self.ui.querytype[:3] == 'any':
435-
queries = [string.join(words, '|')]
435+
queries = ['|'.join(words)]
436436
else:
437437
# Each of the individual queries must match
438438
queries = words
@@ -551,7 +551,7 @@ def do_recent(self):
551551
if not self.ui.days:
552552
days = 1
553553
else:
554-
days = string.atof(self.ui.days)
554+
days = float(self.ui.days)
555555
try:
556556
cutoff = now - days * 24 * 3600
557557
except OverflowError:
@@ -623,7 +623,7 @@ def rlog(self, command, entry=None):
623623
output = os.popen(command).read()
624624
sys.stdout.write('<PRE>')
625625
athead = 0
626-
lines = string.split(output, '\n')
626+
lines = output.split('\n')
627627
while lines and not lines[-1]:
628628
del lines[-1]
629629
if lines:
@@ -634,7 +634,7 @@ def rlog(self, command, entry=None):
634634
headrev = None
635635
for line in lines:
636636
if entry and athead and line[:9] == 'revision ':
637-
rev = string.strip(line[9:])
637+
rev = line[9:].split()
638638
mami = revparse(rev)
639639
if not mami:
640640
print line
@@ -690,7 +690,7 @@ def shell(self, command):
690690
print '</PRE>'
691691

692692
def do_new(self):
693-
entry = self.dir.new(section=string.atoi(self.ui.section))
693+
entry = self.dir.new(section=int(self.ui.section))
694694
entry.version = '*new*'
695695
self.prologue(T_EDIT)
696696
emit(EDITHEAD)
@@ -723,7 +723,7 @@ def do_review(self):
723723
entry = self.dir.open(self.ui.file)
724724
entry.load_version()
725725
# Check that the FAQ entry number didn't change
726-
if string.split(self.ui.title)[:1] != string.split(entry.title)[:1]:
726+
if self.ui.title.split()[:1] != entry.title.split()[:1]:
727727
self.error("Don't change the entry number please!")
728728
return
729729
# Check that the edited version is the current version
@@ -779,7 +779,7 @@ def commit(self, entry):
779779
if '\r' in self.ui.body:
780780
self.ui.body = re.sub('\r\n?', '\n', self.ui.body)
781781
# Normalize whitespace in title
782-
self.ui.title = string.join(string.split(self.ui.title))
782+
self.ui.title = ' '.join(self.ui.title.split())
783783
# Check that there were any changes
784784
if self.ui.body == entry.body and self.ui.title == entry.title:
785785
self.error("You didn't make any changes!")

0 commit comments

Comments
 (0)