[Python-checkins] r88675 - in python/branches/pep-3151: Doc/bugs.rst Doc/faq/general.rst Doc/howto/logging-cookbook.rst Doc/library/json.rst Doc/reference/executionmodel.rst Doc/using/unix.rst Doc/using/windows.rst Lib/collections/__init__.py Lib/lib2to3 Lib/lib2to3/patcomp.py Lib/lib2to3/pgen2/driver.py Lib/lib2to3/tests/test_parser.py Lib/logging/__init__.py Lib/ssl.py Lib/test/support.py Lib/test/test_collections.py Lib/test/test_logging.py Lib/test/test_os.py Lib/test/test_ssl.py Misc/NEWS Modules/posixmodule.c Objects/typeslots.inc

antoine.pitrou python-checkins at python.org
Mon Feb 28 19:08:11 CET 2011


Author: antoine.pitrou
Date: Mon Feb 28 19:08:07 2011
New Revision: 88675

Log:
Merged revisions 88633,88636,88639-88640,88643-88647,88650,88652-88654,88656,88658,88660,88663-88664,88668,88671 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r88633 | raymond.hettinger | 2011-02-26 07:53:58 +0100 (sam., 26 févr. 2011) | 1 line
  
  Add __bool__ method. Add tests. Fix-up broken test.
................
  r88636 | vinay.sajip | 2011-02-26 08:18:22 +0100 (sam., 26 févr. 2011) | 1 line
  
  test_logging: Changed TimedRotatingFileHandler tests to use UTC time rather than local time.
................
  r88639 | antoine.pitrou | 2011-02-26 09:45:20 +0100 (sam., 26 févr. 2011) | 4 lines
  
  Issue #11258: Speed up ctypes.util.find_library() under Linux a lot.  Patch
  by Jonas H.
................
  r88640 | antoine.pitrou | 2011-02-26 10:37:45 +0100 (sam., 26 févr. 2011) | 3 lines
  
  Revert r88639 (the optimization changes behaviour and breaks buildbots)
................
  r88643 | antoine.pitrou | 2011-02-26 14:38:35 +0100 (sam., 26 févr. 2011) | 3 lines
  
  Check error return from _parse_off_t(), and remove cruft from the 2->3 transition.
................
  r88644 | vinay.sajip | 2011-02-26 15:15:48 +0100 (sam., 26 févr. 2011) | 1 line
  
  Issue #11330: asctime format bug fixed.
................
  r88645 | vinay.sajip | 2011-02-26 15:24:29 +0100 (sam., 26 févr. 2011) | 1 line
  
  Issue #11331: fixed documentation in logging cookbook.
................
  r88646 | vinay.sajip | 2011-02-26 15:28:36 +0100 (sam., 26 févr. 2011) | 1 line
  
  Removed typo.
................
  r88647 | antoine.pitrou | 2011-02-26 15:29:24 +0100 (sam., 26 févr. 2011) | 3 lines
  
  Issue #11323: fix sendfile tests under 64-bit Solaris.
................
  r88650 | eric.araujo | 2011-02-26 15:57:23 +0100 (sam., 26 févr. 2011) | 2 lines
  
  Replace links to the old dev doc with links to the new devguide.
................
  r88652 | antoine.pitrou | 2011-02-26 16:58:05 +0100 (sam., 26 févr. 2011) | 4 lines
  
  Issue #9931: Fix hangs in GUI tests under Windows in certain conditions.
  Patch by Hirokazu Yamamoto.
................
  r88653 | vinay.sajip | 2011-02-26 17:00:04 +0100 (sam., 26 févr. 2011) | 1 line
  
  Issue #11330: Added regression test.
................
  r88654 | vinay.sajip | 2011-02-26 17:06:02 +0100 (sam., 26 févr. 2011) | 1 line
  
  Issue #11330: Updated tests for correct asctime handling.
................
  r88656 | antoine.pitrou | 2011-02-26 18:52:50 +0100 (sam., 26 févr. 2011) | 3 lines
  
  Make sendfile tests more robust
................
  r88658 | benjamin.peterson | 2011-02-26 22:32:16 +0100 (sam., 26 févr. 2011) | 1 line
  
  this isn't true anymore
................
  r88660 | benjamin.peterson | 2011-02-26 22:35:16 +0100 (sam., 26 févr. 2011) | 1 line
  
  revert accidental formatting change
................
  r88663 | benjamin.peterson | 2011-02-26 23:12:10 +0100 (sam., 26 févr. 2011) | 12 lines
  
  Merged revisions 88661 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
  
  ........
    r88661 | benjamin.peterson | 2011-02-26 16:06:24 -0600 (Sat, 26 Feb 2011) | 6 lines
    
    fix refactoring on formfeed characters #11250
    
    This is because text.splitlines() is not the same as
    list(StringIO.StringIO(text)).
  ........
................
  r88664 | antoine.pitrou | 2011-02-27 00:24:06 +0100 (dim., 27 févr. 2011) | 4 lines
  
  Issue #11326: Add the missing connect_ex() implementation for SSL sockets,
  and make it work for non-blocking connects.
................
  r88668 | benjamin.peterson | 2011-02-27 16:06:44 +0100 (dim., 27 févr. 2011) | 1 line
  
  make this a link #11345
................
  r88671 | antoine.pitrou | 2011-02-27 16:44:12 +0100 (dim., 27 févr. 2011) | 3 lines
  
  Follow up to r88664: non-blocking connect-ex() can return EWOULDBLOCK under Windows
................


Modified:
   python/branches/pep-3151/   (props changed)
   python/branches/pep-3151/Doc/bugs.rst
   python/branches/pep-3151/Doc/faq/general.rst
   python/branches/pep-3151/Doc/howto/logging-cookbook.rst
   python/branches/pep-3151/Doc/library/json.rst
   python/branches/pep-3151/Doc/reference/executionmodel.rst
   python/branches/pep-3151/Doc/using/unix.rst
   python/branches/pep-3151/Doc/using/windows.rst
   python/branches/pep-3151/Lib/collections/__init__.py
   python/branches/pep-3151/Lib/lib2to3/   (props changed)
   python/branches/pep-3151/Lib/lib2to3/patcomp.py
   python/branches/pep-3151/Lib/lib2to3/pgen2/driver.py
   python/branches/pep-3151/Lib/lib2to3/tests/test_parser.py
   python/branches/pep-3151/Lib/logging/__init__.py
   python/branches/pep-3151/Lib/ssl.py
   python/branches/pep-3151/Lib/test/support.py
   python/branches/pep-3151/Lib/test/test_collections.py
   python/branches/pep-3151/Lib/test/test_logging.py
   python/branches/pep-3151/Lib/test/test_os.py
   python/branches/pep-3151/Lib/test/test_ssl.py
   python/branches/pep-3151/Misc/NEWS
   python/branches/pep-3151/Modules/posixmodule.c
   python/branches/pep-3151/Objects/typeslots.inc

Modified: python/branches/pep-3151/Doc/bugs.rst
==============================================================================
--- python/branches/pep-3151/Doc/bugs.rst	(original)
+++ python/branches/pep-3151/Doc/bugs.rst	Mon Feb 28 19:08:07 2011
@@ -57,12 +57,14 @@
 
 Each bug report will be assigned to a developer who will determine what needs to
 be done to correct the problem.  You will receive an update each time action is
-taken on the bug.  See http://www.python.org/dev/workflow/ for a detailed
-description of the issue workflow.
+taken on the bug.
 
 
 .. seealso::
 
+   `Python Developer's Guide <http://docs.python.org/devguide/>`_
+      Detailed description of the issue workflow and developers tools.
+
    `How to Report Bugs Effectively <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>`_
       Article which goes into some detail about how to create a useful bug report.
       This describes what kind of information is useful and why it is useful.

Modified: python/branches/pep-3151/Doc/faq/general.rst
==============================================================================
--- python/branches/pep-3151/Doc/faq/general.rst	(original)
+++ python/branches/pep-3151/Doc/faq/general.rst	Mon Feb 28 19:08:07 2011
@@ -166,7 +166,7 @@
 
 .. XXX update link once the dev faq is relocated
 
-Consult the `Developer FAQ <http://www.python.org/dev/faq/>`__ for more
+Consult the `Developer FAQ <http://docs.python.org/devguide/faq>`__ for more
 information on getting the source code and compiling it.
 
 
@@ -224,7 +224,7 @@
 .. XXX update link once the dev faq is relocated
 
 You can also access the development version of Python through Subversion.  See
-http://www.python.org/dev/faq/ for details.
+http://docs.python.org/devguide/faq for details.
 
 
 How do I submit bug reports and patches for Python?
@@ -242,7 +242,7 @@
 .. XXX adapt link to dev guide
 
 For more information on how Python is developed, consult `the Python Developer's
-Guide <http://python.org/dev/>`_.
+Guide <http://docs.python.org/devguide/>`_.
 
 
 Are there any published articles about Python that I can reference?

