From 16d2b478372ba68923f8e325c75202416aaeaa93 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Tue, 18 Sep 2012 07:20:18 +0300 Subject: [PATCH 01/10] #15796: Fix \n in readline docstring. Patch by Serhiy Storchaka. --- Modules/_io/_iomodule.c | 2 +- Modules/_io/iobase.c | 2 +- Modules/_io/textio.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 59876791d80..e18aec66861 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -264,7 +264,7 @@ PyDoc_STRVAR(open_doc, "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" -" newline is '' or '\n', no translation takes place. If newline is any\n" +" newline is '' or '\\n', no translation takes place. If newline is any\n" " of the other legal values, any '\\n' characters written are translated\n" " to the given string.\n" "\n" diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 2bba1bfd58f..ba861467904 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -451,7 +451,7 @@ PyDoc_STRVAR(iobase_readline_doc, "\n" "If limit is specified, at most limit bytes will be read.\n" "\n" - "The line terminator is always b'\n' for binary files; for text\n" + "The line terminator is always b'\\n' for binary files; for text\n" "files, the newlines argument to open can be used to select the line\n" "terminator(s) recognized.\n"); diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 490484254b3..2fbb8f30523 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -635,7 +635,7 @@ PyDoc_STRVAR(textiowrapper_doc, "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" - " newline is '' or '\n', no translation takes place. If newline is any\n" + " newline is '' or '\\n', no translation takes place. If newline is any\n" " of the other legal values, any '\\n' characters written are translated\n" " to the given string.\n" "\n" From 1da769a30295eb9e4acb5367b49c7cb21ca255cb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 18 Sep 2012 22:40:03 +0200 Subject: [PATCH 02/10] What's New in Python 3.3: mention unittest.mock --- Doc/whatsnew/3.3.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index caa838f3532..2aa41f916e2 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -69,6 +69,7 @@ New library modules: * :mod:`faulthandler` (helps debugging low-level crashes) * :mod:`ipaddress` (high-level objects representing IP addresses and masks) * :mod:`lzma` (compress data using the XZ / LZMA algorithm) +* :mod:`unittest.mock` (replace parts of your system under test with mock objects) * :mod:`venv` (Python :ref:`virtual environments `, as in the popular ``virtualenv`` package) @@ -923,7 +924,7 @@ New Modules faulthandler ------------ -This new debug module contains functions to dump Python tracebacks explicitly, +This new debug module :mod:`faulthandler` contains functions to dump Python tracebacks explicitly, on a fault (a crash like a segmentation fault), after a timeout, or on a user signal. Call :func:`faulthandler.enable` to install fault handlers for the :const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS`, and From 9a46105a897f6a4d6e2cf74cdb215d934fab76d9 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Tue, 18 Sep 2012 21:50:06 -0400 Subject: [PATCH 03/10] #15965: Explicitly cast AT_FDCWD as (int). Required on Solaris 10 (which defines AT_FDCWD as 0xffd19553), harmless on other platforms. --- Misc/NEWS | 3 +++ Modules/posixmodule.c | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 990f4d6c92f..90e3cc188c5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.3.1 Core and Builtins ----------------- +- Issue #15965: Explicitly cast AT_FDCWD as (int). Required on Solaris 10 + (which defines AT_FDCWD as 0xffd19553), harmless on other platforms. + - Issue #15926: Fix crash after multiple reinitializations of the interpreter. - Issue #15895: Fix FILE pointer leak in one error branch of diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 54f6cd2b22c..e0efebfe1b0 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -414,7 +414,14 @@ win32_warn_bytes_api() #ifdef AT_FDCWD -#define DEFAULT_DIR_FD AT_FDCWD +/* + * Why the (int) cast? Solaris 10 defines AT_FDCWD as 0xffd19553 (-3041965); + * without the int cast, the value gets interpreted as uint (4291925331), + * which doesn't play nicely with all the initializer lines in this file that + * look like this: + * int dir_fd = DEFAULT_DIR_FD; + */ +#define DEFAULT_DIR_FD (int)AT_FDCWD #else #define DEFAULT_DIR_FD (-100) #endif From ab02db23b1032c7b1fcf7063ae736b25e4466624 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Tue, 18 Sep 2012 21:58:03 -0400 Subject: [PATCH 04/10] Silence compiler warnings on Solaris 10 via explicit (void *) casts. (Compiler: Solaris Studio 12.3) --- Objects/typeobject.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 0fc0ad38e82..fd2ae67d860 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5772,7 +5772,7 @@ update_one_slot(PyTypeObject *type, slotdef *p) descr = _PyType_Lookup(type, p->name_strobj); if (descr == NULL) { if (ptr == (void**)&type->tp_iternext) { - specific = _PyObject_NextNotImplemented; + specific = (void *)_PyObject_NextNotImplemented; } continue; } @@ -5819,7 +5819,7 @@ update_one_slot(PyTypeObject *type, slotdef *p) /* We specifically allow __hash__ to be set to None to prevent inheritance of the default implementation from object.__hash__ */ - specific = PyObject_HashNotImplemented; + specific = (void *)PyObject_HashNotImplemented; } else { use_generic = 1; @@ -6034,7 +6034,7 @@ add_operators(PyTypeObject *type) continue; if (PyDict_GetItem(dict, p->name_strobj)) continue; - if (*ptr == PyObject_HashNotImplemented) { + if (*ptr == (void *)PyObject_HashNotImplemented) { /* Classes may prevent the inheritance of the tp_hash slot by storing PyObject_HashNotImplemented in it. Make it visible as a None value for the __hash__ attribute. */ From c90111f9ab617a1dbdde8952a4b81e6eecc36e7c Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Wed, 19 Sep 2012 08:19:12 +0300 Subject: [PATCH 05/10] #15970: xml.etree.ElementTree now serializes correctly the empty HTML elements "meta" and "param". --- Lib/test/test_xml_etree.py | 20 ++++++++++++++++++++ Lib/xml/etree/ElementTree.py | 2 +- Misc/NEWS | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index b7a996c29ca..3092f3bc11e 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1851,6 +1851,26 @@ def check_issue10777(): >>> ET.register_namespace('test10777', 'http://myuri/') """ +def check_html_empty_elems_serialization(self): + # issue 15970 + # from http://www.w3.org/TR/html401/index/elements.html + """ + + >>> empty_elems = ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'FRAME', 'HR', + ... 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM'] + >>> elems = ''.join('<%s />' % elem for elem in empty_elems) + >>> serialize(ET.XML('%s' % elems), method='html') + '

' + >>> serialize(ET.XML('%s' % elems.lower()), method='html') + '

' + >>> elems = ''.join('<%s>' % (elem, elem) for elem in empty_elems) + >>> serialize(ET.XML('%s' % elems), method='html') + '

' + >>> serialize(ET.XML('%s' % elems.lower()), method='html') + '

' + + """ + # -------------------------------------------------------------------- diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index f94c48c09c7..9742f32f381 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -983,7 +983,7 @@ def _serialize_xml(write, elem, qnames, namespaces): write(_escape_cdata(elem.tail)) HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr", - "img", "input", "isindex", "link", "meta" "param") + "img", "input", "isindex", "link", "meta", "param") try: HTML_EMPTY = set(HTML_EMPTY) diff --git a/Misc/NEWS b/Misc/NEWS index 29e2c195656..5113ec08ce9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -120,6 +120,9 @@ Core and Builtins Library ------- +- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML + elements 'meta' and 'param'. + - Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed. Patch by Alessandro Moura. From a3ccb237c7e16d15dca294f377d73ad14c48fcca Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Thu, 20 Sep 2012 06:13:38 +0300 Subject: [PATCH 06/10] Fix rst markup in timeit docs. --- Doc/library/timeit.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/timeit.rst b/Doc/library/timeit.rst index cd2d205b99f..1e734dfe520 100644 --- a/Doc/library/timeit.rst +++ b/Doc/library/timeit.rst @@ -31,13 +31,13 @@ The module defines the following public class: may also contain multiple statements separated by ``;`` or newlines, as long as they don't contain multi-line string literals. - To measure the execution time of the first statement, use the :meth:`timeit` - method. The :meth:`repeat` method is a convenience to call :meth:`timeit` + To measure the execution time of the first statement, use the :meth:`Timer.timeit` + method. The :meth:`repeat` method is a convenience to call :meth:`.timeit` multiple times and return a list of results. The *stmt* and *setup* parameters can also take objects that are callable without arguments. This will embed calls to them in a timer function that - will then be executed by :meth:`timeit`. Note that the timing overhead is a + will then be executed by :meth:`.timeit`. Note that the timing overhead is a little larger in this case because of the extra function calls. @@ -60,12 +60,12 @@ The module defines the following public class: .. method:: Timer.repeat(repeat=3, number=1000000) - Call :meth:`timeit` a few times. + Call :meth:`.timeit` a few times. - This is a convenience function that calls the :meth:`timeit` repeatedly, + This is a convenience function that calls the :meth:`.timeit` repeatedly, returning a list of results. The first argument specifies how many times to - call :meth:`timeit`. The second argument specifies the *number* argument for - :func:`timeit`. + call :meth:`.timeit`. The second argument specifies the *number* argument for + :meth:`.timeit`. .. note:: @@ -89,7 +89,7 @@ The module defines the following public class: .. note:: - By default, :meth:`timeit` temporarily turns off :term:`garbage collection` + By default, :meth:`.timeit` temporarily turns off :term:`garbage collection` during the timing. The advantage of this approach is that it makes independent timings more comparable. This disadvantage is that GC may be an important component of the performance of the function being measured. @@ -123,7 +123,7 @@ The module also defines three convenience functions: .. function:: timeit(stmt='pass', setup='pass', timer=, number=1000000) Create a :class:`Timer` instance with the given statement, setup code and timer - function and run its :meth:`timeit` method with *number* executions. + function and run its :meth:`.timeit` method with *number* executions. Command Line Interface @@ -243,7 +243,7 @@ attributes. :: 3.15 usec/pass To give the :mod:`timeit` module access to functions you define, you can pass a -``setup`` parameter which contains an import statement:: +*setup* parameter which contains an import statement:: def test(): """Stupid test function""" From 7598e18bf236a035fe16c62c0ca51290dfd21949 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Thu, 20 Sep 2012 08:33:53 +0300 Subject: [PATCH 07/10] Fix rst markup. --- Doc/c-api/import.rst | 2 +- Doc/whatsnew/3.3.rst | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst index c3c8f42cf01..270152ebbe7 100644 --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -76,7 +76,7 @@ Importing Modules UTF-8 encoded string instead of a Unicode object. .. versionchanged:: 3.3 - Negative values for **level** are no longer accepted. + Negative values for *level* are no longer accepted. .. c:function:: PyObject* PyImport_Import(PyObject *name) diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index 2aa41f916e2..7d7747299d2 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -1928,7 +1928,7 @@ Porting Python code updated to use the full name of the module instead of just the tail of the name. -* The **index** argument to :func:`__import__` now defaults to 0 instead of -1 +* The *index* argument to :func:`__import__` now defaults to 0 instead of -1 and no longer support negative values. It was an oversight when :pep:`328` was implemented that the default value remained -1. If you need to continue to perform a relative import followed by an absolute import, then perform the @@ -1996,9 +1996,9 @@ Porting C code * :c:func:`PyImport_GetMagicNumber` now returns -1 upon failure. -* As a negative value for the **level** argument to :func:`__import__` is no +* As a negative value for the *level* argument to :func:`__import__` is no longer valid, the same now holds for :c:func:`PyImport_ImportModuleLevel`. - This also means that the value of **level** used by + This also means that the value of *level* used by :c:func:`PyImport_ImportModuleEx` is now 0 instead of -1. From be54d6d2f3a4f2f73caf4980046e53bfc5a6901a Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Thu, 20 Sep 2012 08:46:06 +0300 Subject: [PATCH 08/10] Update suspicious ignore file. --- Doc/tools/sphinxext/susp-ignored.csv | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/tools/sphinxext/susp-ignored.csv b/Doc/tools/sphinxext/susp-ignored.csv index 7317ca26087..138e00049c6 100644 --- a/Doc/tools/sphinxext/susp-ignored.csv +++ b/Doc/tools/sphinxext/susp-ignored.csv @@ -124,9 +124,8 @@ library/functions,,:step,a[start:stop:step] library/functions,,:stop,"a[start:stop, i]" library/functions,,:stop,a[start:stop:step] library/hotshot,,:lineno,"ncalls tottime percall cumtime percall filename:lineno(function)" -library/http.client,52,:port,host:port +library/http.client,,:port,host:port library/http.cookies,,`,!#$%&'*+-.^_`|~: -library/httplib,,:port,host:port library/imaplib,,:MM,"""DD-Mmm-YYYY HH:MM:SS" library/imaplib,,:SS,"""DD-Mmm-YYYY HH:MM:SS" library/inspect,,:int,">>> def foo(a, *, b:int, **kwargs):" From 8bbcb584ddc74e6b2a58ee5bda8387776300d815 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Thu, 20 Sep 2012 09:06:51 +0300 Subject: [PATCH 09/10] Fix markup in smtpd.rst. --- Doc/library/smtpd.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/library/smtpd.rst b/Doc/library/smtpd.rst index 48da5d0cf51..bfdc7271f76 100644 --- a/Doc/library/smtpd.rst +++ b/Doc/library/smtpd.rst @@ -104,12 +104,13 @@ SMTPChannel Objects .. attribute:: addr Holds the address of the client, the second value returned by - socket.accept() + :func:`socket.accept ` .. attribute:: received_lines Holds a list of the line strings (decoded using UTF-8) received from - the client. The lines have their "\\r\\n" line ending translated to "\\n". + the client. The lines have their ``"\r\n"`` line ending translated to + ``"\n"``. .. attribute:: smtp_state @@ -134,12 +135,12 @@ SMTPChannel Objects .. attribute:: received_data Holds a string containing all of the data sent by the client during the - DATA state, up to but not including the terminating "\r\n.\r\n". + DATA state, up to but not including the terminating ``"\r\n.\r\n"``. .. attribute:: fqdn Holds the fully-qualified domain name of the server as returned by - ``socket.getfqdn()``. + :func:`socket.getfqdn`. .. attribute:: peer @@ -166,5 +167,5 @@ SMTPChannel Objects :attr:`received_data`, but not the greeting. DATA Sets the internal state to :attr:`DATA` and stores remaining lines from the client in :attr:`received_data` until the terminator - "\r\n.\r\n" is received. + ``"\r\n.\r\n"`` is received. ======== =================================================================== From 694f2331c6959872e05f76c757799be0c4b00748 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Thu, 20 Sep 2012 09:47:03 +0300 Subject: [PATCH 10/10] Fix a few quotes/backslashes. --- Doc/faq/windows.rst | 10 +++++----- Doc/library/doctest.rst | 2 +- Doc/library/pyexpat.rst | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/faq/windows.rst b/Doc/faq/windows.rst index 68a1b5c153c..84e3ff47391 100644 --- a/Doc/faq/windows.rst +++ b/Doc/faq/windows.rst @@ -464,13 +464,13 @@ to console subprocesses which are designed to handle those signals. See Why does os.path.isdir() fail on NT shared directories? ------------------------------------------------------- -The solution appears to be always append the "\\" on the end of shared -drives. +In order to work correctly, :func:`os.path.isdir` requires a ``"\\"`` at the +end of the shared drive:: >>> import os - >>> os.path.isdir( '\\\\rorschach\\public') + >>> os.path.isdir('\\\\rorschach\\public') 0 - >>> os.path.isdir( '\\\\rorschach\\public\\') + >>> os.path.isdir('\\\\rorschach\\public\\') 1 It helps to think of share points as being like drive letters. Example:: @@ -480,7 +480,7 @@ It helps to think of share points as being like drive letters. Example:: k:\media is a directory k:\media\ is not a directory -The same rules apply if you substitute "k:" with "\\conky\foo":: +The same rules apply if you substitute ``"k:"`` with ``"\\conky\foo"``:: \\conky\foo is not a directory \\conky\foo\ is a directory diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index cad03bd2a1b..ed53f060517 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -338,7 +338,7 @@ The fine print: Backslashes in a raw docstring: m\n Otherwise, the backslash will be interpreted as part of the string. For example, - the "\\" above would be interpreted as a newline character. Alternatively, you + the ``\n`` above would be interpreted as a newline character. Alternatively, you can double each backslash in the doctest version (and not use a raw string):: >>> def f(x): diff --git a/Doc/library/pyexpat.rst b/Doc/library/pyexpat.rst index a648cfa5290..861546c2e87 100644 --- a/Doc/library/pyexpat.rst +++ b/Doc/library/pyexpat.rst @@ -402,7 +402,7 @@ otherwise stated. .. method:: xmlparser.CommentHandler(data) Called for comments. *data* is the text of the comment, excluding the leading - '````'. + ``''``. .. method:: xmlparser.StartCdataSectionHandler()