Merged revisions 53005-53303 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53012 | walter.doerwald | 2006-12-12 22:55:31 +0100 (Tue, 12 Dec 2006) | 2 lines
Fix typo.
........
r53023 | brett.cannon | 2006-12-13 23:31:37 +0100 (Wed, 13 Dec 2006) | 2 lines
Remove an unneeded import of 'warnings'.
........
r53025 | brett.cannon | 2006-12-14 00:02:38 +0100 (Thu, 14 Dec 2006) | 2 lines
Remove unneeded imports of 'warnings'.
........
r53026 | brett.cannon | 2006-12-14 00:09:53 +0100 (Thu, 14 Dec 2006) | 4 lines
Add test.test_support.guard_warnings_filter . This function returns a context
manager that protects warnings.filter from being modified once the context is
exited.
........
r53029 | george.yoshida | 2006-12-14 03:22:44 +0100 (Thu, 14 Dec 2006) | 2 lines
Note that guard_warnings_filter was added in 2.6
........
r53031 | vinay.sajip | 2006-12-14 09:53:55 +0100 (Thu, 14 Dec 2006) | 1 line
Added news on recent changes to logging
........
r53032 | andrew.kuchling | 2006-12-14 19:57:53 +0100 (Thu, 14 Dec 2006) | 1 line
[Patch #1599256 from David Watson] check that os.fsync is available before using it
........
r53042 | kurt.kaiser | 2006-12-15 06:13:11 +0100 (Fri, 15 Dec 2006) | 6 lines
1. Avoid hang when encountering a duplicate in a completion list. Bug 1571112.
2. Duplicate some old entries from Python's NEWS to IDLE's NEWS.txt
M AutoCompleteWindow.py
M NEWS.txt
........
r53048 | andrew.kuchling | 2006-12-18 18:12:31 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1618083] Add missing word; make a few grammar fixes
........
r53050 | andrew.kuchling | 2006-12-18 18:16:05 +0100 (Mon, 18 Dec 2006) | 1 line
Bump version
........
r53051 | andrew.kuchling | 2006-12-18 18:22:07 +0100 (Mon, 18 Dec 2006) | 1 line
[Bug #1616726] Fix description of generator.close(); if you raise some random exception, the exception is raised and doesn't trigger a RuntimeError
........
r53052 | andrew.kuchling | 2006-12-18 18:38:14 +0100 (Mon, 18 Dec 2006) | 1 line
Describe new methods in Queue module
........
r53053 | andrew.kuchling | 2006-12-18 20:22:24 +0100 (Mon, 18 Dec 2006) | 1 line
[Patch #1615868 by Lars Gustaebel] Use Py_off_t to fix BZ2File.seek() for offsets > 2Gb
........
r53057 | andrew.kuchling | 2006-12-18 22:29:07 +0100 (Mon, 18 Dec 2006) | 1 line
Fix markup
........
r53063 | thomas.wouters | 2006-12-19 09:17:50 +0100 (Tue, 19 Dec 2006) | 5 lines
Make sre's SubPattern objects accept slice objects like it already accepts
simple slices.
........
r53065 | andrew.kuchling | 2006-12-19 15:13:05 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1618455 by Ben Maurer] Improve speed of HMAC by using str.translate()
instead of a more general XOR that has to construct a list.
Slightly modified from Maurer's patch: the _strxor() function is no longer
necessary at all.
........
r53066 | andrew.kuchling | 2006-12-19 15:28:23 +0100 (Tue, 19 Dec 2006) | 9 lines
[Bug #1613651] Document socket.recv_into, socket.recvfrom_into
Also, the text for recvfrom told you to read recv() for an explanation of the
'flags' argument, but recv() just pointed you at the man page. Copied the
man-page text to recvfrom(), recvfrom_into, recv_into to avoid the pointless
redirection.
I don't have LaTeX on this machine; hope my markup is OK.
........
r53067 | andrew.kuchling | 2006-12-19 15:29:04 +0100 (Tue, 19 Dec 2006) | 1 line
Comment typo
........
r53068 | andrew.kuchling | 2006-12-19 16:11:41 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1617413 from Dug Song] Fix HTTP Basic authentication via HTTPS
........
r53071 | andrew.kuchling | 2006-12-19 16:18:12 +0100 (Tue, 19 Dec 2006) | 1 line
[Patch #1600491 from Jim Jewett] Describe how to build help files on Windows
........
r53073 | andrew.kuchling | 2006-12-19 16:43:10 +0100 (Tue, 19 Dec 2006) | 6 lines
[Patch #1587139 by kxroberto] Protect lock acquisition/release with
try...finally to ensure the lock is always released. This could use
the 'with' statement, but the patch uses 'finally'.
2.5 backport candidate.
........
r53074 | vinay.sajip | 2006-12-19 19:29:11 +0100 (Tue, 19 Dec 2006) | 1 line
Updated documentation for findCaller() to indicate that a 3-tuple is now returned, rather than a 2-tuple.
........
r53090 | georg.brandl | 2006-12-19 23:06:46 +0100 (Tue, 19 Dec 2006) | 3 lines
Patch #1484695: The tarfile module now raises a HeaderError exception
if a buffer given to frombuf() is invalid.
........
r53099 | raymond.hettinger | 2006-12-20 07:42:06 +0100 (Wed, 20 Dec 2006) | 5 lines
Bug #1590891: random.randrange don't return correct value for big number
Needs to be backported.
........
r53106 | georg.brandl | 2006-12-20 12:55:16 +0100 (Wed, 20 Dec 2006) | 3 lines
Testcase for patch #1484695.
........
r53110 | andrew.kuchling | 2006-12-20 20:48:20 +0100 (Wed, 20 Dec 2006) | 17 lines
[Apply length-checking.diff from bug #1599254]
Add length checking to single-file mailbox formats: before doing a
flush() on a mailbox, seek to the end and verify its length is
unchanged, raising ExternalClashError if the file's length has
changed.
This fix avoids potential data loss if some other process appends to
the mailbox file after the table of contents has been generated;
instead of overwriting the modified file, you'll get the exception.
I also noticed that the self._lookup() call in self.flush() wasn't
necessary (everything that sets self._pending to True also calls
self.lookup()), and replaced it by an assertion.
2.5 backport candidate.
........
r53112 | andrew.kuchling | 2006-12-20 20:57:10 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619674] Make sum() use the term iterable, not sequence
........
r53113 | andrew.kuchling | 2006-12-20 20:58:11 +0100 (Wed, 20 Dec 2006) | 1 line
Two grammar fixes
........
r53115 | andrew.kuchling | 2006-12-20 21:11:12 +0100 (Wed, 20 Dec 2006) | 5 lines
Some other built-in functions are described with 'sequence' arguments
that should really be 'iterable'; this commit changes them.
Did I miss any? Did I introduce any errors?
........
r53117 | andrew.kuchling | 2006-12-20 21:20:42 +0100 (Wed, 20 Dec 2006) | 1 line
[Bug #1619680] in_dll() arguments are documented in the wrong order
........
r53120 | neal.norwitz | 2006-12-21 05:38:00 +0100 (Thu, 21 Dec 2006) | 1 line
Lars asked for permission on on python-dev for work on tarfile.py
........
r53125 | andrew.kuchling | 2006-12-21 14:40:29 +0100 (Thu, 21 Dec 2006) | 1 line
Mention the os.SEEK_* constants
........
r53129 | walter.doerwald | 2006-12-21 19:06:30 +0100 (Thu, 21 Dec 2006) | 2 lines
Fix typo.
........
r53131 | thomas.heller | 2006-12-21 19:30:56 +0100 (Thu, 21 Dec 2006) | 3 lines
Fix wrong markup of an argument in a method signature.
Will backport.
........
r53137 | andrew.kuchling | 2006-12-22 01:50:56 +0100 (Fri, 22 Dec 2006) | 1 line
Typo fix
........
r53139 | andrew.kuchling | 2006-12-22 14:25:02 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #737202; fix from Titus Brown] Make CGIHTTPServer work for scripts in sub-directories
........
r53141 | andrew.kuchling | 2006-12-22 16:04:45 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128] Make the mode argument of dumbdbm actually work the way it's
described, and add a test for it.
2.5 bugfix candidate, maybe; arguably this patch changes the API of
dumbdbm and shouldn't be added in a point-release.
........
r53142 | andrew.kuchling | 2006-12-22 16:16:58 +0100 (Fri, 22 Dec 2006) | 6 lines
[Bug #802128 continued] Modify mode depending on the process umask.
Is there really no other way to read the umask than to set it?
Hope this works on Windows...
........
r53145 | andrew.kuchling | 2006-12-22 17:43:26 +0100 (Fri, 22 Dec 2006) | 1 line
[Bug #776202] Apply Walter Doerwald's patch to use text mode for encoded files
........
r53146 | andrew.kuchling | 2006-12-22 19:41:42 +0100 (Fri, 22 Dec 2006) | 9 lines
[Patch #783050 from Patrick Lynch] The emulation of forkpty() is incorrect;
the master should close the slave fd.
Added a test to test_pty.py that reads from the master_fd after doing
a pty.fork(); without the fix it hangs forever instead of raising an
exception. (<crossing fingers for the buildbots>)
2.5 backport candidate.
........
r53147 | andrew.kuchling | 2006-12-22 20:06:16 +0100 (Fri, 22 Dec 2006) | 1 line
[Patch #827559 from Chris Gonnerman] Make SimpleHTTPServer redirect when a directory URL is missing the trailing slash; this lets relative links work.
........
r53149 | andrew.kuchling | 2006-12-22 20:21:27 +0100 (Fri, 22 Dec 2006) | 1 line
Darn; this test works when you run test_pty.py directly, but fails when regrtest runs it (the os.read() raises os.error). I can't figure out the cause, so am commenting out the test.
........
r53150 | andrew.kuchling | 2006-12-22 22:48:19 +0100 (Fri, 22 Dec 2006) | 1 line
Frak; this test also fails
........
r53153 | lars.gustaebel | 2006-12-23 17:40:13 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1230446: tarfile.py: fix ExFileObject so that read() and tell()
work correctly together with readline().
Will backport to 2.5.
........
r53155 | lars.gustaebel | 2006-12-23 18:57:23 +0100 (Sat, 23 Dec 2006) | 5 lines
Patch #1262036: Prevent TarFiles from being added to themselves under
certain conditions.
Will backport to 2.5.
........
r53159 | andrew.kuchling | 2006-12-27 04:25:31 +0100 (Wed, 27 Dec 2006) | 4 lines
[Part of patch #1182394] Move the HMAC blocksize to be a class-level
constant; this allows changing it in a subclass. To accommodate this,
copy() now uses __class__. Also add some text to a comment.
........
r53160 | andrew.kuchling | 2006-12-27 04:31:24 +0100 (Wed, 27 Dec 2006) | 1 line
[Rest of patch #1182394] Add ._current() method so that we can use the written-in-C .hexdigest() method
........
r53161 | lars.gustaebel | 2006-12-27 11:30:46 +0100 (Wed, 27 Dec 2006) | 4 lines
Patch #1504073: Fix tarfile.open() for mode "r" with a fileobj argument.
Will backport to 2.5.
........
r53165 | neal.norwitz | 2006-12-28 05:39:20 +0100 (Thu, 28 Dec 2006) | 1 line
Remove a stray (old) macro name left around (I guess)
........
r53188 | neal.norwitz | 2006-12-29 04:01:53 +0100 (Fri, 29 Dec 2006) | 1 line
SF bug #1623890, fix argument name in docstring
........
r53200 | raymond.hettinger | 2006-12-30 05:01:17 +0100 (Sat, 30 Dec 2006) | 1 line
For sets with cyclical reprs, emit an ellipsis instead of infinitely recursing.
........
r53232 | brett.cannon | 2007-01-04 01:23:49 +0100 (Thu, 04 Jan 2007) | 3 lines
Add EnvironmentVarGuard to test.test_support. Provides a context manager to
temporarily set or unset environment variables.
........
r53235 | neal.norwitz | 2007-01-04 07:25:31 +0100 (Thu, 04 Jan 2007) | 1 line
SF #1627373, fix typo in CarbonEvt.
........
r53244 | raymond.hettinger | 2007-01-04 18:53:34 +0100 (Thu, 04 Jan 2007) | 1 line
Fix stability of heapq's nlargest() and nsmallest().
........
r53249 | martin.v.loewis | 2007-01-04 22:06:12 +0100 (Thu, 04 Jan 2007) | 3 lines
Bug #1566280: Explicitly invoke threading._shutdown from Py_Main,
to avoid relying on atexit.
Will backport to 2.5.
........
r53252 | gregory.p.smith | 2007-01-05 02:59:42 +0100 (Fri, 05 Jan 2007) | 3 lines
Support linking of the bsddb module against BerkeleyDB 4.5.x
(will backport to 2.5)
........
r53253 | gregory.p.smith | 2007-01-05 03:06:17 +0100 (Fri, 05 Jan 2007) | 2 lines
bump module version to match supported berkeleydb version
........
r53255 | neal.norwitz | 2007-01-05 06:25:22 +0100 (Fri, 05 Jan 2007) | 6 lines
Prevent crash on shutdown which can occur if we are finalizing
and the module dict has been cleared already and some object
raises a warning (like in a __del__).
Will backport.
........
r53258 | gregory.p.smith | 2007-01-05 08:21:35 +0100 (Fri, 05 Jan 2007) | 2 lines
typo fix
........
r53260 | neal.norwitz | 2007-01-05 09:06:43 +0100 (Fri, 05 Jan 2007) | 1 line
Add Collin Winter for access to update PEP 3107
........
r53262 | andrew.kuchling | 2007-01-05 15:22:17 +0100 (Fri, 05 Jan 2007) | 1 line
[Bug #1622533] Make docstrings raw strings because they contain control characters (\0, \1)
........
r53264 | andrew.kuchling | 2007-01-05 16:51:24 +0100 (Fri, 05 Jan 2007) | 1 line
[Patch #1520904] Fix bsddb tests to write to the temp directory instead of the Lib/bsddb/test directory
........
r53279 | brett.cannon | 2007-01-05 22:45:09 +0100 (Fri, 05 Jan 2007) | 3 lines
Silence a warning from gcc 4.0.1 by specifying a function's parameter list is
'void' instead of just a set of empty parentheses.
........
r53285 | raymond.hettinger | 2007-01-06 02:14:41 +0100 (Sat, 06 Jan 2007) | 2 lines
SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros.
........
r53286 | anthony.baxter | 2007-01-06 05:45:54 +0100 (Sat, 06 Jan 2007) | 1 line
update to (c) years to include 2007
........
r53291 | neal.norwitz | 2007-01-06 22:24:35 +0100 (Sat, 06 Jan 2007) | 1 line
Add Josiah to SF for maintaining asyncore/asynchat
........
r53293 | peter.astrand | 2007-01-07 09:53:46 +0100 (Sun, 07 Jan 2007) | 1 line
Re-implemented fix for #1531862 once again, in a way that works with Python 2.2. Fixes bug #1603424.
........
r53295 | peter.astrand | 2007-01-07 15:34:16 +0100 (Sun, 07 Jan 2007) | 1 line
Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181.
........
r53300 | raymond.hettinger | 2007-01-08 19:09:20 +0100 (Mon, 08 Jan 2007) | 1 line
Fix zero-length corner case for iterating over a mutating deque.
........
r53301 | vinay.sajip | 2007-01-08 19:50:32 +0100 (Mon, 08 Jan 2007) | 4 lines
Bare except clause removed from SMTPHandler.emit(). Now, only ImportError is trapped.
Bare except clause removed from SocketHandler.createSocket(). Now, only socket.error is trapped.
(SF #411881)
........
r53302 | vinay.sajip | 2007-01-08 19:51:46 +0100 (Mon, 08 Jan 2007) | 2 lines
Bare except clause removed from LogRecord.__init__. Now, only ValueError, TypeError and AttributeError are trapped.
(SF #411881)
........
r53303 | vinay.sajip | 2007-01-08 19:52:36 +0100 (Mon, 08 Jan 2007) | 1 line
Added entries about removal of some bare except clauses from logging.
........
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 73ef2d4..b517daa 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -1,5 +1,4 @@
import unittest
-import warnings
import sys
from test import test_support
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 4c5d1ee..56031a7 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -396,6 +396,12 @@
d.pop()
self.assertRaises(RuntimeError, it.next)
+ def test_runtime_error_on_empty_deque(self):
+ d = deque()
+ it = iter(d)
+ d.append(10)
+ self.assertRaises(RuntimeError, it.next)
+
class Deque(deque):
pass
diff --git a/Lib/test/test_dumbdbm.py b/Lib/test/test_dumbdbm.py
index 63b14b0..e5dfe1d 100644
--- a/Lib/test/test_dumbdbm.py
+++ b/Lib/test/test_dumbdbm.py
@@ -38,6 +38,24 @@
self.read_helper(f)
f.close()
+ def test_dumbdbm_creation_mode(self):
+ # On platforms without chmod, don't do anything.
+ if not (hasattr(os, 'chmod') and hasattr(os, 'umask')):
+ return
+
+ try:
+ old_umask = os.umask(0002)
+ f = dumbdbm.open(_fname, 'c', 0637)
+ f.close()
+ finally:
+ os.umask(old_umask)
+
+ import stat
+ st = os.stat(_fname + '.dat')
+ self.assertEqual(stat.S_IMODE(st.st_mode), 0635)
+ st = os.stat(_fname + '.dir')
+ self.assertEqual(stat.S_IMODE(st.st_mode), 0635)
+
def test_close_twice(self):
f = dumbdbm.open(_fname)
f['a'] = 'b'
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index abce41e..7619aae 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -3,7 +3,6 @@
import os
import sys
import unittest
-import warnings
import pickle
try:
import cPickle
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index 1916449..b652d41 100644
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -104,20 +104,20 @@
self.assertEqual(heap_sorted, sorted(data))
def test_nsmallest(self):
- data = [random.randrange(2000) for i in range(1000)]
- f = lambda x: x * 547 % 2000
- for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
- self.assertEqual(nsmallest(n, data), sorted(data)[:n])
- self.assertEqual(nsmallest(n, data, key=f),
- sorted(data, key=f)[:n])
+ data = [(random.randrange(2000), i) for i in range(1000)]
+ for f in (None, lambda x: x[0] * 547 % 2000):
+ for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
+ self.assertEqual(nsmallest(n, data), sorted(data)[:n])
+ self.assertEqual(nsmallest(n, data, key=f),
+ sorted(data, key=f)[:n])
def test_nlargest(self):
- data = [random.randrange(2000) for i in range(1000)]
- f = lambda x: x * 547 % 2000
- for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
- self.assertEqual(nlargest(n, data), sorted(data, reverse=True)[:n])
- self.assertEqual(nlargest(n, data, key=f),
- sorted(data, key=f, reverse=True)[:n])
+ data = [(random.randrange(2000), i) for i in range(1000)]
+ for f in (None, lambda x: x[0] * 547 % 2000):
+ for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
+ self.assertEqual(nlargest(n, data), sorted(data, reverse=True)[:n])
+ self.assertEqual(nlargest(n, data, key=f),
+ sorted(data, key=f, reverse=True)[:n])
#==============================================================================
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index e37378f..58de944 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -1,10 +1,11 @@
-from test.test_support import TESTFN, run_unittest
+from test.test_support import TESTFN, run_unittest, guard_warnings_filter
import unittest
import os
import random
import sys
import py_compile
+import warnings
def remove_files(name):
@@ -204,15 +205,11 @@
self.assert_(y is test.test_support, y.__name__)
def test_import_initless_directory_warning(self):
- import warnings
- oldfilters = warnings.filters[:]
- warnings.simplefilter('error', ImportWarning);
- try:
+ with guard_warnings_filter():
# Just a random non-package directory we always expect to be
# somewhere in sys.path...
+ warnings.simplefilter('error', ImportWarning)
self.assertRaises(ImportWarning, __import__, "site-packages")
- finally:
- warnings.filters = oldfilters
def test_main(verbose=None):
run_unittest(ImportTest)
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index 59e5162..8a83e39 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -115,6 +115,12 @@
os._exit(4)
else:
debug("Waiting for child (%d) to finish."%pid)
+ ##line = os.read(master_fd, 80)
+ ##lines = line.replace('\r\n', '\n').split('\n')
+ ##if False and lines != ['In child, calling os.setsid()',
+ ## 'Good: OSError was raised.', '']:
+ ## raise TestFailed("Unexpected output from child: %r" % line)
+
(pid, status) = os.waitpid(pid, 0)
res = status >> 8
debug("Child (%d) exited with status %d (%d)."%(pid, res, status))
@@ -127,6 +133,15 @@
elif res != 4:
raise TestFailed, "pty.fork() failed for unknown reasons."
+ ##debug("Reading from master_fd now that the child has exited")
+ ##try:
+ ## s1 = os.read(master_fd, 1024)
+ ##except os.error:
+ ## pass
+ ##else:
+ ## raise TestFailed("Read from master_fd did not raise exception")
+
+
os.close(master_fd)
# pty.fork() passed.
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index afcf113..7ec130d 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -180,10 +180,9 @@
def test_bigrand(self):
# Verify warnings are raised when randrange is too large for random()
- oldfilters = warnings.filters[:]
- warnings.filterwarnings("error", "Underlying random")
- self.assertRaises(UserWarning, self.gen.randrange, 2**60)
- warnings.filters[:] = oldfilters
+ with test_support.guard_warnings_filter():
+ warnings.filterwarnings("error", "Underlying random")
+ self.assertRaises(UserWarning, self.gen.randrange, 2**60)
class SystemRandom_TestBasicOps(TestBasicOps):
gen = random.SystemRandom()
@@ -441,6 +440,14 @@
self.assertEqual(k, numbits) # note the stronger assertion
self.assert_(2**k > n > 2**(k-1)) # note the stronger assertion
+ def test_randrange_bug_1590891(self):
+ start = 1000000000000
+ stop = -100000000000000000000
+ step = -200
+ x = self.gen.randrange(start, stop, step)
+ self.assert_(stop < x <= start)
+ self.assertEqual((x+stop)%step, 0)
+
_gammacoeff = (0.9999999999995183, 676.5203681218835, -1259.139216722289,
771.3234287757674, -176.6150291498386, 12.50734324009056,
-0.1385710331296526, 0.9934937113930748e-05, 0.1659470187408462e-06)
diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py
index 1dfa282..823298b 100644
--- a/Lib/test/test_repr.py
+++ b/Lib/test/test_repr.py
@@ -136,7 +136,6 @@
'<built-in method split of str object at 0x'))
def test_xrange(self):
- import warnings
eq = self.assertEquals
eq(repr(xrange(1)), 'xrange(1)')
eq(repr(xrange(1, 2)), 'xrange(1, 2)')
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index a4830d4..6641ff8 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -21,6 +21,11 @@
def __eq__(self, other):
raise RuntimeError
+class ReprWrapper:
+ 'Used to test self-referential repr() calls'
+ def __repr__(self):
+ return repr(self.value)
+
class TestJointOps(unittest.TestCase):
# Tests common to both set and frozenset
@@ -244,6 +249,30 @@
self.assertRaises(RuntimeError, s.discard, BadCmp())
self.assertRaises(RuntimeError, s.remove, BadCmp())
+ def test_cyclical_repr(self):
+ w = ReprWrapper()
+ s = self.thetype([w])
+ w.value = s
+ if self.thetype == set:
+ self.assertEqual(repr(s), '{set(...)}')
+ else:
+ name = repr(s).partition('(')[0] # strip class name
+ self.assertEqual(repr(s), '%s([%s(...)])' % (name, name))
+
+ def test_cyclical_print(self):
+ w = ReprWrapper()
+ s = self.thetype([w])
+ w.value = s
+ try:
+ fo = open(test_support.TESTFN, "wb")
+ print >> fo, s,
+ fo.close()
+ fo = open(test_support.TESTFN, "rb")
+ self.assertEqual(fo.read(), repr(s))
+ finally:
+ fo.close()
+ os.remove(test_support.TESTFN)
+
class TestSet(TestJointOps):
thetype = set
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 302698b..d4744dd 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -50,22 +50,17 @@
def with_warning_restore(func):
def _with_warning_restore(*args, **kw):
- # The `warnings` module doesn't have an advertised way to restore
- # its filter list. Cheat.
- save_warnings_filters = warnings.filters[:]
- # Grrr, we need this function to warn every time. Without removing
- # the warningregistry, running test_tarfile then test_struct would fail
- # on 64-bit platforms.
- globals = func.func_globals
- if '__warningregistry__' in globals:
- del globals['__warningregistry__']
- warnings.filterwarnings("error", r"""^struct.*""", DeprecationWarning)
- warnings.filterwarnings("error", r""".*format requires.*""",
- DeprecationWarning)
- try:
+ with test.test_support.guard_warnings_filter():
+ # Grrr, we need this function to warn every time. Without removing
+ # the warningregistry, running test_tarfile then test_struct would fail
+ # on 64-bit platforms.
+ globals = func.func_globals
+ if '__warningregistry__' in globals:
+ del globals['__warningregistry__']
+ warnings.filterwarnings("error", r"""^struct.*""", DeprecationWarning)
+ warnings.filterwarnings("error", r""".*format requires.*""",
+ DeprecationWarning)
return func(*args, **kw)
- finally:
- warnings.filters[:] = save_warnings_filters[:]
return _with_warning_restore
def deprecated_err(func, *args):
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 2829c55..2c19698 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -3,7 +3,9 @@
if __name__ != 'test.test_support':
raise ImportError, 'test_support must be imported from the test package'
+from contextlib import contextmanager
import sys
+import warnings
class Error(Exception):
"""Base class for regression test exceptions."""
@@ -267,6 +269,48 @@
print >> get_original_stdout(), '\tfetching %s ...' % url
fn, _ = urllib.urlretrieve(url, filename)
return open(fn)
+
+@contextmanager
+def guard_warnings_filter():
+ """Guard the warnings filter from being permanently changed."""
+ original_filters = warnings.filters[:]
+ try:
+ yield
+ finally:
+ warnings.filters = original_filters
+
+class EnvironmentVarGuard(object):
+
+ """Class to help protect the environment variable properly. Can be used as
+ a context manager."""
+
+ def __init__(self):
+ from os import environ
+ self._environ = environ
+ self._unset = set()
+ self._reset = dict()
+
+ def set(self, envvar, value):
+ if envvar not in self._environ:
+ self._unset.add(envvar)
+ else:
+ self._reset[envvar] = self._environ[envvar]
+ self._environ[envvar] = value
+
+ def unset(self, envvar):
+ if envvar in self._environ:
+ self._reset[envvar] = self._environ[envvar]
+ del self._environ[envvar]
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *ignore_exc):
+ for envvar, value in self._reset.iteritems():
+ self._environ[envvar] = value
+ for unset in self._unset:
+ del self._environ[unset]
+
#=======================================================================
# Decorator for running a function in a different locale, correctly resetting
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 0cebb29..2b39715 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -110,7 +110,7 @@
"""Test seek() method of _FileObject, incl. random reading.
"""
if self.sep != "|":
- filename = "0-REGTYPE"
+ filename = "0-REGTYPE-TEXT"
self.tar.extract(filename, dirname())
f = open(os.path.join(dirname(), filename), "rb")
data = f.read()
@@ -149,6 +149,16 @@
s2 = fobj.readlines()
self.assert_(s1 == s2,
"readlines() after seek failed")
+ fobj.seek(0)
+ self.assert_(len(fobj.readline()) == fobj.tell(),
+ "tell() after readline() failed")
+ fobj.seek(512)
+ self.assert_(len(fobj.readline()) + 512 == fobj.tell(),
+ "tell() after seek() and readline() failed")
+ fobj.seek(0)
+ line = fobj.readline()
+ self.assert_(fobj.read() == data[len(line):],
+ "read() after readline() failed")
fobj.close()
def test_old_dirtype(self):
@@ -280,6 +290,20 @@
else:
self.dst.addfile(tarinfo, f)
+ def test_add_self(self):
+ dstname = os.path.abspath(self.dstname)
+
+ self.assertEqual(self.dst.name, dstname, "archive name must be absolute")
+
+ self.dst.add(dstname)
+ self.assertEqual(self.dst.getnames(), [], "added the archive to itself")
+
+ cwd = os.getcwd()
+ os.chdir(dirname())
+ self.dst.add(dstname)
+ os.chdir(cwd)
+ self.assertEqual(self.dst.getnames(), [], "added the archive to itself")
+
class Write100Test(BaseTest):
# The name field in a tar header stores strings of at most 100 chars.
@@ -601,6 +625,38 @@
self.assertEqual(tarfile.filemode(0755), '-rwxr-xr-x')
self.assertEqual(tarfile.filemode(07111), '---s--s--t')
+class HeaderErrorTest(unittest.TestCase):
+
+ def test_truncated_header(self):
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "")
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "filename\0")
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "\0" * 511)
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "\0" * 513)
+
+ def test_empty_header(self):
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "\0" * 512)
+
+ def test_invalid_header(self):
+ buf = tarfile.TarInfo("filename").tobuf()
+ buf = buf[:148] + "foo\0\0\0\0\0" + buf[156:] # invalid number field.
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, buf)
+
+ def test_bad_checksum(self):
+ buf = tarfile.TarInfo("filename").tobuf()
+ b = buf[:148] + " " + buf[156:] # clear the checksum field.
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, b)
+ b = "a" + buf[1:] # manipulate the buffer, so checksum won't match.
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, b)
+
+class OpenFileobjTest(BaseTest):
+ # Test for SF bug #1496501.
+
+ def test_opener(self):
+ fobj = StringIO.StringIO("foo\n")
+ try:
+ tarfile.open("", "r", fileobj=fobj)
+ except tarfile.ReadError:
+ self.assertEqual(fobj.tell(), 0, "fileobj's position has moved")
if bz2:
# Bzip2 TestCases
@@ -646,6 +702,8 @@
tests = [
FileModeTest,
+ HeaderErrorTest,
+ OpenFileobjTest,
ReadTest,
ReadStreamTest,
ReadDetectTest,
diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py
index 7786316..16a55e4 100644
--- a/Lib/test/test_uu.py
+++ b/Lib/test/test_uu.py
@@ -114,11 +114,11 @@
def test_encode(self):
try:
- fin = open(self.tmpin, 'wb')
+ fin = open(self.tmpin, 'w')
fin.write(plaintext)
fin.close()
- fin = open(self.tmpin, 'rb')
+ fin = open(self.tmpin, 'r')
fout = open(self.tmpout, 'w')
uu.encode(fin, fout, self.tmpin, mode=0644)
fin.close()
@@ -130,7 +130,7 @@
self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin))
# in_file and out_file as filenames
- uu.encode(self.tmpin, self.tmpout, mode=0644)
+ uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0644)
fout = open(self.tmpout, 'r')
s = fout.read()
fout.close()
@@ -142,11 +142,11 @@
def test_decode(self):
try:
- f = open(self.tmpin, 'wb')
+ f = open(self.tmpin, 'w')
f.write(encodedtextwrapped % (0644, self.tmpout))
f.close()
- f = open(self.tmpin, 'rb')
+ f = open(self.tmpin, 'r')
uu.decode(f)
f.close()
@@ -163,11 +163,11 @@
try:
f = cStringIO.StringIO(encodedtextwrapped % (0644, self.tmpout))
- f = open(self.tmpin, 'rb')
+ f = open(self.tmpin, 'r')
uu.decode(f)
f.close()
- f = open(self.tmpin, 'rb')
+ f = open(self.tmpin, 'r')
self.assertRaises(uu.Error, uu.decode, f)
f.close()
finally:
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 1165980..06f4537 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -189,7 +189,7 @@
# None as the value for the callback, where either means "no
# callback". The "no callback" ref and proxy objects are supposed
# to be shared so long as they exist by all callers so long as
- # they are active. In Python 2.3.3 and earlier, this guaranttee
+ # they are active. In Python 2.3.3 and earlier, this guarantee
# was not honored, and was broken in different ways for
# PyWeakref_NewRef() and PyWeakref_NewProxy(). (Two tests.)