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

Skip to content

Commit 5b787e8

Browse files
committed
Fix pybench so it works -- Larry Hastings.
1 parent 16be03e commit 5b787e8

4 files changed

Lines changed: 41 additions & 39 deletions

File tree

Tools/pybench/CommandLine.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Option:
165165
def __init__(self,name,help=None):
166166

167167
if not name[:1] == '-':
168-
raise TypeError,'option names must start with "-"'
168+
raise TypeError('option names must start with "-"')
169169
if name[1:2] == '-':
170170
self.prefix = '--'
171171
self.name = name[2:]
@@ -324,30 +324,32 @@ def __init__(self,argv=None):
324324

325325
# Append preset options
326326
for option in self.preset_options:
327-
if not self.option_map.has_key(option.name):
327+
if not option.name in self.option_map:
328328
self.add_option(option)
329329

330330
# Init .files list
331331
self.files = []
332332

333333
# Start Application
334+
rc = 0
334335
try:
335336
# Process startup
336337
rc = self.startup()
337338
if rc is not None:
338-
raise SystemExit,rc
339+
raise SystemExit(rc)
339340

340341
# Parse command line
341342
rc = self.parse()
342343
if rc is not None:
343-
raise SystemExit,rc
344+
raise SystemExit(rc)
344345

345346
# Start application
346347
rc = self.main()
347348
if rc is None:
348349
rc = 0
349350

350-
except SystemExit as rc:
351+
except SystemExit as rcException:
352+
rc = rcException
351353
pass
352354

353355
except KeyboardInterrupt:
@@ -367,7 +369,7 @@ def __init__(self,argv=None):
367369
print
368370
rc = 1
369371

370-
raise SystemExit,rc
372+
raise SystemExit(rc)
371373

372374
def add_option(self, option):
373375

@@ -398,7 +400,7 @@ def exit(self, rc=0):
398400
program. It defaults to 0 which usually means: OK.
399401
400402
"""
401-
raise SystemExit, rc
403+
raise SystemExit(rc)
402404

403405
def parse(self):
404406

@@ -459,7 +461,7 @@ def parse(self):
459461
except AttributeError:
460462
if value == '':
461463
# count the number of occurances
462-
if values.has_key(optionname):
464+
if optionname in values:
463465
values[optionname] = values[optionname] + 1
464466
else:
465467
values[optionname] = 1
@@ -468,7 +470,7 @@ def parse(self):
468470
else:
469471
rc = handler(value)
470472
if rc is not None:
471-
raise SystemExit, rc
473+
raise SystemExit(rc)
472474

473475
# Apply final file check (for backward compatibility)
474476
rc = self.check_files(self.files)

Tools/pybench/Dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class SimpleDictManipulation(Test):
351351
def test(self):
352352

353353
d = {}
354-
has_key = d.has_key
354+
has_key = lambda key: key in d
355355

356356
for i in xrange(self.rounds):
357357

@@ -498,7 +498,7 @@ def test(self):
498498
def calibrate(self):
499499

500500
d = {}
501-
has_key = d.has_key
501+
has_key = lambda key: key in d
502502

503503
for i in xrange(self.rounds):
504504
pass

Tools/pybench/Exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def test(self):
2020
except:
2121
pass
2222
try:
23-
raise error,"something"
23+
raise error("something")
2424
except:
2525
pass
2626
try:
27-
raise error,"something"
27+
raise error("something")
2828
except:
2929
pass
3030
try:
31-
raise error,"something"
31+
raise error("something")
3232
except:
3333
pass
3434
try:

Tools/pybench/Lookups.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,11 @@ def test(self):
774774
l.sort
775775
l.sort
776776

777-
d.has_key
778-
d.has_key
779-
d.has_key
780-
d.has_key
781-
d.has_key
777+
# d.has_key
778+
# d.has_key
779+
# d.has_key
780+
# d.has_key
781+
# d.has_key
782782

783783
d.items
784784
d.items
@@ -810,11 +810,11 @@ def test(self):
810810
l.sort
811811
l.sort
812812

813-
d.has_key
814-
d.has_key
815-
d.has_key
816-
d.has_key
817-
d.has_key
813+
# d.has_key
814+
# d.has_key
815+
# d.has_key
816+
# d.has_key
817+
# d.has_key
818818

819819
d.items
820820
d.items
@@ -846,11 +846,11 @@ def test(self):
846846
l.sort
847847
l.sort
848848

849-
d.has_key
850-
d.has_key
851-
d.has_key
852-
d.has_key
853-
d.has_key
849+
# d.has_key
850+
# d.has_key
851+
# d.has_key
852+
# d.has_key
853+
# d.has_key
854854

855855
d.items
856856
d.items
@@ -882,11 +882,11 @@ def test(self):
882882
l.sort
883883
l.sort
884884

885-
d.has_key
886-
d.has_key
887-
d.has_key
888-
d.has_key
889-
d.has_key
885+
# d.has_key
886+
# d.has_key
887+
# d.has_key
888+
# d.has_key
889+
# d.has_key
890890

891891
d.items
892892
d.items
@@ -918,11 +918,11 @@ def test(self):
918918
l.sort
919919
l.sort
920920

921-
d.has_key
922-
d.has_key
923-
d.has_key
924-
d.has_key
925-
d.has_key
921+
# d.has_key
922+
# d.has_key
923+
# d.has_key
924+
# d.has_key
925+
# d.has_key
926926

927927
d.items
928928
d.items

0 commit comments

Comments
 (0)