mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
String method conversion.
This commit is contained in:
parent
d8c628bd59
commit
fc170b1fd5
19 changed files with 58 additions and 79 deletions
|
@ -9,7 +9,7 @@ in the distutils.command package.
|
||||||
|
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import sys, os, string, re
|
import sys, os, re
|
||||||
from types import *
|
from types import *
|
||||||
from distutils.errors import *
|
from distutils.errors import *
|
||||||
from distutils import util, dir_util, file_util, archive_util, dep_util
|
from distutils import util, dir_util, file_util, archive_util, dep_util
|
||||||
|
@ -161,7 +161,7 @@ class Command:
|
||||||
print indent + header
|
print indent + header
|
||||||
indent = indent + " "
|
indent = indent + " "
|
||||||
for (option, _, _) in self.user_options:
|
for (option, _, _) in self.user_options:
|
||||||
option = string.translate(option, longopt_xlate)
|
option = option.translate(longopt_xlate)
|
||||||
if option[-1] == "=":
|
if option[-1] == "=":
|
||||||
option = option[:-1]
|
option = option[:-1]
|
||||||
value = getattr(self, option)
|
value = getattr(self, option)
|
||||||
|
@ -421,7 +421,7 @@ class Command:
|
||||||
"""
|
"""
|
||||||
if exec_msg is None:
|
if exec_msg is None:
|
||||||
exec_msg = "generating %s from %s" % \
|
exec_msg = "generating %s from %s" % \
|
||||||
(outfile, string.join(infiles, ', '))
|
(outfile, ', '.join(infiles))
|
||||||
if skip_msg is None:
|
if skip_msg is None:
|
||||||
skip_msg = "skipping %s (inputs unchanged)" % outfile
|
skip_msg = "skipping %s (inputs unchanged)" % outfile
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ def getcodename(co):
|
||||||
if ord(code[0]) == SET_LINENO:
|
if ord(code[0]) == SET_LINENO:
|
||||||
lineno = ord(code[1]) | ord(code[2]) << 8
|
lineno = ord(code[1]) | ord(code[2]) << 8
|
||||||
line = linecache.getline(filename, lineno)
|
line = linecache.getline(filename, lineno)
|
||||||
words = string.split(line)
|
words = line.split()
|
||||||
if len(words) >= 2 and words[0] in ('def', 'class'):
|
if len(words) >= 2 and words[0] in ('def', 'class'):
|
||||||
name = words[1]
|
name = words[1]
|
||||||
for i in range(len(name)):
|
for i in range(len(name)):
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import regex
|
import regex
|
||||||
from regex_syntax import *
|
from regex_syntax import *
|
||||||
import string
|
|
||||||
|
|
||||||
opt_show_where = 0
|
opt_show_where = 0
|
||||||
opt_show_filename = 0
|
opt_show_filename = 0
|
||||||
|
@ -59,7 +58,7 @@ def pgrep(pat, *files):
|
||||||
def showline(filename, lineno, line, prog):
|
def showline(filename, lineno, line, prog):
|
||||||
if line[-1:] == '\n': line = line[:-1]
|
if line[-1:] == '\n': line = line[:-1]
|
||||||
if opt_show_lineno:
|
if opt_show_lineno:
|
||||||
prefix = string.rjust(`lineno`, 3) + ': '
|
prefix = `lineno`.rjust(, 3) + ': '
|
||||||
else:
|
else:
|
||||||
prefix = ''
|
prefix = ''
|
||||||
if opt_show_filename:
|
if opt_show_filename:
|
||||||
|
|
|
@ -163,7 +163,6 @@ XXX Need to have an explicit name for '', e.g. '__root__'.
|
||||||
|
|
||||||
|
|
||||||
import imp
|
import imp
|
||||||
import string
|
|
||||||
import sys
|
import sys
|
||||||
import __builtin__
|
import __builtin__
|
||||||
|
|
||||||
|
@ -206,7 +205,7 @@ class PackageLoader(ModuleLoader):
|
||||||
def load_dynamic(self, name, stuff):
|
def load_dynamic(self, name, stuff):
|
||||||
file, filename, (suff, mode, type) = stuff
|
file, filename, (suff, mode, type) = stuff
|
||||||
# Hack around restriction in imp.load_dynamic()
|
# Hack around restriction in imp.load_dynamic()
|
||||||
i = string.rfind(name, '.')
|
i = name.rfind('.')
|
||||||
tail = name[i+1:]
|
tail = name[i+1:]
|
||||||
if sys.modules.has_key(tail):
|
if sys.modules.has_key(tail):
|
||||||
save = sys.modules[tail]
|
save = sys.modules[tail]
|
||||||
|
@ -241,7 +240,7 @@ class PackageLoader(ModuleLoader):
|
||||||
def set_parent(self, m):
|
def set_parent(self, m):
|
||||||
name = m.__name__
|
name = m.__name__
|
||||||
if '.' in name:
|
if '.' in name:
|
||||||
name = name[:string.rfind(name, '.')]
|
name = name[:name.rfind('.')]
|
||||||
else:
|
else:
|
||||||
name = ''
|
name = ''
|
||||||
m.__ = sys.modules[name]
|
m.__ = sys.modules[name]
|
||||||
|
@ -250,7 +249,7 @@ class PackageLoader(ModuleLoader):
|
||||||
name = package.__name__
|
name = package.__name__
|
||||||
package.__domain__ = domain = [name]
|
package.__domain__ = domain = [name]
|
||||||
while '.' in name:
|
while '.' in name:
|
||||||
name = name[:string.rfind(name, '.')]
|
name = name[:name.rfind('.')]
|
||||||
domain.append(name)
|
domain.append(name)
|
||||||
if name:
|
if name:
|
||||||
domain.append('')
|
domain.append('')
|
||||||
|
@ -285,7 +284,7 @@ class PackageImporter(ModuleImporter):
|
||||||
if not name:
|
if not name:
|
||||||
return self.finish(package, p, '', fromlist)
|
return self.finish(package, p, '', fromlist)
|
||||||
if '.' in name:
|
if '.' in name:
|
||||||
i = string.find(name, '.')
|
i = name.find('.')
|
||||||
name, tail = name[:i], name[i:]
|
name, tail = name[:i], name[i:]
|
||||||
else:
|
else:
|
||||||
tail = ''
|
tail = ''
|
||||||
|
@ -293,7 +292,7 @@ class PackageImporter(ModuleImporter):
|
||||||
m = self.get1(mname)
|
m = self.get1(mname)
|
||||||
return self.finish(package, m, tail, fromlist)
|
return self.finish(package, m, tail, fromlist)
|
||||||
if '.' in name:
|
if '.' in name:
|
||||||
i = string.find(name, '.')
|
i = name.find('.')
|
||||||
name, tail = name[:i], name[i:]
|
name, tail = name[:i], name[i:]
|
||||||
else:
|
else:
|
||||||
tail = ''
|
tail = ''
|
||||||
|
@ -312,7 +311,7 @@ class PackageImporter(ModuleImporter):
|
||||||
yname, tail = yname + tail, ''
|
yname, tail = yname + tail, ''
|
||||||
m = self.get1(yname)
|
m = self.get1(yname)
|
||||||
while tail:
|
while tail:
|
||||||
i = string.find(tail, '.', 1)
|
i = tail.find('.', 1)
|
||||||
if i > 0:
|
if i > 0:
|
||||||
head, tail = tail[:i], tail[i:]
|
head, tail = tail[:i], tail[i:]
|
||||||
else:
|
else:
|
||||||
|
@ -351,7 +350,7 @@ class PackageImporter(ModuleImporter):
|
||||||
if sys.modules.has_key(name):
|
if sys.modules.has_key(name):
|
||||||
return sys.modules[name]
|
return sys.modules[name]
|
||||||
if '.' in name:
|
if '.' in name:
|
||||||
i = string.rfind(name, '.')
|
i = name.rfind('.')
|
||||||
head, tail = name[:i], name[i+1:]
|
head, tail = name[:i], name[i+1:]
|
||||||
else:
|
else:
|
||||||
head, tail = '', name
|
head, tail = '', name
|
||||||
|
@ -367,7 +366,7 @@ class PackageImporter(ModuleImporter):
|
||||||
def reload(self, module):
|
def reload(self, module):
|
||||||
name = module.__name__
|
name = module.__name__
|
||||||
if '.' in name:
|
if '.' in name:
|
||||||
i = string.rfind(name, '.')
|
i = name.rfind('.')
|
||||||
head, tail = name[:i], name[i+1:]
|
head, tail = name[:i], name[i+1:]
|
||||||
path = sys.modules[head].__path__
|
path = sys.modules[head].__path__
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from stat import ST_MTIME
|
from stat import ST_MTIME
|
||||||
import string
|
|
||||||
|
|
||||||
# Print help
|
# Print help
|
||||||
def help():
|
def help():
|
||||||
|
@ -103,7 +102,7 @@ def packtree(outfp, dirname):
|
||||||
packtree(outfp, subdirname)
|
packtree(outfp, subdirname)
|
||||||
|
|
||||||
def unixfix(name):
|
def unixfix(name):
|
||||||
comps = string.splitfields(name, os.sep)
|
comps = name.splitfields(os.sep)
|
||||||
res = ''
|
res = ''
|
||||||
for comp in comps:
|
for comp in comps:
|
||||||
if comp:
|
if comp:
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from stat import *
|
from stat import *
|
||||||
import string
|
|
||||||
import linecache
|
import linecache
|
||||||
|
|
||||||
def br(): browser(sys.last_traceback)
|
def br(): browser(sys.last_traceback)
|
||||||
|
@ -35,7 +34,7 @@ def browser(tb):
|
||||||
except EOFError:
|
except EOFError:
|
||||||
print '\n[EOF]'
|
print '\n[EOF]'
|
||||||
break
|
break
|
||||||
cmd = string.strip(line)
|
cmd = line.strip()
|
||||||
if cmd:
|
if cmd:
|
||||||
if cmd == 'quit':
|
if cmd == 'quit':
|
||||||
break
|
break
|
||||||
|
@ -62,8 +61,8 @@ def browserlist(tb):
|
||||||
last = lineno
|
last = lineno
|
||||||
first = max(1, last-10)
|
first = max(1, last-10)
|
||||||
for i in range(first, last+1):
|
for i in range(first, last+1):
|
||||||
if i == lineno: prefix = '***' + string.rjust(`i`, 4) + ':'
|
if i == lineno: prefix = '***' + `i`.rjust(4) + ':'
|
||||||
else: prefix = string.rjust(`i`, 7) + ':'
|
else: prefix = `i`.rjust(7) + ':'
|
||||||
line = linecache.getline(filename, i)
|
line = linecache.getline(filename, i)
|
||||||
if line[-1:] == '\n': line = line[:-1]
|
if line[-1:] == '\n': line = line[:-1]
|
||||||
print prefix + line
|
print prefix + line
|
||||||
|
@ -115,14 +114,14 @@ def printtbheader(tb):
|
||||||
info = '"' + filename + '"(' + `lineno` + ')'
|
info = '"' + filename + '"(' + `lineno` + ')'
|
||||||
line = linecache.getline(filename, lineno)
|
line = linecache.getline(filename, lineno)
|
||||||
if line:
|
if line:
|
||||||
info = info + ': ' + string.strip(line)
|
info = info + ': ' + line.strip()
|
||||||
print info
|
print info
|
||||||
|
|
||||||
def printsymbols(d):
|
def printsymbols(d):
|
||||||
keys = d.keys()
|
keys = d.keys()
|
||||||
keys.sort()
|
keys.sort()
|
||||||
for name in keys:
|
for name in keys:
|
||||||
print ' ' + string.ljust(name, 12) + ':',
|
print ' ' + name.ljust(12) + ':',
|
||||||
printobject(d[name], 4)
|
printobject(d[name], 4)
|
||||||
print
|
print
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,13 @@ tkinter = _tkinter # b/w compat for export
|
||||||
TclError = _tkinter.TclError
|
TclError = _tkinter.TclError
|
||||||
from types import *
|
from types import *
|
||||||
from Tkconstants import *
|
from Tkconstants import *
|
||||||
import string; _string = string; del string
|
|
||||||
try:
|
try:
|
||||||
import MacOS; _MacOS = MacOS; del MacOS
|
import MacOS; _MacOS = MacOS; del MacOS
|
||||||
except ImportError:
|
except ImportError:
|
||||||
_MacOS = None
|
_MacOS = None
|
||||||
|
|
||||||
TkVersion = _string.atof(_tkinter.TK_VERSION)
|
TkVersion = float(_tkinter.TK_VERSION)
|
||||||
TclVersion = _string.atof(_tkinter.TCL_VERSION)
|
TclVersion = float(_tkinter.TCL_VERSION)
|
||||||
|
|
||||||
READABLE = _tkinter.READABLE
|
READABLE = _tkinter.READABLE
|
||||||
WRITABLE = _tkinter.WRITABLE
|
WRITABLE = _tkinter.WRITABLE
|
||||||
|
@ -782,7 +781,7 @@ class Misc:
|
||||||
return t[:1] + tuple(map(self.__winfo_getint, t[1:]))
|
return t[:1] + tuple(map(self.__winfo_getint, t[1:]))
|
||||||
def __winfo_getint(self, x):
|
def __winfo_getint(self, x):
|
||||||
"""Internal function."""
|
"""Internal function."""
|
||||||
return _string.atoi(x, 0)
|
return int(x, 0)
|
||||||
def winfo_vrootheight(self):
|
def winfo_vrootheight(self):
|
||||||
"""Return the height of the virtual root window associated with this
|
"""Return the height of the virtual root window associated with this
|
||||||
widget in pixels. If there is no virtual root window return the
|
widget in pixels. If there is no virtual root window return the
|
||||||
|
@ -850,7 +849,7 @@ class Misc:
|
||||||
%
|
%
|
||||||
(add and '+' or '',
|
(add and '+' or '',
|
||||||
funcid,
|
funcid,
|
||||||
_string.join(self._subst_format)))
|
" ".join(self._subst_format)))
|
||||||
self.tk.call(what + (sequence, cmd))
|
self.tk.call(what + (sequence, cmd))
|
||||||
return funcid
|
return funcid
|
||||||
elif sequence:
|
elif sequence:
|
||||||
|
@ -972,9 +971,8 @@ class Misc:
|
||||||
if name[0] == '.':
|
if name[0] == '.':
|
||||||
w = w._root()
|
w = w._root()
|
||||||
name = name[1:]
|
name = name[1:]
|
||||||
find = _string.find
|
|
||||||
while name:
|
while name:
|
||||||
i = find(name, '.')
|
i = name.find('.')
|
||||||
if i >= 0:
|
if i >= 0:
|
||||||
name, tail = name[:i], name[i+1:]
|
name, tail = name[:i], name[i+1:]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
__version__ = "0.9"
|
__version__ = "0.9"
|
||||||
|
|
||||||
import Tkinter
|
import Tkinter
|
||||||
import string
|
|
||||||
|
|
||||||
# weight/slant
|
# weight/slant
|
||||||
NORMAL = "normal"
|
NORMAL = "normal"
|
||||||
|
@ -120,7 +119,7 @@ class Font:
|
||||||
|
|
||||||
def measure(self, text):
|
def measure(self, text):
|
||||||
"Return text width"
|
"Return text width"
|
||||||
return string.atoi(self._call("font", "measure", self.name, text))
|
return int(self._call("font", "measure", self.name, text))
|
||||||
|
|
||||||
def metrics(self, *options):
|
def metrics(self, *options):
|
||||||
"""Return font metrics.
|
"""Return font metrics.
|
||||||
|
@ -129,14 +128,14 @@ class Font:
|
||||||
using this font before calling this method."""
|
using this font before calling this method."""
|
||||||
|
|
||||||
if options:
|
if options:
|
||||||
return string.atoi(
|
return int(
|
||||||
self._call("font", "metrics", self.name, self._get(options))
|
self._call("font", "metrics", self.name, self._get(options))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
res = self._split(self._call("font", "metrics", self.name))
|
res = self._split(self._call("font", "metrics", self.name))
|
||||||
options = {}
|
options = {}
|
||||||
for i in range(0, len(res), 2):
|
for i in range(0, len(res), 2):
|
||||||
options[res[i][1:]] = string.atoi(res[i+1])
|
options[res[i][1:]] = int(res[i+1])
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def families(root=None):
|
def families(root=None):
|
||||||
|
|
|
@ -157,8 +157,6 @@ class Dialog(Toplevel):
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# convenience dialogues
|
# convenience dialogues
|
||||||
|
|
||||||
import string
|
|
||||||
|
|
||||||
class _QueryDialog(Dialog):
|
class _QueryDialog(Dialog):
|
||||||
|
|
||||||
def __init__(self, title, prompt,
|
def __init__(self, title, prompt,
|
||||||
|
@ -236,7 +234,7 @@ class _QueryDialog(Dialog):
|
||||||
class _QueryInteger(_QueryDialog):
|
class _QueryInteger(_QueryDialog):
|
||||||
errormessage = "Not an integer."
|
errormessage = "Not an integer."
|
||||||
def getresult(self):
|
def getresult(self):
|
||||||
return string.atoi(self.entry.get())
|
return int(self.entry.get())
|
||||||
|
|
||||||
def askinteger(title, prompt, **kw):
|
def askinteger(title, prompt, **kw):
|
||||||
'''get an integer from the user
|
'''get an integer from the user
|
||||||
|
@ -255,7 +253,7 @@ def askinteger(title, prompt, **kw):
|
||||||
class _QueryFloat(_QueryDialog):
|
class _QueryFloat(_QueryDialog):
|
||||||
errormessage = "Not a floating point value."
|
errormessage = "Not a floating point value."
|
||||||
def getresult(self):
|
def getresult(self):
|
||||||
return string.atof(self.entry.get())
|
return float(self.entry.get())
|
||||||
|
|
||||||
def askfloat(title, prompt, **kw):
|
def askfloat(title, prompt, **kw):
|
||||||
'''get a float from the user
|
'''get a float from the user
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
# XXX: show string offset and offending character for all errors
|
# XXX: show string offset and offending character for all errors
|
||||||
|
|
||||||
import string, sys
|
import sys
|
||||||
|
|
||||||
from sre_constants import *
|
from sre_constants import *
|
||||||
|
|
||||||
|
@ -60,12 +60,6 @@ FLAGS = {
|
||||||
"u": SRE_FLAG_UNICODE,
|
"u": SRE_FLAG_UNICODE,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
|
||||||
int("10", 8)
|
|
||||||
atoi = int
|
|
||||||
except TypeError:
|
|
||||||
atoi = string.atoi
|
|
||||||
|
|
||||||
class Pattern:
|
class Pattern:
|
||||||
# master pattern object. keeps track of global attributes
|
# master pattern object. keeps track of global attributes
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -222,7 +216,7 @@ def isname(name):
|
||||||
def _group(escape, groups):
|
def _group(escape, groups):
|
||||||
# check if the escape string represents a valid group
|
# check if the escape string represents a valid group
|
||||||
try:
|
try:
|
||||||
gid = atoi(escape[1:])
|
gid = int(escape[1:])
|
||||||
if gid and gid < groups:
|
if gid and gid < groups:
|
||||||
return gid
|
return gid
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -245,13 +239,13 @@ def _class_escape(source, escape):
|
||||||
escape = escape[2:]
|
escape = escape[2:]
|
||||||
if len(escape) != 2:
|
if len(escape) != 2:
|
||||||
raise error, "bogus escape: %s" % repr("\\" + escape)
|
raise error, "bogus escape: %s" % repr("\\" + escape)
|
||||||
return LITERAL, atoi(escape, 16) & 0xff
|
return LITERAL, int(escape, 16) & 0xff
|
||||||
elif str(escape[1:2]) in OCTDIGITS:
|
elif str(escape[1:2]) in OCTDIGITS:
|
||||||
# octal escape (up to three digits)
|
# octal escape (up to three digits)
|
||||||
while source.next in OCTDIGITS and len(escape) < 5:
|
while source.next in OCTDIGITS and len(escape) < 5:
|
||||||
escape = escape + source.get()
|
escape = escape + source.get()
|
||||||
escape = escape[1:]
|
escape = escape[1:]
|
||||||
return LITERAL, atoi(escape, 8) & 0xff
|
return LITERAL, int(escape, 8) & 0xff
|
||||||
if len(escape) == 2:
|
if len(escape) == 2:
|
||||||
return LITERAL, ord(escape[1])
|
return LITERAL, ord(escape[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -273,12 +267,12 @@ def _escape(source, escape, state):
|
||||||
escape = escape + source.get()
|
escape = escape + source.get()
|
||||||
if len(escape) != 4:
|
if len(escape) != 4:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
return LITERAL, atoi(escape[2:], 16) & 0xff
|
return LITERAL, int(escape[2:], 16) & 0xff
|
||||||
elif escape[1:2] == "0":
|
elif escape[1:2] == "0":
|
||||||
# octal escape
|
# octal escape
|
||||||
while source.next in OCTDIGITS and len(escape) < 4:
|
while source.next in OCTDIGITS and len(escape) < 4:
|
||||||
escape = escape + source.get()
|
escape = escape + source.get()
|
||||||
return LITERAL, atoi(escape[1:], 8) & 0xff
|
return LITERAL, int(escape[1:], 8) & 0xff
|
||||||
elif escape[1:2] in DIGITS:
|
elif escape[1:2] in DIGITS:
|
||||||
# octal escape *or* decimal group reference (sigh)
|
# octal escape *or* decimal group reference (sigh)
|
||||||
here = source.tell()
|
here = source.tell()
|
||||||
|
@ -288,7 +282,7 @@ def _escape(source, escape, state):
|
||||||
source.next in OCTDIGITS):
|
source.next in OCTDIGITS):
|
||||||
# got three octal digits; this is an octal escape
|
# got three octal digits; this is an octal escape
|
||||||
escape = escape + source.get()
|
escape = escape + source.get()
|
||||||
return LITERAL, atoi(escape[1:], 8) & 0xff
|
return LITERAL, int(escape[1:], 8) & 0xff
|
||||||
# got at least one decimal digit; this is a group reference
|
# got at least one decimal digit; this is a group reference
|
||||||
group = _group(escape, state.groups)
|
group = _group(escape, state.groups)
|
||||||
if group:
|
if group:
|
||||||
|
@ -462,9 +456,9 @@ def _parse(source, state):
|
||||||
source.seek(here)
|
source.seek(here)
|
||||||
continue
|
continue
|
||||||
if lo:
|
if lo:
|
||||||
min = atoi(lo)
|
min = int(lo)
|
||||||
if hi:
|
if hi:
|
||||||
max = atoi(hi)
|
max = int(hi)
|
||||||
if max < min:
|
if max < min:
|
||||||
raise error, "bad repeat interval"
|
raise error, "bad repeat interval"
|
||||||
else:
|
else:
|
||||||
|
@ -652,7 +646,7 @@ def parse_template(source, pattern):
|
||||||
if not name:
|
if not name:
|
||||||
raise error, "bad group name"
|
raise error, "bad group name"
|
||||||
try:
|
try:
|
||||||
index = atoi(name)
|
index = int(name)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if not isname(name):
|
if not isname(name):
|
||||||
raise error, "bad character in group name"
|
raise error, "bad character in group name"
|
||||||
|
@ -676,7 +670,7 @@ def parse_template(source, pattern):
|
||||||
break
|
break
|
||||||
if not code:
|
if not code:
|
||||||
this = this[1:]
|
this = this[1:]
|
||||||
code = LITERAL, atoi(this[-6:], 8) & 0xff
|
code = LITERAL, int(this[-6:], 8) & 0xff
|
||||||
a(code)
|
a(code)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -705,4 +699,4 @@ def expand_template(template, match):
|
||||||
if s is None:
|
if s is None:
|
||||||
raise error, "empty group"
|
raise error, "empty group"
|
||||||
a(s)
|
a(s)
|
||||||
return string.join(p, sep)
|
return sep.join(p)
|
||||||
|
|
|
@ -32,7 +32,6 @@ of /tmp).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import string
|
|
||||||
import os
|
import os
|
||||||
import getopt
|
import getopt
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -106,7 +105,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
|
||||||
filename = os.path.join(gettempdir(), 'pynexttest')
|
filename = os.path.join(gettempdir(), 'pynexttest')
|
||||||
try:
|
try:
|
||||||
fp = open(filename, 'r')
|
fp = open(filename, 'r')
|
||||||
next = string.strip(fp.read())
|
next = fp.read().strip()
|
||||||
tests = [next]
|
tests = [next]
|
||||||
fp.close()
|
fp.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
|
@ -163,10 +162,10 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
|
||||||
print "that passes in verbose mode may fail without it."
|
print "that passes in verbose mode may fail without it."
|
||||||
if bad:
|
if bad:
|
||||||
print count(len(bad), "test"), "failed:",
|
print count(len(bad), "test"), "failed:",
|
||||||
print string.join(bad)
|
print " ".join(bad)
|
||||||
if skipped and not quiet:
|
if skipped and not quiet:
|
||||||
print count(len(skipped), "test"), "skipped:",
|
print count(len(skipped), "test"), "skipped:",
|
||||||
print string.join(skipped)
|
print " ".join(skipped)
|
||||||
|
|
||||||
if single:
|
if single:
|
||||||
alltests = findtests(testdir, stdtests, nottests)
|
alltests = findtests(testdir, stdtests, nottests)
|
||||||
|
|
|
@ -112,16 +112,15 @@ def main():
|
||||||
Extra arguments are used to seed the random generator.
|
Extra arguments are used to seed the random generator.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import string
|
|
||||||
# default range (inclusive)
|
# default range (inclusive)
|
||||||
k1 = 15
|
k1 = 15
|
||||||
k2 = 19
|
k2 = 19
|
||||||
if sys.argv[1:]:
|
if sys.argv[1:]:
|
||||||
# one argument: single point
|
# one argument: single point
|
||||||
k1 = k2 = string.atoi(sys.argv[1])
|
k1 = k2 = int(sys.argv[1])
|
||||||
if sys.argv[2:]:
|
if sys.argv[2:]:
|
||||||
# two arguments: specify range
|
# two arguments: specify range
|
||||||
k2 = string.atoi(sys.argv[2])
|
k2 = int(sys.argv[2])
|
||||||
if sys.argv[3:]:
|
if sys.argv[3:]:
|
||||||
# derive random seed from remaining arguments
|
# derive random seed from remaining arguments
|
||||||
x, y, z = 0, 0, 0
|
x, y, z = 0, 0, 0
|
||||||
|
|
|
@ -44,8 +44,8 @@ def run_module_tests(test):
|
||||||
test('join', BadSeq2(), 'a b c')
|
test('join', BadSeq2(), 'a b c')
|
||||||
|
|
||||||
# try a few long ones
|
# try a few long ones
|
||||||
print string.join(['x' * 100] * 100, ':')
|
print ":".join(['x' * 100] * 100)
|
||||||
print string.join(('x' * 100,) * 100, ':')
|
print ":".join(('x' * 100,) * 100)
|
||||||
|
|
||||||
|
|
||||||
def run_method_tests(test):
|
def run_method_tests(test):
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import dospath
|
import dospath
|
||||||
import string
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
errors = 0
|
errors = 0
|
||||||
|
|
||||||
def tester(fn, wantResult):
|
def tester(fn, wantResult):
|
||||||
fn = string.replace(fn, "\\", "\\\\")
|
fn = fn.replace("\\", "\\\\")
|
||||||
gotResult = eval(fn)
|
gotResult = eval(fn)
|
||||||
if wantResult != gotResult:
|
if wantResult != gotResult:
|
||||||
print "error!"
|
print "error!"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from test_support import verify, verbose, TestFailed
|
from test_support import verify, verbose, TestFailed
|
||||||
from UserList import UserList
|
from UserList import UserList
|
||||||
import string
|
|
||||||
|
|
||||||
def sortdict(d):
|
def sortdict(d):
|
||||||
keys = d.keys()
|
keys = d.keys()
|
||||||
|
@ -195,7 +194,7 @@ for args in ['', 'a', 'ab']:
|
||||||
if vararg: arglist.append('*' + vararg)
|
if vararg: arglist.append('*' + vararg)
|
||||||
if kwarg: arglist.append('**' + kwarg)
|
if kwarg: arglist.append('**' + kwarg)
|
||||||
decl = 'def %s(%s): print "ok %s", a, b, d, e, v, k' % (
|
decl = 'def %s(%s): print "ok %s", a, b, d, e, v, k' % (
|
||||||
name, string.join(arglist, ', '), name)
|
name, ', '.join(arglist), name)
|
||||||
exec(decl)
|
exec(decl)
|
||||||
func = eval(name)
|
func = eval(name)
|
||||||
funcs.append(func)
|
funcs.append(func)
|
||||||
|
|
|
@ -30,7 +30,6 @@ def testimage(name):
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import string
|
|
||||||
|
|
||||||
outputfile = '/tmp/deleteme'
|
outputfile = '/tmp/deleteme'
|
||||||
|
|
||||||
|
@ -47,9 +46,9 @@ def testimage(name):
|
||||||
else: # ...or the full path of the module
|
else: # ...or the full path of the module
|
||||||
ourname = sys.modules[__name__].__file__
|
ourname = sys.modules[__name__].__file__
|
||||||
|
|
||||||
parts = string.splitfields(ourname, os.sep)
|
parts = ourname.split(os.sep)
|
||||||
parts[-1] = name
|
parts[-1] = name
|
||||||
name = string.joinfields(parts, os.sep)
|
name = os.sep.joinfields(parts)
|
||||||
sizes = imgfile.getsizes(name)
|
sizes = imgfile.getsizes(name)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Opening test image: %s, sizes: %s' % (name, str(sizes))
|
print 'Opening test image: %s, sizes: %s' % (name, str(sizes))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from test_support import verify
|
from test_support import verify
|
||||||
import mmap
|
import mmap
|
||||||
import string, os, re, sys
|
import os, re, sys
|
||||||
|
|
||||||
PAGESIZE = mmap.PAGESIZE
|
PAGESIZE = mmap.PAGESIZE
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ def test_both():
|
||||||
# Simple sanity checks
|
# Simple sanity checks
|
||||||
|
|
||||||
print type(m) # SF bug 128713: segfaulted on Linux
|
print type(m) # SF bug 128713: segfaulted on Linux
|
||||||
print ' Position of foo:', string.find(m, 'foo') / float(PAGESIZE), 'pages'
|
print ' Position of foo:', m.find('foo') / float(PAGESIZE), 'pages'
|
||||||
verify(string.find(m, 'foo') == PAGESIZE)
|
verify(m.find('foo') == PAGESIZE)
|
||||||
|
|
||||||
print ' Length of file:', len(m) / float(PAGESIZE), 'pages'
|
print ' Length of file:', len(m) / float(PAGESIZE), 'pages'
|
||||||
verify(len(m) == 2*PAGESIZE)
|
verify(len(m) == 2*PAGESIZE)
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import ntpath
|
import ntpath
|
||||||
import string
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
errors = 0
|
errors = 0
|
||||||
|
|
||||||
def tester(fn, wantResult):
|
def tester(fn, wantResult):
|
||||||
fn = string.replace(fn, "\\", "\\\\")
|
fn = fn.replace("\\", "\\\\")
|
||||||
gotResult = eval(fn)
|
gotResult = eval(fn)
|
||||||
if wantResult != gotResult:
|
if wantResult != gotResult:
|
||||||
print "error!"
|
print "error!"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Test packages (dotted-name import)
|
# Test packages (dotted-name import)
|
||||||
|
|
||||||
import sys, os, string, tempfile, traceback
|
import sys, os, tempfile, traceback
|
||||||
from os import mkdir, rmdir # Can't test if these fail
|
from os import mkdir, rmdir # Can't test if these fail
|
||||||
del mkdir, rmdir
|
del mkdir, rmdir
|
||||||
from test_support import verify, verbose, TestFailed
|
from test_support import verify, verbose, TestFailed
|
||||||
|
@ -10,7 +10,7 @@ from test_support import verify, verbose, TestFailed
|
||||||
def mkhier(root, descr):
|
def mkhier(root, descr):
|
||||||
mkdir(root)
|
mkdir(root)
|
||||||
for name, contents in descr:
|
for name, contents in descr:
|
||||||
comps = string.split(name)
|
comps = name.split()
|
||||||
fullname = root
|
fullname = root
|
||||||
for c in comps:
|
for c in comps:
|
||||||
fullname = os.path.join(fullname, c)
|
fullname = os.path.join(fullname, c)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue