[Python-checkins] cpython (merge 2.7 -> 2.7): Merge heads

benjamin.peterson python-checkins at python.org
Sun Jul 5 17:40:01 CEST 2015


https://hg.python.org/cpython/rev/756876e059cb
changeset:   96829:756876e059cb
branch:      2.7
parent:      96828:5097c91cdc2d
parent:      96806:64b42ec6ef42
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Jul 05 10:39:53 2015 -0500
summary:
  Merge heads

files:
  Doc/library/idle.rst                                          |    3 +-
  Doc/library/unittest.rst                                      |    2 +-
  Doc/library/urllib.rst                                        |    2 +-
  Lib/ensurepip/__init__.py                                     |    4 +-
  Lib/ensurepip/_bundled/pip-7.0.3-py2.py3-none-any.whl         |  Bin 
  Lib/ensurepip/_bundled/pip-7.1.0-py2.py3-none-any.whl         |  Bin 
  Lib/ensurepip/_bundled/setuptools-17.0-py2.py3-none-any.whl   |  Bin 
  Lib/ensurepip/_bundled/setuptools-18.0.1-py2.py3-none-any.whl |  Bin 
  Lib/idlelib/help.txt                                          |    7 +-
  Lib/tarfile.py                                                |    2 +-
  Lib/test/test_audioop.py                                      |   15 +++
  Lib/test/test_bytes.py                                        |   19 ++++-
  Lib/test/test_contextlib.py                                   |    8 ++
  Lib/test/test_tarfile.py                                      |    9 ++
  Lib/test/test_tokenize.py                                     |   20 +++++-
  Lib/tokenize.py                                               |   17 ++++
  Mac/BuildScript/build-installer.py                            |    6 +-
  Mac/BuildScript/openssl_sdk_makedepend.patch                  |    2 +-
  Misc/NEWS                                                     |   20 +++++
  Modules/audioop.c                                             |   38 +++++++--
  Objects/bytearrayobject.c                                     |    4 +-
  PCbuild/get_externals.bat                                     |    2 +-
  PCbuild/pyproject.vsprops                                     |    2 +-
  PCbuild/readme.txt                                            |    2 +-
  configure                                                     |    5 +-
  configure.ac                                                  |    2 +-
  26 files changed, 160 insertions(+), 31 deletions(-)


diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst
--- a/Doc/library/idle.rst
+++ b/Doc/library/idle.rst
@@ -248,7 +248,8 @@
    help sources can be specified.  Non-default user setting are saved in a
    .idlerc directory in the user's home directory.  Problems caused by bad user
    configuration files are solved by editing or deleting one or more of the
-   files in .idlerc.
+   files in .idlerc.  On OS X, open the configuration dialog by selecting
+   Preferences in the application menu.
 
 Configure Extensions
    Open a configuration dialog for setting preferences for extensions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -83,7 +83,7 @@
       discovery. unittest2 allows you to use these features with earlier
       versions of Python.
 
-   `Simple Smalltalk Testing: With Patterns <http://www.XProgramming.com/testfram.htm>`_
+   `Simple Smalltalk Testing: With Patterns <https://web.archive.org/web/20150315073817/http://www.xprogramming.com/testfram.htm>`_
       Kent Beck's original paper on testing frameworks using the pattern shared
       by :mod:`unittest`.
 
diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst
--- a/Doc/library/urllib.rst
+++ b/Doc/library/urllib.rst
@@ -296,7 +296,7 @@
 .. note::
     urllib also exposes certain utility functions like splittype, splithost and
     others parsing url into various components. But it is recommended to use
-    :mod:`urlparse` for parsing urls than using these functions directly.
+    :mod:`urlparse` for parsing urls rather than using these functions directly.
     Python 3 does not expose these helper functions from :mod:`urllib.parse`
     module.
 
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
--- a/Lib/ensurepip/__init__.py
+++ b/Lib/ensurepip/__init__.py
@@ -12,9 +12,9 @@
 __all__ = ["version", "bootstrap"]
 
 
-_SETUPTOOLS_VERSION = "17.0"
+_SETUPTOOLS_VERSION = "18.0.1"
 
-_PIP_VERSION = "7.0.3"
+_PIP_VERSION = "7.1.0"
 
 # pip currently requires ssl support, so we try to provide a nicer
 # error message when that is missing (http://bugs.python.org/issue19744)
diff --git a/Lib/ensurepip/_bundled/pip-7.0.3-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-7.0.3-py2.py3-none-any.whl
deleted file mode 100644
index bb0cb3138ba4ade7fa5ba3285d04f70d439f490f..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
[stripped]
diff --git a/Lib/ensurepip/_bundled/pip-7.1.0-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-7.1.0-py2.py3-none-any.whl
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..76fcad1c7efb6223b049967e84fda31f9fd68dfc
GIT binary patch
[stripped]
diff --git a/Lib/ensurepip/_bundled/setuptools-17.0-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/setuptools-17.0-py2.py3-none-any.whl
deleted file mode 100644
index a1d3561bad9c3709196b6481dd2e540b0914129b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
[stripped]
diff --git a/Lib/ensurepip/_bundled/setuptools-18.0.1-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/setuptools-18.0.1-py2.py3-none-any.whl
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..67aaca50a921a164fac7d721bc2aa80735c5515e
GIT binary patch
[stripped]
diff --git a/Lib/idlelib/help.txt b/Lib/idlelib/help.txt
--- a/Lib/idlelib/help.txt
+++ b/Lib/idlelib/help.txt
@@ -90,10 +90,9 @@
 	Configure IDLE -- Open a configuration dialog.  Fonts, indentation,
                           keybindings, and color themes may be altered.
                           Startup Preferences may be set, and Additional Help
-                          Sources can be specified.
-			  
-			  On OS X this menu is not present, use
-			  menu 'IDLE -> Preferences...' instead.
+                          Sources can be specified.  On OS X, open the
+                          configuration dialog by selecting Preferences
+                          in the application menu.
 	---
 	Code Context --	  Open a pane at the top of the edit window which
 			  shows the block context of the section of code
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -186,7 +186,7 @@
     # itn() below.
     if s[0] != chr(0200):
         try:
-            n = int(nts(s) or "0", 8)
+            n = int(nts(s).strip() or "0", 8)
         except ValueError:
             raise InvalidHeaderError("invalid header")
     else:
diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py
--- a/Lib/test/test_audioop.py
+++ b/Lib/test/test_audioop.py
@@ -210,6 +210,21 @@
             self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None),
                              (b'\0' * 5, (0, 0)))
 
+    def test_invalid_adpcm_state(self):
+        # state must be a tuple or None, not an integer
+        self.assertRaises(TypeError, audioop.adpcm2lin, b'\0', 1, 555)
+        self.assertRaises(TypeError, audioop.lin2adpcm, b'\0', 1, 555)
+        # Issues #24456, #24457: index out of range
+        self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (0, -1))
+        self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (0, 89))
+        self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (0, -1))
+        self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (0, 89))
+        # value out of range
+        self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (-0x8001, 0))
+        self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (0x8000, 0))
+        self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (-0x8001, 0))
+        self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (0x8000, 0))
+
     def test_lin2alaw(self):
         self.assertEqual(audioop.lin2alaw(datas[1], 1),
                          b'\xd5\x87\xa4\x24\xaa\x2a\x5a')
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -722,10 +722,27 @@
         for i in range(100):
             b += b"x"
             alloc = b.__alloc__()
-            self.assertTrue(alloc >= len(b))
+            self.assertGreater(alloc, len(b))  # including trailing null byte
             if alloc not in seq:
                 seq.append(alloc)
 