Modified: python/branches/pep-3151/Doc/howto/logging-cookbook.rst
==============================================================================
--- python/branches/pep-3151/Doc/howto/logging-cookbook.rst	(original)
+++ python/branches/pep-3151/Doc/howto/logging-cookbook.rst	Mon Feb 28 19:08:07 2011
@@ -630,8 +630,6 @@
 
     if __name__ == '__main__':
        levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL)
-       a1 = logging.LoggerAdapter(logging.getLogger('a.b.c'),
-                                  { 'ip' : '123.231.231.123', 'user' : 'sheila' })
        logging.basicConfig(level=logging.DEBUG,
                            format='%(asctime)-15s %(name)-5s %(levelname)-8s IP: %(ip)-15s User: %(user)-8s %(message)s')
        a1 = logging.getLogger('a.b.c')

Modified: python/branches/pep-3151/Doc/library/json.rst
==============================================================================
--- python/branches/pep-3151/Doc/library/json.rst	(original)
+++ python/branches/pep-3151/Doc/library/json.rst	Mon Feb 28 19:08:07 2011
@@ -6,7 +6,7 @@
 .. moduleauthor:: Bob Ippolito <bob at redivi.com>
 .. sectionauthor:: Bob Ippolito <bob at redivi.com>
 
-JSON (JavaScript Object Notation) <http://json.org> is a subset of JavaScript
+`JSON (JavaScript Object Notation) <http://json.org>`_ is a subset of JavaScript
 syntax (ECMA-262 3rd edition) used as a lightweight data interchange format.
 
 :mod:`json` exposes an API familiar to users of the standard library

Modified: python/branches/pep-3151/Doc/reference/executionmodel.rst
==============================================================================
--- python/branches/pep-3151/Doc/reference/executionmodel.rst	(original)
+++ python/branches/pep-3151/Doc/reference/executionmodel.rst	Mon Feb 28 19:08:07 2011
@@ -94,9 +94,7 @@
 at the module level.
 
 A target occurring in a :keyword:`del` statement is also considered bound for
-this purpose (though the actual semantics are to unbind the name).  It is
-illegal to unbind a name that is referenced by an enclosing scope; the compiler
-will report a :exc:`SyntaxError`.
+this purpose (though the actual semantics are to unbind the name).
 
 Each assignment or import statement occurs within a block defined by a class or
 function definition or at the module level (the top-level code block).

Modified: python/branches/pep-3151/Doc/using/unix.rst
==============================================================================
--- python/branches/pep-3151/Doc/using/unix.rst	(original)
+++ python/branches/pep-3151/Doc/using/unix.rst	Mon Feb 28 19:08:07 2011
@@ -66,7 +66,7 @@
 If you want to compile CPython yourself, first thing you should do is get the
 `source <http://python.org/download/source/>`_. You can download either the
 latest release's source or just grab a fresh `checkout
-<http://www.python.org/dev/faq/#how-do-i-get-a-checkout-of-the-repository-read-only-and-read-write>`_.
+<http://docs.python.org/devguide/setup#checking-out-the-code>`_.
 
 The build process consists the usual ::
 

Modified: python/branches/pep-3151/Doc/using/windows.rst
==============================================================================
--- python/branches/pep-3151/Doc/using/windows.rst	(original)
+++ python/branches/pep-3151/Doc/using/windows.rst	Mon Feb 28 19:08:07 2011
@@ -290,7 +290,7 @@
 If you want to compile CPython yourself, first thing you should do is get the
 `source <http://python.org/download/source/>`_. You can download either the
 latest release's source or just grab a fresh `checkout
-<http://www.python.org/dev/faq/#how-do-i-get-a-checkout-of-the-repository-read-only-and-read-write>`_.
+<http://docs.python.org/devguide/setup#checking-out-the-code>`_.
 
 For Microsoft Visual C++, which is the compiler with which official Python
 releases are built, the source tree contains solutions/project files.  View the

Modified: python/branches/pep-3151/Lib/collections/__init__.py
==============================================================================
--- python/branches/pep-3151/Lib/collections/__init__.py	(original)
+++ python/branches/pep-3151/Lib/collections/__init__.py	Mon Feb 28 19:08:07 2011
@@ -679,6 +679,9 @@
     def __contains__(self, key):
         return any(key in m for m in self.maps)
 
