diff options
-rw-r--r-- | Doc/lib/libshlex.tex | 3 | ||||
-rw-r--r-- | Doc/lib/libshutil.tex | 11 | ||||
-rw-r--r-- | Doc/lib/libtarfile.tex | 10 | ||||
-rw-r--r-- | Doc/lib/libwinreg.tex | 2 | ||||
-rw-r--r-- | Lib/difflib.py | 2 | ||||
-rw-r--r-- | Lib/distutils/dir_util.py | 8 | ||||
-rwxr-xr-x | Lib/keyword.py | 3 | ||||
-rw-r--r-- | Lib/logging/__init__.py | 4 | ||||
-rwxr-xr-x | Lib/pydoc.py | 9 | ||||
-rw-r--r-- | Lib/tarfile.py | 14 | ||||
-rw-r--r-- | Lib/test/test_tarfile.py | 21 | ||||
-rw-r--r-- | Python/ceval.c | 2 | ||||
-rw-r--r-- | Tools/pybench/CommandLine.py | 104 | ||||
-rw-r--r-- | Tools/pybench/Lists.py | 4 | ||||
-rw-r--r-- | Tools/pybench/Strings.py | 41 | ||||
-rw-r--r-- | Tools/pybench/Unicode.py | 37 | ||||
-rw-r--r-- | Tools/pybench/clockres.py | 8 | ||||
-rwxr-xr-x | Tools/pybench/pybench.py | 230 | ||||
-rw-r--r-- | Tools/pybench/systimes.py | 24 | ||||
-rwxr-xr-x | runtests.sh | 2 |
20 files changed, 286 insertions, 253 deletions
diff --git a/Doc/lib/libshlex.tex b/Doc/lib/libshlex.tex index 23babd3..230ae9f 100644 --- a/Doc/lib/libshlex.tex +++ b/Doc/lib/libshlex.tex @@ -28,6 +28,9 @@ in \POSIX{} mode by default, but uses non-\POSIX{} mode if the \var{posix} argument is false. \versionadded{2.3} \versionchanged[Added the \var{posix} parameter]{2.6} +\note{Since the \function{split()} function instantiates a \class{shlex} + instance, passing \code{None} for \var{s} will read the string + to split from standard input.} \end{funcdesc} The \module{shlex} module defines the following class: diff --git a/Doc/lib/libshutil.tex b/Doc/lib/libshutil.tex index 5201332..65cba54 100644 --- a/Doc/lib/libshutil.tex +++ b/Doc/lib/libshutil.tex @@ -91,11 +91,12 @@ file type and creator codes will not be correct. \end{funcdesc} \begin{funcdesc}{rmtree}{path\optional{, ignore_errors\optional{, onerror}}} - Delete an entire directory tree.\index{directory!deleting} - If \var{ignore_errors} is true, - errors resulting from failed removals will be ignored; if false or - omitted, such errors are handled by calling a handler specified by - \var{onerror} or, if that is omitted, they raise an exception. + \index{directory!deleting} + Delete an entire directory tree (\var{path} must point to a directory). + If \var{ignore_errors} is true, errors resulting from failed removals + will be ignored; if false or omitted, such errors are handled by + calling a handler specified by \var{onerror} or, if that is omitted, + they raise an exception. If \var{onerror} is provided, it must be a callable that accepts three parameters: \var{function}, \var{path}, and \var{excinfo}. diff --git a/Doc/lib/libtarfile.tex b/Doc/lib/libtarfile.tex index 54683a7..95ea051 100644 --- a/Doc/lib/libtarfile.tex +++ b/Doc/lib/libtarfile.tex @@ -314,13 +314,17 @@ tar archive several times. Each archive member is represented by a \end{notice} \end{methoddesc} -\begin{methoddesc}{add}{name\optional{, arcname\optional{, recursive}}} +\begin{methoddesc}{add}{name\optional{, arcname\optional{, recursive\optional{, exclude}}}} Add the file \var{name} to the archive. \var{name} may be any type of file (directory, fifo, symbolic link, etc.). If given, \var{arcname} specifies an alternative name for the file in the archive. Directories are added recursively by default. - This can be avoided by setting \var{recursive} to \constant{False}; - the default is \constant{True}. + This can be avoided by setting \var{recursive} to \constant{False}. + If \var{exclude} is given it must be a function that takes one filename + argument and returns a boolean value. Depending on this value the + respective file is either excluded (\constant{True}) or added + (\constant{False}). + \versionchanged[Added the \var{exclude} parameter]{2.6} \end{methoddesc} \begin{methoddesc}{addfile}{tarinfo\optional{, fileobj}} diff --git a/Doc/lib/libwinreg.tex b/Doc/lib/libwinreg.tex index 1a38964..d31c3ca 100644 --- a/Doc/lib/libwinreg.tex +++ b/Doc/lib/libwinreg.tex @@ -321,7 +321,7 @@ This module offers the following functions: \var{key} is an already open key, or one of the predefined \constant{HKEY_*} constants. - \var{sub_key} is a string that names the subkey with which the + \var{value_name} is a string that names the subkey with which the value is associated. \var{type} is an integer that specifies the type of the data. diff --git a/Lib/difflib.py b/Lib/difflib.py index 601479c..f992650 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -719,7 +719,7 @@ def get_close_matches(word, possibilities, n=3, cutoff=0.6): >>> import keyword as _keyword >>> get_close_matches("wheel", _keyword.kwlist) ['while'] - >>> get_close_matches("apple", _keyword.kwlist) + >>> get_close_matches("Apple", _keyword.kwlist) [] >>> get_close_matches("accept", _keyword.kwlist) ['except'] diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py index 0cfca2e..a6c4416 100644 --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -96,14 +96,12 @@ def create_tree (base_dir, files, mode=0o777, verbose=0, dry_run=0): for 'mkpath()'.""" # First get the list of directories to create - need_dir = {} + need_dir = set() for file in files: - need_dir[os.path.join(base_dir, os.path.dirname(file))] = 1 - need_dirs = need_dir.keys() - need_dirs.sort() + need_dir.add(os.path.join(base_dir, os.path.dirname(file))) # Now create them - for dir in need_dirs: + for dir in sorted(need_dir): mkpath(dir, mode, dry_run=dry_run) # create_tree () diff --git a/Lib/keyword.py b/Lib/keyword.py index 3fa801d..9c49cd2 100755 --- a/Lib/keyword.py +++ b/Lib/keyword.py @@ -14,6 +14,9 @@ __all__ = ["iskeyword", "kwlist"] kwlist = [ #--start keywords-- + 'False', + 'None', + 'True', 'and', 'as', 'assert', diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 6dc5387..2c1e706 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -400,7 +400,7 @@ class Formatter: traceback.print_exception(ei[0], ei[1], ei[2], None, sio) s = sio.getvalue() sio.close() - if s[-1] == "\n": + if s[-1:] == "\n": s = s[:-1] return s @@ -427,7 +427,7 @@ class Formatter: if not record.exc_text: record.exc_text = self.formatException(record.exc_info) if record.exc_text: - if s[-1] != "\n": + if s[-1:] != "\n": s = s + "\n" s = s + record.exc_text return s diff --git a/Lib/pydoc.py b/Lib/pydoc.py index e4074dc..4594333 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1748,17 +1748,16 @@ such as "spam", type "modules spam". ''' % sys.version[:3]) def list(self, items, columns=4, width=80): - items = items[:] - items.sort() - colw = width / columns - rows = (len(items) + columns - 1) / columns + items = list(sorted(items)) + colw = width // columns + rows = (len(items) + columns - 1) // columns for row in range(rows): for col in range(columns): i = col * rows + row if i < len(items): self.output.write(items[i]) if col < columns - 1: - self.output.write(' ' + ' ' * (colw-1 - len(items[i]))) + self.output.write(' ' + ' ' * (colw - 1 - len(items[i]))) self.output.write('\n') def listkeywords(self): diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 94dac98..92daa5a 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1925,18 +1925,24 @@ class TarFile(object): print("link to", tarinfo.linkname, end=' ') print() - def add(self, name, arcname=None, recursive=True): + def add(self, name, arcname=None, recursive=True, exclude=None): """Add the file `name' to the archive. `name' may be any type of file (directory, fifo, symbolic link, etc.). If given, `arcname' specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by - setting `recursive' to False. + setting `recursive' to False. `exclude' is a function that should + return True for each filename to be excluded. """ self._check("aw") if arcname is None: arcname = name + # Exclude pathnames. + if exclude is not None and exclude(name): + self._dbg(2, "tarfile: Excluded %r" % name) + return + # Skip if somebody tries to archive the archive... if self.name is not None and os.path.abspath(name) == self.name: self._dbg(2, "tarfile: Skipped %r" % name) @@ -1949,7 +1955,7 @@ class TarFile(object): if arcname == ".": arcname = "" for f in os.listdir(name): - self.add(f, os.path.join(arcname, f)) + self.add(f, os.path.join(arcname, f), recursive, exclude) return self._dbg(1, name) @@ -1971,7 +1977,7 @@ class TarFile(object): self.addfile(tarinfo) if recursive: for f in os.listdir(name): - self.add(os.path.join(name, f), os.path.join(arcname, f)) + self.add(os.path.join(name, f), os.path.join(arcname, f), recursive, exclude) else: self.addfile(tarinfo) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 50c5bbe..1bfe9dcd 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -558,6 +558,27 @@ class WriteTest(unittest.TestCase): os.chdir(cwd) self.assert_(tar.getnames() == [], "added the archive to itself") + def test_exclude(self): + tempdir = os.path.join(TEMPDIR, "exclude") + os.mkdir(tempdir) + try: + for name in ("foo", "bar", "baz"): + name = os.path.join(tempdir, name) + open(name, "wb").close() + + def exclude(name): + return os.path.isfile(name) + + tar = tarfile.open(tmpname, self.mode, encoding="iso8859-1") + tar.add(tempdir, arcname="empty_dir", exclude=exclude) + tar.close() + + tar = tarfile.open(tmpname, "r") + self.assertEqual(len(tar.getmembers()), 1) + self.assertEqual(tar.getnames()[0], "empty_dir") + finally: + shutil.rmtree(tempdir) + class StreamWriteTest(unittest.TestCase): diff --git a/Python/ceval.c b/Python/ceval.c index bb05a16..6c69b08 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3959,7 +3959,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) } } -#define CANNOT_CATCH_MSG "catching classes that do not inherit from"\ +#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\ "BaseException is not allowed" static PyObject * 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() diff --git a/Tools/pybench/Lists.py b/Tools/pybench/Lists.py index aedd352..9aeb408 100644 --- a/Tools/pybench/Lists.py +++ b/Tools/pybench/Lists.py @@ -138,8 +138,8 @@ class ListSlicing(Test): def test(self): - n = range(100) - r = range(25) + n = list(range(100)) + r = list(range(25)) for i in range(self.rounds): diff --git a/Tools/pybench/Strings.py b/Tools/pybench/Strings.py index 2668d6b..25e2ad5 100644 --- a/Tools/pybench/Strings.py +++ b/Tools/pybench/Strings.py @@ -1,5 +1,4 @@ from pybench import Test -from string import join import sys class ConcatStrings(Test): @@ -11,8 +10,8 @@ class ConcatStrings(Test): def test(self): # Make sure the strings are *not* interned - s = join(map(str,range(100))) - t = join(map(str,range(1,101))) + s = ''.join(map(str,range(100))) + t = ''.join(map(str,range(1,101))) for i in range(self.rounds): t + s @@ -77,8 +76,8 @@ class ConcatStrings(Test): def calibrate(self): - s = join(map(str,range(100))) - t = join(map(str,range(1,101))) + s = ''.join(map(str,range(100))) + t = ''.join(map(str,range(1,101))) for i in range(self.rounds): pass @@ -93,8 +92,8 @@ class CompareStrings(Test): def test(self): # Make sure the strings are *not* interned - s = join(map(str,range(10))) - t = join(map(str,range(10))) + "abc" + s = ''.join(map(str,range(10))) + t = ''.join(map(str,range(10))) + "abc" for i in range(self.rounds): t < s @@ -159,8 +158,8 @@ class CompareStrings(Test): def calibrate(self): - s = join(map(str,range(10))) - t = join(map(str,range(10))) + "abc" + s = ''.join(map(str,range(10))) + t = ''.join(map(str,range(10))) + "abc" for i in range(self.rounds): pass @@ -175,7 +174,7 @@ class CompareInternedStrings(Test): def test(self): # Make sure the strings *are* interned - s = sys.intern(join(map(str,range(10)))) + s = sys.intern(''.join(map(str,range(10)))) t = s for i in range(self.rounds): @@ -241,7 +240,7 @@ class CompareInternedStrings(Test): def calibrate(self): - s = sys.intern(join(map(str,range(10)))) + s = sys.intern(''.join(map(str,range(10)))) t = s for i in range(self.rounds): @@ -331,7 +330,7 @@ class StringSlicing(Test): def test(self): - s = join(map(str,range(100))) + s = ''.join(map(str,range(100))) for i in range(self.rounds): @@ -377,7 +376,7 @@ class StringSlicing(Test): def calibrate(self): - s = join(map(str,range(100))) + s = ''.join(map(str,range(100))) for i in range(self.rounds): pass @@ -394,10 +393,10 @@ if hasattr('', 'lower'): def test(self): - s = join(map(chr,range(20)),'') - t = join(map(chr,range(50)),'') - u = join(map(chr,range(100)),'') - v = join(map(chr,range(256)),'') + s = ''.join(map(chr,range(20))) + t = ''.join(map(chr,range(50))) + u = ''.join(map(chr,range(100))) + v = ''.join(map(chr,range(256))) for i in range(self.rounds): @@ -451,10 +450,10 @@ if hasattr('', 'lower'): def calibrate(self): - s = join(map(chr,range(20)),'') - t = join(map(chr,range(50)),'') - u = join(map(chr,range(100)),'') - v = join(map(chr,range(256)),'') + s = ''.join(map(chr,range(20))) + t = ''.join(map(chr,range(50))) + u = ''.join(map(chr,range(100))) + v = ''.join(map(chr,range(256))) for i in range(self.rounds): pass diff --git a/Tools/pybench/Unicode.py b/Tools/pybench/Unicode.py index 21e24c0..b17a7c3 100644 --- a/Tools/pybench/Unicode.py +++ b/Tools/pybench/Unicode.py @@ -4,7 +4,6 @@ except NameError: raise ImportError from pybench import Test -from string import join class ConcatUnicode(Test): @@ -15,8 +14,8 @@ class ConcatUnicode(Test): def test(self): # Make sure the strings are *not* interned - s = unicode(join(map(str,range(100)))) - t = unicode(join(map(str,range(1,101)))) + s = unicode(u''.join(map(str,range(100)))) + t = unicode(u''.join(map(str,range(1,101)))) for i in range(self.rounds): t + s @@ -81,8 +80,8 @@ class ConcatUnicode(Test): def calibrate(self): - s = unicode(join(map(str,range(100)))) - t = unicode(join(map(str,range(1,101)))) + s = unicode(u''.join(map(str,range(100)))) + t = unicode(u''.join(map(str,range(1,101)))) for i in range(self.rounds): pass @@ -97,8 +96,8 @@ class CompareUnicode(Test): def test(self): # Make sure the strings are *not* interned - s = unicode(join(map(str,range(10)))) - t = unicode(join(map(str,range(10))) + "abc") + s = unicode(u''.join(map(str,range(10)))) + t = unicode(u''.join(map(str,range(10))) + "abc") for i in range(self.rounds): t < s @@ -163,8 +162,8 @@ class CompareUnicode(Test): def calibrate(self): - s = unicode(join(map(str,range(10)))) - t = unicode(join(map(str,range(10))) + "abc") + s = unicode(u''.join(map(str,range(10)))) + t = unicode(u''.join(map(str,range(10))) + "abc") for i in range(self.rounds): pass @@ -253,7 +252,7 @@ class UnicodeSlicing(Test): def test(self): - s = unicode(join(map(str,range(100)))) + s = unicode(u''.join(map(str,range(100)))) for i in range(self.rounds): @@ -299,7 +298,7 @@ class UnicodeSlicing(Test): def calibrate(self): - s = unicode(join(map(str,range(100)))) + s = unicode(u''.join(map(str,range(100)))) for i in range(self.rounds): pass @@ -314,10 +313,10 @@ class UnicodeMappings(Test): def test(self): - s = join(map(unichr,range(20)),'') - t = join(map(unichr,range(100)),'') - u = join(map(unichr,range(500)),'') - v = join(map(unichr,range(1000)),'') + s = u''.join(map(unichr,range(20))) + t = u''.join(map(unichr,range(100))) + u = u''.join(map(unichr,range(500))) + v = u''.join(map(unichr,range(1000))) for i in range(self.rounds): @@ -371,10 +370,10 @@ class UnicodeMappings(Test): def calibrate(self): - s = join(map(unichr,range(20)),'') - t = join(map(unichr,range(100)),'') - u = join(map(unichr,range(500)),'') - v = join(map(unichr,range(1000)),'') + s = u''.join(map(unichr,range(20))) + t = u''.join(map(unichr,range(100))) + u = u''.join(map(unichr,range(500))) + v = u''.join(map(unichr,range(1000))) for i in range(self.rounds): pass diff --git a/Tools/pybench/clockres.py b/Tools/pybench/clockres.py index 64095b3..42f5ee7 100644 --- a/Tools/pybench/clockres.py +++ b/Tools/pybench/clockres.py @@ -33,11 +33,11 @@ def clockres(timer): return min_diff if __name__ == '__main__': - print 'Clock resolution of various timer implementations:' - print 'time.clock: %10.3fus' % (clockres(time.clock) * 1e6) - print 'time.time: %10.3fus' % (clockres(time.time) * 1e6) + print('Clock resolution of various timer implementations:') + print('time.clock: %10.3fus' % (clockres(time.clock) * 1e6)) + print('time.time: %10.3fus' % (clockres(time.time) * 1e6)) try: import systimes - print 'systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6) + print('systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6)) except ImportError: pass diff --git a/Tools/pybench/pybench.py b/Tools/pybench/pybench.py index 6c9d445..17b4704 100755 --- a/Tools/pybench/pybench.py +++ b/Tools/pybench/pybench.py @@ -34,7 +34,7 @@ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE ! """ -import sys, time, operator, string, platform +import sys, time, operator, platform from CommandLine import * try: @@ -103,7 +103,7 @@ def get_timer(timertype): def get_machine_details(): if _debug: - print 'Getting machine details...' + print('Getting machine details...') buildno, builddate = platform.python_build() python = platform.python_version() try: @@ -146,7 +146,8 @@ def print_machine_details(d, indent=''): d.get('buildno', 'n/a')), ' Unicode: %s' % d.get('unicode', 'n/a'), ] - print indent + string.join(l, '\n' + indent) + '\n' + joiner = '\n' + indent + print(indent + joiner.join(l) + '\n') ### Test baseclass @@ -280,9 +281,9 @@ class Test: prep_times.append(t) min_prep_time = min(prep_times) if _debug: - print - print 'Calib. prep time = %.6fms' % ( - min_prep_time * MILLI_SECONDS) + print() + print('Calib. prep time = %.6fms' % ( + min_prep_time * MILLI_SECONDS)) # Time the calibration runs (doing CALIBRATION_LOOPS loops of # .calibrate() method calls each) @@ -298,8 +299,8 @@ class Test: min_overhead = min(self.overhead_times) max_overhead = max(self.overhead_times) if _debug: - print 'Calib. overhead time = %.6fms' % ( - min_overhead * MILLI_SECONDS) + print('Calib. overhead time = %.6fms' % ( + min_overhead * MILLI_SECONDS)) if min_overhead < 0.0: raise ValueError('calibration setup did not work') if max_overhead - min_overhead > 0.1: @@ -436,7 +437,7 @@ class Benchmark: # Init vars self.tests = {} if _debug: - print 'Getting machine details...' + print('Getting machine details...') self.machine_details = get_machine_details() # Make .version an instance attribute to have it saved in the @@ -473,8 +474,8 @@ class Benchmark: # Add tests if self.verbose: - print 'Searching for tests ...' - print '--------------------------------------' + print('Searching for tests ...') + print('--------------------------------------') for testclass in setupmod.__dict__.values(): if not hasattr(testclass, 'is_a_test'): continue @@ -488,77 +489,74 @@ class Benchmark: warp=self.warp, calibration_runs=self.calibration_runs, timer=self.timer) - l = self.tests.keys() - l.sort() + l = sorted(self.tests) if self.verbose: for name in l: - print ' %s' % name - print '--------------------------------------' - print ' %i tests found' % len(l) - print + print(' %s' % name) + print('--------------------------------------') + print(' %i tests found' % len(l)) + print() def calibrate(self): - print 'Calibrating tests. Please wait...', + print('Calibrating tests. Please wait...', end=' ') if self.verbose: - print - print - print 'Test min max' - print '-' * LINE - tests = self.tests.items() - tests.sort() + print() + print() + print('Test min max') + print('-' * LINE) + tests = sorted(self.tests.items()) for i in range(len(tests)): name, test = tests[i] test.calibrate_test() if self.verbose: - print '%30s: %6.3fms %6.3fms' % \ + print('%30s: %6.3fms %6.3fms' % \ (name, min(test.overhead_times) * MILLI_SECONDS, - max(test.overhead_times) * MILLI_SECONDS) + max(test.overhead_times) * MILLI_SECONDS)) if self.verbose: - print - print 'Done with the calibration.' + print() + print('Done with the calibration.') else: - print 'done.' - print + print('done.') + print() def run(self): - tests = self.tests.items() - tests.sort() + tests = sorted(self.tests.items()) timer = self.get_timer() - print 'Running %i round(s) of the suite at warp factor %i:' % \ - (self.rounds, self.warp) - print + print('Running %i round(s) of the suite at warp factor %i:' % \ + (self.rounds, self.warp)) + print() self.roundtimes = [] for i in range(self.rounds): if self.verbose: - print ' Round %-25i effective absolute overhead' % (i+1) + print(' Round %-25i effective absolute overhead' % (i+1)) total_eff_time = 0.0 for j in range(len(tests)): name, test = tests[j] if self.verbose: - print '%30s:' % name, + print('%30s:' % name, end=' ') test.run() (eff_time, abs_time, min_overhead) = test.last_timing total_eff_time = total_eff_time + eff_time if self.verbose: - print ' %5.0fms %5.0fms %7.3fms' % \ + print(' %5.0fms %5.0fms %7.3fms' % \ (eff_time * MILLI_SECONDS, abs_time * MILLI_SECONDS, - min_overhead * MILLI_SECONDS) + min_overhead * MILLI_SECONDS)) self.roundtimes.append(total_eff_time) if self.verbose: - print (' ' - ' ------------------------------') - print (' ' + print((' ' + ' ------------------------------')) + print((' ' ' Totals: %6.0fms' % - (total_eff_time * MILLI_SECONDS)) - print + (total_eff_time * MILLI_SECONDS))) + print() else: - print '* Round %i done in %.3f seconds.' % (i+1, - total_eff_time) - print + print('* Round %i done in %.3f seconds.' % (i+1, + total_eff_time)) + print() def stat(self): @@ -583,25 +581,24 @@ class Benchmark: def print_header(self, title='Benchmark'): - print '-' * LINE - print '%s: %s' % (title, self.name) - print '-' * LINE - print - print ' Rounds: %s' % self.rounds - print ' Warp: %s' % self.warp - print ' Timer: %s' % self.timer - print + print('-' * LINE) + print('%s: %s' % (title, self.name)) + print('-' * LINE) + print() + print(' Rounds: %s' % self.rounds) + print(' Warp: %s' % self.warp) + print(' Timer: %s' % self.timer) + print() if self.machine_details: print_machine_details(self.machine_details, indent=' ') - print + print() def print_benchmark(self, hidenoise=0, limitnames=None): - print ('Test ' - ' minimum average operation overhead') - print '-' * LINE - tests = self.tests.items() - tests.sort() + print(('Test ' + ' minimum average operation overhead')) + print('-' * LINE) + tests = sorted(self.tests.items()) total_min_time = 0.0 total_avg_time = 0.0 for name, test in tests: @@ -615,43 +612,42 @@ class Benchmark: min_overhead) = test.stat() total_min_time = total_min_time + min_time total_avg_time = total_avg_time + avg_time - print '%30s: %5.0fms %5.0fms %6.2fus %7.3fms' % \ + print('%30s: %5.0fms %5.0fms %6.2fus %7.3fms' % \ (name, min_time * MILLI_SECONDS, avg_time * MILLI_SECONDS, op_avg * MICRO_SECONDS, - min_overhead *MILLI_SECONDS) - print '-' * LINE - print ('Totals: ' + min_overhead *MILLI_SECONDS)) + print('-' * LINE) + print(('Totals: ' ' %6.0fms %6.0fms' % (total_min_time * MILLI_SECONDS, total_avg_time * MILLI_SECONDS, - )) - print + ))) + print() def print_comparison(self, compare_to, hidenoise=0, limitnames=None): # Check benchmark versions if compare_to.version != self.version: - print ('* Benchmark versions differ: ' + print(('* Benchmark versions differ: ' 'cannot compare this benchmark to "%s" !' % - compare_to.name) - print + compare_to.name)) + print() self.print_benchmark(hidenoise=hidenoise, limitnames=limitnames) return # Print header compare_to.print_header('Comparing with') - print ('Test ' - ' minimum run-time average run-time') - print (' ' - ' this other diff this other diff') - print '-' * LINE + print(('Test ' + ' minimum run-time average run-time')) + print((' ' + ' this other diff this other diff')) + print('-' * LINE) # Print test comparisons - tests = self.tests.items() - tests.sort() + tests = sorted(self.tests.items()) total_min_time = other_total_min_time = 0.0 total_avg_time = other_total_avg_time = 0.0 benchmarks_compatible = self.compatible(compare_to) @@ -704,15 +700,15 @@ class Benchmark: # Benchmark or tests are not comparible min_diff, avg_diff = 'n/a', 'n/a' tests_compatible = 0 - print '%30s: %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' % \ + print('%30s: %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' % \ (name, min_time * MILLI_SECONDS, other_min_time * MILLI_SECONDS * compare_to.warp / self.warp, min_diff, avg_time * MILLI_SECONDS, other_avg_time * MILLI_SECONDS * compare_to.warp / self.warp, - avg_diff) - print '-' * LINE + avg_diff)) + print('-' * LINE) # Summarise test results if not benchmarks_compatible or not tests_compatible: @@ -730,7 +726,7 @@ class Benchmark: (other_total_avg_time * compare_to.warp) - 1.0) * PERCENT) else: avg_diff = 'n/a' - print ('Totals: ' + print(('Totals: ' ' %5.0fms %5.0fms %7s %5.0fms %5.0fms %7s' % (total_min_time * MILLI_SECONDS, (other_total_min_time * compare_to.warp/self.warp @@ -740,11 +736,11 @@ class Benchmark: (other_total_avg_time * compare_to.warp/self.warp * MILLI_SECONDS), avg_diff - )) - print - print '(this=%s, other=%s)' % (self.name, - compare_to.name) - print + ))) + print() + print('(this=%s, other=%s)' % (self.name, + compare_to.name)) + print() class PyBenchCmdline(Application): @@ -823,8 +819,8 @@ python pybench.py -s p25.pybench -c p21.pybench limitnames = self.values['-t'] if limitnames: if _debug: - print '* limiting test names to one with substring "%s"' % \ - limitnames + print('* limiting test names to one with substring "%s"' % \ + limitnames) limitnames = re.compile(limitnames, re.I) else: limitnames = None @@ -833,26 +829,26 @@ python pybench.py -s p25.pybench -c p21.pybench calibration_runs = self.values['-C'] timer = self.values['--timer'] - print '-' * LINE - print 'PYBENCH %s' % __version__ - print '-' * LINE - print '* using %s %s' % ( + print('-' * LINE) + print('PYBENCH %s' % __version__) + print('-' * LINE) + print('* using %s %s' % ( platform.python_implementation(), - string.join(string.split(sys.version), ' ')) + ' '.join(sys.version.split()))) # Switch off garbage collection if not withgc: try: import gc except ImportError: - print '* Python version doesn\'t support garbage collection' + print('* Python version doesn\'t support garbage collection') else: try: gc.disable() except NotImplementedError: - print '* Python version doesn\'t support gc.disable' + print('* Python version doesn\'t support gc.disable') else: - print '* disabled garbage collection' + print('* disabled garbage collection') # "Disable" sys check interval if not withsyscheck: @@ -861,18 +857,18 @@ python pybench.py -s p25.pybench -c p21.pybench try: sys.setcheckinterval(value) except (AttributeError, NotImplementedError): - print '* Python version doesn\'t support sys.setcheckinterval' + print('* Python version doesn\'t support sys.setcheckinterval') else: - print '* system check interval set to maximum: %s' % value + print('* system check interval set to maximum: %s' % value) if timer == TIMER_SYSTIMES_PROCESSTIME: import systimes - print '* using timer: systimes.processtime (%s)' % \ - systimes.SYSTIMES_IMPLEMENTATION + print('* using timer: systimes.processtime (%s)' % \ + systimes.SYSTIMES_IMPLEMENTATION) else: - print '* using timer: %s' % timer + print('* using timer: %s' % timer) - print + print() if compare_to: try: @@ -882,9 +878,9 @@ python pybench.py -s p25.pybench -c p21.pybench f.close() compare_to = bench except IOError as reason: - print '* Error opening/reading file %s: %s' % ( + print('* Error opening/reading file %s: %s' % ( repr(compare_to), - reason) + reason)) compare_to = None if show_bench: @@ -902,16 +898,16 @@ python pybench.py -s p25.pybench -c p21.pybench bench.print_benchmark(hidenoise=hidenoise, limitnames=limitnames) except IOError as reason: - print '* Error opening/reading file %s: %s' % ( + print('* Error opening/reading file %s: %s' % ( repr(show_bench), - reason) - print + reason)) + print() return if reportfile: - print 'Creating benchmark: %s (rounds=%i, warp=%i)' % \ - (reportfile, rounds, warp) - print + print('Creating benchmark: %s (rounds=%i, warp=%i)' % \ + (reportfile, rounds, warp)) + print() # Create benchmark object bench = Benchmark(reportfile, @@ -925,9 +921,9 @@ python pybench.py -s p25.pybench -c p21.pybench bench.calibrate() bench.run() except KeyboardInterrupt: - print - print '*** KeyboardInterrupt -- Aborting' - print + print() + print('*** KeyboardInterrupt -- Aborting') + print() return bench.print_header() if compare_to: @@ -948,12 +944,12 @@ python pybench.py -s p25.pybench -c p21.pybench pickle.dump(bench,f) f.close() except IOError as reason: - print '* Error opening/writing reportfile' + print('* Error opening/writing reportfile') except IOError as reason: - print '* Error opening/writing reportfile %s: %s' % ( + print('* Error opening/writing reportfile %s: %s' % ( reportfile, - reason) - print + reason)) + print() if __name__ == '__main__': PyBenchCmdline() diff --git a/Tools/pybench/systimes.py b/Tools/pybench/systimes.py index 13bed2f..fb3d3b5 100644 --- a/Tools/pybench/systimes.py +++ b/Tools/pybench/systimes.py @@ -185,27 +185,27 @@ def some_workload(): x = x + 1 def test_workload(): - print 'Testing systimes() under load conditions' + print('Testing systimes() under load conditions') t0 = systimes() some_workload() t1 = systimes() - print 'before:', t0 - print 'after:', t1 - print 'differences:', (t1[0] - t0[0], t1[1] - t0[1]) - print + print('before:', t0) + print('after:', t1) + print('differences:', (t1[0] - t0[0], t1[1] - t0[1])) + print() def test_idle(): - print 'Testing systimes() under idle conditions' + print('Testing systimes() under idle conditions') t0 = systimes() time.sleep(1) t1 = systimes() - print 'before:', t0 - print 'after:', t1 - print 'differences:', (t1[0] - t0[0], t1[1] - t0[1]) - print + print('before:', t0) + print('after:', t1) + print('differences:', (t1[0] - t0[0], t1[1] - t0[1])) + print() if __name__ == '__main__': - print 'Using %s as timer' % SYSTIMES_IMPLEMENTATION - print + print('Using %s as timer' % SYSTIMES_IMPLEMENTATION) + print() test_workload() test_idle() diff --git a/runtests.sh b/runtests.sh index 310f8bb..2a6c0ba 100755 --- a/runtests.sh +++ b/runtests.sh @@ -25,7 +25,7 @@ mkdir -p OUT >SKIPPED # The -u flag (edit this file to change). -UFLAG="-unetwork" +UFLAG="" # Compute the list of tests to run. case $# in |