summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-06-01 22:42:33 +0000
committerBenjamin Peterson <benjamin@python.org>2009-06-01 22:42:33 +0000
commitfa0d7034339fee79cf5f095ee48488ea13a3fc4b (patch)
tree4f5f97efccb004fbfcd0d4ec8536638c55005d50 /Lib
parentf11be757603ba63887618ac67c9f3025e82e40f1 (diff)
downloadcpython-git-fa0d7034339fee79cf5f095ee48488ea13a3fc4b.tar.gz
Merged revisions 72506,72525-72526,72551,72558,72616,72654-72655,72689,72745,72750,72802,72812,72822,72824,72826-72827,72833,72876,72890,72923,72946,73026,73042,73045,73047,73065,73068-73069 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72506 | vinay.sajip | 2009-05-09 07:07:17 -0500 (Sat, 09 May 2009) | 1 line Issue #5971: StreamHandler.handleError now swallows IOErrors which occur when trying to print a traceback. ........ r72525 | benjamin.peterson | 2009-05-09 20:38:02 -0500 (Sat, 09 May 2009) | 1 line close file explicitly ........ r72526 | benjamin.peterson | 2009-05-09 21:29:00 -0500 (Sat, 09 May 2009) | 1 line make sure files are closed using the with statement ........ r72551 | benjamin.peterson | 2009-05-10 09:16:47 -0500 (Sun, 10 May 2009) | 1 line use isinstance ........ r72558 | benjamin.peterson | 2009-05-10 18:52:09 -0500 (Sun, 10 May 2009) | 1 line sys.setdefaultencoding() strikes me as a bad example ........ r72616 | benjamin.peterson | 2009-05-13 19:33:10 -0500 (Wed, 13 May 2009) | 1 line importlib.import_module is better these days ........ r72654 | benjamin.peterson | 2009-05-14 17:37:49 -0500 (Thu, 14 May 2009) | 1 line prevent refleaks from threads ........ r72655 | benjamin.peterson | 2009-05-14 17:40:34 -0500 (Thu, 14 May 2009) | 1 line a useful decorator for cleaning up threads ........ r72689 | benjamin.peterson | 2009-05-16 13:44:34 -0500 (Sat, 16 May 2009) | 1 line use skipTest() ........ r72745 | benjamin.peterson | 2009-05-17 09:16:29 -0500 (Sun, 17 May 2009) | 1 line ignore .rst files in sphinx its self ........ r72750 | benjamin.peterson | 2009-05-17 11:59:27 -0500 (Sun, 17 May 2009) | 1 line chop off slash ........ r72802 | georg.brandl | 2009-05-20 13:35:27 -0500 (Wed, 20 May 2009) | 1 line #6051: refer to email examples for better way to construct email messages. ........ r72812 | michael.foord | 2009-05-21 17:57:02 -0500 (Thu, 21 May 2009) | 1 line Rename TestCase._result to _resultForDoCleanups to avoid potential clashes in TestCase subclasses. Issue 6072. ........ r72822 | georg.brandl | 2009-05-22 04:33:25 -0500 (Fri, 22 May 2009) | 1 line #6084: fix example. ........ r72824 | georg.brandl | 2009-05-22 04:43:17 -0500 (Fri, 22 May 2009) | 1 line Fix references to file-related functions and methods (os.* vs file.*). ........ r72826 | georg.brandl | 2009-05-22 04:49:42 -0500 (Fri, 22 May 2009) | 1 line Fix confusing wording. ........ r72827 | georg.brandl | 2009-05-22 04:50:30 -0500 (Fri, 22 May 2009) | 1 line s/use/call/ ........ r72833 | georg.brandl | 2009-05-22 12:00:17 -0500 (Fri, 22 May 2009) | 1 line #6078: _warnings is a builtin module and has no standard init_warnings function. ........ r72876 | benjamin.peterson | 2009-05-23 15:59:09 -0500 (Sat, 23 May 2009) | 1 line remove mention of old ctypes version ........ r72890 | gregory.p.smith | 2009-05-24 13:00:13 -0500 (Sun, 24 May 2009) | 2 lines add a versionadded tag for set_tunnel ........ r72923 | michael.foord | 2009-05-25 15:36:56 -0500 (Mon, 25 May 2009) | 1 line Make assertSequenceEqual error messages less cryptic, particularly for nested sequences. ........ r72946 | ronald.oussoren | 2009-05-26 13:44:48 -0500 (Tue, 26 May 2009) | 2 lines Fixes issue 6110 ........ r73026 | r.david.murray | 2009-05-29 14:30:27 -0500 (Fri, 29 May 2009) | 3 lines Issue 6141: document that the first item of args is still the command name even when executable is specified. ........ r73042 | benjamin.peterson | 2009-05-29 22:10:52 -0500 (Fri, 29 May 2009) | 1 line no fdatasync on macos ........ r73045 | georg.brandl | 2009-05-30 02:26:04 -0500 (Sat, 30 May 2009) | 1 line #6146: fix markup bug. ........ r73047 | georg.brandl | 2009-05-30 05:33:23 -0500 (Sat, 30 May 2009) | 1 line Fix some more small markup problems. ........ r73065 | antoine.pitrou | 2009-05-30 16:39:25 -0500 (Sat, 30 May 2009) | 3 lines The test for #5330 wasn't correct. ........ r73068 | antoine.pitrou | 2009-05-30 16:45:40 -0500 (Sat, 30 May 2009) | 3 lines Update ACKS ........ r73069 | benjamin.peterson | 2009-05-30 19:42:42 -0500 (Sat, 30 May 2009) | 1 line fix signature ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/gettext.py4
-rw-r--r--Lib/idlelib/macosxSupport.py1
-rw-r--r--Lib/logging/__init__.py8
-rw-r--r--Lib/test/support.py11
-rw-r--r--Lib/test/test_hashlib.py3
-rw-r--r--Lib/test/test_os.py4
-rw-r--r--Lib/test/test_unittest.py2
-rw-r--r--Lib/unittest.py63
-rw-r--r--Lib/zipfile.py48
9 files changed, 81 insertions, 63 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py
index d62ac07516..4c957c0c6a 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -415,7 +415,6 @@ def translation(domain, localedir=None, languages=None,
if fallback:
return NullTranslations()
raise IOError(ENOENT, 'No translation file found for domain', domain)
- # TBD: do we need to worry about the file pointer getting collected?
# Avoid opening, reading, and parsing the .mo file after it's been done
# once.
result = None
@@ -423,7 +422,8 @@ def translation(domain, localedir=None, languages=None,
key = os.path.abspath(mofile)
t = _translations.get(key)
if t is None:
- t = _translations.setdefault(key, class_(open(mofile, 'rb')))
+ with open(mofile, 'rb') as fp:
+ t = _translations.setdefault(key, class_(fp))
# Copy the translation object to allow setting fallbacks and
# output charset. All other instance data is shared with the
# cached object.
diff --git a/Lib/idlelib/macosxSupport.py b/Lib/idlelib/macosxSupport.py
index b23221e759..b794a83bd5 100644
--- a/Lib/idlelib/macosxSupport.py
+++ b/Lib/idlelib/macosxSupport.py
@@ -88,6 +88,7 @@ def overrideRootMenu(root, flist):
# on an EditorWindow instance that is then passed as the first
# argument to ConfigDialog)
root.instance_dict = flist.inversedict
+ root.instance_dict = flist.inversedict
configDialog.ConfigDialog(root, 'Settings')
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 517a7a94f0..9780c830ae 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -720,8 +720,12 @@ class Handler(Filterer):
"""
if raiseExceptions:
ei = sys.exc_info()
- traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
- del ei
+ try:
+ traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
+ except IOError:
+ pass # see issue 5971
+ finally:
+ del ei
class StreamHandler(Handler):
"""
diff --git a/Lib/test/support.py b/Lib/test/support.py
index df114a2188..b91d7328d4 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -5,6 +5,7 @@ if __name__ != 'test.support':
import contextlib
import errno
+import functools
import socket
import sys
import os
@@ -933,6 +934,16 @@ def threading_cleanup(num_active, num_limbo):
count += 1
time.sleep(0.1)
+def reap_threads(func):
+ @functools.wraps(func)
+ def decorator(*args):
+ key = threading_setup()
+ try:
+ return func(*args)
+ finally:
+ threading_cleanup(*key)
+ return decorator
+
def reap_children():
"""Use this function at the end of test_main() whenever sub-processes
are started. This will help ensure that no extra children (zombies)
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index 594f5dd885..5bfea6b9d2 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -267,10 +267,9 @@ class HashLibTestCase(unittest.TestCase):
self.assertEqual(expected_hash, hasher.hexdigest())
-
+@support.reap_threads
def test_main():
support.run_unittest(HashLibTestCase)
-
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index c680d8d77a..0600cfc0ee 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -35,9 +35,7 @@ class FileTests(unittest.TestCase):
retries += 1
if retries > 10:
# XXX test skipped
- print("couldn't allocate two consecutive fds, "
- "skipping test_closerange", file=sys.stderr)
- return
+ self.skipTest("couldn't allocate two consecutive fds")
first, second = second, os.dup(second)
finally:
os.close(second)
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index ea331808b3..858f24b7d4 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -3175,7 +3175,7 @@ class TestCleanUp(TestCase):
result = MockResult()
test = TestableTest('testNothing')
- test._result = result
+ test._resultForDoCleanups = result
exc1 = Exception('foo')
exc2 = Exception('bar')
diff --git a/Lib/unittest.py b/Lib/unittest.py
index cdccd8c3cc..9c3024af69 100644
--- a/Lib/unittest.py
+++ b/Lib/unittest.py
@@ -353,7 +353,7 @@ class TestCase(object):
not have a method with the specified name.
"""
self._testMethodName = methodName
- self._result = None
+ self._resultForDoCleanups = None
try:
testMethod = getattr(self, methodName)
except AttributeError:
@@ -457,7 +457,7 @@ class TestCase(object):
if startTestRun is not None:
startTestRun()
- self._result = result
+ self._resultForDoCleanups = result
result.startTest(self)
if getattr(self.__class__, "__unittest_skip__", False):
# If the whole class was skipped.
@@ -511,7 +511,7 @@ class TestCase(object):
def doCleanups(self):
"""Execute all cleanup functions. Normally called for you after
tearDown."""
- result = self._result
+ result = self._resultForDoCleanups
ok = True
while self._cleanups:
function, args, kwargs = self._cleanups.pop(-1)
@@ -732,23 +732,32 @@ class TestCase(object):
if seq1 == seq2:
return
+ seq1_repr = repr(seq1)
+ seq2_repr = repr(seq2)
+ if len(seq1_repr) > 30:
+ seq1_repr = seq1_repr[:30] + '...'
+ if len(seq2_repr) > 30:
+ seq2_repr = seq2_repr[:30] + '...'
+ elements = (seq_type_name.capitalize(), seq1_repr, seq2_repr)
+ differing = '%ss differ: %s != %s\n' % elements
+
for i in range(min(len1, len2)):
try:
item1 = seq1[i]
except (TypeError, IndexError, NotImplementedError):
- differing = ('Unable to index element %d of first %s\n' %
+ differing += ('\nUnable to index element %d of first %s\n' %
(i, seq_type_name))
break
try:
item2 = seq2[i]
except (TypeError, IndexError, NotImplementedError):
- differing = ('Unable to index element %d of second %s\n' %
+ differing += ('\nUnable to index element %d of second %s\n' %
(i, seq_type_name))
break
if item1 != item2:
- differing = ('First differing element %d:\n%s\n%s\n' %
+ differing += ('\nFirst differing element %d:\n%s\n%s\n' %
(i, item1, item2))
break
else:
@@ -756,28 +765,26 @@ class TestCase(object):
type(seq1) != type(seq2)):
# The sequences are the same, but have differing types.
return
- # A catch-all message for handling arbitrary user-defined
- # sequences.
- differing = '%ss differ:\n' % seq_type_name.capitalize()
- if len1 > len2:
- differing = ('First %s contains %d additional '
- 'elements.\n' % (seq_type_name, len1 - len2))
- try:
- differing += ('First extra element %d:\n%s\n' %
- (len2, seq1[len2]))
- except (TypeError, IndexError, NotImplementedError):
- differing += ('Unable to index element %d '
- 'of first %s\n' % (len2, seq_type_name))
- elif len1 < len2:
- differing = ('Second %s contains %d additional '
- 'elements.\n' % (seq_type_name, len2 - len1))
- try:
- differing += ('First extra element %d:\n%s\n' %
- (len1, seq2[len1]))
- except (TypeError, IndexError, NotImplementedError):
- differing += ('Unable to index element %d '
- 'of second %s\n' % (len1, seq_type_name))
- standardMsg = differing + '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
+
+ if len1 > len2:
+ differing += ('\nFirst %s contains %d additional '
+ 'elements.\n' % (seq_type_name, len1 - len2))
+ try:
+ differing += ('First extra element %d:\n%s\n' %
+ (len2, seq1[len2]))
+ except (TypeError, IndexError, NotImplementedError):
+ differing += ('Unable to index element %d '
+ 'of first %s\n' % (len2, seq_type_name))
+ elif len1 < len2:
+ differing += ('\nSecond %s contains %d additional '
+ 'elements.\n' % (seq_type_name, len2 - len1))
+ try:
+ differing += ('First extra element %d:\n%s\n' %
+ (len1, seq2[len1]))
+ except (TypeError, IndexError, NotImplementedError):
+ differing += ('Unable to index element %d '
+ 'of second %s\n' % (len1, seq_type_name))
+ standardMsg = differing + '\n' + '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
pprint.pformat(seq2).splitlines()))
msg = self._formatMessage(msg, standardMsg)
self.fail(msg)
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 5f2efb9b3c..5f2418734d 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1055,28 +1055,27 @@ class ZipFile:
self.fp.write(zinfo.FileHeader())
return
- fp = io.open(filename, "rb")
- # Must overwrite CRC and sizes with correct data later
- zinfo.CRC = CRC = 0
- zinfo.compress_size = compress_size = 0
- zinfo.file_size = file_size = 0
- self.fp.write(zinfo.FileHeader())
- if zinfo.compress_type == ZIP_DEFLATED:
- cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
- zlib.DEFLATED, -15)
- else:
- cmpr = None
- while 1:
- buf = fp.read(1024 * 8)
- if not buf:
- break
- file_size = file_size + len(buf)
- CRC = crc32(buf, CRC) & 0xffffffff
- if cmpr:
- buf = cmpr.compress(buf)
- compress_size = compress_size + len(buf)
- self.fp.write(buf)
- fp.close()
+ with open(filename, "rb") as fp:
+ # Must overwrite CRC and sizes with correct data later
+ zinfo.CRC = CRC = 0
+ zinfo.compress_size = compress_size = 0
+ zinfo.file_size = file_size = 0
+ self.fp.write(zinfo.FileHeader())
+ if zinfo.compress_type == ZIP_DEFLATED:
+ cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
+ zlib.DEFLATED, -15)
+ else:
+ cmpr = None
+ while 1:
+ buf = fp.read(1024 * 8)
+ if not buf:
+ break
+ file_size = file_size + len(buf)
+ CRC = crc32(buf, CRC) & 0xffffffff
+ if cmpr:
+ buf = cmpr.compress(buf)
+ compress_size = compress_size + len(buf)
+ self.fp.write(buf)
if cmpr:
buf = cmpr.flush()
compress_size = compress_size + len(buf)
@@ -1400,9 +1399,8 @@ def main(args = None):
tgtdir = os.path.dirname(tgt)
if not os.path.exists(tgtdir):
os.makedirs(tgtdir)
- fp = io.open(tgt, 'wb')
- fp.write(zf.read(path))
- fp.close()
+ with open(tgt, 'wb') as fp:
+ fp.write(zf.read(path))
zf.close()
elif args[0] == '-c':