Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf82e37

Browse files
committed
More 2to3 fixes in the Tools directory. Fixes python#2893.
1 parent acbca71 commit bf82e37

38 files changed

Lines changed: 1999 additions & 2032 deletions

Tools/bgen/bgen/bgenGenerator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def stringify(str):
8888
res = '"'
8989
map = _stringify_map
9090
for c in str:
91-
if map.has_key(c): res = res + map[c]
91+
if c in map: res = res + map[c]
9292
elif ' ' <= c <= '~': res = res + c
9393
else: res = res + '\\%03o' % ord(c)
9494
res = res + '"'

Tools/bgen/bgen/bgenOutput.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def Out(text):
182182
line = line[n:]
183183
else:
184184
for c in indent:
185-
if line[:1] <> c: break
185+
if line[:1] != c: break
186186
line = line[1:]
187187
VaOutput("%s", line)
188188

Tools/bgen/bgen/scantools.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,20 @@ def initusedtypes(self):
126126
self.usedtypes = {}
127127

128128
def typeused(self, type, mode):
129-
if not self.usedtypes.has_key(type):
129+
if type not in self.usedtypes:
130130
self.usedtypes[type] = {}
131131
self.usedtypes[type][mode] = None
132132

133133
def reportusedtypes(self):
134-
types = self.usedtypes.keys()
135-
types.sort()
134+
types = sorted(self.usedtypes.keys())
136135
for type in types:
137-
modes = self.usedtypes[type].keys()
138-
modes.sort()
136+
modes = sorted(self.usedtypes[type].keys())
139137
self.report("%s %s", type, " ".join(modes))
140138

141139
def gentypetest(self, file):
142140
fp = open(file, "w")
143141
fp.write("types=[\n")
144-
types = self.usedtypes.keys()
145-
types.sort()
142+
types = sorted(self.usedtypes.keys())
146143
for type in types:
147144
fp.write("\t'%s',\n"%type)
148145
fp.write("]\n")
@@ -236,7 +233,7 @@ def makerepairinstructions(self):
236233
if i >= 0: line = line[:i]
237234
words = [s.strip() for s in line.split(':')]
238235
if words == ['']: continue
239-
if len(words) <> 3:
236+
if len(words) != 3:
240237
print("Line", startlineno, end=' ')
241238
print(": bad line (not 3 colon-separated fields)")
242239
print(repr(line))
@@ -703,7 +700,7 @@ def repairarglist(self, functionname, arglist):
703700
return arglist
704701

705702
def matcharg(self, patarg, arg):
706-
return len(filter(None, map(fnmatch.fnmatchcase, arg, patarg))) == 3
703+
return len(f for f in map(fnmatch.fnmatchcase, arg, patarg) if f) == 3
707704

708705
def substituteargs(self, pattern, replacement, old):
709706
new = []
@@ -739,7 +736,7 @@ def generate(self, tp, name, arglist, modifiers=[]):
739736
self.typeused(atype, amode)
740737
self.specfile.write(" (%s, %r, %s),\n" %
741738
(atype, aname, amode))
742-
if self.greydictnames.has_key(name):
739+
if name in self.greydictnames:
743740
self.specfile.write(" condition=%r,\n"%(self.greydictnames[name],))
744741
self.generatemodifiers(classname, name, modifiers)
745742
self.specfile.write(")\n")

Tools/faqwiz/faqwiz.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def log(text):
120120
logfile.close()
121121

122122
def load_cookies():
123-
if not os.environ.has_key('HTTP_COOKIE'):
123+
if 'HTTP_COOKIE' not in os.environ:
124124
return {}
125125
raw = os.environ['HTTP_COOKIE']
126126
words = [s.strip() for s in raw.split(';')]
@@ -359,7 +359,7 @@ def show(self, file, edit=1):
359359
self.open(file).show(edit=edit)
360360

361361
def new(self, section):
362-
if not SECTION_TITLES.has_key(section):
362+
if section not in SECTION_TITLES:
363363
raise NoSuchSection(section)
364364
maxnum = 0
365365
for file in self.list():
@@ -426,11 +426,11 @@ def do_search(self):
426426
query = re.escape(query)
427427
queries = [query]
428428
elif self.ui.querytype in ('anykeywords', 'allkeywords'):
429-
words = filter(None, re.split('\W+', query))
429+
words = [_f for _f in re.split('\W+', query) if _f]
430430
if not words:
431431
self.error("No keywords specified!")
432432
return
433-
words = map(lambda w: r'\b%s\b' % w, words)
433+
words = [r'\b%s\b' % w for w in words]
434434
if self.ui.querytype[:3] == 'any':
435435
queries = ['|'.join(words)]
436436
else:
@@ -577,7 +577,7 @@ def do_recent(self):
577577
emit(ONE_RECENT, period=period)
578578
else:
579579
emit(SOME_RECENT, period=period, count=len(list))
580-
self.format_all(map(lambda (mtime, file): file, list), headers=0)
580+
self.format_all([mtime_file[1] for mtime_file in list], headers=0)
581581
emit(TAIL_RECENT)
582582

583583
def do_roulette(self):
@@ -603,8 +603,7 @@ def do_show(self):
603603
def do_add(self):
604604
self.prologue(T_ADD)
605605
emit(ADD_HEAD)
606-
sections = SECTION_TITLES.items()
607-
sections.sort()
606+
sections = sorted(SECTION_TITLES.items())
608607
for section, title in sections:
609608
emit(ADD_SECTION, section=section, title=title)
610609
emit(ADD_TAIL)

Tools/framer/framer/bases.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
from types import FunctionType
1212

13-
def sortitems(dict):
14-
L = dict.items()
15-
L.sort()
16-
return L
17-
1813
# The Module and Type classes are implemented using metaclasses,
1914
# because most of the methods are class methods. It is easier to use
2015
# metaclasses than the cumbersome classmethod() builtin. They have
@@ -32,7 +27,7 @@ def p(templ, vars=vars): # helper function to generate output
3227
if not functions:
3328
return
3429
p(template.methoddef_start)
35-
for name, func in sortitems(functions):
30+
for name, func in sorted(functions.items()):
3631
if func.__doc__:
3732
p(template.methoddef_def_doc, func.vars)
3833
else:
@@ -55,7 +50,7 @@ def analyze(self):
5550
self.__types = {}
5651
self.__members = False
5752

58-
for name, obj in self.__dict__.iteritems():
53+
for name, obj in self.__dict__.items():
5954
if isinstance(obj, FunctionType):
6055
self.__functions[name] = Function(obj, self)
6156
elif isinstance(obj, TypeMetaclass):
@@ -87,16 +82,16 @@ def p(templ, vars=self.__vars): # helper function to generate output
8782
if self.__doc__:
8883
p(template.module_doc)
8984

90-
for name, type in sortitems(self.__types):
85+
for name, type in sorted(self.__types.items()):
9186
type.dump(f)
9287

93-
for name, func in sortitems(self.__functions):
88+
for name, func in sorted(self.__functions.items()):
9489
func.dump(f)
9590

9691
self.dump_methoddef(f, self.__functions, self.__vars)
9792

9893
p(template.module_init_start)
99-
for name, type in sortitems(self.__types):
94+
for name, type in sorted(self.__types.items()):
10095
type.dump_init(f)
10196

10297
p("}")
@@ -119,7 +114,7 @@ def p(templ, vars=self.__vars):
119114
if self.__doc__:
120115
p(template.docstring)
121116

122-
for name, func in sortitems(self.__methods):
117+
for name, func in sorted(self.__methods.items()):
123118
func.dump(f)
124119