+    def __bool__(self):
+        return any(self.maps)
+
     @_recursive_repr()
     def __repr__(self):
         return '{0.__class__.__name__}({1})'.format(

Modified: python/branches/pep-3151/Lib/lib2to3/patcomp.py
==============================================================================
--- python/branches/pep-3151/Lib/lib2to3/patcomp.py	(original)
+++ python/branches/pep-3151/Lib/lib2to3/patcomp.py	Mon Feb 28 19:08:07 2011
@@ -11,6 +11,7 @@
 __author__ = "Guido van Rossum <guido at python.org>"
 
 # Python imports
+import io
 import os
 
 # Fairly local imports
@@ -32,7 +33,7 @@
 def tokenize_wrapper(input):
     """Tokenizes a string suppressing significant whitespace."""
     skip = set((token.NEWLINE, token.INDENT, token.DEDENT))
-    tokens = tokenize.generate_tokens(driver.generate_lines(input).__next__)
+    tokens = tokenize.generate_tokens(io.StringIO(input).readline)
     for quintuple in tokens:
         type, value, start, end, line_text = quintuple
         if type not in skip:

Modified: python/branches/pep-3151/Lib/lib2to3/pgen2/driver.py
==============================================================================
--- python/branches/pep-3151/Lib/lib2to3/pgen2/driver.py	(original)
+++ python/branches/pep-3151/Lib/lib2to3/pgen2/driver.py	Mon Feb 28 19:08:07 2011
@@ -17,6 +17,7 @@
 
 # Python imports
 import codecs
+import io
 import os
 import logging
 import sys
@@ -101,18 +102,10 @@
 
     def parse_string(self, text, debug=False):
         """Parse a string and return the syntax tree."""
-        tokens = tokenize.generate_tokens(generate_lines(text).__next__)
+        tokens = tokenize.generate_tokens(io.StringIO(text).readline)
         return self.parse_tokens(tokens, debug)
 
 
-def generate_lines(text):
-    """Generator that behaves like readline without using StringIO."""
-    for line in text.splitlines(True):
-        yield line
-    while True:
-        yield ""
-
-
 def load_grammar(gt="Grammar.txt", gp=None,
                  save=True, force=False, logger=None):
     """Load the grammar (maybe from a pickle)."""

Modified: python/branches/pep-3151/Lib/lib2to3/tests/test_parser.py
==============================================================================
--- python/branches/pep-3151/Lib/lib2to3/tests/test_parser.py	(original)
+++ python/branches/pep-3151/Lib/lib2to3/tests/test_parser.py	Mon Feb 28 19:08:07 2011
@@ -18,6 +18,16 @@
 # Local imports
 from lib2to3.pgen2 import tokenize
 from ..pgen2.parse import ParseError
+from lib2to3.pygram import python_symbols as syms
+
+
+class TestDriver(support.TestCase):
+
+    def test_formfeed(self):
+        s = """print 1\n\x0Cprint 2\n"""
+        t = driver.parse_string(s)
+        self.assertEqual(t.children[0].children[0].type, syms.print_stmt)
+        self.assertEqual(t.children[1].children[0].type, syms.print_stmt)
 
 
 class GrammarTest(support.TestCase):

Modified: python/branches/pep-3151/Lib/logging/__init__.py
==============================================================================
--- python/branches/pep-3151/Lib/logging/__init__.py	(original)
+++ python/branches/pep-3151/Lib/logging/__init__.py	Mon Feb 28 19:08:07 2011
@@ -360,12 +360,13 @@
 
     default_format = '%(message)s'
     asctime_format = '%(asctime)s'
+    asctime_search = '%(asctime)'
 
     def __init__(self, fmt):
         self._fmt = fmt or self.default_format
 
     def usesTime(self):
-        return self._fmt.find(self.asctime_format) >= 0
+        return self._fmt.find(self.asctime_search) >= 0
 
     def format(self, record):
         return self._fmt % record.__dict__
@@ -373,6 +374,7 @@
 class StrFormatStyle(PercentStyle):
     default_format = '{message}'
     asctime_format = '{asctime}'
+    asctime_search = '{asctime'
 
     def format(self, record):
         return self._fmt.format(**record.__dict__)
@@ -381,6 +383,7 @@
 class StringTemplateStyle(PercentStyle):
     default_format = '${message}'
     asctime_format = '${asctime}'
+    asctime_search = '${asctime}'
 
     def __init__(self, fmt):
         self._fmt = fmt or self.default_format

Modified: python/branches/pep-3151/Lib/ssl.py
==============================================================================
--- python/branches/pep-3151/Lib/ssl.py	(original)
+++ python/branches/pep-3151/Lib/ssl.py	Mon Feb 28 19:08:07 2011
@@ -237,6 +237,7 @@
 
         self._closed = False
         self._sslobj = None
+        self._connected = connected
         if connected:
             # create the SSL object
             try:
@@ -430,23 +431,36 @@
         finally:
             self.settimeout(timeout)
 
-    def connect(self, addr):
-        """Connects to remote ADDR, and then wraps the connection in
-        an SSL channel."""
+    def _real_connect(self, addr, return_errno):
         if self.server_side:
             raise ValueError("can't connect in server-side mode")
         # Here we assume that the socket is client-side, and not
         # connected at the time of the call.  We connect it, then wrap it.
-        if self._sslobj:
+        if self._connected:
             raise ValueError("attempt to connect already-connected SSLSocket!")
-        socket.connect(self, addr)
         self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
         try:
+            socket.connect(self, addr)
             if self.do_handshake_on_connect:
                 self.do_handshake()
-        except:
-            self._sslobj = None
-            raise
+        except socket_error as e:
+            if return_errno:
+                return e.errno
+            else:
+                self._sslobj = None
+                raise e
+        self._connected = True
+        return 0
+
+    def connect(self, addr):
+        """Connects to remote ADDR, and then wraps the connection in
+        an SSL channel."""
+        self._real_connect(addr, False)
+
+    def connect_ex(self, addr):
+        """Connects to remote ADDR, and then wraps the connection in
+        an SSL channel."""
+        return self._real_connect(addr, True)
 
     def accept(self):
         """Accepts a new connection from a remote client, and returns

Modified: python/branches/pep-3151/Lib/test/support.py
==============================================================================
--- python/branches/pep-3151/Lib/test/support.py	(original)
+++ python/branches/pep-3151/Lib/test/support.py	Mon Feb 28 19:08:07 2011
@@ -233,6 +233,36 @@
         unlink(imp.cache_from_source(source, debug_override=True))
         unlink(imp.cache_from_source(source, debug_override=False))
 
+# On some platforms, should not run gui test even if it is allowed
+# in `use_resources'.
+if sys.platform.startswith('win'):
+    import ctypes
+    import ctypes.wintypes
+    def _is_gui_available():
+        UOI_FLAGS = 1
+        WSF_VISIBLE = 0x0001
+        class USEROBJECTFLAGS(ctypes.Structure):
+            _fields_ = [("fInherit", ctypes.wintypes.BOOL),
+                        ("fReserved", ctypes.wintypes.BOOL),
+                        ("dwFlags", ctypes.wintypes.DWORD)]
+        dll = ctypes.windll.user32
+        h = dll.GetProcessWindowStation()
+        if not h:
+            raise ctypes.WinError()
+        uof = USEROBJECTFLAGS()
+        needed = ctypes.wintypes.DWORD()
+        res = dll.GetUserObjectInformationW(h,
+            UOI_FLAGS,
+            ctypes.byref(uof),
+            ctypes.sizeof(uof),
+            ctypes.byref(needed))
+        if not res:
+            raise ctypes.WinError()
+        return bool(uof.dwFlags & WSF_VISIBLE)
+else:
+    def _is_gui_available():
+        return True
+
 def is_resource_enabled(resource):
     """Test whether a resource is enabled.  Known resources are set by
     regrtest.py."""
@@ -245,6 +275,8 @@
     possibility of False being returned occurs when regrtest.py is
     executing.
     """
+    if resource == 'gui' and not _is_gui_available():
+        raise unittest.SkipTest("Cannot use the 'gui' resource")
     # see if the caller's module is __main__ - if so, treat as if
     # the resource was set
     if sys._getframe(1).f_globals.get("__name__") == "__main__":
@@ -1045,6 +1077,8 @@
     return obj
 
 def requires_resource(resource):
+    if resource == 'gui' and not _is_gui_available():
+        return unittest.skip("resource 'gui' is not available")
     if is_resource_enabled(resource):
         return _id
     else:

Modified: python/branches/pep-3151/Lib/test/test_collections.py
==============================================================================
--- python/branches/pep-3151/Lib/test/test_collections.py	(original)
+++ python/branches/pep-3151/Lib/test/test_collections.py	Mon Feb 28 19:08:07 2011
@@ -72,17 +72,23 @@
             for m1, m2 in zip(d.maps, e.maps):
                 self.assertIsNot(m1, m2, e)
 
-        d.new_child()
-        d['b'] = 5
-        self.assertEqual(d.maps, [{'b': 5}, {'c':30}, {'a':1, 'b':2}])
-        self.assertEqual(d.parents.maps, [{'c':30}, {'a':1, 'b':2}])   # check parents
-        self.assertEqual(d['b'], 5)                                    # find first in chain
-        self.assertEqual(d.parents['b'], 2)                            # look beyond maps[0]
+        f = d.new_child()
+        f['b'] = 5
+        self.assertEqual(f.maps, [{'b': 5}, {'c':30}, {'a':1, 'b':2}])
+        self.assertEqual(f.parents.maps, [{'c':30}, {'a':1, 'b':2}])   # check parents
+        self.assertEqual(f['b'], 5)                                    # find first in chain
+        self.assertEqual(f.parents['b'], 2)                            # look beyond maps[0]
 
     def test_contructor(self):
-        self.assertEqual(ChainedContext().maps, [{}])                  # no-args --> one new dict
+        self.assertEqual(ChainMap().maps, [{}])                        # no-args --> one new dict
         self.assertEqual(ChainMap({1:2}).maps, [{1:2}])                # 1 arg --> list
 
+    def test_bool(self):
+        self.assertFalse(ChainMap())
+        self.assertFalse(ChainMap({}, {}))
+        self.assertTrue(ChainMap({1:2}, {}))
+        self.assertTrue(ChainMap({}, {1:2}))
+
     def test_missing(self):
         class DefaultChainMap(ChainMap):
             def __missing__(self, key):
@@ -1182,7 +1188,7 @@
 def test_main(verbose=None):
     NamedTupleDocs = doctest.DocTestSuite(module=collections)
     test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
-                    TestCollectionABCs, TestCounter,
+                    TestCollectionABCs, TestCounter, TestChainMap,
                     TestOrderedDict, GeneralMappingTests, SubclassMappingTests]
     support.run_unittest(*test_classes)
     support.run_doctest(collections, verbose)