+    def test_init_alloc(self):
+        b = bytearray()
+        def g():
+            for i in range(1, 100):
+                yield i
+                a = list(b)
+                self.assertEqual(a, list(range(1, len(a)+1)))
+                self.assertEqual(len(b), len(a))
+                self.assertLessEqual(len(b), i)
+                alloc = b.__alloc__()
+                self.assertGreater(alloc, len(b))  # including trailing null byte
+        b.__init__(g())
+        self.assertEqual(list(b), list(range(1, 100)))
+        self.assertEqual(len(b), 99)
+        alloc = b.__alloc__()
+        self.assertGreater(alloc, len(b))
+
     def test_extend(self):
         orig = b'hello'
         a = bytearray(orig)
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -106,6 +106,14 @@
         baz = self._create_contextmanager_attribs()
         self.assertEqual(baz.__doc__, "Whee!")
 
+    def test_keywords(self):
+        # Ensure no keyword arguments are inhibited
+        @contextmanager
+        def woohoo(self, func, args, kwds):
+            yield (self, func, args, kwds)
+        with woohoo(self=11, func=22, args=33, kwds=44) as target:
+            self.assertEqual(target, (11, 22, 33, 44))
+
 class NestedTestCase(unittest.TestCase):
 
     # XXX This needs more work
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1566,6 +1566,14 @@
         tarinfo.tobuf(tarfile.PAX_FORMAT)
 
 
+class MiscTest(unittest.TestCase):
+
+    def test_read_number_fields(self):
+        # Issue 24514: Test if empty number fields are converted to zero.
+        self.assertEqual(tarfile.nti("\0"), 0)
+        self.assertEqual(tarfile.nti("       \0"), 0)
+
+
 class ContextManagerTest(unittest.TestCase):
 
     def test_basic(self):
@@ -1730,6 +1738,7 @@
         PaxUnicodeTest,
         AppendTest,
         LimitsTest,
+        MiscTest,
         ContextManagerTest,
     ]
 
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -559,7 +559,7 @@
 
 from test import test_support
 from tokenize import (untokenize, generate_tokens, NUMBER, NAME, OP,
-                     STRING, ENDMARKER, tok_name, Untokenizer)
+                     STRING, ENDMARKER, tok_name, Untokenizer, tokenize)
 from StringIO import StringIO
 import os
 from unittest import TestCase
@@ -650,12 +650,30 @@
         self.assertEqual(u.untokenize(iter([token])), 'Hello ')
 
 
+class TestRoundtrip(TestCase):
+    def roundtrip(self, code):
+        if isinstance(code, str):
+            code = code.encode('utf-8')
+        tokens = generate_tokens(StringIO(code).readline)
+        return untokenize(tokens).decode('utf-8')
+
+    def test_indentation_semantics_retained(self):
+        """
+        Ensure that although whitespace might be mutated in a roundtrip,
+        the semantic meaning of the indentation remains consistent.
+        """
+        code = "if False:\n\tx=3\n\tx=3\n"
+        codelines = self.roundtrip(code).split('\n')
+        self.assertEqual(codelines[1], codelines[2])
+
+
 __test__ = {"doctests" : doctests, 'decistmt': decistmt}
 
 def test_main():
     from test import test_tokenize
     test_support.run_doctest(test_tokenize, True)
     test_support.run_unittest(UntokenizeTest)
+    test_support.run_unittest(TestRoundtrip)
 
 if __name__ == "__main__":
     test_main()
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -198,6 +198,8 @@
 
     def untokenize(self, iterable):
         it = iter(iterable)
+        indents = []
+        startline = False
         for t in it:
             if len(t) == 2:
                 self.compat(t, it)
@@ -205,6 +207,21 @@
             tok_type, token, start, end, line = t
             if tok_type == ENDMARKER:
                 break
