summaryrefslogtreecommitdiffstats
path: root/Tools/pybench/CommandLine.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/pybench/CommandLine.py')
-rw-r--r--Tools/pybench/CommandLine.py104
1 files changed, 54 insertions, 50 deletions
diff --git a/Tools/pybench/CommandLine.py b/Tools/pybench/CommandLine.py
index 1cdcfc1..d0142f8 100644
--- a/Tools/pybench/CommandLine.py
+++ b/Tools/pybench/CommandLine.py
@@ -20,7 +20,7 @@ or contact the author. All Rights Reserved.
__version__ = '1.2'
-import sys, getopt, string, glob, os, re, exceptions, traceback
+import sys, getopt, glob, os, re, traceback
### Helpers
@@ -44,7 +44,7 @@ def _getopt_flags(options):
l.append(o.name+'=')
else:
l.append(o.name)
- return string.join(s,''),l
+ return ''.join(s), l
def invisible_input(prompt='>>> '):
@@ -102,7 +102,7 @@ _integerRangeRE = re.compile('\s*(-?\d+)\s*-\s*(-?\d+)\s*$')
def srange(s,
- split=string.split,integer=_integerRE,
+ integer=_integerRE,
integerRange=_integerRangeRE):
""" Converts a textual representation of integer numbers and ranges
@@ -116,7 +116,7 @@ def srange(s,
"""
l = []
append = l.append
- for entry in split(s,','):
+ for entry in s.split(','):
m = integer.match(entry)
if m:
append(int(m.groups()[0]))
@@ -293,7 +293,7 @@ class Application:
verbose = 0
# Internal errors to catch
- InternalError = exceptions.Exception
+ InternalError = BaseException
# Instance variables:
values = None # Dictionary of passed options (or default values)
@@ -353,20 +353,20 @@ class Application:
pass
except KeyboardInterrupt:
- print
- print '* User Break'
- print
+ print()
+ print('* User Break')
+ print()
rc = 1
except self.InternalError:
- print
- print '* Internal Error (use --debug to display the traceback)'
+ print()
+ print('* Internal Error (use --debug to display the traceback)')
if self.debug:
- print
+ print()
traceback.print_exc(20, sys.stdout)
elif self.verbose:
- print ' %s: %s' % sys.exc_info()[:2]
- print
+ print(' %s: %s' % sys.exc_info()[:2])
+ print()
rc = 1
raise SystemExit(rc)
@@ -449,13 +449,13 @@ class Application:
# Try to convert value to integer
try:
- value = string.atoi(value)
+ value = int(value)
except ValueError:
pass
# Find handler and call it (or count the number of option
# instances on the command line)
- handlername = 'handle' + string.replace(optionname, '-', '_')
+ handlername = 'handle' + optionname.replace('-', '_')
try:
handler = getattr(self, handlername)
except AttributeError:
@@ -494,54 +494,55 @@ class Application:
self.print_header()
if self.synopsis:
- print 'Synopsis:'
+ print('Synopsis:')
# To remain backward compatible:
try:
synopsis = self.synopsis % self.name
except (NameError, KeyError, TypeError):
synopsis = self.synopsis % self.__dict__
- print ' ' + synopsis
- print
+ print(' ' + synopsis)
+ print()
self.print_options()
if self.version:
- print 'Version:'
- print ' %s' % self.version
- print
+ print('Version:')
+ print(' %s' % self.version)
+ print()
if self.about:
- print string.strip(self.about % self.__dict__)
- print
+ about = self.about % self.__dict__
+ print(about.strip())
+ print()
if note:
- print '-'*72
- print 'Note:',note
- print
+ print('-'*72)
+ print('Note:',note)
+ print()
def notice(self,note):
- print '-'*72
- print 'Note:',note
- print '-'*72
- print
+ print('-'*72)
+ print('Note:',note)
+ print('-'*72)
+ print()
def print_header(self):
- print '-'*72
- print self.header % self.__dict__
- print '-'*72
- print
+ print('-'*72)
+ print(self.header % self.__dict__)
+ print('-'*72)
+ print()
def print_options(self):
options = self.options
- print 'Options and default settings:'
+ print('Options and default settings:')
if not options:
- print ' None'
+ print(' None')
return
long = filter(lambda x: x.prefix == '--', options)
short = filter(lambda x: x.prefix == '-', options)
items = short + long
for o in options:
- print ' ',o
- print
+ print(' ',o)
+ print()
#
# Example handlers:
@@ -579,26 +580,29 @@ class Application:
self.debug = 1
# We don't want to catch internal errors:
- self.InternalError = None
+ class NoErrorToCatch(Exception): pass
+ self.InternalError = NoErrorToCatch
def handle__copyright(self,arg):
self.print_header()
- print string.strip(self.copyright % self.__dict__)
- print
+ copyright = self.copyright % self.__dict__
+ print(copyright.strip())
+ print()
return 0
def handle__examples(self,arg):
self.print_header()
if self.examples:
- print 'Examples:'
- print
- print string.strip(self.examples % self.__dict__)
- print
+ print('Examples:')
+ print()
+ examples = self.examples % self.__dict__
+ print(examples.strip())
+ print()
else:
- print 'No examples available.'
- print
+ print('No examples available.')
+ print()
return 0
def main(self):
@@ -624,13 +628,13 @@ def _test():
options = [Option('-v','verbose')]
def handle_v(self,arg):
- print 'VERBOSE, Yeah !'
+ print('VERBOSE, Yeah !')
cmd = MyApplication()
if not cmd.values['-h']:
cmd.help()
- print 'files:',cmd.files
- print 'Bye...'
+ print('files:',cmd.files)
+ print('Bye...')
if __name__ == '__main__':
_test()