Modified: python/branches/pep-3151/Lib/test/test_logging.py
==============================================================================
--- python/branches/pep-3151/Lib/test/test_logging.py	(original)
+++ python/branches/pep-3151/Lib/test/test_logging.py	Mon Feb 28 19:08:07 2011
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright 2001-2010 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2011 by Vinay Sajip. All Rights Reserved.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose and without fee is hereby granted,
@@ -18,7 +18,7 @@
 
 """Test harness for the logging module. Run all tests.
 
-Copyright (C) 2001-2010 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2011 Vinay Sajip. All Rights Reserved.
 """
 
 import logging
@@ -1907,6 +1907,8 @@
         self.assertFalse(f.usesTime())
         f = logging.Formatter('%(asctime)s')
         self.assertTrue(f.usesTime())
+        f = logging.Formatter('%(asctime)-15s')
+        self.assertTrue(f.usesTime())
         f = logging.Formatter('asctime')
         self.assertFalse(f.usesTime())
 
@@ -1920,6 +1922,10 @@
         self.assertFalse(f.usesTime())
         f = logging.Formatter('{asctime}', style='{')
         self.assertTrue(f.usesTime())
+        f = logging.Formatter('{asctime!s:15}', style='{')
+        self.assertTrue(f.usesTime())
+        f = logging.Formatter('{asctime:15}', style='{')
+        self.assertTrue(f.usesTime())
         f = logging.Formatter('asctime', style='{')
         self.assertFalse(f.usesTime())
 