+            if tok_type == INDENT:
+                indents.append(token)
+                continue
+            elif tok_type == DEDENT:
+                indents.pop()
+                self.prev_row, self.prev_col = end
+                continue
+            elif tok_type in (NEWLINE, NL):
+                startline = True
+            elif startline and indents:
+                indent = indents[-1]
+                if start[1] >= len(indent):
+                    self.tokens.append(indent)
+                    self.prev_col = len(indent)
+                startline = False
             self.add_whitespace(start)
             self.tokens.append(token)
             self.prev_row, self.prev_col = end
diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py
--- a/Mac/BuildScript/build-installer.py
+++ b/Mac/BuildScript/build-installer.py
@@ -237,9 +237,9 @@
 
         result.extend([
           dict(
-              name="OpenSSL 1.0.2a",
-              url="https://www.openssl.org/source/openssl-1.0.2a.tar.gz",
-              checksum='a06c547dac9044161a477211049f60ef',
+              name="OpenSSL 1.0.2c",
+              url="https://www.openssl.org/source/openssl-1.0.2c.tar.gz",
+              checksum='8c8d81a9ae7005276e486702edbcd4b6',
               patches=[
                   "openssl_sdk_makedepend.patch",
                    ],
diff --git a/Mac/BuildScript/openssl_sdk_makedepend.patch b/Mac/BuildScript/openssl_sdk_makedepend.patch
--- a/Mac/BuildScript/openssl_sdk_makedepend.patch
+++ b/Mac/BuildScript/openssl_sdk_makedepend.patch
@@ -2,7 +2,7 @@
 # Parent  25a9af415e8c3faf591c360d5f0e361d049b2b43
 # openssl_sdk_makedepend.patch
 #
-# 	using openssl 1.0.2a
+# 	using openssl 1.0.2c
 #
 # - support building with an OS X SDK
 # - allow "make depend" to use compilers with names other than "gcc"
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
 Core and Builtins
 -----------------
 
+- Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
+  object now always allocates place for trailing null byte and it's buffer now
+  is always null-terminated.
+
 - Issue #19543: encode() and decode() methods and constructors of str,
   unicode and bytearray classes now emit deprecation warning for known
   non-text encodings when Python is ran with the -3 option.
@@ -30,6 +34,16 @@
 Library
 -------
 
+- Issue #24514: tarfile now tolerates number fields consisting of only
+  whitespace.
+
+- Issue #20387: Restore semantic round-trip correctness in tokenize/untokenize
+  for tab-indented blocks.
+
+- Issue #24456: Fixed possible buffer over-read in adpcm2lin() and lin2adpcm()
+  functions of the audioop module.  Fixed SystemError when the state is not a
+  tuple.  Fixed possible memory leak.
+
 - Issue #24481: Fix possible memory corruption with large profiler info strings
   in hotshot.
 
@@ -78,6 +92,12 @@
 
 - Issue #24134: Reverted issue #24134 changes.
 
+Build
+-----
+
+- Issue #24432: Update Windows builds and OS X 10.5 installer to use OpenSSL
+  1.0.2c.
+
 IDLE
 ----
 
diff --git a/Modules/audioop.c b/Modules/audioop.c
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1420,18 +1420,29 @@
     if (!audioop_check_parameters(len, size))
         return NULL;
 
-    str = PyString_FromStringAndSize(NULL, len/(size*2));
-    if ( str == 0 )
-        return 0;
-    ncp = (signed char *)PyString_AsString(str);
-
     /* Decode state, should have (value, step) */
     if ( state == Py_None ) {
         /* First time, it seems. Set defaults */
         valpred = 0;
         index = 0;
-    } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
+    }
+    else if (!PyTuple_Check(state)) {
+        PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+        return NULL;
+    }
+    else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) {
+        return NULL;
+    }
+    else if (valpred >= 0x8000 || valpred < -0x8000 ||
+             (size_t)index >= sizeof(stepsizeTable)/sizeof(stepsizeTable[0])) {
+        PyErr_SetString(PyExc_ValueError, "bad state");
+        return NULL;
+    }
+
+    str = PyString_FromStringAndSize(NULL, len/(size*2));
+    if ( str == 0 )
         return 0;
+    ncp = (signed char *)PyString_AsString(str);
 
     step = stepsizeTable[index];
     bufferstep = 1;
@@ -1529,8 +1540,19 @@
         /* First time, it seems. Set defaults */
         valpred = 0;
         index = 0;
-    } else if ( !PyArg_ParseTuple(state, "ii", &valpred, &index) )
-        return 0;
+    }
+    else if (!PyTuple_Check(state)) {
+        PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+        return NULL;
+    }
+    else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) {
+        return NULL;
+    }
+    else if (valpred >= 0x8000 || valpred < -0x8000 ||
+             (size_t)index >= sizeof(stepsizeTable)/sizeof(stepsizeTable[0])) {
+        PyErr_SetString(PyExc_ValueError, "bad state");
+        return NULL;
+    }
 
     if (len > (INT_MAX/2)/size) {
         PyErr_SetString(PyExc_MemoryError,
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -897,8 +897,10 @@
             goto error;
 
         /* Append the byte */
-        if (Py_SIZE(self) < self->ob_alloc)
+        if (Py_SIZE(self) + 1 < self->ob_alloc) {
             Py_SIZE(self)++;
+            PyByteArray_AS_STRING(self)[Py_SIZE(self)] = '\0';
+        }
         else if (PyByteArray_Resize((PyObject *)self, Py_SIZE(self)+1) < 0)
             goto error;
         self->ob_bytes[Py_SIZE(self)-1] = value;
diff --git a/PCbuild/get_externals.bat b/PCbuild/get_externals.bat
--- a/PCbuild/get_externals.bat
+++ b/PCbuild/get_externals.bat
@@ -55,7 +55,7 @@
             bzip2-1.0.6
             db-4.7.25.0
             nasm-2.11.06
-            openssl-1.0.2a
+            openssl-1.0.2c
             tcl-8.5.15.0
             tk-8.5.15.0
             tix-8.4.3.5
diff --git a/PCbuild/pyproject.vsprops b/PCbuild/pyproject.vsprops
--- a/PCbuild/pyproject.vsprops
+++ b/PCbuild/pyproject.vsprops
@@ -82,7 +82,7 @@
 	/>
 	<UserMacro
 		Name="opensslDir"
-		Value="$(externalsDir)\openssl-1.0.2a"
+		Value="$(externalsDir)\openssl-1.0.2c"
 	/>
 	<UserMacro
 		Name="tcltkDir"
diff --git a/PCbuild/readme.txt b/PCbuild/readme.txt
--- a/PCbuild/readme.txt
+++ b/PCbuild/readme.txt
@@ -132,7 +132,7 @@
 
     Get the source code through
 
-    svn export http://svn.python.org/projects/external/openssl-1.0.2a
+    svn export http://svn.python.org/projects/external/openssl-1.0.2c
 
     ** NOTE: if you use the PCbuild\get_externals.bat approach for
     obtaining external sources then you don't need to manually get the source
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -12747,12 +12747,13 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+if ac_fn_c_try_link "$LINENO"; then :
   have_gcc_asm_for_x87=yes
 else
   have_gcc_asm_for_x87=no
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_asm_for_x87" >&5
 $as_echo "$have_gcc_asm_for_x87" >&6; }
 if test "$have_gcc_asm_for_x87" = yes
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -3723,7 +3723,7 @@
 # so we try it on all platforms.
 
 AC_MSG_CHECKING(whether we can use gcc inline assembler to get and set x87 control word)
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
   unsigned short cw;
   __asm__ __volatile__ ("fnstcw %0" : "=m" (cw));
   __asm__ __volatile__ ("fldcw %0" : : "m" (cw));

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list