[Python-checkins] r86518 - in python/branches/py3k-cdecimal: Doc/library/functools.rst Doc/library/pydoc.rst Doc/library/ssl.rst Doc/library/threading.rst Doc/reference/simple_stmts.rst Include/moduleobject.h Lib/decimal.py Lib/importlib/_bootstrap.py Lib/pydoc.py Lib/test/lock_tests.py Lib/test/pydoc_mod.py Lib/test/test_decimal.py Lib/test/test_dict.py Lib/test/test_nntplib.py Lib/test/test_pydoc.py Lib/test/test_ssl.py Lib/test/test_xmlrpc.py Lib/test/test_zipfile.py Lib/threading.py Lib/unittest/runner.py Lib/xmlrpc/client.py Misc/NEWS Modules/_ssl.c Objects/dictobject.c Python/getargs.c
stefan.krah
python-checkins at python.org
Thu Nov 18 16:28:35 CET 2010
Author: stefan.krah
Date: Thu Nov 18 16:28:34 2010
New Revision: 86518
Log:
Merged revisions 86498-86501,86504,86506-86511,86513-86514,86516-86517 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r86498 | antoine.pitrou | 2010-11-17 21:29:42 +0100 (Wed, 17 Nov 2010) | 3 lines
Issue #10443: Add the SSLContext.set_default_verify_paths() method.
........
r86499 | david.malcolm | 2010-11-17 22:20:18 +0100 (Wed, 17 Nov 2010) | 6 lines
Issue #9518: Extend the PyModuleDef_HEAD_INIT macro to explicitly
zero-initialize all fields, fixing compiler warnings seen when building
extension modules with gcc with "-Wmissing-field-initializers" (implied
by "-W")
........
r86500 | antoine.pitrou | 2010-11-17 22:55:41 +0100 (Wed, 17 Nov 2010) | 3 lines
Use laxer timeouts in barrier tests
........
r86501 | benjamin.peterson | 2010-11-17 23:33:12 +0100 (Wed, 17 Nov 2010) | 1 line
handle dict subclasses gracefully in PyArg_ValidateKeywordArguments
........
r86504 | alexander.belopolsky | 2010-11-18 02:52:54 +0100 (Thu, 18 Nov 2010) | 15 lines
Issue #10446: Several changes to module documentation generated by pydoc:
1. Online reference manual link is now version-specific and the
'MODULE DOCS' section renamed to 'MODULE REFERENCE'.
2. 'FILE' section is moved to the end of the file.
3. Special names processed by pydoc such as __version__ or __credits__
are now excluded from the DATA section.
4. Defined __all__ to prevent pydoc from exposing undocumented details
about itself.
5. Removed Python 2.3 compatibility code.
........
r86506 | brian.curtin | 2010-11-18 03:15:28 +0100 (Thu, 18 Nov 2010) | 2 lines
Fix #8886. Use context managers throughout the test.
........
r86507 | brett.cannon | 2010-11-18 04:03:04 +0100 (Thu, 18 Nov 2010) | 5 lines
Fix a minor inconsistency in capitalization for the 'No module named' exception
message in importlib.
Thanks to Éric Araujo for spotting the inconsistency.
........
r86508 | alexander.belopolsky | 2010-11-18 04:50:18 +0100 (Thu, 18 Nov 2010) | 1 line
Issue #10446 NEWS entry
........
r86509 | michael.foord | 2010-11-18 12:02:50 +0100 (Thu, 18 Nov 2010) | 1 line
Remove duplicate period from reference doc
........
r86510 | kristjan.jonsson | 2010-11-18 13:46:39 +0100 (Thu, 18 Nov 2010) | 2 lines
Issue 10260
Adding the wait_for() method to threading.Condition
........
r86511 | benjamin.peterson | 2010-11-18 15:14:43 +0100 (Thu, 18 Nov 2010) | 1 line
reduce try block compass
........
r86513 | eric.araujo | 2010-11-18 15:22:08 +0100 (Thu, 18 Nov 2010) | 2 lines
Remove spurious space that was breaking Vim’s reST highlighting.
........
r86514 | senthil.kumaran | 2010-11-18 16:00:53 +0100 (Thu, 18 Nov 2010) | 3 lines
Fix Issue 9991: xmlrpc client ssl check faulty
........
r86516 | antoine.pitrou | 2010-11-18 16:11:43 +0100 (Thu, 18 Nov 2010) | 3 lines
Make test_nntplib more robust when the "last" article in a group can't be retrieved
........
r86517 | stefan.krah | 2010-11-18 16:20:34 +0100 (Thu, 18 Nov 2010) | 3 lines
Issue #10356: hash(Decimal("sNaN")) now raises ValueError instead of TypeError.
........
Modified:
python/branches/py3k-cdecimal/ (props changed)
python/branches/py3k-cdecimal/Doc/library/functools.rst
python/branches/py3k-cdecimal/Doc/library/pydoc.rst
python/branches/py3k-cdecimal/Doc/library/ssl.rst
python/branches/py3k-cdecimal/Doc/library/threading.rst
python/branches/py3k-cdecimal/Doc/reference/simple_stmts.rst
python/branches/py3k-cdecimal/Include/moduleobject.h
python/branches/py3k-cdecimal/Lib/decimal.py
python/branches/py3k-cdecimal/Lib/importlib/_bootstrap.py
python/branches/py3k-cdecimal/Lib/pydoc.py
python/branches/py3k-cdecimal/Lib/test/lock_tests.py
python/branches/py3k-cdecimal/Lib/test/pydoc_mod.py
python/branches/py3k-cdecimal/Lib/test/test_decimal.py
python/branches/py3k-cdecimal/Lib/test/test_dict.py
python/branches/py3k-cdecimal/Lib/test/test_nntplib.py
python/branches/py3k-cdecimal/Lib/test/test_pydoc.py
python/branches/py3k-cdecimal/Lib/test/test_ssl.py
python/branches/py3k-cdecimal/Lib/test/test_xmlrpc.py
python/branches/py3k-cdecimal/Lib/test/test_zipfile.py
python/branches/py3k-cdecimal/Lib/threading.py
python/branches/py3k-cdecimal/Lib/unittest/runner.py
python/branches/py3k-cdecimal/Lib/xmlrpc/client.py
python/branches/py3k-cdecimal/Misc/NEWS
python/branches/py3k-cdecimal/Modules/_ssl.c
python/branches/py3k-cdecimal/Objects/dictobject.c
python/branches/py3k-cdecimal/Python/getargs.c
Modified: python/branches/py3k-cdecimal/Doc/library/functools.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/functools.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/functools.rst Thu Nov 18 16:28:34 2010
@@ -20,7 +20,7 @@
The :mod:`functools` module defines the following functions:
-.. function:: cmp_to_key(func)
+.. function:: cmp_to_key(func)
Transform an old-style comparison function to a key-function. Used with
tools that accept key functions (such as :func:`sorted`, :func:`min`,
Modified: python/branches/py3k-cdecimal/Doc/library/pydoc.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/pydoc.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/pydoc.rst Thu Nov 18 16:28:34 2010
@@ -63,7 +63,9 @@
Python interpreter and typed ``import spam``.
Module docs for core modules are assumed to reside in
-http://docs.python.org/library/. This can be overridden by setting the
-:envvar:`PYTHONDOCS` environment variable to a different URL or to a local
-directory containing the Library Reference Manual pages.
+``http://docs.python.org/X.Y/library/`` where ``X`` and ``Y`` are the
+major and minor version numbers of the Python interpreter. This can
+be overridden by setting the :envvar:`PYTHONDOCS` environment variable
+to a different URL or to a local directory containing the Library
+Reference Manual pages.
Modified: python/branches/py3k-cdecimal/Doc/library/ssl.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/ssl.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/ssl.rst Thu Nov 18 16:28:34 2010
@@ -536,6 +536,15 @@
following an `OpenSSL specific layout
<http://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html>`_.
+.. method:: SSLContext.set_default_verify_paths()
+
+ Load a set of default "certification authority" (CA) certificates from
+ a filesystem path defined when building the OpenSSL library. Unfortunately,
+ there's no easy way to know whether this method succeeds: no error is
+ returned if no certificates are to be found. When the OpenSSL library is
+ provided as part of the operating system, though, it is likely to be
+ configured properly.
+
.. method:: SSLContext.set_ciphers(ciphers)
Set the available ciphers for sockets created with this context.
Modified: python/branches/py3k-cdecimal/Doc/library/threading.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/library/threading.rst (original)
+++ python/branches/py3k-cdecimal/Doc/library/threading.rst Thu Nov 18 16:28:34 2010
@@ -539,6 +539,13 @@
in a typical producer-consumer situation, adding one item to the buffer only
needs to wake up one consumer thread.
+Note: Condition variables can be, depending on the implementation, subject
+to both spurious wakeups (when :meth:`wait` returns without a :meth:`notify`
+call) and stolen wakeups (when another thread acquires the lock before the
+awoken thread.) For this reason, it is always necessary to verify the state
+the thread is waiting for when :meth:`wait` returns and optionally repeat
+the call as often as necessary.
+
.. class:: Condition(lock=None)
@@ -585,6 +592,35 @@
.. versionchanged:: 3.2
Previously, the method always returned ``None``.
+ .. method:: wait_for(predicate, timeout=None)
+
+ Wait until a condition evaluates to True. *predicate* should be a
+ callable which result will be interpreted as a boolean value.
+ A *timeout* may be provided giving the maximum time to wait.
+
+ This utility method may call :meth:`wait` repeatedly until the predicate
+ is satisfied, or until a timeout occurs. The return value is
+ the last return value of the predicate and will evaluate to
+ ``False`` if the method timed out.
+
+ Ignoring the timeout feature, calling this method is roughly equivalent to
+ writing::
+
+ while not predicate():
+ cv.wait()
+
+ Therefore, the same rules apply as with :meth:`wait`: The lock must be
+ held when called and is re-aquired on return. The predicate is evaluated
+ with the lock held.
+
+ Using this method, the consumer example above can be written thus::
+
+ with cv:
+ cv.wait_for(an_item_is_available)
+ get_an_available_item()
+
+ .. versionadded:: 3.2
+
.. method:: notify()
Wake up a thread waiting on this condition, if any. If the calling thread
Modified: python/branches/py3k-cdecimal/Doc/reference/simple_stmts.rst
==============================================================================
--- python/branches/py3k-cdecimal/Doc/reference/simple_stmts.rst (original)
+++ python/branches/py3k-cdecimal/Doc/reference/simple_stmts.rst Thu Nov 18 16:28:34 2010
@@ -791,7 +791,7 @@
specifying ":keyword:`as` localname". If a name is not found,
:exc:`ImportError` is raised. If the list of identifiers is replaced by a star
(``'*'``), all public names defined in the module are bound in the local
-namespace of the :keyword:`import` statement..
+namespace of the :keyword:`import` statement.
.. index:: single: __all__ (optional module attribute)
Modified: python/branches/py3k-cdecimal/Include/moduleobject.h
==============================================================================
--- python/branches/py3k-cdecimal/Include/moduleobject.h (original)
+++ python/branches/py3k-cdecimal/Include/moduleobject.h Thu Nov 18 16:28:34 2010
@@ -28,7 +28,12 @@
PyObject* m_copy;
} PyModuleDef_Base;
-#define PyModuleDef_HEAD_INIT {PyObject_HEAD_INIT(NULL)}
+#define PyModuleDef_HEAD_INIT { \
+ PyObject_HEAD_INIT(NULL) \
+ NULL, /* m_init */ \
+ 0, /* m_index */ \
+ NULL, /* m_copy */ \
+ }
typedef struct PyModuleDef{
PyModuleDef_Base m_base;
Modified: python/branches/py3k-cdecimal/Lib/decimal.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/decimal.py (original)
+++ python/branches/py3k-cdecimal/Lib/decimal.py Thu Nov 18 16:28:34 2010
@@ -943,7 +943,7 @@
# in the documentation. (See library docs, 'Built-in Types').
if self._is_special:
if self.is_snan():
- raise TypeError('Cannot hash a signaling NaN value.')
+ raise ValueError('Cannot hash a signaling NaN value.')
elif self.is_nan():
return _PyHASH_NAN
else:
Modified: python/branches/py3k-cdecimal/Lib/importlib/_bootstrap.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/importlib/_bootstrap.py (original)
+++ python/branches/py3k-cdecimal/Lib/importlib/_bootstrap.py Thu Nov 18 16:28:34 2010
@@ -758,6 +758,8 @@
_IMPLICIT_META_PATH = [BuiltinImporter, FrozenImporter, _DefaultPathFinder]
+_ERR_MSG = 'No module named {}'
+
def _gcd_import(name, package=None, level=0):
"""Import and return the module based on its name, the package the call is
being made from, and the level adjustment.
@@ -808,8 +810,8 @@
try:
path = parent_module.__path__
except AttributeError:
- raise ImportError("no module named {}; "
- "{} is not a package".format(name, parent))
+ msg = (_ERR_MSG + '; {} is not a package').format(name, parent)
+ raise ImportError(msg)
meta_path = sys.meta_path + _IMPLICIT_META_PATH
for finder in meta_path:
loader = finder.find_module(name, path)
@@ -817,7 +819,7 @@
loader.load_module(name)
break
else:
- raise ImportError("No module named {0}".format(name))
+ raise ImportError(_ERR_MSG.format(name))
# Backwards-compatibility; be nicer to skip the dict lookup.
module = sys.modules[name]
if parent:
Modified: python/branches/py3k-cdecimal/Lib/pydoc.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/pydoc.py (original)
+++ python/branches/py3k-cdecimal/Lib/pydoc.py Thu Nov 18 16:28:34 2010
@@ -26,13 +26,13 @@
Module docs for core modules are assumed to be in
- http://docs.python.org/library/
+ http://docs.python.org/X.Y/library/
This can be overridden by setting the PYTHONDOCS environment variable
to a different URL or to a local directory containing the Library
Reference Manual pages.
"""
-
+__all__ = ['help']
__author__ = "Ka-Ping Yee <ping at lfw.org>"
__date__ = "26 February 2001"
@@ -54,14 +54,7 @@
import sys, imp, os, re, inspect, builtins, pkgutil
from reprlib import Repr
from traceback import extract_tb as _extract_tb
-try:
- from collections import deque
-except ImportError:
- # Python 2.3 compatibility
- class deque(list):
- def popleft(self):
- return self.pop(0)
-
+from collections import deque
# --------------------------------------------------------- common routines
def pathdirs():
@@ -159,7 +152,8 @@
# Certain special names are redundant.
_hidden_names = ('__builtins__', '__doc__', '__file__', '__path__',
'__module__', '__name__', '__slots__', '__package__',
- '__cached__')
+ '__cached__', '__author__', '__credits__', '__date__',
+ '__version__')
if name in _hidden_names: return 0
# Private names are hidden, but special names are displayed.
if name.startswith('__') and name.endswith('__'): return 1
@@ -306,6 +300,11 @@
# ---------------------------------------------------- formatter base class
class Doc:
+
+ PYTHONDOCS = os.environ.get("PYTHONDOCS",
+ "http://docs.python.org/%d.%d/library"
+ % sys.version_info[:2])
+
def document(self, object, name=None, *args):
"""Generate documentation for an object."""
args = (object, name) + args
@@ -340,10 +339,10 @@
except TypeError:
file = '(built-in)'
- docloc = os.environ.get("PYTHONDOCS",
- "http://docs.python.org/library")
+ docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS)
+
basedir = os.path.join(sys.exec_prefix, "lib",
- "python"+sys.version[0:3])
+ "python%d.%d" % sys.version_info[:2])
if (isinstance(object, type(os)) and
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
'marshal', 'posix', 'signal', 'sys',
@@ -607,7 +606,7 @@
head = head + ' (%s)' % ', '.join(info)
docloc = self.getdocloc(object)
if docloc is not None:
- docloc = '<br><a href="%(docloc)s">Module Docs</a>' % locals()
+ docloc = '<br><a href="%(docloc)s">Module Reference</a>' % locals()
else:
docloc = ''
result = self.heading(
@@ -1016,21 +1015,16 @@
name = object.__name__ # ignore the passed-in name
synop, desc = splitdoc(getdoc(object))
result = self.section('NAME', name + (synop and ' - ' + synop))
-
- try:
- all = object.__all__
- except AttributeError:
- all = None
-
- try:
- file = inspect.getabsfile(object)
- except TypeError:
- file = '(built-in)'
- result = result + self.section('FILE', file)
-
+ all = getattr(object, '__all__', None)
docloc = self.getdocloc(object)
if docloc is not None:
- result = result + self.section('MODULE DOCS', docloc)
+ result = result + self.section('MODULE REFERENCE', docloc + """
+
+The following documentation is automatically generated from the Python source
+files. It may be incomplete, incorrect or include features that are considered
+implementation detail and may vary between Python implementations. When in
+doubt, consult the module reference at the location listed above.
+""")
if desc:
result = result + self.section('DESCRIPTION', desc)
@@ -1109,6 +1103,11 @@
result = result + self.section('AUTHOR', str(object.__author__))
if hasattr(object, '__credits__'):
result = result + self.section('CREDITS', str(object.__credits__))
+ try:
+ file = inspect.getabsfile(object)
+ except TypeError:
+ file = '(built-in)'
+ result = result + self.section('FILE', file)
return result
def docclass(self, object, name=None, mod=None):
Modified: python/branches/py3k-cdecimal/Lib/test/lock_tests.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/lock_tests.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/lock_tests.py Thu Nov 18 16:28:34 2010
@@ -446,6 +446,46 @@
# In practice, this implementation has no spurious wakeups.
self.assertFalse(result)
+ def test_waitfor(self):
+ cond = self.condtype()
+ state = 0
+ def f():
+ with cond:
+ result = cond.wait_for(lambda : state==4)
+ self.assertTrue(result)
+ self.assertEqual(state, 4)
+ b = Bunch(f, 1)
+ b.wait_for_started()
+ for i in range(5):
+ time.sleep(0.01)
+ with cond:
+ state += 1
+ cond.notify()
+ b.wait_for_finished()
+
+ def test_waitfor_timeout(self):
+ cond = self.condtype()
+ state = 0
+ success = []
+ def f():
+ with cond:
+ dt = time.time()
+ result = cond.wait_for(lambda : state==4, timeout=0.1)
+ dt = time.time() - dt
+ self.assertFalse(result)
+ self.assertTimeout(dt, 0.1)
+ success.append(None)
+ b = Bunch(f, 1)
+ b.wait_for_started()
+ # Only increment 3 times, so state == 4 is never reached.
+ for i in range(3):
+ time.sleep(0.01)
+ with cond:
+ state += 1
+ cond.notify()
+ b.wait_for_finished()
+ self.assertEqual(len(success), 1)
+
class BaseSemaphoreTests(BaseTestCase):
"""
@@ -604,7 +644,7 @@
Tests for Barrier objects.
"""
N = 5
- defaultTimeout = 0.5
+ defaultTimeout = 2.0
def setUp(self):
self.barrier = self.barriertype(self.N, timeout=self.defaultTimeout)
@@ -766,10 +806,10 @@
i = self.barrier.wait()
if i == self.N // 2:
# One thread is late!
- time.sleep(0.1)
- # Default timeout is 0.1, so this is shorter.
+ time.sleep(1.0)
+ # Default timeout is 2.0, so this is shorter.
self.assertRaises(threading.BrokenBarrierError,
- self.barrier.wait, 0.05)
+ self.barrier.wait, 0.5)
self.run_threads(f)
def test_default_timeout(self):
@@ -782,7 +822,7 @@
i = barrier.wait()
if i == self.N // 2:
# One thread is later than the default timeout of 0.1s.
- time.sleep(0.2)
+ time.sleep(1.0)
self.assertRaises(threading.BrokenBarrierError, barrier.wait)
self.run_threads(f)
Modified: python/branches/py3k-cdecimal/Lib/test/pydoc_mod.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/pydoc_mod.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/pydoc_mod.py Thu Nov 18 16:28:34 2010
@@ -3,7 +3,7 @@
__author__ = "Benjamin Peterson"
__credits__ = "Nobody"
__version__ = "1.2.3.4"
-
+__xyz__ = "X, Y and Z"
class A:
"""Hello and goodbye"""
Modified: python/branches/py3k-cdecimal/Lib/test/test_decimal.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_decimal.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_decimal.py Thu Nov 18 16:28:34 2010
@@ -1346,7 +1346,7 @@
#the same hash that to an int
self.assertEqual(hashit(Decimal(23)), hashit(23))
- self.assertRaises(TypeError, hash, Decimal('sNaN'))
+ self.assertRaises(ValueError, hash, Decimal('sNaN'))
self.assertTrue(hashit(Decimal('Inf')))
self.assertTrue(hashit(Decimal('-Inf')))
Modified: python/branches/py3k-cdecimal/Lib/test/test_dict.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_dict.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_dict.py Thu Nov 18 16:28:34 2010
@@ -8,10 +8,13 @@
class DictTest(unittest.TestCase):
def test_invalid_keyword_arguments(self):
- with self.assertRaises(TypeError):
- dict(**{1 : 2})
- with self.assertRaises(TypeError):
- {}.update(**{1 : 2})
+ class Custom(dict):
+ pass
+ for invalid in {1 : 2}, Custom({1 : 2}):
+ with self.assertRaises(TypeError):
+ dict(**invalid)
+ with self.assertRaises(TypeError):
+ {}.update(**invalid)
def test_constructor(self):
# calling built-in types without argument must return empty
Modified: python/branches/py3k-cdecimal/Lib/test/test_nntplib.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_nntplib.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_nntplib.py Thu Nov 18 16:28:34 2010
@@ -112,9 +112,13 @@
def test_xover(self):
resp, count, first, last, name = self.server.group(self.GROUP_NAME)
- resp, lines = self.server.xover(last, last)
+ resp, lines = self.server.xover(last - 5, last)
+ if len(lines) == 0:
+ self.skipTest("no articles retrieved")
+ # The 'last' article is not necessarily part of the output (cancelled?)
art_num, art_dict = lines[0]
- self.assertEqual(art_num, last)
+ self.assertGreaterEqual(art_num, last - 5)
+ self.assertLessEqual(art_num, last)
self._check_art_dict(art_dict)
def test_over(self):
@@ -127,7 +131,9 @@
# The "start-end" article range form
resp, lines = self.server.over((start, last))
art_num, art_dict = lines[-1]
- self.assertEqual(art_num, last)
+ # The 'last' article is not necessarily part of the output (cancelled?)
+ self.assertGreaterEqual(art_num, start)
+ self.assertLessEqual(art_num, last)
self._check_art_dict(art_dict)
# XXX The "message_id" form is unsupported by gmane
# 503 Overview by message-ID unsupported
@@ -149,15 +155,26 @@
def test_article_head_body(self):
resp, count, first, last, name = self.server.group(self.GROUP_NAME)
- resp, head = self.server.head(last)
+ # Try to find an available article
+ for art_num in (last, first, last - 1):
+ try:
+ resp, head = self.server.head(art_num)
+ except nntplib.NNTPTemporaryError as e:
+ if not e.response.startswith("423 "):
+ raise
+ # "423 No such article" => choose another one
+ continue
+ break
+ else:
+ self.skipTest("could not find a suitable article number")
self.assertTrue(resp.startswith("221 "), resp)
- self.check_article_resp(resp, head, last)
- resp, body = self.server.body(last)
+ self.check_article_resp(resp, head, art_num)
+ resp, body = self.server.body(art_num)
self.assertTrue(resp.startswith("222 "), resp)
- self.check_article_resp(resp, body, last)
- resp, article = self.server.article(last)
+ self.check_article_resp(resp, body, art_num)
+ resp, article = self.server.article(art_num)
self.assertTrue(resp.startswith("220 "), resp)
- self.check_article_resp(resp, article, last)
+ self.check_article_resp(resp, article, art_num)
self.assertEqual(article.lines, head.lines + [b''] + body.lines)
def test_capabilities(self):
Modified: python/branches/py3k-cdecimal/Lib/test/test_pydoc.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_pydoc.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_pydoc.py Thu Nov 18 16:28:34 2010
@@ -22,9 +22,6 @@
expected_text_pattern = """
NAME
test.pydoc_mod - This is a test module for test_pydoc
-
-FILE
- %s
%s
CLASSES
builtins.object
@@ -72,9 +69,7 @@
nodoc_func()
DATA
- __author__ = 'Benjamin Peterson'
- __credits__ = 'Nobody'
- __version__ = '1.2.3.4'
+ __xyz__ = 'X, Y and Z'
VERSION
1.2.3.4
@@ -84,6 +79,9 @@
CREDITS
Nobody
+
+FILE
+ %s
""".strip()
expected_html_pattern = """
@@ -167,9 +165,7 @@
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
\x20\x20\x20\x20
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
-<td width="100%%"><strong>__author__</strong> = 'Benjamin Peterson'<br>
-<strong>__credits__</strong> = 'Nobody'<br>
-<strong>__version__</strong> = '1.2.3.4'</td></tr></table><p>
+<td width="100%%"><strong>__xyz__</strong> = 'X, Y and Z'</td></tr></table><p>
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom> <br>
@@ -259,7 +255,7 @@
def test_text_doc(self):
result, doc_loc = get_pydoc_text(pydoc_mod)
expected_text = expected_text_pattern % \
- (inspect.getabsfile(pydoc_mod), doc_loc)
+ (doc_loc, inspect.getabsfile(pydoc_mod))
if result != expected_text:
print_diffs(expected_text, result)
self.fail("outputs are not equal, see diff above")
Modified: python/branches/py3k-cdecimal/Lib/test/test_ssl.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_ssl.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_ssl.py Thu Nov 18 16:28:34 2010
@@ -412,6 +412,12 @@
'cache_full': 0,
})
+ def test_set_default_verify_paths(self):
+ # There's not much we can do to test that it acts as expected,
+ # so just check it doesn't crash or raise an exception.
+ ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ ctx.set_default_verify_paths()
+
class NetworkedTests(unittest.TestCase):
Modified: python/branches/py3k-cdecimal/Lib/test/test_xmlrpc.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_xmlrpc.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_xmlrpc.py Thu Nov 18 16:28:34 2010
@@ -149,6 +149,31 @@
('host.tld',
[('Authorization', 'Basic dXNlcg==')], {}))
+ def test_ssl_presence(self):
+ #Check for ssl support
+ have_ssl = False
+ if hasattr(socket, 'ssl'):
+ have_ssl = True
+ else:
+ try:
+ import ssl
+ except:
+ pass
+ else:
+ have_ssl = True
+ try:
+ xmlrpc.client.ServerProxy('https://localhost:9999').bad_function()
+ except:
+ exc = sys.exc_info()
+ if exc[0] == socket.error:
+ self.assertTrue(have_ssl,
+ "No SSL support, but xmlrpclib reports supported.")
+ elif exc[0] == NotImplementedError and str(exc[1]) == \
+ "your version of http.client doesn't support HTTPS":
+ self.assertFalse(have_ssl,
+ "SSL supported, but xmlrpclib reports not.")
+ else:
+ self.fail("Unable to determine status of SSL check.")
class HelperTestCase(unittest.TestCase):
Modified: python/branches/py3k-cdecimal/Lib/test/test_zipfile.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/test/test_zipfile.py (original)
+++ python/branches/py3k-cdecimal/Lib/test/test_zipfile.py Thu Nov 18 16:28:34 2010
@@ -112,20 +112,20 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r", compression) as zipfp:
zipdata1 = []
- zipopen1 = zipfp.open(TESTFN)
- while True:
- read_data = zipopen1.read(256)
- if not read_data:
- break
- zipdata1.append(read_data)
+ with zipfp.open(TESTFN) as zipopen1:
+ while True:
+ read_data = zipopen1.read(256)
+ if not read_data:
+ break
+ zipdata1.append(read_data)
zipdata2 = []
- zipopen2 = zipfp.open("another.name")
- while True:
- read_data = zipopen2.read(256)
- if not read_data:
- break
- zipdata2.append(read_data)
+ with zipfp.open("another.name") as zipopen2:
+ while True:
+ read_data = zipopen2.read(256)
+ if not read_data:
+ break
+ zipdata2.append(read_data)
self.assertEqual(b''.join(zipdata1), self.data)
self.assertEqual(b''.join(zipdata2), self.data)
@@ -146,7 +146,8 @@
infos = zipfp.infolist()
data = b""
for info in infos:
- data += zipfp.open(info).read()
+ with zipfp.open(info) as zipopen:
+ data += zipopen.read()
self.assertTrue(data == b"foobar" or data == b"barfoo")
data = b""
for info in infos:
@@ -159,12 +160,12 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r", compression) as zipfp:
zipdata1 = []
- zipopen1 = zipfp.open(TESTFN)
- while True:
- read_data = zipopen1.read(randint(1, 1024))
- if not read_data:
- break
- zipdata1.append(read_data)
+ with zipfp.open(TESTFN) as zipopen1:
+ while True:
+ read_data = zipopen1.read(randint(1, 1024))
+ if not read_data:
+ break
+ zipdata1.append(read_data)
self.assertEqual(b''.join(zipdata1), self.data)
if not isinstance(f, str):
@@ -184,9 +185,9 @@
data2 = b''
zipfp = zipfile.ZipFile(f, 'r')
- zipopen = zipfp.open(TESTFN, 'rU')
- for line in zipopen:
- data2 += line
+ with zipfp.open(TESTFN, 'rU') as zipopen:
+ for line in zipopen:
+ data2 += line
zipfp.close()
self.assertEqual(data, data2.replace(b'\n', b'\r\n'))
@@ -196,19 +197,18 @@
# Read the ZIP archive
zipfp = zipfile.ZipFile(f, "r")
- zipopen = zipfp.open(TESTFN)
+ with zipfp.open(TESTFN) as zipopen:
+ data = b''
+ while True:
+ read = zipopen.readline()
+ if not read:
+ break
+ data += read
- data = b''
- while True:
- read = zipopen.readline()
- if not read:
- break
- data += read
-
- read = zipopen.read(100)
- if not read:
- break
- data += read
+ read = zipopen.read(100)
+ if not read:
+ break
+ data += read
self.assertEqual(data, self.data)
zipfp.close()
@@ -220,10 +220,10 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r") as zipfp:
- zipopen = zipfp.open(TESTFN)
- for line in self.line_gen:
- linedata = zipopen.readline()
- self.assertEqual(linedata, line + '\n')
+ with zipfp.open(TESTFN) as zipopen:
+ for line in self.line_gen:
+ linedata = zipopen.readline()
+ self.assertEqual(linedata, line + '\n')
if not isinstance(f, str):
f.close()
@@ -232,7 +232,8 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r") as zipfp:
- ziplines = zipfp.open(TESTFN).readlines()
+ with zipfp.open(TESTFN) as zipopen:
+ ziplines = zipopen.readlines()
for line, zipline in zip(self.line_gen, ziplines):
self.assertEqual(zipline, line + '\n')
if not isinstance(f, str):
@@ -243,8 +244,9 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r") as zipfp:
- for line, zipline in zip(self.line_gen, zipfp.open(TESTFN)):
- self.assertEqual(zipline, line + '\n')
+ with zipfp.open(TESTFN) as zipopen:
+ for line, zipline in zip(self.line_gen, zipopen):
+ self.assertEqual(zipline, line + '\n')
if not isinstance(f, str):
f.close()
@@ -311,9 +313,9 @@
# Get an open object for strfile
with zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_DEFLATED) as zipfp:
- openobj = zipfp.open("strfile")
- self.assertEqual(openobj.read(1), b'1')
- self.assertEqual(openobj.read(1), b'2')
+ with zipfp.open("strfile") as openobj:
+ self.assertEqual(openobj.read(1), b'1')
+ self.assertEqual(openobj.read(1), b'2')
def test_absolute_arcnames(self):
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
@@ -352,7 +354,8 @@
produces the expected result."""
with zipfile.ZipFile(TESTFN2, "w") as zipfp:
zipfp.write(TESTFN)
- self.assertEqual(zipfp.read(TESTFN), open(TESTFN, "rb").read())
+ with open(TESTFN, "rb") as f:
+ self.assertEqual(zipfp.read(TESTFN), f.read())
@skipUnless(zlib, "requires zlib")
def test_per_file_compression(self):
@@ -394,7 +397,8 @@
self.assertEqual(writtenfile, correctfile)
# make sure correct data is in correct file
- self.assertEqual(fdata.encode(), open(writtenfile, "rb").read())
+ with open(writtenfile, "rb") as f:
+ self.assertEqual(fdata.encode(), f.read())
os.remove(writtenfile)
@@ -414,7 +418,8 @@
else:
outfile = os.path.join(os.getcwd(), fpath)
- self.assertEqual(fdata.encode(), open(outfile, "rb").read())
+ with open(outfile, "rb") as f:
+ self.assertEqual(fdata.encode(), f.read())
os.remove(outfile)
@@ -674,7 +679,8 @@
def test_write_non_pyfile(self):
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
- open(TESTFN, 'w').write('most definitely not a python file')
+ with open(TESTFN, 'w') as f:
+ f.write('most definitely not a python file')
self.assertRaises(RuntimeError, zipfp.writepy, TESTFN)
os.remove(TESTFN)
@@ -825,7 +831,8 @@
self.assertRaises(RuntimeError, zipf.open, "foo.txt")
self.assertRaises(RuntimeError, zipf.testzip)
self.assertRaises(RuntimeError, zipf.writestr, "bogus.txt", "bogus")
- open(TESTFN, 'w').write('zipfile test data')
+ with open(TESTFN, 'w') as f:
+ f.write('zipfile test data')
self.assertRaises(RuntimeError, zipf.write, TESTFN)
def test_bad_constructor_mode(self):
@@ -848,11 +855,11 @@
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
# read the data to make sure the file is there
- f = zipf.open("foo.txt")
- for i in range(FIXEDTEST_SIZE):
- self.assertEqual(f.read(0), b'')
+ with zipf.open("foo.txt") as f:
+ for i in range(FIXEDTEST_SIZE):
+ self.assertEqual(f.read(0), b'')
- self.assertEqual(f.read(), b"O, for a Muse of Fire!")
+ self.assertEqual(f.read(), b"O, for a Muse of Fire!")
def test_open_non_existent_item(self):
"""Check that attempting to call open() for an item that doesn't
@@ -1115,20 +1122,20 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r", compression) as zipfp:
zipdata1 = []
- zipopen1 = zipfp.open(TESTFN)
- while True:
- read_data = zipopen1.read(256)
- if not read_data:
- break
- zipdata1.append(read_data)
+ with zipfp.open(TESTFN) as zipopen1:
+ while True:
+ read_data = zipopen1.read(256)
+ if not read_data:
+ break
+ zipdata1.append(read_data)
zipdata2 = []
- zipopen2 = zipfp.open("another.name")
- while True:
- read_data = zipopen2.read(256)
- if not read_data:
- break
- zipdata2.append(read_data)
+ with zipfp.open("another.name") as zipopen2:
+ while True:
+ read_data = zipopen2.read(256)
+ if not read_data:
+ break
+ zipdata2.append(read_data)
testdata1 = b''.join(zipdata1)
self.assertEqual(len(testdata1), len(self.data))
@@ -1155,12 +1162,12 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r", compression) as zipfp:
zipdata1 = []
- zipopen1 = zipfp.open(TESTFN)
- while True:
- read_data = zipopen1.read(randint(1, 1024))
- if not read_data:
- break
- zipdata1.append(read_data)
+ with zipfp.open(TESTFN) as zipopen1:
+ while True:
+ read_data = zipopen1.read(randint(1, 1024))
+ if not read_data:
+ break
+ zipdata1.append(read_data)
testdata = b''.join(zipdata1)
self.assertEqual(len(testdata), len(self.data))
@@ -1190,24 +1197,22 @@
# Verify that (when the ZipFile is in control of creating file objects)
# multiple open() calls can be made without interfering with each other.
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
- zopen1 = zipf.open('ones')
- zopen2 = zipf.open('ones')
- data1 = zopen1.read(500)
- data2 = zopen2.read(500)
- data1 += zopen1.read(500)
- data2 += zopen2.read(500)
+ with zipf.open('ones') as zopen1, zipf.open('ones') as zopen2:
+ data1 = zopen1.read(500)
+ data2 = zopen2.read(500)
+ data1 += zopen1.read(500)
+ data2 += zopen2.read(500)
self.assertEqual(data1, data2)
def test_different_file(self):
# Verify that (when the ZipFile is in control of creating file objects)
# multiple open() calls can be made without interfering with each other.
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
- zopen1 = zipf.open('ones')
- zopen2 = zipf.open('twos')
- data1 = zopen1.read(500)
- data2 = zopen2.read(500)
- data1 += zopen1.read(500)
- data2 += zopen2.read(500)
+ with zipf.open('ones') as zopen1, zipf.open('twos') as zopen2:
+ data1 = zopen1.read(500)
+ data2 = zopen2.read(500)
+ data1 += zopen1.read(500)
+ data2 += zopen2.read(500)
self.assertEqual(data1, b'1'*FIXEDTEST_SIZE)
self.assertEqual(data2, b'2'*FIXEDTEST_SIZE)
@@ -1215,12 +1220,11 @@
# Verify that (when the ZipFile is in control of creating file objects)
# multiple open() calls can be made without interfering with each other.
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
- zopen1 = zipf.open('ones')
- data1 = zopen1.read(500)
- zopen2 = zipf.open('twos')
- data2 = zopen2.read(500)
- data1 += zopen1.read(500)
- data2 += zopen2.read(500)
+ with zipf.open('ones') as zopen1, zipf.open('twos') as zopen2:
+ data1 = zopen1.read(500)
+ data2 = zopen2.read(500)
+ data1 += zopen1.read(500)
+ data2 += zopen2.read(500)
self.assertEqual(data1, b'1'*FIXEDTEST_SIZE)
self.assertEqual(data2, b'2'*FIXEDTEST_SIZE)
@@ -1294,25 +1298,23 @@
self.make_test_archive(f, compression)
# Read the ZIP archive
- zipfp = zipfile.ZipFile(f, "r")
- for sep, fn in self.arcfiles.items():
- zipopen = zipfp.open(fn, "rU")
- data = b''
- while True:
- read = zipopen.readline()
- if not read:
- break
- data += read
-
- read = zipopen.read(5)
- if not read:
- break
- data += read
+ with zipfile.ZipFile(f, "r") as zipfp:
+ for sep, fn in self.arcfiles.items():
+ with zipfp.open(fn, "rU") as zipopen:
+ data = b''
+ while True:
+ read = zipopen.readline()
+ if not read:
+ break
+ data += read
+
+ read = zipopen.read(5)
+ if not read:
+ break
+ data += read
- zipopen.close()
self.assertEqual(data, self.arcdata['\n'])
- zipfp.close()
if not isinstance(f, str):
f.close()
Modified: python/branches/py3k-cdecimal/Lib/threading.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/threading.py (original)
+++ python/branches/py3k-cdecimal/Lib/threading.py Thu Nov 18 16:28:34 2010
@@ -254,6 +254,32 @@
finally:
self._acquire_restore(saved_state)
+ def wait_for(self, predicate, timeout=None):
+ endtime = None
+ waittime = timeout
+ result = predicate()
+ while not result:
+ if waittime is not None:
+ if endtime is None:
+ endtime = _time() + waittime
+ else:
+ waittime = endtime - _time()
+ if waittime <= 0:
+ if __debug__:
+ self._note("%s.wait_for(%r, %r): Timed out.",
+ self, predicate, timeout)
+ break
+ if __debug__:
+ self._note("%s.wait_for(%r, %r): Waiting with timeout=%s.",
+ self, predicate, timeout, waittime)
+ self.wait(waittime)
+ result = predicate()
+ else:
+ if __debug__:
+ self._note("%s.wait_for(%r, %r): Success.",
+ self, predicate, timeout)
+ return result
+
def notify(self, n=1):
if not self._is_owned():
raise RuntimeError("cannot notify on un-acquired lock")
@@ -482,13 +508,12 @@
# Wait in the barrier until we are relased. Raise an exception
# if the barrier is reset or broken.
def _wait(self, timeout):
- while self._state == 0:
- if self._cond.wait(timeout) is False:
- #timed out. Break the barrier
- self._break()
- raise BrokenBarrierError
- if self._state < 0:
- raise BrokenBarrierError
+ if not self._cond.wait_for(lambda : self._state != 0, timeout):
+ #timed out. Break the barrier
+ self._break()
+ raise BrokenBarrierError
+ if self._state < 0:
+ raise BrokenBarrierError
assert self._state == 1
# If we are the last thread to exit the barrier, signal any threads
Modified: python/branches/py3k-cdecimal/Lib/unittest/runner.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/unittest/runner.py (original)
+++ python/branches/py3k-cdecimal/Lib/unittest/runner.py Thu Nov 18 16:28:34 2010
@@ -168,9 +168,10 @@
results = map(len, (result.expectedFailures,
result.unexpectedSuccesses,
result.skipped))
- expectedFails, unexpectedSuccesses, skipped = results
except AttributeError:
pass
+ else:
+ expectedFails, unexpectedSuccesses, skipped = results
infos = []
if not result.wasSuccessful():
Modified: python/branches/py3k-cdecimal/Lib/xmlrpc/client.py
==============================================================================
--- python/branches/py3k-cdecimal/Lib/xmlrpc/client.py (original)
+++ python/branches/py3k-cdecimal/Lib/xmlrpc/client.py Thu Nov 18 16:28:34 2010
@@ -1330,7 +1330,7 @@
if self._connection and host == self._connection[0]:
return self._connection[1]
- if not hasattr(socket, "ssl"):
+ if not hasattr(http.client, "ssl"):
raise NotImplementedError(
"your version of http.client doesn't support HTTPS")
# create a HTTPS connection object from a host descriptor
Modified: python/branches/py3k-cdecimal/Misc/NEWS
==============================================================================
--- python/branches/py3k-cdecimal/Misc/NEWS (original)
+++ python/branches/py3k-cdecimal/Misc/NEWS Thu Nov 18 16:28:34 2010
@@ -10,15 +10,38 @@
Core and Builtins
-----------------
+- Issue #9518: Extend the PyModuleDef_HEAD_INIT macro to explicitly
+ zero-initialize all fields, fixing compiler warnings seen when building
+ extension modules with gcc with "-Wmissing-field-initializers" (implied
+ by "-W")
+
Library
-------
+- Issue #10446: Module documentation generated by pydoc now links to a
+ version-specific online reference manual.
+
+- Make the 'No module named' exception message from importlib consistent.
+
+- Issue #10443: Add the SSLContext.set_default_verify_paths() method.
+
- Issue #10440: Support RUSAGE_THREAD as a constant in the resource module.
Patch by Robert Collins.
- Issue #10429: IMAP.starttls() stored the capabilities as bytes objects,
rather than strings.
+C-API
+-----
+
+- Loosen PyArg_ValidateKeywordArguments to allow dict subclasses.
+
+Tests
+-----
+
+- Issue #8886: Use context managers throughout test_zipfile. Patch by
+ Eric Carstensen.
+
What's New in Python 3.2 Alpha 4?
=================================
@@ -81,6 +104,9 @@
Library
-------
+- Issue #10356: hash(Decimal("sNaN")) now raises ValueError instead of
+ TypeError.
+
- Issue #10356: Decimal.__hash__(-1) should return -2.
- Issue #1553375: logging: Added stack_info kwarg to display stack information.
Modified: python/branches/py3k-cdecimal/Modules/_ssl.c
==============================================================================
--- python/branches/py3k-cdecimal/Modules/_ssl.c (original)
+++ python/branches/py3k-cdecimal/Modules/_ssl.c Thu Nov 18 16:28:34 2010
@@ -1783,6 +1783,16 @@
return NULL;
}
+static PyObject *
+set_default_verify_paths(PySSLContext *self, PyObject *unused)
+{
+ if (!SSL_CTX_set_default_verify_paths(self->ctx)) {
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
static PyGetSetDef context_getsetlist[] = {
{"options", (getter) get_options,
(setter) set_options, NULL},
@@ -1802,6 +1812,8 @@
METH_VARARGS | METH_KEYWORDS, NULL},
{"session_stats", (PyCFunction) session_stats,
METH_NOARGS, NULL},
+ {"set_default_verify_paths", (PyCFunction) set_default_verify_paths,
+ METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};
Modified: python/branches/py3k-cdecimal/Objects/dictobject.c
==============================================================================
--- python/branches/py3k-cdecimal/Objects/dictobject.c (original)
+++ python/branches/py3k-cdecimal/Objects/dictobject.c Thu Nov 18 16:28:34 2010
@@ -454,7 +454,7 @@
{
Py_ssize_t pos = 0;
PyObject *key, *value;
- assert(PyDict_CheckExact(dict));
+ assert(PyDict_Check(dict));
/* Shortcut */
if (((PyDictObject *)dict)->ma_lookup == lookdict_unicode)
return 1;
Modified: python/branches/py3k-cdecimal/Python/getargs.c
==============================================================================
--- python/branches/py3k-cdecimal/Python/getargs.c (original)
+++ python/branches/py3k-cdecimal/Python/getargs.c Thu Nov 18 16:28:34 2010
@@ -1394,7 +1394,7 @@
int
PyArg_ValidateKeywordArguments(PyObject *kwargs)
{
- if (!PyDict_CheckExact(kwargs)) {
+ if (!PyDict_Check(kwargs)) {
PyErr_BadInternalCall();
return 0;
}
More information about the Python-checkins
mailing list