@@ -1935,6 +1941,8 @@
         self.assertFalse(f.usesTime())
         f = logging.Formatter('${asctime}', style='$')
         self.assertTrue(f.usesTime())
+        f = logging.Formatter('${asctime', style='$')
+        self.assertFalse(f.usesTime())
         f = logging.Formatter('$asctime', style='$')
         self.assertTrue(f.usesTime())
         f = logging.Formatter('asctime', style='$')
@@ -2044,13 +2052,13 @@
                   ('M', 60),
                   ('H', 60 * 60),
                   ('D', 60 * 60 * 24),
-                  ('MIDNIGHT', 60 * 60 * 23),
+                  ('MIDNIGHT', 60 * 60 * 24),
                   # current time (epoch start) is a Thursday, W0 means Monday
-                  ('W0', secs(days=4, hours=23)),
+                  ('W0', secs(days=4, hours=24)),
                  ):
     def test_compute_rollover(self, when=when, exp=exp):
         rh = logging.handlers.TimedRotatingFileHandler(
-            self.fn, when=when, interval=1, backupCount=0)
+            self.fn, when=when, interval=1, backupCount=0, utc=True)
         currentTime = 0.0
         actual = rh.computeRollover(currentTime)
         if exp != actual:

Modified: python/branches/pep-3151/Lib/test/test_os.py
==============================================================================
--- python/branches/pep-3151/Lib/test/test_os.py	(original)
+++ python/branches/pep-3151/Lib/test/test_os.py	Mon Feb 28 19:08:07 2011
@@ -1340,7 +1340,7 @@
 
     def wait(self):
         # wait for handler connection to be closed, then stop the server
