/* * tclStringRep.h -- * * This file contains the definition of internal representations of a string * and macros to access it. * * Conceptually, a string is a sequence of Unicode code points. Internally * it may be stored in an encoding form such as a modified version of UTF-8 * or UTF-32. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright (c) 1999 by Scriptics Corporation. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #ifndef _TCLSTRINGREP #define _TCLSTRINGREP /* * The following structure is the internal rep for a String object. It keeps * track of how much memory has been used and how much has been allocated for * the various representations to enable growing and shrinking of * the String object with fewer mallocs. To optimize string * length and indexing operations, this structure also stores the number of * code points (independent of encoding form) once that value has been computed. */ typedef struct { Tcl_Size numChars; /* The number of chars in the string. * TCL_INDEX_NONE means this value has not been * calculated. Any other means that there is a valid * Unicode rep, or that the number of UTF bytes == * the number of chars. */ Tcl_Size allocated; /* The amount of space allocated for * the UTF-8 string. Does not include nul * terminator so actual allocation is * (allocated+1). */ Tcl_Size maxChars; /* Max number of chars that can fit in the * space allocated for the Unicode array. */ int hasUnicode; /* Boolean determining whether the string has * a Tcl_UniChar representation. */ Tcl_UniChar unicode[TCLFLEXARRAY]; /* The array of Tcl_UniChar units. * The actual size of this field depends on * the maxChars field above. */ } String; /* Limit on string lengths. The -1 because limit does not include the nul */ #define STRING_MAXCHARS \ ((Tcl_Size)((TCL_SIZE_MAX - offsetof(String, unicode))/sizeof(Tcl_UniChar) - 1)) /* Memory needed to hold a string of length numChars - including NUL */ #define STRING_SIZE(numChars) \ (offsetof(String, unicode) + sizeof(Tcl_UniChar) + ((numChars) * sizeof(Tcl_UniChar))) #define stringAttemptAlloc(numChars) \ (String *) Tcl_AttemptAlloc(STRING_SIZE(numChars)) #define stringAlloc(numChars) \ (String *) Tcl_Alloc(STRING_SIZE(numChars)) #define stringRealloc(ptr, numChars) \ (String *) Tcl_Realloc((ptr), STRING_SIZE(numChars)) #define stringAttemptRealloc(ptr, numChars) \ (String *) Tcl_AttemptRealloc((ptr), STRING_SIZE(numChars)) #define GET_STRING(objPtr) \ ((String *) (objPtr)->internalRep.twoPtrValue.ptr1) #define SET_STRING(objPtr, stringPtr) \ ((objPtr)->internalRep.twoPtrValue.ptr2 = NULL), \ ((objPtr)->internalRep.twoPtrValue.ptr1 = (void *) (stringPtr)) #endif /* _TCLSTRINGREP */ /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */ Tools/scripts/objgraph.py | 1 - Tools/scripts/pathfix.py | 5 ++-- Tools/scripts/pdeps.py | 7 ++--- Tools/scripts/pindent.py | 11 ++++--- Tools/scripts/rgrep.py | 3 +- Tools/scripts/sum5.py | 3 +- Tools/scripts/trace.py | 23 +++++++-------- Tools/scripts/treesync.py | 8 +++--- Tools/scripts/untabify.py | 3 +- Tools/scripts/which.py | 4 +-- Tools/scripts/xxci.py | 3 +- Tools/unicode/makeunicodedata.py | 14 ++++----- Tools/versioncheck/checkversions.py | 3 +- Tools/versioncheck/pyversioncheck.py | 5 ++-- Tools/webchecker/tktools.py | 5 ++-- Tools/webchecker/wcgui.py | 9 +++--- Tools/webchecker/webchecker.py | 19 ++++++------ Tools/webchecker/websucker.py | 9 +++--- Tools/webchecker/wsgui.py | 7 ++--- 70 files changed, 271 insertions(+), 346 deletions(-) diff --git a/Tools/audiopy/audiopy b/Tools/audiopy/audiopy index f5a1021..b817c5c 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 aa39668..1c19388 100644 --- a/Tools/bgen/bgen/bgenGenerator.py +++ b/Tools/bgen/bgen/bgenGenerator.py @@ -131,7 +131,6 @@ class FunctionGenerator(BaseFunctionGenerator): self.argumentList.append(arg) def docstring(self): - import string input = [] output = [] for arg in self.argumentList: @@ -156,11 +155,11 @@ class FunctionGenerator(BaseFunctionGenerator): 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 a269585..c7e560c 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 205a1ce..61c2f37 100644 --- a/Tools/bgen/bgen/scantools.py +++ b/Tools/bgen/bgen/scantools.py @@ -15,7 +15,6 @@ although most Mac specific details are contained in header-specific subclasses. """ import re -import string import sys import os import fnmatch @@ -67,8 +66,8 @@ class Scanner: 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 @@ if missing: raise "Missing Types" 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 @@ if missing: raise "Missing Types" 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 @@ if missing: raise "Missing Types" 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 @@ if missing: raise "Missing Types" 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 @@ if missing: raise "Missing Types" 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 @@ if missing: raise "Missing Types" # 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 @@ if missing: raise "Missing Types" 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 2e2a8b5..e91d4dc 100644 --- a/Tools/faqwiz/faqwiz.py +++ b/Tools/faqwiz/faqwiz.py @@ -11,7 +11,7 @@ The actual script to place in cgi-bin is faqw.py. """ -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 @@ class NoSuchFile(FileError): 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 @@ class UserInput: except (TypeError, KeyError): value = '' else: - value = string.strip(value) + value = value.strip() setattr(self, name, value) return value @@ -209,7 +209,7 @@ class FaqEntry: 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 @@ class FaqEntry: 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 @@ class FaqEntry: 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 @@ class FaqEntry: 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 @@ class FaqEntry: 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 @@ class FaqDir: 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 @@ class FaqWizard: 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 @@ class FaqWizard: 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 @@ class FaqWizard: 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 @@ class FaqWizard:
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 @@ class FaqWizard:
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 @@ class FaqWizard:
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 @@ class FaqWizard:
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 8d597bf..584f8a6 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 85c3a3c..669a142 100644
--- a/Tools/freeze/checkextensions_win32.py
+++ b/Tools/freeze/checkextensions_win32.py
@@ -22,7 +22,7 @@ At the moment the name and location of this INI file is hardcoded,
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 0b9b206..2c59807 100755
--- a/Tools/freeze/freeze.py
+++ b/Tools/freeze/freeze.py
@@ -91,7 +91,6 @@ if it does, the resulting binary is not self-contained.
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 3888050..29a6ad6 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 e33e32e..b8b99b8 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 741ef4d..e9c1140 100644
--- a/Tools/freeze/modulefinder.py
+++ b/Tools/freeze/modulefinder.py
@@ -5,7 +5,6 @@ import imp
import marshal
import os
import re
-import string
import sys
import new
@@ -150,7 +149,7 @@ class ModuleFinder:
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 @@ class ModuleFinder:
def find_head_pac