125120
self.dump_methoddef(f, self.__methods, self.__vars)
@@ -143,7 +138,7 @@ def analyze(self):
143138
self.__methods = {}
144139
self.__members = {}
145140
for cls in self.__mro__:
146-
for k, v in cls.__dict__.iteritems():
141+
for k, v in cls.__dict__.items():
147142
if isinstance(v, FunctionType):
148143
self.__methods[k] = Method(v, self)
149144
if isinstance(v, member):
@@ -190,7 +185,7 @@ def p(templ, vars=self.__vars):
190185
if not self.__members:
191186
return
192187
p(template.memberdef_start)
193-
for name, slot in sortitems(self.__members):
188+
for name, slot in sorted(self.__members.items()):
194189
slot.dump(f)
195190
p(template.memberdef_end)
196191

Tools/framer/framer/function.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class _ArgumentList(object):
4545
fmt = None
4646

4747
def __init__(self, args):
48-
self.args = map(Argument, args)
48+
self.args = list(map(Argument, args))
4949

5050
def __len__(self):
5151
return len(self.args)
@@ -99,15 +99,15 @@ def dump_decls(self, f):
9999
print(" %s" % a.decl(), file=f)
100100

101101
def ArgumentList(func, method):
102-
code = func.func_code
102+
code = func.__code__
103103
args = code.co_varnames[:code.co_argcount]
104104
if method:
105105
args = args[1:]
106106
pyarg = getattr(func, "pyarg", None)
107107
if pyarg is not None:
108108
args = VarArgs(args, pyarg)
109-
if func.func_defaults:
110-
L = list(func.func_defaults)
109+
if func.__defaults__:
110+
L = list(func.__defaults__)
111111
ndefault = len(L)
112112
i = len(args) - ndefault
113113
while L:

Tools/framer/framer/struct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def parse(s):
2525
The parser is very restricted in what it will accept.
2626
"""
2727

28-
lines = filter(None, s.split("\n")) # get non-empty lines
28+
lines = [_f for _f in s.split("\n") if _f] # get non-empty lines
2929
assert lines[0].strip() == "typedef struct {"
3030
pyhead = lines[1].strip()
3131
assert (pyhead.startswith("PyObject") and

Tools/framer/framer/structparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def parse(s):
1919
The parser is very restricted in what it will accept.
2020
"""
2121

22-
lines = filter(None, s.split("\n")) # get non-empty lines
22+
lines = [_f for _f in s.split("\n") if _f] # get non-empty lines
2323
assert lines[0].strip() == "typedef struct {"
2424
pyhead = lines[1].strip()
2525
assert (pyhead.startswith("PyObject") and

Tools/freeze/checkextensions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def checkextensions(unknown, extensions):
1818
for mod in unknown:
1919
for e in extensions:
2020
(mods, vars), liba = edict[e]
21-
if not mods.has_key(mod):
21+
if mod not in mods:
2222
continue
2323
modules.append(mod)
2424
if liba:
@@ -28,7 +28,7 @@ def checkextensions(unknown, extensions):
2828
if liba in files:
2929
break
3030
files.append(liba)
31-
for m in mods.keys():
31+
for m in list(mods.keys()):
3232
files = files + select(e, mods, vars,
3333
m, 1)
3434
break
@@ -84,7 +84,7 @@ def expandvars(str, vars):
8484
break
8585
var = str[i:j]
8686
i = j+1
87-
if vars.has_key(var):
87+
if var in vars:
8888
str = str[:k] + vars[var] + str[i:]
8989
i = k
9090
return str

Tools/freeze/freeze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def main():
460460
somevars = {}
461461
if os.path.exists(makefile_in):
462462
makevars = parsesetup.getmakevars(makefile_in)
463-
for key in makevars.keys():
463+
for key in makevars:
464464
somevars[key] = makevars[key]
465465

466466
somevars['CFLAGS'] = ' '.join(cflags) # override

0 commit comments

Comments
 (0)