-        while not getattr(self.handler_instance, "closed", True):
+        while not getattr(self.handler_instance, "closed", False):
             time.sleep(0.001)
         self.stop()
 
@@ -1374,7 +1374,7 @@
 @unittest.skipUnless(hasattr(os, 'sendfile'), "test needs os.sendfile()")
 class TestSendfile(unittest.TestCase):
 
-    DATA = b"12345abcde" * 1024 * 1024  # 10 Mb
+    DATA = b"12345abcde" * 16 * 1024  # 160 KB
     SUPPORT_HEADERS_TRAILERS = not sys.platform.startswith("linux") and \
                                not sys.platform.startswith("solaris") and \
                                not sys.platform.startswith("sunos")
@@ -1432,7 +1432,7 @@
         total_sent = 0
         offset = 0
         nbytes = 4096
-        while 1:
+        while total_sent < len(self.DATA):
             sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbytes)
             if sent == 0:
                 break
@@ -1442,17 +1442,20 @@
             self.assertEqual(offset, total_sent)
 
         self.assertEqual(total_sent, len(self.DATA))
+        self.client.shutdown(socket.SHUT_RDWR)
         self.client.close()
         self.server.wait()
         data = self.server.handler_instance.get_data()
-        self.assertEqual(hash(data), hash(self.DATA))
+        self.assertEqual(len(data), len(self.DATA))
+        self.assertEqual(data, self.DATA)
 
     def test_send_at_certain_offset(self):
         # start sending a file at a certain offset
         total_sent = 0
-        offset = len(self.DATA) / 2
+        offset = len(self.DATA) // 2
+        must_send = len(self.DATA) - offset
         nbytes = 4096
-        while 1:
+        while total_sent < must_send:
             sent = self.sendfile_wrapper(self.sockno, self.fileno, offset, nbytes)
             if sent == 0:
                 break
@@ -1460,18 +1463,27 @@
             total_sent += sent
             self.assertTrue(sent <= nbytes)
 
+        self.client.shutdown(socket.SHUT_RDWR)
         self.client.close()
         self.server.wait()
         data = self.server.handler_instance.get_data()
-        expected = self.DATA[int(len(self.DATA) / 2):]
+        expected = self.DATA[len(self.DATA) // 2:]
         self.assertEqual(total_sent, len(expected))
-        self.assertEqual(hash(data), hash(expected))
+        self.assertEqual(len(data), len(expected))
+        self.assertEqual(data, expected)
 
     def test_offset_overflow(self):
         # specify an offset > file size
         offset = len(self.DATA) + 4096
-        sent = os.sendfile(self.sockno, self.fileno, offset, 4096)
-        self.assertEqual(sent, 0)
+        try:
+            sent = os.sendfile(self.sockno, self.fileno, offset, 4096)
+        except OSError as e:
+            # Solaris can raise EINVAL if offset >= file length, ignore.
+            if e.errno != errno.EINVAL:
+                raise
+        else:
+            self.assertEqual(sent, 0)
+        self.client.shutdown(socket.SHUT_RDWR)
         self.client.close()
         self.server.wait()
         data = self.server.handler_instance.get_data()

Modified: python/branches/pep-3151/Lib/test/test_ssl.py
==============================================================================
--- python/branches/pep-3151/Lib/test/test_ssl.py	(original)
+++ python/branches/pep-3151/Lib/test/test_ssl.py	Mon Feb 28 19:08:07 2011
@@ -451,6 +451,50 @@
             finally:
                 s.close()
 
+    def test_connect_ex(self):
+        # Issue #11326: check connect_ex() implementation
+        with support.transient_internet("svn.python.org"):
+            s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+                                cert_reqs=ssl.CERT_REQUIRED,
+                                ca_certs=SVN_PYTHON_ORG_ROOT_CERT)
+            try:
+                self.assertEqual(0, s.connect_ex(("svn.python.org", 443)))
+                self.assertTrue(s.getpeercert())
+            finally:
+                s.close()
+
+    def test_non_blocking_connect_ex(self):
+        # Issue #11326: non-blocking connect_ex() should allow handshake
+        # to proceed after the socket gets ready.
+        with support.transient_internet("svn.python.org"):
+            s = ssl.wrap_socket(socket.socket(socket.AF_INET),
+                                cert_reqs=ssl.CERT_REQUIRED,
+                                ca_certs=SVN_PYTHON_ORG_ROOT_CERT,
+                                do_handshake_on_connect=False)
+            try:
+                s.setblocking(False)
+                rc = s.connect_ex(('svn.python.org', 443))
+                # EWOULDBLOCK under Windows, EINPROGRESS elsewhere
+                self.assertIn(rc, (0, errno.EINPROGRESS, errno.EWOULDBLOCK))
+                # Wait for connect to finish
+                select.select([], [s], [], 5.0)
+                # Non-blocking handshake
+                while True:
+                    try:
+                        s.do_handshake()
+                        break
+                    except ssl.SSLError as err:
+                        if err.args[0] == ssl.SSL_ERROR_WANT_READ:
+                            select.select([s], [], [], 5.0)
+                        elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
+                            select.select([], [s], [], 5.0)
+                        else:
+                            raise
+                # SSL established
+                self.assertTrue(s.getpeercert())
+            finally:
+                s.close()
+
     def test_connect_with_context(self):
         with support.transient_internet("svn.python.org"):
             # Same as test_connect, but with a separately created context

Modified: python/branches/pep-3151/Misc/NEWS
==============================================================================
--- python/branches/pep-3151/Misc/NEWS	(original)
+++ python/branches/pep-3151/Misc/NEWS	Mon Feb 28 19:08:07 2011
@@ -35,6 +35,9 @@
 Library
 -------
 
+- Issue #11326: Add the missing connect_ex() implementation for SSL sockets,
+  and make it work for non-blocking connects.
+
 - Issue #11297: Add collections.ChainMap().
 
 - Issue #10755: Add the posix.fdlistdir() function.  Patch by Ross Lagerwall.
@@ -105,6 +108,9 @@
 Tests
 -----
 
+- Issue #9931: Fix hangs in GUI tests under Windows in certain conditions.
+  Patch by Hirokazu Yamamoto.
+
 - Issue #10512: Properly close sockets under test.test_cgi.
 
 - Issue #10992: Make tests pass under coverage.

Modified: python/branches/pep-3151/Modules/posixmodule.c
==============================================================================
--- python/branches/pep-3151/Modules/posixmodule.c	(original)
+++ python/branches/pep-3151/Modules/posixmodule.c	Mon Feb 28 19:08:07 2011
@@ -369,8 +369,7 @@
 #if !defined(HAVE_LARGEFILE_SUPPORT)
     *((off_t*)addr) = PyLong_AsLong(arg);
 #else
-    *((off_t*)addr) = PyLong_Check(arg) ? PyLong_AsLongLong(arg)
-            : PyLong_AsLong(arg);
+    *((off_t*)addr) = PyLong_AsLongLong(arg);
 #endif
     if (PyErr_Occurred())
         return 0;
@@ -5772,8 +5771,7 @@
 #if !defined(HAVE_LARGEFILE_SUPPORT)
     pos = PyLong_AsLong(posobj);
 #else
-    pos = PyLong_Check(posobj) ?
-        PyLong_AsLongLong(posobj) : PyLong_AsLong(posobj);
+    pos = PyLong_AsLongLong(posobj);
 #endif
     if (PyErr_Occurred())
         return NULL;
@@ -6030,7 +6028,8 @@
         return Py_BuildValue("nO", ret, Py_None);
     }
 #endif
-    _parse_off_t(offobj, &offset);
+    if (!_parse_off_t(offobj, &offset))
+        return NULL;
     Py_BEGIN_ALLOW_THREADS
     ret = sendfile(out, in, &offset, count);
     Py_END_ALLOW_THREADS

Modified: python/branches/pep-3151/Objects/typeslots.inc
==============================================================================
--- python/branches/pep-3151/Objects/typeslots.inc	(original)
+++ python/branches/pep-3151/Objects/typeslots.inc	Mon Feb 28 19:08:07 2011
@@ -1,4 +1,4 @@
-/* Generated by typeslots.py $Revision: 87806 $ */
+/* Generated by typeslots.py $Revision: 88635 $ */
 0,
 0,
 offsetof(PyHeapTypeObject, as_mapping.mp_ass_subscript),


More information about the Python-checkins mailing list