diff --git a/Tools/audiopy/audiopy b/Tools/audiopy/audiopy index f5a10218d2b..b817c5cc05f 100755 --- a/Tools/audiopy/audiopy +++ b/Tools/audiopy/audiopy @@ -47,7 +47,6 @@ Other options are: import sys import os -import string import errno import sunaudiodev from SUNAUDIODEV import * @@ -372,9 +371,9 @@ class Helpwin: fp = open(readmefile) contents = fp.read() # wax the last page, it contains Emacs cruft - i = string.rfind(contents, '\f') + i = contents.rfind('\f') if i > 0: - contents = string.rstrip(contents[:i]) + contents = contents[:i].rstrip() finally: if fp: fp.close() diff --git a/Tools/bgen/bgen/bgenGenerator.py b/Tools/bgen/bgen/bgenGenerator.py index aa3966864ec..1c19388091a 100644 --- a/Tools/bgen/bgen/bgenGenerator.py +++ b/Tools/bgen/bgen/bgenGenerator.py @@ -131,7 +131,6 @@ def parseArgumentList(self, argumentList): self.argumentList.append(arg) def docstring(self): - import string input = [] output = [] for arg in self.argumentList: @@ -156,11 +155,11 @@ def docstring(self): if not input: instr = "()" else: - instr = "(%s)" % string.joinfields(input, ", ") + instr = "(%s)" % ", ".join(input) if not output or output == ["void"]: outstr = "None" else: - outstr = "(%s)" % string.joinfields(output, ", ") + outstr = "(%s)" % ", ".join(output) return instr + " -> " + outstr def functionbody(self): diff --git a/Tools/bgen/bgen/bgenOutput.py b/Tools/bgen/bgen/bgenOutput.py index a269585560c..c7e560ccea0 100644 --- a/Tools/bgen/bgen/bgenOutput.py +++ b/Tools/bgen/bgen/bgenOutput.py @@ -69,12 +69,11 @@ def VaOutput(format, args): text = format % args if _Level > 0: indent = '\t' * _Level - import string - lines = string.splitfields(text, '\n') + lines = text.split('\n') for i in range(len(lines)): if lines[i] and lines[i][0] != '#': lines[i] = indent + lines[i] - text = string.joinfields(lines, '\n') + text = '\n'.join(lines) _File.write(text + '\n') def IndentLevel(by = 1): @@ -168,13 +167,12 @@ def Out(text): """ # (Don't you love using triple quotes *inside* triple quotes? :-) - import string - lines = string.splitfields(text, '\n') + lines = text.split('\n') indent = "" for line in lines: - if string.strip(line): + if line.strip(): for c in line: - if c not in string.whitespace: + if not c.isspace(): break indent = indent + c break diff --git a/Tools/bgen/bgen/scantools.py b/Tools/bgen/bgen/scantools.py index 205a1ce2f0c..61c2f37581f 100644 --- a/Tools/bgen/bgen/scantools.py +++ b/Tools/bgen/bgen/scantools.py @@ -15,7 +15,6 @@ """ import re -import string import sys import os import fnmatch @@ -67,8 +66,8 @@ def reportusedtypes(self): for type in types: modes = self.usedtypes[type].keys() modes.sort() - self.report("%s %s", type, string.join(modes)) - + self.report("%s %s", type, " ".join(modes)) + def gentypetest(self, file): fp = open(file, "w") fp.write("types=[\n") @@ -163,9 +162,9 @@ def makerepairinstructions(self): while line[-2:] == '\\\n': line = line[:-2] + ' ' + f.readline() lineno = lineno + 1 - i = string.find(line, '#') + i = line.find('#') if i >= 0: line = line[:i] - words = map(string.strip, string.splitfields(line, ':')) + words = [s.strip() for s in line.split(':')] if words == ['']: continue if len(words) <> 3: print "Line", startlineno, @@ -179,8 +178,8 @@ def makerepairinstructions(self): print "Empty pattern" print `line` continue - patparts = map(string.strip, string.splitfields(pat, ',')) - repparts = map(string.strip, string.splitfields(rep, ',')) + patparts = [s.strip() for s in pat.split(',')] + repparts = [s.strip() for s in rep.split(',')] patterns = [] for p in patparts: if not p: @@ -188,7 +187,7 @@ def makerepairinstructions(self): print "Empty pattern part" print `line` continue - pattern = string.split(p) + pattern = p.split() if len(pattern) > 3: print "Line", startlineno, print "Pattern part has > 3 words" @@ -205,7 +204,7 @@ def makerepairinstructions(self): print "Empty replacement part" print `line` continue - replacement = string.split(p) + replacement = p.split() if len(replacement) > 3: print "Line", startlineno, print "Pattern part has > 3 words" @@ -502,10 +501,10 @@ def processrawspec(self, raw): self.generate(type, name, arglist) def extractarglist(self, args): - args = string.strip(args) + args = args.strip() if not args or args == "void": return [] - parts = map(string.strip, string.splitfields(args, ",")) + parts = [s.strip() for s in args.split(",")] arglist = [] for part in parts: arg = self.extractarg(part) @@ -524,7 +523,7 @@ def extractarg(self, part): # array matches an optional [] after the argument name type = type + " ptr " type = re.sub("\*", " ptr ", type) - type = string.strip(type) + type = type.strip() type = re.sub("[ \t]+", "_", type) return self.modifyarg(type, name, mode) @@ -581,7 +580,7 @@ def substituteargs(self, pattern, replacement, old): if item[i] == '*': newitem[i] = old[k][i] elif item[i][:1] == '$': - index = string.atoi(item[i][1:]) - 1 + index = int(item[i][1:]) - 1 newitem[i] = old[index][i] new.append(tuple(newitem)) ##self.report("old: %s", `old`) diff --git a/Tools/faqwiz/faqwiz.py b/Tools/faqwiz/faqwiz.py index 2e2a8b538e2..e91d4dce879 100644 --- a/Tools/faqwiz/faqwiz.py +++ b/Tools/faqwiz/faqwiz.py @@ -11,7 +11,7 @@ """ -import sys, string, time, os, stat, re, cgi, faqconf +import sys, time, os, stat, re, cgi, faqconf from faqconf import * # This imports all uppercase names now = time.time() @@ -33,14 +33,14 @@ def __init__(self, file, why=None): self.why = why def escape(s): - s = string.replace(s, '&', '&') - s = string.replace(s, '<', '<') - s = string.replace(s, '>', '>') + s = s.replace('&', '&') + s = s.replace('<', '<') + s = s.replace('>', '>') return s def escapeq(s): s = escape(s) - s = string.replace(s, '"', '"') + s = s.replace('"', '"') return s def _interpolate(format, args, kw): @@ -95,7 +95,7 @@ def translate(text, pre=0): list.append(repl) j = len(text) list.append(escape(text[i:j])) - return string.join(list, '') + return ''.join(list) def emphasize(line): return re.sub(r'\*([a-zA-Z]+)\*', r'\1', line) @@ -109,7 +109,7 @@ def revparse(rev): m = revparse_prog.match(rev) if not m: return None - [major, minor] = map(string.atoi, m.group(1, 2)) + [major, minor] = map(int, m.group(1, 2)) return major, minor logon = 0 @@ -123,10 +123,10 @@ def load_cookies(): if not os.environ.has_key('HTTP_COOKIE'): return {} raw = os.environ['HTTP_COOKIE'] - words = map(string.strip, string.split(raw, ';')) + words = [s.strip() for s in raw.split(';')] cookies = {} for word in words: - i = string.find(word, '=') + i = word.find('=') if i >= 0: key, value = word[:i], word[i+1:] cookies[key] = value @@ -140,10 +140,10 @@ def load_my_cookie(): return {} import urllib value = urllib.unquote(value) - words = string.split(value, '/') + words = value.split('/') while len(words) < 3: words.append('') - author = string.join(words[:-2], '/') + author = '/'.join(words[:-2]) email = words[-2] password = words[-1] return {'author': author, @@ -194,7 +194,7 @@ def __getattr__(self, name): except (TypeError, KeyError): value = '' else: - value = string.strip(value) + value = value.strip() setattr(self, name, value) return value @@ -209,7 +209,7 @@ def __init__(self, fp, file, sec_num): if fp: import rfc822 self.__headers = rfc822.Message(fp) - self.body = string.strip(fp.read()) + self.body = fp.read().strip() else: self.__headers = {'title': "%d.%d. " % sec_num} self.body = '' @@ -217,7 +217,7 @@ def __init__(self, fp, file, sec_num): def __getattr__(self, name): if name[0] == '_': raise AttributeError - key = string.join(string.split(name, '_'), '-') + key = '-'.join(name.split('_')) try: value = self.__headers[key] except KeyError: @@ -237,7 +237,7 @@ def load_version(self): if not line: break if line[:5] == 'head:': - version = string.strip(line[5:]) + version = line[5:].strip() p.close() self.version = version @@ -262,10 +262,10 @@ def show(self, edit=1): emit(ENTRY_HEADER2, self) pre = 0 raw = 0 - for line in string.split(self.body, '\n'): + for line in self.body.split('\n'): # Allow the user to insert raw html into a FAQ answer # (Skip Montanaro, with changes by Guido) - tag = string.lower(string.rstrip(line)) + tag = line.rstrip().lower() if tag == '': raw = 1 continue @@ -275,14 +275,14 @@ def show(self, edit=1): if raw: print line continue - if not string.strip(line): + if not line.strip(): if pre: print '' pre = 0 else: print '
' else: - if line[0] not in string.whitespace: + if not line[0].isspace(): if pre: print '' pre = 0 @@ -335,7 +335,7 @@ def parse(self, file): if not m: return None sec, num = m.group(1, 2) - return string.atoi(sec), string.atoi(num) + return int(sec), int(num) def list(self): # XXX Caller shouldn't modify result @@ -432,7 +432,7 @@ def do_search(self): return words = map(lambda w: r'\b%s\b' % w, words) if self.ui.querytype[:3] == 'any': - queries = [string.join(words, '|')] + queries = ['|'.join(words)] else: # Each of the individual queries must match queries = words @@ -551,7 +551,7 @@ def do_recent(self): if not self.ui.days: days = 1 else: - days = string.atof(self.ui.days) + days = float(self.ui.days) try: cutoff = now - days * 24 * 3600 except OverflowError: @@ -623,7 +623,7 @@ def rlog(self, command, entry=None): output = os.popen(command).read() sys.stdout.write('
')
athead = 0
- lines = string.split(output, '\n')
+ lines = output.split('\n')
while lines and not lines[-1]:
del lines[-1]
if lines:
@@ -634,7 +634,7 @@ def rlog(self, command, entry=None):
headrev = None
for line in lines:
if entry and athead and line[:9] == 'revision ':
- rev = string.strip(line[9:])
+ rev = line[9:].split()
mami = revparse(rev)
if not mami:
print line
@@ -690,7 +690,7 @@ def shell(self, command):
print ''
def do_new(self):
- entry = self.dir.new(section=string.atoi(self.ui.section))
+ entry = self.dir.new(section=int(self.ui.section))
entry.version = '*new*'
self.prologue(T_EDIT)
emit(EDITHEAD)
@@ -723,7 +723,7 @@ def do_review(self):
entry = self.dir.open(self.ui.file)
entry.load_version()
# Check that the FAQ entry number didn't change
- if string.split(self.ui.title)[:1] != string.split(entry.title)[:1]:
+ if self.ui.title.split()[:1] != entry.title.split()[:1]:
self.error("Don't change the entry number please!")
return
# Check that the edited version is the current version
@@ -779,7 +779,7 @@ def commit(self, entry):
if '\r' in self.ui.body:
self.ui.body = re.sub('\r\n?', '\n', self.ui.body)
# Normalize whitespace in title
- self.ui.title = string.join(string.split(self.ui.title))
+ self.ui.title = ' '.join(self.ui.title.split())
# Check that there were any changes
if self.ui.body == entry.body and self.ui.title == entry.title:
self.error("You didn't make any changes!")
diff --git a/Tools/freeze/checkextensions.py b/Tools/freeze/checkextensions.py
index 8d597bfae96..584f8a66dbc 100644
--- a/Tools/freeze/checkextensions.py
+++ b/Tools/freeze/checkextensions.py
@@ -3,7 +3,6 @@
# and one or more .o files or a lib.a file.
import os
-import string
import parsesetup
def checkextensions(unknown, extensions):
@@ -44,7 +43,7 @@ def select(e, mods, vars, mod, skipofiles):
if not w:
continue
w = expandvars(w, vars)
- for w in string.split(w):
+ for w in w.split():
if skipofiles and w[-2:] == '.o':
continue
# Assume $var expands to absolute pathname
@@ -73,14 +72,14 @@ def treatword(w):
def expandvars(str, vars):
i = 0
while i < len(str):
- i = k = string.find(str, '$', i)
+ i = k = str.find('$', i)
if i < 0:
break
i = i+1
var = str[i:i+1]
i = i+1
if var == '(':
- j = string.find(str, ')', i)
+ j = str.find(')', i)
if j < 0:
break
var = str[i:j]
diff --git a/Tools/freeze/checkextensions_win32.py b/Tools/freeze/checkextensions_win32.py
index 85c3a3c0cdd..669a1429464 100644
--- a/Tools/freeze/checkextensions_win32.py
+++ b/Tools/freeze/checkextensions_win32.py
@@ -22,7 +22,7 @@
but an obvious enhancement would be to provide command line options.
"""
-import os, string, sys
+import os, sys
try:
import win32api
except ImportError:
@@ -107,12 +107,12 @@ def get_extension_defn(moduleName, mapFileName, prefix):
module.AddCompilerOption(win32api.ExpandEnvironmentStrings(cl_options))
exclude = win32api.GetProfileVal(moduleName, "exclude", "", mapFileName)
- exclude = string.split(exclude)
+ exclude = exclude.split()
if win32api.GetProfileVal(moduleName, "Unicode", 0, mapFileName):
module.AddCompilerOption('/D UNICODE /D _UNICODE')
- libs = string.split(win32api.GetProfileVal(moduleName, "libs", "", mapFileName))
+ libs = win32api.GetProfileVal(moduleName, "libs", "", mapFileName).split()
for lib in libs:
module.AddLinkerLib(win32api.ExpandEnvironmentStrings(lib))
@@ -135,9 +135,9 @@ def parse_dsp(dsp):
sys.stderr.write("%s: %s\n" % (dsp, msg))
return None
for line in lines:
- fields = string.split(string.strip(line), "=", 2)
+ fields = line.strip().split("=", 2)
if fields[0]=="SOURCE":
- if string.lower(os.path.splitext(fields[1])[1]) in ['.cpp', '.c']:
+ if os.path.splitext(fields[1])[1].lower() in ['.cpp', '.c']:
ret.append( win32api.GetFullPathName(os.path.join(dsp_path, fields[1] ) ) )
return ret
@@ -148,12 +148,12 @@ def write_extension_table(fname, modules):
# Write fn protos
for module in modules:
# bit of a hack for .pyd's as part of packages.
- name = string.split(module.name,'.')[-1]
+ name = module.name.split('.')[-1]
fp.write('extern void init%s(void);\n' % (name) )
# Write the table
fp.write (ext_tab_header)
for module in modules:
- name = string.split(module.name,'.')[-1]
+ name = module.name.split('.')[-1]
fp.write('\t{"%s", init%s},\n' % (name, name) )
fp.write (ext_tab_footer)
diff --git a/Tools/freeze/freeze.py b/Tools/freeze/freeze.py
index 0b9b20639fc..2c59807733a 100755
--- a/Tools/freeze/freeze.py
+++ b/Tools/freeze/freeze.py
@@ -91,7 +91,6 @@
import getopt
import os
-import string
import sys
@@ -148,7 +147,7 @@ def main():
# last option can not be "-i", so this ensures "pos+1" is in range!
if sys.argv[pos] == '-i':
try:
- options = string.split(open(sys.argv[pos+1]).read())
+ options = open(sys.argv[pos+1]).read().split()
except IOError, why:
usage("File name '%s' specified with the -i option "
"can not be read - %s" % (sys.argv[pos+1], why) )
@@ -198,9 +197,9 @@ def main():
if o == '-l':
addn_link.append(a)
if o == '-a':
- apply(modulefinder.AddPackagePath, tuple(string.split(a,"=", 2)))
+ apply(modulefinder.AddPackagePath, tuple(a.split("=", 2)))
if o == '-r':
- f,r = string.split(a,"=", 2)
+ f,r = a.split("=", 2)
replace_paths.append( (f,r) )
# default prefix and exec_prefix
@@ -419,7 +418,7 @@ def main():
# report unknown modules
if unknown:
sys.stderr.write('Warning: unknown modules remain: %s\n' %
- string.join(unknown))
+ ' '.join(unknown))
# windows gets different treatment
if win:
@@ -462,8 +461,8 @@ def main():
for key in makevars.keys():
somevars[key] = makevars[key]
- somevars['CFLAGS'] = string.join(cflags) # override
- somevars['CPPFLAGS'] = string.join(cppflags) # override
+ somevars['CFLAGS'] = ' '.join(cflags) # override
+ somevars['CPPFLAGS'] = ' '.join(cppflags) # override
files = [base_config_c, base_frozen_c] + \
files + supp_sources + addfiles + libs + \
['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)']
diff --git a/Tools/freeze/makefreeze.py b/Tools/freeze/makefreeze.py
index 38880501124..29a6ad6d8d7 100644
--- a/Tools/freeze/makefreeze.py
+++ b/Tools/freeze/makefreeze.py
@@ -1,5 +1,4 @@
import marshal
-import string
import bkfile
@@ -38,7 +37,7 @@ def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
mods.sort()
for mod in mods:
m = dict[mod]
- mangled = string.join(string.split(mod, "."), "__")
+ mangled = "__".join(mod.split("."))
if m.__code__:
file = 'M_' + mangled + '.c'
outfp = bkfile.open(base + file, 'w')
@@ -88,4 +87,4 @@ def writecode(outfp, mod, str):
## def writecode(outfp, mod, str):
## outfp.write('unsigned char M_%s[%d] = "%s";\n' % (mod, len(str),
-## string.join(map(lambda s: `s`[1:-1], string.split(str, '"')), '\\"')))
+## '\\"'.join(map(lambda s: `s`[1:-1], str.split('"')))))
diff --git a/Tools/freeze/makemakefile.py b/Tools/freeze/makemakefile.py
index e33e32e21e3..b8b99b87684 100644
--- a/Tools/freeze/makemakefile.py
+++ b/Tools/freeze/makemakefile.py
@@ -1,7 +1,6 @@
# Write the actual Makefile.
import os
-import string
def makemakefile(outfp, makevars, files, target):
outfp.write("# Makefile generated by freeze.py script\n\n")
@@ -23,8 +22,8 @@ def makemakefile(outfp, makevars, files, target):
files[i] = dest
deps.append(dest)
- outfp.write("\n%s: %s\n" % (target, string.join(deps)))
+ outfp.write("\n%s: %s\n" % (target, ' '.join(deps)))
outfp.write("\t$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) %s -o %s $(LDLAST)\n" %
- (string.join(files), target))
+ (' '.join(files), target))
outfp.write("\nclean:\n\t-rm -f *.o %s\n" % target)
diff --git a/Tools/freeze/modulefinder.py b/Tools/freeze/modulefinder.py
index 741ef4d9266..e9c1140b71b 100644
--- a/Tools/freeze/modulefinder.py
+++ b/Tools/freeze/modulefinder.py
@@ -5,7 +5,6 @@
import marshal
import os
import re
-import string
import sys
import new
@@ -150,7 +149,7 @@ def determine_parent(self, caller):
self.msgout(4, "determine_parent ->", parent)
return parent
if '.' in pname:
- i = string.rfind(pname, '.')
+ i = pname.rfind('.')
pname = pname[:i]
parent = self.modules[pname]
assert parent.__name__ == pname
@@ -162,7 +161,7 @@ def determine_parent(self, caller):
def find_head_package(self, parent, name):
self.msgin(4, "find_head_package", parent, name)
if '.' in name:
- i = string.find(name, '.')
+ i = name.find('.')
head = name[:i]
tail = name[i+1:]
else:
@@ -190,7 +189,7 @@ def load_tail(self, q, tail):
self.msgin(4, "load_tail", q, tail)
m = q
while tail:
- i = string.find(tail, '.')
+ i = tail.find('.')
if i < 0: i = len(tail)
head, tail = tail[:i], tail[i+1:]
mname = "%s.%s" % (m.__name__, head)
@@ -357,7 +356,7 @@ def add_module(self, fqname):
def find_module(self, name, path):
if path:
- fullname = string.join(path, '.')+'.'+name
+ fullname = '.'.join(path)+'.'+name
else:
fullname = name
if fullname in self.excludes:
@@ -399,7 +398,7 @@ def report(self):
if key not in self.excludes:
mods = self.badmodules[key].keys()
mods.sort()
- print "?", key, "from", string.join(mods, ', ')
+ print "?", key, "from", ', '.join(mods)
def any_missing(self):
keys = self.badmodules.keys()
@@ -457,7 +456,7 @@ def test():
if o == '-m':
domods = 1
if o == '-p':
- addpath = addpath + string.split(a, os.pathsep)
+ addpath = addpath + a.split(os.pathsep)
if o == '-q':
debug = 0
if o == '-x':
diff --git a/Tools/freeze/parsesetup.py b/Tools/freeze/parsesetup.py
index 7a6b72ef770..2b9123ea4de 100644
--- a/Tools/freeze/parsesetup.py
+++ b/Tools/freeze/parsesetup.py
@@ -1,7 +1,6 @@
# Parse Makefiles and Python Setup(.in) files.
import re
-import string
# Extract variable definitions from a Makefile.
@@ -29,10 +28,10 @@ def getmakevars(filename):
continue
(name, value) = matchobj.group(1, 2)
# Strip trailing comment
- i = string.find(value, '#')
+ i = value.find('#')
if i >= 0:
value = value[:i]
- value = string.strip(value)
+ value = value.strip()
variables[name] = value
finally:
fp.close()
@@ -60,7 +59,7 @@ def getsetupinfo(filename):
if not line:
break
# Strip comments
- i = string.find(line, '#')
+ i = line.find('#')
if i >= 0:
line = line[:i]
if line.endswith('\\\n'):
@@ -69,9 +68,9 @@ def getsetupinfo(filename):
matchobj = setupvardef.match(line)
if matchobj:
(name, value) = matchobj.group(1, 2)
- variables[name] = string.strip(value)
+ variables[name] = value.strip()
else:
- words = string.split(line)
+ words = line.split()
if words:
modules[words[0]] = words[1:]
finally:
diff --git a/Tools/freeze/winmakemakefile.py b/Tools/freeze/winmakemakefile.py
index d668a6e8273..763e8205c5c 100644
--- a/Tools/freeze/winmakemakefile.py
+++ b/Tools/freeze/winmakemakefile.py
@@ -1,4 +1,4 @@
-import sys, os, string
+import sys, os
# Template used then the program is a GUI program
WINMAINTEMPLATE = """
@@ -112,7 +112,7 @@ def realwork(vars, moddefns, target):
print "\t\t$(cflags) $(cdebug) $(cinclude) \\"
extra = moddefn.GetCompilerOptions()
if extra:
- print "\t\t%s \\" % (string.join(extra),)
+ print "\t\t%s \\" % (' '.join(extra),)
print '\t\t"%s"' % file
print
diff --git a/Tools/idle/AutoIndent.py b/Tools/idle/AutoIndent.py
index f8bb847b2f5..7bc195b19bf 100644
--- a/Tools/idle/AutoIndent.py
+++ b/Tools/idle/AutoIndent.py
@@ -1,4 +1,3 @@
-import string
#from Tkinter import TclError
#import tkMessageBox
#import tkSimpleDialog
@@ -168,15 +167,15 @@ def smart_backspace_event(self, event):
return "break"
# Ick. It may require *inserting* spaces if we back up over a
# tab character! This is written to be clear, not fast.
- expand, tabwidth = string.expandtabs, self.tabwidth
- have = len(expand(chars, tabwidth))
+ tabwidth = self.tabwidth
+ have = len(chars.expandtabs(tabwidth))
assert have > 0
want = ((have - 1) // self.indentwidth) * self.indentwidth
ncharsdeleted = 0
while 1:
chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1
- have = len(expand(chars, tabwidth))
+ have = len(chars.expandtabs(tabwidth))
if have <= want or chars[-1] not in " \t":
break
text.undo_block_start()
@@ -210,8 +209,7 @@ def smart_indent_event(self, event):
if self.usetabs:
pad = '\t'
else:
- effective = len(string.expandtabs(prefix,
- self.tabwidth))
+ effective = len(prefix.expandtabs(self.tabwidth))
n = self.indentwidth
pad = ' ' * (n - effective % n)
text.insert("insert", pad)
@@ -376,7 +374,7 @@ def untabify_region_event(self, event):
head, tail, chars, lines = self.get_region()
tabwidth = self._asktabwidth()
for pos in range(len(lines)):
- lines[pos] = string.expandtabs(lines[pos], tabwidth)
+ lines[pos] = lines[pos].expandtabs(tabwidth)
self.set_region(head, tail, chars, lines)
def toggle_tabs_event(self, event):
@@ -417,12 +415,12 @@ def get_region(self):
head = text.index("insert linestart")
tail = text.index("insert lineend +1c")
chars = text.get(head, tail)
- lines = string.split(chars, "\n")
+ lines = chars.split("\n")
return head, tail, chars, lines
def set_region(self, head, tail, chars, lines):
text = self.text
- newchars = string.join(lines, "\n")
+ newchars = "\n".join(lines)
if newchars == chars:
text.bell()
return
diff --git a/Tools/idle/Bindings.py b/Tools/idle/Bindings.py
index 8bf0e704c4b..a7d3802eb99 100644
--- a/Tools/idle/Bindings.py
+++ b/Tools/idle/Bindings.py
@@ -6,7 +6,6 @@
# Debug menu here, which is only present in the PythonShell window.
import sys
-import string
from keydefs import *
menudefs = [
diff --git a/Tools/idle/CallTips.py b/Tools/idle/CallTips.py
index dc25083e7eb..d8445a432bf 100644
--- a/Tools/idle/CallTips.py
+++ b/Tools/idle/CallTips.py
@@ -141,7 +141,7 @@ def get_arg_text(ob):
items.append("...")
if fob.func_code.co_flags & 0x8:
items.append("***")
- argText = string.join(items , ", ")
+ argText = ", ".join(items)
argText = "(%s)" % argText
except:
pass
diff --git a/Tools/idle/ClassBrowser.py b/Tools/idle/ClassBrowser.py
index 19f3b7e6003..6e4b2a32eea 100644
--- a/Tools/idle/ClassBrowser.py
+++ b/Tools/idle/ClassBrowser.py
@@ -12,7 +12,6 @@
import os
import sys
-import string
import pyclbr
# XXX Patch pyclbr with dummies if it's vintage Python 1.5.2:
@@ -117,7 +116,7 @@ def listclasses(self):
if sup.module != cl.module:
sname = "%s.%s" % (sup.module, sname)
supers.append(sname)
- s = s + "(%s)" % string.join(supers, ", ")
+ s = s + "(%s)" % ", ".join(supers)
items.append((cl.lineno, s))
self.classes[s] = cl
items.sort()
diff --git a/Tools/idle/ColorDelegator.py b/Tools/idle/ColorDelegator.py
index 3d2ecefe97d..059108f65c9 100644
--- a/Tools/idle/ColorDelegator.py
+++ b/Tools/idle/ColorDelegator.py
@@ -1,5 +1,4 @@
import time
-import string
import re
import keyword
from Tkinter import *
@@ -14,7 +13,7 @@
def any(name, list):
- return "(?P<%s>" % name + string.join(list, "|") + ")"
+ return "(?P<%s>" % name + "|".join(list) + ")"
def make_pat():
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
diff --git a/Tools/idle/EditorWindow.py b/Tools/idle/EditorWindow.py
index e8b63ffde27..c0ae556d3a6 100644
--- a/Tools/idle/EditorWindow.py
+++ b/Tools/idle/EditorWindow.py
@@ -1,6 +1,5 @@
import sys
import os
-import string
import re
import imp
from Tkinter import *
@@ -221,7 +220,7 @@ def set_status_bar(self):
self.text.after_idle(self.set_line_and_column)
def set_line_and_column(self, event=None):
- line, column = string.split(self.text.index(INSERT), '.')
+ line, column = self.text.index(INSERT).split('.')
self.status_bar.set_label('column', 'Col: %s' % column)
self.status_bar.set_label('line', 'Ln: %s' % line)
@@ -344,14 +343,14 @@ def open_module(self, event=None):
except TclError:
name = ""
else:
- name = string.strip(name)
+ name = name.strip()
if not name:
name = tkSimpleDialog.askstring("Module",
"Enter the name of a Python module\n"
"to search on sys.path and open:",
parent=self.text)
if name:
- name = string.strip(name)
+ name = name.strip()
if not name:
return
# XXX Ought to insert current file's directory in front of path
@@ -408,7 +407,7 @@ def ispythonsource(self, filename):
f.close()
except IOError:
return False
- return line[:2] == '#!' and string.find(line, 'python') >= 0
+ return line.startswith('#!') and 'python' in line
def close_hook(self):
if self.flist:
@@ -580,7 +579,7 @@ def load_extension(self, name):
if keydefs:
self.apply_bindings(keydefs)
for vevent in keydefs.keys():
- methodname = string.replace(vevent, "-", "_")
+ methodname = vevent.replace("-", "_")
while methodname[:1] == '<':
methodname = methodname[1:]
while methodname[-1:] == '>':
@@ -700,7 +699,7 @@ def set_tabwidth(self, newtabwidth):
def prepstr(s):
# Helper to extract the underscore from a string, e.g.
# prepstr("Co_py") returns (2, "Copy").
- i = string.find(s, '_')
+ i = s.find('_')
if i >= 0:
s = s[:i] + s[i+1:]
return i, s
@@ -717,7 +716,7 @@ def get_accelerator(keydefs, event):
if not keylist:
return ""
s = keylist[0]
- s = re.sub(r"-[a-z]\b", lambda m: string.upper(m.group()), s)
+ s = re.sub(r"-[a-z]\b", lambda m: m.group().upper(), s)
s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
s = re.sub("Key-", "", s)
s = re.sub("Control-", "Ctrl-", s)
diff --git a/Tools/idle/FormatParagraph.py b/Tools/idle/FormatParagraph.py
index ea18cc056dd..c1bc769c22e 100644
--- a/Tools/idle/FormatParagraph.py
+++ b/Tools/idle/FormatParagraph.py
@@ -14,7 +14,6 @@
# spaces, they will not be considered part of the same block.
# * Fancy comments, like this bulleted list, arent handled :-)
-import string
import re
class FormatParagraph:
@@ -50,14 +49,14 @@ def format_paragraph_event(self, event):
find_paragraph(text, text.index("insert"))
if comment_header:
# Reformat the comment lines - convert to text sans header.
- lines = string.split(data, "\n")
+ lines = data.split("\n")
lines = map(lambda st, l=len(comment_header): st[l:], lines)
- data = string.join(lines, "\n")
+ data = "\n".join(lines)
# Reformat to 70 chars or a 20 char width, whichever is greater.
format_width = max(70-len(comment_header), 20)
newdata = reformat_paragraph(data, format_width)
# re-split and re-insert the comment header.
- newdata = string.split(newdata, "\n")
+ newdata = newdata.split("\n")
# If the block ends in a \n, we dont want the comment
# prefix inserted after it. (Im not sure it makes sense to
# reformat a comment block that isnt made of complete
@@ -68,7 +67,7 @@ def format_paragraph_event(self, event):
block_suffix = "\n"
newdata = newdata[:-1]
builder = lambda item, prefix=comment_header: prefix+item
- newdata = string.join(map(builder, newdata), '\n') + block_suffix
+ newdata = '\n'.join(map(builder, newdata)) + block_suffix
else:
# Just a normal text format
newdata = reformat_paragraph(data)
@@ -84,7 +83,7 @@ def format_paragraph_event(self, event):
text.see("insert")
def find_paragraph(text, mark):
- lineno, col = map(int, string.split(mark, "."))
+ lineno, col = map(int, mark.split("."))
line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
lineno = lineno + 1
@@ -109,7 +108,7 @@ def find_paragraph(text, mark):
return first, last, comment_header, text.get(first, last)
def reformat_paragraph(data, limit=70):
- lines = string.split(data, "\n")
+ lines = data.split("\n")
i = 0
n = len(lines)
while i < n and is_all_white(lines[i]):
@@ -130,18 +129,18 @@ def reformat_paragraph(data, limit=70):
word = words[j]
if not word:
continue # Can happen when line ends in whitespace
- if len(string.expandtabs(partial + word)) > limit and \
+ if len((partial + word).expandtabs()) > limit and \
partial != indent1:
- new.append(string.rstrip(partial))
+ new.append(partial.rstrip())
partial = indent2
partial = partial + word + " "
if j+1 < len(words) and words[j+1] != " ":
partial = partial + " "
i = i+1
- new.append(string.rstrip(partial))
+ new.append(partial.rstrip())
# XXX Should reformat remaining paragraphs as well
new.extend(lines[i:])
- return string.join(new, "\n")
+ return "\n".join(new)
def is_all_white(line):
return re.match(r"^\s*$", line) is not None
diff --git a/Tools/idle/GrepDialog.py b/Tools/idle/GrepDialog.py
index 61c77c34938..ed5a9791b8b 100644
--- a/Tools/idle/GrepDialog.py
+++ b/Tools/idle/GrepDialog.py
@@ -1,4 +1,3 @@
-import string
import os
import re
import fnmatch
diff --git a/Tools/idle/IdleHistory.py b/Tools/idle/IdleHistory.py
index b882c92c152..46e70e12248 100644
--- a/Tools/idle/IdleHistory.py
+++ b/Tools/idle/IdleHistory.py
@@ -1,5 +1,3 @@
-import string
-
class History:
def __init__(self, text, output_sep = "\n"):
@@ -22,11 +20,11 @@ def history_prev(self, event):
def _get_source(self, start, end):
# Get source code from start index to end index. Lines in the
# text control may be separated by sys.ps2 .
- lines = string.split(self.text.get(start, end), self.output_sep)
- return string.join(lines, "\n")
+ lines = self.text.get(start, end).split(self.output_sep)
+ return "\n".join(lines)
def _put_source(self, where, source):
- output = string.join(string.split(source, "\n"), self.output_sep)
+ output = self.output_sep.join(source.split("\n"))
self.text.insert(where, output)
def history_do(self, reverse):
@@ -68,7 +66,7 @@ def history_do(self, reverse):
self.history_prefix = prefix
def history_store(self, source):
- source = string.strip(source)
+ source = source.strip()
if len(source) > 2:
# avoid duplicates
try:
@@ -80,7 +78,7 @@ def history_store(self, source):
self.history_prefix = None
def recall(self, s):
- s = string.strip(s)
+ s = s.strip()
self.text.tag_remove("sel", "1.0", "end")
self.text.delete("iomark", "end-1c")
self.text.mark_set("insert", "end-1c")
diff --git a/Tools/idle/MultiScrolledLists.py b/Tools/idle/MultiScrolledLists.py
index 6c140df4514..6398b86dd38 100644
--- a/Tools/idle/MultiScrolledLists.py
+++ b/Tools/idle/MultiScrolledLists.py
@@ -3,7 +3,6 @@
# the right list displays the substructure of the selected item
# in the left list.
-import string
from Tkinter import *
from WindowList import ListedToplevel
from Separator import HSeparator
diff --git a/Tools/idle/OldStackViewer.py b/Tools/idle/OldStackViewer.py
index 2fa41275a1f..4f295e8dbeb 100644
--- a/Tools/idle/OldStackViewer.py
+++ b/Tools/idle/OldStackViewer.py
@@ -1,4 +1,3 @@
-import string
import sys
import os
from Tkinter import *
@@ -121,7 +120,7 @@ def load_stack(self, stack, index=None):
filename = code.co_filename
funcname = code.co_name
sourceline = linecache.getline(filename, lineno)
- sourceline = string.strip(sourceline)
+ sourceline = sourceline.strip()
if funcname in ("?", "", None):
item = "%s, line %d: %s" % (modname, lineno, sourceline)
else:
diff --git a/Tools/idle/ParenMatch.py b/Tools/idle/ParenMatch.py
index 17d76c2659c..1be60c0fdab 100644
--- a/Tools/idle/ParenMatch.py
+++ b/Tools/idle/ParenMatch.py
@@ -10,8 +10,6 @@
extensions what to capture the same event.
"""
-import string
-
import PyParse
from AutoIndent import AutoIndent, index2line
from IdleConf import idleconf
@@ -177,10 +175,10 @@ def find(self, right_keysym_type):
if i is None \
or keysym_type(buf[i]) != right_keysym_type:
return None
- lines_back = string.count(buf[i:], "\n") - 1
+ lines_back = buf[i:].count("\n") - 1
# subtract one for the "\n" added to please the parser
upto_open = buf[:i]
- j = string.rfind(upto_open, "\n") + 1 # offset of column 0 of line
+ j = upto_open.rfind("\n") + 1 # offset of column 0 of line
offset = i - j
return "%d.%d" % (lno - lines_back, offset)
diff --git a/Tools/idle/PyParse.py b/Tools/idle/PyParse.py
index c8212b21436..422a86cc76a 100644
--- a/Tools/idle/PyParse.py
+++ b/Tools/idle/PyParse.py
@@ -1,4 +1,3 @@
-import string
import re
import sys
@@ -7,7 +6,7 @@
if 0: # for throwaway debugging output
def dump(*stuff):
- sys.__stdout__.write(string.join(map(str, stuff), " ") + "\n")
+ sys.__stdout__.write(" ".join(map(str, stuff)) + "\n")
# Find what looks like the start of a popular stmt.
@@ -103,7 +102,7 @@ def dump(*stuff):
_tran[ord(ch)] = ')'
for ch in "\"'\\\n#":
_tran[ord(ch)] = ch
-_tran = string.join(_tran, '')
+_tran = ''.join(_tran)
del ch
try:
@@ -153,13 +152,12 @@ def set_str(self, str):
# Python 1.5.2 (#0, Apr 13 1999, ...
def find_good_parse_start(self, use_ps1, is_char_in_string=None,
- _rfind=string.rfind,
_synchre=_synchre):
str, pos = self.str, None
if use_ps1:
# shell window
ps1 = '\n' + sys.ps1
- i = _rfind(str, ps1)
+ i = str.rfind(ps1)
if i >= 0:
pos = i + len(ps1)
# make it look like there's a newline instead
@@ -178,10 +176,10 @@ def find_good_parse_start(self, use_ps1, is_char_in_string=None,
# bumped to a legitimate synch point.
limit = len(str)
for tries in range(5):
- i = _rfind(str, ":\n", 0, limit)
+ i = str.rfind(":\n", 0, limit)
if i < 0:
break
- i = _rfind(str, '\n', 0, i) + 1 # start of colon line
+ i = str.rfind('\n', 0, i) + 1 # start of colon line
m = _synchre(str, i, limit)
if m and not is_char_in_string(m.start()):
pos = m.start()
@@ -226,7 +224,7 @@ def set_lo(self, lo):
# based) of the non-continuation lines.
# Creates self.{goodlines, continuation}.
- def _study1(self, _replace=string.replace, _find=string.find):
+ def _study1(self):
if self.study_level >= 1:
return
self.study_level = 1
@@ -236,12 +234,12 @@ def _study1(self, _replace=string.replace, _find=string.find):
# uninteresting characters. This can cut the number of chars
# by a factor of 10-40, and so greatly speed the following loop.
str = self.str
- str = string.translate(str, _tran)
- str = _replace(str, 'xxxxxxxx', 'x')
- str = _replace(str, 'xxxx', 'x')
- str = _replace(str, 'xx', 'x')
- str = _replace(str, 'xx', 'x')
- str = _replace(str, '\nx', '\n')
+ str = str.translate(_tran)
+ str = str.replace('xxxxxxxx', 'x')
+ str = str.replace('xxxx', 'x')
+ str = str.replace('xx', 'x')
+ str = str.replace('xx', 'x')
+ str = str.replace('\nx', '\n')
# note that replacing x\n with \n would be incorrect, because
# x may be preceded by a backslash
@@ -322,7 +320,7 @@ def _study1(self, _replace=string.replace, _find=string.find):
if ch == '#':
# consume the comment
- i = _find(str, '\n', i)
+ i = str.find('\n', i)
assert i >= 0
continue
@@ -363,8 +361,7 @@ def get_continuation_type(self):
# self.lastopenbracketpos
# if continuation is C_BRACKET, index of last open bracket
- def _study2(self, _rfind=string.rfind, _find=string.find,
- _ws=string.whitespace):
+ def _study2(self):
if self.study_level >= 2:
return
self._study1()
@@ -381,7 +378,7 @@ def _study2(self, _rfind=string.rfind, _find=string.find,
q = p
for nothing in range(goodlines[i-1], goodlines[i]):
# tricky: sets p to 0 if no preceding newline
- p = _rfind(str, '\n', 0, p-1) + 1
+ p = str.rfind('\n', 0, p-1) + 1
# The stmt str[p:q] isn't a continuation, but may be blank
# or a non-indenting comment line.
if _junkre(str, p):
@@ -444,7 +441,7 @@ def _study2(self, _rfind=string.rfind, _find=string.find,
if ch == '#':
# consume comment and trailing newline
- p = _find(str, '\n', p, q) + 1
+ p = str.find('\n', p, q) + 1
assert p > 0
continue
@@ -465,13 +462,13 @@ def _study2(self, _rfind=string.rfind, _find=string.find,
# Assuming continuation is C_BRACKET, return the number
# of spaces the next line should be indented.
- def compute_bracket_indent(self, _find=string.find):
+ def compute_bracket_indent(self):
self._study2()
assert self.continuation == C_BRACKET
j = self.lastopenbracketpos
str = self.str
n = len(str)
- origi = i = string.rfind(str, '\n', 0, j) + 1
+ origi = i = str.rfind('\n', 0, j) + 1
j = j+1 # one beyond open bracket
# find first list item; set i to start of its line
while j < n:
@@ -482,7 +479,7 @@ def compute_bracket_indent(self, _find=string.find):
break
else:
# this line is junk; advance to next line
- i = j = _find(str, '\n', j) + 1
+ i = j = str.find('\n', j) + 1
else:
# nothing interesting follows the bracket;
# reproduce the bracket line's indentation + a level
@@ -490,8 +487,7 @@ def compute_bracket_indent(self, _find=string.find):
while str[j] in " \t":
j = j+1
extra = self.indentwidth
- return len(string.expandtabs(str[i:j],
- self.tabwidth)) + extra
+ return len(str[i:j].expandtabs(self.tabwidth)) + extra
# Return number of physical lines in last stmt (whether or not
# it's an interesting stmt! this is intended to be called when
@@ -517,7 +513,7 @@ def compute_backslash_indent(self):
# See whether the initial line starts an assignment stmt; i.e.,
# look for an = operator
- endpos = string.find(str, '\n', startpos) + 1
+ endpos = str.find('\n', startpos) + 1
found = level = 0
while i < endpos:
ch = str[i]
@@ -553,8 +549,7 @@ def compute_backslash_indent(self):
while str[i] not in " \t\n":
i = i+1
- return len(string.expandtabs(str[self.stmt_start :
- i],
+ return len(str[self.stmt_start:i].expandtabs(\
self.tabwidth)) + 1
# Return the leading whitespace on the initial line of the last
diff --git a/Tools/idle/PyShell.py b/Tools/idle/PyShell.py
index e71a9a17a5f..7fd28eba21a 100644
--- a/Tools/idle/PyShell.py
+++ b/Tools/idle/PyShell.py
@@ -208,7 +208,7 @@ def stuffsource(self, source):
# Stuff source in the filename cache
filename = "