mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
More 2to3 fixes in the Tools directory. Fixes #2893.
This commit is contained in:
@@ -88,7 +88,7 @@ def stringify(str):
|
||||
res = '"'
|
||||
map = _stringify_map
|
||||
for c in str:
|
||||
if map.has_key(c): res = res + map[c]
|
||||
if c in map: res = res + map[c]
|
||||
elif ' ' <= c <= '~': res = res + c
|
||||
else: res = res + '\\%03o' % ord(c)
|
||||
res = res + '"'
|
||||
|
||||
@@ -182,7 +182,7 @@ def Out(text):
|
||||
line = line[n:]
|
||||
else:
|
||||
for c in indent:
|
||||
if line[:1] <> c: break
|
||||
if line[:1] != c: break
|
||||
line = line[1:]
|
||||
VaOutput("%s", line)
|
||||
|
||||
|
||||
@@ -126,23 +126,20 @@ class Scanner:
|
||||
self.usedtypes = {}
|
||||
|
||||
def typeused(self, type, mode):
|
||||
if not self.usedtypes.has_key(type):
|
||||
if type not in self.usedtypes:
|
||||
self.usedtypes[type] = {}
|
||||
self.usedtypes[type][mode] = None
|
||||
|
||||
def reportusedtypes(self):
|
||||
types = self.usedtypes.keys()
|
||||
types.sort()
|
||||
types = sorted(self.usedtypes.keys())
|
||||
for type in types:
|
||||
modes = self.usedtypes[type].keys()
|
||||
modes.sort()
|
||||
modes = sorted(self.usedtypes[type].keys())
|
||||
self.report("%s %s", type, " ".join(modes))
|
||||
|
||||
def gentypetest(self, file):
|
||||
fp = open(file, "w")
|
||||
fp.write("types=[\n")
|
||||
types = self.usedtypes.keys()
|
||||
types.sort()
|
||||
types = sorted(self.usedtypes.keys())
|
||||
for type in types:
|
||||
fp.write("\t'%s',\n"%type)
|
||||
fp.write("]\n")
|
||||
@@ -236,7 +233,7 @@ if missing: raise "Missing Types"
|
||||
if i >= 0: line = line[:i]
|
||||
words = [s.strip() for s in line.split(':')]
|
||||
if words == ['']: continue
|
||||
if len(words) <> 3:
|
||||
if len(words) != 3:
|
||||
print("Line", startlineno, end=' ')
|
||||
print(": bad line (not 3 colon-separated fields)")
|
||||
print(repr(line))
|
||||
@@ -703,7 +700,7 @@ if missing: raise "Missing Types"
|
||||
return arglist
|
||||
|
||||
def matcharg(self, patarg, arg):
|
||||
return len(filter(None, map(fnmatch.fnmatchcase, arg, patarg))) == 3
|
||||
return len(f for f in map(fnmatch.fnmatchcase, arg, patarg) if f) == 3
|
||||
|
||||
def substituteargs(self, pattern, replacement, old):
|
||||
new = []
|
||||
@@ -739,7 +736,7 @@ if missing: raise "Missing Types"
|
||||
self.typeused(atype, amode)
|
||||
self.specfile.write(" (%s, %r, %s),\n" %
|
||||
(atype, aname, amode))
|
||||
if self.greydictnames.has_key(name):
|
||||
if name in self.greydictnames:
|
||||
self.specfile.write(" condition=%r,\n"%(self.greydictnames[name],))
|
||||
self.generatemodifiers(classname, name, modifiers)
|
||||
self.specfile.write(")\n")
|
||||
|
||||
@@ -120,7 +120,7 @@ def log(text):
|
||||
logfile.close()
|
||||
|
||||
def load_cookies():
|
||||
if not os.environ.has_key('HTTP_COOKIE'):
|
||||
if 'HTTP_COOKIE' not in os.environ:
|
||||
return {}
|
||||
raw = os.environ['HTTP_COOKIE']
|
||||
words = [s.strip() for s in raw.split(';')]
|
||||
@@ -359,7 +359,7 @@ class FaqDir:
|
||||
self.open(file).show(edit=edit)
|
||||
|
||||
def new(self, section):
|
||||
if not SECTION_TITLES.has_key(section):
|
||||
if section not in SECTION_TITLES:
|
||||
raise NoSuchSection(section)
|
||||
maxnum = 0
|
||||
for file in self.list():
|
||||
@@ -426,11 +426,11 @@ class FaqWizard:
|
||||
query = re.escape(query)
|
||||
queries = [query]
|
||||
elif self.ui.querytype in ('anykeywords', 'allkeywords'):
|
||||
words = filter(None, re.split('\W+', query))
|
||||
words = [_f for _f in re.split('\W+', query) if _f]
|
||||
if not words:
|
||||
self.error("No keywords specified!")
|
||||
return
|
||||
words = map(lambda w: r'\b%s\b' % w, words)
|
||||
words = [r'\b%s\b' % w for w in words]
|
||||
if self.ui.querytype[:3] == 'any':
|
||||
queries = ['|'.join(words)]
|
||||
else:
|
||||
@@ -577,7 +577,7 @@ class FaqWizard:
|
||||
emit(ONE_RECENT, period=period)
|
||||
else:
|
||||
emit(SOME_RECENT, period=period, count=len(list))
|
||||
self.format_all(map(lambda (mtime, file): file, list), headers=0)
|
||||
self.format_all([mtime_file[1] for mtime_file in list], headers=0)
|
||||
emit(TAIL_RECENT)
|
||||
|
||||
def do_roulette(self):
|
||||
@@ -603,8 +603,7 @@ class FaqWizard:
|
||||
def do_add(self):
|
||||
self.prologue(T_ADD)
|
||||
emit(ADD_HEAD)
|
||||
sections = SECTION_TITLES.items()
|
||||
sections.sort()
|
||||
sections = sorted(SECTION_TITLES.items())
|
||||
for section, title in sections:
|
||||
emit(ADD_SECTION, section=section, title=title)
|
||||
emit(ADD_TAIL)
|
||||
|
||||
@@ -10,11 +10,6 @@ from framer.util import cstring, unindent
|
||||
|
||||
from types import FunctionType
|
||||
|
||||
def sortitems(dict):
|
||||
L = dict.items()
|
||||
L.sort()
|
||||
return L
|
||||
|
||||
# The Module and Type classes are implemented using metaclasses,
|
||||
# because most of the methods are class methods. It is easier to use
|
||||
# metaclasses than the cumbersome classmethod() builtin. They have
|
||||
@@ -32,7 +27,7 @@ class BaseMetaclass(type):
|
||||
if not functions:
|
||||
return
|
||||
p(template.methoddef_start)
|
||||
for name, func in sortitems(functions):
|
||||
for name, func in sorted(functions.items()):
|
||||
if func.__doc__:
|
||||
p(template.methoddef_def_doc, func.vars)
|
||||
else:
|
||||
@@ -55,7 +50,7 @@ class ModuleMetaclass(BaseMetaclass):
|
||||
self.__types = {}
|
||||
self.__members = False
|
||||
|
||||
for name, obj in self.__dict__.iteritems():
|
||||
for name, obj in self.__dict__.items():
|
||||
if isinstance(obj, FunctionType):
|
||||
self.__functions[name] = Function(obj, self)
|
||||
elif isinstance(obj, TypeMetaclass):
|
||||
@@ -87,16 +82,16 @@ class ModuleMetaclass(BaseMetaclass):
|
||||
if self.__doc__:
|
||||
p(template.module_doc)
|
||||
|
||||
for name, type in sortitems(self.__types):
|
||||
for name, type in sorted(self.__types.items()):
|
||||
type.dump(f)
|
||||
|
||||
for name, func in sortitems(self.__functions):
|
||||
for name, func in sorted(self.__functions.items()):
|
||||
func.dump(f)
|
||||
|
||||
self.dump_methoddef(f, self.__functions, self.__vars)
|
||||
|
||||
p(template.module_init_start)
|
||||
for name, type in sortitems(self.__types):
|
||||
for name, type in sorted(self.__types.items()):
|
||||
type.dump_init(f)
|
||||
|
||||
p("}")
|
||||
@@ -119,7 +114,7 @@ class TypeMetaclass(BaseMetaclass):
|
||||
if self.__doc__:
|
||||
p(template.docstring)
|
||||
|
||||
for name, func in sortitems(self.__methods):
|
||||
for name, func in sorted(self.__methods.items()):
|
||||
func.dump(f)
|
||||
|
||||
self.dump_methoddef(f, self.__methods, self.__vars)
|
||||
@@ -143,7 +138,7 @@ class TypeMetaclass(BaseMetaclass):
|
||||
self.__methods = {}
|
||||
self.__members = {}
|
||||
for cls in self.__mro__:
|
||||
for k, v in cls.__dict__.iteritems():
|
||||
for k, v in cls.__dict__.items():
|
||||
if isinstance(v, FunctionType):
|
||||
self.__methods[k] = Method(v, self)
|
||||
if isinstance(v, member):
|
||||
@@ -190,7 +185,7 @@ class TypeMetaclass(BaseMetaclass):
|
||||
if not self.__members:
|
||||
return
|
||||
p(template.memberdef_start)
|
||||
for name, slot in sortitems(self.__members):
|
||||
for name, slot in sorted(self.__members.items()):
|
||||
slot.dump(f)
|
||||
p(template.memberdef_end)
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class _ArgumentList(object):
|
||||
fmt = None
|
||||
|
||||
def __init__(self, args):
|
||||
self.args = map(Argument, args)
|
||||
self.args = list(map(Argument, args))
|
||||
|
||||
def __len__(self):
|
||||
return len(self.args)
|
||||
@@ -99,15 +99,15 @@ class VarArgs(_ArgumentList):
|
||||
print(" %s" % a.decl(), file=f)
|
||||
|
||||
def ArgumentList(func, method):
|
||||
code = func.func_code
|
||||
code = func.__code__
|
||||
args = code.co_varnames[:code.co_argcount]
|
||||
if method:
|
||||
args = args[1:]
|
||||
pyarg = getattr(func, "pyarg", None)
|
||||
if pyarg is not None:
|
||||
args = VarArgs(args, pyarg)
|
||||
if func.func_defaults:
|
||||
L = list(func.func_defaults)
|
||||
if func.__defaults__:
|
||||
L = list(func.__defaults__)
|
||||
ndefault = len(L)
|
||||
i = len(args) - ndefault
|
||||
while L:
|
||||
|
||||
@@ -25,7 +25,7 @@ def parse(s):
|
||||
The parser is very restricted in what it will accept.
|
||||
"""
|
||||
|
||||
lines = filter(None, s.split("\n")) # get non-empty lines
|
||||
lines = [_f for _f in s.split("\n") if _f] # get non-empty lines
|
||||
assert lines[0].strip() == "typedef struct {"
|
||||
pyhead = lines[1].strip()
|
||||
assert (pyhead.startswith("PyObject") and
|
||||
|
||||
@@ -19,7 +19,7 @@ def parse(s):
|
||||
The parser is very restricted in what it will accept.
|
||||
"""
|
||||
|
||||
lines = filter(None, s.split("\n")) # get non-empty lines
|
||||
lines = [_f for _f in s.split("\n") if _f] # get non-empty lines
|
||||
assert lines[0].strip() == "typedef struct {"
|
||||
pyhead = lines[1].strip()
|
||||
assert (pyhead.startswith("PyObject") and
|
||||
|
||||
@@ -18,7 +18,7 @@ def checkextensions(unknown, extensions):
|
||||
for mod in unknown:
|
||||
for e in extensions:
|
||||
(mods, vars), liba = edict[e]
|
||||
if not mods.has_key(mod):
|
||||
if mod not in mods:
|
||||
continue
|
||||
modules.append(mod)
|
||||
if liba:
|
||||
@@ -28,7 +28,7 @@ def checkextensions(unknown, extensions):
|
||||
if liba in files:
|
||||
break
|
||||
files.append(liba)
|
||||
for m in mods.keys():
|
||||
for m in list(mods.keys()):
|
||||
files = files + select(e, mods, vars,
|
||||
m, 1)
|
||||
break
|
||||
@@ -84,7 +84,7 @@ def expandvars(str, vars):
|
||||
break
|
||||
var = str[i:j]
|
||||
i = j+1
|
||||
if vars.has_key(var):
|
||||
if var in vars:
|
||||
str = str[:k] + vars[var] + str[i:]
|
||||
i = k
|
||||
return str
|
||||
|
||||
@@ -460,7 +460,7 @@ def main():
|
||||
somevars = {}
|
||||
if os.path.exists(makefile_in):
|
||||
makevars = parsesetup.getmakevars(makefile_in)
|
||||
for key in makevars.keys():
|
||||
for key in makevars:
|
||||
somevars[key] = makevars[key]
|
||||
|
||||
somevars['CFLAGS'] = ' '.join(cflags) # override
|
||||
|
||||
@@ -45,18 +45,14 @@ def parse(filename):
|
||||
return data
|
||||
|
||||
def pprint(data):
|
||||
|
||||
items = data.items()
|
||||
items.sort()
|
||||
for k,v in items:
|
||||
items = sorted(data.items())
|
||||
for k, v in items:
|
||||
print(' %-40s%r,' % ('%r:' % k, v))
|
||||
|
||||
def print_differences(data, olddata):
|
||||
|
||||
items = olddata.items()
|
||||
items.sort()
|
||||
items = sorted(olddata.items())
|
||||
for k, v in items:
|
||||
if not data.has_key(k):
|
||||
if k not in data:
|
||||
print('# removed %r' % k)
|
||||
elif olddata[k] != data[k]:
|
||||
print('# updated %r -> %r to %r' % \
|
||||
|
||||
@@ -56,9 +56,8 @@ def add(id, str, fuzzy):
|
||||
def generate():
|
||||
"Return the generated output."
|
||||
global MESSAGES
|
||||
keys = MESSAGES.keys()
|
||||
# the keys are sorted in the .mo file
|
||||
keys.sort()
|
||||
keys = sorted(MESSAGES.keys())
|
||||
offsets = []
|
||||
ids = strs = ''
|
||||
for id in keys:
|
||||
|
||||
@@ -265,7 +265,7 @@ def containsAny(str, set):
|
||||
def _visit_pyfiles(list, dirname, names):
|
||||
"""Helper for getFilesForName()."""
|
||||
# get extension for python source files
|
||||
if not globals().has_key('_py_ext'):
|
||||
if '_py_ext' not in globals():
|
||||
global _py_ext
|
||||
_py_ext = [triple[0] for triple in imp.get_suffixes()
|
||||
if triple[2] == imp.PY_SOURCE][0]
|
||||
|
||||
@@ -19,7 +19,7 @@ class ScrolledListbox(Listbox):
|
||||
fcnf = {}
|
||||
vcnf = {'name': 'vbar',
|
||||
Pack: {'side': 'right', 'fill': 'y'},}
|
||||
for k in cnf.keys():
|
||||
for k in list(cnf.keys()):
|
||||
if type(k) == ClassType or k == 'name':
|
||||
fcnf[k] = cnf[k]
|
||||
del cnf[k]
|
||||
@@ -32,6 +32,6 @@ class ScrolledListbox(Listbox):
|
||||
self.vbar['command'] = (self, 'yview')
|
||||
|
||||
# Copy Pack methods of self.frame -- hack!
|
||||
for m in Pack.__dict__.keys():
|
||||
for m in Pack.__dict__:
|
||||
if m[0] != '_' and m != 'config':
|
||||
setattr(self, m, getattr(self.frame, m))
|
||||
|
||||
@@ -40,7 +40,7 @@ class writer:
|
||||
|
||||
def makesubst(self):
|
||||
if not self._subst:
|
||||
if not self.__dict__.has_key('abbrev'):
|
||||
if 'abbrev' not in self.__dict__:
|
||||
self.abbrev = self.name
|
||||
self.Abbrev = self.abbrev[0].upper()+self.abbrev[1:]
|
||||
subst = varsubst.Varsubst(self.__dict__)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#
|
||||
|
||||
import sys, os
|
||||
if os.name <> 'mac':
|
||||
if os.name != 'mac':
|
||||
sys.path.append(os.path.join(os.environ['HOME'],
|
||||
'src/python/Tools/modulator'))
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class Varsubst:
|
||||
s = s[2:]
|
||||
continue
|
||||
name = m.group(1)
|
||||
if not self.dict.has_key(name):
|
||||
if name not in self.dict:
|
||||
raise error('No such variable: '+name)
|
||||
value = self.dict[name]
|
||||
if self.do_useindent and '\n' in value:
|
||||
|
||||
@@ -19,23 +19,23 @@ def merge(msi, feature, rootdir, modules):
|
||||
# Step 1: Merge databases, extract cabfiles
|
||||
m = msilib.MakeMerge2()
|
||||
m.OpenLog("merge.log")
|
||||
print "Opened Log"
|
||||
print("Opened Log")
|
||||
m.OpenDatabase(msi)
|
||||
print "Opened DB"
|
||||
print("Opened DB")
|
||||
for module in modules:
|
||||
print module
|
||||
print(module)
|
||||
m.OpenModule(module,0)
|
||||
print "Opened Module",module
|
||||
print("Opened Module",module)
|
||||
m.Merge(feature, rootdir)
|
||||
print "Errors:"
|
||||
print("Errors:")
|
||||
for e in m.Errors:
|
||||
print e.Type, e.ModuleTable, e.DatabaseTable
|
||||
print " Modkeys:",
|
||||
for s in e.ModuleKeys: print s,
|
||||
print
|
||||
print " DBKeys:",
|
||||
for s in e.DatabaseKeys: print s,
|
||||
print
|
||||
print(e.Type, e.ModuleTable, e.DatabaseTable)
|
||||
print(" Modkeys:", end=' ')
|
||||
for s in e.ModuleKeys: print(s, end=' ')
|
||||
print()
|
||||
print(" DBKeys:", end=' ')
|
||||
for s in e.DatabaseKeys: print(s, end=' ')
|
||||
print()
|
||||
cabname = tempfile.mktemp(suffix=".cab")
|
||||
m.ExtractCAB(cabname)
|
||||
cab_and_filecount.append((cabname, len(m.ModuleFiles)))
|
||||
@@ -56,7 +56,7 @@ def merge(msi, feature, rootdir, modules):
|
||||
seq = r.IntegerData(1)
|
||||
if seq > maxmedia:
|
||||
maxmedia = seq
|
||||
print "Start of Media", maxmedia
|
||||
print("Start of Media", maxmedia)
|
||||
|
||||
for cabname, count in cab_and_filecount:
|
||||
stream = "merged%d" % maxmedia
|
||||
|
||||
@@ -205,7 +205,7 @@ def build_database():
|
||||
schema, ProductName="Python "+full_current_version,
|
||||
ProductCode=product_code,
|
||||
ProductVersion=current_version,
|
||||
Manufacturer=u"Python Software Foundation")
|
||||
Manufacturer="Python Software Foundation")
|
||||
# The default sequencing of the RemoveExistingProducts action causes
|
||||
# removal of files that got just installed. Place it after
|
||||
# InstallInitialize, so we first uninstall everything, but still roll
|
||||
@@ -335,7 +335,7 @@ def add_ui(db):
|
||||
|
||||
# Bitmaps
|
||||
if not os.path.exists(srcdir+r"\PC\python_icon.exe"):
|
||||
raise "Run icons.mak in PC directory"
|
||||
raise RuntimeError("Run icons.mak in PC directory")
|
||||
add_data(db, "Binary",
|
||||
[("PythonWin", msilib.Binary(r"%s\PCbuild\installer.bmp" % srcdir)), # 152x328 pixels
|
||||
("py.ico",msilib.Binary(srcdir+r"\PC\py.ico")),
|
||||
@@ -349,7 +349,7 @@ def add_ui(db):
|
||||
# the installed/uninstalled state according to both the
|
||||
# Extensions and TclTk features.
|
||||
if os.system("nmake /nologo /c /f msisupport.mak") != 0:
|
||||
raise "'nmake /f msisupport.mak' failed"
|
||||
raise RuntimeError("'nmake /f msisupport.mak' failed")
|
||||
add_data(db, "Binary", [("Script", msilib.Binary("msisupport.dll"))])
|
||||
# See "Custom Action Type 1"
|
||||
if msilib.Win64:
|
||||
@@ -845,7 +845,7 @@ class PyDirectory(Directory):
|
||||
"""By default, all components in the Python installer
|
||||
can run from source."""
|
||||
def __init__(self, *args, **kw):
|
||||
if not kw.has_key("componentflags"):
|
||||
if "componentflags" not in kw:
|
||||
kw['componentflags'] = 2 #msidbComponentAttributesOptional
|
||||
Directory.__init__(self, *args, **kw)
|
||||
|
||||
|
||||
@@ -7,11 +7,6 @@ import pythoncom, pywintypes
|
||||
from win32com.client import constants
|
||||
import re, string, os, sets, glob, subprocess, sys, _winreg, struct
|
||||
|
||||
try:
|
||||
basestring
|
||||
except NameError:
|
||||
basestring = (str, unicode)
|
||||
|
||||
# Partially taken from Wine
|
||||
datasizemask= 0x00ff
|
||||
type_valid= 0x0100
|
||||
@@ -173,14 +168,14 @@ def gen_schema(destpath, schemapath):
|
||||
r = v.Fetch()
|
||||
if not r:break
|
||||
# Table, Column, Nullable
|
||||
f.write("(%s,%s,%s," %
|
||||
(`r.StringData(1)`, `r.StringData(2)`, `r.StringData(3)`))
|
||||
f.write("(%r,%r,%r," %
|
||||
(r.StringData(1), r.StringData(2), r.StringData(3)))
|
||||
def put_int(i):
|
||||
if r.IsNull(i):f.write("None, ")
|
||||
else:f.write("%d," % r.IntegerData(i))
|
||||
def put_str(i):
|
||||
if r.IsNull(i):f.write("None, ")
|
||||
else:f.write("%s," % `r.StringData(i)`)
|
||||
else:f.write("%r," % r.StringData(i))
|
||||
put_int(4) # MinValue
|
||||
put_int(5) # MaxValue
|
||||
put_str(6) # KeyTable
|
||||
@@ -235,12 +230,12 @@ def gen_sequence(destpath, msipath):
|
||||
else:
|
||||
rec.append(bytes)
|
||||
else:
|
||||
raise "Unsupported column type", info.StringData(i)
|
||||
raise ValueError("Unsupported column type", info.StringData(i))
|
||||
f.write(repr(tuple(rec))+",\n")
|
||||
v1.Close()
|
||||
f.write("]\n\n")
|
||||
v.Close()
|
||||
f.write("tables=%s\n" % repr(map(str,tables)))
|
||||
f.write("tables=%s\n" % repr(list(map(str,tables))))
|
||||
f.close()
|
||||
|
||||
class _Unspecified:pass
|
||||
@@ -265,9 +260,9 @@ def add_data(db, table, values):
|
||||
assert len(value) == count, value
|
||||
for i in range(count):
|
||||
field = value[i]
|
||||
if isinstance(field, (int, long)):
|
||||
if isinstance(field, int):
|
||||
r.SetIntegerData(i+1,field)
|
||||
elif isinstance(field, basestring):
|
||||
elif isinstance(field, str):
|
||||
r.SetStringData(i+1,field)
|
||||
elif field is None:
|
||||
pass
|
||||
@@ -522,7 +517,7 @@ class Directory:
|
||||
file = os.path.basename(file)
|
||||
absolute = os.path.join(self.absolute, src)
|
||||
assert not re.search(r'[\?|><:/*]"', file) # restrictions on long names
|
||||
if self.keyfiles.has_key(file):
|
||||
if file in self.keyfiles:
|
||||
logical = self.keyfiles[file]
|
||||
else:
|
||||
logical = None
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user