Commit fa0d7034 authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions...

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
........
parent f11be757
...@@ -137,7 +137,7 @@ Buffer related functions ...@@ -137,7 +137,7 @@ Buffer related functions
Return 1 if *obj* supports the buffer interface otherwise 0. Return 1 if *obj* supports the buffer interface otherwise 0.
.. cfunction:: int PyObject_GetBuffer(PyObject *obj, PyObject *view, int flags) .. cfunction:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
Export *obj* into a :ctype:`Py_buffer`, *view*. These arguments must Export *obj* into a :ctype:`Py_buffer`, *view*. These arguments must
never be *NULL*. The *flags* argument is a bit field indicating what never be *NULL*. The *flags* argument is a bit field indicating what
......
...@@ -50,7 +50,7 @@ Sequence Protocol ...@@ -50,7 +50,7 @@ Sequence Protocol
.. cfunction:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i) .. cfunction:: PyObject* PySequence_GetItem(PyObject *o, Py_ssize_t i)
Return the *i*th element of *o*, or *NULL* on failure. This is the equivalent of Return the *i*\ th element of *o*, or *NULL* on failure. This is the equivalent of
the Python expression ``o[i]``. the Python expression ``o[i]``.
...@@ -62,14 +62,14 @@ Sequence Protocol ...@@ -62,14 +62,14 @@ Sequence Protocol
.. cfunction:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v) .. cfunction:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)
Assign object *v* to the *i*th element of *o*. Returns ``-1`` on failure. This Assign object *v* to the *i*\ th element of *o*. Returns ``-1`` on failure. This
is the equivalent of the Python statement ``o[i] = v``. This function *does is the equivalent of the Python statement ``o[i] = v``. This function *does
not* steal a reference to *v*. not* steal a reference to *v*.
.. cfunction:: int PySequence_DelItem(PyObject *o, Py_ssize_t i) .. cfunction:: int PySequence_DelItem(PyObject *o, Py_ssize_t i)
Delete the *i*th element of object *o*. Returns ``-1`` on failure. This is the Delete the *i*\ th element of object *o*. Returns ``-1`` on failure. This is the
equivalent of the Python statement ``del o[i]``. equivalent of the Python statement ``del o[i]``.
...@@ -131,7 +131,7 @@ Sequence Protocol ...@@ -131,7 +131,7 @@ Sequence Protocol
.. cfunction:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i) .. cfunction:: PyObject* PySequence_Fast_GET_ITEM(PyObject *o, Py_ssize_t i)
Return the *i*th element of *o*, assuming that *o* was returned by Return the *i*\ th element of *o*, assuming that *o* was returned by
:cfunc:`PySequence_Fast`, *o* is not *NULL*, and that *i* is within bounds. :cfunc:`PySequence_Fast`, *o* is not *NULL*, and that *i* is within bounds.
...@@ -147,7 +147,7 @@ Sequence Protocol ...@@ -147,7 +147,7 @@ Sequence Protocol
.. cfunction:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i) .. cfunction:: PyObject* PySequence_ITEM(PyObject *o, Py_ssize_t i)
Return the *i*th element of *o* or *NULL* on failure. Macro form of Return the *i*\ th element of *o* or *NULL* on failure. Macro form of
:cfunc:`PySequence_GetItem` but without checking that :cfunc:`PySequence_GetItem` but without checking that
:cfunc:`PySequence_Check(o)` is true and without adjustment for negative :cfunc:`PySequence_Check(o)` is true and without adjustment for negative
indices. indices.
......
...@@ -46,6 +46,9 @@ unused_docs = [ ...@@ -46,6 +46,9 @@ unused_docs = [
'library/xml.etree', 'library/xml.etree',
] ]
# Ignore .rst in Sphinx its self.
exclude_trees = ['tools/sphinx']
# Relative filename of the reference count data file. # Relative filename of the reference count data file.
refcount_file = 'data/refcounts.dat' refcount_file = 'data/refcounts.dat'
......
...@@ -1207,8 +1207,7 @@ constructs a new Python object each time! ...@@ -1207,8 +1207,7 @@ constructs a new Python object each time!
Variable-sized data types Variable-sized data types
^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^
``ctypes`` provides some support for variable-sized arrays and structures (this ``ctypes`` provides some support for variable-sized arrays and structures.
was added in version 0.9.9.7).
The ``resize`` function can be used to resize the memory buffer of an existing The ``resize`` function can be used to resize the memory buffer of an existing
ctypes object. The function takes the object as first argument, and the ctypes object. The function takes the object as first argument, and the
......
.. _email-examples:
:mod:`email`: Examples :mod:`email`: Examples
---------------------- ----------------------
......
...@@ -73,9 +73,9 @@ The following exceptions are only used as base classes for other exceptions. ...@@ -73,9 +73,9 @@ The following exceptions are only used as base classes for other exceptions.
.. exception:: LookupError .. exception:: LookupError
The base class for the exceptions that are raised when a key or index used on a The base class for the exceptions that are raised when a key or index used on
mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This can be a mapping or sequence is invalid: :exc:`IndexError`, :exc:`KeyError`. This
raised directly by :func:`sys.setdefaultencoding`. can be raised directly by :func:`codecs.lookup`.
.. exception:: EnvironmentError .. exception:: EnvironmentError
......
...@@ -1209,7 +1209,7 @@ are always available. They are listed here in alphabetical order. ...@@ -1209,7 +1209,7 @@ are always available. They are listed here in alphabetical order.
>>> list(zipped) >>> list(zipped)
[(1, 4), (2, 5), (3, 6)] [(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zip(x, y)) >>> x2, y2 = zip(*zip(x, y))
>>> x == x2, y == y2 >>> x == list(x2) and y == list(y2)
True True
...@@ -1272,7 +1272,7 @@ are always available. They are listed here in alphabetical order. ...@@ -1272,7 +1272,7 @@ are always available. They are listed here in alphabetical order.
names. names.
If you simply want to import a module (potentially within a package) by name, If you simply want to import a module (potentially within a package) by name,
you can get it from :data:`sys.modules`:: you can call :func:`__import__` and then look it up in :data:`sys.modules`::
>>> import sys >>> import sys
>>> name = 'foo.bar.baz' >>> name = 'foo.bar.baz'
......
...@@ -384,6 +384,8 @@ HTTPConnection Objects ...@@ -384,6 +384,8 @@ HTTPConnection Objects
Set the debugging level (the amount of debugging output printed). The default Set the debugging level (the amount of debugging output printed). The default
debug level is ``0``, meaning no debugging output is printed. debug level is ``0``, meaning no debugging output is printed.
.. versionadded:: 2.7
.. method:: HTTPConnection.connect() .. method:: HTTPConnection.connect()
......
...@@ -386,9 +386,9 @@ by file descriptors. ...@@ -386,9 +386,9 @@ by file descriptors.
.. note:: .. note::
This function is intended for low-level I/O and must be applied to a file This function is intended for low-level I/O and must be applied to a file
descriptor as returned by :func:`open` or :func:`pipe`. To close a "file descriptor as returned by :func:`os.open` or :func:`pipe`. To close a "file
object" returned by the built-in function :func:`open` or by :func:`popen` or object" returned by the built-in function :func:`open` or by :func:`popen` or
:func:`fdopen`, use its :meth:`close` method. :func:`fdopen`, use its :meth:`~file.close` method.
.. function:: closerange(fd_low, fd_high) .. function:: closerange(fd_low, fd_high)
...@@ -439,6 +439,9 @@ by file descriptors. ...@@ -439,6 +439,9 @@ by file descriptors.
Force write of file with filedescriptor *fd* to disk. Does not force update of Force write of file with filedescriptor *fd* to disk. Does not force update of
metadata. Availability: Unix. metadata. Availability: Unix.
.. note::
This function is not available on MacOS.
.. function:: fpathconf(fd, name) .. function:: fpathconf(fd, name)
...@@ -514,8 +517,8 @@ by file descriptors. ...@@ -514,8 +517,8 @@ by file descriptors.
.. note:: .. note::
This function is intended for low-level I/O. For normal usage, use the built-in This function is intended for low-level I/O. For normal usage, use the built-in
function :func:`open`, which returns a "file object" with :meth:`read` and function :func:`open`, which returns a "file object" with :meth:`~file.read` and
:meth:`write` methods (and many more). To wrap a file descriptor in a "file :meth:`~file.write` methods (and many more). To wrap a file descriptor in a "file
object", use :func:`fdopen`. object", use :func:`fdopen`.
...@@ -544,22 +547,22 @@ by file descriptors. ...@@ -544,22 +547,22 @@ by file descriptors.
.. note:: .. note::
This function is intended for low-level I/O and must be applied to a file This function is intended for low-level I/O and must be applied to a file
descriptor as returned by :func:`open` or :func:`pipe`. To read a "file object" descriptor as returned by :func:`os.open` or :func:`pipe`. To read a "file object"
returned by the built-in function :func:`open` or by :func:`popen` or returned by the built-in function :func:`open` or by :func:`popen` or
:func:`fdopen`, or :data:`sys.stdin`, use its :meth:`read` or :meth:`readline` :func:`fdopen`, or :data:`sys.stdin`, use its :meth:`~file.read` or
methods. :meth:`~file.readline` methods.
.. function:: tcgetpgrp(fd) .. function:: tcgetpgrp(fd)
Return the process group associated with the terminal given by *fd* (an open Return the process group associated with the terminal given by *fd* (an open
file descriptor as returned by :func:`open`). Availability: Unix. file descriptor as returned by :func:`os.open`). Availability: Unix.
.. function:: tcsetpgrp(fd, pg) .. function:: tcsetpgrp(fd, pg)
Set the process group associated with the terminal given by *fd* (an open file Set the process group associated with the terminal given by *fd* (an open file
descriptor as returned by :func:`open`) to *pg*. Availability: Unix. descriptor as returned by :func:`os.open`) to *pg*. Availability: Unix.
.. function:: ttyname(fd) .. function:: ttyname(fd)
...@@ -577,13 +580,13 @@ by file descriptors. ...@@ -577,13 +580,13 @@ by file descriptors.
.. note:: .. note::
This function is intended for low-level I/O and must be applied to a file This function is intended for low-level I/O and must be applied to a file
descriptor as returned by :func:`open` or :func:`pipe`. To write a "file descriptor as returned by :func:`os.open` or :func:`pipe`. To write a "file
object" returned by the built-in function :func:`open` or by :func:`popen` or object" returned by the built-in function :func:`open` or by :func:`popen` or
:func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its :meth:`write` :func:`fdopen`, or :data:`sys.stdout` or :data:`sys.stderr`, use its
method. :meth:`~file.write` method.
The following constants are options for the *flags* parameter to the The following constants are options for the *flags* parameter to the
:func:`open` function. They can be combined using the bitwise OR operator :func:`~os.open` function. They can be combined using the bitwise OR operator
``|``. Some of them are not available on all platforms. For descriptions of ``|``. Some of them are not available on all platforms. For descriptions of
their availability and use, consult the :manpage:`open(2)` manual page on Unix their availability and use, consult the :manpage:`open(2)` manual page on Unix
or `the MSDN <http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>` on Windows. or `the MSDN <http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>` on Windows.
...@@ -660,7 +663,7 @@ Files and Directories ...@@ -660,7 +663,7 @@ Files and Directories
.. note:: .. note::
Using :func:`access` to check if a user is authorized to e.g. open a file before Using :func:`access` to check if a user is authorized to e.g. open a file before
actually doing so using :func:`open` creates a security hole, because the user actually doing so using :func:`open` creates a security hole, because the user
might exploit the short time interval between checking and opening the file to might exploit the short time interval between checking and opening the file to
manipulate it. manipulate it.
......
...@@ -52,7 +52,7 @@ Completer objects have the following method: ...@@ -52,7 +52,7 @@ Completer objects have the following method:
.. method:: Completer.complete(text, state) .. method:: Completer.complete(text, state)
Return the *state*th completion for *text*. Return the *state*\ th completion for *text*.
If called for *text* that doesn't include a period character (``'.'``), it will If called for *text* that doesn't include a period character (``'.'``), it will
complete from names currently defined in :mod:`__main__`, :mod:`builtins` and complete from names currently defined in :mod:`__main__`, :mod:`builtins` and
......
...@@ -364,3 +364,8 @@ example doesn't do any processing of the :rfc:`822` headers. In particular, the ...@@ -364,3 +364,8 @@ example doesn't do any processing of the :rfc:`822` headers. In particular, the
server.sendmail(fromaddr, toaddrs, msg) server.sendmail(fromaddr, toaddrs, msg)
server.quit() server.quit()
.. note::
In general, you will want to use the :mod:`email` package's features to
construct an email message, which you can then convert to a string and send
via :meth:`sendmail`; see :ref:`email-examples`.
...@@ -34,9 +34,12 @@ This module defines one class called :class:`Popen`: ...@@ -34,9 +34,12 @@ This module defines one class called :class:`Popen`:
Arguments are: Arguments are:
*args* should be a string, or a sequence of program arguments. The program *args* should be a string, or a sequence of program arguments. The program
to execute is normally the first item in the args sequence or the string if a to execute is normally the first item in the args sequence or the string if
string is given, but can be explicitly set by using the *executable* a string is given, but can be explicitly set by using the *executable*
argument. argument. When *executable* is given, the first item in the args sequence
is still treated by most programs as the command name, which can then be
different from the actual executable name. On Unix, it becomes the display
name for the executing program in utilities such as :program:`ps`.
On Unix, with *shell=False* (default): In this case, the Popen class uses On Unix, with *shell=False* (default): In this case, the Popen class uses
:meth:`os.execvp` to execute the child program. *args* should normally be a :meth:`os.execvp` to execute the child program. *args* should normally be a
......
...@@ -815,12 +815,8 @@ then you will end up importing ``pkg.mod``. If you execute ``from ..subpkg2 ...@@ -815,12 +815,8 @@ then you will end up importing ``pkg.mod``. If you execute ``from ..subpkg2
imprt mod`` from within ``pkg.subpkg1`` you will import ``pkg.subpkg2.mod``. imprt mod`` from within ``pkg.subpkg1`` you will import ``pkg.subpkg2.mod``.
The specification for relative imports is contained within :pep:`328`. The specification for relative imports is contained within :pep:`328`.
:func:`importlib.import_module` is provided to support applications that
.. index:: builtin: __import__ determine which modules need to be loaded dynamically.
The built-in function :func:`__import__` is provided to support applications
that determine which modules need to be loaded dynamically; refer to
:ref:`built-in-funcs` for additional information.
.. _future: .. _future:
......
...@@ -415,7 +415,6 @@ def translation(domain, localedir=None, languages=None, ...@@ -415,7 +415,6 @@ def translation(domain, localedir=None, languages=None,
if fallback: if fallback:
return NullTranslations() return NullTranslations()
raise IOError(ENOENT, 'No translation file found for domain', domain) 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 # Avoid opening, reading, and parsing the .mo file after it's been done
# once. # once.
result = None result = None
...@@ -423,7 +422,8 @@ def translation(domain, localedir=None, languages=None, ...@@ -423,7 +422,8 @@ def translation(domain, localedir=None, languages=None,
key = os.path.abspath(mofile) key = os.path.abspath(mofile)
t = _translations.get(key) t = _translations.get(key)
if t is None: 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 # Copy the translation object to allow setting fallbacks and
# output charset. All other instance data is shared with the # output charset. All other instance data is shared with the
# cached object. # cached object.
......
...@@ -88,6 +88,7 @@ def overrideRootMenu(root, flist): ...@@ -88,6 +88,7 @@ def overrideRootMenu(root, flist):
# on an EditorWindow instance that is then passed as the first # on an EditorWindow instance that is then passed as the first
# argument to ConfigDialog) # argument to ConfigDialog)
root.instance_dict = flist.inversedict root.instance_dict = flist.inversedict
root.instance_dict = flist.inversedict
configDialog.ConfigDialog(root, 'Settings') configDialog.ConfigDialog(root, 'Settings')
......
...@@ -720,8 +720,12 @@ class Handler(Filterer): ...@@ -720,8 +720,12 @@ class Handler(Filterer):
""" """
if raiseExceptions: if raiseExceptions:
ei = sys.exc_info() ei = sys.exc_info()
traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr) try:
del ei traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
except IOError:
pass # see issue 5971
finally:
del ei
class StreamHandler(Handler): class StreamHandler(Handler):
""" """
......
...@@ -5,6 +5,7 @@ if __name__ != 'test.support': ...@@ -5,6 +5,7 @@ if __name__ != 'test.support':
import contextlib import contextlib
import errno import errno
import functools
import socket import socket
import sys import sys
import os import os
...@@ -933,6 +934,16 @@ def threading_cleanup(num_active, num_limbo): ...@@ -933,6 +934,16 @@ def threading_cleanup(num_active, num_limbo):
count += 1 count += 1
time.sleep(0.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(): def reap_children():
"""Use this function at the end of test_main() whenever sub-processes """Use this function at the end of test_main() whenever sub-processes
are started. This will help ensure that no extra children (zombies) are started. This will help ensure that no extra children (zombies)
......
...@@ -267,10 +267,9 @@ class HashLibTestCase(unittest.TestCase): ...@@ -267,10 +267,9 @@ class HashLibTestCase(unittest.TestCase):
self.assertEqual(expected_hash, hasher.hexdigest()) self.assertEqual(expected_hash, hasher.hexdigest())
@support.reap_threads
def test_main(): def test_main():
support.run_unittest(HashLibTestCase) support.run_unittest(HashLibTestCase)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
...@@ -35,9 +35,7 @@ class FileTests(unittest.TestCase): ...@@ -35,9 +35,7 @@ class FileTests(unittest.TestCase):
retries += 1 retries += 1
if retries > 10: if retries > 10:
# XXX test skipped # XXX test skipped
print("couldn't allocate two consecutive fds, " self.skipTest("couldn't allocate two consecutive fds")
"skipping test_closerange", file=sys.stderr)
return
first, second = second, os.dup(second) first, second = second, os.dup(second)
finally: finally:
os.close(second) os.close(second)
......
...@@ -3175,7 +3175,7 @@ class TestCleanUp(TestCase): ...@@ -3175,7 +3175,7 @@ class TestCleanUp(TestCase):
result = MockResult() result = MockResult()
test = TestableTest('testNothing') test = TestableTest('testNothing')
test._result = result test._resultForDoCleanups = result
exc1 = Exception('foo') exc1 = Exception('foo')
exc2 = Exception('bar') exc2 = Exception('bar')
......
...@@ -353,7 +353,7 @@ class TestCase(object): ...@@ -353,7 +353,7 @@ class TestCase(object):
not have a method with the specified name. not have a method with the specified name.
""" """
self._testMethodName = methodName self._testMethodName = methodName
self._result = None self._resultForDoCleanups = None
try: try:
testMethod = getattr(self, methodName) testMethod = getattr(self, methodName)
except AttributeError: except AttributeError:
...@@ -457,7 +457,7 @@ class TestCase(object): ...@@ -457,7 +457,7 @@ class TestCase(object):
if startTestRun is not None: if startTestRun is not None:
startTestRun() startTestRun()
self._result = result self._resultForDoCleanups = result
result.startTest(self) result.startTest(self)
if getattr(self.__class__, "__unittest_skip__", False): if getattr(self.__class__, "__unittest_skip__", False):
# If the whole class was skipped. # If the whole class was skipped.
...@@ -511,7 +511,7 @@ class TestCase(object): ...@@ -511,7 +511,7 @@ class TestCase(object):
def doCleanups(self): def doCleanups(self):
"""Execute all cleanup functions. Normally called for you after """Execute all cleanup functions. Normally called for you after
tearDown.""" tearDown."""
result = self._result result = self._resultForDoCleanups
ok = True ok = True
while self._cleanups: while self._cleanups:
function, args, kwargs = self._cleanups.pop(-1) function, args, kwargs = self._cleanups.pop(-1)
...@@ -732,23 +732,32 @@ class TestCase(object): ...@@ -732,23 +732,32 @@ class TestCase(object):
if seq1 == seq2: if seq1 == seq2:
return 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)): for i in range(min(len1, len2)):
try: try:
item1 = seq1[i] item1 = seq1[i]
except (TypeError, IndexError, NotImplementedError): 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)) (i, seq_type_name))
break break
try: try:
item2 = seq2[i] item2 = seq2[i]
except (TypeError, IndexError, NotImplementedError): 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)) (i, seq_type_name))
break break
if item1 != item2: 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)) (i, item1, item2))
break break
else: else:
...@@ -756,28 +765,26 @@ class TestCase(object): ...@@ -756,28 +765,26 @@ class TestCase(object):
type(seq1) != type(seq2)): type(seq1) != type(seq2)):
# The sequences are the same, but have differing types. # The sequences are the same, but have differing types.
return return
# A catch-all message for handling arbitrary user-defined
# sequences. if len1 > len2:
differing = '%ss differ:\n' % seq_type_name.capitalize() differing += ('\nFirst %s contains %d additional '
if len1 > len2: 'elements.\n' % (seq_type_name, len1 - len2))
differing = ('First %s contains %d additional ' try:
'elements.\n' % (seq_type_name, len1 - len2)) differing += ('First extra element %d:\n%s\n' %
try: (len2, seq1[len2]))
differing += ('First extra element %d:\n%s\n' % except (TypeError, IndexError, NotImplementedError):
(len2, seq1[len2])) differing += ('Unable to index element %d '
except (TypeError, IndexError, NotImplementedError): 'of first %s\n' % (len2, seq_type_name))
differing += ('Unable to index element %d ' elif len1 < len2:
'of first %s\n' % (len2, seq_type_name)) differing += ('\nSecond %s contains %d additional '
elif len1 < len2: 'elements.\n' % (seq_type_name, len2 - len1))
differing = ('Second %s contains %d additional ' try:
'elements.\n' % (seq_type_name, len2 - len1)) differing += ('First extra element %d:\n%s\n' %
try: (len1, seq2[len1]))
differing += ('First extra element %d:\n%s\n' % except (TypeError, IndexError, NotImplementedError):
(len1, seq2[len1])) differing += ('Unable to index element %d '
except (TypeError, IndexError, NotImplementedError): 'of second %s\n' % (len1, seq_type_name))
differing += ('Unable to index element %d ' standardMsg = differing + '\n' + '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
'of second %s\n' % (len1, seq_type_name))
standardMsg = differing + '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
pprint.pformat(seq2).splitlines())) pprint.pformat(seq2).splitlines()))
msg = self._formatMessage(msg, standardMsg) msg = self._formatMessage(msg, standardMsg)
self.fail(msg) self.fail(msg)
......
...@@ -1055,28 +1055,27 @@ class ZipFile: ...@@ -1055,28 +1055,27 @@ class ZipFile:
self.fp.write(zinfo.FileHeader()) self.fp.write(zinfo.FileHeader())
return return
fp = io.open(filename, "rb") with open(filename, "rb") as fp:
# Must overwrite CRC and sizes with correct data later # Must overwrite CRC and sizes with correct data later
zinfo.CRC = CRC = 0 zinfo.CRC = CRC = 0
zinfo.compress_size = compress_size = 0 zinfo.compress_size = compress_size = 0
zinfo.file_size = file_size = 0 zinfo.file_size = file_size = 0
self.fp.write(zinfo.FileHeader()) self.fp.write(zinfo.FileHeader())
if zinfo.compress_type == ZIP_DEFLATED: if zinfo.compress_type == ZIP_DEFLATED:
cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
zlib.DEFLATED, -15) zlib.DEFLATED, -15)
else: else:
cmpr = None cmpr = None
while 1: while 1:
buf = fp.read(1024 * 8) buf = fp.read(1024 * 8)
if not buf: if not buf:
break break
file_size = file_size + len(buf) file_size = file_size + len(buf)
CRC = crc32(buf, CRC) & 0xffffffff CRC = crc32(buf, CRC) & 0xffffffff
if cmpr: if cmpr:
buf = cmpr.compress(buf) buf = cmpr.compress(buf)
compress_size = compress_size + len(buf) compress_size = compress_size + len(buf)
self.fp.write(buf) self.fp.write(buf)
fp.close()
if cmpr: if cmpr:
buf = cmpr.flush() buf = cmpr.flush()
compress_size = compress_size + len(buf) compress_size = compress_size + len(buf)
...@@ -1400,9 +1399,8 @@ def main(args = None): ...@@ -1400,9 +1399,8 @@ def main(args = None):
tgtdir = os.path.dirname(tgt) tgtdir = os.path.dirname(tgt)
if not os.path.exists(tgtdir): if not os.path.exists(tgtdir):
os.makedirs(tgtdir) os.makedirs(tgtdir)
fp = io.open(tgt, 'wb') with open(tgt, 'wb') as fp:
fp.write(zf.read(path)) fp.write(zf.read(path))
fp.close()
zf.close() zf.close()
elif args[0] == '-c': elif args[0] == '-c':
......
...@@ -3,7 +3,7 @@ import re ...@@ -3,7 +3,7 @@ import re
# Write the config.c file # Write the config.c file
never = ['marshal', '__main__', 'builtins', 'sys', 'exceptions'] never = ['marshal', '__main__', 'builtins', 'sys', 'exceptions', '_warnings']
def makeconfig(infp, outfp, modules, with_ifdef=0): def makeconfig(infp, outfp, modules, with_ifdef=0):
m1 = re.compile('-- ADDMODULE MARKER 1 --') m1 = re.compile('-- ADDMODULE MARKER 1 --')
......
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