Commit 486364b8 authored by Guido van Rossum's avatar Guido van Rossum

Merged revisions 56020-56124 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/p3yk

................
  r56037 | georg.brandl | 2007-06-19 05:33:20 -0700 (Tue, 19 Jun 2007) | 2 lines

  Patch #1739659: don't slice dict.keys() in pydoc.
................
  r56060 | martin.v.loewis | 2007-06-21 13:00:02 -0700 (Thu, 21 Jun 2007) | 2 lines

  Regenerate to add True, False, None.
................
  r56069 | neal.norwitz | 2007-06-21 22:31:56 -0700 (Thu, 21 Jun 2007) | 1 line

  Get the doctest working again after adding None, True, and False as kewyords.
................
  r56070 | neal.norwitz | 2007-06-21 23:25:33 -0700 (Thu, 21 Jun 2007) | 1 line

  Add space to error message.
................
  r56071 | neal.norwitz | 2007-06-21 23:40:04 -0700 (Thu, 21 Jun 2007) | 6 lines

  Get pybench working, primarily
   * Use print function
   * Stop using string module
   * Use sorted instead of assuming dict methods return lists
   * Convert range result to a list
................
  r56089 | collin.winter | 2007-06-26 10:31:48 -0700 (Tue, 26 Jun 2007) | 1 line

  Fix AttributeError in distutils/dir_util.py.
................
  r56124 | guido.van.rossum | 2007-06-29 18:04:31 -0700 (Fri, 29 Jun 2007) | 30 lines

  Merged revisions 56014-56123 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r56019 | lars.gustaebel | 2007-06-18 04:42:11 -0700 (Mon, 18 Jun 2007) | 2 lines

    Added exclude keyword argument to the TarFile.add() method.
  ........
    r56023 | lars.gustaebel | 2007-06-18 13:05:55 -0700 (Mon, 18 Jun 2007) | 3 lines

    Added missing \versionchanged tag for the new exclude
    parameter.
  ........
    r56038 | georg.brandl | 2007-06-19 05:36:00 -0700 (Tue, 19 Jun 2007) | 2 lines

    Bug #1737864: allow empty message in logging format routines.
  ........
    r56040 | georg.brandl | 2007-06-19 05:38:20 -0700 (Tue, 19 Jun 2007) | 2 lines

    Bug #1739115: make shutil.rmtree docs clear wrt. file deletion.
  ........
    r56084 | georg.brandl | 2007-06-25 08:21:23 -0700 (Mon, 25 Jun 2007) | 2 lines

    Bug #1742901: document None behavior of shlex.split.
  ........
    r56091 | georg.brandl | 2007-06-27 07:09:56 -0700 (Wed, 27 Jun 2007) | 2 lines

    Fix a variable name in winreg docs.
  ........
................
parent 8ddff708
......@@ -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:
......
......@@ -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}.
......
......@@ -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}}
......
......@@ -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.
......
......@@ -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']
......
......@@ -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 ()
......
......@@ -14,6 +14,9 @@ __all__ = ["iskeyword", "kwlist"]
kwlist = [
#--start keywords--
'False',
'None',
'True',
'and',
'as',
'assert',
......
......@@ -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
......
......@@ -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):
......
......@@ -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)
......
......@@ -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):
......
......@@ -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 *
......
......@@ -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()
......@@ -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):
......
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
......
......@@ -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
......
......@@ -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
This diff is collapsed.
......@@ -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()
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment