From solipsis at pitrou.net Sat Dec 1 05:59:18 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 01 Dec 2012 05:59:18 +0100 Subject: [Python-checkins] Daily reference leaks (6fdc5e3daa8c): sum=-1 Message-ID: results for 6fdc5e3daa8c on branch "default" -------------------------------------------- test_support leaked [0, 0, -1] references, sum=-1 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog0lpkJC', '-x'] From python-checkins at python.org Sat Dec 1 15:08:11 2012 From: python-checkins at python.org (ezio.melotti) Date: Sat, 1 Dec 2012 15:08:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Clarify_a_sentence_and_fi?= =?utf-8?q?x_a_typo=2E__Patch_by_Daniel_Shahaf=2E?= Message-ID: <3YDDp30yLjzPM9@mail.python.org> http://hg.python.org/devguide/rev/06225ce4c1d3 changeset: 577:06225ce4c1d3 user: Ezio Melotti date: Sat Dec 01 16:07:51 2012 +0200 summary: Clarify a sentence and fix a typo. Patch by Daniel Shahaf. files: buildbots.rst | 2 +- tracker.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildbots.rst b/buildbots.rst --- a/buildbots.rst +++ b/buildbots.rst @@ -54,7 +54,7 @@ --------- A subset of the buildbots are marked "stable". They are taken into account -when making a new release. The rule is that no stable buildbot must witness +when making a new release. The rule is that all builders must be free of persistent failures when the release is cut. It is absolutely **vital** that core developers fix any issue they introduce on the stable buildbots, as soon as possible. diff --git a/tracker.rst b/tracker.rst --- a/tracker.rst +++ b/tracker.rst @@ -50,7 +50,7 @@ * if you have JavaScript enabled, you can use the **Nosy List** field to search developers that can help with the issue by entering the name of the affected module, operating system, or interest area. -* least but not last, you have to describe the problem in detail, including +* last but not least, you have to describe the problem in detail, including what you expected to happen and what did happen, in the **Comment** field. Be sure to include whether any extension modules were involved, and what hardware and software platform you were using (including version information -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Sat Dec 1 18:36:15 2012 From: python-checkins at python.org (ezio.melotti) Date: Sat, 1 Dec 2012 18:36:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NTg5OiBmaXgg?= =?utf-8?q?pprint_signatures_in_the_doc_=28backport_of_106ee4eb5970=29=2E?= Message-ID: <3YDKQ72gjjzPcJ@mail.python.org> http://hg.python.org/cpython/rev/62fed5f18681 changeset: 80668:62fed5f18681 branch: 2.7 parent: 80666:1e614dae8448 user: Ezio Melotti date: Sat Dec 01 19:36:00 2012 +0200 summary: #16589: fix pprint signatures in the doc (backport of 106ee4eb5970). files: Doc/library/pprint.rst | 13 ++++++------- 1 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst --- a/Doc/library/pprint.rst +++ b/Doc/library/pprint.rst @@ -36,7 +36,7 @@ .. First the implementation class: -.. class:: PrettyPrinter(...) +.. class:: PrettyPrinter(indent=1, width=80, depth=None, stream=None) Construct a :class:`PrettyPrinter` instance. This constructor understands several keyword parameters. An output stream may be set using the *stream* @@ -73,9 +73,7 @@ The :class:`PrettyPrinter` class supports several derivative functions: -.. Now the derivative functions: - -.. function:: pformat(object[, indent[, width[, depth]]]) +.. function:: pformat(object, indent=1, width=80, depth=None) Return the formatted representation of *object* as a string. *indent*, *width* and *depth* will be passed to the :class:`PrettyPrinter` constructor as @@ -85,10 +83,10 @@ The parameters *indent*, *width* and *depth* were added. -.. function:: pprint(object[, stream[, indent[, width[, depth]]]]) +.. function:: pprint(object, stream=None, indent=1, width=80, depth=None) Prints the formatted representation of *object* on *stream*, followed by a - newline. If *stream* is omitted, ``sys.stdout`` is used. This may be used in + newline. If *stream* is ``None``, ``sys.stdout`` is used. This may be used in the interactive interpreter instead of a :keyword:`print` statement for inspecting values. *indent*, *width* and *depth* will be passed to the :class:`PrettyPrinter` constructor as formatting parameters. @@ -206,7 +204,8 @@ pprint Example -------------- -This example demonstrates several uses of the :func:`pprint` function and its parameters. +This example demonstrates several uses of the :func:`pprint` function and its +parameters. >>> import pprint >>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 1 19:35:49 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 1 Dec 2012 19:35:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316590=3A_remove_o?= =?utf-8?q?bsolete_compatibility_code_from_the_=5Fjson_module=2E?= Message-ID: <3YDLks2FSNzQ0W@mail.python.org> http://hg.python.org/cpython/rev/2c04d2102534 changeset: 80669:2c04d2102534 parent: 80667:6fdc5e3daa8c user: Antoine Pitrou date: Sat Dec 01 19:34:16 2012 +0100 summary: Issue #16590: remove obsolete compatibility code from the _json module. Patch by Serhiy Storchaka. files: Modules/_json.c | 45 ++++-------------------------------- 1 files changed, 5 insertions(+), 40 deletions(-) diff --git a/Modules/_json.c b/Modules/_json.c --- a/Modules/_json.c +++ b/Modules/_json.c @@ -2,20 +2,6 @@ #include "structmember.h" #include "accu.h" -#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TYPE) -#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) -#endif -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) -typedef int Py_ssize_t; -#define PY_SSIZE_T_MAX INT_MAX -#define PY_SSIZE_T_MIN INT_MIN -#define PyInt_FromSsize_t PyInt_FromLong -#define PyInt_AsSsize_t PyInt_AsLong -#endif -#ifndef Py_IS_FINITE -#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X)) -#endif - #ifdef __GNUC__ #define UNUSED __attribute__((__unused__)) #else @@ -129,33 +115,12 @@ raise_errmsg(char *msg, PyObject *s, Py_ssize_t end); static PyObject * encoder_encode_string(PyEncoderObject *s, PyObject *obj); -static int -_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr); -static PyObject * -_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr); static PyObject * encoder_encode_float(PyEncoderObject *s, PyObject *obj); #define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '"') #define IS_WHITESPACE(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') || ((c) == '\r')) -static int -_convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr) -{ - /* PyObject to Py_ssize_t converter */ - *size_ptr = PyLong_AsSsize_t(o); - if (*size_ptr == -1 && PyErr_Occurred()) - return 0; - return 1; -} - -static PyObject * -_convertPyInt_FromSsize_t(Py_ssize_t *size_ptr) -{ - /* Py_ssize_t to PyObject converter */ - return PyLong_FromSsize_t(*size_ptr); -} - static Py_ssize_t ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars) { @@ -265,7 +230,7 @@ if (errmsg_fn == NULL) return; } - pymsg = PyObject_CallFunction(errmsg_fn, "(zOO&)", msg, s, _convertPyInt_FromSsize_t, &end); + pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end); if (pymsg) { PyErr_SetObject(PyExc_ValueError, pymsg); Py_DECREF(pymsg); @@ -524,7 +489,7 @@ Py_ssize_t end; Py_ssize_t next_end = -1; int strict = 1; - if (!PyArg_ParseTuple(args, "OO&|i:scanstring", &pystr, _convertPyInt_AsSsize_t, &end, &strict)) { + if (!PyArg_ParseTuple(args, "On|i:scanstring", &pystr, &end, &strict)) { return NULL; } if (PyUnicode_Check(pystr)) { @@ -1087,7 +1052,7 @@ PyScannerObject *s; assert(PyScanner_Check(self)); s = (PyScannerObject *)self; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:scan_once", kwlist, &pystr, _convertPyInt_AsSsize_t, &idx)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:scan_once", kwlist, &pystr, &idx)) return NULL; if (PyUnicode_Check(pystr)) { @@ -1288,8 +1253,8 @@ assert(PyEncoder_Check(self)); s = (PyEncoderObject *)self; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:_iterencode", kwlist, - &obj, _convertPyInt_AsSsize_t, &indent_level)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "On:_iterencode", kwlist, + &obj, &indent_level)) return NULL; if (_PyAccu_Init(&acc)) return NULL; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 04:23:54 2012 From: python-checkins at python.org (raymond.hettinger) Date: Sun, 2 Dec 2012 04:23:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Minor_fixups?= =?utf-8?q?=2E_Early-out_for_equality_test=2E__Inline_PREV/NEXT_constants?= =?utf-8?q?=2E?= Message-ID: <3YDZSB07LbzN8g@mail.python.org> http://hg.python.org/cpython/rev/c82151aac59a changeset: 80670:c82151aac59a branch: 2.7 parent: 80668:62fed5f18681 user: Raymond Hettinger date: Sat Dec 01 19:22:02 2012 -0800 summary: Minor fixups. Early-out for equality test. Inline PREV/NEXT constants. files: Lib/collections.py | 31 +++++++++++++++---------------- 1 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Lib/collections.py b/Lib/collections.py --- a/Lib/collections.py +++ b/Lib/collections.py @@ -6,11 +6,12 @@ __all__ += _abcoll.__all__ from _collections import deque, defaultdict -from operator import itemgetter as _itemgetter +from operator import itemgetter as _itemgetter, eq as _eq from keyword import iskeyword as _iskeyword import sys as _sys import heapq as _heapq from itertools import repeat as _repeat, chain as _chain, starmap as _starmap +from itertools import imap as _imap try: from thread import get_ident as _get_ident @@ -50,44 +51,42 @@ self.__map = {} self.__update(*args, **kwds) - def __setitem__(self, key, value, PREV=0, NEXT=1, dict_setitem=dict.__setitem__): + def __setitem__(self, key, value, dict_setitem=dict.__setitem__): 'od.__setitem__(i, y) <==> od[i]=y' # Setting a new item creates a new link at the end of the linked list, # and the inherited dictionary is updated with the new key/value pair. if key not in self: root = self.__root - last = root[PREV] - last[NEXT] = root[PREV] = self.__map[key] = [last, root, key] + last = root[0] + last[1] = root[0] = self.__map[key] = [last, root, key] return dict_setitem(self, key, value) - def __delitem__(self, key, PREV=0, NEXT=1, dict_delitem=dict.__delitem__): + def __delitem__(self, key, dict_delitem=dict.__delitem__): 'od.__delitem__(y) <==> del od[y]' # Deleting an existing item uses self.__map to find the link which gets # removed by updating the links in the predecessor and successor nodes. dict_delitem(self, key) link_prev, link_next, key = self.__map.pop(key) - link_prev[NEXT] = link_next - link_next[PREV] = link_prev + link_prev[1] = link_next # update link_prev[NEXT] + link_next[0] = link_prev # update link_next[PREV] def __iter__(self): 'od.__iter__() <==> iter(od)' # Traverse the linked list in order. - NEXT, KEY = 1, 2 root = self.__root - curr = root[NEXT] + curr = root[1] # start at the first node while curr is not root: - yield curr[KEY] - curr = curr[NEXT] + yield curr[2] # yield the curr[KEY] + curr = curr[1] # move to next node def __reversed__(self): 'od.__reversed__() <==> reversed(od)' # Traverse the linked list in reverse order. - PREV, KEY = 0, 2 root = self.__root - curr = root[PREV] + curr = root[0] # start at the last node while curr is not root: - yield curr[KEY] - curr = curr[PREV] + yield curr[2] # yield the curr[KEY] + curr = curr[0] # move to previous node def clear(self): 'od.clear() -> None. Remove all items from od.' @@ -206,7 +205,7 @@ ''' if isinstance(other, OrderedDict): - return len(self)==len(other) and self.items() == other.items() + return dict.__eq__(self, other) and all(_imap(_eq, self, other)) return dict.__eq__(self, other) def __ne__(self, other): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 07:39:02 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 07:39:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Have_BSD_=27make_-s=27_do_?= =?utf-8?q?the_right_thing=2C_thanks_to_Daniel_Shahaf?= Message-ID: <3YDfnL6021zNG2@mail.python.org> http://hg.python.org/cpython/rev/50af56c27b9a changeset: 80671:50af56c27b9a parent: 80669:2c04d2102534 user: Christian Heimes date: Sun Dec 02 07:37:35 2012 +0100 summary: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf files: Makefile.pre.in | 5 +++-- Misc/ACKS | 1 + Misc/NEWS | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -478,11 +478,12 @@ $(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars # Build the shared modules -# MAKEFLAGS are sorted and normalized. Under GNU make the 's' for +# Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for # -s, --silent or --quiet is always the first char. +# Under BSD make, MAKEFLAGS might be " -s -v x=y". sharedmods: $(BUILDPYTHON) pybuilddir.txt @case "$$MAKEFLAGS" in \ - s*) quiet="-q";; \ + *\ -s*|s*) quiet="-q";; \ *) quiet="";; \ esac; \ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1075,6 +1075,7 @@ Pete Sevander Denis Severson Ian Seyer +Daniel Shahaf Ha Shao Mark Shannon Richard Shapiro diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -408,6 +408,8 @@ Build ----- +- Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf + - Issue #16262: fix out-of-src-tree builds, if mercurial is not installed. - Issue #15298: ensure _sysconfigdata is generated in build directory, not -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 07:56:52 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 07:56:52 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316592=3A_stringli?= =?utf-8?q?b=5Fbytes=5Fjoin_doesn=27t_raise_MemoryError_on_allocation?= Message-ID: <3YDg9w52qKzNGR@mail.python.org> http://hg.python.org/cpython/rev/9af5a2611202 changeset: 80672:9af5a2611202 user: Christian Heimes date: Sun Dec 02 07:56:42 2012 +0100 summary: Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation failure files: Misc/NEWS | 3 +++ Objects/stringlib/join.h | 1 + 2 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation + failure. + - Issue #16546: Fix: ast.YieldFrom argument is now mandatory. - Issue #16514: Fix regression causing a traceback when sys.path[0] is None diff --git a/Objects/stringlib/join.h b/Objects/stringlib/join.h --- a/Objects/stringlib/join.h +++ b/Objects/stringlib/join.h @@ -43,6 +43,7 @@ buffers = PyMem_NEW(Py_buffer, seqlen); if (buffers == NULL) { Py_DECREF(seq); + PyErr_NoMemory(); return NULL; } } -- Repository URL: http://hg.python.org/cpython From ncoghlan at gmail.com Sun Dec 2 08:08:28 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 2 Dec 2012 17:08:28 +1000 Subject: [Python-checkins] cpython: Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation In-Reply-To: <3YDg9w52qKzNGR@mail.python.org> References: <3YDg9w52qKzNGR@mail.python.org> Message-ID: On Sun, Dec 2, 2012 at 4:56 PM, christian.heimes wrote: > http://hg.python.org/cpython/rev/9af5a2611202 > changeset: 80672:9af5a2611202 > user: Christian Heimes > date: Sun Dec 02 07:56:42 2012 +0100 > summary: > Issue #16592: stringlib_bytes_join doesn't raise MemoryError on > allocation failure > > files: > Misc/NEWS | 3 +++ > Objects/stringlib/join.h | 1 + > 2 files changed, 4 insertions(+), 0 deletions(-) > > > diff --git a/Misc/NEWS b/Misc/NEWS > --- a/Misc/NEWS > +++ b/Misc/NEWS > @@ -10,6 +10,9 @@ > Core and Builtins > ----------------- > > +- Issue #16592: stringlib_bytes_join doesn't raise MemoryError on > allocation > + failure. > Please don't write NEWS entries in past tense like this - they're annoyingly ambiguous, as it isn't clear whether the entry is describing the reported problem or the fix for the problem. Describing just the new behaviour or the original problem and the fix is much easier to follow. For example: - Issue #16592: stringlib_bytes_join now correctly raises MemoryError on allocation failure. - Issue #16592: stringlib_bytes_join was triggering SystemError on allocation failure. It now correctly raises MemoryError. Issue titles for actual bugs generally don't make good NEWS entries, as they're typically a summary of the problem rather than the solution (RFE's are different, as there the issue title is often a good summary of the proposed change) Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Sun Dec 2 08:26:17 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 08:26:17 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogLSBJc3N1ZSAjMTY1?= =?utf-8?q?93=3A_Have_BSD_=27make_-s=27_do_the_right_thing=2C_thanks_to_Da?= =?utf-8?q?niel_Shahaf?= Message-ID: <3YDgqs1KrHzNGR@mail.python.org> http://hg.python.org/cpython/rev/ceb325fdd54e changeset: 80673:ceb325fdd54e branch: 3.2 parent: 80657:a35ee2d6a4ad user: Christian Heimes date: Sun Dec 02 08:14:50 2012 +0100 summary: - Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf files: Makefile.pre.in | 5 +++-- Misc/NEWS | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -441,11 +441,12 @@ # Build the shared modules -# MAKEFLAGS are sorted and normalized. Under GNU make the 's' for +# Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for # -s, --silent or --quiet is always the first char. +# Under BSD make, MAKEFLAGS might be " -s -v x=y". sharedmods: $(BUILDPYTHON) @case "$$MAKEFLAGS" in \ - s*) quiet="-q";; \ + *\ -s*|s*) quiet="-q";; \ *) quiet="";; \ esac; \ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -706,6 +706,8 @@ Build ----- +- Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf + - Issue #16262: fix out-of-src-tree builds, if mercurial is not installed. - Issue #15923: fix a mistake in asdl_c.py that resulted in a TypeError after -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 08:26:18 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 08:26:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316593=3A_Have_BSD_=27make_-s=27_do_the_right_thing=2C?= =?utf-8?q?_thanks_to_Daniel_Shahaf?= Message-ID: <3YDgqt40RHzNPc@mail.python.org> http://hg.python.org/cpython/rev/323f0aeba89d changeset: 80674:323f0aeba89d branch: 3.3 parent: 80658:cff7995ca7e8 parent: 80673:ceb325fdd54e user: Christian Heimes date: Sun Dec 02 08:23:05 2012 +0100 summary: Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf files: Makefile.pre.in | 5 +++-- Misc/NEWS | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -478,11 +478,12 @@ $(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars # Build the shared modules -# MAKEFLAGS are sorted and normalized. Under GNU make the 's' for +# Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for # -s, --silent or --quiet is always the first char. +# Under BSD make, MAKEFLAGS might be " -s -v x=y". sharedmods: $(BUILDPYTHON) pybuilddir.txt @case "$$MAKEFLAGS" in \ - s*) quiet="-q";; \ + *\ -s*|s*) quiet="-q";; \ *) quiet="";; \ esac; \ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -277,6 +277,8 @@ Build ----- +- Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf + - Issue #16262: fix out-of-src-tree builds, if mercurial is not installed. - Issue #15298: ensure _sysconfigdata is generated in build directory, not -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 08:26:19 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 08:26:19 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogLSBJc3N1ZSAjMTY1?= =?utf-8?q?93=3A_Have_BSD_=27make_-s=27_do_the_right_thing=2C_thanks_to_Da?= =?utf-8?q?niel_Shahaf?= Message-ID: <3YDgqv6F7JzNVm@mail.python.org> http://hg.python.org/cpython/rev/0fa67e3f195d changeset: 80675:0fa67e3f195d branch: 2.7 parent: 80670:c82151aac59a user: Christian Heimes date: Sun Dec 02 08:14:50 2012 +0100 summary: - Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf files: Makefile.pre.in | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -410,11 +410,12 @@ # Build the shared modules -# MAKEFLAGS are sorted and normalized. Under GNU make the 's' for +# Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for # -s, --silent or --quiet is always the first char. +# Under BSD make, MAKEFLAGS might be " -s -v x=y". sharedmods: $(BUILDPYTHON) @case "$$MAKEFLAGS" in \ - s*) quiet="-q";; \ + *\ -s*|s*) quiet="-q";; \ *) quiet="";; \ esac; \ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 08:26:21 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 08:26:21 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_null_merge?= Message-ID: <3YDgqx1pmKzNS4@mail.python.org> http://hg.python.org/cpython/rev/58d831412e67 changeset: 80676:58d831412e67 parent: 80672:9af5a2611202 parent: 80674:323f0aeba89d user: Christian Heimes date: Sun Dec 02 08:26:02 2012 +0100 summary: null merge files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 08:39:44 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 08:39:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NTg4?= =?utf-8?q?=3A_Silence_unused-but-set_warnings_in_Python/thread=5Fpthread?= =?utf-8?q?=2Eh?= Message-ID: <3YDh7N3YtbzNHd@mail.python.org> http://hg.python.org/cpython/rev/280469ce6669 changeset: 80677:280469ce6669 branch: 3.2 parent: 80673:ceb325fdd54e user: Christian Heimes date: Sun Dec 02 08:37:00 2012 +0100 summary: Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h files: Misc/NEWS | 2 ++ Python/thread_pthread.h | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h + - Issue #16306: Fix multiple error messages when unknown command line parameters where passed to the interpreter. Patch by Hieu Nguyen. diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -309,6 +309,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_free_lock(%p) called\n", lock)); if (!thelock) @@ -341,6 +342,7 @@ int status, error = 0; struct timespec ts; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", lock, microseconds, intr_flag)); @@ -391,6 +393,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_release_lock(%p) called\n", lock)); status = sem_post(thelock); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 08:39:45 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 08:39:45 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316588=3A_Silence_unused-but-set_warnings_in_Python/th?= =?utf-8?q?read=5Fpthread=2Eh?= Message-ID: <3YDh7P6FN2zNHd@mail.python.org> http://hg.python.org/cpython/rev/470785a9fdd5 changeset: 80678:470785a9fdd5 branch: 3.3 parent: 80674:323f0aeba89d parent: 80677:280469ce6669 user: Christian Heimes date: Sun Dec 02 08:38:42 2012 +0100 summary: Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h files: Misc/NEWS | 2 ++ Python/thread_pthread.h | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ Core and Builtins ----------------- +- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread + - Issue #16546: Fix: ast.YieldFrom argument is now mandatory. - Issue #16514: Fix regression causing a traceback when sys.path[0] is None diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -303,6 +303,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_free_lock(%p) called\n", lock)); if (!thelock) @@ -335,6 +336,7 @@ int status, error = 0; struct timespec ts; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", lock, microseconds, intr_flag)); @@ -385,6 +387,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_release_lock(%p) called\n", lock)); status = sem_post(thelock); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 08:39:47 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 08:39:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316588=3A_Silence_unused-but-set_warnings_in_Pyt?= =?utf-8?q?hon/thread=5Fpthread=2Eh?= Message-ID: <3YDh7R1kyHzNbK@mail.python.org> http://hg.python.org/cpython/rev/33b070ef0bad changeset: 80679:33b070ef0bad parent: 80676:58d831412e67 parent: 80678:470785a9fdd5 user: Christian Heimes date: Sun Dec 02 08:39:23 2012 +0100 summary: Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h files: Misc/NEWS | 2 ++ Python/thread_pthread.h | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread + - Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation failure. diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -303,6 +303,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_free_lock(%p) called\n", lock)); if (!thelock) @@ -335,6 +336,7 @@ int status, error = 0; struct timespec ts; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_acquire_lock_timed(%p, %lld, %d) called\n", lock, microseconds, intr_flag)); @@ -385,6 +387,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_release_lock(%p) called\n", lock)); status = sem_post(thelock); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 09:33:28 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 09:33:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_reject_pep_369=2E_It=27s_outd?= =?utf-8?q?ated_and_superseded_by_the_new_importlib?= Message-ID: <3YDjKN22C8zNSW@mail.python.org> http://hg.python.org/peps/rev/08a5ecc86296 changeset: 4591:08a5ecc86296 user: Christian Heimes date: Sun Dec 02 09:32:28 2012 +0100 summary: reject pep 369. It's outdated and superseded by the new importlib files: pep-0369.txt | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pep-0369.txt b/pep-0369.txt --- a/pep-0369.txt +++ b/pep-0369.txt @@ -3,12 +3,18 @@ Version: $Revision$ Last-Modified: $Date$ Author: Christian Heimes -Status: Draft +Status: Rejected Type: Standards Track Content-Type: text/x-rst Created: 02-Jan-2008 Python-Version: 2.6, 3.0 -Post-History: +Post-History: 02-Dec-2012 + +Rejection Notice +================ + +This PEP is rejected by its author, because it has been superseded by the new +importlib. Abstract -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sun Dec 2 09:35:50 2012 From: python-checkins at python.org (christian.heimes) Date: Sun, 2 Dec 2012 09:35:50 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_update_my_email_address_to_?= =?utf-8?q?=40python=2Eorg?= Message-ID: <3YDjN662YDzNTy@mail.python.org> http://hg.python.org/peps/rev/2b0ff65e8872 changeset: 4592:2b0ff65e8872 user: Christian Heimes date: Sun Dec 02 09:35:44 2012 +0100 summary: update my email address to @python.org files: pep-0369.txt | 2 +- pep-0370.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pep-0369.txt b/pep-0369.txt --- a/pep-0369.txt +++ b/pep-0369.txt @@ -2,7 +2,7 @@ Title: Post import hooks Version: $Revision$ Last-Modified: $Date$ -Author: Christian Heimes +Author: Christian Heimes Status: Rejected Type: Standards Track Content-Type: text/x-rst diff --git a/pep-0370.txt b/pep-0370.txt --- a/pep-0370.txt +++ b/pep-0370.txt @@ -2,7 +2,7 @@ Title: Per user site-packages directory Version: $Revision$ Last-Modified: $Date$ -Author: Christian Heimes +Author: Christian Heimes Status: Final Type: Standards Track Content-Type: text/x-rst -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Sun Dec 2 10:59:21 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 2 Dec 2012 10:59:21 +0100 Subject: [Python-checkins] cpython: Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation References: <3YDg9w52qKzNGR@mail.python.org> Message-ID: <20121202105921.22ddce60@pitrou.net> On Sun, 2 Dec 2012 17:08:28 +1000 Nick Coghlan wrote: > On Sun, Dec 2, 2012 at 4:56 PM, christian.heimes > wrote: > > > http://hg.python.org/cpython/rev/9af5a2611202 > > changeset: 80672:9af5a2611202 > > user: Christian Heimes > > date: Sun Dec 02 07:56:42 2012 +0100 > > summary: > > Issue #16592: stringlib_bytes_join doesn't raise MemoryError on > > allocation failure > > > > files: > > Misc/NEWS | 3 +++ > > Objects/stringlib/join.h | 1 + > > 2 files changed, 4 insertions(+), 0 deletions(-) > > > > > > diff --git a/Misc/NEWS b/Misc/NEWS > > --- a/Misc/NEWS > > +++ b/Misc/NEWS > > @@ -10,6 +10,9 @@ > > Core and Builtins > > ----------------- > > > > +- Issue #16592: stringlib_bytes_join doesn't raise MemoryError on > > allocation > > + failure. > > > > Please don't write NEWS entries in past tense like this - they're > annoyingly ambiguous, as it isn't clear whether the entry is describing the > reported problem or the fix for the problem. Do you mean present tense? Agreed otherwise. cheers Antoine. From python-checkins at python.org Sun Dec 2 12:56:37 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 2 Dec 2012 12:56:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzEwMTgy?= =?utf-8?q?=3A_The_re_module_doesn=27t_truncate_indices_to_32_bits_anymore?= =?utf-8?q?=2E?= Message-ID: <3YDnqn2BvfzNBQ@mail.python.org> http://hg.python.org/cpython/rev/0edc92d78192 changeset: 80680:0edc92d78192 branch: 3.2 parent: 80677:280469ce6669 user: Antoine Pitrou date: Sun Dec 02 12:52:36 2012 +0100 summary: Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. files: Lib/test/test_re.py | 17 ++++++++++++++++- Misc/NEWS | 3 +++ Modules/_sre.c | 10 +++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1,4 +1,4 @@ -from test.support import verbose, run_unittest, gc_collect +from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G import io import re from re import Scanner @@ -854,6 +854,21 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + # The huge memuse is because of re.sub() using a list and a join() + # to create the replacement result. + @bigmemtest(size=_2G, memuse=20) + def test_large(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) + r, n = re.subn('', '', s) + self.assertEqual(r, s) + self.assertEqual(n, size + 1) + + def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR if verbose: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -169,6 +169,9 @@ Library ------- +- Issue #10182: The re module doesn't truncate indices to 32 bits anymore. + Patch by Serhiy Storchaka. + - Issue #16573: In 2to3, treat enumerate() like a consuming call, so superfluous list() calls aren't added to filter(), map(), and zip() which are directly passed enumerate(). diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1629,7 +1629,7 @@ static PyObject * sre_codesize(PyObject* self, PyObject *unused) { - return Py_BuildValue("l", sizeof(SRE_CODE)); + return PyLong_FromSize_t(sizeof(SRE_CODE)); } static PyObject * @@ -2467,7 +2467,7 @@ return NULL; if (subn) - return Py_BuildValue("Ni", item, n); + return Py_BuildValue("Nn", item, n); return item; @@ -3423,7 +3423,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2]); + return PyLong_FromSsize_t(self->mark[index*2]); } static PyObject* @@ -3446,7 +3446,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2+1]); + return PyLong_FromSsize_t(self->mark[index*2+1]); } LOCAL(PyObject*) @@ -3596,7 +3596,7 @@ match_lastindex_get(MatchObject *self) { if (self->lastindex >= 0) - return Py_BuildValue("i", self->lastindex); + return PyLong_FromSsize_t(self->lastindex); Py_INCREF(Py_None); return Py_None; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 12:56:38 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 2 Dec 2012 12:56:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2310182=3A_The_re_module_doesn=27t_truncate_indices_to_?= =?utf-8?q?32_bits_anymore=2E?= Message-ID: <3YDnqp4tGSzNPd@mail.python.org> http://hg.python.org/cpython/rev/21ceee08a375 changeset: 80681:21ceee08a375 branch: 3.3 parent: 80678:470785a9fdd5 parent: 80680:0edc92d78192 user: Antoine Pitrou date: Sun Dec 02 12:54:28 2012 +0100 summary: Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. files: Lib/test/test_re.py | 17 ++++++++++++++++- Misc/NEWS | 3 +++ Modules/_sre.c | 10 +++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1,4 +1,4 @@ -from test.support import verbose, run_unittest, gc_collect +from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G import io import re from re import Scanner @@ -949,6 +949,21 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + # The huge memuse is because of re.sub() using a list and a join() + # to create the replacement result. + @bigmemtest(size=_2G, memuse=20) + def test_large(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) + r, n = re.subn('', '', s) + self.assertEqual(r, s) + self.assertEqual(n, size + 1) + + def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR if verbose: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -98,6 +98,9 @@ Library ------- +- Issue #10182: The re module doesn't truncate indices to 32 bits anymore. + Patch by Serhiy Storchaka. + - Issue #16573: In 2to3, treat enumerate() like a consuming call, so superfluous list() calls aren't added to filter(), map(), and zip() which are directly passed enumerate(). diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1618,7 +1618,7 @@ static PyObject * sre_codesize(PyObject* self, PyObject *unused) { - return Py_BuildValue("l", sizeof(SRE_CODE)); + return PyLong_FromSize_t(sizeof(SRE_CODE)); } static PyObject * @@ -2435,7 +2435,7 @@ return NULL; if (subn) - return Py_BuildValue("Ni", item, n); + return Py_BuildValue("Nn", item, n); return item; @@ -3387,7 +3387,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2]); + return PyLong_FromSsize_t(self->mark[index*2]); } static PyObject* @@ -3410,7 +3410,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2+1]); + return PyLong_FromSsize_t(self->mark[index*2+1]); } LOCAL(PyObject*) @@ -3560,7 +3560,7 @@ match_lastindex_get(MatchObject *self) { if (self->lastindex >= 0) - return Py_BuildValue("i", self->lastindex); + return PyLong_FromSsize_t(self->lastindex); Py_INCREF(Py_None); return Py_None; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 12:56:40 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 2 Dec 2012 12:56:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2310182=3A_The_re_module_doesn=27t_truncate_indic?= =?utf-8?q?es_to_32_bits_anymore=2E?= Message-ID: <3YDnqr0KWdzNcB@mail.python.org> http://hg.python.org/cpython/rev/e7104cc09d02 changeset: 80682:e7104cc09d02 parent: 80679:33b070ef0bad parent: 80681:21ceee08a375 user: Antoine Pitrou date: Sun Dec 02 12:55:12 2012 +0100 summary: Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. files: Lib/test/test_re.py | 17 ++++++++++++++++- Misc/NEWS | 3 +++ Modules/_sre.c | 10 +++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1,4 +1,4 @@ -from test.support import verbose, run_unittest, gc_collect +from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G import io import re from re import Scanner @@ -949,6 +949,21 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + # The huge memuse is because of re.sub() using a list and a join() + # to create the replacement result. + @bigmemtest(size=_2G, memuse=20) + def test_large(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) + r, n = re.subn('', '', s) + self.assertEqual(r, s) + self.assertEqual(n, size + 1) + + def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR if verbose: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -145,6 +145,9 @@ Library ------- +- Issue #10182: The re module doesn't truncate indices to 32 bits anymore. + Patch by Serhiy Storchaka. + - Issue #16333: use (",", ": ") as default separator when indent is specified to avoid trailing whitespace. Patch by Serhiy Storchaka. diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1618,7 +1618,7 @@ static PyObject * sre_codesize(PyObject* self, PyObject *unused) { - return Py_BuildValue("l", sizeof(SRE_CODE)); + return PyLong_FromSize_t(sizeof(SRE_CODE)); } static PyObject * @@ -2435,7 +2435,7 @@ return NULL; if (subn) - return Py_BuildValue("Ni", item, n); + return Py_BuildValue("Nn", item, n); return item; @@ -3387,7 +3387,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2]); + return PyLong_FromSsize_t(self->mark[index*2]); } static PyObject* @@ -3410,7 +3410,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2+1]); + return PyLong_FromSsize_t(self->mark[index*2+1]); } LOCAL(PyObject*) @@ -3560,7 +3560,7 @@ match_lastindex_get(MatchObject *self) { if (self->lastindex >= 0) - return Py_BuildValue("i", self->lastindex); + return PyLong_FromSsize_t(self->lastindex); Py_INCREF(Py_None); return Py_None; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 13:01:09 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 2 Dec 2012 13:01:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzEwMTgy?= =?utf-8?q?=3A_The_re_module_doesn=27t_truncate_indices_to_32_bits_anymore?= =?utf-8?q?=2E?= Message-ID: <3YDnx16mt4zNP4@mail.python.org> http://hg.python.org/cpython/rev/de0f38f9280e changeset: 80683:de0f38f9280e branch: 2.7 parent: 80675:0fa67e3f195d user: Antoine Pitrou date: Sun Dec 02 12:52:36 2012 +0100 summary: Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. files: Lib/test/test_re.py | 16 ++++++++++++++++ Misc/NEWS | 3 +++ Modules/_sre.c | 10 +++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1,4 +1,5 @@ from test.test_support import verbose, run_unittest, import_module +from test.test_support import precisionbigmemtest, _2G import re from re import Scanner import sys @@ -819,6 +820,21 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + # The huge memuse is because of re.sub() using a list and a join() + # to create the replacement result. + @precisionbigmemtest(size=_2G, memuse=20) + def test_large(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) + r, n = re.subn('', '', s) + self.assertEqual(r, s) + self.assertEqual(n, size + 1) + + def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR if verbose: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -154,6 +154,9 @@ Library ------- +- Issue #10182: The re module doesn't truncate indices to 32 bits anymore. + Patch by Serhiy Storchaka. + - Issue #16573: In 2to3, treat enumerate() like a consuming call, so superfluous list() calls aren't added to filter(), map(), and zip() which are directly passed enumerate(). diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -1636,7 +1636,7 @@ static PyObject * sre_codesize(PyObject* self, PyObject *unused) { - return Py_BuildValue("l", sizeof(SRE_CODE)); + return PyLong_FromSize_t(sizeof(SRE_CODE)); } static PyObject * @@ -2448,7 +2448,7 @@ return NULL; if (subn) - return Py_BuildValue("Ni", item, n); + return Py_BuildValue("Nn", item, n); return item; @@ -3389,7 +3389,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2]); + return PyLong_FromSsize_t(self->mark[index*2]); } static PyObject* @@ -3412,7 +3412,7 @@ } /* mark is -1 if group is undefined */ - return Py_BuildValue("i", self->mark[index*2+1]); + return PyLong_FromSsize_t(self->mark[index*2+1]); } LOCAL(PyObject*) @@ -3562,7 +3562,7 @@ match_lastindex_get(MatchObject *self) { if (self->lastindex >= 0) - return Py_BuildValue("i", self->lastindex); + return PyLong_FromSsize_t(self->lastindex); Py_INCREF(Py_None); return Py_None; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 13:11:51 2012 From: python-checkins at python.org (mark.dickinson) Date: Sun, 2 Dec 2012 13:11:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_10052=3A_fix_failed_?= =?utf-8?q?uint32=5Ft_/_uint64=5Ft_/_int32=5Ft_/_int64=5Ft_detection_on?= Message-ID: <3YDp9M09PSzPcV@mail.python.org> http://hg.python.org/cpython/rev/6f9aba5f8d32 changeset: 80684:6f9aba5f8d32 parent: 80682:e7104cc09d02 user: Mark Dickinson date: Sun Dec 02 12:11:38 2012 +0000 summary: Issue 10052: fix failed uint32_t / uint64_t / int32_t / int64_t detection on some platforms. files: Include/pyport.h | 29 ++++++++++++++++++------- configure | 40 ++++++++++++++++++++++++++++++++++++ configure.ac | 20 ++++++++++++++++++ pyconfig.h.in | 12 ++++++++++ 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -87,9 +87,12 @@ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t. * However, it doesn't set HAVE_UINT32_T, so we do that here. */ -#if (defined UINT32_MAX || defined uint32_t) +#ifdef uint32_t +#define HAVE_UINT32_T 1 +#endif + +#ifdef HAVE_UINT32_T #ifndef PY_UINT32_T -#define HAVE_UINT32_T 1 #define PY_UINT32_T uint32_t #endif #endif @@ -97,23 +100,33 @@ /* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the * long integer implementation, when 30-bit digits are enabled. */ -#if (defined UINT64_MAX || defined uint64_t) +#ifdef uint64_t +#define HAVE_UINT64_T 1 +#endif + +#ifdef HAVE_UINT64_T #ifndef PY_UINT64_T -#define HAVE_UINT64_T 1 #define PY_UINT64_T uint64_t #endif #endif /* Signed variants of the above */ -#if (defined INT32_MAX || defined int32_t) +#ifdef int32_t +#define HAVE_INT32_T 1 +#endif + +#ifdef HAVE_INT32_T #ifndef PY_INT32_T -#define HAVE_INT32_T 1 #define PY_INT32_T int32_t #endif #endif -#if (defined INT64_MAX || defined int64_t) + +#ifdef int64_t +#define HAVE_INT64_T 1 +#endif + +#ifdef HAVE_INT64_T #ifndef PY_INT64_T -#define HAVE_INT64_T 1 #define PY_INT64_T int64_t #endif #endif diff --git a/configure b/configure --- a/configure +++ b/configure @@ -7433,6 +7433,21 @@ fi + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +ac_fn_c_check_type "$LINENO" "uint32_t" "ac_cv_type_uint32_t" "$ac_includes_default" +if test "x$ac_cv_type_uint32_t" = xyes; then : + +$as_echo "#define HAVE_UINT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "32" "ac_cv_c_uint32_t" case $ac_cv_c_uint32_t in #( no|yes) ;; #( @@ -7447,6 +7462,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "uint64_t" "ac_cv_type_uint64_t" "$ac_includes_default" +if test "x$ac_cv_type_uint64_t" = xyes; then : + +$as_echo "#define HAVE_UINT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "64" "ac_cv_c_uint64_t" case $ac_cv_c_uint64_t in #( no|yes) ;; #( @@ -7461,6 +7484,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int32_t" "ac_cv_type_int32_t" "$ac_includes_default" +if test "x$ac_cv_type_int32_t" = xyes; then : + +$as_echo "#define HAVE_INT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "32" "ac_cv_c_int32_t" case $ac_cv_c_int32_t in #( no|yes) ;; #( @@ -7472,6 +7503,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int64_t" "ac_cv_type_int64_t" "$ac_includes_default" +if test "x$ac_cv_type_int64_t" = xyes; then : + +$as_echo "#define HAVE_INT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "64" "ac_cv_c_int64_t" case $ac_cv_c_int64_t in #( no|yes) ;; #( @@ -7483,6 +7522,7 @@ ;; esac + ac_fn_c_check_type "$LINENO" "ssize_t" "ac_cv_type_ssize_t" "$ac_includes_default" if test "x$ac_cv_type_ssize_t" = xyes; then : diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1638,10 +1638,30 @@ AC_DEFINE_UNQUOTED([RETSIGTYPE],[void],[assume C89 semantics that RETSIGTYPE is always void]) AC_TYPE_SIZE_T AC_TYPE_UID_T + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +AC_CHECK_TYPE(uint32_t, + AC_DEFINE(HAVE_UINT32_T, 1, [Define if your compiler provides uint32_t.]),,) AC_TYPE_UINT32_T + +AC_CHECK_TYPE(uint64_t, + AC_DEFINE(HAVE_UINT64_T, 1, [Define if your compiler provides uint64_t.]),,) AC_TYPE_UINT64_T + +AC_CHECK_TYPE(int32_t, + AC_DEFINE(HAVE_INT32_T, 1, [Define if your compiler provides int32_t.]),,) AC_TYPE_INT32_T + +AC_CHECK_TYPE(int64_t, + AC_DEFINE(HAVE_INT64_T, 1, [Define if your compiler provides int64_t.]),,) AC_TYPE_INT64_T + AC_CHECK_TYPE(ssize_t, AC_DEFINE(HAVE_SSIZE_T, 1, [Define if your compiler provides ssize_t]),,) AC_CHECK_TYPE(__uint128_t, diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -426,6 +426,12 @@ /* Define to 1 if you have the `initgroups' function. */ #undef HAVE_INITGROUPS +/* Define if your compiler provides int32_t. */ +#undef HAVE_INT32_T + +/* Define if your compiler provides int64_t. */ +#undef HAVE_INT64_T + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H @@ -1047,6 +1053,12 @@ /* Define this if you have tcl and TCL_UTF_MAX==6 */ #undef HAVE_UCS4_TCL +/* Define if your compiler provides uint32_t. */ +#undef HAVE_UINT32_T + +/* Define if your compiler provides uint64_t. */ +#undef HAVE_UINT64_T + /* Define to 1 if the system has the type `uintptr_t'. */ #undef HAVE_UINTPTR_T -- Repository URL: http://hg.python.org/cpython From ncoghlan at gmail.com Sun Dec 2 12:58:16 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Sun, 2 Dec 2012 21:58:16 +1000 Subject: [Python-checkins] cpython: Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation In-Reply-To: <20121202105921.22ddce60@pitrou.net> References: <3YDg9w52qKzNGR@mail.python.org> <20121202105921.22ddce60@pitrou.net> Message-ID: On Sun, Dec 2, 2012 at 7:59 PM, Antoine Pitrou wrote: > Do you mean present tense? > Ah, you're right - my main objection is to describing the old broken behaviour, without describing the *new* behaviour. Any use of present tense should relate to the new behaviour after the commit. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Sun Dec 2 14:16:02 2012 From: python-checkins at python.org (mark.dickinson) Date: Sun, 2 Dec 2012 14:16:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgMTAwNTI6?= =?utf-8?q?_fix_failed_uint32=5Ft_/_uint64=5Ft_/_int32=5Ft_/_int64=5Ft_det?= =?utf-8?q?ection_on?= Message-ID: <3YDqbQ2ZC0zN8g@mail.python.org> http://hg.python.org/cpython/rev/48fbe78167cd changeset: 80685:48fbe78167cd branch: 2.7 parent: 80683:de0f38f9280e user: Mark Dickinson date: Sun Dec 02 13:13:56 2012 +0000 summary: Issue 10052: fix failed uint32_t / uint64_t / int32_t / int64_t detection on some platforms. files: Include/pyport.h | 29 ++++++++++++++++++------- configure | 40 ++++++++++++++++++++++++++++++++++++ configure.ac | 20 ++++++++++++++++++ pyconfig.h.in | 12 ++++++++++ 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -93,9 +93,12 @@ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t. * However, it doesn't set HAVE_UINT32_T, so we do that here. */ -#if (defined UINT32_MAX || defined uint32_t) +#ifdef uint32_t +#define HAVE_UINT32_T 1 +#endif + +#ifdef HAVE_UINT32_T #ifndef PY_UINT32_T -#define HAVE_UINT32_T 1 #define PY_UINT32_T uint32_t #endif #endif @@ -103,23 +106,33 @@ /* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the * long integer implementation, when 30-bit digits are enabled. */ -#if (defined UINT64_MAX || defined uint64_t) +#ifdef uint64_t +#define HAVE_UINT64_T 1 +#endif + +#ifdef HAVE_UINT64_T #ifndef PY_UINT64_T -#define HAVE_UINT64_T 1 #define PY_UINT64_T uint64_t #endif #endif /* Signed variants of the above */ -#if (defined INT32_MAX || defined int32_t) +#ifdef int32_t +#define HAVE_INT32_T 1 +#endif + +#ifdef HAVE_INT32_T #ifndef PY_INT32_T -#define HAVE_INT32_T 1 #define PY_INT32_T int32_t #endif #endif -#if (defined INT64_MAX || defined int64_t) + +#ifdef int64_t +#define HAVE_INT64_T 1 +#endif + +#ifdef HAVE_INT64_T #ifndef PY_INT64_T -#define HAVE_INT64_T 1 #define PY_INT64_T int64_t #endif #endif diff --git a/configure b/configure --- a/configure +++ b/configure @@ -6703,6 +6703,21 @@ fi + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +ac_fn_c_check_type "$LINENO" "uint32_t" "ac_cv_type_uint32_t" "$ac_includes_default" +if test "x$ac_cv_type_uint32_t" = xyes; then : + +$as_echo "#define HAVE_UINT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "32" "ac_cv_c_uint32_t" case $ac_cv_c_uint32_t in #( no|yes) ;; #( @@ -6717,6 +6732,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "uint64_t" "ac_cv_type_uint64_t" "$ac_includes_default" +if test "x$ac_cv_type_uint64_t" = xyes; then : + +$as_echo "#define HAVE_UINT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "64" "ac_cv_c_uint64_t" case $ac_cv_c_uint64_t in #( no|yes) ;; #( @@ -6731,6 +6754,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int32_t" "ac_cv_type_int32_t" "$ac_includes_default" +if test "x$ac_cv_type_int32_t" = xyes; then : + +$as_echo "#define HAVE_INT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "32" "ac_cv_c_int32_t" case $ac_cv_c_int32_t in #( no|yes) ;; #( @@ -6742,6 +6773,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int64_t" "ac_cv_type_int64_t" "$ac_includes_default" +if test "x$ac_cv_type_int64_t" = xyes; then : + +$as_echo "#define HAVE_INT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "64" "ac_cv_c_int64_t" case $ac_cv_c_int64_t in #( no|yes) ;; #( @@ -6753,6 +6792,7 @@ ;; esac + ac_fn_c_check_type "$LINENO" "ssize_t" "ac_cv_type_ssize_t" "$ac_includes_default" if test "x$ac_cv_type_ssize_t" = xyes; then : diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1517,10 +1517,30 @@ AC_DEFINE_UNQUOTED([RETSIGTYPE],[void],[assume C89 semantics that RETSIGTYPE is always void]) AC_TYPE_SIZE_T AC_TYPE_UID_T + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +AC_CHECK_TYPE(uint32_t, + AC_DEFINE(HAVE_UINT32_T, 1, [Define if your compiler provides uint32_t.]),,) AC_TYPE_UINT32_T + +AC_CHECK_TYPE(uint64_t, + AC_DEFINE(HAVE_UINT64_T, 1, [Define if your compiler provides uint64_t.]),,) AC_TYPE_UINT64_T + +AC_CHECK_TYPE(int32_t, + AC_DEFINE(HAVE_INT32_T, 1, [Define if your compiler provides int32_t.]),,) AC_TYPE_INT32_T + +AC_CHECK_TYPE(int64_t, + AC_DEFINE(HAVE_INT64_T, 1, [Define if your compiler provides int64_t.]),,) AC_TYPE_INT64_T + AC_CHECK_TYPE(ssize_t, AC_DEFINE(HAVE_SSIZE_T, 1, [Define if your compiler provides ssize_t]),,) diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -370,6 +370,12 @@ /* Define to 1 if you have the `initgroups' function. */ #undef HAVE_INITGROUPS +/* Define if your compiler provides int32_t. */ +#undef HAVE_INT32_T + +/* Define if your compiler provides int64_t. */ +#undef HAVE_INT64_T + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H @@ -847,6 +853,12 @@ /* Define this if you have tcl and TCL_UTF_MAX==6 */ #undef HAVE_UCS4_TCL +/* Define if your compiler provides uint32_t. */ +#undef HAVE_UINT32_T + +/* Define if your compiler provides uint64_t. */ +#undef HAVE_UINT64_T + /* Define to 1 if the system has the type `uintptr_t'. */ #undef HAVE_UINTPTR_T -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 14:22:57 2012 From: python-checkins at python.org (mark.dickinson) Date: Sun, 2 Dec 2012 14:22:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgMTAwNTI6?= =?utf-8?q?_fix_failed_uint32=5Ft_/_uint64=5Ft_/_int32=5Ft_/_int64=5Ft_det?= =?utf-8?q?ection_on?= Message-ID: <3YDqlP2M6LzNHf@mail.python.org> http://hg.python.org/cpython/rev/d82b73366227 changeset: 80686:d82b73366227 branch: 3.2 parent: 80680:0edc92d78192 user: Mark Dickinson date: Sun Dec 02 13:20:22 2012 +0000 summary: Issue 10052: fix failed uint32_t / uint64_t / int32_t / int64_t detection on some platforms. files: Include/pyport.h | 29 ++++++++++++++++++------- configure | 40 ++++++++++++++++++++++++++++++++++++ configure.ac | 20 ++++++++++++++++++ pyconfig.h.in | 12 ++++++++++ 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -87,9 +87,12 @@ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t. * However, it doesn't set HAVE_UINT32_T, so we do that here. */ -#if (defined UINT32_MAX || defined uint32_t) +#ifdef uint32_t +#define HAVE_UINT32_T 1 +#endif + +#ifdef HAVE_UINT32_T #ifndef PY_UINT32_T -#define HAVE_UINT32_T 1 #define PY_UINT32_T uint32_t #endif #endif @@ -97,23 +100,33 @@ /* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the * long integer implementation, when 30-bit digits are enabled. */ -#if (defined UINT64_MAX || defined uint64_t) +#ifdef uint64_t +#define HAVE_UINT64_T 1 +#endif + +#ifdef HAVE_UINT64_T #ifndef PY_UINT64_T -#define HAVE_UINT64_T 1 #define PY_UINT64_T uint64_t #endif #endif /* Signed variants of the above */ -#if (defined INT32_MAX || defined int32_t) +#ifdef int32_t +#define HAVE_INT32_T 1 +#endif + +#ifdef HAVE_INT32_T #ifndef PY_INT32_T -#define HAVE_INT32_T 1 #define PY_INT32_T int32_t #endif #endif -#if (defined INT64_MAX || defined int64_t) + +#ifdef int64_t +#define HAVE_INT64_T 1 +#endif + +#ifdef HAVE_INT64_T #ifndef PY_INT64_T -#define HAVE_INT64_T 1 #define PY_INT64_T int64_t #endif #endif diff --git a/configure b/configure --- a/configure +++ b/configure @@ -6755,6 +6755,21 @@ fi + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +ac_fn_c_check_type "$LINENO" "uint32_t" "ac_cv_type_uint32_t" "$ac_includes_default" +if test "x$ac_cv_type_uint32_t" = xyes; then : + +$as_echo "#define HAVE_UINT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "32" "ac_cv_c_uint32_t" case $ac_cv_c_uint32_t in #( no|yes) ;; #( @@ -6769,6 +6784,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "uint64_t" "ac_cv_type_uint64_t" "$ac_includes_default" +if test "x$ac_cv_type_uint64_t" = xyes; then : + +$as_echo "#define HAVE_UINT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "64" "ac_cv_c_uint64_t" case $ac_cv_c_uint64_t in #( no|yes) ;; #( @@ -6783,6 +6806,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int32_t" "ac_cv_type_int32_t" "$ac_includes_default" +if test "x$ac_cv_type_int32_t" = xyes; then : + +$as_echo "#define HAVE_INT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "32" "ac_cv_c_int32_t" case $ac_cv_c_int32_t in #( no|yes) ;; #( @@ -6794,6 +6825,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int64_t" "ac_cv_type_int64_t" "$ac_includes_default" +if test "x$ac_cv_type_int64_t" = xyes; then : + +$as_echo "#define HAVE_INT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "64" "ac_cv_c_int64_t" case $ac_cv_c_int64_t in #( no|yes) ;; #( @@ -6805,6 +6844,7 @@ ;; esac + ac_fn_c_check_type "$LINENO" "ssize_t" "ac_cv_type_ssize_t" "$ac_includes_default" if test "x$ac_cv_type_ssize_t" = xyes; then : diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1469,10 +1469,30 @@ AC_DEFINE_UNQUOTED([RETSIGTYPE],[void],[assume C89 semantics that RETSIGTYPE is always void]) AC_TYPE_SIZE_T AC_TYPE_UID_T + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +AC_CHECK_TYPE(uint32_t, + AC_DEFINE(HAVE_UINT32_T, 1, [Define if your compiler provides uint32_t.]),,) AC_TYPE_UINT32_T + +AC_CHECK_TYPE(uint64_t, + AC_DEFINE(HAVE_UINT64_T, 1, [Define if your compiler provides uint64_t.]),,) AC_TYPE_UINT64_T + +AC_CHECK_TYPE(int32_t, + AC_DEFINE(HAVE_INT32_T, 1, [Define if your compiler provides int32_t.]),,) AC_TYPE_INT32_T + +AC_CHECK_TYPE(int64_t, + AC_DEFINE(HAVE_INT64_T, 1, [Define if your compiler provides int64_t.]),,) AC_TYPE_INT64_T + AC_CHECK_TYPE(ssize_t, AC_DEFINE(HAVE_SSIZE_T, 1, [Define if your compiler provides ssize_t]),,) diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -377,6 +377,12 @@ /* Define to 1 if you have the `initgroups' function. */ #undef HAVE_INITGROUPS +/* Define if your compiler provides int32_t. */ +#undef HAVE_INT32_T + +/* Define if your compiler provides int64_t. */ +#undef HAVE_INT64_T + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H @@ -863,6 +869,12 @@ /* Define this if you have tcl and TCL_UTF_MAX==6 */ #undef HAVE_UCS4_TCL +/* Define if your compiler provides uint32_t. */ +#undef HAVE_UINT32_T + +/* Define if your compiler provides uint64_t. */ +#undef HAVE_UINT64_T + /* Define to 1 if the system has the type `uintptr_t'. */ #undef HAVE_UINTPTR_T -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 14:22:58 2012 From: python-checkins at python.org (mark.dickinson) Date: Sun, 2 Dec 2012 14:22:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_10052=3A_merge_fix_from_3=2E2=2E?= Message-ID: <3YDqlQ6MQwzPjS@mail.python.org> http://hg.python.org/cpython/rev/48de792747dc changeset: 80687:48de792747dc branch: 3.3 parent: 80681:21ceee08a375 parent: 80686:d82b73366227 user: Mark Dickinson date: Sun Dec 02 13:21:37 2012 +0000 summary: Issue 10052: merge fix from 3.2. files: Include/pyport.h | 29 ++++++++++++++++++------- configure | 40 ++++++++++++++++++++++++++++++++++++ configure.ac | 20 ++++++++++++++++++ pyconfig.h.in | 12 ++++++++++ 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -87,9 +87,12 @@ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t. * However, it doesn't set HAVE_UINT32_T, so we do that here. */ -#if (defined UINT32_MAX || defined uint32_t) +#ifdef uint32_t +#define HAVE_UINT32_T 1 +#endif + +#ifdef HAVE_UINT32_T #ifndef PY_UINT32_T -#define HAVE_UINT32_T 1 #define PY_UINT32_T uint32_t #endif #endif @@ -97,23 +100,33 @@ /* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the * long integer implementation, when 30-bit digits are enabled. */ -#if (defined UINT64_MAX || defined uint64_t) +#ifdef uint64_t +#define HAVE_UINT64_T 1 +#endif + +#ifdef HAVE_UINT64_T #ifndef PY_UINT64_T -#define HAVE_UINT64_T 1 #define PY_UINT64_T uint64_t #endif #endif /* Signed variants of the above */ -#if (defined INT32_MAX || defined int32_t) +#ifdef int32_t +#define HAVE_INT32_T 1 +#endif + +#ifdef HAVE_INT32_T #ifndef PY_INT32_T -#define HAVE_INT32_T 1 #define PY_INT32_T int32_t #endif #endif -#if (defined INT64_MAX || defined int64_t) + +#ifdef int64_t +#define HAVE_INT64_T 1 +#endif + +#ifdef HAVE_INT64_T #ifndef PY_INT64_T -#define HAVE_INT64_T 1 #define PY_INT64_T int64_t #endif #endif diff --git a/configure b/configure --- a/configure +++ b/configure @@ -7433,6 +7433,21 @@ fi + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +ac_fn_c_check_type "$LINENO" "uint32_t" "ac_cv_type_uint32_t" "$ac_includes_default" +if test "x$ac_cv_type_uint32_t" = xyes; then : + +$as_echo "#define HAVE_UINT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "32" "ac_cv_c_uint32_t" case $ac_cv_c_uint32_t in #( no|yes) ;; #( @@ -7447,6 +7462,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "uint64_t" "ac_cv_type_uint64_t" "$ac_includes_default" +if test "x$ac_cv_type_uint64_t" = xyes; then : + +$as_echo "#define HAVE_UINT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_uintX_t "$LINENO" "64" "ac_cv_c_uint64_t" case $ac_cv_c_uint64_t in #( no|yes) ;; #( @@ -7461,6 +7484,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int32_t" "ac_cv_type_int32_t" "$ac_includes_default" +if test "x$ac_cv_type_int32_t" = xyes; then : + +$as_echo "#define HAVE_INT32_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "32" "ac_cv_c_int32_t" case $ac_cv_c_int32_t in #( no|yes) ;; #( @@ -7472,6 +7503,14 @@ ;; esac + +ac_fn_c_check_type "$LINENO" "int64_t" "ac_cv_type_int64_t" "$ac_includes_default" +if test "x$ac_cv_type_int64_t" = xyes; then : + +$as_echo "#define HAVE_INT64_T 1" >>confdefs.h + +fi + ac_fn_c_find_intX_t "$LINENO" "64" "ac_cv_c_int64_t" case $ac_cv_c_int64_t in #( no|yes) ;; #( @@ -7483,6 +7522,7 @@ ;; esac + ac_fn_c_check_type "$LINENO" "ssize_t" "ac_cv_type_ssize_t" "$ac_includes_default" if test "x$ac_cv_type_ssize_t" = xyes; then : diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1638,10 +1638,30 @@ AC_DEFINE_UNQUOTED([RETSIGTYPE],[void],[assume C89 semantics that RETSIGTYPE is always void]) AC_TYPE_SIZE_T AC_TYPE_UID_T + +# There are two separate checks for each of the exact-width integer types we +# need. First we check whether the type is available using the usual +# AC_CHECK_TYPE macro with the default includes (which includes +# and where available). We then also use the special type checks of +# the form AC_TYPE_UINT32_T, which in the case that uint32_t is not available +# directly, #define's uint32_t to be a suitable type. + +AC_CHECK_TYPE(uint32_t, + AC_DEFINE(HAVE_UINT32_T, 1, [Define if your compiler provides uint32_t.]),,) AC_TYPE_UINT32_T + +AC_CHECK_TYPE(uint64_t, + AC_DEFINE(HAVE_UINT64_T, 1, [Define if your compiler provides uint64_t.]),,) AC_TYPE_UINT64_T + +AC_CHECK_TYPE(int32_t, + AC_DEFINE(HAVE_INT32_T, 1, [Define if your compiler provides int32_t.]),,) AC_TYPE_INT32_T + +AC_CHECK_TYPE(int64_t, + AC_DEFINE(HAVE_INT64_T, 1, [Define if your compiler provides int64_t.]),,) AC_TYPE_INT64_T + AC_CHECK_TYPE(ssize_t, AC_DEFINE(HAVE_SSIZE_T, 1, [Define if your compiler provides ssize_t]),,) AC_CHECK_TYPE(__uint128_t, diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -426,6 +426,12 @@ /* Define to 1 if you have the `initgroups' function. */ #undef HAVE_INITGROUPS +/* Define if your compiler provides int32_t. */ +#undef HAVE_INT32_T + +/* Define if your compiler provides int64_t. */ +#undef HAVE_INT64_T + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H @@ -1047,6 +1053,12 @@ /* Define this if you have tcl and TCL_UTF_MAX==6 */ #undef HAVE_UCS4_TCL +/* Define if your compiler provides uint32_t. */ +#undef HAVE_UINT32_T + +/* Define if your compiler provides uint64_t. */ +#undef HAVE_UINT64_T + /* Define to 1 if the system has the type `uintptr_t'. */ #undef HAVE_UINTPTR_T -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 14:23:00 2012 From: python-checkins at python.org (mark.dickinson) Date: Sun, 2 Dec 2012 14:23:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_10052=3A_null_merge_from_3=2E3?= Message-ID: <3YDqlS1qgfzNr9@mail.python.org> http://hg.python.org/cpython/rev/22d891a2d533 changeset: 80688:22d891a2d533 parent: 80684:6f9aba5f8d32 parent: 80687:48de792747dc user: Mark Dickinson date: Sun Dec 02 13:22:32 2012 +0000 summary: Issue 10052: null merge from 3.3 files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 16:53:54 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 16:53:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogdW5pY29kZSAtPiBz?= =?utf-8?q?tr?= Message-ID: <3YDv5Z5fg2zNVm@mail.python.org> http://hg.python.org/cpython/rev/b1db531736a3 changeset: 80689:b1db531736a3 branch: 3.3 parent: 80687:48de792747dc user: Benjamin Peterson date: Sun Dec 02 10:53:41 2012 -0500 summary: unicode -> str files: Modules/cjkcodecs/multibytecodec.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -320,7 +320,7 @@ !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) { PyErr_SetString(PyExc_TypeError, "encoding error handler must return " - "(unicode, int) tuple"); + "(str, int) tuple"); goto errorexit; } @@ -439,7 +439,7 @@ !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) { PyErr_SetString(PyExc_TypeError, "decoding error handler must return " - "(unicode, int) tuple"); + "(str, int) tuple"); goto errorexit; } @@ -760,7 +760,7 @@ return NULL; else if (!PyUnicode_Check(unistr)) { PyErr_SetString(PyExc_TypeError, - "couldn't convert the object to unicode."); + "couldn't convert the object to str."); Py_DECREF(ucvt); return NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 16:53:56 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 16:53:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4z?= Message-ID: <3YDv5c18xPzNbK@mail.python.org> http://hg.python.org/cpython/rev/12cd1c8a6bb0 changeset: 80690:12cd1c8a6bb0 parent: 80688:22d891a2d533 parent: 80689:b1db531736a3 user: Benjamin Peterson date: Sun Dec 02 10:53:48 2012 -0500 summary: merge 3.3 files: Modules/cjkcodecs/multibytecodec.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -320,7 +320,7 @@ !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) { PyErr_SetString(PyExc_TypeError, "encoding error handler must return " - "(unicode, int) tuple"); + "(str, int) tuple"); goto errorexit; } @@ -439,7 +439,7 @@ !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) { PyErr_SetString(PyExc_TypeError, "decoding error handler must return " - "(unicode, int) tuple"); + "(str, int) tuple"); goto errorexit; } @@ -760,7 +760,7 @@ return NULL; else if (!PyUnicode_Check(unistr)) { PyErr_SetString(PyExc_TypeError, - "couldn't convert the object to unicode."); + "couldn't convert the object to str."); Py_DECREF(ucvt); return NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 17:21:15 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 17:21:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_support_encodi?= =?utf-8?q?ng_error_handlers_that_return_bytes_=28closes_=2316585=29?= Message-ID: <3YDvj709s2zN8g@mail.python.org> http://hg.python.org/cpython/rev/5c88c72dec60 changeset: 80691:5c88c72dec60 branch: 3.3 parent: 80689:b1db531736a3 user: Benjamin Peterson date: Sun Dec 02 11:20:28 2012 -0500 summary: support encoding error handlers that return bytes (closes #16585) files: Lib/test/test_multibytecodec.py | 4 ++++ Misc/NEWS | 3 +++ Modules/cjkcodecs/multibytecodec.c | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -45,6 +45,10 @@ self.assertRaises(IndexError, dec, b'apple\x92ham\x93spam', 'test.cjktest') + def test_errorhandler_returns_bytes(self): + enc = "\u30fb\udc80".encode('gb18030', 'surrogateescape') + self.assertEqual(enc, b'\x819\xa79\x80') + def test_codingspec(self): try: for enc in ALL_CJKENCODINGS: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -98,6 +98,9 @@ Library ------- +- Issue #16585: Make CJK encoders support error handlers that return bytes per + PEP 383. + - Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -316,7 +316,7 @@ goto errorexit; if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 || - !PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) || + (!PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) && !PyBytes_Check(tobj)) || !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) { PyErr_SetString(PyExc_TypeError, "encoding error handler must return " @@ -324,7 +324,7 @@ goto errorexit; } - { + if (PyUnicode_Check(tobj)) { const Py_UNICODE *uraw = PyUnicode_AS_UNICODE(tobj); retstr = multibytecodec_encode(codec, state, &uraw, @@ -333,6 +333,10 @@ if (retstr == NULL) goto errorexit; } + else { + Py_INCREF(tobj); + retstr = tobj; + } assert(PyBytes_Check(retstr)); retstrsize = PyBytes_GET_SIZE(retstr); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 17:21:16 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 17:21:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4zICgjMTY1ODUp?= Message-ID: <3YDvj82YT3zQ5C@mail.python.org> http://hg.python.org/cpython/rev/2181c37977d3 changeset: 80692:2181c37977d3 parent: 80690:12cd1c8a6bb0 parent: 80691:5c88c72dec60 user: Benjamin Peterson date: Sun Dec 02 11:21:02 2012 -0500 summary: merge 3.3 (#16585) files: Lib/test/test_multibytecodec.py | 4 ++++ Misc/NEWS | 3 +++ Modules/cjkcodecs/multibytecodec.c | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -45,6 +45,10 @@ self.assertRaises(IndexError, dec, b'apple\x92ham\x93spam', 'test.cjktest') + def test_errorhandler_returns_bytes(self): + enc = "\u30fb\udc80".encode('gb18030', 'surrogateescape') + self.assertEqual(enc, b'\x819\xa79\x80') + def test_codingspec(self): try: for enc in ALL_CJKENCODINGS: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -145,6 +145,9 @@ Library ------- +- Issue #16585: Make CJK encoders support error handlers that return bytes per + PEP 383. + - Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -316,7 +316,7 @@ goto errorexit; if (!PyTuple_Check(retobj) || PyTuple_GET_SIZE(retobj) != 2 || - !PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) || + (!PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0))) && !PyBytes_Check(tobj)) || !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))) { PyErr_SetString(PyExc_TypeError, "encoding error handler must return " @@ -324,7 +324,7 @@ goto errorexit; } - { + if (PyUnicode_Check(tobj)) { const Py_UNICODE *uraw = PyUnicode_AS_UNICODE(tobj); retstr = multibytecodec_encode(codec, state, &uraw, @@ -333,6 +333,10 @@ if (retstr == NULL) goto errorexit; } + else { + Py_INCREF(tobj); + retstr = tobj; + } assert(PyBytes_Check(retstr)); retstrsize = PyBytes_GET_SIZE(retstr); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 17:33:25 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 17:33:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_document_that_?= =?utf-8?q?encoding_error_handlers_may_return_bytes_=28=2316585=29?= Message-ID: <3YDvz90nkrzNbJ@mail.python.org> http://hg.python.org/cpython/rev/777aabdff35a changeset: 80693:777aabdff35a branch: 3.3 parent: 80691:5c88c72dec60 user: Benjamin Peterson date: Sun Dec 02 11:26:10 2012 -0500 summary: document that encoding error handlers may return bytes (#16585) files: Doc/library/codecs.rst | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst --- a/Doc/library/codecs.rst +++ b/Doc/library/codecs.rst @@ -155,13 +155,16 @@ when *name* is specified as the errors parameter. For encoding *error_handler* will be called with a :exc:`UnicodeEncodeError` - instance, which contains information about the location of the error. The error - handler must either raise this or a different exception or return a tuple with a - replacement for the unencodable part of the input and a position where encoding - should continue. The encoder will encode the replacement and continue encoding - the original input at the specified position. Negative position values will be - treated as being relative to the end of the input string. If the resulting - position is out of bound an :exc:`IndexError` will be raised. + instance, which contains information about the location of the error. The + error handler must either raise this or a different exception or return a + tuple with a replacement for the unencodable part of the input and a position + where encoding should continue. The replacement may be either :class:`str` or + :class:`bytes`. If the replacement is bytes, the encoder will simply copy + them into the output buffer. If the replacement is a string, the encoder will + encode the replacement. Encoding continues on original input at the + specified position. Negative position values will be treated as being + relative to the end of the input string. If the resulting position is out of + bound an :exc:`IndexError` will be raised. Decoding and translating works similar, except :exc:`UnicodeDecodeError` or :exc:`UnicodeTranslateError` will be passed to the handler and that the -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 17:33:26 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 17:33:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_document_Unico?= =?utf-8?q?deError_attributes?= Message-ID: <3YDvzB31xMzNr9@mail.python.org> http://hg.python.org/cpython/rev/221858c0d3b1 changeset: 80694:221858c0d3b1 branch: 3.3 user: Benjamin Peterson date: Sun Dec 02 11:33:06 2012 -0500 summary: document UnicodeError attributes files: Doc/library/exceptions.rst | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -371,6 +371,30 @@ Raised when a Unicode-related encoding or decoding error occurs. It is a subclass of :exc:`ValueError`. + :exc:`UnicodeError` has attributes that describe the encoding or decoding + error. For example, ``err.object[err.start:err.end]`` gives the particular + invalid input that the codec failed on. + + .. attribute:: encoding + + The name of the encoding that raised the error. + + .. attribute:: reason + + A string describing the specific codec error. + + .. attribute:: object + + The object the codec was attempting to encode or decode. + + .. attribute:: start + + The first index of invalid data in :attr:`object`. + + .. attribute:: end + + The index after the last invalid data in :attr:`object`. + .. exception:: UnicodeEncodeError -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 17:33:27 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 17:33:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4z?= Message-ID: <3YDvzC5HtPzQBm@mail.python.org> http://hg.python.org/cpython/rev/239486c4e469 changeset: 80695:239486c4e469 parent: 80692:2181c37977d3 parent: 80694:221858c0d3b1 user: Benjamin Peterson date: Sun Dec 02 11:33:14 2012 -0500 summary: merge 3.3 files: Doc/library/codecs.rst | 17 ++++++++++------- Doc/library/exceptions.rst | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst --- a/Doc/library/codecs.rst +++ b/Doc/library/codecs.rst @@ -155,13 +155,16 @@ when *name* is specified as the errors parameter. For encoding *error_handler* will be called with a :exc:`UnicodeEncodeError` - instance, which contains information about the location of the error. The error - handler must either raise this or a different exception or return a tuple with a - replacement for the unencodable part of the input and a position where encoding - should continue. The encoder will encode the replacement and continue encoding - the original input at the specified position. Negative position values will be - treated as being relative to the end of the input string. If the resulting - position is out of bound an :exc:`IndexError` will be raised. + instance, which contains information about the location of the error. The + error handler must either raise this or a different exception or return a + tuple with a replacement for the unencodable part of the input and a position + where encoding should continue. The replacement may be either :class:`str` or + :class:`bytes`. If the replacement is bytes, the encoder will simply copy + them into the output buffer. If the replacement is a string, the encoder will + encode the replacement. Encoding continues on original input at the + specified position. Negative position values will be treated as being + relative to the end of the input string. If the resulting position is out of + bound an :exc:`IndexError` will be raised. Decoding and translating works similar, except :exc:`UnicodeDecodeError` or :exc:`UnicodeTranslateError` will be passed to the handler and that the diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -377,6 +377,30 @@ Raised when a Unicode-related encoding or decoding error occurs. It is a subclass of :exc:`ValueError`. + :exc:`UnicodeError` has attributes that describe the encoding or decoding + error. For example, ``err.object[err.start:err.end]`` gives the particular + invalid input that the codec failed on. + + .. attribute:: encoding + + The name of the encoding that raised the error. + + .. attribute:: reason + + A string describing the specific codec error. + + .. attribute:: object + + The object the codec was attempting to encode or decode. + + .. attribute:: start + + The first index of invalid data in :attr:`object`. + + .. attribute:: end + + The index after the last invalid data in :attr:`object`. + .. exception:: UnicodeEncodeError -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 18:34:55 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 18:34:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_document_Unico?= =?utf-8?q?deError_attributes?= Message-ID: <3YDxL70XzVzQ1f@mail.python.org> http://hg.python.org/cpython/rev/11c2fbd039ac changeset: 80696:11c2fbd039ac branch: 2.7 parent: 80685:48fbe78167cd user: Benjamin Peterson date: Sun Dec 02 11:33:06 2012 -0500 summary: document UnicodeError attributes files: Doc/library/exceptions.rst | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -387,6 +387,30 @@ Raised when a Unicode-related encoding or decoding error occurs. It is a subclass of :exc:`ValueError`. + :exc:`UnicodeError` has attributes that describe the encoding or decoding + error. For example, ``err.object[err.start:err.end]`` gives the particular + invalid input that the codec failed on. + + .. attribute:: encoding + + The name of the encoding that raised the error. + + .. attribute:: reason + + A string describing the specific codec error. + + .. attribute:: object + + The object the codec was attempting to encode or decode. + + .. attribute:: start + + The first index of invalid data in :attr:`object`. + + .. attribute:: end + + The index after the last invalid data in :attr:`object`. + .. versionadded:: 2.0 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 18:37:16 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 18:37:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_loosen_test_no?= =?utf-8?q?w_that_bytes_are_allowed?= Message-ID: <3YDxNr0mmFzNG2@mail.python.org> http://hg.python.org/cpython/rev/72623edae4df changeset: 80697:72623edae4df branch: 3.3 parent: 80694:221858c0d3b1 user: Benjamin Peterson date: Sun Dec 02 12:37:04 2012 -0500 summary: loosen test now that bytes are allowed files: Lib/test/multibytecodec_support.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/multibytecodec_support.py b/Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py +++ b/Lib/test/multibytecodec_support.py @@ -113,7 +113,7 @@ return (ret, exc.end) codecs.register_error("test.cjktest", myreplace) - for ret in ([1, 2, 3], [], None, object(), b'string', b''): + for ret in ([1, 2, 3], [], None, object()): self.assertRaises(TypeError, self.encode, self.unmappedunicode, 'test.cjktest') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 18:37:17 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 18:37:17 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4z?= Message-ID: <3YDxNs301ZzNRc@mail.python.org> http://hg.python.org/cpython/rev/31d6da06a899 changeset: 80698:31d6da06a899 parent: 80695:239486c4e469 parent: 80697:72623edae4df user: Benjamin Peterson date: Sun Dec 02 12:37:09 2012 -0500 summary: merge 3.3 files: Lib/test/multibytecodec_support.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/multibytecodec_support.py b/Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py +++ b/Lib/test/multibytecodec_support.py @@ -113,7 +113,7 @@ return (ret, exc.end) codecs.register_error("test.cjktest", myreplace) - for ret in ([1, 2, 3], [], None, object(), b'string', b''): + for ret in ([1, 2, 3], [], None, object()): self.assertRaises(TypeError, self.encode, self.unmappedunicode, 'test.cjktest') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 19:04:51 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 19:04:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_more_test_to_m?= =?utf-8?q?ore_general_test_file=2C_so_it_can_test_more_things?= Message-ID: <3YDy0g5FJ0zNcL@mail.python.org> http://hg.python.org/cpython/rev/03ce83e43e1b changeset: 80699:03ce83e43e1b branch: 3.3 parent: 80697:72623edae4df user: Benjamin Peterson date: Sun Dec 02 13:04:37 2012 -0500 summary: more test to more general test file, so it can test more things files: Lib/test/multibytecodec_support.py | 7 +++++++ Lib/test/test_multibytecodec.py | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Lib/test/multibytecodec_support.py b/Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py +++ b/Lib/test/multibytecodec_support.py @@ -108,6 +108,13 @@ self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout) + def test_callback_returns_bytes(self): + def myreplace(exc): + return (b"1234", exc.end) + codecs.register_error("test.cjktest", myreplace) + enc = self.encode("abc" + self.unmappedunicode + "def", "test.cjktest")[0] + self.assertEqual(enc, b"abc1234def") + def test_callback_wrong_objects(self): def myreplace(exc): return (ret, exc.end) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -45,10 +45,6 @@ self.assertRaises(IndexError, dec, b'apple\x92ham\x93spam', 'test.cjktest') - def test_errorhandler_returns_bytes(self): - enc = "\u30fb\udc80".encode('gb18030', 'surrogateescape') - self.assertEqual(enc, b'\x819\xa79\x80') - def test_codingspec(self): try: for enc in ALL_CJKENCODINGS: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 19:04:53 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 2 Dec 2012 19:04:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4z?= Message-ID: <3YDy0j0SMGzNcL@mail.python.org> http://hg.python.org/cpython/rev/c69dc1664aaf changeset: 80700:c69dc1664aaf parent: 80698:31d6da06a899 parent: 80699:03ce83e43e1b user: Benjamin Peterson date: Sun Dec 02 13:04:44 2012 -0500 summary: merge 3.3 files: Lib/test/multibytecodec_support.py | 7 +++++++ Lib/test/test_multibytecodec.py | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Lib/test/multibytecodec_support.py b/Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py +++ b/Lib/test/multibytecodec_support.py @@ -108,6 +108,13 @@ self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout) + def test_callback_returns_bytes(self): + def myreplace(exc): + return (b"1234", exc.end) + codecs.register_error("test.cjktest", myreplace) + enc = self.encode("abc" + self.unmappedunicode + "def", "test.cjktest")[0] + self.assertEqual(enc, b"abc1234def") + def test_callback_wrong_objects(self): def myreplace(exc): return (ret, exc.end) diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -45,10 +45,6 @@ self.assertRaises(IndexError, dec, b'apple\x92ham\x93spam', 'test.cjktest') - def test_errorhandler_returns_bytes(self): - enc = "\u30fb\udc80".encode('gb18030', 'surrogateescape') - self.assertEqual(enc, b'\x819\xa79\x80') - def test_codingspec(self): try: for enc in ALL_CJKENCODINGS: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 2 19:11:44 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 2 Dec 2012 19:11:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316562=3A_Optimize?= =?utf-8?q?_dict_equality_testing=2E?= Message-ID: <3YDy8c2mQjzPjS@mail.python.org> http://hg.python.org/cpython/rev/d12785ecca72 changeset: 80701:d12785ecca72 user: Antoine Pitrou date: Sun Dec 02 19:10:07 2012 +0100 summary: Issue #16562: Optimize dict equality testing. Patch by Serhiy Storchaka (reviewed by Martin and Raymond). files: Misc/NEWS | 2 ++ Objects/dictobject.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #16562: Optimize dict equality testing. Patch by Serhiy Storchaka. + - Issue #16588: Silence unused-but-set warnings in Python/thread_pthread - Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation diff --git a/Objects/dictobject.c b/Objects/dictobject.c --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2114,13 +2114,18 @@ if (aval != NULL) { int cmp; PyObject *bval; + PyObject **vaddr; PyObject *key = ep->me_key; /* temporarily bump aval's refcount to ensure it stays alive until we're done with it */ Py_INCREF(aval); /* ditto for key */ Py_INCREF(key); - bval = PyDict_GetItemWithError((PyObject *)b, key); + /* reuse the known hash value */ + if ((b->ma_keys->dk_lookup)(b, key, ep->me_hash, &vaddr) == NULL) + bval = NULL; + else + bval = *vaddr; Py_DECREF(key); if (bval == NULL) { Py_DECREF(aval); -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Dec 3 05:59:01 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 03 Dec 2012 05:59:01 +0100 Subject: [Python-checkins] Daily reference leaks (d12785ecca72): sum=0 Message-ID: results for d12785ecca72 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog6jwbba', '-x'] From python-checkins at python.org Mon Dec 3 12:49:14 2012 From: python-checkins at python.org (victor.stinner) Date: Mon, 3 Dec 2012 12:49:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NDE2?= =?utf-8?q?=3A_On_Mac_OS_X=2C_operating_system_data_are_now_always?= Message-ID: <3YFPcp4JPnzQC5@mail.python.org> http://hg.python.org/cpython/rev/c838c9b117f1 changeset: 80702:c838c9b117f1 branch: 3.2 parent: 80686:d82b73366227 user: Victor Stinner date: Mon Dec 03 12:47:59 2012 +0100 summary: Issue #16416: On Mac OS X, operating system data are now always encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no locale environment variable is set), to avoid inconsistencies with os.fsencode() and os.fsdecode() functions which are already using UTF-8/surrogateescape. files: Misc/NEWS | 6 ++ Modules/python.c | 8 --- Objects/unicodeobject.c | 11 ++-- Python/fileutils.c | 60 ++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,12 @@ Core and Builtins ----------------- +- Issue #16416: On Mac OS X, operating system data are now always + encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding + (which may be ASCII if no locale environment variable is set), to avoid + inconsistencies with os.fsencode() and os.fsdecode() functions which are + already using UTF-8/surrogateescape. + - Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h - Issue #16306: Fix multiple error messages when unknown command line diff --git a/Modules/python.c b/Modules/python.c --- a/Modules/python.c +++ b/Modules/python.c @@ -15,10 +15,6 @@ } #else -#ifdef __APPLE__ -extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); -#endif - int main(int argc, char **argv) { @@ -45,11 +41,7 @@ oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { -#ifdef __APPLE__ - argv_copy[i] = _Py_DecodeUTF8_surrogateescape(argv[i], strlen(argv[i])); -#else argv_copy[i] = _Py_char2wchar(argv[i], NULL); -#endif if (!argv_copy[i]) { fprintf(stderr, "Fatal Python error: " "unable to decode the command line argument #%i\n", diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2792,7 +2792,10 @@ #ifdef __APPLE__ /* Simplified UTF-8 decoder using surrogateescape error handler, - used to decode the command line arguments on Mac OS X. */ + used to decode the command line arguments on Mac OS X. + + Return a pointer to a newly allocated wide character string (use + PyMem_Free() to free the memory), or NULL on memory allocation error. */ wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size) @@ -2803,10 +2806,8 @@ /* Note: size will always be longer than the resulting Unicode character count */ - if (PY_SSIZE_T_MAX / sizeof(wchar_t) < (size + 1)) { - PyErr_NoMemory(); - return NULL; - } + if (PY_SSIZE_T_MAX / sizeof(wchar_t) < (size + 1)) + return NULL; unicode = PyMem_Malloc((size + 1) * sizeof(wchar_t)); if (!unicode) return NULL; diff --git a/Python/fileutils.c b/Python/fileutils.c --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -3,6 +3,10 @@ # include #endif +#ifdef __APPLE__ +extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); +#endif + #ifdef HAVE_STAT /* Decode a byte string from the locale encoding with the @@ -23,6 +27,17 @@ wchar_t* _Py_char2wchar(const char* arg, size_t *size) { +#ifdef __APPLE__ + wchar_t *wstr; + wstr = _Py_DecodeUTF8_surrogateescape(arg, strlen(arg)); + if (size != NULL) { + if (wstr != NULL) + *size = wcslen(wstr); + else + *size = (size_t)-1; + } + return wstr; +#else wchar_t *res; #ifdef HAVE_BROKEN_MBSTOWCS /* Some platforms have a broken implementation of @@ -107,7 +122,7 @@ argsize -= converted; out++; } -#else +#else /* HAVE_MBRTOWC */ /* Cannot use C locale for escaping; manually escape as if charset is ASCII (i.e. escape all bytes > 128. This will still roundtrip correctly in the locale's charset, which must be an ASCII superset. */ @@ -121,13 +136,14 @@ else *out++ = 0xdc00 + *in++; *out = 0; -#endif +#endif /* HAVE_MBRTOWC */ if (size != NULL) *size = out - res; return res; oom: fprintf(stderr, "out of memory\n"); return NULL; +#endif /* __APPLE__ */ } /* Encode a (wide) character string to the locale encoding with the @@ -144,14 +160,42 @@ char* _Py_wchar2char(const wchar_t *text, size_t *error_pos) { +#ifdef __APPLE__ + Py_ssize_t len; + PyObject *unicode, *bytes = NULL; + char *cpath; + + unicode = PyUnicode_FromWideChar(text, wcslen(text)); + if (unicode == NULL) + return NULL; + + bytes = _PyUnicode_AsUTF8String(unicode, "surrogateescape"); + Py_DECREF(unicode); + if (bytes == NULL) { + PyErr_Clear(); + if (error_pos != NULL) + *error_pos = (size_t)-1; + return NULL; + } + + len = PyBytes_GET_SIZE(bytes); + cpath = PyMem_Malloc(len+1); + if (cpath == NULL) { + PyErr_Clear(); + Py_DECREF(bytes); + if (error_pos != NULL) + *error_pos = (size_t)-1; + return NULL; + } + memcpy(cpath, PyBytes_AsString(bytes), len + 1); + Py_DECREF(bytes); + return cpath; +#else /* __APPLE__ */ const size_t len = wcslen(text); char *result = NULL, *bytes = NULL; size_t i, size, converted; wchar_t c, buf[2]; - if (error_pos != NULL) - *error_pos = (size_t)-1; - /* The function works in two steps: 1. compute the length of the output buffer in bytes (size) 2. outputs the bytes */ @@ -198,11 +242,15 @@ size += 1; /* nul byte at the end */ result = PyMem_Malloc(size); - if (result == NULL) + if (result == NULL) { + if (error_pos != NULL) + *error_pos = (size_t)-1; return NULL; + } bytes = result; } return result; +#endif /* __APPLE__ */ } /* In principle, this should use HAVE__WSTAT, and _wstat -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 12:49:16 2012 From: python-checkins at python.org (victor.stinner) Date: Mon, 3 Dec 2012 12:49:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=28Merge_3=2E2=29_Issue_=2316416=3A_On_Mac_OS_X=2C_operating_s?= =?utf-8?q?ystem_data_are_now_always?= Message-ID: <3YFPcr0zBpzQJt@mail.python.org> http://hg.python.org/cpython/rev/26c4748351cb changeset: 80703:26c4748351cb branch: 3.3 parent: 80699:03ce83e43e1b parent: 80702:c838c9b117f1 user: Victor Stinner date: Mon Dec 03 12:48:53 2012 +0100 summary: (Merge 3.2) Issue #16416: On Mac OS X, operating system data are now always encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no locale environment variable is set), to avoid inconsistencies with os.fsencode() and os.fsdecode() functions which are already using UTF-8/surrogateescape. files: Misc/NEWS | 6 ++ Modules/python.c | 8 --- Objects/unicodeobject.c | 11 ++-- Python/fileutils.c | 60 ++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,12 @@ Core and Builtins ----------------- +- Issue #16416: On Mac OS X, operating system data are now always + encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding + (which may be ASCII if no locale environment variable is set), to avoid + inconsistencies with os.fsencode() and os.fsdecode() functions which are + already using UTF-8/surrogateescape. + - Issue #16588: Silence unused-but-set warnings in Python/thread_pthread - Issue #16546: Fix: ast.YieldFrom argument is now mandatory. diff --git a/Modules/python.c b/Modules/python.c --- a/Modules/python.c +++ b/Modules/python.c @@ -15,10 +15,6 @@ } #else -#ifdef __APPLE__ -extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); -#endif - int main(int argc, char **argv) { @@ -45,11 +41,7 @@ oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { -#ifdef __APPLE__ - argv_copy[i] = _Py_DecodeUTF8_surrogateescape(argv[i], strlen(argv[i])); -#else argv_copy[i] = _Py_char2wchar(argv[i], NULL); -#endif if (!argv_copy[i]) { free(oldloc); fprintf(stderr, "Fatal Python error: " diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4809,7 +4809,10 @@ #ifdef __APPLE__ /* Simplified UTF-8 decoder using surrogateescape error handler, - used to decode the command line arguments on Mac OS X. */ + used to decode the command line arguments on Mac OS X. + + Return a pointer to a newly allocated wide character string (use + PyMem_Free() to free the memory), or NULL on memory allocation error. */ wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size) @@ -4820,10 +4823,8 @@ /* Note: size will always be longer than the resulting Unicode character count */ - if (PY_SSIZE_T_MAX / sizeof(wchar_t) < (size + 1)) { - PyErr_NoMemory(); - return NULL; - } + if (PY_SSIZE_T_MAX / sizeof(wchar_t) < (size + 1)) + return NULL; unicode = PyMem_Malloc((size + 1) * sizeof(wchar_t)); if (!unicode) return NULL; diff --git a/Python/fileutils.c b/Python/fileutils.c --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -8,6 +8,10 @@ #include #endif +#ifdef __APPLE__ +extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); +#endif + PyObject * _Py_device_encoding(int fd) { @@ -60,6 +64,17 @@ wchar_t* _Py_char2wchar(const char* arg, size_t *size) { +#ifdef __APPLE__ + wchar_t *wstr; + wstr = _Py_DecodeUTF8_surrogateescape(arg, strlen(arg)); + if (size != NULL) { + if (wstr != NULL) + *size = wcslen(wstr); + else + *size = (size_t)-1; + } + return wstr; +#else wchar_t *res; #ifdef HAVE_BROKEN_MBSTOWCS /* Some platforms have a broken implementation of @@ -145,7 +160,7 @@ argsize -= converted; out++; } -#else +#else /* HAVE_MBRTOWC */ /* Cannot use C locale for escaping; manually escape as if charset is ASCII (i.e. escape all bytes > 128. This will still roundtrip correctly in the locale's charset, which must be an ASCII superset. */ @@ -160,7 +175,7 @@ else *out++ = 0xdc00 + *in++; *out = 0; -#endif +#endif /* HAVE_MBRTOWC */ if (size != NULL) *size = out - res; return res; @@ -168,6 +183,7 @@ if (size != NULL) *size = (size_t)-1; return NULL; +#endif /* __APPLE__ */ } /* Encode a (wide) character string to the locale encoding with the @@ -184,14 +200,42 @@ char* _Py_wchar2char(const wchar_t *text, size_t *error_pos) { +#ifdef __APPLE__ + Py_ssize_t len; + PyObject *unicode, *bytes = NULL; + char *cpath; + + unicode = PyUnicode_FromWideChar(text, wcslen(text)); + if (unicode == NULL) + return NULL; + + bytes = _PyUnicode_AsUTF8String(unicode, "surrogateescape"); + Py_DECREF(unicode); + if (bytes == NULL) { + PyErr_Clear(); + if (error_pos != NULL) + *error_pos = (size_t)-1; + return NULL; + } + + len = PyBytes_GET_SIZE(bytes); + cpath = PyMem_Malloc(len+1); + if (cpath == NULL) { + PyErr_Clear(); + Py_DECREF(bytes); + if (error_pos != NULL) + *error_pos = (size_t)-1; + return NULL; + } + memcpy(cpath, PyBytes_AsString(bytes), len + 1); + Py_DECREF(bytes); + return cpath; +#else /* __APPLE__ */ const size_t len = wcslen(text); char *result = NULL, *bytes = NULL; size_t i, size, converted; wchar_t c, buf[2]; - if (error_pos != NULL) - *error_pos = (size_t)-1; - /* The function works in two steps: 1. compute the length of the output buffer in bytes (size) 2. outputs the bytes */ @@ -238,11 +282,15 @@ size += 1; /* nul byte at the end */ result = PyMem_Malloc(size); - if (result == NULL) + if (result == NULL) { + if (error_pos != NULL) + *error_pos = (size_t)-1; return NULL; + } bytes = result; } return result; +#endif /* __APPLE__ */ } /* In principle, this should use HAVE__WSTAT, and _wstat -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 14:13:14 2012 From: python-checkins at python.org (victor.stinner) Date: Mon, 3 Dec 2012 14:13:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NDE2?= =?utf-8?q?=3A_Fix_compilation_error?= Message-ID: <3YFRTk3FvLzPsF@mail.python.org> http://hg.python.org/cpython/rev/af6fd3ca6de9 changeset: 80704:af6fd3ca6de9 branch: 3.2 parent: 80702:c838c9b117f1 user: Victor Stinner date: Mon Dec 03 14:11:57 2012 +0100 summary: Issue #16416: Fix compilation error files: Python/fileutils.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -169,7 +169,9 @@ if (unicode == NULL) return NULL; - bytes = _PyUnicode_AsUTF8String(unicode, "surrogateescape"); + bytes = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode), + PyUnicode_GET_SIZE(unicode), + "surrogateescape"); Py_DECREF(unicode); if (bytes == NULL) { PyErr_Clear(); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 14:13:15 2012 From: python-checkins at python.org (victor.stinner) Date: Mon, 3 Dec 2012 14:13:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=28Null_merge_3=2E2=29?= Message-ID: <3YFRTl5m63zPsF@mail.python.org> http://hg.python.org/cpython/rev/2a67d79490ae changeset: 80705:2a67d79490ae branch: 3.3 parent: 80703:26c4748351cb parent: 80704:af6fd3ca6de9 user: Victor Stinner date: Mon Dec 03 14:12:22 2012 +0100 summary: (Null merge 3.2) files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 14:13:17 2012 From: python-checkins at python.org (victor.stinner) Date: Mon, 3 Dec 2012 14:13:17 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogKE51bGwgbWVyZ2UgMy4zKQ==?= Message-ID: <3YFRTn1C2BzQC6@mail.python.org> http://hg.python.org/cpython/rev/3b344eac6b0f changeset: 80706:3b344eac6b0f parent: 80701:d12785ecca72 parent: 80705:2a67d79490ae user: Victor Stinner date: Mon Dec 03 14:12:50 2012 +0100 summary: (Null merge 3.3) files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 15:13:59 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 3 Dec 2012 15:13:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NTgz?= =?utf-8?q?=3A_Prevent_nesting_SystemExit_in_tkinter=2ECallWrapper?= Message-ID: <3YFSqq2fQ6zNT9@mail.python.org> http://hg.python.org/cpython/rev/b742bbf6b07f changeset: 80707:b742bbf6b07f branch: 3.2 parent: 80704:af6fd3ca6de9 user: Andrew Svetlov date: Mon Dec 03 16:13:07 2012 +0200 summary: Issue #16583: Prevent nesting SystemExit in tkinter.CallWrapper files: Lib/tkinter/__init__.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1421,8 +1421,8 @@ if self.subst: args = self.subst(*args) return self.func(*args) - except SystemExit as msg: - raise SystemExit(msg) + except SystemExit: + raise except: self.widget._report_exception() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 15:14:00 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 3 Dec 2012 15:14:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_issue_=2316583=3A_Prevent_nesting_SystemExit_in_tkinter?= =?utf-8?q?=2ECallWrapper?= Message-ID: <3YFSqr4wt4zQ8l@mail.python.org> http://hg.python.org/cpython/rev/96b6e6522a1d changeset: 80708:96b6e6522a1d branch: 3.3 parent: 80705:2a67d79490ae parent: 80707:b742bbf6b07f user: Andrew Svetlov date: Mon Dec 03 16:13:34 2012 +0200 summary: Merge issue #16583: Prevent nesting SystemExit in tkinter.CallWrapper files: Lib/tkinter/__init__.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1440,8 +1440,8 @@ if self.subst: args = self.subst(*args) return self.func(*args) - except SystemExit as msg: - raise SystemExit(msg) + except SystemExit: + raise except: self.widget._report_exception() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 15:14:02 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 3 Dec 2012 15:14:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_issue_=2316583=3A_Prevent_nesting_SystemExit_in_tk?= =?utf-8?q?inter=2ECallWrapper?= Message-ID: <3YFSqt07TQzQFP@mail.python.org> http://hg.python.org/cpython/rev/657caf5d3eb1 changeset: 80709:657caf5d3eb1 parent: 80706:3b344eac6b0f parent: 80708:96b6e6522a1d user: Andrew Svetlov date: Mon Dec 03 16:13:48 2012 +0200 summary: Merge issue #16583: Prevent nesting SystemExit in tkinter.CallWrapper files: Lib/tkinter/__init__.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1440,8 +1440,8 @@ if self.subst: args = self.subst(*args) return self.func(*args) - except SystemExit as msg: - raise SystemExit(msg) + except SystemExit: + raise except: self.widget._report_exception() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 20:58:40 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 20:58:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Split_the_bigm?= =?utf-8?q?em_re_test_in_two_separate_tests_with_different_memory?= Message-ID: <3YFcTX4N24zNDJ@mail.python.org> http://hg.python.org/cpython/rev/70ebb4d3b356 changeset: 80710:70ebb4d3b356 branch: 3.2 parent: 80707:b742bbf6b07f user: Antoine Pitrou date: Mon Dec 03 20:53:12 2012 +0100 summary: Split the bigmem re test in two separate tests with different memory requirements. files: Lib/test/test_re.py | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -7,6 +7,9 @@ import traceback from weakref import proxy +from test.test_bigmem import character_size + + # Misc tests from Tim Peters' re.doc # WARNING: Don't change details in these tests if you don't know @@ -854,10 +857,17 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + @bigmemtest(size=_2G, memuse=character_size) + def test_large_search(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. - @bigmemtest(size=_2G, memuse=20) - def test_large(self, size): + @bigmemtest(size=_2G, memuse=16 + 2 * character_size) + def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size m = re.search('$', s) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 20:58:42 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 20:58:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Split_the_bigmem_re_test_in_two_separate_tests_with_different_?= =?utf-8?q?memory?= Message-ID: <3YFcTZ0mLbzMKb@mail.python.org> http://hg.python.org/cpython/rev/ca268ad1ccd6 changeset: 80711:ca268ad1ccd6 branch: 3.3 parent: 80708:96b6e6522a1d parent: 80710:70ebb4d3b356 user: Antoine Pitrou date: Mon Dec 03 20:55:56 2012 +0100 summary: Split the bigmem re test in two separate tests with different memory requirements. files: Lib/test/test_re.py | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -949,10 +949,17 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + @bigmemtest(size=_2G, memuse=1) + def test_large_search(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. - @bigmemtest(size=_2G, memuse=20) - def test_large(self, size): + @bigmemtest(size=_2G, memuse=16 + 2) + def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size m = re.search('$', s) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 20:58:43 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 20:58:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Split_the_bigmem_re_test_in_two_separate_tests_with_diff?= =?utf-8?q?erent_memory?= Message-ID: <3YFcTb3h3wzN0W@mail.python.org> http://hg.python.org/cpython/rev/305c5b9515f8 changeset: 80712:305c5b9515f8 parent: 80709:657caf5d3eb1 parent: 80711:ca268ad1ccd6 user: Antoine Pitrou date: Mon Dec 03 20:56:27 2012 +0100 summary: Split the bigmem re test in two separate tests with different memory requirements. files: Lib/test/test_re.py | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -949,10 +949,17 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + @bigmemtest(size=_2G, memuse=1) + def test_large_search(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. - @bigmemtest(size=_2G, memuse=20) - def test_large(self, size): + @bigmemtest(size=_2G, memuse=16 + 2) + def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size m = re.search('$', s) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 21:01:29 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 21:01:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Split_the_bigm?= =?utf-8?q?em_re_test_in_two_separate_tests_with_different_memory?= Message-ID: <3YFcXn4QbczMt4@mail.python.org> http://hg.python.org/cpython/rev/30a3970285a6 changeset: 80713:30a3970285a6 branch: 2.7 parent: 80696:11c2fbd039ac user: Antoine Pitrou date: Mon Dec 03 20:53:12 2012 +0100 summary: Split the bigmem re test in two separate tests with different memory requirements. files: Lib/test/test_re.py | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -7,6 +7,7 @@ import traceback from weakref import proxy + # Misc tests from Tim Peters' re.doc # WARNING: Don't change details in these tests if you don't know @@ -820,10 +821,17 @@ # Test behaviour when not given a string or pattern as parameter self.assertRaises(TypeError, re.compile, 0) + @precisionbigmemtest(size=_2G, memuse=1) + def test_large_search(self, size): + # Issue #10182: indices were 32-bit-truncated. + s = 'a' * size + m = re.search('$', s) + self.assertIsNotNone(m) + # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. - @precisionbigmemtest(size=_2G, memuse=20) - def test_large(self, size): + @precisionbigmemtest(size=_2G, memuse=16 + 2) + def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size m = re.search('$', s) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 21:10:55 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 21:10:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_test_split?= =?utf-8?q?ting_in_previous_commit=2E?= Message-ID: <3YFclg3GBczQPG@mail.python.org> http://hg.python.org/cpython/rev/c9b62cd81e1f changeset: 80714:c9b62cd81e1f branch: 3.2 parent: 80710:70ebb4d3b356 user: Antoine Pitrou date: Mon Dec 03 21:08:43 2012 +0100 summary: Fix test splitting in previous commit. files: Lib/test/test_re.py | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -863,6 +863,8 @@ s = 'a' * size m = re.search('$', s) self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. @@ -870,10 +872,6 @@ def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size - m = re.search('$', s) - self.assertIsNotNone(m) - self.assertEqual(m.start(), size) - self.assertEqual(m.end(), size) r, n = re.subn('', '', s) self.assertEqual(r, s) self.assertEqual(n, size + 1) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 21:10:56 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 21:10:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Fix_test_splitting_in_previous_commit=2E?= Message-ID: <3YFclh5cZlzN4q@mail.python.org> http://hg.python.org/cpython/rev/6f8b5336beae changeset: 80715:6f8b5336beae branch: 3.3 parent: 80711:ca268ad1ccd6 parent: 80714:c9b62cd81e1f user: Antoine Pitrou date: Mon Dec 03 21:09:08 2012 +0100 summary: Fix test splitting in previous commit. files: Lib/test/test_re.py | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -955,6 +955,8 @@ s = 'a' * size m = re.search('$', s) self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. @@ -962,10 +964,6 @@ def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size - m = re.search('$', s) - self.assertIsNotNone(m) - self.assertEqual(m.start(), size) - self.assertEqual(m.end(), size) r, n = re.subn('', '', s) self.assertEqual(r, s) self.assertEqual(n, size + 1) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 21:10:58 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 21:10:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_test_splitting_in_previous_commit=2E?= Message-ID: <3YFclk191SzQR4@mail.python.org> http://hg.python.org/cpython/rev/b845901cf702 changeset: 80716:b845901cf702 parent: 80712:305c5b9515f8 parent: 80715:6f8b5336beae user: Antoine Pitrou date: Mon Dec 03 21:09:27 2012 +0100 summary: Fix test splitting in previous commit. files: Lib/test/test_re.py | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -955,6 +955,8 @@ s = 'a' * size m = re.search('$', s) self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. @@ -962,10 +964,6 @@ def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size - m = re.search('$', s) - self.assertIsNotNone(m) - self.assertEqual(m.start(), size) - self.assertEqual(m.end(), size) r, n = re.subn('', '', s) self.assertEqual(r, s) self.assertEqual(n, size + 1) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 3 21:11:48 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 3 Dec 2012 21:11:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_test_split?= =?utf-8?q?ting_in_previous_commit=2E?= Message-ID: <3YFcmh1THszQPJ@mail.python.org> http://hg.python.org/cpython/rev/6dc1f417ec56 changeset: 80717:6dc1f417ec56 branch: 2.7 parent: 80713:30a3970285a6 user: Antoine Pitrou date: Mon Dec 03 21:08:43 2012 +0100 summary: Fix test splitting in previous commit. files: Lib/test/test_re.py | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -827,6 +827,8 @@ s = 'a' * size m = re.search('$', s) self.assertIsNotNone(m) + self.assertEqual(m.start(), size) + self.assertEqual(m.end(), size) # The huge memuse is because of re.sub() using a list and a join() # to create the replacement result. @@ -834,10 +836,6 @@ def test_large_subn(self, size): # Issue #10182: indices were 32-bit-truncated. s = 'a' * size - m = re.search('$', s) - self.assertIsNotNone(m) - self.assertEqual(m.start(), size) - self.assertEqual(m.end(), size) r, n = re.subn('', '', s) self.assertEqual(r, s) self.assertEqual(n, size + 1) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 4 02:36:40 2012 From: python-checkins at python.org (daniel.holth) Date: Tue, 4 Dec 2012 02:36:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP-0426_trivial_copy_changes?= Message-ID: <3YFlzX09CXzQS4@mail.python.org> http://hg.python.org/peps/rev/d91dce82d802 changeset: 4593:d91dce82d802 parent: 4589:55c706023fa2 user: Daniel Holth date: Mon Nov 19 18:46:41 2012 -0500 summary: PEP-0426 trivial copy changes files: pep-0426.txt | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pep-0426.txt b/pep-0426.txt --- a/pep-0426.txt +++ b/pep-0426.txt @@ -34,9 +34,9 @@ The syntax defined in this PEP is for use with Python distribution metadata files. The file format is a simple UTF-8 encoded Key: value -format with no maximum line length, followed by a blank line and an -arbitrary payload. The keys are case-insensitive. It is parseable by -the ``email`` module with an appropriate ``email.policy.Policy()``. +format with case-insensitive keys and no maximum line length, followed by +a blank line and an arbitrary payload. It is parseable by the ``email`` +module with an appropriate ``email.policy.Policy()``. When ``metadata`` is a Unicode string, ```email.parser.Parser().parsestr(metadata)`` is a serviceable parser. -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Tue Dec 4 02:36:41 2012 From: python-checkins at python.org (daniel.holth) Date: Tue, 4 Dec 2012 02:36:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_426=3A_try_to_clarify_the?= =?utf-8?q?_bundle=5EH=5EH=5EHmerge/fork_meaning_of_Provides-Dist?= Message-ID: <3YFlzY3GtkzQS4@mail.python.org> http://hg.python.org/peps/rev/026aebf2265d changeset: 4594:026aebf2265d user: Daniel Holth date: Mon Dec 03 20:36:13 2012 -0500 summary: PEP 426: try to clarify the bundle^H^H^Hmerge/fork meaning of Provides-Dist files: pep-0426.txt | 43 +++++++++++++++++++++------------------ 1 files changed, 23 insertions(+), 20 deletions(-) diff --git a/pep-0426.txt b/pep-0426.txt --- a/pep-0426.txt +++ b/pep-0426.txt @@ -94,7 +94,7 @@ ::::::: A string containing the distribution's version number. This -field must be in the format specified in PEP 386. +field should be in the format specified in PEP 386. Example:: @@ -283,12 +283,13 @@ Each entry contains a string naming some other distutils project required by this distribution. -The format of a requirement string is identical to that of a -distutils project name (e.g., as found in the ``Name:`` field. -optionally followed by a version declaration within parentheses. +The format of a requirement string is identical to that of a distribution +name (e.g., as found in the ``Name:`` field) optionally followed by a +version declaration within parentheses. -The distutils project names should correspond to names as found -on the `Python Package Index`_. +The distribution names should correspond to names as found on the `Python +Package Index`_; often the same as, but distinct from, the module names +as accessed with ``import x``. Version declarations must follow the rules described in `Version Specifiers`_ @@ -305,7 +306,8 @@ Like Requires-Dist, but names dependencies needed while the distributions's distutils / packaging `setup.py` / `setup.cfg` is run. -Commonly used to generate a manifest from version control. +Commonly used to bring in extra compiler support or a package needed +to generate a manifest from version control. Examples:: @@ -318,17 +320,19 @@ Provides-Dist (multiple use) :::::::::::::::::::::::::::: -Each entry contains a string naming a Distutils project which -is contained within this distribution. This field *must* include -the project identified in the ``Name`` field, followed by the -version : Name (Version). +Each entry contains a string naming a requirement that is satisfied by +installing this distribution. This field *must* include the project +identified in the ``Name`` field, optionally followed by the version: +Name (Version). A distribution may provide additional names, e.g. to indicate that -multiple projects have been bundled together. For instance, source -distributions of the ``ZODB`` project have historically included -the ``transaction`` project, which is now available as a separate -distribution. Installing such a source distribution satisfies -requirements for both ``ZODB`` and ``transaction``. +multiple projects have been merged into and replaced by a single +distribution or to indicate that this project is a substitute for another. +For instance distribute (a fork of setuptools) could ``Provides-Dist`` +setuptools to prevent the conflicting package from being downloaded and +installed when distribute is already installed. A distribution that has +been merged with another might ``Provides-Dist`` the obsolete name(s) +to satisfy any projects that require the obsolete distribution's name. A distribution may also provide a "virtual" project name, which does not correspond to any separately-distributed project: such a name @@ -359,10 +363,9 @@ Version declarations can be supplied. Version numbers must be in the format specified in `Version Specifiers`_. -The most common use of this field will be in case a project name -changes, e.g. Gorgon 2.3 gets subsumed into Torqued Python 1.0. -When you install Torqued Python, the Gorgon distribution should be -removed. +The most common use of this field will be in case a project name changes, +e.g. Gorgon 2.3 gets renamed to Torqued Python 1.0. When you install +Torqued Python, the Gorgon distribution should be removed. Examples:: -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Tue Dec 4 02:36:42 2012 From: python-checkins at python.org (daniel.holth) Date: Tue, 4 Dec 2012 02:36:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps_=28merge_default_-=3E_default=29?= =?utf-8?q?=3A_merge?= Message-ID: <3YFlzZ5fJ9zQW8@mail.python.org> http://hg.python.org/peps/rev/cbddfb22807f changeset: 4595:cbddfb22807f parent: 4594:026aebf2265d parent: 4592:2b0ff65e8872 user: Daniel Holth date: Mon Dec 03 20:36:20 2012 -0500 summary: merge files: pep-0369.txt | 12 +++++++++--- pep-0370.txt | 2 +- pep-0395.txt | 14 +++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/pep-0369.txt b/pep-0369.txt --- a/pep-0369.txt +++ b/pep-0369.txt @@ -2,13 +2,19 @@ Title: Post import hooks Version: $Revision$ Last-Modified: $Date$ -Author: Christian Heimes -Status: Draft +Author: Christian Heimes +Status: Rejected Type: Standards Track Content-Type: text/x-rst Created: 02-Jan-2008 Python-Version: 2.6, 3.0 -Post-History: +Post-History: 02-Dec-2012 + +Rejection Notice +================ + +This PEP is rejected by its author, because it has been superseded by the new +importlib. Abstract diff --git a/pep-0370.txt b/pep-0370.txt --- a/pep-0370.txt +++ b/pep-0370.txt @@ -2,7 +2,7 @@ Title: Per user site-packages directory Version: $Revision$ Last-Modified: $Date$ -Author: Christian Heimes +Author: Christian Heimes Status: Final Type: Standards Track Content-Type: text/x-rst diff --git a/pep-0395.txt b/pep-0395.txt --- a/pep-0395.txt +++ b/pep-0395.txt @@ -3,11 +3,11 @@ Version: $Revision$ Last-Modified: $Date$ Author: Nick Coghlan -Status: Draft +Status: Deferred Type: Standards Track Content-Type: text/x-rst Created: 4-Mar-2011 -Python-Version: 3.3 +Python-Version: 3.4 Post-History: 5-Mar-2011, 19-Nov-2011 @@ -24,6 +24,11 @@ Relationship with Other PEPs ---------------------------- +Most significantly, this PEP is currently deferred as it requires +significant changes in order to be made compatible with the removal +of mandatory __init__.py files in PEP 420 (which has been implemented +and released in Python 3.3). + This PEP builds on the "qualified name" concept introduced by PEP 3155, and also shares in that PEP's aim of fixing some ugly corner cases when dealing with serialisation of arbitrary functions and classes. @@ -32,11 +37,6 @@ explicit relative imports from the main module work correctly in at least *some* circumstances. -This PEP is also affected by the two competing "namespace package" PEPs -(PEP 382 and PEP 402). This PEP would require some minor adjustments to -accommodate PEP 382, but has some critical incompatibilities with respect to -the implicit namespace package mechanism proposed in PEP 402. - Finally, PEP 328 eliminated implicit relative imports from imported modules. This PEP proposes that the de facto implicit relative imports from main modules that are provided by the current initialisation behaviour for -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Tue Dec 4 03:23:05 2012 From: python-checkins at python.org (victor.stinner) Date: Tue, 4 Dec 2012 03:23:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316455=3A_On_FreeB?= =?utf-8?q?SD_and_Solaris=2C_if_the_locale_is_C=2C_the?= Message-ID: <3YFn1558hdzQFW@mail.python.org> http://hg.python.org/cpython/rev/c25635b137cc changeset: 80718:c25635b137cc parent: 80716:b845901cf702 user: Victor Stinner date: Tue Dec 04 01:34:47 2012 +0100 summary: Issue #16455: On FreeBSD and Solaris, if the locale is C, the ASCII/surrogateescape codec is now used, instead of the locale encoding, to decode the command line arguments. This change fixes inconsistencies with os.fsencode() and os.fsdecode() because these operating systems announces an ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice. files: Include/unicodeobject.h | 2 +- Lib/test/test_cmd_line_script.py | 9 +- Misc/NEWS | 6 + Objects/unicodeobject.c | 24 +- Python/fileutils.c | 240 +++++++++++++++++- 5 files changed, 241 insertions(+), 40 deletions(-) diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -1742,7 +1742,7 @@ /* Encode a Unicode object to the current locale encoding. The encoder is strict is *surrogateescape* is equal to zero, otherwise the "surrogateescape" error handler is used. Return a bytes object. The string - cannot contain embedded null characters.. */ + cannot contain embedded null characters. */ PyAPI_FUNC(PyObject*) PyUnicode_EncodeLocale( PyObject *unicode, diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py --- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -367,11 +367,10 @@ # Mac OS X denies the creation of a file with an invalid UTF-8 name. # Windows allows to create a name with an arbitrary bytes name, but # Python cannot a undecodable bytes argument to a subprocess. - #if (support.TESTFN_UNDECODABLE - #and sys.platform not in ('win32', 'darwin')): - # name = os.fsdecode(support.TESTFN_UNDECODABLE) - #elif support.TESTFN_NONASCII: - if support.TESTFN_NONASCII: + if (support.TESTFN_UNDECODABLE + and sys.platform not in ('win32', 'darwin')): + name = os.fsdecode(support.TESTFN_UNDECODABLE) + elif support.TESTFN_NONASCII: name = support.TESTFN_NONASCII else: self.skipTest("need support.TESTFN_NONASCII") diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,12 @@ Core and Builtins ----------------- +- Issue #16455: On FreeBSD and Solaris, if the locale is C, the + ASCII/surrogateescape codec is now used, instead of the locale encoding, to + decode the command line arguments. This change fixes inconsistencies with + os.fsencode() and os.fsdecode() because these operating systems announces an + ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice. + - Issue #16562: Optimize dict equality testing. Patch by Serhiy Storchaka. - Issue #16588: Silence unused-but-set warnings in Python/thread_pthread diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2863,10 +2863,10 @@ /* Convert encoding to lower case and replace '_' with '-' in order to catch e.g. UTF_8. Return 0 on error (encoding is longer than lower_len-1), 1 on success. */ -static int -normalize_encoding(const char *encoding, - char *lower, - size_t lower_len) +int +_Py_normalize_encoding(const char *encoding, + char *lower, + size_t lower_len) { const char *e; char *l; @@ -2908,7 +2908,7 @@ char lower[11]; /* Enough for any encoding shortcut */ /* Shortcuts for common default encodings */ - if (normalize_encoding(encoding, lower, sizeof(lower))) { + if (_Py_normalize_encoding(encoding, lower, sizeof(lower))) { if ((strcmp(lower, "utf-8") == 0) || (strcmp(lower, "utf8") == 0)) return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL); @@ -3110,7 +3110,8 @@ *surrogateescape = 0; return 0; } - if (strcmp(errors, "surrogateescape") == 0) { + if (errors == "surrogateescape" + || strcmp(errors, "surrogateescape") == 0) { *surrogateescape = 1; return 0; } @@ -3148,7 +3149,7 @@ } if (surrogateescape) { - /* locale encoding with surrogateescape */ + /* "surrogateescape" error handler */ char *str; str = _Py_wchar2char(wstr, &error_pos); @@ -3168,6 +3169,7 @@ PyMem_Free(str); } else { + /* strict mode */ size_t len, len2; len = wcstombs(NULL, wstr, 0); @@ -3273,7 +3275,7 @@ } /* Shortcuts for common default encodings */ - if (normalize_encoding(encoding, lower, sizeof(lower))) { + if (_Py_normalize_encoding(encoding, lower, sizeof(lower))) { if ((strcmp(lower, "utf-8") == 0) || (strcmp(lower, "utf8") == 0)) { @@ -3413,8 +3415,8 @@ return NULL; } - if (surrogateescape) - { + if (surrogateescape) { + /* "surrogateescape" error handler */ wstr = _Py_char2wchar(str, &wlen); if (wstr == NULL) { if (wlen == (size_t)-1) @@ -3428,6 +3430,7 @@ PyMem_Free(wstr); } else { + /* strict mode */ #ifndef HAVE_BROKEN_MBSTOWCS wlen = mbstowcs(NULL, str, 0); #else @@ -3447,7 +3450,6 @@ return PyErr_NoMemory(); } - /* This shouldn't fail now */ wlen2 = mbstowcs(wstr, str, wlen+1); if (wlen2 == (size_t)-1) { if (wstr != smallbuf) diff --git a/Python/fileutils.c b/Python/fileutils.c --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -5,6 +5,7 @@ #endif #ifdef HAVE_LANGINFO_H +#include #include #endif @@ -42,7 +43,182 @@ Py_RETURN_NONE; } -#ifdef HAVE_STAT +#if !defined(__APPLE__) && !defined(MS_WINDOWS) +extern int _Py_normalize_encoding(const char *, char *, size_t); + +/* Workaround FreeBSD and OpenIndiana locale encoding issue with the C locale. + On these operating systems, nl_langinfo(CODESET) announces an alias of the + ASCII encoding, whereas mbstowcs() and wcstombs() functions use the + ISO-8859-1 encoding. The problem is that os.fsencode() and os.fsdecode() use + locale.getpreferredencoding() codec. For example, if command line arguments + are decoded by mbstowcs() and encoded back by os.fsencode(), we get a + UnicodeEncodeError instead of retrieving the original byte string. + + The workaround is enabled if setlocale(LC_CTYPE, NULL) returns "C", + nl_langinfo(CODESET) announces "ascii" (or an alias to ASCII), and at least + one byte in range 0x80-0xff can be decoded from the locale encoding. The + workaround is also enabled on error, for example if getting the locale + failed. + + Values of locale_is_ascii: + + 1: the workaround is used: _Py_wchar2char() uses + encode_ascii_surrogateescape() and _Py_char2wchar() uses + decode_ascii_surrogateescape() + 0: the workaround is not used: _Py_wchar2char() uses wcstombs() and + _Py_char2wchar() uses mbstowcs() + -1: unknown, need to call check_force_ascii() to get the value +*/ +static int force_ascii = -1; + +static int +check_force_ascii(void) +{ + char *loc; +#if defined(HAVE_LANGINFO_H) && defined(CODESET) + char *codeset, **alias; + char encoding[100]; + int is_ascii; + unsigned int i; + char* ascii_aliases[] = { + "ascii", + "646", + "ansi-x3.4-1968", + "ansi-x3-4-1968", + "ansi-x3.4-1986", + "cp367", + "csascii", + "ibm367", + "iso646-us", + "iso-646.irv-1991", + "iso-ir-6", + "us", + "us-ascii", + NULL + }; +#endif + + loc = setlocale(LC_CTYPE, NULL); + if (loc == NULL) + goto error; + if (strcmp(loc, "C") != 0) { + /* the LC_CTYPE locale is different than C */ + return 0; + } + +#if defined(HAVE_LANGINFO_H) && defined(CODESET) + codeset = nl_langinfo(CODESET); + if (!codeset || codeset[0] == '\0') { + /* CODESET is not set or empty */ + goto error; + } + if (!_Py_normalize_encoding(codeset, encoding, sizeof(encoding))) + goto error; + + is_ascii = 0; + for (alias=ascii_aliases; *alias != NULL; alias++) { + if (strcmp(encoding, *alias) == 0) { + is_ascii = 1; + break; + } + } + if (!is_ascii) { + /* nl_langinfo(CODESET) is not "ascii" or an alias of ASCII */ + return 0; + } + + for (i=0x80; i<0xff; i++) { + unsigned char ch; + wchar_t wch; + size_t res; + + ch = (unsigned char)i; + res = mbstowcs(&wch, (char*)&ch, 1); + if (res != (size_t)-1) { + /* decoding a non-ASCII character from the locale encoding succeed: + the locale encoding is not ASCII, force ASCII */ + return 1; + } + } + /* None of the bytes in the range 0x80-0xff can be decoded from the locale + encoding: the locale encoding is really ASCII */ + return 0; +#else + /* nl_langinfo(CODESET) is not available: always force ASCII */ + return 1; +#endif + +error: + /* if an error occured, force the ASCII encoding */ + return 1; +} + +static char* +encode_ascii_surrogateescape(const wchar_t *text, size_t *error_pos) +{ + char *result = NULL, *out; + size_t len, i; + wchar_t ch; + + if (error_pos != NULL) + *error_pos = (size_t)-1; + + len = wcslen(text); + + result = PyMem_Malloc(len + 1); /* +1 for NUL byte */ + if (result == NULL) + return NULL; + + out = result; + for (i=0; i 128. This will still roundtrip correctly in the locale's charset, which must be an ASCII superset. */ - res = PyMem_Malloc((strlen(arg)+1)*sizeof(wchar_t)); - if (!res) + res = decode_ascii_surrogateescape(arg, size); + if (res == NULL) goto oom; - in = (unsigned char*)arg; - out = res; - while(*in) - if(*in < 128) - *out++ = *in++; - else - *out++ = 0xdc00 + *in++; - *out = 0; #endif /* HAVE_MBRTOWC */ - if (size != NULL) - *size = out - res; return res; oom: if (size != NULL) @@ -236,6 +419,14 @@ size_t i, size, converted; wchar_t c, buf[2]; +#ifndef MS_WINDOWS + if (force_ascii == -1) + force_ascii = check_force_ascii(); + + if (force_ascii) + return encode_ascii_surrogateescape(text, error_pos); +#endif + /* The function works in two steps: 1. compute the length of the output buffer in bytes (size) 2. outputs the bytes */ @@ -276,7 +467,7 @@ } } if (result != NULL) { - *bytes = 0; + *bytes = '\0'; break; } @@ -320,6 +511,8 @@ } #endif +#ifdef HAVE_STAT + /* Call _wstat() on Windows, or encode the path to the filesystem encoding and call stat() otherwise. Only fill st_mode attribute on Windows. @@ -352,6 +545,8 @@ #endif } +#endif + /* Open a file. Use _wfopen() on Windows, encode the path to the locale encoding and use fopen() otherwise. */ @@ -533,4 +728,3 @@ #endif } -#endif -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Tue Dec 4 05:54:57 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 04 Dec 2012 05:54:57 +0100 Subject: [Python-checkins] Daily reference leaks (c25635b137cc): sum=-42 Message-ID: results for c25635b137cc on branch "default" -------------------------------------------- test_ssl leaked [-42, 0, 0] references, sum=-42 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogk7d0fB', '-x'] From christian at python.org Tue Dec 4 08:33:17 2012 From: christian at python.org (Christian Heimes) Date: Tue, 04 Dec 2012 08:33:17 +0100 Subject: [Python-checkins] cpython: Issue #16455: On FreeBSD and Solaris, if the locale is C, the In-Reply-To: <3YFn1558hdzQFW@mail.python.org> References: <3YFn1558hdzQFW@mail.python.org> Message-ID: <50BDA73D.5090206@python.org> Am 04.12.2012 03:23, schrieb victor.stinner: > http://hg.python.org/cpython/rev/c25635b137cc > changeset: 80718:c25635b137cc > parent: 80716:b845901cf702 > user: Victor Stinner > date: Tue Dec 04 01:34:47 2012 +0100 > summary: > Issue #16455: On FreeBSD and Solaris, if the locale is C, the > ASCII/surrogateescape codec is now used, instead of the locale encoding, to > decode the command line arguments. This change fixes inconsistencies with > os.fsencode() and os.fsdecode() because these operating systems announces an > ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice. > > files: > Include/unicodeobject.h | 2 +- > Lib/test/test_cmd_line_script.py | 9 +- > Misc/NEWS | 6 + > Objects/unicodeobject.c | 24 +- > Python/fileutils.c | 240 +++++++++++++++++- > 5 files changed, 241 insertions(+), 40 deletions(-) ... > @@ -3110,7 +3110,8 @@ > *surrogateescape = 0; > return 0; > } > - if (strcmp(errors, "surrogateescape") == 0) { > + if (errors == "surrogateescape" > + || strcmp(errors, "surrogateescape") == 0) { > *surrogateescape = 1; > return 0; > } Victor, That doesn't look right. :) GCC is complaining about the code: Objects/unicodeobject.c: In function 'locale_error_handler': Objects/unicodeobject.c:3113:16: warning: comparison with string literal results in unspecified behavior [-Waddress] I'm also getting additional warnings in PyUnicode_Format(). Objects/unicodeobject.c: In function 'PyUnicode_Format': Objects/unicodeobject.c:13782:8: warning: 'arg.sign' may be used uninitialized in this function [-Wmaybe-uninitialized] Objects/unicodeobject.c:13893:33: note: 'arg.sign' was declared here Objects/unicodeobject.c:13779:12: warning: 'str' may be used uninitialized in this function [-Wmaybe-uninitialized] Objects/unicodeobject.c:13894:15: note: 'str' was declared here From python-checkins at python.org Tue Dec 4 10:07:45 2012 From: python-checkins at python.org (victor.stinner) Date: Tue, 4 Dec 2012 10:07:45 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Cleanup_unicodeobject=2Ec?= Message-ID: <3YFy0150rKzQHg@mail.python.org> http://hg.python.org/cpython/rev/b3fe2ef13470 changeset: 80719:b3fe2ef13470 user: Victor Stinner date: Tue Dec 04 09:30:24 2012 +0100 summary: Cleanup unicodeobject.c * Remove micro-optization: (errors == "surrogateescape" || strcmp(errors, "surrogateescape") == 0). Only use strcmp() * Initialize 'arg' members in unicode_format_arg() to help the compiler to diagnose real bugs and also make the code simpler to read files: Objects/unicodeobject.c | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3110,8 +3110,7 @@ *surrogateescape = 0; return 0; } - if (errors == "surrogateescape" - || strcmp(errors, "surrogateescape") == 0) { + if (strcmp(errors, "surrogateescape") == 0) { *surrogateescape = 1; return 0; } @@ -13438,7 +13437,6 @@ PyObject *v; - arg->ch = FORMAT_READ(ctx); if (arg->ch == '(') { /* Get argument value from a dictionary. Example: "%(name)s". */ Py_ssize_t keystart; @@ -13487,7 +13485,6 @@ } /* Parse flags. Example: "%+i" => flags=F_SIGN. */ - arg->flags = 0; while (--ctx->fmtcnt >= 0) { arg->ch = FORMAT_READ(ctx); ctx->fmtpos++; @@ -13502,7 +13499,6 @@ } /* Parse width. Example: "%10s" => width=10 */ - arg->width = -1; if (arg->ch == '*') { v = unicode_format_getnextarg(ctx); if (v == NULL) @@ -13544,7 +13540,6 @@ } /* Parse precision. Example: "%.3f" => prec=3 */ - arg->prec = -1; if (arg->ch == '.') { arg->prec = 0; if (--ctx->fmtcnt >= 0) { @@ -13613,9 +13608,12 @@ - "e", "E", "f", "F", "g", "G": float - "c": int or str (1 character) + When possible, the output is written directly into the Unicode writer + (ctx->writer). A string is created when padding is required. + Return 0 if the argument has been formatted into *p_str, 1 if the argument has been written into ctx->writer, - -1 on error. */ + -1 on error. */ static int unicode_format_arg_format(struct unicode_formatter_t *ctx, struct unicode_format_arg_t *arg, @@ -13639,10 +13637,8 @@ if (v == NULL) return -1; - arg->sign = 0; switch (arg->ch) { - case 's': case 'r': case 'a': @@ -13894,6 +13890,13 @@ PyObject *str; int ret; + arg.ch = PyUnicode_READ(ctx->fmtkind, ctx->fmtdata, ctx->fmtpos); + arg.flags = 0; + arg.width = -1; + arg.prec = -1; + arg.sign = 0; + str = NULL; + ret = unicode_format_arg_parse(ctx, &arg); if (ret == -1) return -1; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 4 10:07:47 2012 From: python-checkins at python.org (victor.stinner) Date: Tue, 4 Dec 2012 10:07:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NzQ3?= =?utf-8?q?=3A_skip_chflags_UF=5FIMMUTABLE_tests_if_EOPNOTSUPP_is_raised?= =?utf-8?q?=2E?= Message-ID: <3YFy030Lp4zQHg@mail.python.org> http://hg.python.org/cpython/rev/4beb1630544f changeset: 80720:4beb1630544f branch: 2.7 parent: 80717:6dc1f417ec56 user: Victor Stinner date: Tue Dec 04 10:07:16 2012 +0100 summary: Issue #15747: skip chflags UF_IMMUTABLE tests if EOPNOTSUPP is raised. This is necessary for ZFS systems, which don't support UF_IMMUTABLE. -- Kubilay Kocak (koobs) asked me on IRC to backport this fix to Python 2.7: done! files: Lib/test/test_posix.py | 23 ++++++++++++++++++++--- Misc/NEWS | 4 ++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -334,7 +334,16 @@ def _test_chflags_regular_file(self, chflags_func, target_file): st = os.stat(target_file) self.assertTrue(hasattr(st, 'st_flags')) - chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE) + + # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE. + try: + chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE) + except OSError as err: + if err.errno != errno.EOPNOTSUPP: + raise + msg = 'chflag UF_IMMUTABLE not supported by underlying fs' + self.skipTest(msg) + try: new_st = os.stat(target_file) self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags) @@ -363,8 +372,16 @@ self.teardown_files.append(_DUMMY_SYMLINK) dummy_symlink_st = os.lstat(_DUMMY_SYMLINK) - posix.lchflags(_DUMMY_SYMLINK, - dummy_symlink_st.st_flags | stat.UF_IMMUTABLE) + # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE. + try: + posix.lchflags(_DUMMY_SYMLINK, + dummy_symlink_st.st_flags | stat.UF_IMMUTABLE) + except OSError as err: + if err.errno != errno.EOPNOTSUPP: + raise + msg = 'chflag UF_IMMUTABLE not supported by underlying fs' + self.skipTest(msg) + try: new_testfn_st = os.stat(test_support.TESTFN) new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -530,6 +530,10 @@ Tests ----- +- Issue #15747: ZFS always returns EOPNOTSUPP when attempting to set the + UF_IMMUTABLE flag (via either chflags or lchflags); refactor affected + tests in test_posix.py to account for this. + - Issue #16549: Add tests for json.tools. Initial patch by Berker Peksag and Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 4 20:11:08 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 4 Dec 2012 20:11:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzEzMTIw?= =?utf-8?q?=3A_Allow_to_call_pdb=2Eset=5Ftrace=28=29_from_thread=2E?= Message-ID: <3YGCND05lTzNcB@mail.python.org> http://hg.python.org/cpython/rev/708586792eec changeset: 80721:708586792eec branch: 3.2 parent: 80714:c9b62cd81e1f user: Andrew Svetlov date: Tue Dec 04 21:08:28 2012 +0200 summary: Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. files: Lib/pdb.py | 11 +++++++++-- Lib/test/test_pdb.py | 27 +++++++++++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -955,8 +955,15 @@ Continue execution, only stop when a breakpoint is encountered. """ if not self.nosigint: - self._previous_sigint_handler = \ - signal.signal(signal.SIGINT, self.sigint_handler) + try: + self._previous_sigint_handler = \ + signal.signal(signal.SIGINT, self.sigint_handler) + except ValueError: + # ValueError happens when do_continue() is invoked from + # a non-main thread in which case we just continue without + # SIGINT set. Would printing a message here (once) make + # sense? + pass self.set_continue() return 1 do_c = do_cont = do_continue diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -664,6 +664,33 @@ any('main.py(5)foo()->None' in l for l in stdout.splitlines()), 'Fail to step into the caller after a return') + def test_issue13210(self): + # invoking "continue" on a non-main thread triggered an exception + # inside signal.signal + + with open(support.TESTFN, 'wb') as f: + f.write(textwrap.dedent(""" + import threading + import pdb + + def start_pdb(): + pdb.Pdb().set_trace() + x = 1 + y = 1 + + t = threading.Thread(target=start_pdb) + t.start()""").encode('ascii')) + cmd = [sys.executable, '-u', support.TESTFN] + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + self.addCleanup(proc.stdout.close) + stdout, stderr = proc.communicate(b'cont\n') + self.assertNotIn('Error', stdout.decode(), + "Got an error running test script under PDB") + def tearDown(self): support.unlink(support.TESTFN) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -175,6 +175,9 @@ Library ------- +- Issue #13120: Allow to call pdb.set_trace() from thread. + Patch by Ilya Sandler. + - Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 4 20:11:09 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 4 Dec 2012 20:11:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_issue_=2313120=3A_Allow_to_call_pdb=2Eset=5Ftrace=28=29_?= =?utf-8?q?from_thread=2E?= Message-ID: <3YGCNF2WdGzQ0Y@mail.python.org> http://hg.python.org/cpython/rev/678dba60c12d changeset: 80722:678dba60c12d branch: 3.3 parent: 80715:6f8b5336beae parent: 80721:708586792eec user: Andrew Svetlov date: Tue Dec 04 21:10:20 2012 +0200 summary: Merge issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. files: Lib/pdb.py | 11 +++++++++-- Lib/test/test_pdb.py | 27 +++++++++++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1031,8 +1031,15 @@ Continue execution, only stop when a breakpoint is encountered. """ if not self.nosigint: - self._previous_sigint_handler = \ - signal.signal(signal.SIGINT, self.sigint_handler) + try: + self._previous_sigint_handler = \ + signal.signal(signal.SIGINT, self.sigint_handler) + except ValueError: + # ValueError happens when do_continue() is invoked from + # a non-main thread in which case we just continue without + # SIGINT set. Would printing a message here (once) make + # sense? + pass self.set_continue() return 1 do_c = do_cont = do_continue diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -667,6 +667,33 @@ any('main.py(5)foo()->None' in l for l in stdout.splitlines()), 'Fail to step into the caller after a return') + def test_issue13210(self): + # invoking "continue" on a non-main thread triggered an exception + # inside signal.signal + + with open(support.TESTFN, 'wb') as f: + f.write(textwrap.dedent(""" + import threading + import pdb + + def start_pdb(): + pdb.Pdb().set_trace() + x = 1 + y = 1 + + t = threading.Thread(target=start_pdb) + t.start()""").encode('ascii')) + cmd = [sys.executable, '-u', support.TESTFN] + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + self.addCleanup(proc.stdout.close) + stdout, stderr = proc.communicate(b'cont\n') + self.assertNotIn('Error', stdout.decode(), + "Got an error running test script under PDB") + def tearDown(self): support.unlink(support.TESTFN) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,9 @@ Library ------- +- Issue #13120: Allow to call pdb.set_trace() from thread. + Patch by Ilya Sandler. + - Issue #16585: Make CJK encoders support error handlers that return bytes per PEP 383. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 4 20:11:10 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 4 Dec 2012 20:11:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_issue_=2313120=3A_Allow_to_call_pdb=2Eset=5Ftrace?= =?utf-8?b?KCkgZnJvbSB0aHJlYWQu?= Message-ID: <3YGCNG5BcjzQ2M@mail.python.org> http://hg.python.org/cpython/rev/4006c4ca0c1f changeset: 80723:4006c4ca0c1f parent: 80719:b3fe2ef13470 parent: 80722:678dba60c12d user: Andrew Svetlov date: Tue Dec 04 21:10:55 2012 +0200 summary: Merge issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. files: Lib/pdb.py | 11 +++++++++-- Lib/test/test_pdb.py | 27 +++++++++++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1031,8 +1031,15 @@ Continue execution, only stop when a breakpoint is encountered. """ if not self.nosigint: - self._previous_sigint_handler = \ - signal.signal(signal.SIGINT, self.sigint_handler) + try: + self._previous_sigint_handler = \ + signal.signal(signal.SIGINT, self.sigint_handler) + except ValueError: + # ValueError happens when do_continue() is invoked from + # a non-main thread in which case we just continue without + # SIGINT set. Would printing a message here (once) make + # sense? + pass self.set_continue() return 1 do_c = do_cont = do_continue diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -667,6 +667,33 @@ any('main.py(5)foo()->None' in l for l in stdout.splitlines()), 'Fail to step into the caller after a return') + def test_issue13210(self): + # invoking "continue" on a non-main thread triggered an exception + # inside signal.signal + + with open(support.TESTFN, 'wb') as f: + f.write(textwrap.dedent(""" + import threading + import pdb + + def start_pdb(): + pdb.Pdb().set_trace() + x = 1 + y = 1 + + t = threading.Thread(target=start_pdb) + t.start()""").encode('ascii')) + cmd = [sys.executable, '-u', support.TESTFN] + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + self.addCleanup(proc.stdout.close) + stdout, stderr = proc.communicate(b'cont\n') + self.assertNotIn('Error', stdout.decode(), + "Got an error running test script under PDB") + def tearDown(self): support.unlink(support.TESTFN) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -153,6 +153,9 @@ Library ------- +- Issue #13120: Allow to call pdb.set_trace() from thread. + Patch by Ilya Sandler. + - Issue #16585: Make CJK encoders support error handlers that return bytes per PEP 383. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 4 21:42:01 2012 From: python-checkins at python.org (victor.stinner) Date: Tue, 4 Dec 2012 21:42:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316444=3A_test_mor?= =?utf-8?q?e_bytes_in_support=2ETESTFN=5FUNDECODABLE_to_support_more?= Message-ID: <3YGFP53RrZzNf3@mail.python.org> http://hg.python.org/cpython/rev/ed0ff4b3d1c4 changeset: 80724:ed0ff4b3d1c4 user: Victor Stinner date: Tue Dec 04 11:55:04 2012 +0100 summary: Issue #16444: test more bytes in support.TESTFN_UNDECODABLE to support more Windows code pages files: Lib/test/support.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -717,6 +717,9 @@ b'\xae\xd5' # undecodable from UTF-8 (UNIX and Mac OS X) b'\xed\xb2\x80', b'\xed\xb4\x80', + # undecodable from shift_jis, cp869, cp874, cp932, cp1250, cp1251, cp1252, + # cp1253, cp1254, cp1255, cp1257, cp1258 + b'\x81\x98', ): try: name.decode(TESTFN_ENCODING) -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Dec 5 05:58:29 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 05 Dec 2012 05:58:29 +0100 Subject: [Python-checkins] Daily reference leaks (ed0ff4b3d1c4): sum=0 Message-ID: results for ed0ff4b3d1c4 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflognRZC5a', '-x'] From python-checkins at python.org Wed Dec 5 08:53:13 2012 From: python-checkins at python.org (eric.snow) Date: Wed, 5 Dec 2012 08:53:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315627=3A_This_is_?= =?utf-8?q?simply_an_update_to_the_name_of_a_new_method_recently?= Message-ID: <3YGXHY0PRYzQQ9@mail.python.org> http://hg.python.org/cpython/rev/7caab48f171e changeset: 80725:7caab48f171e user: Eric Snow date: Tue Dec 04 23:43:43 2012 -0800 summary: Issue #15627: This is simply an update to the name of a new method recently added to importlib.abc.SourceLoader. files: Doc/library/importlib.rst | 2 +- Lib/importlib/_bootstrap.py | 4 +- Lib/test/test_importlib/source/test_abc_loader.py | 4 +- Misc/NEWS | 2 +- Python/importlib.h | 16 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -409,7 +409,7 @@ When writing to the path fails because the path is read-only (:attr:`errno.EACCES`), do not propagate the exception. - .. method:: compile_source(data, path) + .. method:: source_to_code(data, path) Create a code object from Python source. diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -931,7 +931,7 @@ raise ImportError("Failed to decode source file", name=fullname) from exc - def compile_source(self, data, path): + def source_to_code(self, data, path): """Return the code object compiled from source. The 'data' argument can be any object type that compile() supports. @@ -984,7 +984,7 @@ raise ImportError(msg.format(bytecode_path), name=fullname, path=bytecode_path) source_bytes = self.get_data(source_path) - code_object = self.compile_source(source_bytes, source_path) + code_object = self.source_to_code(source_bytes, source_path) _verbose_message('code object from {}', source_path) if (not sys.dont_write_bytecode and bytecode_path is not None and source_mtime is not None): diff --git a/Lib/test/test_importlib/source/test_abc_loader.py b/Lib/test/test_importlib/source/test_abc_loader.py --- a/Lib/test/test_importlib/source/test_abc_loader.py +++ b/Lib/test/test_importlib/source/test_abc_loader.py @@ -148,9 +148,9 @@ code_object = self.loader.get_code(self.name) self.verify_code(code_object) - def test_compile_source(self): + def test_source_to_code(self): # Verify the compiled code object. - code = self.loader.compile_source(self.loader.source, self.path) + code = self.loader.source_to_code(self.loader.source, self.path) self.verify_code(code) def test_load_module(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -190,7 +190,7 @@ - Issue #16522: added FAIL_FAST flag to doctest. -- Issue #15627: Add the importlib.abc.SourceLoader.compile_source() method. +- Issue #15627: Add the importlib.abc.SourceLoader.source_to_code() method. - Issue #16408: Fix file descriptors not being closed in error conditions in the zipfile module. Patch by Serhiy Storchaka. diff --git a/Python/importlib.h b/Python/importlib.h --- a/Python/importlib.h +++ b/Python/importlib.h [stripped] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 10:12:59 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 5 Dec 2012 10:12:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogRml4IHR5cG8u?= Message-ID: <3YGZ3b2K9WzNLc@mail.python.org> http://hg.python.org/cpython/rev/4e5c690e7f99 changeset: 80726:4e5c690e7f99 branch: 3.3 parent: 80722:678dba60c12d user: Andrew Svetlov date: Wed Dec 05 11:12:14 2012 +0200 summary: Fix typo. files: Doc/library/exceptions.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -516,7 +516,7 @@ .. exception:: InterruptedError Raised when a system call is interrupted by an incoming signal. - Corresponds to :c:data:`errno` ``EEINTR``. + Corresponds to :c:data:`errno` ``EINTR``. .. exception:: IsADirectoryError -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 10:13:00 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 5 Dec 2012 10:13:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4z?= Message-ID: <3YGZ3c4XvwzNLc@mail.python.org> http://hg.python.org/cpython/rev/e771edf43149 changeset: 80727:e771edf43149 parent: 80725:7caab48f171e parent: 80726:4e5c690e7f99 user: Andrew Svetlov date: Wed Dec 05 11:12:50 2012 +0200 summary: Merge 3.3 files: Doc/library/exceptions.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -522,7 +522,7 @@ .. exception:: InterruptedError Raised when a system call is interrupted by an incoming signal. - Corresponds to :c:data:`errno` ``EEINTR``. + Corresponds to :c:data:`errno` ``EINTR``. .. exception:: IsADirectoryError -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 14:07:21 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 5 Dec 2012 14:07:21 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Skip_pdb_test_?= =?utf-8?q?for_=2313120_if_threading_is_not_available=2E?= Message-ID: <3YGgG11dHxzQNn@mail.python.org> http://hg.python.org/cpython/rev/26056f8a0afe changeset: 80728:26056f8a0afe branch: 3.2 parent: 80721:708586792eec user: Andrew Svetlov date: Wed Dec 05 15:06:23 2012 +0200 summary: Skip pdb test for #13120 if threading is not available. files: Lib/test/test_pdb.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -668,6 +668,9 @@ # invoking "continue" on a non-main thread triggered an exception # inside signal.signal + # raises SkipTest if python was built without threads + support.import_module('threading') + with open(support.TESTFN, 'wb') as f: f.write(textwrap.dedent(""" import threading -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 14:07:22 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 5 Dec 2012 14:07:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge=3A_skip_pdb_test_for_=2313120_if_threading_is_not_availa?= =?utf-8?q?ble=2E?= Message-ID: <3YGgG23vnRzQQ9@mail.python.org> http://hg.python.org/cpython/rev/328a8824c1a7 changeset: 80729:328a8824c1a7 branch: 3.3 parent: 80726:4e5c690e7f99 parent: 80728:26056f8a0afe user: Andrew Svetlov date: Wed Dec 05 15:06:54 2012 +0200 summary: Merge: skip pdb test for #13120 if threading is not available. files: Lib/test/test_pdb.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -671,6 +671,9 @@ # invoking "continue" on a non-main thread triggered an exception # inside signal.signal + # raises SkipTest if python was built without threads + support.import_module('threading') + with open(support.TESTFN, 'wb') as f: f.write(textwrap.dedent(""" import threading -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 14:07:23 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 5 Dec 2012 14:07:23 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge=3A_skip_pdb_test_for_=2313120_if_threading_is_not_?= =?utf-8?q?available=2E?= Message-ID: <3YGgG36XrgzQRD@mail.python.org> http://hg.python.org/cpython/rev/4cb84c0fbee2 changeset: 80730:4cb84c0fbee2 parent: 80727:e771edf43149 parent: 80729:328a8824c1a7 user: Andrew Svetlov date: Wed Dec 05 15:07:10 2012 +0200 summary: Merge: skip pdb test for #13120 if threading is not available. files: Lib/test/test_pdb.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -671,6 +671,9 @@ # invoking "continue" on a non-main thread triggered an exception # inside signal.signal + # raises SkipTest if python was built without threads + support.import_module('threading') + with open(support.TESTFN, 'wb') as f: f.write(textwrap.dedent(""" import threading -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 14:42:19 2012 From: python-checkins at python.org (jesus.cea) Date: Wed, 5 Dec 2012 14:42:19 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICMxNjU4?= =?utf-8?q?8=3A_Silence_unused-but-set_warnings_in_Python/thread=5Fpthread?= =?utf-8?q?=2Eh?= Message-ID: <3YGh2M17HszQQ9@mail.python.org> http://hg.python.org/cpython/rev/0adfbafe8a99 changeset: 80731:0adfbafe8a99 branch: 2.7 parent: 80720:4beb1630544f user: Jesus Cea date: Wed Dec 05 14:41:11 2012 +0100 summary: Closes #16588: Silence unused-but-set warnings in Python/thread_pthread.h files: Misc/NEWS | 2 ++ Python/thread_pthread.h | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,8 @@ HTTP servers and reduce memory usage. It's actually a backport of a Python 3.2 fix. Thanks to Adrien Kunysz. +- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread + - Issue #13992: The trashcan mechanism is now thread-safe. This eliminates sporadic crashes in multi-thread programs when several long deallocator chains ran concurrently and involved subclasses of built-in container diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -284,6 +284,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_free_lock(%p) called\n", lock)); if (!thelock) @@ -314,6 +315,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); do { @@ -341,6 +343,7 @@ sem_t *thelock = (sem_t *)lock; int status, error = 0; + (void) error; /* silence unused-but-set-variable warning */ dprintf(("PyThread_release_lock(%p) called\n", lock)); status = sem_post(thelock); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 16:59:39 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 5 Dec 2012 16:59:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Update_comment?= =?utf-8?q?=3A_SAVE=5FEXC=5FSTATE_and_SWAP=5FEXC=5FSTATE_macroses_are_saav?= =?utf-8?q?e=5Fexc=5Fstate?= Message-ID: <3YGl4q18ZKzN03@mail.python.org> http://hg.python.org/cpython/rev/2ca476e20f39 changeset: 80732:2ca476e20f39 branch: 3.3 parent: 80729:328a8824c1a7 user: Andrew Svetlov date: Wed Dec 05 17:59:10 2012 +0200 summary: Update comment: SAVE_EXC_STATE and SWAP_EXC_STATE macroses are saave_exc_state and swap_exc_state functions now. files: Include/frameobject.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/frameobject.h b/Include/frameobject.h --- a/Include/frameobject.h +++ b/Include/frameobject.h @@ -33,8 +33,8 @@ frame (which shouldn't be impacted when the generator "yields" from an except handler). These three fields exist exactly for that, and are unused for - non-generator frames. See the SAVE_EXC_STATE and SWAP_EXC_STATE - macros in ceval.c for details of their use. */ + non-generator frames. See the save_exc_state and swap_exc_state + functions in ceval.c for details of their use. */ PyObject *f_exc_type, *f_exc_value, *f_exc_traceback; PyThreadState *f_tstate; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 5 16:59:40 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 5 Dec 2012 16:59:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Update_comment=3A_SAVE=5FEXC=5FSTATE_and_SWAP=5FEXC=5FST?= =?utf-8?q?ATE_macroses_are_saave=5Fexc=5Fstate?= Message-ID: <3YGl4r3rXhzQ9W@mail.python.org> http://hg.python.org/cpython/rev/ece75a3b942c changeset: 80733:ece75a3b942c parent: 80730:4cb84c0fbee2 parent: 80732:2ca476e20f39 user: Andrew Svetlov date: Wed Dec 05 17:59:29 2012 +0200 summary: Update comment: SAVE_EXC_STATE and SWAP_EXC_STATE macroses are saave_exc_state and swap_exc_state functions now. files: Include/frameobject.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/frameobject.h b/Include/frameobject.h --- a/Include/frameobject.h +++ b/Include/frameobject.h @@ -33,8 +33,8 @@ frame (which shouldn't be impacted when the generator "yields" from an except handler). These three fields exist exactly for that, and are unused for - non-generator frames. See the SAVE_EXC_STATE and SWAP_EXC_STATE - macros in ceval.c for details of their use. */ + non-generator frames. See the save_exc_state and swap_exc_state + functions in ceval.c for details of their use. */ PyObject *f_exc_type, *f_exc_value, *f_exc_traceback; PyThreadState *f_tstate; -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Thu Dec 6 05:57:50 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 06 Dec 2012 05:57:50 +0100 Subject: [Python-checkins] Daily reference leaks (ece75a3b942c): sum=1 Message-ID: results for ece75a3b942c on branch "default" -------------------------------------------- test_buffer leaked [1, 0, 0] references, sum=1 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogLburCU', '-x'] From python-checkins at python.org Thu Dec 6 11:21:32 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 6 Dec 2012 11:21:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Specify_which_?= =?utf-8?q?I/O_ABC_methods_have_implementations_in_the_docs=2E?= Message-ID: <3YHCXD3873zRTB@mail.python.org> http://hg.python.org/cpython/rev/93742b046519 changeset: 80734:93742b046519 branch: 3.2 parent: 80728:26056f8a0afe user: Andrew Svetlov date: Thu Dec 06 12:20:56 2012 +0200 summary: Specify which I/O ABC methods have implementations in the docs. files: Doc/library/io.rst | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -189,6 +189,25 @@ Argument names are not part of the specification, and only the arguments of :func:`open` are intended to be used as keyword arguments. +The following table summarizes the ABCs provided by the :mod:`io` module: + +========================= ================== ======================== ================================================== +ABC Inherits Stub Methods Mixin Methods and Properties +========================= ================== ======================== ================================================== +:class:`IOBase` ``fileno``, ``seek``, ``close``, ``closed``, ``__enter__``, + and ``truncate`` ``__exit__``, ``flush``, ``isatty``, ``__iter__``, + ``__next__``, ``readable``, ``readline``, + ``readlines``, ``seekable``, ``tell``, + ``writable``, and ``writelines`` +:class:`RawIOBase` :class:`IOBase` ``readinto`` and Inherited :class:`IOBase` methods, ``read``, + ``write`` and ``readall`` +:class:`BufferedIOBase` :class:`IOBase` ``detach``, ``read``, Inherited :class:`IOBase` methods, ``readinto`` + ``read1``, and ``write`` +:class:`TextIOBase` :class:`IOBase` ``detach``, ``read``, Inherited :class:`IOBase` methods, ``encoding``, + ``readline``, and ``errors``, and ``newlines`` + ``write`` +========================= ================== ======================== ================================================== + I/O Base Classes ^^^^^^^^^^^^^^^^ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 6 11:21:33 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 6 Dec 2012 11:21:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Specify_which_I/O_ABC_methods_have_implementations_in_the_docs?= =?utf-8?q?=2E?= Message-ID: <3YHCXF5S47zRS3@mail.python.org> http://hg.python.org/cpython/rev/3cb85250a0a3 changeset: 80735:3cb85250a0a3 branch: 3.3 parent: 80732:2ca476e20f39 parent: 80734:93742b046519 user: Andrew Svetlov date: Thu Dec 06 12:21:12 2012 +0200 summary: Specify which I/O ABC methods have implementations in the docs. files: Doc/library/io.rst | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -185,6 +185,25 @@ Argument names are not part of the specification, and only the arguments of :func:`open` are intended to be used as keyword arguments. +The following table summarizes the ABCs provided by the :mod:`io` module: + +========================= ================== ======================== ================================================== +ABC Inherits Stub Methods Mixin Methods and Properties +========================= ================== ======================== ================================================== +:class:`IOBase` ``fileno``, ``seek``, ``close``, ``closed``, ``__enter__``, + and ``truncate`` ``__exit__``, ``flush``, ``isatty``, ``__iter__``, + ``__next__``, ``readable``, ``readline``, + ``readlines``, ``seekable``, ``tell``, + ``writable``, and ``writelines`` +:class:`RawIOBase` :class:`IOBase` ``readinto`` and Inherited :class:`IOBase` methods, ``read``, + ``write`` and ``readall`` +:class:`BufferedIOBase` :class:`IOBase` ``detach``, ``read``, Inherited :class:`IOBase` methods, ``readinto`` + ``read1``, and ``write`` +:class:`TextIOBase` :class:`IOBase` ``detach``, ``read``, Inherited :class:`IOBase` methods, ``encoding``, + ``readline``, and ``errors``, and ``newlines`` + ``write`` +========================= ================== ======================== ================================================== + I/O Base Classes ^^^^^^^^^^^^^^^^ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 6 11:21:35 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 6 Dec 2012 11:21:35 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Specify_which_I/O_ABC_methods_have_implementations_in_th?= =?utf-8?q?e_docs=2E?= Message-ID: <3YHCXH18JHzRVg@mail.python.org> http://hg.python.org/cpython/rev/a58204570a7c changeset: 80736:a58204570a7c parent: 80733:ece75a3b942c parent: 80735:3cb85250a0a3 user: Andrew Svetlov date: Thu Dec 06 12:21:22 2012 +0200 summary: Specify which I/O ABC methods have implementations in the docs. files: Doc/library/io.rst | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -185,6 +185,25 @@ Argument names are not part of the specification, and only the arguments of :func:`open` are intended to be used as keyword arguments. +The following table summarizes the ABCs provided by the :mod:`io` module: + +========================= ================== ======================== ================================================== +ABC Inherits Stub Methods Mixin Methods and Properties +========================= ================== ======================== ================================================== +:class:`IOBase` ``fileno``, ``seek``, ``close``, ``closed``, ``__enter__``, + and ``truncate`` ``__exit__``, ``flush``, ``isatty``, ``__iter__``, + ``__next__``, ``readable``, ``readline``, + ``readlines``, ``seekable``, ``tell``, + ``writable``, and ``writelines`` +:class:`RawIOBase` :class:`IOBase` ``readinto`` and Inherited :class:`IOBase` methods, ``read``, + ``write`` and ``readall`` +:class:`BufferedIOBase` :class:`IOBase` ``detach``, ``read``, Inherited :class:`IOBase` methods, ``readinto`` + ``read1``, and ``write`` +:class:`TextIOBase` :class:`IOBase` ``detach``, ``read``, Inherited :class:`IOBase` methods, ``encoding``, + ``readline``, and ``errors``, and ``newlines`` + ``write`` +========================= ================== ======================== ================================================== + I/O Base Classes ^^^^^^^^^^^^^^^^ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 6 15:32:48 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 6 Dec 2012 15:32:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Document_that_?= =?utf-8?q?hour_in_datetime=2Etime_ctor_is_optional_parameter=2E?= Message-ID: <3YHK6808fJzRWv@mail.python.org> http://hg.python.org/cpython/rev/0fd2ea06e17d changeset: 80737:0fd2ea06e17d branch: 2.7 parent: 80731:0adfbafe8a99 user: Andrew Svetlov date: Thu Dec 06 16:32:37 2012 +0200 summary: Document that hour in datetime.time ctor is optional parameter. Thanks to Sean Munkel from docs@ files: Doc/library/datetime.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1154,7 +1154,7 @@ A time object represents a (local) time of day, independent of any particular day, and subject to adjustment via a :class:`tzinfo` object. -.. class:: time(hour[, minute[, second[, microsecond[, tzinfo]]]]) +.. class:: time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) All arguments are optional. *tzinfo* may be ``None``, or an instance of a :class:`tzinfo` subclass. The remaining arguments may be ints or longs, in the -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 6 23:41:13 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 6 Dec 2012 23:41:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_create_NameConstant_AST_cl?= =?utf-8?q?ass_for_None=2C_True=2C_and_False_literals_=28closes_=2316619?= =?utf-8?q?=29?= Message-ID: <3YHWxj5Z93zRfY@mail.python.org> http://hg.python.org/cpython/rev/03f92a9f0875 changeset: 80738:03f92a9f0875 parent: 80736:a58204570a7c user: Benjamin Peterson date: Thu Dec 06 17:41:04 2012 -0500 summary: create NameConstant AST class for None, True, and False literals (closes #16619) files: Include/Python-ast.h | 12 +++- Include/asdl.h | 1 + Lib/ast.py | 6 +- Lib/test/test_ast.py | 13 +++- Lib/test/test_syntax.py | 4 +- Misc/NEWS | 4 + Parser/Python.asdl | 3 +- Parser/asdl.py | 2 +- Parser/asdl_c.py | 12 ++++ Python/Python-ast.c | 73 +++++++++++++++++++++++++++++ Python/ast.c | 22 +++++++- Python/compile.c | 21 +++++-- Python/peephole.c | 46 ------------------ Python/symtable.c | 1 + Tools/parser/unparse.py | 3 + 15 files changed, 152 insertions(+), 71 deletions(-) diff --git a/Include/Python-ast.h b/Include/Python-ast.h --- a/Include/Python-ast.h +++ b/Include/Python-ast.h @@ -182,8 +182,9 @@ SetComp_kind=9, DictComp_kind=10, GeneratorExp_kind=11, Yield_kind=12, YieldFrom_kind=13, Compare_kind=14, Call_kind=15, Num_kind=16, Str_kind=17, Bytes_kind=18, - Ellipsis_kind=19, Attribute_kind=20, Subscript_kind=21, - Starred_kind=22, Name_kind=23, List_kind=24, Tuple_kind=25}; + NameConstant_kind=19, Ellipsis_kind=20, Attribute_kind=21, + Subscript_kind=22, Starred_kind=23, Name_kind=24, + List_kind=25, Tuple_kind=26}; struct _expr { enum _expr_kind kind; union { @@ -279,6 +280,10 @@ } Bytes; struct { + singleton value; + } NameConstant; + + struct { expr_ty value; identifier attr; expr_context_ty ctx; @@ -509,6 +514,9 @@ expr_ty _Py_Str(string s, int lineno, int col_offset, PyArena *arena); #define Bytes(a0, a1, a2, a3) _Py_Bytes(a0, a1, a2, a3) expr_ty _Py_Bytes(bytes s, int lineno, int col_offset, PyArena *arena); +#define NameConstant(a0, a1, a2, a3) _Py_NameConstant(a0, a1, a2, a3) +expr_ty _Py_NameConstant(singleton value, int lineno, int col_offset, PyArena + *arena); #define Ellipsis(a0, a1, a2) _Py_Ellipsis(a0, a1, a2) expr_ty _Py_Ellipsis(int lineno, int col_offset, PyArena *arena); #define Attribute(a0, a1, a2, a3, a4, a5) _Py_Attribute(a0, a1, a2, a3, a4, a5) diff --git a/Include/asdl.h b/Include/asdl.h --- a/Include/asdl.h +++ b/Include/asdl.h @@ -5,6 +5,7 @@ typedef PyObject * string; typedef PyObject * bytes; typedef PyObject * object; +typedef PyObject * singleton; /* It would be nice if the code generated by asdl_c.py was completely independent of Python, but it is a goal the requires too much work diff --git a/Lib/ast.py b/Lib/ast.py --- a/Lib/ast.py +++ b/Lib/ast.py @@ -42,7 +42,6 @@ Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None. """ - _safe_names = {'None': None, 'True': True, 'False': False} if isinstance(node_or_string, str): node_or_string = parse(node_or_string, mode='eval') if isinstance(node_or_string, Expression): @@ -61,9 +60,8 @@ elif isinstance(node, Dict): return dict((_convert(k), _convert(v)) for k, v in zip(node.keys, node.values)) - elif isinstance(node, Name): - if node.id in _safe_names: - return _safe_names[node.id] + elif isinstance(node, NameConstant): + return node.value elif isinstance(node, UnaryOp) and \ isinstance(node.op, (UAdd, USub)) and \ isinstance(node.operand, (Num, UnaryOp, BinOp)): diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -928,6 +928,9 @@ def test_tuple(self): self._sequence(ast.Tuple) + def test_nameconstant(self): + self.expr(ast.NameConstant(4), "singleton must be True, False, or None") + def test_stdlib_validates(self): stdlib = os.path.dirname(ast.__file__) tests = [fn for fn in os.listdir(stdlib) if fn.endswith(".py")] @@ -959,13 +962,13 @@ #### EVERYTHING BELOW IS GENERATED ##### exec_results = [ -('Module', [('Expr', (1, 0), ('Name', (1, 0), 'None', ('Load',)))]), +('Module', [('Expr', (1, 0), ('NameConstant', (1, 0), None))]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Pass', (1, 9))], [], None)]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], None, None, [], None, None, [], []), [('Pass', (1, 10))], [], None)]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], None, None, [], None, None, [('Num', (1, 8), 0)], []), [('Pass', (1, 12))], [], None)]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], 'args', None, [], None, None, [], []), [('Pass', (1, 14))], [], None)]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], 'kwargs', None, [], []), [('Pass', (1, 17))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None), ('arg', 'b', None), ('arg', 'c', None), ('arg', 'd', None), ('arg', 'e', None)], 'args', None, [], 'kwargs', None, [('Num', (1, 11), 1), ('Name', (1, 16), 'None', ('Load',)), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])], []), [('Pass', (1, 52))], [], None)]), +('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None), ('arg', 'b', None), ('arg', 'c', None), ('arg', 'd', None), ('arg', 'e', None)], 'args', None, [], 'kwargs', None, [('Num', (1, 11), 1), ('NameConstant', (1, 16), None), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])], []), [('Pass', (1, 52))], [], None)]), ('Module', [('ClassDef', (1, 0), 'C', [], [], None, None, [('Pass', (1, 8))], [])]), ('Module', [('ClassDef', (1, 0), 'C', [('Name', (1, 8), 'object', ('Load',))], [], None, None, [('Pass', (1, 17))], [])]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Return', (1, 8), ('Num', (1, 15), 1))], [], None)]), @@ -1002,14 +1005,14 @@ ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]), ] eval_results = [ -('Expression', ('Name', (1, 0), 'None', ('Load',))), +('Expression', ('NameConstant', (1, 0), None)), ('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ('Name', (1, 6), 'b', ('Load',))])), ('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('Name', (1, 4), 'b', ('Load',)))), ('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))), -('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, [], None, None, [], []), ('Name', (1, 7), 'None', ('Load',)))), +('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, [], None, None, [], []), ('NameConstant', (1, 7), None))), ('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])), ('Expression', ('Dict', (1, 0), [], [])), -('Expression', ('Set', (1, 0), [('Name', (1, 1), 'None', ('Load',))])), +('Expression', ('Set', (1, 0), [('NameConstant', (1, 1), None)])), ('Expression', ('Dict', (1, 0), [('Num', (2, 6), 1)], [('Num', (4, 10), 2)])), ('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), ('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -33,7 +33,7 @@ >>> None = 1 Traceback (most recent call last): -SyntaxError: assignment to keyword +SyntaxError: can't assign to keyword It's a syntax error to assign to the empty tuple. Why isn't it an error to assign to the empty list? It will always raise some error at @@ -233,7 +233,7 @@ SyntaxError: can't assign to generator expression >>> None += 1 Traceback (most recent call last): -SyntaxError: assignment to keyword +SyntaxError: can't assign to keyword >>> f() += 1 Traceback (most recent call last): SyntaxError: can't assign to function call diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16619: Create NameConstant AST class to represent None, True, and False + literals. As a result, these constants are never loaded at runtime from + builtins. + - Issue #16455: On FreeBSD and Solaris, if the locale is C, the ASCII/surrogateescape codec is now used, instead of the locale encoding, to decode the command line arguments. This change fixes inconsistencies with diff --git a/Parser/Python.asdl b/Parser/Python.asdl --- a/Parser/Python.asdl +++ b/Parser/Python.asdl @@ -1,4 +1,4 @@ --- ASDL's five builtin types are identifier, int, string, bytes, object +-- ASDL's six builtin types are identifier, int, string, bytes, object, singleton module Python { @@ -69,8 +69,8 @@ | Num(object n) -- a number as a PyObject. | Str(string s) -- need to specify raw, unicode, etc? | Bytes(bytes s) + | NameConstant(singleton value) | Ellipsis - -- other literals? bools? -- the following expression can appear in assignment context | Attribute(expr value, identifier attr, expr_context ctx) diff --git a/Parser/asdl.py b/Parser/asdl.py --- a/Parser/asdl.py +++ b/Parser/asdl.py @@ -222,7 +222,7 @@ " field ::= Id ? " return Field(type[0], opt=True) -builtin_types = ("identifier", "string", "bytes", "int", "object") +builtin_types = ("identifier", "string", "bytes", "int", "object", "singleton") # below is a collection of classes to capture the AST of an AST :-) # not sure if any of the methods are useful yet, but I'm adding them diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -820,6 +820,7 @@ Py_INCREF((PyObject*)o); return (PyObject*)o; } +#define ast2obj_singleton ast2obj_object #define ast2obj_identifier ast2obj_object #define ast2obj_string ast2obj_object #define ast2obj_bytes ast2obj_object @@ -831,6 +832,17 @@ /* Conversion Python -> AST */ +static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) +{ + if (obj != Py_None && obj != Py_True && obj != Py_False) { + PyErr_SetString(PyExc_ValueError, + "AST singleton must be True, False, or None"); + return 1; + } + *out = obj; + return 0; +} + static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) { if (obj == Py_None) diff --git a/Python/Python-ast.c b/Python/Python-ast.c --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -271,6 +271,10 @@ static char *Bytes_fields[]={ "s", }; +static PyTypeObject *NameConstant_type; +static char *NameConstant_fields[]={ + "value", +}; static PyTypeObject *Ellipsis_type; static PyTypeObject *Attribute_type; _Py_IDENTIFIER(attr); @@ -673,6 +677,7 @@ Py_INCREF((PyObject*)o); return (PyObject*)o; } +#define ast2obj_singleton ast2obj_object #define ast2obj_identifier ast2obj_object #define ast2obj_string ast2obj_object #define ast2obj_bytes ast2obj_object @@ -684,6 +689,17 @@ /* Conversion Python -> AST */ +static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) +{ + if (obj != Py_None && obj != Py_True && obj != Py_False) { + PyErr_SetString(PyExc_ValueError, + "AST singleton must be True, False, or None"); + return 1; + } + *out = obj; + return 0; +} + static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) { if (obj == Py_None) @@ -860,6 +876,9 @@ if (!Str_type) return 0; Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); if (!Bytes_type) return 0; + NameConstant_type = make_type("NameConstant", expr_type, + NameConstant_fields, 1); + if (!NameConstant_type) return 0; Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); if (!Ellipsis_type) return 0; Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); @@ -1921,6 +1940,25 @@ } expr_ty +NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) +{ + expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for NameConstant"); + return NULL; + } + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) + return NULL; + p->kind = NameConstant_kind; + p->v.NameConstant.value = value; + p->lineno = lineno; + p->col_offset = col_offset; + return p; +} + +expr_ty Ellipsis(int lineno, int col_offset, PyArena *arena) { expr_ty p; @@ -2028,6 +2066,7 @@ *arena) { expr_ty p; + assert(PyUnicode_CompareWithASCIIString(id, "True") && PyUnicode_CompareWithASCIIString(id, "False") && PyUnicode_CompareWithASCIIString(id, "None")); if (!id) { PyErr_SetString(PyExc_ValueError, "field id is required for Name"); @@ -2948,6 +2987,15 @@ goto failed; Py_DECREF(value); break; + case NameConstant_kind: + result = PyType_GenericNew(NameConstant_type, NULL, NULL); + if (!result) goto failed; + value = ast2obj_singleton(o->v.NameConstant.value); + if (!value) goto failed; + if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) + goto failed; + Py_DECREF(value); + break; case Ellipsis_kind: result = PyType_GenericNew(Ellipsis_type, NULL, NULL); if (!result) goto failed; @@ -5688,6 +5736,29 @@ if (*out == NULL) goto failed; return 0; } + isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); + if (isinstance == -1) { + return 1; + } + if (isinstance) { + singleton value; + + if (_PyObject_HasAttrId(obj, &PyId_value)) { + int res; + tmp = _PyObject_GetAttrId(obj, &PyId_value); + if (tmp == NULL) goto failed; + res = obj2ast_singleton(tmp, &value, arena); + if (res != 0) goto failed; + Py_XDECREF(tmp); + tmp = NULL; + } else { + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); + return 1; + } + *out = NameConstant(value, lineno, col_offset, arena); + if (*out == NULL) goto failed; + return 0; + } isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); if (isinstance == -1) { return 1; @@ -7008,6 +7079,8 @@ NULL; if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return NULL; + if (PyDict_SetItemString(d, "NameConstant", + (PyObject*)NameConstant_type) < 0) return NULL; if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) return NULL; if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < diff --git a/Python/ast.c b/Python/ast.c --- a/Python/ast.c +++ b/Python/ast.c @@ -282,6 +282,7 @@ return validate_exprs(exp->v.Tuple.elts, ctx, 0); /* These last cases don't have any checking. */ case Name_kind: + case NameConstant_kind: case Ellipsis_kind: return 1; default: @@ -903,7 +904,7 @@ break; case Name_kind: if (ctx == Store) { - if (forbidden_name(c, e->v.Name.id, n, 1)) + if (forbidden_name(c, e->v.Name.id, n, 0)) return 0; /* forbidden_name() calls ast_error() */ } e->v.Name.ctx = ctx; @@ -955,6 +956,9 @@ case Bytes_kind: expr_name = "literal"; break; + case NameConstant_kind: + expr_name = "keyword"; + break; case Ellipsis_kind: expr_name = "Ellipsis"; break; @@ -1819,11 +1823,21 @@ switch (TYPE(ch)) { case NAME: { - /* All names start in Load context, but may later be - changed. */ - PyObject *name = NEW_IDENTIFIER(ch); + PyObject *name; + const char *s = STR(ch); + size_t len = strlen(s); + if (len >= 4 && len <= 5) { + if (!strcmp(s, "None")) + return NameConstant(Py_None, LINENO(n), n->n_col_offset, c->c_arena); + if (!strcmp(s, "True")) + return NameConstant(Py_True, LINENO(n), n->n_col_offset, c->c_arena); + if (!strcmp(s, "False")) + return NameConstant(Py_False, LINENO(n), n->n_col_offset, c->c_arena); + } + name = new_identifier(s, c); if (!name) return NULL; + /* All names start in Load context, but may later be changed. */ return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena); } case STRING: { diff --git a/Python/compile.c b/Python/compile.c --- a/Python/compile.c +++ b/Python/compile.c @@ -3194,12 +3194,18 @@ case Name_kind: /* optimize away names that can't be reassigned */ id = PyUnicode_AsUTF8(e->v.Name.id); - if (strcmp(id, "True") == 0) return 1; - if (strcmp(id, "False") == 0) return 0; - if (strcmp(id, "None") == 0) return 0; - if (strcmp(id, "__debug__") == 0) - return ! c->c_optimize; - /* fall through */ + if (id && strcmp(id, "__debug__") == 0) + return !c->c_optimize; + return -1; + case NameConstant_kind: { + PyObject *o = e->v.NameConstant.value; + if (o == Py_None) + return 0; + else if (o == Py_True) + return 1; + else if (o == Py_False) + return 0; + } default: return -1; } @@ -3375,6 +3381,9 @@ case Ellipsis_kind: ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); break; + case NameConstant_kind: + ADDOP_O(c, LOAD_CONST, e->v.NameConstant.value, consts); + break; /* The following exprs can be assignment targets. */ case Attribute_kind: if (e->v.Attribute.ctx != AugStore) diff --git a/Python/peephole.c b/Python/peephole.c --- a/Python/peephole.c +++ b/Python/peephole.c @@ -327,37 +327,6 @@ return blocks; } -/* Helper to replace LOAD_NAME None/True/False with LOAD_CONST - Returns: 0 if no change, 1 if change, -1 if error */ -static int -load_global(unsigned char *codestr, Py_ssize_t i, char *name, PyObject *consts) -{ - Py_ssize_t j; - PyObject *obj; - if (name == NULL) - return 0; - if (strcmp(name, "None") == 0) - obj = Py_None; - else if (strcmp(name, "True") == 0) - obj = Py_True; - else if (strcmp(name, "False") == 0) - obj = Py_False; - else - return 0; - for (j = 0; j < PyList_GET_SIZE(consts); j++) { - if (PyList_GET_ITEM(consts, j) == obj) - break; - } - if (j == PyList_GET_SIZE(consts)) { - if (PyList_Append(consts, obj) < 0) - return -1; - } - assert(PyList_GET_ITEM(consts, j) == obj); - codestr[i] = LOAD_CONST; - SETARG(codestr, i, j); - return 1; -} - /* Perform basic peephole optimizations to components of a code object. The consts object should still be in list form to allow new constants to be appended. @@ -392,7 +361,6 @@ Py_ssize_t const_stack_size = 0; int in_consts = 0; /* whether we are in a LOAD_CONST sequence */ unsigned int *blocks = NULL; - char *name; /* Bail out if an exception is set */ if (PyErr_Occurred()) @@ -475,20 +443,6 @@ codestr[i+3] = NOP; break; - /* Replace LOAD_GLOBAL/LOAD_NAME None/True/False - with LOAD_CONST None/True/False */ - case LOAD_NAME: - case LOAD_GLOBAL: - j = GETARG(codestr, i); - name = _PyUnicode_AsString(PyTuple_GET_ITEM(names, j)); - h = load_global(codestr, i, name, consts); - if (h < 0) - goto exitError; - else if (h == 0) - continue; - CONST_STACK_PUSH_OP(i); - break; - /* Skip over LOAD_CONST trueconst POP_JUMP_IF_FALSE xx. This improves "while 1" performance. */ diff --git a/Python/symtable.c b/Python/symtable.c --- a/Python/symtable.c +++ b/Python/symtable.c @@ -1437,6 +1437,7 @@ case Str_kind: case Bytes_kind: case Ellipsis_kind: + case NameConstant_kind: /* Nothing to do here. */ break; /* The following exprs can be assignment targets. */ diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py --- a/Tools/parser/unparse.py +++ b/Tools/parser/unparse.py @@ -307,6 +307,9 @@ def _Name(self, t): self.write(t.id) + def _NameConstant(self, t): + self.write(repr(t.value)) + def _Num(self, t): # Substitute overflowing decimal literal for AST infinities. self.write(repr(t.n).replace("inf", INFSTR)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 6 23:50:05 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 6 Dec 2012 23:50:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_assert_than_we_never_try_t?= =?utf-8?q?o_deal_with_True=2C_False=2C_or_None_as_a_name?= Message-ID: <3YHX7x0JCrzRd5@mail.python.org> http://hg.python.org/cpython/rev/0238cc842805 changeset: 80739:0238cc842805 user: Benjamin Peterson date: Thu Dec 06 17:49:58 2012 -0500 summary: assert than we never try to deal with True, False, or None as a name files: Python/compile.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Python/compile.c b/Python/compile.c --- a/Python/compile.c +++ b/Python/compile.c @@ -2635,6 +2635,10 @@ if (!mangled) return 0; + assert(PyUnicode_CompareWithASCIIString(name, "None") && + PyUnicode_CompareWithASCIIString(name, "True") && + PyUnicode_CompareWithASCIIString(name, "False")); + op = 0; optype = OP_NAME; scope = PyST_GetScope(c->u->u_ste, mangled); -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Fri Dec 7 06:02:14 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 07 Dec 2012 06:02:14 +0100 Subject: [Python-checkins] Daily reference leaks (0238cc842805): sum=0 Message-ID: results for 0238cc842805 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog90ffar', '-x'] From python-checkins at python.org Fri Dec 7 19:18:42 2012 From: python-checkins at python.org (raymond.hettinger) Date: Fri, 7 Dec 2012 19:18:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Improve_OrderedDict_equali?= =?utf-8?q?ty_test=2E?= Message-ID: <3YJ24L3C6KzQKH@mail.python.org> http://hg.python.org/cpython/rev/026b9f5dd97f changeset: 80740:026b9f5dd97f user: Raymond Hettinger date: Fri Dec 07 10:18:22 2012 -0800 summary: Improve OrderedDict equality test. files: Lib/collections/__init__.py | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -228,8 +228,7 @@ ''' if isinstance(other, OrderedDict): - return len(self)==len(other) and \ - all(map(_eq, self.items(), other.items())) + return dict.__eq__(self, other) and all(map(_eq, self, other)) return dict.__eq__(self, other) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 00:54:14 2012 From: python-checkins at python.org (chris.jerdonek) Date: Sat, 8 Dec 2012 00:54:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316495=3A_remove_e?= =?utf-8?q?xtraneous_NULL_encoding_check_from_bytes=5Fdecode=28=29=2E?= Message-ID: <3YJ9WV1SFhzQZ7@mail.python.org> http://hg.python.org/cpython/rev/3fb9e38b00e8 changeset: 80741:3fb9e38b00e8 user: Chris Jerdonek date: Fri Dec 07 15:51:53 2012 -0800 summary: Issue #16495: remove extraneous NULL encoding check from bytes_decode(). The NULL encoding check in bytes_decode() was unnecessary because this case is already taken care of by the call to _Py_normalize_encoding() inside PyUnicode_Decode(). files: Misc/NEWS | 2 ++ Objects/bytesobject.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #16495: Remove extraneous NULL encoding check from bytes_decode(). + - Issue #16619: Create NameConstant AST class to represent None, True, and False literals. As a result, these constants are never loaded at runtime from builtins. diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2236,8 +2236,6 @@ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", kwlist, &encoding, &errors)) return NULL; - if (encoding == NULL) - encoding = PyUnicode_GetDefaultEncoding(); return PyUnicode_FromEncodedObject(self, encoding, errors); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 04:44:17 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 8 Dec 2012 04:44:17 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_add_fixer_for_reload=28=29?= =?utf-8?b?IC0+IGltcC5yZWxvYWQoKSAoY2xvc2VzICMxMTc5NylcblxuUGF0Y2ggYnkg?= =?utf-8?q?Laurie?= Message-ID: <3YJGcx5ZnjzQcC@mail.python.org> http://hg.python.org/cpython/rev/3576c0c6f860 changeset: 80742:3576c0c6f860 user: Benjamin Peterson date: Fri Dec 07 22:44:10 2012 -0500 summary: add fixer for reload() -> imp.reload() (closes #11797)\n\nPatch by Laurie Clark-Michalek and Berker Peksag files: Doc/library/2to3.rst | 4 + Lib/lib2to3/fixer_util.py | 23 +++++++ Lib/lib2to3/fixes/fix_intern.py | 21 +------ Lib/lib2to3/fixes/fix_reload.py | 28 +++++++++ Lib/lib2to3/tests/test_fixers.py | 59 ++++++++++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 2 + 7 files changed, 120 insertions(+), 18 deletions(-) diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -343,6 +343,10 @@ Handles the move of :func:`reduce` to :func:`functools.reduce`. +.. 2to3fixer:: reload + + Converts :func:`reload` to :func:`imp.reload`. + .. 2to3fixer:: renames Changes :data:`sys.maxint` to :data:`sys.maxsize`. diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py --- a/Lib/lib2to3/fixer_util.py +++ b/Lib/lib2to3/fixer_util.py @@ -129,6 +129,29 @@ imp = Node(syms.import_from, children) return imp +def ImportAndCall(node, results, names): + """Returns an import statement and calls a method + of the module: + + import module + module.name()""" + obj = results["obj"].clone() + if obj.type == syms.arglist: + newarglist = obj.clone() + else: + newarglist = Node(syms.arglist, [obj.clone()]) + after = results["after"] + if after: + after = [n.clone() for n in after] + new = Node(syms.power, + Attr(Name(names[0]), Name(names[1])) + + [Node(syms.trailer, + [results["lpar"].clone(), + newarglist, + results["rpar"].clone()])] + after) + new.prefix = node.prefix + return new + ########################################################### ### Determine whether a node represents a given literal diff --git a/Lib/lib2to3/fixes/fix_intern.py b/Lib/lib2to3/fixes/fix_intern.py --- a/Lib/lib2to3/fixes/fix_intern.py +++ b/Lib/lib2to3/fixes/fix_intern.py @@ -6,9 +6,8 @@ intern(s) -> sys.intern(s)""" # Local imports -from .. import pytree from .. import fixer_base -from ..fixer_util import Name, Attr, touch_import +from ..fixer_util import ImportAndCall, touch_import class FixIntern(fixer_base.BaseFix): @@ -26,21 +25,7 @@ """ def transform(self, node, results): - syms = self.syms - obj = results["obj"].clone() - if obj.type == syms.arglist: - newarglist = obj.clone() - else: - newarglist = pytree.Node(syms.arglist, [obj.clone()]) - after = results["after"] - if after: - after = [n.clone() for n in after] - new = pytree.Node(syms.power, - Attr(Name("sys"), Name("intern")) + - [pytree.Node(syms.trailer, - [results["lpar"].clone(), - newarglist, - results["rpar"].clone()])] + after) - new.prefix = node.prefix + names = ('sys', 'intern') + new = ImportAndCall(node, results, names) touch_import(None, 'sys', node) return new diff --git a/Lib/lib2to3/fixes/fix_reload.py b/Lib/lib2to3/fixes/fix_reload.py new file mode 100644 --- /dev/null +++ b/Lib/lib2to3/fixes/fix_reload.py @@ -0,0 +1,28 @@ +"""Fixer for reload(). + +reload(s) -> imp.reload(s)""" + +# Local imports +from .. import fixer_base +from ..fixer_util import ImportAndCall, touch_import + + +class FixReload(fixer_base.BaseFix): + BM_compatible = True + order = "pre" + + PATTERN = """ + power< 'reload' + trailer< lpar='(' + ( not(arglist | argument) any ','> ) + rpar=')' > + after=any* + > + """ + + def transform(self, node, results): + names = ('imp', 'reload') + new = ImportAndCall(node, results, names) + touch_import(None, 'imp', node) + return new diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -282,6 +282,65 @@ b = """f(*args, **kwds)""" self.check(a, b) +class Test_reload(FixerTestCase): + fixer = "reload" + + def test(self): + b = """reload(a)""" + a = """import imp\nimp.reload(a)""" + self.check(b, a) + + def test_comment(self): + b = """reload( a ) # comment""" + a = """import imp\nimp.reload( a ) # comment""" + self.check(b, a) + + # PEP 8 comments + b = """reload( a ) # comment""" + a = """import imp\nimp.reload( a ) # comment""" + self.check(b, a) + + def test_space(self): + b = """reload( a )""" + a = """import imp\nimp.reload( a )""" + self.check(b, a) + + b = """reload( a)""" + a = """import imp\nimp.reload( a)""" + self.check(b, a) + + b = """reload(a )""" + a = """import imp\nimp.reload(a )""" + self.check(b, a) + + def test_unchanged(self): + s = """reload(a=1)""" + self.unchanged(s) + + s = """reload(f, g)""" + self.unchanged(s) + + s = """reload(f, *h)""" + self.unchanged(s) + + s = """reload(f, *h, **i)""" + self.unchanged(s) + + s = """reload(f, **i)""" + self.unchanged(s) + + s = """reload(*h, **i)""" + self.unchanged(s) + + s = """reload(*h)""" + self.unchanged(s) + + s = """reload(**i)""" + self.unchanged(s) + + s = """reload()""" + self.unchanged(s) + class Test_intern(FixerTestCase): fixer = "intern" diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -214,6 +214,7 @@ Craig Citro Gilles Civario Chris Clark +Laurie Clark-Michalek Mike Clarkson Andrew Clegg Brad Clements diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -503,6 +503,8 @@ Tools/Demos ----------- +- Issue #11797: Add a 2to3 fixer that maps reload() to imp.reload(). + - Issue #10966: Remove the concept of unexpected skipped tests. - Issue #9893: Removed the Misc/Vim directory. -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sat Dec 8 06:01:27 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 08 Dec 2012 06:01:27 +0100 Subject: [Python-checkins] Daily reference leaks (3fb9e38b00e8): sum=0 Message-ID: results for 3fb9e38b00e8 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogiLxYO_', '-x'] From python-checkins at python.org Sat Dec 8 11:10:21 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 11:10:21 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NjI4?= =?utf-8?q?=3A_Fix_a_memory_leak_in_ctypes=2Eresize=28=29=2E?= Message-ID: <3YJRBP38NDzLtK@mail.python.org> http://hg.python.org/cpython/rev/1996171cfb96 changeset: 80743:1996171cfb96 branch: 3.2 parent: 80734:93742b046519 user: Antoine Pitrou date: Sat Dec 08 11:05:50 2012 +0100 summary: Issue #16628: Fix a memory leak in ctypes.resize(). files: Misc/NEWS | 2 ++ Modules/_ctypes/_ctypes.c | 2 +- Modules/_ctypes/callproc.c | 2 +- Modules/_ctypes/ctypes.h | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -175,6 +175,8 @@ Library ------- +- Issue #16628: Fix a memory leak in ctypes.resize(). + - Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2442,7 +2442,7 @@ assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) - && ((size_t)dict->size > sizeof(self->b_value))) + && _CDataObject_HasExternalBuffer(self)) PyMem_Free(self->b_ptr); self->b_ptr = NULL; Py_CLEAR(self->b_base); diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1666,7 +1666,7 @@ obj->b_size = size; goto done; } - if (obj->b_size <= sizeof(obj->b_value)) { + if (!_CDataObject_HasExternalBuffer(obj)) { /* We are currently using the objects default buffer, but it isn't large enough any more. */ void *ptr = PyMem_Malloc(size); diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -116,6 +116,7 @@ extern PyTypeObject PyCData_Type; #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) +#define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) extern PyTypeObject PyCSimpleType_Type; #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 11:10:22 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 11:10:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316628=3A_Fix_a_memory_leak_in_ctypes=2Eresize=28=29?= =?utf-8?q?=2E?= Message-ID: <3YJRBQ5cwjzQjj@mail.python.org> http://hg.python.org/cpython/rev/cae5f3266b81 changeset: 80744:cae5f3266b81 branch: 3.3 parent: 80735:3cb85250a0a3 parent: 80743:1996171cfb96 user: Antoine Pitrou date: Sat Dec 08 11:07:16 2012 +0100 summary: Issue #16628: Fix a memory leak in ctypes.resize(). files: Misc/NEWS | 2 ++ Modules/_ctypes/_ctypes.c | 2 +- Modules/_ctypes/callproc.c | 2 +- Modules/_ctypes/ctypes.h | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,8 @@ Library ------- +- Issue #16628: Fix a memory leak in ctypes.resize(). + - Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2446,7 +2446,7 @@ assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) - && ((size_t)dict->size > sizeof(self->b_value))) + && _CDataObject_HasExternalBuffer(self)) PyMem_Free(self->b_ptr); self->b_ptr = NULL; Py_CLEAR(self->b_base); diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1658,7 +1658,7 @@ obj->b_size = size; goto done; } - if (obj->b_size <= sizeof(obj->b_value)) { + if (!_CDataObject_HasExternalBuffer(obj)) { /* We are currently using the objects default buffer, but it isn't large enough any more. */ void *ptr = PyMem_Malloc(size); diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -116,6 +116,7 @@ extern PyTypeObject PyCData_Type; #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) +#define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) extern PyTypeObject PyCSimpleType_Type; #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 11:10:24 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 11:10:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316628=3A_Fix_a_memory_leak_in_ctypes=2Eresize?= =?utf-8?b?KCku?= Message-ID: <3YJRBS11w8zRL4@mail.python.org> http://hg.python.org/cpython/rev/def01022870a changeset: 80745:def01022870a parent: 80742:3576c0c6f860 parent: 80744:cae5f3266b81 user: Antoine Pitrou date: Sat Dec 08 11:07:46 2012 +0100 summary: Issue #16628: Fix a memory leak in ctypes.resize(). files: Misc/NEWS | 2 ++ Modules/_ctypes/_ctypes.c | 2 +- Modules/_ctypes/callproc.c | 2 +- Modules/_ctypes/ctypes.h | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -159,6 +159,8 @@ Library ------- +- Issue #16628: Fix a memory leak in ctypes.resize(). + - Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2446,7 +2446,7 @@ assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) - && ((size_t)dict->size > sizeof(self->b_value))) + && _CDataObject_HasExternalBuffer(self)) PyMem_Free(self->b_ptr); self->b_ptr = NULL; Py_CLEAR(self->b_base); diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1658,7 +1658,7 @@ obj->b_size = size; goto done; } - if (obj->b_size <= sizeof(obj->b_value)) { + if (!_CDataObject_HasExternalBuffer(obj)) { /* We are currently using the objects default buffer, but it isn't large enough any more. */ void *ptr = PyMem_Malloc(size); diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -116,6 +116,7 @@ extern PyTypeObject PyCData_Type; #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) +#define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) extern PyTypeObject PyCSimpleType_Type; #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 11:10:25 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 11:10:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NjI4?= =?utf-8?q?=3A_Fix_a_memory_leak_in_ctypes=2Eresize=28=29=2E?= Message-ID: <3YJRBT3WKpzRNP@mail.python.org> http://hg.python.org/cpython/rev/df5a86a22310 changeset: 80746:df5a86a22310 branch: 2.7 parent: 80737:0fd2ea06e17d user: Antoine Pitrou date: Sat Dec 08 11:05:50 2012 +0100 summary: Issue #16628: Fix a memory leak in ctypes.resize(). files: Misc/NEWS | 2 ++ Modules/_ctypes/_ctypes.c | 2 +- Modules/_ctypes/callproc.c | 2 +- Modules/_ctypes/ctypes.h | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -156,6 +156,8 @@ Library ------- +- Issue #16628: Fix a memory leak in ctypes.resize(). + - Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2530,7 +2530,7 @@ assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) - && ((size_t)dict->size > sizeof(self->b_value))) + && _CDataObject_HasExternalBuffer(self)) PyMem_Free(self->b_ptr); self->b_ptr = NULL; Py_CLEAR(self->b_base); diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1740,7 +1740,7 @@ obj->b_size = size; goto done; } - if (obj->b_size <= sizeof(obj->b_value)) { + if (!_CDataObject_HasExternalBuffer(obj)) { /* We are currently using the objects default buffer, but it isn't large enough any more. */ void *ptr = PyMem_Malloc(size); diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -153,6 +153,7 @@ extern PyTypeObject PyCData_Type; #define CDataObject_CheckExact(v) ((v)->ob_type == &PyCData_Type) #define CDataObject_Check(v) PyObject_TypeCheck(v, &PyCData_Type) +#define _CDataObject_HasExternalBuffer(v) ((v)->b_ptr != (char *)&(v)->b_value) extern PyTypeObject PyCSimpleType_Type; #define PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyCSimpleType_Type) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 11:31:10 2012 From: python-checkins at python.org (ezio.melotti) Date: Sat, 8 Dec 2012 11:31:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Remove_debug_o?= =?utf-8?q?utput_from_example=2E?= Message-ID: <3YJRfQ2Sv4zPRk@mail.python.org> http://hg.python.org/cpython/rev/57f5771de27d changeset: 80747:57f5771de27d branch: 2.7 user: Ezio Melotti date: Sat Dec 08 12:29:40 2012 +0200 summary: Remove debug output from example. files: Doc/library/fractions.rst | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst --- a/Doc/library/fractions.rst +++ b/Doc/library/fractions.rst @@ -57,7 +57,6 @@ Fraction(0, 1) >>> Fraction('3/7') Fraction(3, 7) - [40794 refs] >>> Fraction(' -3/7 ') Fraction(-3, 7) >>> Fraction('1.414213 \t\n') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 11:31:11 2012 From: python-checkins at python.org (ezio.melotti) Date: Sat, 8 Dec 2012 11:31:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Remove_debug_o?= =?utf-8?q?utput_from_example=2E?= Message-ID: <3YJRfR4yZBzQZp@mail.python.org> http://hg.python.org/cpython/rev/cac64fbf65b8 changeset: 80748:cac64fbf65b8 branch: 3.2 parent: 80743:1996171cfb96 user: Ezio Melotti date: Sat Dec 08 12:29:40 2012 +0200 summary: Remove debug output from example. files: Doc/library/fractions.rst | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst --- a/Doc/library/fractions.rst +++ b/Doc/library/fractions.rst @@ -56,7 +56,6 @@ Fraction(0, 1) >>> Fraction('3/7') Fraction(3, 7) - [40794 refs] >>> Fraction(' -3/7 ') Fraction(-3, 7) >>> Fraction('1.414213 \t\n') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 11:31:13 2012 From: python-checkins at python.org (ezio.melotti) Date: Sat, 8 Dec 2012 11:31:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_debug_output_removal_with_3=2E2=2E?= Message-ID: <3YJRfT01MSzQgs@mail.python.org> http://hg.python.org/cpython/rev/cb40fe08ff43 changeset: 80749:cb40fe08ff43 branch: 3.3 parent: 80744:cae5f3266b81 parent: 80748:cac64fbf65b8 user: Ezio Melotti date: Sat Dec 08 12:30:44 2012 +0200 summary: Merge debug output removal with 3.2. files: Doc/library/fractions.rst | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst --- a/Doc/library/fractions.rst +++ b/Doc/library/fractions.rst @@ -56,7 +56,6 @@ Fraction(0, 1) >>> Fraction('3/7') Fraction(3, 7) - [40794 refs] >>> Fraction(' -3/7 ') Fraction(-3, 7) >>> Fraction('1.414213 \t\n') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 11:31:14 2012 From: python-checkins at python.org (ezio.melotti) Date: Sat, 8 Dec 2012 11:31:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_debug_output_removal_with_3=2E3=2E?= Message-ID: <3YJRfV2DPyzQS4@mail.python.org> http://hg.python.org/cpython/rev/a2af31adc747 changeset: 80750:a2af31adc747 parent: 80745:def01022870a parent: 80749:cb40fe08ff43 user: Ezio Melotti date: Sat Dec 08 12:30:58 2012 +0200 summary: Merge debug output removal with 3.3. files: Doc/library/fractions.rst | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/Doc/library/fractions.rst b/Doc/library/fractions.rst --- a/Doc/library/fractions.rst +++ b/Doc/library/fractions.rst @@ -56,7 +56,6 @@ Fraction(0, 1) >>> Fraction('3/7') Fraction(3, 7) - [40794 refs] >>> Fraction(' -3/7 ') Fraction(-3, 7) >>> Fraction('1.414213 \t\n') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 13:24:43 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 8 Dec 2012 13:24:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE1MjA5?= =?utf-8?q?=3A_Clarify_exception_chaining_description?= Message-ID: <3YJV9R2kMdzQfl@mail.python.org> http://hg.python.org/cpython/rev/8ba3c975775b changeset: 80751:8ba3c975775b branch: 3.3 parent: 80749:cb40fe08ff43 user: Nick Coghlan date: Sat Dec 08 21:39:24 2012 +1000 summary: Issue #15209: Clarify exception chaining description - not allowed when implicitly re-raised the current exception - last exception raised is always displayed last - attempt to make it clearer when/if cause and context are shown files: Doc/library/exceptions.rst | 26 ++++++++++++++++---------- Misc/NEWS | 3 +++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -39,17 +39,23 @@ new exception is not handled the traceback that is eventually displayed will include the originating exception(s) and the final exception. -This implicit exception chain can be made explicit by using :keyword:`from` with -:keyword:`raise`. The single argument to :keyword:`from` must be an exception -or ``None``. It will be set as :attr:`__cause__` on the raised exception. -Setting :attr:`__cause__` implicitly sets the :attr:`__suppress_context__` to -``True``. If :attr:`__cause__` is an exception, it will be displayed. If -:attr:`__cause__` is present or :attr:`__suppress_context__` has a true value, -:attr:`__context__` will not be displayed. +When raising a new exception (rather than using to bare ``raise`` to re-raise +the exception currently being handled), the implicit exception chain can be +made explicit by using :keyword:`from` with :keyword:`raise`. The single +argument to :keyword:`from` must be an exception or ``None``. It will be set +as :attr:`__cause__` on the raised exception. Setting :attr:`__cause__` +also implicitly sets the :attr:`__suppress_context__` attribute to +``True``. -In either case, the default exception handling code will not display any of the -remaining links in the :attr:`__context__` chain if :attr:`__cause__` has been -set. +The default traceback display code shows these chained exceptions in +addition to the traceback for the exception itself. An explicitly chained +exception in :attr:`__cause__` is always shown when present. An implicitly +chained exception in :attr:`__context__` is shown only if :attr:`__cause__` +is not set and :attr:`__suppress_context__` is false. + +In either case, the exception itself is always shown after any chained +exceptions so that the final line of the traceback always shows the last +exception that was raised. Base classes diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -322,6 +322,9 @@ Documentation ------------- +- Issue #15209: Clarify exception chaining description in exceptions module + documentation + - Issue #15990: Improve argument/parameter documentation. - Issue #16209: Move the documentation for the str built-in function to a new -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 13:24:44 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 8 Dec 2012 13:24:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_from_3=2E3_=28Issue_=2315209=29?= Message-ID: <3YJV9S5PRhzRJQ@mail.python.org> http://hg.python.org/cpython/rev/5854101552c2 changeset: 80752:5854101552c2 parent: 80750:a2af31adc747 parent: 80751:8ba3c975775b user: Nick Coghlan date: Sat Dec 08 22:24:23 2012 +1000 summary: Merge from 3.3 (Issue #15209) files: Doc/library/exceptions.rst | 26 ++++++++++++++++---------- Misc/NEWS | 3 +++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -39,17 +39,23 @@ new exception is not handled the traceback that is eventually displayed will include the originating exception(s) and the final exception. -This implicit exception chain can be made explicit by using :keyword:`from` with -:keyword:`raise`. The single argument to :keyword:`from` must be an exception -or ``None``. It will be set as :attr:`__cause__` on the raised exception. -Setting :attr:`__cause__` implicitly sets the :attr:`__suppress_context__` to -``True``. If :attr:`__cause__` is an exception, it will be displayed. If -:attr:`__cause__` is present or :attr:`__suppress_context__` has a true value, -:attr:`__context__` will not be displayed. +When raising a new exception (rather than using to bare ``raise`` to re-raise +the exception currently being handled), the implicit exception chain can be +made explicit by using :keyword:`from` with :keyword:`raise`. The single +argument to :keyword:`from` must be an exception or ``None``. It will be set +as :attr:`__cause__` on the raised exception. Setting :attr:`__cause__` +also implicitly sets the :attr:`__suppress_context__` attribute to +``True``. -In either case, the default exception handling code will not display any of the -remaining links in the :attr:`__context__` chain if :attr:`__cause__` has been -set. +The default traceback display code shows these chained exceptions in +addition to the traceback for the exception itself. An explicitly chained +exception in :attr:`__cause__` is always shown when present. An implicitly +chained exception in :attr:`__context__` is shown only if :attr:`__cause__` +is not set and :attr:`__suppress_context__` is false. + +In either case, the exception itself is always shown after any chained +exceptions so that the final line of the traceback always shows the last +exception that was raised. Base classes diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -460,6 +460,9 @@ Documentation ------------- +- Issue #15209: Clarify exception chaining description in exceptions module + documentation + - Issue #15990: Improve argument/parameter documentation. - Issue #16209: Move the documentation for the str built-in function to a new -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 13:57:34 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 8 Dec 2012 13:57:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Close_issue_?= =?utf-8?q?=2316267=3A_better_docs_for_=40abstractmethod_composition?= Message-ID: <3YJVvL0qK3zQgw@mail.python.org> http://hg.python.org/cpython/rev/3345afd6dc61 changeset: 80753:3345afd6dc61 branch: 3.3 parent: 80751:8ba3c975775b user: Nick Coghlan date: Sat Dec 08 22:56:02 2012 +1000 summary: Close issue #16267: better docs for @abstractmethod composition files: Doc/library/abc.rst | 59 ++++++++++++++++++++++++-------- Misc/NEWS | 3 + 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -208,16 +208,20 @@ A subclass of the built-in :func:`classmethod`, indicating an abstract classmethod. Otherwise it is similar to :func:`abstractmethod`. - Usage:: + This special case is deprecated, as the :func:`classmethod` decorator + is now correctly identified as abstract when applied to an abstract + method:: class C(metaclass=ABCMeta): - @abstractclassmethod + @classmethod + @abstractmethod def my_abstract_classmethod(cls, ...): ... .. versionadded:: 3.2 .. deprecated:: 3.3 - Use :class:`classmethod` with :func:`abstractmethod` instead. + It is now possible to use :class:`classmethod` with + :func:`abstractmethod`, making this decorator redundant. .. decorator:: abstractstaticmethod(function) @@ -225,21 +229,26 @@ A subclass of the built-in :func:`staticmethod`, indicating an abstract staticmethod. Otherwise it is similar to :func:`abstractmethod`. - Usage:: + This special case is deprecated, as the :func:`staticmethod` decorator + is now correctly identified as abstract when applied to an abstract + method:: class C(metaclass=ABCMeta): - @abstractstaticmethod + @staticmethod + @abstractmethod def my_abstract_staticmethod(...): ... .. versionadded:: 3.2 .. deprecated:: 3.3 - Use :class:`staticmethod` with :func:`abstractmethod` instead. + It is now possible to use :class:`staticmethod` with + :func:`abstractmethod`, making this decorator redundant. .. decorator:: abstractproperty(fget=None, fset=None, fdel=None, doc=None) - A subclass of the built-in :func:`property`, indicating an abstract property. + A subclass of the built-in :func:`property`, indicating an abstract + property. Using this function requires that the class's metaclass is :class:`ABCMeta` or is derived from it. A class that has a metaclass derived from @@ -247,23 +256,43 @@ and properties are overridden. The abstract properties can be called using any of the normal 'super' call mechanisms. - Usage:: + This special case is deprecated, as the :func:`property` decorator + is now correctly identified as abstract when applied to an abstract + method:: class C(metaclass=ABCMeta): - @abstractproperty + @property + @abstractmethod def my_abstract_property(self): ... - This defines a read-only property; you can also define a read-write abstract - property using the 'long' form of property declaration:: + The above example defines a read-only property; you can also define a + read-write abstract property by appropriately marking one or more of the + underlying methods as abstract:: class C(metaclass=ABCMeta): - def getx(self): ... - def setx(self, value): ... - x = abstractproperty(getx, setx) + @property + def x(self): + ... + + @x.setter + @abstractmethod + def x(self, val): + ... + + If only some components are abstract, only those components need to be + updated to create a concrete property in a subclass:: + + class D(C): + @C.x.setter + def x(self, val): + ... + .. deprecated:: 3.3 - Use :class:`property` with :func:`abstractmethod` instead + It is now possible to use :class:`property`, :meth:`property.getter`, + :meth:`property.setter` and :meth:`property.deleter` with + :func:`abstractmethod`, making this decorator redundant. .. rubric:: Footnotes diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -322,6 +322,9 @@ Documentation ------------- +- Issue #16267: Better document the 3.3+ approach to combining + @abstractmethod with @staticmethod, @classmethod and @property + - Issue #15209: Clarify exception chaining description in exceptions module documentation -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 13:57:35 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 8 Dec 2012 13:57:35 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_from_3=2E3_=28issue_=2316267=29?= Message-ID: <3YJVvM4JYTzQk4@mail.python.org> http://hg.python.org/cpython/rev/be7202c38089 changeset: 80754:be7202c38089 parent: 80752:5854101552c2 parent: 80753:3345afd6dc61 user: Nick Coghlan date: Sat Dec 08 22:57:21 2012 +1000 summary: Merge from 3.3 (issue #16267) files: Doc/library/abc.rst | 59 ++++++++++++++++++++++++-------- Misc/NEWS | 3 + 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -208,16 +208,20 @@ A subclass of the built-in :func:`classmethod`, indicating an abstract classmethod. Otherwise it is similar to :func:`abstractmethod`. - Usage:: + This special case is deprecated, as the :func:`classmethod` decorator + is now correctly identified as abstract when applied to an abstract + method:: class C(metaclass=ABCMeta): - @abstractclassmethod + @classmethod + @abstractmethod def my_abstract_classmethod(cls, ...): ... .. versionadded:: 3.2 .. deprecated:: 3.3 - Use :class:`classmethod` with :func:`abstractmethod` instead. + It is now possible to use :class:`classmethod` with + :func:`abstractmethod`, making this decorator redundant. .. decorator:: abstractstaticmethod(function) @@ -225,21 +229,26 @@ A subclass of the built-in :func:`staticmethod`, indicating an abstract staticmethod. Otherwise it is similar to :func:`abstractmethod`. - Usage:: + This special case is deprecated, as the :func:`staticmethod` decorator + is now correctly identified as abstract when applied to an abstract + method:: class C(metaclass=ABCMeta): - @abstractstaticmethod + @staticmethod + @abstractmethod def my_abstract_staticmethod(...): ... .. versionadded:: 3.2 .. deprecated:: 3.3 - Use :class:`staticmethod` with :func:`abstractmethod` instead. + It is now possible to use :class:`staticmethod` with + :func:`abstractmethod`, making this decorator redundant. .. decorator:: abstractproperty(fget=None, fset=None, fdel=None, doc=None) - A subclass of the built-in :func:`property`, indicating an abstract property. + A subclass of the built-in :func:`property`, indicating an abstract + property. Using this function requires that the class's metaclass is :class:`ABCMeta` or is derived from it. A class that has a metaclass derived from @@ -247,23 +256,43 @@ and properties are overridden. The abstract properties can be called using any of the normal 'super' call mechanisms. - Usage:: + This special case is deprecated, as the :func:`property` decorator + is now correctly identified as abstract when applied to an abstract + method:: class C(metaclass=ABCMeta): - @abstractproperty + @property + @abstractmethod def my_abstract_property(self): ... - This defines a read-only property; you can also define a read-write abstract - property using the 'long' form of property declaration:: + The above example defines a read-only property; you can also define a + read-write abstract property by appropriately marking one or more of the + underlying methods as abstract:: class C(metaclass=ABCMeta): - def getx(self): ... - def setx(self, value): ... - x = abstractproperty(getx, setx) + @property + def x(self): + ... + + @x.setter + @abstractmethod + def x(self, val): + ... + + If only some components are abstract, only those components need to be + updated to create a concrete property in a subclass:: + + class D(C): + @C.x.setter + def x(self, val): + ... + .. deprecated:: 3.3 - Use :class:`property` with :func:`abstractmethod` instead + It is now possible to use :class:`property`, :meth:`property.getter`, + :meth:`property.setter` and :meth:`property.deleter` with + :func:`abstractmethod`, making this decorator redundant. .. rubric:: Footnotes diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -460,6 +460,9 @@ Documentation ------------- +- Issue #16267: Better document the 3.3+ approach to combining + @abstractmethod with @staticmethod, @classmethod and @property + - Issue #15209: Clarify exception chaining description in exceptions module documentation -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 17:01:38 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 8 Dec 2012 17:01:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Drop_double_ne?= =?utf-8?q?wlines_printed_in_some_file_iteration_examples=2E?= Message-ID: <3YJZzk2zHGzQfl@mail.python.org> http://hg.python.org/cpython/rev/fed7306f26ce changeset: 80755:fed7306f26ce branch: 3.2 parent: 80748:cac64fbf65b8 user: Andrew Svetlov date: Sat Dec 08 17:59:03 2012 +0200 summary: Drop double newlines printed in some file iteration examples. Patch by Steven Kryskalla. files: Doc/tutorial/errors.rst | 4 ++-- Misc/ACKS | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -387,7 +387,7 @@ and print its contents to the screen. :: for line in open("myfile.txt"): - print(line) + print(line, end="") The problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing. @@ -397,7 +397,7 @@ with open("myfile.txt") as f: for line in f: - print(line) + print(line, end="") After the statement is executed, the file *f* is always closed, even if a problem was encountered while processing the lines. Objects which, like files, diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -592,6 +592,7 @@ Hannu Krosing Andrej Krpic Ivan Krsti? +Steven Kryskalla Andrew Kuchling Dave Kuhlman Vladimir Kushnir -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 17:01:39 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 8 Dec 2012 17:01:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Drop_double_newlines_printed_in_some_file_iteration_examples?= =?utf-8?q?=2E?= Message-ID: <3YJZzl5Y9qzQhw@mail.python.org> http://hg.python.org/cpython/rev/268ead8ae46b changeset: 80756:268ead8ae46b branch: 3.3 parent: 80753:3345afd6dc61 parent: 80755:fed7306f26ce user: Andrew Svetlov date: Sat Dec 08 17:59:23 2012 +0200 summary: Drop double newlines printed in some file iteration examples. Patch by Steven Kryskalla. files: Doc/tutorial/errors.rst | 4 ++-- Misc/ACKS | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -387,7 +387,7 @@ and print its contents to the screen. :: for line in open("myfile.txt"): - print(line) + print(line, end="") The problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing. @@ -397,7 +397,7 @@ with open("myfile.txt") as f: for line in f: - print(line) + print(line, end="") After the statement is executed, the file *f* is always closed, even if a problem was encountered while processing the lines. Objects which, like files, diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -653,6 +653,7 @@ Hannu Krosing Andrej Krpic Ivan Krsti? +Steven Kryskalla Andrew Kuchling Dave Kuhlman Jon Kuhn -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 17:01:41 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 8 Dec 2012 17:01:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Drop_double_newlines_printed_in_some_file_iteration_exam?= =?utf-8?q?ples=2E?= Message-ID: <3YJZzn0jNwzQkp@mail.python.org> http://hg.python.org/cpython/rev/9e4b003a4d7a changeset: 80757:9e4b003a4d7a parent: 80754:be7202c38089 parent: 80756:268ead8ae46b user: Andrew Svetlov date: Sat Dec 08 17:59:58 2012 +0200 summary: Drop double newlines printed in some file iteration examples. Patch by Steven Kryskalla. files: Doc/tutorial/errors.rst | 4 ++-- Misc/ACKS | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -387,7 +387,7 @@ and print its contents to the screen. :: for line in open("myfile.txt"): - print(line) + print(line, end="") The problem with this code is that it leaves the file open for an indeterminate amount of time after this part of the code has finished executing. @@ -397,7 +397,7 @@ with open("myfile.txt") as f: for line in f: - print(line) + print(line, end="") After the statement is executed, the file *f* is always closed, even if a problem was encountered while processing the lines. Objects which, like files, diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -656,6 +656,7 @@ Hannu Krosing Andrej Krpic Ivan Krsti? +Steven Kryskalla Andrew Kuchling Dave Kuhlman Jon Kuhn -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 17:01:42 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 8 Dec 2012 17:01:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Drop_double_ne?= =?utf-8?q?wlines_printed_in_some_file_iteration_examples=2E?= Message-ID: <3YJZzp3BvgzQk4@mail.python.org> http://hg.python.org/cpython/rev/29627bd5b333 changeset: 80758:29627bd5b333 branch: 2.7 parent: 80747:57f5771de27d user: Andrew Svetlov date: Sat Dec 08 18:01:27 2012 +0200 summary: Drop double newlines printed in some file iteration examples. Patch by Steven Kryskalla. files: Doc/library/stdtypes.rst | 6 +++--- Doc/tutorial/classes.rst | 2 +- Doc/tutorial/errors.rst | 4 ++-- Misc/ACKS | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2330,7 +2330,7 @@ with open("hello.txt") as f: for line in f: - print line + print line, In older versions of Python, you would have needed to do this to get the same effect:: @@ -2338,7 +2338,7 @@ f = open("hello.txt") try: for line in f: - print line + print line, finally: f.close() @@ -2392,7 +2392,7 @@ A file object is its own iterator, for example ``iter(f)`` returns *f* (unless *f* is closed). When a file is used as an iterator, typically in a - :keyword:`for` loop (for example, ``for line in f: print line``), the + :keyword:`for` loop (for example, ``for line in f: print line.strip()``), the :meth:`~file.next` method is called repeatedly. This method returns the next input line, or raises :exc:`StopIteration` when EOF is hit when the file is open for reading (behavior is undefined when the file is open for writing). In order to diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -688,7 +688,7 @@ for char in "123": print char for line in open("myfile.txt"): - print line + print line, This style of access is clear, concise, and convenient. The use of iterators pervades and unifies Python. Behind the scenes, the :keyword:`for` statement diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -397,7 +397,7 @@ and print its contents to the screen. :: for line in open("myfile.txt"): - print line + print line, The problem with this code is that it leaves the file open for an indeterminate amount of time after the code has finished executing. This is not an issue in @@ -407,7 +407,7 @@ with open("myfile.txt") as f: for line in f: - print line + print line, After the statement is executed, the file *f* is always closed, even if a problem was encountered while processing the lines. Other objects which provide diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -546,6 +546,7 @@ Hannu Krosing Andrej Krpic Ivan Krsti? +Steven Kryskalla Andrew Kuchling Ralf W. Grosse-Kunstleve Dave Kuhlman -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 21:20:29 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 21:20:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NjAy?= =?utf-8?q?=3A_When_a_weakref=27s_target_was_part_of_a_long_deallocation_c?= =?utf-8?q?hain=2C?= Message-ID: <3YJhkP2YLGzRQg@mail.python.org> http://hg.python.org/cpython/rev/0748c22b37e5 changeset: 80759:0748c22b37e5 branch: 3.2 parent: 80755:fed7306f26ce user: Antoine Pitrou date: Sat Dec 08 21:15:26 2012 +0100 summary: Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero. Thanks to Eugene Toder for diagnosing and reporting the issue. files: Include/weakrefobject.h | 12 +++++++++++- Lib/test/test_weakref.py | 21 +++++++++++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 4 ++++ Objects/weakrefobject.c | 5 ++--- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Include/weakrefobject.h b/Include/weakrefobject.h --- a/Include/weakrefobject.h +++ b/Include/weakrefobject.h @@ -70,7 +70,17 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); #endif -#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object) +/* Explanation for the Py_REFCNT() check: when a weakref's target is part + of a long chain of deallocations which triggers the trashcan mechanism, + clearing the weakrefs can be delayed long after the target's refcount + has dropped to zero. In the meantime, code accessing the weakref will + be able to "see" the target object even though it is supposed to be + unreachable. See issue #16602. */ + +#define PyWeakref_GET_OBJECT(ref) \ + (Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0 \ + ? ((PyWeakReference *)(ref))->wr_object \ + : Py_None) #ifdef __cplusplus diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -776,6 +776,27 @@ self.assertEqual(hash(a), hash(42)) self.assertRaises(TypeError, hash, b) + def test_trashcan_16602(self): + # Issue #16602: when a weakref's target was part of a long + # deallocation chain, the trashcan mechanism could delay clearing + # of the weakref and make the target object visible from outside + # code even though its refcount had dropped to 0. A crash ensued. + class C: + def __init__(self, parent): + if not parent: + return + wself = weakref.ref(self) + def cb(wparent): + o = wself() + self.wparent = weakref.ref(parent, cb) + + d = weakref.WeakKeyDictionary() + root = c = C(None) + for n in range(100): + d[c] = c = C(c) + del root + gc.collect() + class SubclassableWeakrefTestCase(TestBase): diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1067,6 +1067,7 @@ Frank J. Tobin R Lindsay Todd Bennett Todd +Eugene Toder Erik Tollerud Matias Torchinsky Sandro Tosi diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16602: When a weakref's target was part of a long deallocation + chain, the object could remain reachable through its weakref even though + its refcount had dropped to zero. + - Issue #16416: On Mac OS X, operating system data are now always encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no locale environment variable is set), to avoid diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -52,9 +52,8 @@ { PyObject *callback = self->wr_callback; - if (PyWeakref_GET_OBJECT(self) != Py_None) { - PyWeakReference **list = GET_WEAKREFS_LISTPTR( - PyWeakref_GET_OBJECT(self)); + if (self->wr_object != Py_None) { + PyWeakReference **list = GET_WEAKREFS_LISTPTR(self->wr_object); if (*list == self) /* If 'self' is the end of the list (and thus self->wr_next == NULL) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 21:20:30 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 21:20:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316602=3A_When_a_weakref=27s_target_was_part_of_a_long?= =?utf-8?q?_deallocation_chain=2C?= Message-ID: <3YJhkQ61X0zRQj@mail.python.org> http://hg.python.org/cpython/rev/259c1636c884 changeset: 80760:259c1636c884 branch: 3.3 parent: 80756:268ead8ae46b parent: 80759:0748c22b37e5 user: Antoine Pitrou date: Sat Dec 08 21:17:03 2012 +0100 summary: Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero. Thanks to Eugene Toder for diagnosing and reporting the issue. files: Include/weakrefobject.h | 12 +++++++++++- Lib/test/test_weakref.py | 21 +++++++++++++++++++++ Misc/NEWS | 4 ++++ Objects/weakrefobject.c | 5 ++--- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Include/weakrefobject.h b/Include/weakrefobject.h --- a/Include/weakrefobject.h +++ b/Include/weakrefobject.h @@ -70,7 +70,17 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); #endif -#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object) +/* Explanation for the Py_REFCNT() check: when a weakref's target is part + of a long chain of deallocations which triggers the trashcan mechanism, + clearing the weakrefs can be delayed long after the target's refcount + has dropped to zero. In the meantime, code accessing the weakref will + be able to "see" the target object even though it is supposed to be + unreachable. See issue #16602. */ + +#define PyWeakref_GET_OBJECT(ref) \ + (Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0 \ + ? ((PyWeakReference *)(ref))->wr_object \ + : Py_None) #ifdef __cplusplus diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -776,6 +776,27 @@ self.assertEqual(hash(a), hash(42)) self.assertRaises(TypeError, hash, b) + def test_trashcan_16602(self): + # Issue #16602: when a weakref's target was part of a long + # deallocation chain, the trashcan mechanism could delay clearing + # of the weakref and make the target object visible from outside + # code even though its refcount had dropped to 0. A crash ensued. + class C: + def __init__(self, parent): + if not parent: + return + wself = weakref.ref(self) + def cb(wparent): + o = wself() + self.wparent = weakref.ref(parent, cb) + + d = weakref.WeakKeyDictionary() + root = c = C(None) + for n in range(100): + d[c] = c = C(c) + del root + gc.collect() + class SubclassableWeakrefTestCase(TestBase): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,10 @@ Core and Builtins ----------------- +- Issue #16602: When a weakref's target was part of a long deallocation + chain, the object could remain reachable through its weakref even though + its refcount had dropped to zero. + - Issue #16416: On Mac OS X, operating system data are now always encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no locale environment variable is set), to avoid diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -52,9 +52,8 @@ { PyObject *callback = self->wr_callback; - if (PyWeakref_GET_OBJECT(self) != Py_None) { - PyWeakReference **list = GET_WEAKREFS_LISTPTR( - PyWeakref_GET_OBJECT(self)); + if (self->wr_object != Py_None) { + PyWeakReference **list = GET_WEAKREFS_LISTPTR(self->wr_object); if (*list == self) /* If 'self' is the end of the list (and thus self->wr_next == NULL) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 21:20:32 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 21:20:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316602=3A_When_a_weakref=27s_target_was_part_of_?= =?utf-8?q?a_long_deallocation_chain=2C?= Message-ID: <3YJhkS1d0mzRQD@mail.python.org> http://hg.python.org/cpython/rev/17e5acad302e changeset: 80761:17e5acad302e parent: 80757:9e4b003a4d7a parent: 80760:259c1636c884 user: Antoine Pitrou date: Sat Dec 08 21:18:50 2012 +0100 summary: Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero. Thanks to Eugene Toder for diagnosing and reporting the issue. files: Include/weakrefobject.h | 12 +++++++++++- Lib/test/test_weakref.py | 21 +++++++++++++++++++++ Misc/NEWS | 4 ++++ Objects/weakrefobject.c | 5 ++--- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Include/weakrefobject.h b/Include/weakrefobject.h --- a/Include/weakrefobject.h +++ b/Include/weakrefobject.h @@ -70,7 +70,17 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); #endif -#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object) +/* Explanation for the Py_REFCNT() check: when a weakref's target is part + of a long chain of deallocations which triggers the trashcan mechanism, + clearing the weakrefs can be delayed long after the target's refcount + has dropped to zero. In the meantime, code accessing the weakref will + be able to "see" the target object even though it is supposed to be + unreachable. See issue #16602. */ + +#define PyWeakref_GET_OBJECT(ref) \ + (Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0 \ + ? ((PyWeakReference *)(ref))->wr_object \ + : Py_None) #ifdef __cplusplus diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -781,6 +781,27 @@ self.assertEqual(hash(a), hash(42)) self.assertRaises(TypeError, hash, b) + def test_trashcan_16602(self): + # Issue #16602: when a weakref's target was part of a long + # deallocation chain, the trashcan mechanism could delay clearing + # of the weakref and make the target object visible from outside + # code even though its refcount had dropped to 0. A crash ensued. + class C: + def __init__(self, parent): + if not parent: + return + wself = weakref.ref(self) + def cb(wparent): + o = wself() + self.wparent = weakref.ref(parent, cb) + + d = weakref.WeakKeyDictionary() + root = c = C(None) + for n in range(100): + d[c] = c = C(c) + del root + gc.collect() + class SubclassableWeakrefTestCase(TestBase): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16602: When a weakref's target was part of a long deallocation + chain, the object could remain reachable through its weakref even though + its refcount had dropped to zero. + - Issue #16495: Remove extraneous NULL encoding check from bytes_decode(). - Issue #16619: Create NameConstant AST class to represent None, True, and False diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -52,9 +52,8 @@ { PyObject *callback = self->wr_callback; - if (PyWeakref_GET_OBJECT(self) != Py_None) { - PyWeakReference **list = GET_WEAKREFS_LISTPTR( - PyWeakref_GET_OBJECT(self)); + if (self->wr_object != Py_None) { + PyWeakReference **list = GET_WEAKREFS_LISTPTR(self->wr_object); if (*list == self) /* If 'self' is the end of the list (and thus self->wr_next == NULL) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 8 21:23:58 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 8 Dec 2012 21:23:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NjAy?= =?utf-8?q?=3A_When_a_weakref=27s_target_was_part_of_a_long_deallocation_c?= =?utf-8?q?hain=2C?= Message-ID: <3YJhpQ3bqnzRL4@mail.python.org> http://hg.python.org/cpython/rev/7e771f0363e2 changeset: 80762:7e771f0363e2 branch: 2.7 parent: 80758:29627bd5b333 user: Antoine Pitrou date: Sat Dec 08 21:15:26 2012 +0100 summary: Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero. Thanks to Eugene Toder for diagnosing and reporting the issue. files: Include/weakrefobject.h | 12 +++++++++++- Lib/test/test_weakref.py | 21 +++++++++++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 4 ++++ Objects/weakrefobject.c | 5 ++--- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Include/weakrefobject.h b/Include/weakrefobject.h --- a/Include/weakrefobject.h +++ b/Include/weakrefobject.h @@ -66,7 +66,17 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); -#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object) +/* Explanation for the Py_REFCNT() check: when a weakref's target is part + of a long chain of deallocations which triggers the trashcan mechanism, + clearing the weakrefs can be delayed long after the target's refcount + has dropped to zero. In the meantime, code accessing the weakref will + be able to "see" the target object even though it is supposed to be + unreachable. See issue #16602. */ + +#define PyWeakref_GET_OBJECT(ref) \ + (Py_REFCNT(((PyWeakReference *)(ref))->wr_object) > 0 \ + ? ((PyWeakReference *)(ref))->wr_object \ + : Py_None) #ifdef __cplusplus diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -774,6 +774,27 @@ self.assertEqual(hash(a), hash(42)) self.assertRaises(TypeError, hash, b) + def test_trashcan_16602(self): + # Issue #16602: when a weakref's target was part of a long + # deallocation chain, the trashcan mechanism could delay clearing + # of the weakref and make the target object visible from outside + # code even though its refcount had dropped to 0. A crash ensued. + class C(object): + def __init__(self, parent): + if not parent: + return + wself = weakref.ref(self) + def cb(wparent): + o = wself() + self.wparent = weakref.ref(parent, cb) + + d = weakref.WeakKeyDictionary() + root = c = C(None) + for n in range(100): + d[c] = c = C(c) + del root + gc.collect() + class SubclassableWeakrefTestCase(TestBase): diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -990,6 +990,7 @@ Frank J. Tobin R Lindsay Todd Bennett Todd +Eugene Toder Matias Torchinsky Sandro Tosi Richard Townsend diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,10 @@ Core and Builtins ----------------- +- Issue #16602: When a weakref's target was part of a long deallocation + chain, the object could remain reachable through its weakref even though + its refcount had dropped to zero. + - Issue #9011: Fix hacky AST code that modified the CST when compiling a negated numeric literal. diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -52,9 +52,8 @@ { PyObject *callback = self->wr_callback; - if (PyWeakref_GET_OBJECT(self) != Py_None) { - PyWeakReference **list = GET_WEAKREFS_LISTPTR( - PyWeakref_GET_OBJECT(self)); + if (self->wr_object != Py_None) { + PyWeakReference **list = GET_WEAKREFS_LISTPTR(self->wr_object); if (*list == self) /* If 'self' is the end of the list (and thus self->wr_next == NULL) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:46:05 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:46:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Add_versioncha?= =?utf-8?q?nged_note_for_a56cebff113a?= Message-ID: <3YJtcY1RnrzRSx@mail.python.org> http://hg.python.org/cpython/rev/802f529f886f changeset: 80763:802f529f886f branch: 2.7 parent: 80758:29627bd5b333 user: ?ric Araujo date: Sat Dec 08 14:18:26 2012 -0500 summary: Add versionchanged note for a56cebff113a files: Doc/distutils/apiref.rst | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -991,6 +991,9 @@ these files is available in answer D2 of the `NFS FAQ page `_. + .. versionchanged:: 2.7.4 + NFS files are ignored. + .. function:: remove_tree(directory[, verbose=0, dry_run=0]) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:46:06 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:46:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Remove_code_un?= =?utf-8?q?needed_after_f833e7ec4de1?= Message-ID: <3YJtcZ3nkfzRTQ@mail.python.org> http://hg.python.org/cpython/rev/d9fe5b5a8110 changeset: 80764:d9fe5b5a8110 branch: 2.7 user: ?ric Araujo date: Sat Dec 08 14:41:39 2012 -0500 summary: Remove code unneeded after f833e7ec4de1 files: Lib/distutils/config.py | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-) diff --git a/Lib/distutils/config.py b/Lib/distutils/config.py --- a/Lib/distutils/config.py +++ b/Lib/distutils/config.py @@ -47,11 +47,6 @@ f.write(DEFAULT_PYPIRC % (username, password)) finally: f.close() - try: - os.chmod(rc, 0600) - except OSError: - # should do something better here - pass def _read_pypirc(self): """Reads the .pypirc file.""" -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:46:07 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:46:07 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogRml4IHNldHVwLnB5?= =?utf-8?q?_register_failure_with_invalid_rst_in_description_=28=2313614?= =?utf-8?b?KS4=?= Message-ID: <3YJtcb6XKrzRTw@mail.python.org> http://hg.python.org/cpython/rev/692be1f9fa1d changeset: 80765:692be1f9fa1d branch: 2.7 user: ?ric Araujo date: Sat Dec 08 22:26:57 2012 -0500 summary: Fix setup.py register failure with invalid rst in description (#13614). Original patch by Julien Courteau and Pierre Paul Lefebvre. files: Lib/distutils/command/check.py | 3 + Lib/distutils/tests/test_register.py | 25 +++++++++++++-- Misc/ACKS | 2 + Misc/NEWS | 3 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -26,6 +26,9 @@ def system_message(self, level, message, *children, **kwargs): self.messages.append((level, message, children, kwargs)) + return nodes.system_message(message, level=level, + type=self.levels[level], + *children, **kwargs) HAS_DOCUTILS = True except ImportError: diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -1,6 +1,5 @@ # -*- encoding: utf8 -*- """Tests for distutils.command.register.""" -import sys import os import unittest import getpass @@ -11,11 +10,14 @@ from distutils.command import register as register_module from distutils.command.register import register -from distutils.core import Distribution from distutils.errors import DistutilsSetupError -from distutils.tests import support -from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +from distutils.tests.test_config import PyPIRCCommandTestCase + +try: + import docutils +except ImportError: + docutils = None PYPIRC_NOPASSWORD = """\ [distutils] @@ -264,6 +266,21 @@ finally: del register_module.raw_input + @unittest.skipUnless(docutils is not None, 'needs docutils') + def test_register_invalid_long_description(self): + description = ':funkie:`str`' # mimic Sphinx-specific markup + metadata = {'url': 'xxx', 'author': 'xxx', + 'author_email': 'xxx', + 'name': 'xxx', 'version': 'xxx', + 'long_description': description} + cmd = self._get_cmd(metadata) + cmd.ensure_finalized() + cmd.strict = True + inputs = RawInputs('2', 'tarek', 'tarek at ziade.org') + register_module.raw_input = inputs + self.addCleanup(delattr, register_module, 'raw_input') + self.assertRaises(DistutilsSetupError, cmd.run) + def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated cmd = self._get_cmd() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -201,6 +201,7 @@ Scott Cotton Greg Couch David Cournapeau +Julien Courteau Steve Cousins Alex Coventry Matthew Dixon Cowles @@ -572,6 +573,7 @@ Thomas Lee Christopher Lee Luc Lefebvre +Pierre Paul Lefebvre Glyph Lefkowitz Vincent Legoll Kip Lehman diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -158,6 +158,9 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #13614: Fix setup.py register failure with invalid rst in description. + Patch by Julien Courteau and Pierre Paul Lefebvre. + - Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:46:09 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:46:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Use_proper_ski?= =?utf-8?q?p_instead_of_reporting_success_in_one_distutils_test?= Message-ID: <3YJtcd1sH5zRTb@mail.python.org> http://hg.python.org/cpython/rev/2383114ad7bd changeset: 80766:2383114ad7bd branch: 2.7 user: ?ric Araujo date: Sat Dec 08 22:30:47 2012 -0500 summary: Use proper skip instead of reporting success in one distutils test files: Lib/distutils/tests/test_register.py | 8 +------- 1 files changed, 1 insertions(+), 7 deletions(-) diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -194,6 +194,7 @@ self.assertEqual(headers['Content-length'], '290') self.assertTrue('tarek' in req.data) + @unittest.skipUnless(docutils is not None, 'needs docutils') def test_strict(self): # testing the script option # when on, the register command stops if @@ -206,13 +207,6 @@ cmd.strict = 1 self.assertRaises(DistutilsSetupError, cmd.run) - # we don't test the reSt feature if docutils - # is not installed - try: - import docutils - except ImportError: - return - # metadata are OK but long_description is broken metadata = {'url': 'xxx', 'author': 'xxx', 'author_email': u'?x?x?', -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:46:10 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:46:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMi43IC0+IDIuNyk6?= =?utf-8?q?_Branch_merge?= Message-ID: <3YJtcf5d3HzRVj@mail.python.org> http://hg.python.org/cpython/rev/80f0c7d5deda changeset: 80767:80f0c7d5deda branch: 2.7 parent: 80762:7e771f0363e2 parent: 80766:2383114ad7bd user: ?ric Araujo date: Sat Dec 08 22:45:09 2012 -0500 summary: Branch merge files: Doc/distutils/apiref.rst | 3 + Lib/distutils/command/check.py | 3 + Lib/distutils/config.py | 5 -- Lib/distutils/tests/test_register.py | 33 ++++++++++----- Misc/ACKS | 2 + Misc/NEWS | 3 + 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -991,6 +991,9 @@ these files is available in answer D2 of the `NFS FAQ page `_. + .. versionchanged:: 2.7.4 + NFS files are ignored. + .. function:: remove_tree(directory[, verbose=0, dry_run=0]) diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -26,6 +26,9 @@ def system_message(self, level, message, *children, **kwargs): self.messages.append((level, message, children, kwargs)) + return nodes.system_message(message, level=level, + type=self.levels[level], + *children, **kwargs) HAS_DOCUTILS = True except ImportError: diff --git a/Lib/distutils/config.py b/Lib/distutils/config.py --- a/Lib/distutils/config.py +++ b/Lib/distutils/config.py @@ -47,11 +47,6 @@ f.write(DEFAULT_PYPIRC % (username, password)) finally: f.close() - try: - os.chmod(rc, 0600) - except OSError: - # should do something better here - pass def _read_pypirc(self): """Reads the .pypirc file.""" diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -1,6 +1,5 @@ # -*- encoding: utf8 -*- """Tests for distutils.command.register.""" -import sys import os import unittest import getpass @@ -11,11 +10,14 @@ from distutils.command import register as register_module from distutils.command.register import register -from distutils.core import Distribution from distutils.errors import DistutilsSetupError -from distutils.tests import support -from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +from distutils.tests.test_config import PyPIRCCommandTestCase + +try: + import docutils +except ImportError: + docutils = None PYPIRC_NOPASSWORD = """\ [distutils] @@ -192,6 +194,7 @@ self.assertEqual(headers['Content-length'], '290') self.assertTrue('tarek' in req.data) + @unittest.skipUnless(docutils is not None, 'needs docutils') def test_strict(self): # testing the script option # when on, the register command stops if @@ -204,13 +207,6 @@ cmd.strict = 1 self.assertRaises(DistutilsSetupError, cmd.run) - # we don't test the reSt feature if docutils - # is not installed - try: - import docutils - except ImportError: - return - # metadata are OK but long_description is broken metadata = {'url': 'xxx', 'author': 'xxx', 'author_email': u'?x?x?', @@ -264,6 +260,21 @@ finally: del register_module.raw_input + @unittest.skipUnless(docutils is not None, 'needs docutils') + def test_register_invalid_long_description(self): + description = ':funkie:`str`' # mimic Sphinx-specific markup + metadata = {'url': 'xxx', 'author': 'xxx', + 'author_email': 'xxx', + 'name': 'xxx', 'version': 'xxx', + 'long_description': description} + cmd = self._get_cmd(metadata) + cmd.ensure_finalized() + cmd.strict = True + inputs = RawInputs('2', 'tarek', 'tarek at ziade.org') + register_module.raw_input = inputs + self.addCleanup(delattr, register_module, 'raw_input') + self.assertRaises(DistutilsSetupError, cmd.run) + def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated cmd = self._get_cmd() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -201,6 +201,7 @@ Scott Cotton Greg Couch David Cournapeau +Julien Courteau Steve Cousins Alex Coventry Matthew Dixon Cowles @@ -572,6 +573,7 @@ Thomas Lee Christopher Lee Luc Lefebvre +Pierre Paul Lefebvre Glyph Lefkowitz Vincent Legoll Kip Lehman diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -162,6 +162,9 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #13614: Fix setup.py register failure with invalid rst in description. + Patch by Julien Courteau and Pierre Paul Lefebvre. + - Issue #10182: The re module doesn't truncate indices to 32 bits anymore. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:57:22 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:57:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSWdub3JlIC5uZnMq?= =?utf-8?q?_files_in_distutils_=28=237719=29=2E?= Message-ID: <3YJtsZ0MyKzRTn@mail.python.org> http://hg.python.org/cpython/rev/d978828bfd0e changeset: 80768:d978828bfd0e branch: 3.2 parent: 80755:fed7306f26ce user: ?ric Araujo date: Sat Dec 08 14:21:51 2012 -0500 summary: Ignore .nfs* files in distutils (#7719). These files are created by some NFS clients a file is edited and removed concurrently (see added link in doc for more info). If such a file is removed between distutils calls listdir and copy, it will get confused. Other special files are ignored in sdist (namely VCS directories), but this has to be filtered out earlier. files: Doc/distutils/apiref.rst | 6 ++++ Lib/distutils/dir_util.py | 4 +++ Lib/distutils/tests/test_dir_util.py | 21 ++++++++++++--- Lib/distutils/tests/test_sdist.py | 7 +++-- Misc/NEWS | 3 ++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -992,6 +992,12 @@ destination of the symlink will be copied. *update* and *verbose* are the same as for :func:`copy_file`. + Files in *src* that begin with :file:`.nfs` are skipped (more information on + these files is available in answer D2 of the `NFS FAQ page + `_. + + .. versionchanged:: 3.2.4 + NFS files are ignored. .. function:: remove_tree(directory[, verbose=0, dry_run=0]) diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -141,6 +141,10 @@ src_name = os.path.join(src, n) dst_name = os.path.join(dst, n) + if n.startswith('.nfs'): + # skip NFS rename files + continue + if preserve_symlinks and os.path.islink(src_name): link_dest = os.readlink(src_name) if verbose >= 1: diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py --- a/Lib/distutils/tests/test_dir_util.py +++ b/Lib/distutils/tests/test_dir_util.py @@ -76,7 +76,6 @@ remove_tree(self.root_target, verbose=0) - def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) @@ -88,11 +87,8 @@ mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') - f = open(a_file, 'w') - try: + with open(a_file, 'w') as f: f.write('some content') - finally: - f.close() wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) @@ -101,6 +97,21 @@ remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0) + def test_copy_tree_skips_nfs_temp_files(self): + mkpath(self.target, verbose=0) + + a_file = os.path.join(self.target, 'ok.txt') + nfs_file = os.path.join(self.target, '.nfs123abc') + for f in a_file, nfs_file: + with open(f, 'w') as fh: + fh.write('some content') + + copy_tree(self.target, self.target2) + self.assertEqual(os.listdir(self.target2), ['ok.txt']) + + remove_tree(self.root_target, verbose=0) + remove_tree(self.target2, verbose=0) + def test_ensure_relative(self): if os.sep == '/': self.assertEqual(ensure_relative('/home/foo'), 'home/foo') diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py --- a/Lib/distutils/tests/test_sdist.py +++ b/Lib/distutils/tests/test_sdist.py @@ -83,9 +83,8 @@ @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') def test_prune_file_list(self): - # this test creates a package with some vcs dirs in it - # and launch sdist to make sure they get pruned - # on all systems + # this test creates a project with some VCS dirs and an NFS rename + # file, then launches sdist to check they get pruned on all systems # creating VCS directories with some files in them os.mkdir(join(self.tmp_dir, 'somecode', '.svn')) @@ -99,6 +98,8 @@ self.write_file((self.tmp_dir, 'somecode', '.git', 'ok'), 'xxx') + self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx') + # now building a sdist dist, cmd = self.get_cmd() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -177,6 +177,9 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later + on. Initial patch by SilentGhost and Jeff Ramnani. + - Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:57:23 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:57:23 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogQ3JlYXRlIH4vLnB5?= =?utf-8?q?pirc_securely_=28=2313512=29=2E?= Message-ID: <3YJtsb2nKyzRVp@mail.python.org> http://hg.python.org/cpython/rev/4a2814f24a10 changeset: 80769:4a2814f24a10 branch: 3.2 user: ?ric Araujo date: Sat Dec 08 14:51:47 2012 -0500 summary: Create ~/.pypirc securely (#13512). There was a window between the write and the chmod where the user?s password would be exposed, depending on default permissions. Philip Jenvey?s patch fixes it. files: Lib/distutils/config.py | 11 +---------- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Lib/distutils/config.py b/Lib/distutils/config.py --- a/Lib/distutils/config.py +++ b/Lib/distutils/config.py @@ -4,7 +4,6 @@ that uses .pypirc in the distutils.command package. """ import os -import sys from configparser import ConfigParser from distutils.cmd import Command @@ -43,16 +42,8 @@ def _store_pypirc(self, username, password): """Creates a default .pypirc file.""" rc = self._get_rc_file() - f = open(rc, 'w') - try: + with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f: f.write(DEFAULT_PYPIRC % (username, password)) - finally: - f.close() - try: - os.chmod(rc, 0o600) - except OSError: - # should do something better here - pass def _read_pypirc(self): """Reads the .pypirc file.""" diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -512,6 +512,7 @@ Drew Jenkins Flemming Kj?r Jensen Philip H. Jensen +Philip Jenvey MunSic Jeong Chris Jerdonek Pedro Diaz Jimenez diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -177,6 +177,9 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #13512: Create ~/.pypirc securely (CVE-2011-4944). Initial patch by + Philip Jenvey, tested by Mageia and Debian. + - Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later on. Initial patch by SilentGhost and Jeff Ramnani. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:57:24 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:57:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_a_few_mark?= =?utf-8?q?up/grammar_nits?= Message-ID: <3YJtsc4xt8zRVL@mail.python.org> http://hg.python.org/cpython/rev/594325babdb8 changeset: 80770:594325babdb8 branch: 3.2 user: ?ric Araujo date: Sat Dec 08 18:35:31 2012 -0500 summary: Fix a few markup/grammar nits files: Doc/library/abc.rst | 6 +++--- Doc/library/io.rst | 2 +- Doc/library/sys.rst | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -126,7 +126,7 @@ It also provides the following decorators: -.. decorator:: abstractmethod(function) +.. decorator:: abstractmethod A decorator indicating abstract methods. @@ -161,7 +161,7 @@ multiple-inheritance. -.. decorator:: abstractclassmethod(function) +.. decorator:: abstractclassmethod A subclass of the built-in :func:`classmethod`, indicating an abstract classmethod. Otherwise it is similar to :func:`abstractmethod`. @@ -176,7 +176,7 @@ .. versionadded:: 3.2 -.. decorator:: abstractstaticmethod(function) +.. decorator:: abstractstaticmethod A subclass of the built-in :func:`staticmethod`, indicating an abstract staticmethod. Otherwise it is similar to :func:`abstractmethod`. diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -236,7 +236,7 @@ Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise :exc:`IOError` in this case. - IOBase (and its subclasses) support the iterator protocol, meaning that an + IOBase (and its subclasses) supports the iterator protocol, meaning that an :class:`IOBase` object can be iterated over yielding the lines in a stream. Lines are defined slightly differently depending on whether the stream is a binary stream (yielding bytes), or a text stream (yielding character diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -739,7 +739,7 @@ For other systems, the values are: ====================== =========================== - System :data:`platform` value + System ``platform`` value ====================== =========================== Linux (2.x *and* 3.x) ``'linux2'`` Windows ``'win32'`` -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:57:26 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:57:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4IHNldHVwLnB5?= =?utf-8?q?_register_failure_with_invalid_rst_in_description_=28=2313614?= =?utf-8?b?KS4=?= Message-ID: <3YJtsf1LyJzRTm@mail.python.org> http://hg.python.org/cpython/rev/99c80e8a721e changeset: 80771:99c80e8a721e branch: 3.2 user: ?ric Araujo date: Sat Dec 08 22:41:11 2012 -0500 summary: Fix setup.py register failure with invalid rst in description (#13614). Original patch by Julien Courteau and Pierre Paul Lefebvre. files: Lib/distutils/command/check.py | 3 + Lib/distutils/tests/test_register.py | 34 ++++++++++----- Misc/ACKS | 2 + Misc/NEWS | 3 + 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -23,6 +23,9 @@ def system_message(self, level, message, *children, **kwargs): self.messages.append((level, message, children, kwargs)) + return nodes.system_message(message, level=level, + type=self.levels[level], + *children, **kwargs) HAS_DOCUTILS = True except Exception: diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -1,5 +1,4 @@ """Tests for distutils.command.register.""" -import sys import os import unittest import getpass @@ -10,11 +9,14 @@ from distutils.command import register as register_module from distutils.command.register import register -from distutils.core import Distribution from distutils.errors import DistutilsSetupError -from distutils.tests import support -from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +from distutils.tests.test_config import PyPIRCCommandTestCase + +try: + import docutils +except ImportError: + docutils = None PYPIRC_NOPASSWORD = """\ [distutils] @@ -193,6 +195,7 @@ self.assertEqual(headers['Content-length'], '290') self.assertTrue((b'tarek') in req.data) + @unittest.skipUnless(docutils is not None, 'needs docutils') def test_strict(self): # testing the script option # when on, the register command stops if @@ -205,13 +208,6 @@ cmd.strict = 1 self.assertRaises(DistutilsSetupError, cmd.run) - # we don't test the reSt feature if docutils - # is not installed - try: - import docutils - except ImportError: - return - # metadata are OK but long_description is broken metadata = {'url': 'xxx', 'author': 'xxx', 'author_email': '?x?x?', @@ -265,6 +261,22 @@ finally: del register_module.input + @unittest.skipUnless(docutils is not None, 'needs docutils') + def test_register_invalid_long_description(self): + description = ':funkie:`str`' # mimic Sphinx-specific markup + metadata = {'url': 'xxx', 'author': 'xxx', + 'author_email': 'xxx', + 'name': 'xxx', 'version': 'xxx', + 'long_description': description} + cmd = self._get_cmd(metadata) + cmd.ensure_finalized() + cmd.strict = True + inputs = Inputs('2', 'tarek', 'tarek at ziade.org') + register_module.input = inputs + self.addCleanup(delattr, register_module, 'input') + + self.assertRaises(DistutilsSetupError, cmd.run) + def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated cmd = self._get_cmd() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -222,6 +222,7 @@ Scott Cotton Greg Couch David Cournapeau +Julien Courteau Steve Cousins Alex Coventry Matthew Dixon Cowles @@ -621,6 +622,7 @@ Christopher Lee Tennessee Leeuwenburg Luc Lefebvre +Pierre Paul Lefebvre Glyph Lefkowitz Vincent Legoll Kip Lehman diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -177,6 +177,9 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #13614: Fix setup.py register failure with invalid rst in description. + Patch by Julien Courteau and Pierre Paul Lefebvre. + - Issue #13512: Create ~/.pypirc securely (CVE-2011-4944). Initial patch by Philip Jenvey, tested by Mageia and Debian. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:57:27 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:57:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMik6?= =?utf-8?q?_Branch_merge?= Message-ID: <3YJtsg58rGzRTv@mail.python.org> http://hg.python.org/cpython/rev/ffb64a074b66 changeset: 80772:ffb64a074b66 branch: 3.2 parent: 80759:0748c22b37e5 parent: 80771:99c80e8a721e user: ?ric Araujo date: Sat Dec 08 22:47:03 2012 -0500 summary: Branch merge files: Doc/distutils/apiref.rst | 6 ++ Doc/library/abc.rst | 6 +- Doc/library/io.rst | 2 +- Doc/library/sys.rst | 2 +- Lib/distutils/command/check.py | 3 + Lib/distutils/config.py | 11 +---- Lib/distutils/dir_util.py | 4 + Lib/distutils/tests/test_dir_util.py | 21 +++++++-- Lib/distutils/tests/test_register.py | 34 ++++++++++----- Lib/distutils/tests/test_sdist.py | 7 +- Misc/ACKS | 3 + Misc/NEWS | 9 ++++ 12 files changed, 74 insertions(+), 34 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -992,6 +992,12 @@ destination of the symlink will be copied. *update* and *verbose* are the same as for :func:`copy_file`. + Files in *src* that begin with :file:`.nfs` are skipped (more information on + these files is available in answer D2 of the `NFS FAQ page + `_. + + .. versionchanged:: 3.2.4 + NFS files are ignored. .. function:: remove_tree(directory[, verbose=0, dry_run=0]) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -126,7 +126,7 @@ It also provides the following decorators: -.. decorator:: abstractmethod(function) +.. decorator:: abstractmethod A decorator indicating abstract methods. @@ -161,7 +161,7 @@ multiple-inheritance. -.. decorator:: abstractclassmethod(function) +.. decorator:: abstractclassmethod A subclass of the built-in :func:`classmethod`, indicating an abstract classmethod. Otherwise it is similar to :func:`abstractmethod`. @@ -176,7 +176,7 @@ .. versionadded:: 3.2 -.. decorator:: abstractstaticmethod(function) +.. decorator:: abstractstaticmethod A subclass of the built-in :func:`staticmethod`, indicating an abstract staticmethod. Otherwise it is similar to :func:`abstractmethod`. diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -236,7 +236,7 @@ Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise :exc:`IOError` in this case. - IOBase (and its subclasses) support the iterator protocol, meaning that an + IOBase (and its subclasses) supports the iterator protocol, meaning that an :class:`IOBase` object can be iterated over yielding the lines in a stream. Lines are defined slightly differently depending on whether the stream is a binary stream (yielding bytes), or a text stream (yielding character diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -739,7 +739,7 @@ For other systems, the values are: ====================== =========================== - System :data:`platform` value + System ``platform`` value ====================== =========================== Linux (2.x *and* 3.x) ``'linux2'`` Windows ``'win32'`` diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -23,6 +23,9 @@ def system_message(self, level, message, *children, **kwargs): self.messages.append((level, message, children, kwargs)) + return nodes.system_message(message, level=level, + type=self.levels[level], + *children, **kwargs) HAS_DOCUTILS = True except Exception: diff --git a/Lib/distutils/config.py b/Lib/distutils/config.py --- a/Lib/distutils/config.py +++ b/Lib/distutils/config.py @@ -4,7 +4,6 @@ that uses .pypirc in the distutils.command package. """ import os -import sys from configparser import ConfigParser from distutils.cmd import Command @@ -43,16 +42,8 @@ def _store_pypirc(self, username, password): """Creates a default .pypirc file.""" rc = self._get_rc_file() - f = open(rc, 'w') - try: + with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f: f.write(DEFAULT_PYPIRC % (username, password)) - finally: - f.close() - try: - os.chmod(rc, 0o600) - except OSError: - # should do something better here - pass def _read_pypirc(self): """Reads the .pypirc file.""" diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -141,6 +141,10 @@ src_name = os.path.join(src, n) dst_name = os.path.join(dst, n) + if n.startswith('.nfs'): + # skip NFS rename files + continue + if preserve_symlinks and os.path.islink(src_name): link_dest = os.readlink(src_name) if verbose >= 1: diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py --- a/Lib/distutils/tests/test_dir_util.py +++ b/Lib/distutils/tests/test_dir_util.py @@ -76,7 +76,6 @@ remove_tree(self.root_target, verbose=0) - def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) @@ -88,11 +87,8 @@ mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') - f = open(a_file, 'w') - try: + with open(a_file, 'w') as f: f.write('some content') - finally: - f.close() wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) @@ -101,6 +97,21 @@ remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0) + def test_copy_tree_skips_nfs_temp_files(self): + mkpath(self.target, verbose=0) + + a_file = os.path.join(self.target, 'ok.txt') + nfs_file = os.path.join(self.target, '.nfs123abc') + for f in a_file, nfs_file: + with open(f, 'w') as fh: + fh.write('some content') + + copy_tree(self.target, self.target2) + self.assertEqual(os.listdir(self.target2), ['ok.txt']) + + remove_tree(self.root_target, verbose=0) + remove_tree(self.target2, verbose=0) + def test_ensure_relative(self): if os.sep == '/': self.assertEqual(ensure_relative('/home/foo'), 'home/foo') diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -1,5 +1,4 @@ """Tests for distutils.command.register.""" -import sys import os import unittest import getpass @@ -10,11 +9,14 @@ from distutils.command import register as register_module from distutils.command.register import register -from distutils.core import Distribution from distutils.errors import DistutilsSetupError -from distutils.tests import support -from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +from distutils.tests.test_config import PyPIRCCommandTestCase + +try: + import docutils +except ImportError: + docutils = None PYPIRC_NOPASSWORD = """\ [distutils] @@ -193,6 +195,7 @@ self.assertEqual(headers['Content-length'], '290') self.assertTrue((b'tarek') in req.data) + @unittest.skipUnless(docutils is not None, 'needs docutils') def test_strict(self): # testing the script option # when on, the register command stops if @@ -205,13 +208,6 @@ cmd.strict = 1 self.assertRaises(DistutilsSetupError, cmd.run) - # we don't test the reSt feature if docutils - # is not installed - try: - import docutils - except ImportError: - return - # metadata are OK but long_description is broken metadata = {'url': 'xxx', 'author': 'xxx', 'author_email': '?x?x?', @@ -265,6 +261,22 @@ finally: del register_module.input + @unittest.skipUnless(docutils is not None, 'needs docutils') + def test_register_invalid_long_description(self): + description = ':funkie:`str`' # mimic Sphinx-specific markup + metadata = {'url': 'xxx', 'author': 'xxx', + 'author_email': 'xxx', + 'name': 'xxx', 'version': 'xxx', + 'long_description': description} + cmd = self._get_cmd(metadata) + cmd.ensure_finalized() + cmd.strict = True + inputs = Inputs('2', 'tarek', 'tarek at ziade.org') + register_module.input = inputs + self.addCleanup(delattr, register_module, 'input') + + self.assertRaises(DistutilsSetupError, cmd.run) + def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated cmd = self._get_cmd() diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py --- a/Lib/distutils/tests/test_sdist.py +++ b/Lib/distutils/tests/test_sdist.py @@ -83,9 +83,8 @@ @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') def test_prune_file_list(self): - # this test creates a package with some vcs dirs in it - # and launch sdist to make sure they get pruned - # on all systems + # this test creates a project with some VCS dirs and an NFS rename + # file, then launches sdist to check they get pruned on all systems # creating VCS directories with some files in them os.mkdir(join(self.tmp_dir, 'somecode', '.svn')) @@ -99,6 +98,8 @@ self.write_file((self.tmp_dir, 'somecode', '.git', 'ok'), 'xxx') + self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx') + # now building a sdist dist, cmd = self.get_cmd() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -222,6 +222,7 @@ Scott Cotton Greg Couch David Cournapeau +Julien Courteau Steve Cousins Alex Coventry Matthew Dixon Cowles @@ -512,6 +513,7 @@ Drew Jenkins Flemming Kj?r Jensen Philip H. Jensen +Philip Jenvey MunSic Jeong Chris Jerdonek Pedro Diaz Jimenez @@ -620,6 +622,7 @@ Christopher Lee Tennessee Leeuwenburg Luc Lefebvre +Pierre Paul Lefebvre Glyph Lefkowitz Vincent Legoll Kip Lehman diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -181,6 +181,15 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #13614: Fix setup.py register failure with invalid rst in description. + Patch by Julien Courteau and Pierre Paul Lefebvre. + +- Issue #13512: Create ~/.pypirc securely (CVE-2011-4944). Initial patch by + Philip Jenvey, tested by Mageia and Debian. + +- Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later + on. Initial patch by SilentGhost and Jeff Ramnani. + - Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:57:29 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:57:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_fixes_for_=2313614=2C_=2313512_and_=237719_from_3=2E2?= Message-ID: <3YJtsj1q27zRVW@mail.python.org> http://hg.python.org/cpython/rev/10ab746f55fb changeset: 80773:10ab746f55fb branch: 3.3 parent: 80760:259c1636c884 parent: 80772:ffb64a074b66 user: ?ric Araujo date: Sat Dec 08 22:53:43 2012 -0500 summary: Merge fixes for #13614, #13512 and #7719 from 3.2 files: Doc/distutils/apiref.rst | 6 ++ Doc/library/abc.rst | 6 +- Doc/library/io.rst | 2 +- Doc/library/sys.rst | 2 +- Lib/distutils/command/check.py | 3 + Lib/distutils/config.py | 11 +---- Lib/distutils/dir_util.py | 4 + Lib/distutils/tests/test_dir_util.py | 21 +++++++-- Lib/distutils/tests/test_register.py | 34 ++++++++++----- Lib/distutils/tests/test_sdist.py | 7 +- Misc/ACKS | 3 + Misc/NEWS | 9 ++++ 12 files changed, 74 insertions(+), 34 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -992,6 +992,12 @@ destination of the symlink will be copied. *update* and *verbose* are the same as for :func:`copy_file`. + Files in *src* that begin with :file:`.nfs` are skipped (more information on + these files is available in answer D2 of the `NFS FAQ page + `_. + + .. versionchanged:: 3.3.1 + NFS files are ignored. .. function:: remove_tree(directory[, verbose=0, dry_run=0]) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -129,7 +129,7 @@ The :mod:`abc` module also provides the following decorators: -.. decorator:: abstractmethod(function) +.. decorator:: abstractmethod A decorator indicating abstract methods. @@ -203,7 +203,7 @@ multiple-inheritance. -.. decorator:: abstractclassmethod(function) +.. decorator:: abstractclassmethod A subclass of the built-in :func:`classmethod`, indicating an abstract classmethod. Otherwise it is similar to :func:`abstractmethod`. @@ -224,7 +224,7 @@ :func:`abstractmethod`, making this decorator redundant. -.. decorator:: abstractstaticmethod(function) +.. decorator:: abstractstaticmethod A subclass of the built-in :func:`staticmethod`, indicating an abstract staticmethod. Otherwise it is similar to :func:`abstractmethod`. diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -232,7 +232,7 @@ Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise :exc:`ValueError` in this case. - :class:`IOBase` (and its subclasses) support the iterator protocol, meaning + :class:`IOBase` (and its subclasses) supports the iterator protocol, meaning that an :class:`IOBase` object can be iterated over yielding the lines in a stream. Lines are defined slightly differently depending on whether the stream is a binary stream (yielding bytes), or a text stream (yielding diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -833,7 +833,7 @@ For other systems, the values are: ================ =========================== - System :data:`platform` value + System ``platform`` value ================ =========================== Linux ``'linux'`` Windows ``'win32'`` diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -23,6 +23,9 @@ def system_message(self, level, message, *children, **kwargs): self.messages.append((level, message, children, kwargs)) + return nodes.system_message(message, level=level, + type=self.levels[level], + *children, **kwargs) HAS_DOCUTILS = True except Exception: diff --git a/Lib/distutils/config.py b/Lib/distutils/config.py --- a/Lib/distutils/config.py +++ b/Lib/distutils/config.py @@ -4,7 +4,6 @@ that uses .pypirc in the distutils.command package. """ import os -import sys from configparser import ConfigParser from distutils.cmd import Command @@ -43,16 +42,8 @@ def _store_pypirc(self, username, password): """Creates a default .pypirc file.""" rc = self._get_rc_file() - f = open(rc, 'w') - try: + with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f: f.write(DEFAULT_PYPIRC % (username, password)) - finally: - f.close() - try: - os.chmod(rc, 0o600) - except OSError: - # should do something better here - pass def _read_pypirc(self): """Reads the .pypirc file.""" diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -141,6 +141,10 @@ src_name = os.path.join(src, n) dst_name = os.path.join(dst, n) + if n.startswith('.nfs'): + # skip NFS rename files + continue + if preserve_symlinks and os.path.islink(src_name): link_dest = os.readlink(src_name) if verbose >= 1: diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py --- a/Lib/distutils/tests/test_dir_util.py +++ b/Lib/distutils/tests/test_dir_util.py @@ -76,7 +76,6 @@ remove_tree(self.root_target, verbose=0) - def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) @@ -88,11 +87,8 @@ mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') - f = open(a_file, 'w') - try: + with open(a_file, 'w') as f: f.write('some content') - finally: - f.close() wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) @@ -101,6 +97,21 @@ remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0) + def test_copy_tree_skips_nfs_temp_files(self): + mkpath(self.target, verbose=0) + + a_file = os.path.join(self.target, 'ok.txt') + nfs_file = os.path.join(self.target, '.nfs123abc') + for f in a_file, nfs_file: + with open(f, 'w') as fh: + fh.write('some content') + + copy_tree(self.target, self.target2) + self.assertEqual(os.listdir(self.target2), ['ok.txt']) + + remove_tree(self.root_target, verbose=0) + remove_tree(self.target2, verbose=0) + def test_ensure_relative(self): if os.sep == '/': self.assertEqual(ensure_relative('/home/foo'), 'home/foo') diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -1,5 +1,4 @@ """Tests for distutils.command.register.""" -import sys import os import unittest import getpass @@ -10,11 +9,14 @@ from distutils.command import register as register_module from distutils.command.register import register -from distutils.core import Distribution from distutils.errors import DistutilsSetupError -from distutils.tests import support -from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +from distutils.tests.test_config import PyPIRCCommandTestCase + +try: + import docutils +except ImportError: + docutils = None PYPIRC_NOPASSWORD = """\ [distutils] @@ -193,6 +195,7 @@ self.assertEqual(headers['Content-length'], '290') self.assertTrue((b'tarek') in req.data) + @unittest.skipUnless(docutils is not None, 'needs docutils') def test_strict(self): # testing the script option # when on, the register command stops if @@ -205,13 +208,6 @@ cmd.strict = 1 self.assertRaises(DistutilsSetupError, cmd.run) - # we don't test the reSt feature if docutils - # is not installed - try: - import docutils - except ImportError: - return - # metadata are OK but long_description is broken metadata = {'url': 'xxx', 'author': 'xxx', 'author_email': '?x?x?', @@ -265,6 +261,22 @@ finally: del register_module.input + @unittest.skipUnless(docutils is not None, 'needs docutils') + def test_register_invalid_long_description(self): + description = ':funkie:`str`' # mimic Sphinx-specific markup + metadata = {'url': 'xxx', 'author': 'xxx', + 'author_email': 'xxx', + 'name': 'xxx', 'version': 'xxx', + 'long_description': description} + cmd = self._get_cmd(metadata) + cmd.ensure_finalized() + cmd.strict = True + inputs = Inputs('2', 'tarek', 'tarek at ziade.org') + register_module.input = inputs + self.addCleanup(delattr, register_module, 'input') + + self.assertRaises(DistutilsSetupError, cmd.run) + def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated cmd = self._get_cmd() diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py --- a/Lib/distutils/tests/test_sdist.py +++ b/Lib/distutils/tests/test_sdist.py @@ -83,9 +83,8 @@ @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') def test_prune_file_list(self): - # this test creates a package with some vcs dirs in it - # and launch sdist to make sure they get pruned - # on all systems + # this test creates a project with some VCS dirs and an NFS rename + # file, then launches sdist to check they get pruned on all systems # creating VCS directories with some files in them os.mkdir(join(self.tmp_dir, 'somecode', '.svn')) @@ -99,6 +98,8 @@ self.write_file((self.tmp_dir, 'somecode', '.git', 'ok'), 'xxx') + self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx') + # now building a sdist dist, cmd = self.get_cmd() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -242,6 +242,7 @@ Scott Cotton Greg Couch David Cournapeau +Julien Courteau Steve Cousins Alex Coventry Matthew Dixon Cowles @@ -564,6 +565,7 @@ Drew Jenkins Flemming Kj?r Jensen Philip H. Jensen +Philip Jenvey MunSic Jeong Chris Jerdonek Jim Jewett @@ -685,6 +687,7 @@ Thomas Lee Tennessee Leeuwenburg Luc Lefebvre +Pierre Paul Lefebvre Glyph Lefkowitz Vincent Legoll Kip Lehman diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -110,6 +110,15 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #13614: Fix setup.py register failure with invalid rst in description. + Patch by Julien Courteau and Pierre Paul Lefebvre. + +- Issue #13512: Create ~/.pypirc securely (CVE-2011-4944). Initial patch by + Philip Jenvey, tested by Mageia and Debian. + +- Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later + on. Initial patch by SilentGhost and Jeff Ramnani. + - Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 04:57:30 2012 From: python-checkins at python.org (eric.araujo) Date: Sun, 9 Dec 2012 04:57:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_fixes_for_=2313614=2C_=2313512_and_=237719_from_3?= =?utf-8?q?=2E3?= Message-ID: <3YJtsk5bngzRV9@mail.python.org> http://hg.python.org/cpython/rev/b10c1c6f869f changeset: 80774:b10c1c6f869f parent: 80761:17e5acad302e parent: 80773:10ab746f55fb user: ?ric Araujo date: Sat Dec 08 22:57:08 2012 -0500 summary: Merge fixes for #13614, #13512 and #7719 from 3.3 files: Doc/distutils/apiref.rst | 6 ++ Doc/library/abc.rst | 6 +- Doc/library/io.rst | 2 +- Doc/library/sys.rst | 2 +- Lib/distutils/command/check.py | 3 + Lib/distutils/config.py | 11 +---- Lib/distutils/dir_util.py | 4 + Lib/distutils/tests/test_dir_util.py | 21 +++++++-- Lib/distutils/tests/test_register.py | 34 ++++++++++----- Lib/distutils/tests/test_sdist.py | 7 +- Misc/ACKS | 3 + Misc/NEWS | 9 ++++ 12 files changed, 74 insertions(+), 34 deletions(-) diff --git a/Doc/distutils/apiref.rst b/Doc/distutils/apiref.rst --- a/Doc/distutils/apiref.rst +++ b/Doc/distutils/apiref.rst @@ -992,6 +992,12 @@ destination of the symlink will be copied. *update* and *verbose* are the same as for :func:`copy_file`. + Files in *src* that begin with :file:`.nfs` are skipped (more information on + these files is available in answer D2 of the `NFS FAQ page + `_. + + .. versionchanged:: 3.3.1 + NFS files are ignored. .. function:: remove_tree(directory[, verbose=0, dry_run=0]) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -129,7 +129,7 @@ The :mod:`abc` module also provides the following decorators: -.. decorator:: abstractmethod(function) +.. decorator:: abstractmethod A decorator indicating abstract methods. @@ -203,7 +203,7 @@ multiple-inheritance. -.. decorator:: abstractclassmethod(function) +.. decorator:: abstractclassmethod A subclass of the built-in :func:`classmethod`, indicating an abstract classmethod. Otherwise it is similar to :func:`abstractmethod`. @@ -224,7 +224,7 @@ :func:`abstractmethod`, making this decorator redundant. -.. decorator:: abstractstaticmethod(function) +.. decorator:: abstractstaticmethod A subclass of the built-in :func:`staticmethod`, indicating an abstract staticmethod. Otherwise it is similar to :func:`abstractmethod`. diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -232,7 +232,7 @@ Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise :exc:`ValueError` in this case. - :class:`IOBase` (and its subclasses) support the iterator protocol, meaning + :class:`IOBase` (and its subclasses) supports the iterator protocol, meaning that an :class:`IOBase` object can be iterated over yielding the lines in a stream. Lines are defined slightly differently depending on whether the stream is a binary stream (yielding bytes), or a text stream (yielding diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -833,7 +833,7 @@ For other systems, the values are: ================ =========================== - System :data:`platform` value + System ``platform`` value ================ =========================== Linux ``'linux'`` Windows ``'win32'`` diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -23,6 +23,9 @@ def system_message(self, level, message, *children, **kwargs): self.messages.append((level, message, children, kwargs)) + return nodes.system_message(message, level=level, + type=self.levels[level], + *children, **kwargs) HAS_DOCUTILS = True except Exception: diff --git a/Lib/distutils/config.py b/Lib/distutils/config.py --- a/Lib/distutils/config.py +++ b/Lib/distutils/config.py @@ -4,7 +4,6 @@ that uses .pypirc in the distutils.command package. """ import os -import sys from configparser import ConfigParser from distutils.cmd import Command @@ -43,16 +42,8 @@ def _store_pypirc(self, username, password): """Creates a default .pypirc file.""" rc = self._get_rc_file() - f = open(rc, 'w') - try: + with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f: f.write(DEFAULT_PYPIRC % (username, password)) - finally: - f.close() - try: - os.chmod(rc, 0o600) - except OSError: - # should do something better here - pass def _read_pypirc(self): """Reads the .pypirc file.""" diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -141,6 +141,10 @@ src_name = os.path.join(src, n) dst_name = os.path.join(dst, n) + if n.startswith('.nfs'): + # skip NFS rename files + continue + if preserve_symlinks and os.path.islink(src_name): link_dest = os.readlink(src_name) if verbose >= 1: diff --git a/Lib/distutils/tests/test_dir_util.py b/Lib/distutils/tests/test_dir_util.py --- a/Lib/distutils/tests/test_dir_util.py +++ b/Lib/distutils/tests/test_dir_util.py @@ -76,7 +76,6 @@ remove_tree(self.root_target, verbose=0) - def test_copy_tree_verbosity(self): mkpath(self.target, verbose=0) @@ -88,11 +87,8 @@ mkpath(self.target, verbose=0) a_file = os.path.join(self.target, 'ok.txt') - f = open(a_file, 'w') - try: + with open(a_file, 'w') as f: f.write('some content') - finally: - f.close() wanted = ['copying %s -> %s' % (a_file, self.target2)] copy_tree(self.target, self.target2, verbose=1) @@ -101,6 +97,21 @@ remove_tree(self.root_target, verbose=0) remove_tree(self.target2, verbose=0) + def test_copy_tree_skips_nfs_temp_files(self): + mkpath(self.target, verbose=0) + + a_file = os.path.join(self.target, 'ok.txt') + nfs_file = os.path.join(self.target, '.nfs123abc') + for f in a_file, nfs_file: + with open(f, 'w') as fh: + fh.write('some content') + + copy_tree(self.target, self.target2) + self.assertEqual(os.listdir(self.target2), ['ok.txt']) + + remove_tree(self.root_target, verbose=0) + remove_tree(self.target2, verbose=0) + def test_ensure_relative(self): if os.sep == '/': self.assertEqual(ensure_relative('/home/foo'), 'home/foo') diff --git a/Lib/distutils/tests/test_register.py b/Lib/distutils/tests/test_register.py --- a/Lib/distutils/tests/test_register.py +++ b/Lib/distutils/tests/test_register.py @@ -1,5 +1,4 @@ """Tests for distutils.command.register.""" -import sys import os import unittest import getpass @@ -10,11 +9,14 @@ from distutils.command import register as register_module from distutils.command.register import register -from distutils.core import Distribution from distutils.errors import DistutilsSetupError -from distutils.tests import support -from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase +from distutils.tests.test_config import PyPIRCCommandTestCase + +try: + import docutils +except ImportError: + docutils = None PYPIRC_NOPASSWORD = """\ [distutils] @@ -193,6 +195,7 @@ self.assertEqual(headers['Content-length'], '290') self.assertTrue((b'tarek') in req.data) + @unittest.skipUnless(docutils is not None, 'needs docutils') def test_strict(self): # testing the script option # when on, the register command stops if @@ -205,13 +208,6 @@ cmd.strict = 1 self.assertRaises(DistutilsSetupError, cmd.run) - # we don't test the reSt feature if docutils - # is not installed - try: - import docutils - except ImportError: - return - # metadata are OK but long_description is broken metadata = {'url': 'xxx', 'author': 'xxx', 'author_email': '?x?x?', @@ -265,6 +261,22 @@ finally: del register_module.input + @unittest.skipUnless(docutils is not None, 'needs docutils') + def test_register_invalid_long_description(self): + description = ':funkie:`str`' # mimic Sphinx-specific markup + metadata = {'url': 'xxx', 'author': 'xxx', + 'author_email': 'xxx', + 'name': 'xxx', 'version': 'xxx', + 'long_description': description} + cmd = self._get_cmd(metadata) + cmd.ensure_finalized() + cmd.strict = True + inputs = Inputs('2', 'tarek', 'tarek at ziade.org') + register_module.input = inputs + self.addCleanup(delattr, register_module, 'input') + + self.assertRaises(DistutilsSetupError, cmd.run) + def test_check_metadata_deprecated(self): # makes sure make_metadata is deprecated cmd = self._get_cmd() diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py --- a/Lib/distutils/tests/test_sdist.py +++ b/Lib/distutils/tests/test_sdist.py @@ -83,9 +83,8 @@ @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') def test_prune_file_list(self): - # this test creates a package with some vcs dirs in it - # and launch sdist to make sure they get pruned - # on all systems + # this test creates a project with some VCS dirs and an NFS rename + # file, then launches sdist to check they get pruned on all systems # creating VCS directories with some files in them os.mkdir(join(self.tmp_dir, 'somecode', '.svn')) @@ -99,6 +98,8 @@ self.write_file((self.tmp_dir, 'somecode', '.git', 'ok'), 'xxx') + self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx') + # now building a sdist dist, cmd = self.get_cmd() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -243,6 +243,7 @@ Scott Cotton Greg Couch David Cournapeau +Julien Courteau Steve Cousins Alex Coventry Matthew Dixon Cowles @@ -566,6 +567,7 @@ Drew Jenkins Flemming Kj?r Jensen Philip H. Jensen +Philip Jenvey MunSic Jeong Chris Jerdonek Jim Jewett @@ -688,6 +690,7 @@ Thomas Lee Tennessee Leeuwenburg Luc Lefebvre +Pierre Paul Lefebvre Glyph Lefkowitz Vincent Legoll Kip Lehman diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -165,6 +165,15 @@ - Issue #16628: Fix a memory leak in ctypes.resize(). +- Issue #13614: Fix setup.py register failure with invalid rst in description. + Patch by Julien Courteau and Pierre Paul Lefebvre. + +- Issue #13512: Create ~/.pypirc securely (CVE-2011-4944). Initial patch by + Philip Jenvey, tested by Mageia and Debian. + +- Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later + on. Initial patch by SilentGhost and Jeff Ramnani. + - Issue #13120: Allow to call pdb.set_trace() from thread. Patch by Ilya Sandler. -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sun Dec 9 05:59:21 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 09 Dec 2012 05:59:21 +0100 Subject: [Python-checkins] Daily reference leaks (17e5acad302e): sum=0 Message-ID: results for 17e5acad302e on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogXCWQ2f', '-x'] From python-checkins at python.org Sun Dec 9 07:22:30 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 9 Dec 2012 07:22:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE1MjA5?= =?utf-8?q?=3A_Fix_typo_and_some_additional_wording_tweaks?= Message-ID: <3YJy524jJpzQKy@mail.python.org> http://hg.python.org/cpython/rev/3b67247f0bbb changeset: 80775:3b67247f0bbb branch: 3.3 parent: 80773:10ab746f55fb user: Nick Coghlan date: Sun Dec 09 16:21:46 2012 +1000 summary: Issue #15209: Fix typo and some additional wording tweaks files: Doc/library/exceptions.rst | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -39,19 +39,27 @@ new exception is not handled the traceback that is eventually displayed will include the originating exception(s) and the final exception. -When raising a new exception (rather than using to bare ``raise`` to re-raise -the exception currently being handled), the implicit exception chain can be -made explicit by using :keyword:`from` with :keyword:`raise`. The single -argument to :keyword:`from` must be an exception or ``None``. It will be set -as :attr:`__cause__` on the raised exception. Setting :attr:`__cause__` -also implicitly sets the :attr:`__suppress_context__` attribute to -``True``. +When raising a new exception (rather than using a bare ``raise`` to re-raise +the exception currently being handled), the implicit exception context can be +supplemented with an explicit cause by using :keyword:`from` with +:keyword:`raise`:: + + raise new_exc from original_exc + +The expression following :keyword:`from` must be an exception or ``None``. It +will be set as :attr:`__cause__` on the raised exception. Setting +:attr:`__cause__` also implicitly sets the :attr:`__suppress_context__` +attribute to ``True``, so that using ``raise new_exc from None`` +effectively replaces the old exception with the new one for display +purposes (e.g. converting :exc:`KeyError` to :exc:`AttributeError`, while +leaving the old exception available in :attr:`__context__` for introspection +when debugging. The default traceback display code shows these chained exceptions in addition to the traceback for the exception itself. An explicitly chained exception in :attr:`__cause__` is always shown when present. An implicitly chained exception in :attr:`__context__` is shown only if :attr:`__cause__` -is not set and :attr:`__suppress_context__` is false. +is :const:`None` and :attr:`__suppress_context__` is false. In either case, the exception itself is always shown after any chained exceptions so that the final line of the traceback always shows the last -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 07:22:31 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 9 Dec 2012 07:22:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_from_3=2E3_=28issue_=2315209=29?= Message-ID: <3YJy53750NzRSK@mail.python.org> http://hg.python.org/cpython/rev/04eb89e078b5 changeset: 80776:04eb89e078b5 parent: 80774:b10c1c6f869f parent: 80775:3b67247f0bbb user: Nick Coghlan date: Sun Dec 09 16:22:17 2012 +1000 summary: Merge from 3.3 (issue #15209) files: Doc/library/exceptions.rst | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -39,19 +39,27 @@ new exception is not handled the traceback that is eventually displayed will include the originating exception(s) and the final exception. -When raising a new exception (rather than using to bare ``raise`` to re-raise -the exception currently being handled), the implicit exception chain can be -made explicit by using :keyword:`from` with :keyword:`raise`. The single -argument to :keyword:`from` must be an exception or ``None``. It will be set -as :attr:`__cause__` on the raised exception. Setting :attr:`__cause__` -also implicitly sets the :attr:`__suppress_context__` attribute to -``True``. +When raising a new exception (rather than using a bare ``raise`` to re-raise +the exception currently being handled), the implicit exception context can be +supplemented with an explicit cause by using :keyword:`from` with +:keyword:`raise`:: + + raise new_exc from original_exc + +The expression following :keyword:`from` must be an exception or ``None``. It +will be set as :attr:`__cause__` on the raised exception. Setting +:attr:`__cause__` also implicitly sets the :attr:`__suppress_context__` +attribute to ``True``, so that using ``raise new_exc from None`` +effectively replaces the old exception with the new one for display +purposes (e.g. converting :exc:`KeyError` to :exc:`AttributeError`, while +leaving the old exception available in :attr:`__context__` for introspection +when debugging. The default traceback display code shows these chained exceptions in addition to the traceback for the exception itself. An explicitly chained exception in :attr:`__cause__` is always shown when present. An implicitly chained exception in :attr:`__context__` is shown only if :attr:`__cause__` -is not set and :attr:`__suppress_context__` is false. +is :const:`None` and :attr:`__suppress_context__` is false. In either case, the exception itself is always shown after any chained exceptions so that the final line of the traceback always shows the last -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 14:29:59 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 9 Dec 2012 14:29:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2313390=3A_New_func?= =?utf-8?q?tion_=3Afunc=3A=60sys=2Egetallocatedblocks=28=29=60_returns_the?= =?utf-8?q?_number?= Message-ID: <3YK7ZH2zCmzRSV@mail.python.org> http://hg.python.org/cpython/rev/c40f4c19d20b changeset: 80777:c40f4c19d20b user: Antoine Pitrou date: Sun Dec 09 14:28:26 2012 +0100 summary: Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated. Also, the ``-R`` option to regrtest uses this function to guard against memory allocation leaks. files: Doc/library/sys.rst | 14 ++++++++ Include/objimpl.h | 2 + Lib/test/regrtest.py | 54 +++++++++++++++++++++---------- Lib/test/support.py | 2 +- Lib/test/test_sys.py | 24 ++++++++++++++ Misc/NEWS | 6 +++ Objects/obmalloc.c | 21 +++++++++++- Python/pythonrun.c | 7 ++- Python/sysmodule.c | 15 ++++++++ 9 files changed, 123 insertions(+), 22 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -393,6 +393,20 @@ .. versionadded:: 3.1 +.. function:: getallocatedblocks() + + Return the number of memory blocks currently allocated by the interpreter, + regardless of their size. This function is mainly useful for debugging + small memory leaks. Because of the interpreter's internal caches, the + result can vary from call to call; you may have to call + :func:`_clear_type_cache()` to get more predictable results. + + .. versionadded:: 3.4 + + .. impl-detail:: + Not all Python implementations may be able to return this information. + + .. function:: getcheckinterval() Return the interpreter's "check interval"; see :func:`setcheckinterval`. diff --git a/Include/objimpl.h b/Include/objimpl.h --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -98,6 +98,8 @@ PyAPI_FUNC(void *) PyObject_Realloc(void *, size_t); PyAPI_FUNC(void) PyObject_Free(void *); +/* This function returns the number of allocated memory blocks, regardless of size */ +PyAPI_FUNC(Py_ssize_t) _Py_GetAllocatedBlocks(void); /* Macros */ #ifdef WITH_PYMALLOC diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -615,7 +615,7 @@ sys.exit(2) from queue import Queue from subprocess import Popen, PIPE - debug_output_pat = re.compile(r"\[\d+ refs\]$") + debug_output_pat = re.compile(r"\[\d+ refs, \d+ blocks\]$") output = Queue() pending = MultiprocessTests(tests) opt_args = support.args_from_interpreter_flags() @@ -1320,33 +1320,50 @@ del sys.modules[the_module.__name__] exec('import ' + the_module.__name__) - deltas = [] nwarmup, ntracked, fname = huntrleaks fname = os.path.join(support.SAVEDCWD, fname) repcount = nwarmup + ntracked + rc_deltas = [0] * repcount + alloc_deltas = [0] * repcount + print("beginning", repcount, "repetitions", file=sys.stderr) print(("1234567890"*(repcount//10 + 1))[:repcount], file=sys.stderr) sys.stderr.flush() - dash_R_cleanup(fs, ps, pic, zdc, abcs) for i in range(repcount): - rc_before = sys.gettotalrefcount() run_the_test() + alloc_after, rc_after = dash_R_cleanup(fs, ps, pic, zdc, abcs) sys.stderr.write('.') sys.stderr.flush() - dash_R_cleanup(fs, ps, pic, zdc, abcs) - rc_after = sys.gettotalrefcount() if i >= nwarmup: - deltas.append(rc_after - rc_before) + rc_deltas[i] = rc_after - rc_before + alloc_deltas[i] = alloc_after - alloc_before + alloc_before, rc_before = alloc_after, rc_after print(file=sys.stderr) - if any(deltas): - msg = '%s leaked %s references, sum=%s' % (test, deltas, sum(deltas)) - print(msg, file=sys.stderr) - sys.stderr.flush() - with open(fname, "a") as refrep: - print(msg, file=refrep) - refrep.flush() - return True - return False + # These checkers return False on success, True on failure + def check_rc_deltas(deltas): + return any(deltas) + def check_alloc_deltas(deltas): + # At least 1/3rd of 0s + if 3 * deltas.count(0) < len(deltas): + return True + # Nothing else than 1s, 0s and -1s + if not set(deltas) <= {1,0,-1}: + return True + return False + failed = False + for deltas, item_name, checker in [ + (rc_deltas, 'references', check_rc_deltas), + (alloc_deltas, 'memory blocks', check_alloc_deltas)]: + if checker(deltas): + msg = '%s leaked %s %s, sum=%s' % ( + test, deltas[nwarmup:], item_name, sum(deltas)) + print(msg, file=sys.stderr) + sys.stderr.flush() + with open(fname, "a") as refrep: + print(msg, file=refrep) + refrep.flush() + failed = True + return failed def dash_R_cleanup(fs, ps, pic, zdc, abcs): import gc, copyreg @@ -1412,8 +1429,11 @@ else: ctypes._reset_cache() - # Collect cyclic trash. + # Collect cyclic trash and read memory statistics immediately after. + func1 = sys.getallocatedblocks + func2 = sys.gettotalrefcount gc.collect() + return func1(), func2() def warm_caches(): # char cache diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -1772,7 +1772,7 @@ This will typically be run on the result of the communicate() method of a subprocess.Popen object. """ - stderr = re.sub(br"\[\d+ refs\]\r?\n?", b"", stderr).strip() + stderr = re.sub(br"\[\d+ refs, \d+ blocks\]\r?\n?", b"", stderr).strip() return stderr def args_from_interpreter_flags(): diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -6,6 +6,7 @@ import warnings import operator import codecs +import gc # count the number of test runs, used to create unique # strings to intern in test_intern() @@ -611,6 +612,29 @@ ret, out, err = assert_python_ok(*args) self.assertIn(b"free PyDictObjects", err) + @unittest.skipUnless(hasattr(sys, "getallocatedblocks"), + "sys.getallocatedblocks unavailable on this build") + def test_getallocatedblocks(self): + # Some sanity checks + a = sys.getallocatedblocks() + self.assertIs(type(a), int) + self.assertGreater(a, 0) + try: + # While we could imagine a Python session where the number of + # multiple buffer objects would exceed the sharing of references, + # it is unlikely to happen in a normal test run. + self.assertLess(a, sys.gettotalrefcount()) + except AttributeError: + # gettotalrefcount() not available + pass + gc.collect() + b = sys.getallocatedblocks() + self.assertLessEqual(b, a) + gc.collect() + c = sys.getallocatedblocks() + self.assertIn(c, range(b - 50, b + 50)) + + class SizeofTest(unittest.TestCase): def setUp(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -163,6 +163,9 @@ Library ------- +- Issue #13390: New function :func:`sys.getallocatedblocks()` returns the + number of memory blocks currently allocated. + - Issue #16628: Fix a memory leak in ctypes.resize(). - Issue #13614: Fix setup.py register failure with invalid rst in description. @@ -433,6 +436,9 @@ Tests ----- +- Issue #13390: The ``-R`` option to regrtest now also checks for memory + allocation leaks, using :func:`sys.getallocatedblocks()`. + - Issue #16559: Add more tests for the json module, including some from the official test suite at json.org. Patch by Serhiy Storchaka. diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -525,6 +525,15 @@ /* High water mark (max value ever seen) for narenas_currently_allocated. */ static size_t narenas_highwater = 0; +static Py_ssize_t _Py_AllocatedBlocks = 0; + +Py_ssize_t +_Py_GetAllocatedBlocks(void) +{ + return _Py_AllocatedBlocks; +} + + /* Allocate a new arena. If we run out of memory, return NULL. Else * allocate a new arena, and return the address of an arena_object * describing the new arena. It's expected that the caller will set @@ -785,6 +794,8 @@ if (nbytes > PY_SSIZE_T_MAX) return NULL; + _Py_AllocatedBlocks++; + /* * This implicitly redirects malloc(0). */ @@ -901,6 +912,7 @@ * and free list are already initialized. */ bp = pool->freeblock; + assert(bp != NULL); pool->freeblock = *(block **)bp; UNLOCK(); return (void *)bp; @@ -958,7 +970,12 @@ */ if (nbytes == 0) nbytes = 1; - return (void *)malloc(nbytes); + { + void *result = malloc(nbytes); + if (!result) + _Py_AllocatedBlocks--; + return result; + } } /* free */ @@ -978,6 +995,8 @@ if (p == NULL) /* free(NULL) has no effect */ return; + _Py_AllocatedBlocks--; + #ifdef WITH_VALGRIND if (UNLIKELY(running_on_valgrind > 0)) goto redirect; diff --git a/Python/pythonrun.c b/Python/pythonrun.c --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -38,9 +38,10 @@ #ifndef Py_REF_DEBUG #define PRINT_TOTAL_REFS() #else /* Py_REF_DEBUG */ -#define PRINT_TOTAL_REFS() fprintf(stderr, \ - "[%" PY_FORMAT_SIZE_T "d refs]\n", \ - _Py_GetRefTotal()) +#define PRINT_TOTAL_REFS() fprintf(stderr, \ + "[%" PY_FORMAT_SIZE_T "d refs, " \ + "%" PY_FORMAT_SIZE_T "d blocks]\n", \ + _Py_GetRefTotal(), _Py_GetAllocatedBlocks()) #endif #ifdef __cplusplus diff --git a/Python/sysmodule.c b/Python/sysmodule.c --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -894,6 +894,19 @@ reference as an argument to getrefcount()." ); +static PyObject * +sys_getallocatedblocks(PyObject *self) +{ + return PyLong_FromSsize_t(_Py_GetAllocatedBlocks()); +} + +PyDoc_STRVAR(getallocatedblocks_doc, +"getallocatedblocks() -> integer\n\ +\n\ +Return the number of memory blocks currently allocated, regardless of their\n\ +size." +); + #ifdef COUNT_ALLOCS static PyObject * sys_getcounts(PyObject *self) @@ -1062,6 +1075,8 @@ {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, getdlopenflags_doc}, #endif + {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, + getallocatedblocks_doc}, #ifdef COUNT_ALLOCS {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 14:48:58 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 9 Dec 2012 14:48:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2MjQ4?= =?utf-8?q?=3A_Disable_code_execution_from_the_user=27s_home_directory_by_?= =?utf-8?q?tkinter?= Message-ID: <3YK80B2wGbzRSX@mail.python.org> http://hg.python.org/cpython/rev/d8300842a0e9 changeset: 80778:d8300842a0e9 branch: 3.2 parent: 80772:ffb64a074b66 user: Antoine Pitrou date: Sun Dec 09 14:46:18 2012 +0100 summary: Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. files: Lib/tkinter/__init__.py | 4 +++- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1698,7 +1698,9 @@ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) if useTk: self._loadtk() - self.readprofile(baseName, className) + if not sys.flags.ignore_environment: + # Issue #16248: Honor the -E flag to avoid code injection. + self.readprofile(baseName, className) def loadtk(self): if not self._tkloaded: self.tk.loadtk() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,9 @@ Library ------- +- Issue #16248: Disable code execution from the user's home directory by + tkinter when the -E flag is passed to Python. Patch by Zachary Ware. + - Issue #16628: Fix a memory leak in ctypes.resize(). - Issue #13614: Fix setup.py register failure with invalid rst in description. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 14:48:59 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 9 Dec 2012 14:48:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316248=3A_Disable_code_execution_from_the_user=27s_hom?= =?utf-8?q?e_directory_by_tkinter?= Message-ID: <3YK80C5gY1zRT8@mail.python.org> http://hg.python.org/cpython/rev/10d04bdb05ab changeset: 80779:10d04bdb05ab branch: 3.3 parent: 80775:3b67247f0bbb parent: 80778:d8300842a0e9 user: Antoine Pitrou date: Sun Dec 09 14:46:46 2012 +0100 summary: Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. files: Lib/tkinter/__init__.py | 4 +++- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1756,7 +1756,9 @@ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) if useTk: self._loadtk() - self.readprofile(baseName, className) + if not sys.flags.ignore_environment: + # Issue #16248: Honor the -E flag to avoid code injection. + self.readprofile(baseName, className) def loadtk(self): if not self._tkloaded: self.tk.loadtk() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,9 @@ Library ------- +- Issue #16248: Disable code execution from the user's home directory by + tkinter when the -E flag is passed to Python. Patch by Zachary Ware. + - Issue #16628: Fix a memory leak in ctypes.resize(). - Issue #13614: Fix setup.py register failure with invalid rst in description. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 14:49:01 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 9 Dec 2012 14:49:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316248=3A_Disable_code_execution_from_the_user?= =?utf-8?q?=27s_home_directory_by_tkinter?= Message-ID: <3YK80F1FtkzRVH@mail.python.org> http://hg.python.org/cpython/rev/a4fc52da295b changeset: 80780:a4fc52da295b parent: 80777:c40f4c19d20b parent: 80779:10d04bdb05ab user: Antoine Pitrou date: Sun Dec 09 14:47:23 2012 +0100 summary: Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. files: Lib/tkinter/__init__.py | 4 +++- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1756,7 +1756,9 @@ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) if useTk: self._loadtk() - self.readprofile(baseName, className) + if not sys.flags.ignore_environment: + # Issue #16248: Honor the -E flag to avoid code injection. + self.readprofile(baseName, className) def loadtk(self): if not self._tkloaded: self.tk.loadtk() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -163,6 +163,9 @@ Library ------- +- Issue #16248: Disable code execution from the user's home directory by + tkinter when the -E flag is passed to Python. Patch by Zachary Ware. + - Issue #13390: New function :func:`sys.getallocatedblocks()` returns the number of memory blocks currently allocated. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 14:51:26 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 9 Dec 2012 14:51:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2MjQ4?= =?utf-8?q?=3A_Disable_code_execution_from_the_user=27s_home_directory_by_?= =?utf-8?q?tkinter?= Message-ID: <3YK8324p82zRSr@mail.python.org> http://hg.python.org/cpython/rev/822b472eff13 changeset: 80781:822b472eff13 branch: 2.7 parent: 80767:80f0c7d5deda user: Antoine Pitrou date: Sun Dec 09 14:46:18 2012 +0100 summary: Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. files: Lib/lib-tk/Tkinter.py | 4 +++- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -1709,7 +1709,9 @@ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) if useTk: self._loadtk() - self.readprofile(baseName, className) + if not sys.flags.ignore_environment: + # Issue #16248: Honor the -E flag to avoid code injection. + self.readprofile(baseName, className) def loadtk(self): if not self._tkloaded: self.tk.loadtk() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -160,6 +160,9 @@ Library ------- +- Issue #16248: Disable code execution from the user's home directory by + tkinter when the -E flag is passed to Python. Patch by Zachary Ware. + - Issue #16628: Fix a memory leak in ctypes.resize(). - Issue #13614: Fix setup.py register failure with invalid rst in description. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 16:17:51 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 9 Dec 2012 16:17:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4xKTogSXNzdWUgIzE2MjQ4?= =?utf-8?q?=3A_Disable_code_execution_from_the_user=27s_home_directory_by_?= =?utf-8?q?tkinter?= Message-ID: <3YK9yl0KmWzRTP@mail.python.org> http://hg.python.org/cpython/rev/03b3124e9ea3 changeset: 80782:03b3124e9ea3 branch: 3.1 parent: 76255:5a6fa1b8767f user: Antoine Pitrou date: Sun Dec 09 14:46:18 2012 +0100 summary: Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. files: Lib/tkinter/__init__.py | 4 +++- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1632,7 +1632,9 @@ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) if useTk: self._loadtk() - self.readprofile(baseName, className) + if not sys.flags.ignore_environment: + # Issue #16248: Honor the -E flag to avoid code injection. + self.readprofile(baseName, className) def loadtk(self): if not self._tkloaded: self.tk.loadtk() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,9 @@ Library ------- +- Issue #16248: Disable code execution from the user's home directory by tkinter + when the -E flag is passed to Python. + What's New in Python 3.1.5? =========================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 16:17:52 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 9 Dec 2012 16:17:52 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4xIC0+IDMuMik6?= =?utf-8?q?_merge_3=2E1?= Message-ID: <3YK9ym2sc8zRVh@mail.python.org> http://hg.python.org/cpython/rev/1ff72360ceb6 changeset: 80783:1ff72360ceb6 branch: 3.2 parent: 80778:d8300842a0e9 parent: 80782:03b3124e9ea3 user: Benjamin Peterson date: Sun Dec 09 10:14:42 2012 -0500 summary: merge 3.1 files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 16:17:53 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 9 Dec 2012 16:17:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_merge_3=2E2?= Message-ID: <3YK9yn5LQyzRVp@mail.python.org> http://hg.python.org/cpython/rev/3571a2808445 changeset: 80784:3571a2808445 branch: 3.3 parent: 80779:10d04bdb05ab parent: 80783:1ff72360ceb6 user: Benjamin Peterson date: Sun Dec 09 10:16:46 2012 -0500 summary: merge 3.2 files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 16:17:55 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sun, 9 Dec 2012 16:17:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4z?= Message-ID: <3YK9yq0g3kzRVP@mail.python.org> http://hg.python.org/cpython/rev/70ee0b76239d changeset: 80785:70ee0b76239d parent: 80780:a4fc52da295b parent: 80784:3571a2808445 user: Benjamin Peterson date: Sun Dec 09 10:17:39 2012 -0500 summary: merge 3.3 files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 17:10:20 2012 From: python-checkins at python.org (richard.oudkerk) Date: Sun, 9 Dec 2012 17:10:20 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316616=3A_Enable_t?= =?utf-8?q?est_in_test=5Fpoll_which_was_=28accidentally=3F=29_disabled?= Message-ID: <3YKC7J4bj4zRSB@mail.python.org> http://hg.python.org/cpython/rev/5a022c21ad84 changeset: 80786:5a022c21ad84 user: Richard Oudkerk date: Sun Dec 09 16:05:20 2012 +0000 summary: Issue #16616: Enable test in test_poll which was (accidentally?) disabled files: Lib/test/test_poll.py | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py --- a/Lib/test/test_poll.py +++ b/Lib/test/test_poll.py @@ -67,13 +67,11 @@ self.assertEqual(bufs, [MSG] * NUM_PIPES) - def poll_unit_tests(self): + def test_poll_unit_tests(self): # returns NVAL for invalid file descriptor - FD = 42 - try: - os.close(FD) - except OSError: - pass + FD, w = os.pipe() + os.close(FD) + os.close(w) p = select.poll() p.register(FD) r = p.poll() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 17:10:21 2012 From: python-checkins at python.org (richard.oudkerk) Date: Sun, 9 Dec 2012 17:10:21 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Make_test_of_poll=28=29_us?= =?utf-8?q?e_unbuffered_IO?= Message-ID: <3YKC7K6sP4zRSX@mail.python.org> http://hg.python.org/cpython/rev/fae25c3cff28 changeset: 80787:fae25c3cff28 user: Richard Oudkerk date: Sun Dec 09 16:05:22 2012 +0000 summary: Make test of poll() use unbuffered IO files: Lib/test/test_poll.py | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py --- a/Lib/test/test_poll.py +++ b/Lib/test/test_poll.py @@ -1,6 +1,6 @@ # Test case for the os.poll() function -import os, select, random, unittest +import os, select, random, unittest, subprocess from test.support import TESTFN, run_unittest try: @@ -114,7 +114,9 @@ def test_poll2(self): cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' - p = os.popen(cmd, 'r') + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, + bufsize=0) + p = proc.stdout pollster = select.poll() pollster.register( p, select.POLLIN ) for tout in (0, 1000, 2000, 4000, 8000, 16000) + (-1,)*10: @@ -124,7 +126,7 @@ fd, flags = fdlist[0] if flags & select.POLLHUP: line = p.readline() - if line != "": + if line != b"": self.fail('error: pipe seems to be closed, but still returns data') continue @@ -132,6 +134,7 @@ line = p.readline() if not line: break + self.assertEqual(line, b'testing...\n') continue else: self.fail('Unexpected return value from select.poll: %s' % fdlist) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 19:31:31 2012 From: python-checkins at python.org (brett.cannon) Date: Sun, 9 Dec 2012 19:31:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Fix_some_markup_where_the_wro?= =?utf-8?q?ng_text_markup_style_was_used_for_bold_and_italic=2E?= Message-ID: <3YKGGC032gzRTm@mail.python.org> http://hg.python.org/peps/rev/4cc6738cfe3f changeset: 4596:4cc6738cfe3f user: Brett Cannon date: Sun Dec 09 13:31:24 2012 -0500 summary: Fix some markup where the wrong text markup style was used for bold and italic. files: pep-0399.txt | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pep-0399.txt b/pep-0399.txt --- a/pep-0399.txt +++ b/pep-0399.txt @@ -16,7 +16,7 @@ The Python standard library under CPython contains various instances of modules implemented in both pure Python and C (either entirely or partially). This PEP requires that in these instances that the -C code *must* pass the test suite used for the pure Python code +C code **must** pass the test suite used for the pure Python code so as to act as much as a drop-in replacement as reasonably possible (C- and VM-specific tests are exempt). It is also required that new C-based modules lacking a pure Python equivalent implementation get @@ -41,12 +41,12 @@ Python or in the programming language used to implement the VM itself (e.g., in C# for IronPython). This duplication of effort between CPython, PyPy, Jython, and IronPython is extremely unfortunate as -implementing a module *at least* in pure Python would help mitigate +implementing a module **at least** in pure Python would help mitigate this duplicate effort. The purpose of this PEP is to minimize this duplicate effort by mandating that all new modules added to Python's standard library -*must* have a pure Python implementation _unless_ special dispensation +**must** have a pure Python implementation *unless* special dispensation is given. This makes sure that a module in the stdlib is available to all VMs and not just to CPython (pre-existing modules that do not meet this requirement are exempt, although there is nothing preventing -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sun Dec 9 22:53:24 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 9 Dec 2012 22:53:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Document_the_r?= =?utf-8?q?eason_attribute_of_urllib=2EHTTPError__Patch_by_Berker_Peksag?= Message-ID: <3YKLl862cPzRVw@mail.python.org> http://hg.python.org/cpython/rev/856a1d79ad81 changeset: 80788:856a1d79ad81 branch: 2.7 parent: 80781:822b472eff13 user: Senthil Kumaran date: Sun Dec 09 13:36:40 2012 -0800 summary: Document the reason attribute of urllib.HTTPError Patch by Berker Peksag files: Doc/library/urllib2.rst | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Doc/library/urllib2.rst b/Doc/library/urllib2.rst --- a/Doc/library/urllib2.rst +++ b/Doc/library/urllib2.rst @@ -121,7 +121,10 @@ This numeric value corresponds to a value found in the dictionary of codes as found in :attr:`BaseHTTPServer.BaseHTTPRequestHandler.responses`. + .. attribute:: reason + The reason for this error. It can be a message string or another exception + instance. The following classes are provided: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 22:53:26 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 9 Dec 2012 22:53:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_issue13211?= =?utf-8?q?_-_Document_the_reason_attribute_for_urllib=2Eerror=2EHTTPError?= Message-ID: <3YKLlB1Rl3zRVw@mail.python.org> http://hg.python.org/cpython/rev/e1ba514ddcd2 changeset: 80789:e1ba514ddcd2 branch: 3.2 parent: 80783:1ff72360ceb6 user: Senthil Kumaran date: Sun Dec 09 13:51:05 2012 -0800 summary: Fix issue13211 - Document the reason attribute for urllib.error.HTTPError files: Doc/library/urllib.error.rst | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Doc/library/urllib.error.rst b/Doc/library/urllib.error.rst --- a/Doc/library/urllib.error.rst +++ b/Doc/library/urllib.error.rst @@ -39,6 +39,10 @@ to a value found in the dictionary of codes as found in :attr:`http.server.BaseHTTPRequestHandler.responses`. + .. attribute:: reason + + This is usually a string explaining the reason for this error. + .. exception:: ContentTooShortError(msg, content) This exception is raised when the :func:`urlretrieve` function detects that -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 22:53:27 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 9 Dec 2012 22:53:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_merge_from_3=2E2_-_reason_attribute_for_urllib=2Eerror=2EHTTPE?= =?utf-8?q?rror?= Message-ID: <3YKLlC3mKbzRXS@mail.python.org> http://hg.python.org/cpython/rev/10ad43456c29 changeset: 80790:10ad43456c29 branch: 3.3 parent: 80784:3571a2808445 parent: 80789:e1ba514ddcd2 user: Senthil Kumaran date: Sun Dec 09 13:52:31 2012 -0800 summary: merge from 3.2 - reason attribute for urllib.error.HTTPError files: Doc/library/urllib.error.rst | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Doc/library/urllib.error.rst b/Doc/library/urllib.error.rst --- a/Doc/library/urllib.error.rst +++ b/Doc/library/urllib.error.rst @@ -41,6 +41,10 @@ to a value found in the dictionary of codes as found in :attr:`http.server.BaseHTTPRequestHandler.responses`. + .. attribute:: reason + + This is usually a string explaining the reason for this error. + .. exception:: ContentTooShortError(msg, content) This exception is raised when the :func:`urlretrieve` function detects that -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 22:53:28 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 9 Dec 2012 22:53:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_merge_from_3=2E3_-_Document_reason_attribute_for_urllib?= =?utf-8?q?=2Eerror=2EHTTPError?= Message-ID: <3YKLlD684WzRXX@mail.python.org> http://hg.python.org/cpython/rev/dc8c54069a84 changeset: 80791:dc8c54069a84 parent: 80787:fae25c3cff28 parent: 80790:10ad43456c29 user: Senthil Kumaran date: Sun Dec 09 13:53:15 2012 -0800 summary: merge from 3.3 - Document reason attribute for urllib.error.HTTPError files: Doc/library/urllib.error.rst | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Doc/library/urllib.error.rst b/Doc/library/urllib.error.rst --- a/Doc/library/urllib.error.rst +++ b/Doc/library/urllib.error.rst @@ -41,6 +41,10 @@ to a value found in the dictionary of codes as found in :attr:`http.server.BaseHTTPRequestHandler.responses`. + .. attribute:: reason + + This is usually a string explaining the reason for this error. + .. exception:: ContentTooShortError(msg, content) This exception is raised when the :func:`urlretrieve` function detects that -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 23:05:22 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 9 Dec 2012 23:05:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NTgy?= =?utf-8?q?=3A_use_int_exit_code_in_tkinter=2E=5Fexit?= Message-ID: <3YKM0y6NYkzRTP@mail.python.org> http://hg.python.org/cpython/rev/fed68e0bce53 changeset: 80792:fed68e0bce53 branch: 3.2 parent: 80789:e1ba514ddcd2 user: Andrew Svetlov date: Mon Dec 10 00:02:31 2012 +0200 summary: Issue #16582: use int exit code in tkinter._exit files: Lib/tkinter/__init__.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -146,8 +146,12 @@ """Internal function.""" pass -def _exit(code='0'): +def _exit(code=0): """Internal function. Calling it will throw the exception SystemExit.""" + try: + code = int(code) + except ValueError: + pass raise SystemExit(code) _varnum = 0 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 23:05:24 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 9 Dec 2012 23:05:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316582=3A_use_int_exit_code_in_tkinter=2E=5Fexit?= Message-ID: <3YKM101zgFzRX1@mail.python.org> http://hg.python.org/cpython/rev/e39677feabe0 changeset: 80793:e39677feabe0 branch: 3.3 parent: 80790:10ad43456c29 parent: 80792:fed68e0bce53 user: Andrew Svetlov date: Mon Dec 10 00:03:39 2012 +0200 summary: Issue #16582: use int exit code in tkinter._exit files: Lib/tkinter/__init__.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -148,8 +148,12 @@ """Internal function.""" pass -def _exit(code='0'): +def _exit(code=0): """Internal function. Calling it will throw the exception SystemExit.""" + try: + code = int(code) + except ValueError: + pass raise SystemExit(code) _varnum = 0 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 23:05:25 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 9 Dec 2012 23:05:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316582=3A_use_int_exit_code_in_tkinter=2E=5Fexit?= Message-ID: <3YKM114QbczRXS@mail.python.org> http://hg.python.org/cpython/rev/5ad5efc847c7 changeset: 80794:5ad5efc847c7 parent: 80791:dc8c54069a84 parent: 80793:e39677feabe0 user: Andrew Svetlov date: Mon Dec 10 00:03:55 2012 +0200 summary: Issue #16582: use int exit code in tkinter._exit files: Lib/tkinter/__init__.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -148,8 +148,12 @@ """Internal function.""" pass -def _exit(code='0'): +def _exit(code=0): """Internal function. Calling it will throw the exception SystemExit.""" + try: + code = int(code) + except ValueError: + pass raise SystemExit(code) _varnum = 0 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 9 23:05:26 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 9 Dec 2012 23:05:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NTgy?= =?utf-8?q?=3A_use_int_exit_code_in_tkinter=2E=5Fexit?= Message-ID: <3YKM126pLNzRXc@mail.python.org> http://hg.python.org/cpython/rev/37c1d20facd7 changeset: 80795:37c1d20facd7 branch: 2.7 parent: 80788:856a1d79ad81 user: Andrew Svetlov date: Mon Dec 10 00:05:08 2012 +0200 summary: Issue #16582: use int exit code in tkinter._exit files: Lib/lib-tk/Tkinter.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -154,8 +154,12 @@ """Internal function.""" pass -def _exit(code='0'): +def _exit(code=0): """Internal function. Calling it will throw the exception SystemExit.""" + try: + code = int(code) + except ValueError: + pass raise SystemExit, code _varnum = 0 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 03:25:06 2012 From: python-checkins at python.org (chris.jerdonek) Date: Mon, 10 Dec 2012 03:25:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NjI5?= =?utf-8?q?=3A_Fix_IDLE_idlelib=2ECallTips_test=2E__Patch_by_Roger_Serwy?= =?utf-8?q?=2E?= Message-ID: <3YKSmf6TwNzRXk@mail.python.org> http://hg.python.org/cpython/rev/181c170c6270 changeset: 80796:181c170c6270 branch: 3.2 parent: 80792:fed68e0bce53 user: Chris Jerdonek date: Sun Dec 09 18:17:27 2012 -0800 summary: Issue #16629: Fix IDLE idlelib.CallTips test. Patch by Roger Serwy. This commit updates a test broken by the change made for issue #14783. files: Lib/idlelib/CallTips.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -211,7 +211,7 @@ def test_builtins(): # if first line of a possibly multiline compiled docstring changes, # must change corresponding test string - test('int', "int(x[, base]) -> integer") + test('int', "int(x=0) -> integer") test('Int', Int.__doc__) test('types.MethodType', "method(function, instance)") test('list', "list() -> new empty list") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 03:25:08 2012 From: python-checkins at python.org (chris.jerdonek) Date: Mon, 10 Dec 2012 03:25:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316629=3A_Merge_IDLE_test_fix_from_3=2E2=2E?= Message-ID: <3YKSmh1mnGzRZW@mail.python.org> http://hg.python.org/cpython/rev/5182cc18b7b4 changeset: 80797:5182cc18b7b4 branch: 3.3 parent: 80793:e39677feabe0 parent: 80796:181c170c6270 user: Chris Jerdonek date: Sun Dec 09 18:19:54 2012 -0800 summary: Issue #16629: Merge IDLE test fix from 3.2. files: Lib/idlelib/CallTips.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -211,7 +211,7 @@ def test_builtins(): # if first line of a possibly multiline compiled docstring changes, # must change corresponding test string - test('int', "int(x[, base]) -> integer") + test('int', "int(x=0) -> integer") test('Int', Int.__doc__) test('types.MethodType', "method(function, instance)") test('list', "list() -> new empty list") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 03:25:09 2012 From: python-checkins at python.org (chris.jerdonek) Date: Mon, 10 Dec 2012 03:25:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316629=3A_Merge_IDLE_test_fix_from_3=2E3=2E?= Message-ID: <3YKSmj47WMzRYl@mail.python.org> http://hg.python.org/cpython/rev/db17a49395c2 changeset: 80798:db17a49395c2 parent: 80794:5ad5efc847c7 parent: 80797:5182cc18b7b4 user: Chris Jerdonek date: Sun Dec 09 18:22:21 2012 -0800 summary: Issue #16629: Merge IDLE test fix from 3.3. files: Lib/idlelib/CallTips.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -211,7 +211,7 @@ def test_builtins(): # if first line of a possibly multiline compiled docstring changes, # must change corresponding test string - test('int', "int(x[, base]) -> integer") + test('int', "int(x=0) -> integer") test('Int', Int.__doc__) test('types.MethodType', "method(function, instance)") test('list', "list() -> new empty list") -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Dec 10 05:58:44 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 10 Dec 2012 05:58:44 +0100 Subject: [Python-checkins] Daily reference leaks (db17a49395c2): sum=4 Message-ID: results for db17a49395c2 on branch "default" -------------------------------------------- test_dbm leaked [0, 0, 2] references, sum=2 test_dbm leaked [0, 0, 2] memory blocks, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogo6Qn91', '-x'] From python-checkins at python.org Mon Dec 10 09:18:33 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 09:18:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1ODcyOiBBZGQg?= =?utf-8?q?tests_for_a_3=2E3_regression_in_the_new_fd-based_shutil=2Ermtre?= =?utf-8?q?e?= Message-ID: <3YKccT45nwzRYd@mail.python.org> http://hg.python.org/cpython/rev/c9b9f786ec25 changeset: 80799:c9b9f786ec25 branch: 3.2 parent: 80796:181c170c6270 user: Hynek Schlawack date: Mon Dec 10 09:00:09 2012 +0100 summary: #15872: Add tests for a 3.3 regression in the new fd-based shutil.rmtree It cause shutil.rmtree not ignore all errors. Also add a test ensuring that rmtree fails when being called on a symlink. Patch by Serhiy Storchaka. files: Lib/test/test_shutil.py | 46 +++++++++++++++++++++++++++++ Misc/NEWS | 4 ++ 2 files changed, 50 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -100,10 +100,56 @@ self.tempdirs.append(d) return d + @support.skip_unless_symlink + def test_rmtree_fails_on_symlink(self): + tmp = self.mkdtemp() + dir_ = os.path.join(tmp, 'dir') + os.mkdir(dir_) + link = os.path.join(tmp, 'link') + os.symlink(dir_, link) + self.assertRaises(OSError, shutil.rmtree, link) + self.assertTrue(os.path.exists(dir_)) + self.assertTrue(os.path.lexists(link)) + errors = [] + def onerror(*args): + errors.append(args) + shutil.rmtree(link, onerror=onerror) + self.assertEqual(len(errors), 1) + self.assertIs(errors[0][0], os.path.islink) + self.assertEqual(errors[0][1], link) + self.assertIsInstance(errors[0][2][1], OSError) + def test_rmtree_errors(self): # filename is guaranteed not to exist filename = tempfile.mktemp() self.assertRaises(OSError, shutil.rmtree, filename) + # test that ignore_errors option is honoured + shutil.rmtree(filename, ignore_errors=True) + + # existing file + tmpdir = self.mkdtemp() + self.write_file((tmpdir, "tstfile"), "") + filename = os.path.join(tmpdir, "tstfile") + with self.assertRaises(OSError) as cm: + shutil.rmtree(filename) + self.assertEqual(cm.exception.filename, filename) + self.assertTrue(os.path.exists(filename)) + # test that ignore_errors option is honoured + shutil.rmtree(filename, ignore_errors=True) + self.assertTrue(os.path.exists(filename)) + errors = [] + def onerror(*args): + errors.append(args) + shutil.rmtree(filename, onerror=onerror) + self.assertEqual(len(errors), 2) + self.assertIs(errors[0][0], os.listdir) + self.assertEqual(errors[0][1], filename) + self.assertIsInstance(errors[0][2][1], OSError) + self.assertEqual(errors[0][2][1].filename, filename) + self.assertIs(errors[1][0], os.rmdir) + self.assertEqual(errors[1][1], filename) + self.assertIsInstance(errors[1][2][1], OSError) + self.assertEqual(errors[1][2][1].filename, filename) # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -685,6 +685,10 @@ Tests ----- +- Issue #15872: Add tests for a 3.3 regression which caused the new fd-based + shutil.rmtree not ignore all errors. Also add a test ensuring that rmtree + fails when being called on a symlink. Patch by Serhiy Storchaka. + - Issue #16559: Add more tests for the json module, including some from the official test suite at json.org. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 09:18:35 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 09:18:35 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2315872=3A_Fix_3=2E3_regression_introduced_by_the_new_fd-base?= =?utf-8?q?d_shutil=2Ermtree?= Message-ID: <3YKccW0qbZzRYq@mail.python.org> http://hg.python.org/cpython/rev/fc394216c724 changeset: 80800:fc394216c724 branch: 3.3 parent: 80797:5182cc18b7b4 parent: 80799:c9b9f786ec25 user: Hynek Schlawack date: Mon Dec 10 09:11:25 2012 +0100 summary: #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree It caused rmtree to not ignore certain errors when ignore_errors was set. Patch by Alessandro Moura and Serhiy Storchaka. files: Lib/shutil.py | 30 ++++++++++++++++------ Lib/test/test_shutil.py | 38 ++++++++++++++++++++++++++++- Misc/NEWS | 4 +++ 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -375,19 +375,20 @@ names = [] try: names = os.listdir(topfd) - except os.error: + except OSError as err: + err.filename = path onerror(os.listdir, path, sys.exc_info()) for name in names: fullname = os.path.join(path, name) try: orig_st = os.stat(name, dir_fd=topfd, follow_symlinks=False) mode = orig_st.st_mode - except os.error: + except OSError: mode = 0 if stat.S_ISDIR(mode): try: dirfd = os.open(name, os.O_RDONLY, dir_fd=topfd) - except os.error: + except OSError: onerror(os.open, fullname, sys.exc_info()) else: try: @@ -395,14 +396,23 @@ _rmtree_safe_fd(dirfd, fullname, onerror) try: os.rmdir(name, dir_fd=topfd) - except os.error: + except OSError: onerror(os.rmdir, fullname, sys.exc_info()) + else: + try: + # This can only happen if someone replaces + # a directory with a symlink after the call to + # stat.S_ISDIR above. + raise OSError("Cannot call rmtree on a symbolic " + "link") + except OSError: + onerror(os.path.islink, fullname, sys.exc_info()) finally: os.close(dirfd) else: try: os.unlink(name, dir_fd=topfd) - except os.error: + except OSError: onerror(os.unlink, fullname, sys.exc_info()) _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <= @@ -444,16 +454,18 @@ onerror(os.lstat, path, sys.exc_info()) return try: - if (stat.S_ISDIR(orig_st.st_mode) and - os.path.samestat(orig_st, os.fstat(fd))): + if os.path.samestat(orig_st, os.fstat(fd)): _rmtree_safe_fd(fd, path, onerror) try: os.rmdir(path) except os.error: onerror(os.rmdir, path, sys.exc_info()) else: - raise NotADirectoryError(20, - "Not a directory: '{}'".format(path)) + try: + # symlinks to directories are forbidden, see bug #1669 + raise OSError("Cannot call rmtree on a symbolic link") + except OSError: + onerror(os.path.islink, path, sys.exc_info()) finally: os.close(fd) else: diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -126,6 +126,15 @@ os.symlink(dir_, link) self.assertRaises(OSError, shutil.rmtree, link) self.assertTrue(os.path.exists(dir_)) + self.assertTrue(os.path.lexists(link)) + errors = [] + def onerror(*args): + errors.append(args) + shutil.rmtree(link, onerror=onerror) + self.assertEqual(len(errors), 1) + self.assertIs(errors[0][0], os.path.islink) + self.assertEqual(errors[0][1], link) + self.assertIsInstance(errors[0][2][1], OSError) @support.skip_unless_symlink def test_rmtree_works_on_symlinks(self): @@ -152,7 +161,34 @@ def test_rmtree_errors(self): # filename is guaranteed not to exist filename = tempfile.mktemp() - self.assertRaises(OSError, shutil.rmtree, filename) + self.assertRaises(FileNotFoundError, shutil.rmtree, filename) + # test that ignore_errors option is honored + shutil.rmtree(filename, ignore_errors=True) + + # existing file + tmpdir = self.mkdtemp() + write_file((tmpdir, "tstfile"), "") + filename = os.path.join(tmpdir, "tstfile") + with self.assertRaises(NotADirectoryError) as cm: + shutil.rmtree(filename) + self.assertEqual(cm.exception.filename, filename) + self.assertTrue(os.path.exists(filename)) + # test that ignore_errors option is honored + shutil.rmtree(filename, ignore_errors=True) + self.assertTrue(os.path.exists(filename)) + errors = [] + def onerror(*args): + errors.append(args) + shutil.rmtree(filename, onerror=onerror) + self.assertEqual(len(errors), 2) + self.assertIs(errors[0][0], os.listdir) + self.assertEqual(errors[0][1], filename) + self.assertIsInstance(errors[0][2][1], NotADirectoryError) + self.assertEqual(errors[0][2][1].filename, filename) + self.assertIs(errors[1][0], os.rmdir) + self.assertEqual(errors[1][1], filename) + self.assertIsInstance(errors[1][2][1], NotADirectoryError) + self.assertEqual(errors[1][2][1].filename, filename) # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,10 @@ Library ------- +- Issue #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree + that caused it to not ignore certain errors when ignore_errors was set. + Patch by Alessandro Moura and Serhiy Storchaka. + - Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 09:18:36 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 09:18:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=2315872=3A_Fix_3=2E3_regression_introduced_by_the_new_f?= =?utf-8?q?d-based_shutil=2Ermtree?= Message-ID: <3YKccX4QCVzRZS@mail.python.org> http://hg.python.org/cpython/rev/c70d964b26fe changeset: 80801:c70d964b26fe parent: 80798:db17a49395c2 parent: 80800:fc394216c724 user: Hynek Schlawack date: Mon Dec 10 09:15:23 2012 +0100 summary: #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree It caused rmtree to not ignore certain errors when ignore_errors was set. Patch by Alessandro Moura and Serhiy Storchaka. files: Lib/shutil.py | 30 ++++++++++++++++------ Lib/test/test_shutil.py | 38 ++++++++++++++++++++++++++++- Misc/NEWS | 4 +++ 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -381,19 +381,20 @@ names = [] try: names = os.listdir(topfd) - except os.error: + except OSError as err: + err.filename = path onerror(os.listdir, path, sys.exc_info()) for name in names: fullname = os.path.join(path, name) try: orig_st = os.stat(name, dir_fd=topfd, follow_symlinks=False) mode = orig_st.st_mode - except os.error: + except OSError: mode = 0 if stat.S_ISDIR(mode): try: dirfd = os.open(name, os.O_RDONLY, dir_fd=topfd) - except os.error: + except OSError: onerror(os.open, fullname, sys.exc_info()) else: try: @@ -401,14 +402,23 @@ _rmtree_safe_fd(dirfd, fullname, onerror) try: os.rmdir(name, dir_fd=topfd) - except os.error: + except OSError: onerror(os.rmdir, fullname, sys.exc_info()) + else: + try: + # This can only happen if someone replaces + # a directory with a symlink after the call to + # stat.S_ISDIR above. + raise OSError("Cannot call rmtree on a symbolic " + "link") + except OSError: + onerror(os.path.islink, fullname, sys.exc_info()) finally: os.close(dirfd) else: try: os.unlink(name, dir_fd=topfd) - except os.error: + except OSError: onerror(os.unlink, fullname, sys.exc_info()) _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <= @@ -450,16 +460,18 @@ onerror(os.lstat, path, sys.exc_info()) return try: - if (stat.S_ISDIR(orig_st.st_mode) and - os.path.samestat(orig_st, os.fstat(fd))): + if os.path.samestat(orig_st, os.fstat(fd)): _rmtree_safe_fd(fd, path, onerror) try: os.rmdir(path) except os.error: onerror(os.rmdir, path, sys.exc_info()) else: - raise NotADirectoryError(20, - "Not a directory: '{}'".format(path)) + try: + # symlinks to directories are forbidden, see bug #1669 + raise OSError("Cannot call rmtree on a symbolic link") + except OSError: + onerror(os.path.islink, path, sys.exc_info()) finally: os.close(fd) else: diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -127,6 +127,15 @@ os.symlink(dir_, link) self.assertRaises(OSError, shutil.rmtree, link) self.assertTrue(os.path.exists(dir_)) + self.assertTrue(os.path.lexists(link)) + errors = [] + def onerror(*args): + errors.append(args) + shutil.rmtree(link, onerror=onerror) + self.assertEqual(len(errors), 1) + self.assertIs(errors[0][0], os.path.islink) + self.assertEqual(errors[0][1], link) + self.assertIsInstance(errors[0][2][1], OSError) @support.skip_unless_symlink def test_rmtree_works_on_symlinks(self): @@ -153,7 +162,34 @@ def test_rmtree_errors(self): # filename is guaranteed not to exist filename = tempfile.mktemp() - self.assertRaises(OSError, shutil.rmtree, filename) + self.assertRaises(FileNotFoundError, shutil.rmtree, filename) + # test that ignore_errors option is honored + shutil.rmtree(filename, ignore_errors=True) + + # existing file + tmpdir = self.mkdtemp() + write_file((tmpdir, "tstfile"), "") + filename = os.path.join(tmpdir, "tstfile") + with self.assertRaises(NotADirectoryError) as cm: + shutil.rmtree(filename) + self.assertEqual(cm.exception.filename, filename) + self.assertTrue(os.path.exists(filename)) + # test that ignore_errors option is honored + shutil.rmtree(filename, ignore_errors=True) + self.assertTrue(os.path.exists(filename)) + errors = [] + def onerror(*args): + errors.append(args) + shutil.rmtree(filename, onerror=onerror) + self.assertEqual(len(errors), 2) + self.assertIs(errors[0][0], os.listdir) + self.assertEqual(errors[0][1], filename) + self.assertIsInstance(errors[0][2][1], NotADirectoryError) + self.assertEqual(errors[0][2][1].filename, filename) + self.assertIs(errors[1][0], os.rmdir) + self.assertEqual(errors[1][1], filename) + self.assertIsInstance(errors[1][2][1], NotADirectoryError) + self.assertEqual(errors[1][2][1].filename, filename) # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -163,6 +163,10 @@ Library ------- +- Issue #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree + that caused it to not ignore certain errors when ignore_errors was set. + Patch by Alessandro Moura and Serhiy Storchaka. + - Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 10:11:30 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 10:11:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1ODcyOiBGaXgg?= =?utf-8?q?shutil=2Ermtree_error_tests_for_Windows?= Message-ID: <3YKdnZ4crxzMHR@mail.python.org> http://hg.python.org/cpython/rev/5211391928bc changeset: 80802:5211391928bc branch: 3.2 parent: 80799:c9b9f786ec25 user: Hynek Schlawack date: Mon Dec 10 10:07:11 2012 +0100 summary: #15872: Fix shutil.rmtree error tests for Windows files: Lib/test/test_shutil.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -132,7 +132,11 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(OSError) as cm: shutil.rmtree(filename) - self.assertEqual(cm.exception.filename, filename) + if os.name == 'nt': + rm_name = os.path.join(filename, '*.*') + else: + rm_name = filename + self.assertEqual(cm.exception.filename, rm_name) self.assertTrue(os.path.exists(filename)) # test that ignore_errors option is honoured shutil.rmtree(filename, ignore_errors=True) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 10:11:31 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 10:11:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2315872=3A_Fix_shutil=2Ermtree_error_tests_for_Windows?= Message-ID: <3YKdnb6tYKzRTv@mail.python.org> http://hg.python.org/cpython/rev/4b2fca8ad07b changeset: 80803:4b2fca8ad07b branch: 3.3 parent: 80800:fc394216c724 parent: 80802:5211391928bc user: Hynek Schlawack date: Mon Dec 10 10:08:41 2012 +0100 summary: #15872: Fix shutil.rmtree error tests for Windows files: Lib/test/test_shutil.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -171,7 +171,11 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(NotADirectoryError) as cm: shutil.rmtree(filename) - self.assertEqual(cm.exception.filename, filename) + if os.name == 'nt': + rm_name = os.path.join(filename, '*.*') + else: + rm_name = filename + self.assertEqual(cm.exception.filename, rm_name) self.assertTrue(os.path.exists(filename)) # test that ignore_errors option is honored shutil.rmtree(filename, ignore_errors=True) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 10:11:33 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 10:11:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=2315872=3A_Fix_shutil=2Ermtree_error_tests_for_Windows?= Message-ID: <3YKdnd249JzQTW@mail.python.org> http://hg.python.org/cpython/rev/ae1ef62954f7 changeset: 80804:ae1ef62954f7 parent: 80801:c70d964b26fe parent: 80803:4b2fca8ad07b user: Hynek Schlawack date: Mon Dec 10 10:10:40 2012 +0100 summary: #15872: Fix shutil.rmtree error tests for Windows files: Lib/test/test_shutil.py | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -172,7 +172,11 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(NotADirectoryError) as cm: shutil.rmtree(filename) - self.assertEqual(cm.exception.filename, filename) + if os.name == 'nt': + rm_name = os.path.join(filename, '*.*') + else: + rm_name = filename + self.assertEqual(cm.exception.filename, rm_name) self.assertTrue(os.path.exists(filename)) # test that ignore_errors option is honored shutil.rmtree(filename, ignore_errors=True) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 11:09:48 2012 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 10 Dec 2012 11:09:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_Issue15701_=3A_add_=2E?= =?utf-8?q?headers_attribute_to_urllib=2Eerror=2EHTTPError?= Message-ID: <3YKg4r0LDrzRNx@mail.python.org> http://hg.python.org/cpython/rev/ad1c1164f68b changeset: 80805:ad1c1164f68b user: Senthil Kumaran date: Mon Dec 10 02:09:35 2012 -0800 summary: Fix Issue15701 : add .headers attribute to urllib.error.HTTPError files: Doc/library/urllib.error.rst | 7 +++++++ Lib/test/test_urllib2.py | 6 +++++- Lib/urllib/error.py | 8 ++++++++ Misc/NEWS | 3 +++ 4 files changed, 23 insertions(+), 1 deletions(-) diff --git a/Doc/library/urllib.error.rst b/Doc/library/urllib.error.rst --- a/Doc/library/urllib.error.rst +++ b/Doc/library/urllib.error.rst @@ -45,6 +45,13 @@ This is usually a string explaining the reason for this error. + .. attribute:: headers + + The HTTP response headers for the HTTP request that cause the + :exc:`HTTPError`. + + .. versionadded:: 3.4 + .. exception:: ContentTooShortError(msg, content) This exception is raised when the :func:`urlretrieve` function detects that diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1539,11 +1539,15 @@ interface even though HTTPError is a subclass of URLError. >>> msg = 'something bad happened' - >>> url = code = hdrs = fp = None + >>> url = code = fp = None + >>> hdrs = 'Content-Length: 42' >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) >>> assert hasattr(err, 'reason') >>> err.reason 'something bad happened' + >>> assert hasattr(err, 'headers') + >>> err.headers + 'Content-Length: 42' """ def test_main(verbose=None): diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -61,6 +61,14 @@ def reason(self): return self.msg + @property + def headers(self): + return self.hdrs + + @headers.setter + def headers(self, headers): + self.hdrs = headers + # exception raised when downloaded size does not match content-length class ContentTooShortError(URLError): def __init__(self, message, content): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -163,6 +163,9 @@ Library ------- +- Issue #15701: Add a .headers attribute to urllib.error.HTTPError. Patch + contributed by Berker Peksag. + - Issue #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree that caused it to not ignore certain errors when ignore_errors was set. Patch by Alessandro Moura and Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 11:27:16 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 11:27:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1ODcyOiBNb3Jl?= =?utf-8?q?_shutil_test_fixes_for_Windows?= Message-ID: <3YKgT00GM0zRT5@mail.python.org> http://hg.python.org/cpython/rev/7ce8f4a70ccd changeset: 80806:7ce8f4a70ccd branch: 3.2 parent: 80802:5211391928bc user: Hynek Schlawack date: Mon Dec 10 11:08:09 2012 +0100 summary: #15872: More shutil test fixes for Windows files: Lib/test/test_shutil.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -149,11 +149,11 @@ self.assertIs(errors[0][0], os.listdir) self.assertEqual(errors[0][1], filename) self.assertIsInstance(errors[0][2][1], OSError) - self.assertEqual(errors[0][2][1].filename, filename) + self.assertEqual(errors[0][2][1].filename, rm_name) self.assertIs(errors[1][0], os.rmdir) self.assertEqual(errors[1][1], filename) self.assertIsInstance(errors[1][2][1], OSError) - self.assertEqual(errors[1][2][1].filename, filename) + self.assertEqual(errors[1][2][1].filename, rm_name) # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 11:27:17 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 11:27:17 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2315872=3A_More_shutil_test_fixes_for_Windows?= Message-ID: <3YKgT12SPJzRW7@mail.python.org> http://hg.python.org/cpython/rev/a05e2d4094ea changeset: 80807:a05e2d4094ea branch: 3.3 parent: 80803:4b2fca8ad07b parent: 80806:7ce8f4a70ccd user: Hynek Schlawack date: Mon Dec 10 11:08:59 2012 +0100 summary: #15872: More shutil test fixes for Windows files: Lib/test/test_shutil.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -188,11 +188,11 @@ self.assertIs(errors[0][0], os.listdir) self.assertEqual(errors[0][1], filename) self.assertIsInstance(errors[0][2][1], NotADirectoryError) - self.assertEqual(errors[0][2][1].filename, filename) + self.assertEqual(errors[0][2][1].filename, rm_name) self.assertIs(errors[1][0], os.rmdir) self.assertEqual(errors[1][1], filename) self.assertIsInstance(errors[1][2][1], NotADirectoryError) - self.assertEqual(errors[1][2][1].filename, filename) + self.assertEqual(errors[1][2][1].filename, rm_name) # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 11:27:18 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 11:27:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=2315872=3A_More_shutil_test_fixes_for_Windows?= Message-ID: <3YKgT252v2zRXC@mail.python.org> http://hg.python.org/cpython/rev/c23659e2ec1a changeset: 80808:c23659e2ec1a parent: 80805:ad1c1164f68b parent: 80807:a05e2d4094ea user: Hynek Schlawack date: Mon Dec 10 11:12:57 2012 +0100 summary: #15872: More shutil test fixes for Windows This one is different from 3.2 and 3.3. Windows ceased using *.* since 3.4 apparently. files: Lib/test/test_shutil.py | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -172,11 +172,7 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(NotADirectoryError) as cm: shutil.rmtree(filename) - if os.name == 'nt': - rm_name = os.path.join(filename, '*.*') - else: - rm_name = filename - self.assertEqual(cm.exception.filename, rm_name) + self.assertEqual(cm.exception.filename, filename) self.assertTrue(os.path.exists(filename)) # test that ignore_errors option is honored shutil.rmtree(filename, ignore_errors=True) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 12:07:01 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 12:07:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1ODcyOiBCZSBm?= =?utf-8?q?lexible_with_appending_*=2E*_in_shutil=2Ermtree_test_case?= Message-ID: <3YKhLs6nHZzMQq@mail.python.org> http://hg.python.org/cpython/rev/2d953d47d634 changeset: 80809:2d953d47d634 branch: 3.2 parent: 80806:7ce8f4a70ccd user: Hynek Schlawack date: Mon Dec 10 12:01:28 2012 +0100 summary: #15872: Be flexible with appending *.* in shutil.rmtree test case The Windows buildbots seem to be unable to agree whether they need them or not. files: Lib/test/test_shutil.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -132,7 +132,7 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(OSError) as cm: shutil.rmtree(filename) - if os.name == 'nt': + if cm.exception.filename.endswith('*.*'): rm_name = os.path.join(filename, '*.*') else: rm_name = filename -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 12:07:03 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 12:07:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2315872=3A_Be_flexible_with_appending_*=2E*_in_shutil=2Ermtre?= =?utf-8?q?e_test_case?= Message-ID: <3YKhLv2J8pzRXr@mail.python.org> http://hg.python.org/cpython/rev/edb747c6c479 changeset: 80810:edb747c6c479 branch: 3.3 parent: 80807:a05e2d4094ea parent: 80809:2d953d47d634 user: Hynek Schlawack date: Mon Dec 10 12:02:26 2012 +0100 summary: #15872: Be flexible with appending *.* in shutil.rmtree test case The Windows buildbots seem to be unable to agree whether they need them or not. files: Lib/test/test_shutil.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -171,7 +171,7 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(NotADirectoryError) as cm: shutil.rmtree(filename) - if os.name == 'nt': + if cm.exception.filename.endswith('*.*'): rm_name = os.path.join(filename, '*.*') else: rm_name = filename -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 12:07:04 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 12:07:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=2315872=3A_Be_flexible_with_appending_*=2E*_in_shutil?= =?utf-8?q?=2Ermtree_test_case?= Message-ID: <3YKhLw4dQJzRY1@mail.python.org> http://hg.python.org/cpython/rev/a0a25ffdec9d changeset: 80811:a0a25ffdec9d parent: 80808:c23659e2ec1a parent: 80810:edb747c6c479 user: Hynek Schlawack date: Mon Dec 10 12:05:45 2012 +0100 summary: #15872: Be flexible with appending *.* in shutil.rmtree test case The Windows buildbots seem to be unable to agree whether they need them or not. files: Lib/test/test_shutil.py | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -172,7 +172,11 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(NotADirectoryError) as cm: shutil.rmtree(filename) - self.assertEqual(cm.exception.filename, filename) + if cm.exception.filename.endswith('*.*'): + rm_name = os.path.join(filename, '*.*') + else: + rm_name = filename + self.assertEqual(cm.exception.filename, rm_name) self.assertTrue(os.path.exists(filename)) # test that ignore_errors option is honored shutil.rmtree(filename, ignore_errors=True) @@ -185,11 +189,11 @@ self.assertIs(errors[0][0], os.listdir) self.assertEqual(errors[0][1], filename) self.assertIsInstance(errors[0][2][1], NotADirectoryError) - self.assertEqual(errors[0][2][1].filename, filename) + self.assertEqual(errors[0][2][1].filename, rm_name) self.assertIs(errors[1][0], os.rmdir) self.assertEqual(errors[1][1], filename) self.assertIsInstance(errors[1][2][1], NotADirectoryError) - self.assertEqual(errors[1][2][1].filename, filename) + self.assertEqual(errors[1][2][1].filename, rm_name) # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 16:37:11 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 16:37:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1ODcyOiBTb21l?= =?utf-8?q?_more_Windows_related_tuning_to_shutil=2Ermtree_tests?= Message-ID: <3YKpLb6PgYzRYk@mail.python.org> http://hg.python.org/cpython/rev/cb8274e1ebfa changeset: 80812:cb8274e1ebfa branch: 3.2 parent: 80809:2d953d47d634 user: Hynek Schlawack date: Mon Dec 10 16:29:57 2012 +0100 summary: #15872: Some more Windows related tuning to shutil.rmtree tests Turns out, the snakebite bots behave also their peculiarities. I'm really not proud of this stream of commits. :( files: Lib/test/test_shutil.py | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -132,13 +132,12 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(OSError) as cm: shutil.rmtree(filename) - if cm.exception.filename.endswith('*.*'): - rm_name = os.path.join(filename, '*.*') - else: - rm_name = filename - self.assertEqual(cm.exception.filename, rm_name) + # The reason for this rather odd construct is that Windows sprinkles + # a \*.* at the end of file names. But only sometimes on some buildbots + possible_args = [filename, os.path.join(filename, '*.*')] + self.assertIn(cm.exception.filename, possible_args) self.assertTrue(os.path.exists(filename)) - # test that ignore_errors option is honoured + # test that ignore_errors option is honored shutil.rmtree(filename, ignore_errors=True) self.assertTrue(os.path.exists(filename)) errors = [] @@ -149,11 +148,11 @@ self.assertIs(errors[0][0], os.listdir) self.assertEqual(errors[0][1], filename) self.assertIsInstance(errors[0][2][1], OSError) - self.assertEqual(errors[0][2][1].filename, rm_name) + self.assertIn(errors[0][2][1].filename, possible_args) self.assertIs(errors[1][0], os.rmdir) self.assertEqual(errors[1][1], filename) self.assertIsInstance(errors[1][2][1], OSError) - self.assertEqual(errors[1][2][1].filename, rm_name) + self.assertIn(errors[1][2][1].filename, possible_args) # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 16:37:13 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 16:37:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2315872=3A_Some_more_Windows_related_tuning_to_shutil=2Ermtre?= =?utf-8?q?e_tests?= Message-ID: <3YKpLd1jYlzRSG@mail.python.org> http://hg.python.org/cpython/rev/561c4012929a changeset: 80813:561c4012929a branch: 3.3 parent: 80810:edb747c6c479 parent: 80812:cb8274e1ebfa user: Hynek Schlawack date: Mon Dec 10 16:33:41 2012 +0100 summary: #15872: Some more Windows related tuning to shutil.rmtree tests Turns out, the snakebite bots behave also their peculiarities. I'm really not proud of this stream of commits. :( files: Lib/test/test_shutil.py | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -171,11 +171,10 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(NotADirectoryError) as cm: shutil.rmtree(filename) - if cm.exception.filename.endswith('*.*'): - rm_name = os.path.join(filename, '*.*') - else: - rm_name = filename - self.assertEqual(cm.exception.filename, rm_name) + # The reason for this rather odd construct is that Windows sprinkles + # a \*.* at the end of file names. But only sometimes on some buildbots + possible_args = [filename, os.path.join(filename, '*.*')] + self.assertIn(cm.exception.filename, possible_args) self.assertTrue(os.path.exists(filename)) # test that ignore_errors option is honored shutil.rmtree(filename, ignore_errors=True) @@ -188,11 +187,12 @@ self.assertIs(errors[0][0], os.listdir) self.assertEqual(errors[0][1], filename) self.assertIsInstance(errors[0][2][1], NotADirectoryError) - self.assertEqual(errors[0][2][1].filename, rm_name) + self.assertIn(errors[0][2][1].filename, possible_args) self.assertIs(errors[1][0], os.rmdir) self.assertEqual(errors[1][1], filename) self.assertIsInstance(errors[1][2][1], NotADirectoryError) - self.assertEqual(errors[1][2][1].filename, rm_name) + self.assertIn(errors[1][2][1].filename, possible_args) + # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 10 16:37:14 2012 From: python-checkins at python.org (hynek.schlawack) Date: Mon, 10 Dec 2012 16:37:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=2315872=3A_Some_more_Windows_related_tuning_to_shutil?= =?utf-8?q?=2Ermtree_tests?= Message-ID: <3YKpLf42yXzRTv@mail.python.org> http://hg.python.org/cpython/rev/451559508c54 changeset: 80814:451559508c54 parent: 80811:a0a25ffdec9d parent: 80813:561c4012929a user: Hynek Schlawack date: Mon Dec 10 16:35:16 2012 +0100 summary: #15872: Some more Windows related tuning to shutil.rmtree tests Turns out, the snakebite bots have also their peculiarities. I'm really not proud of this stream of commits. :( files: Lib/test/test_shutil.py | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -172,11 +172,10 @@ filename = os.path.join(tmpdir, "tstfile") with self.assertRaises(NotADirectoryError) as cm: shutil.rmtree(filename) - if cm.exception.filename.endswith('*.*'): - rm_name = os.path.join(filename, '*.*') - else: - rm_name = filename - self.assertEqual(cm.exception.filename, rm_name) + # The reason for this rather odd construct is that Windows sprinkles + # a \*.* at the end of file names. But only sometimes on some buildbots + possible_args = [filename, os.path.join(filename, '*.*')] + self.assertIn(cm.exception.filename, possible_args) self.assertTrue(os.path.exists(filename)) # test that ignore_errors option is honored shutil.rmtree(filename, ignore_errors=True) @@ -189,11 +188,12 @@ self.assertIs(errors[0][0], os.listdir) self.assertEqual(errors[0][1], filename) self.assertIsInstance(errors[0][2][1], NotADirectoryError) - self.assertEqual(errors[0][2][1].filename, rm_name) + self.assertIn(errors[0][2][1].filename, possible_args) self.assertIs(errors[1][0], os.rmdir) self.assertEqual(errors[1][1], filename) self.assertIsInstance(errors[1][2][1], NotADirectoryError) - self.assertEqual(errors[1][2][1].filename, rm_name) + self.assertIn(errors[1][2][1].filename, possible_args) + # See bug #1071513 for why we don't run this on cygwin # and bug #1076467 for why we don't run this as root. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 02:52:03 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 02:52:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogMSA8PCAzMSBpcyBp?= =?utf-8?q?nvalid_for_signed_integers=2C_fix_it_by_making_1_unsigned=2E?= Message-ID: <3YL4031wFXzRfw@mail.python.org> http://hg.python.org/cpython/rev/cd10df8ed21a changeset: 80815:cd10df8ed21a branch: 3.2 parent: 80812:cb8274e1ebfa user: Gregory P. Smith date: Mon Dec 10 17:44:44 2012 -0800 summary: 1 << 31 is invalid for signed integers, fix it by making 1 unsigned. Found by Clang trunk's Undefined-Behavior Sanitizer. [more to come] files: Modules/_sre.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -452,7 +452,7 @@ } else { /* (32 bits per code word) */ - if (ch < 256 && (set[ch >> 5] & (1 << (ch & 31)))) + if (ch < 256 && (set[ch >> 5] & (1u << (ch & 31)))) return ok; set += 8; } @@ -491,7 +491,7 @@ block = -1; set += 64; if (block >=0 && - (set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31)))) + (set[block*8 + ((ch & 255)>>5)] & (1u << (ch & 31)))) return ok; set += count*8; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 02:52:04 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 02:52:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_1_=3C=3C_31_is_invalid_for_signed_integers=2C_fix_it_by_making?= =?utf-8?q?_1_unsigned=2E?= Message-ID: <3YL4044cdZzRgB@mail.python.org> http://hg.python.org/cpython/rev/e47a547e63dc changeset: 80816:e47a547e63dc branch: 3.3 parent: 80813:561c4012929a parent: 80815:cd10df8ed21a user: Gregory P. Smith date: Mon Dec 10 17:45:03 2012 -0800 summary: 1 << 31 is invalid for signed integers, fix it by making 1 unsigned. Found by Clang trunk's Undefined-Behavior Sanitizer. [more to come] files: Modules/_sre.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -427,7 +427,7 @@ } else { /* (32 bits per code word) */ - if (ch < 256 && (set[ch >> 5] & (1 << (ch & 31)))) + if (ch < 256 && (set[ch >> 5] & (1u << (ch & 31)))) return ok; set += 8; } @@ -466,7 +466,7 @@ block = -1; set += 64; if (block >=0 && - (set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31)))) + (set[block*8 + ((ch & 255)>>5)] & (1u << (ch & 31)))) return ok; set += count*8; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 02:52:05 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 02:52:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_1_=3C=3C_31_is_invalid_for_signed_integers=2C_fix_it_by_?= =?utf-8?q?making_1_unsigned=2E?= Message-ID: <3YL4056v18zRgV@mail.python.org> http://hg.python.org/cpython/rev/b4c383f31881 changeset: 80817:b4c383f31881 parent: 80814:451559508c54 parent: 80816:e47a547e63dc user: Gregory P. Smith date: Mon Dec 10 17:45:16 2012 -0800 summary: 1 << 31 is invalid for signed integers, fix it by making 1 unsigned. Found by Clang trunk's Undefined-Behavior Sanitizer. [more to come] files: Modules/_sre.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -427,7 +427,7 @@ } else { /* (32 bits per code word) */ - if (ch < 256 && (set[ch >> 5] & (1 << (ch & 31)))) + if (ch < 256 && (set[ch >> 5] & (1u << (ch & 31)))) return ok; set += 8; } @@ -466,7 +466,7 @@ block = -1; set += 64; if (block >=0 && - (set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31)))) + (set[block*8 + ((ch & 255)>>5)] & (1u << (ch & 31)))) return ok; set += count*8; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 02:52:07 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 02:52:07 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogMSA8PCAzMSBpcyBp?= =?utf-8?q?nvalid_for_signed_integers=2C_fix_it_by_making_1_unsigned=2E?= Message-ID: <3YL4072W3DzRgW@mail.python.org> http://hg.python.org/cpython/rev/6c8a7469670b changeset: 80818:6c8a7469670b branch: 2.7 parent: 80795:37c1d20facd7 user: Gregory P. Smith date: Mon Dec 10 17:45:54 2012 -0800 summary: 1 << 31 is invalid for signed integers, fix it by making 1 unsigned. Found by Clang trunk's Undefined-Behavior Sanitizer. [more to come] files: Modules/_sre.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -459,7 +459,7 @@ } else { /* (32 bits per code word) */ - if (ch < 256 && (set[ch >> 5] & (1 << (ch & 31)))) + if (ch < 256 && (set[ch >> 5] & (1u << (ch & 31)))) return ok; set += 8; } @@ -498,7 +498,7 @@ block = -1; set += 64; if (block >=0 && - (set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31)))) + (set[block*8 + ((ch & 255)>>5)] & (1u << (ch & 31)))) return ok; set += count*8; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 03:05:19 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 03:05:19 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Using_=27long_double=27_to?= =?utf-8?q?_force_this_structure_to_be_worst_case_aligned_is_no?= Message-ID: <3YL4HM367BzRYL@mail.python.org> http://hg.python.org/cpython/rev/d61a1be9f5c5 changeset: 80819:d61a1be9f5c5 parent: 80817:b4c383f31881 user: Gregory P. Smith date: Mon Dec 10 18:05:05 2012 -0800 summary: Using 'long double' to force this structure to be worst case aligned is no longer required as of Python 2.5+ when the gc_refs changed from an int (4 bytes) to a Py_ssize_t (8 bytes) as the minimum size is 16 bytes. The use of a 'long double' triggered a warning by Clang trunk's Undefined-Behavior Sanitizer as on many platforms a long double requires 16-byte alignment but the Python memory allocator only guarantees 8 byte alignment. So our code would allocate and use these structures with technically improper alignment. Though it didn't matter since the 'dummy' field is never used. This silences that warning. Spelunking into code history, the double was added in 2001 to force better alignment on some platforms and changed to a long double in 2002 to appease Tru64. That issue should no loner be present since the upgrade from int to Py_ssize_t where the minimum structure size increased to 16 (unless anyone knows of a platform where ssize_t is 4 bytes?) or 24 bytes depending on if the build uses 4 or 8 byte pointers. We can probably get rid of the double and this union hack all together today. That is a slightly more invasive change that can be left for later. A more correct non-hacky alternative if any alignment issues are still found would be to use a compiler specific alignment declaration on the structure and determine which value to use at configure time. files: Include/objimpl.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Include/objimpl.h b/Include/objimpl.h --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -251,7 +251,7 @@ union _gc_head *gc_prev; Py_ssize_t gc_refs; } gc; - long double dummy; /* force worst-case alignment */ + double dummy; /* force worst-case alignment */ } PyGC_Head; extern PyGC_Head *_PyGC_generation0; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 04:53:00 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 04:53:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_the_intern?= =?utf-8?q?als_of_our_hash_functions_to_used_unsigned_values_during_hash?= Message-ID: <3YL6gc0cJKzRWR@mail.python.org> http://hg.python.org/cpython/rev/5c4e440852db changeset: 80820:5c4e440852db branch: 3.2 parent: 80815:cd10df8ed21a user: Gregory P. Smith date: Mon Dec 10 18:15:46 2012 -0800 summary: Fix the internals of our hash functions to used unsigned values during hash computation as the overflow behavior of signed integers is undefined. In practice we require compiling everything with -fwrapv which forces overflow to be defined as twos compliment but this keeps the code cleaner for checkers or in the case where someone has compiled it without -fwrapv or their compiler's equivalent. Found by Clang trunk's Undefined Behavior Sanitizer (UBSan). Cleanup only - no functionality or hash values change. files: Include/pyport.h | 2 +- Objects/bytesobject.c | 2 +- Objects/setobject.c | 12 ++++++------ Objects/tupleobject.c | 10 +++++----- Objects/unicodeobject.c | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -145,7 +145,7 @@ #endif /* Prime multiplier used in string and various other hashes. */ -#define _PyHASH_MULTIPLIER 1000003 /* 0xf4243 */ +#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */ /* Parameters used for the numeric hash implementation. See notes for _PyHash_Double in Objects/object.c. Numeric hashes are based on diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -873,7 +873,7 @@ { register Py_ssize_t len; register unsigned char *p; - register Py_hash_t x; + register Py_uhash_t x; /* Unsigned for defined overflow behavior. */ #ifdef Py_DEBUG assert(_Py_HashSecret_Initialized); diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -77,7 +77,7 @@ static setentry * set_lookkey(PySetObject *so, PyObject *key, register Py_hash_t hash) { - register Py_ssize_t i; + register size_t i; /* Unsigned for defined overflow behavior. */ register size_t perturb; register setentry *freeslot; register size_t mask = so->mask; @@ -159,7 +159,7 @@ static setentry * set_lookkey_unicode(PySetObject *so, PyObject *key, register Py_hash_t hash) { - register Py_ssize_t i; + register size_t i; /* Unsigned for defined overflow behavior. */ register size_t perturb; register setentry *freeslot; register size_t mask = so->mask; @@ -768,7 +768,7 @@ frozenset_hash(PyObject *self) { PySetObject *so = (PySetObject *)self; - Py_hash_t h, hash = 1927868237L; + Py_uhash_t h, hash = 1927868237UL; setentry *entry; Py_ssize_t pos = 0; @@ -783,11 +783,11 @@ hashes so that many distinct combinations collapse to only a handful of distinct hash values. */ h = entry->hash; - hash ^= (h ^ (h << 16) ^ 89869747L) * 3644798167u; + hash ^= (h ^ (h << 16) ^ 89869747UL) * 3644798167UL; } - hash = hash * 69069L + 907133923L; + hash = hash * 69069UL + 907133923UL; if (hash == -1) - hash = 590923713L; + hash = 590923713UL; so->hash = hash; return hash; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -315,11 +315,11 @@ static Py_hash_t tuplehash(PyTupleObject *v) { - register Py_hash_t x, y; + register Py_uhash_t x, y; /* Unsigned for defined overflow behavior. */ register Py_ssize_t len = Py_SIZE(v); register PyObject **p; - Py_hash_t mult = _PyHASH_MULTIPLIER; - x = 0x345678L; + Py_uhash_t mult = _PyHASH_MULTIPLIER; + x = 0x345678UL; p = v->ob_item; while (--len >= 0) { y = PyObject_Hash(*p++); @@ -327,9 +327,9 @@ return -1; x = (x ^ y) * mult; /* the cast might truncate len; that doesn't change hash stability */ - mult += (Py_hash_t)(82520L + len + len); + mult += (Py_uhash_t)(82520UL + len + len); } - x += 97531L; + x += 97531UL; if (x == -1) x = -2; return x; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -7686,7 +7686,7 @@ { Py_ssize_t len; Py_UNICODE *p; - Py_hash_t x; + Py_uhash_t x; /* Unsigned for defined overflow behavior. */ #ifdef Py_DEBUG assert(_Py_HashSecret_Initialized); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 04:53:01 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 04:53:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Fix_the_internals_of_our_hash_functions_to_used_unsigned_value?= =?utf-8?q?s_during_hash?= Message-ID: <3YL6gd4kHyzRXh@mail.python.org> http://hg.python.org/cpython/rev/8b4fff41dee5 changeset: 80821:8b4fff41dee5 branch: 3.3 parent: 80816:e47a547e63dc parent: 80820:5c4e440852db user: Gregory P. Smith date: Mon Dec 10 18:32:53 2012 -0800 summary: Fix the internals of our hash functions to used unsigned values during hash computation as the overflow behavior of signed integers is undefined. NOTE: This change is smaller compared to 3.2 as much of this cleanup had already been done. I added the comment that my change in 3.2 added so that the code would match up. Otherwise this just adds or synchronizes appropriate UL designations on some constants to be pedantic. In practice we require compiling everything with -fwrapv which forces overflow to be defined as twos compliment but this keeps the code cleaner for checkers or in the case where someone has compiled it without -fwrapv or their compiler's equivalent. Found by Clang trunk's Undefined Behavior Sanitizer (UBSan). Cleanup only - no functionality or hash values change. files: Include/pyport.h | 2 +- Objects/setobject.c | 12 ++++++------ Objects/tupleobject.c | 8 ++++---- Objects/unicodeobject.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -145,7 +145,7 @@ #endif /* Prime multiplier used in string and various other hashes. */ -#define _PyHASH_MULTIPLIER 1000003 /* 0xf4243 */ +#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */ /* Parameters used for the numeric hash implementation. See notes for _Py_HashDouble in Objects/object.c. Numeric hashes are based on diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -77,7 +77,7 @@ static setentry * set_lookkey(PySetObject *so, PyObject *key, register Py_hash_t hash) { - register size_t i; + register size_t i; /* Unsigned for defined overflow behavior. */ register size_t perturb; register setentry *freeslot; register size_t mask = so->mask; @@ -159,7 +159,7 @@ static setentry * set_lookkey_unicode(PySetObject *so, PyObject *key, register Py_hash_t hash) { - register size_t i; + register size_t i; /* Unsigned for defined overflow behavior. */ register size_t perturb; register setentry *freeslot; register size_t mask = so->mask; @@ -760,7 +760,7 @@ frozenset_hash(PyObject *self) { PySetObject *so = (PySetObject *)self; - Py_uhash_t h, hash = 1927868237U; + Py_uhash_t h, hash = 1927868237UL; setentry *entry; Py_ssize_t pos = 0; @@ -775,11 +775,11 @@ hashes so that many distinct combinations collapse to only a handful of distinct hash values. */ h = entry->hash; - hash ^= (h ^ (h << 16) ^ 89869747U) * 3644798167U; + hash ^= (h ^ (h << 16) ^ 89869747UL) * 3644798167UL; } - hash = hash * 69069U + 907133923U; + hash = hash * 69069U + 907133923UL; if (hash == -1) - hash = 590923713U; + hash = 590923713UL; so->hash = hash; return hash; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -327,12 +327,12 @@ static Py_hash_t tuplehash(PyTupleObject *v) { - register Py_uhash_t x; + register Py_uhash_t x; /* Unsigned for defined overflow behavior. */ register Py_hash_t y; register Py_ssize_t len = Py_SIZE(v); register PyObject **p; Py_uhash_t mult = _PyHASH_MULTIPLIER; - x = 0x345678; + x = 0x345678UL; p = v->ob_item; while (--len >= 0) { y = PyObject_Hash(*p++); @@ -340,9 +340,9 @@ return -1; x = (x ^ y) * mult; /* the cast might truncate len; that doesn't change hash stability */ - mult += (Py_hash_t)(82520L + len + len); + mult += (Py_hash_t)(82520UL + len + len); } - x += 97531L; + x += 97531UL; if (x == (Py_uhash_t)-1) x = -2; return x; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11008,7 +11008,7 @@ unicode_hash(PyObject *self) { Py_ssize_t len; - Py_uhash_t x; + Py_uhash_t x; /* Unsigned for defined overflow behavior. */ #ifdef Py_DEBUG assert(_Py_HashSecret_Initialized); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 04:53:02 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 04:53:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogS2VlcCB5IGEgUHlf?= =?utf-8?q?hash=5Ft_instead_of_Py=5Fuhash=5Ft_as_it_is_compared_with_=3D?= =?utf-8?q?=3D_-1_and_the?= Message-ID: <3YL6gf71qdzRZX@mail.python.org> http://hg.python.org/cpython/rev/a8fb68576fa0 changeset: 80822:a8fb68576fa0 branch: 3.2 parent: 80820:5c4e440852db user: Gregory P. Smith date: Mon Dec 10 18:34:09 2012 -0800 summary: Keep y a Py_hash_t instead of Py_uhash_t as it is compared with == -1 and the compiler logic will do the right thing with just x as a Py_uhash_t. This matches what was already done in the 3.3 version. cleanup only - no functionality or hash values change. files: Objects/tupleobject.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -315,7 +315,8 @@ static Py_hash_t tuplehash(PyTupleObject *v) { - register Py_uhash_t x, y; /* Unsigned for defined overflow behavior. */ + register Py_uhash_t x; /* Unsigned for defined overflow behavior. */ + register Py_hash_t y; register Py_ssize_t len = Py_SIZE(v); register PyObject **p; Py_uhash_t mult = _PyHASH_MULTIPLIER; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 04:53:04 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 04:53:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_null_merge=2C_no_change_needed_in_3=2E3=2E?= Message-ID: <3YL6gh292mzRcP@mail.python.org> http://hg.python.org/cpython/rev/11236dacc76f changeset: 80823:11236dacc76f branch: 3.3 parent: 80821:8b4fff41dee5 parent: 80822:a8fb68576fa0 user: Gregory P. Smith date: Mon Dec 10 18:34:29 2012 -0800 summary: null merge, no change needed in 3.3. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 04:53:05 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 04:53:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_the_internals_of_our_hash_functions_to_used_unsigned?= =?utf-8?q?_values_during_hash?= Message-ID: <3YL6gj60bVzRdf@mail.python.org> http://hg.python.org/cpython/rev/a1768761358a changeset: 80824:a1768761358a parent: 80819:d61a1be9f5c5 parent: 80823:11236dacc76f user: Gregory P. Smith date: Mon Dec 10 19:51:29 2012 -0800 summary: Fix the internals of our hash functions to used unsigned values during hash computation as the overflow behavior of signed integers is undefined. NOTE: This change is smaller compared to 3.2 as much of this cleanup had already been done. I added the comment that my change in 3.2 added so that the code would match up. Otherwise this just adds or synchronizes appropriate UL designations on some constants to be pedantic. In practice we require compiling everything with -fwrapv which forces overflow to be defined as twos compliment but this keeps the code cleaner for checkers or in the case where someone has compiled it without -fwrapv or their compiler's equivalent. We could work to get rid of the -fwrapv requirement in 3.4 but that requires more planning. Found by Clang trunk's Undefined Behavior Sanitizer (UBSan). Cleanup only - no functionality or hash values change. files: Include/pyport.h | 2 +- Objects/setobject.c | 12 ++++++------ Objects/tupleobject.c | 8 ++++---- Objects/unicodeobject.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -145,7 +145,7 @@ #endif /* Prime multiplier used in string and various other hashes. */ -#define _PyHASH_MULTIPLIER 1000003 /* 0xf4243 */ +#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */ /* Parameters used for the numeric hash implementation. See notes for _Py_HashDouble in Objects/object.c. Numeric hashes are based on diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -77,7 +77,7 @@ static setentry * set_lookkey(PySetObject *so, PyObject *key, register Py_hash_t hash) { - register size_t i; + register size_t i; /* Unsigned for defined overflow behavior. */ register size_t perturb; register setentry *freeslot; register size_t mask = so->mask; @@ -159,7 +159,7 @@ static setentry * set_lookkey_unicode(PySetObject *so, PyObject *key, register Py_hash_t hash) { - register size_t i; + register size_t i; /* Unsigned for defined overflow behavior. */ register size_t perturb; register setentry *freeslot; register size_t mask = so->mask; @@ -760,7 +760,7 @@ frozenset_hash(PyObject *self) { PySetObject *so = (PySetObject *)self; - Py_uhash_t h, hash = 1927868237U; + Py_uhash_t h, hash = 1927868237UL; setentry *entry; Py_ssize_t pos = 0; @@ -775,11 +775,11 @@ hashes so that many distinct combinations collapse to only a handful of distinct hash values. */ h = entry->hash; - hash ^= (h ^ (h << 16) ^ 89869747U) * 3644798167U; + hash ^= (h ^ (h << 16) ^ 89869747UL) * 3644798167UL; } - hash = hash * 69069U + 907133923U; + hash = hash * 69069U + 907133923UL; if (hash == -1) - hash = 590923713U; + hash = 590923713UL; so->hash = hash; return hash; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -327,12 +327,12 @@ static Py_hash_t tuplehash(PyTupleObject *v) { - register Py_uhash_t x; + register Py_uhash_t x; /* Unsigned for defined overflow behavior. */ register Py_hash_t y; register Py_ssize_t len = Py_SIZE(v); register PyObject **p; Py_uhash_t mult = _PyHASH_MULTIPLIER; - x = 0x345678; + x = 0x345678UL; p = v->ob_item; while (--len >= 0) { y = PyObject_Hash(*p++); @@ -340,9 +340,9 @@ return -1; x = (x ^ y) * mult; /* the cast might truncate len; that doesn't change hash stability */ - mult += (Py_hash_t)(82520L + len + len); + mult += (Py_hash_t)(82520UL + len + len); } - x += 97531L; + x += 97531UL; if (x == (Py_uhash_t)-1) x = -2; return x; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -10885,7 +10885,7 @@ unicode_hash(PyObject *self) { Py_ssize_t len; - Py_uhash_t x; + Py_uhash_t x; /* Unsigned for defined overflow behavior. */ #ifdef Py_DEBUG assert(_Py_HashSecret_Initialized); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 05:23:01 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 05:23:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Code_style_fix?= =?utf-8?q?up=3A_No_need_for_double_=28=28parenthesis=29=29_and_use_=7B=7D?= =?utf-8?q?_on_an_if_else=2E?= Message-ID: <3YL7LF0rylzRdZ@mail.python.org> http://hg.python.org/cpython/rev/88dcccb46298 changeset: 80825:88dcccb46298 branch: 3.2 parent: 80822:a8fb68576fa0 user: Gregory P. Smith date: Mon Dec 10 20:20:20 2012 -0800 summary: Code style fixup: No need for double ((parenthesis)) and use {} on an if else. files: Modules/arraymodule.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1461,7 +1461,7 @@ if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n)) return NULL; typecode = self->ob_descr->typecode; - if ((typecode != 'u')) { + if (typecode != 'u') { PyErr_SetString(PyExc_ValueError, "fromunicode() may only be called on " "unicode type arrays"); @@ -1493,7 +1493,7 @@ { Py_UNICODE typecode; typecode = self->ob_descr->typecode; - if ((typecode != 'u')) { + if (typecode != 'u') { PyErr_SetString(PyExc_ValueError, "tounicode() may only be called on unicode type arrays"); return NULL; @@ -2107,10 +2107,11 @@ if (len == 0) { return PyUnicode_FromFormat("array('%c')", (int)typecode); } - if ((typecode == 'u')) + if (typecode == 'u') { v = array_tounicode(a, NULL); - else + } else { v = array_tolist(a, NULL); + } s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v); Py_DECREF(v); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 05:23:02 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 05:23:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Code_style_fixup=3A_No_need_for_double_=28=28parenthesis=29=29?= =?utf-8?q?_and_use_=7B=7D_on_an_if_else=2E?= Message-ID: <3YL7LG38f5zRb4@mail.python.org> http://hg.python.org/cpython/rev/757cc49ced54 changeset: 80826:757cc49ced54 branch: 3.3 parent: 80823:11236dacc76f parent: 80825:88dcccb46298 user: Gregory P. Smith date: Mon Dec 10 20:22:31 2012 -0800 summary: Code style fixup: No need for double ((parenthesis)) and use {} on an if else. files: Modules/arraymodule.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1522,7 +1522,7 @@ if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n)) return NULL; typecode = self->ob_descr->typecode; - if ((typecode != 'u')) { + if (typecode != 'u') { PyErr_SetString(PyExc_ValueError, "fromunicode() may only be called on " "unicode type arrays"); @@ -1554,7 +1554,7 @@ { char typecode; typecode = self->ob_descr->typecode; - if ((typecode != 'u')) { + if (typecode != 'u') { PyErr_SetString(PyExc_ValueError, "tounicode() may only be called on unicode type arrays"); return NULL; @@ -2177,10 +2177,11 @@ if (len == 0) { return PyUnicode_FromFormat("array('%c')", (int)typecode); } - if (typecode == 'u') + if (typecode == 'u') { v = array_tounicode(a, NULL); - else + } else { v = array_tolist(a, NULL); + } s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v); Py_DECREF(v); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 11 05:23:03 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 11 Dec 2012 05:23:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Code_style_fixup=3A_No_need_for_double_=28=28parenthesis?= =?utf-8?q?=29=29_and_use_=7B=7D_on_an_if_else=2E?= Message-ID: <3YL7LH5nkMzRfN@mail.python.org> http://hg.python.org/cpython/rev/bc322469a7a8 changeset: 80827:bc322469a7a8 parent: 80824:a1768761358a parent: 80826:757cc49ced54 user: Gregory P. Smith date: Mon Dec 10 20:22:55 2012 -0800 summary: Code style fixup: No need for double ((parenthesis)) and use {} on an if else. files: Modules/arraymodule.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1522,7 +1522,7 @@ if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n)) return NULL; typecode = self->ob_descr->typecode; - if ((typecode != 'u')) { + if (typecode != 'u') { PyErr_SetString(PyExc_ValueError, "fromunicode() may only be called on " "unicode type arrays"); @@ -1554,7 +1554,7 @@ { char typecode; typecode = self->ob_descr->typecode; - if ((typecode != 'u')) { + if (typecode != 'u') { PyErr_SetString(PyExc_ValueError, "tounicode() may only be called on unicode type arrays"); return NULL; @@ -2174,10 +2174,11 @@ if (len == 0) { return PyUnicode_FromFormat("array('%c')", (int)typecode); } - if (typecode == 'u') + if (typecode == 'u') { v = array_tounicode(a, NULL); - else + } else { v = array_tolist(a, NULL); + } s = PyUnicode_FromFormat("array('%c', %R)", (int)typecode, v); Py_DECREF(v); -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Tue Dec 11 06:00:30 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 11 Dec 2012 06:00:30 +0100 Subject: [Python-checkins] Daily reference leaks (d61a1be9f5c5): sum=6 Message-ID: results for d61a1be9f5c5 on branch "default" -------------------------------------------- test_concurrent_futures leaked [-2, 3, 1] memory blocks, sum=2 test_dbm leaked [0, 0, 2] references, sum=2 test_dbm leaked [0, 0, 2] memory blocks, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogy6MfHo', '-x'] From python-checkins at python.org Tue Dec 11 21:28:53 2012 From: python-checkins at python.org (barry.warsaw) Date: Tue, 11 Dec 2012 21:28:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_431=3A_Time_zone_support_?= =?utf-8?q?improvements?= Message-ID: <3YLXmj2z02zRjC@mail.python.org> http://hg.python.org/peps/rev/296f21c73f0b changeset: 4597:296f21c73f0b user: Barry Warsaw date: Tue Dec 11 15:28:45 2012 -0500 summary: PEP 431: Time zone support improvements (By Lennart Regebro, with very minor formatting by Barry.) files: pep-0431.txt | 261 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 261 insertions(+), 0 deletions(-) diff --git a/pep-0431.txt b/pep-0431.txt new file mode 100644 --- /dev/null +++ b/pep-0431.txt @@ -0,0 +1,261 @@ +PEP: 431 +Title: Time zone support improvements +Version: $Revision$ +Last-Modified: $Date$ +Author: Lennart Regebro +BDFL-Delegate: Barry Warsaw +Status: Draft +Type: Standards Track +Content-Type: text/x-rst +Created: 11-Dec-2012 +Post-History: 11-Dec-2012 + + +Abstract +======== + +This PEP proposes the implementation of concrete time zone support in the +Python standard library, and also improvements to the time zone API to deal +with ambiguous time specifications during DST changes. + + +Proposal +======== + +Concrete time zone support +-------------------------- + +The time zone support in Python has no concrete implementation in the +standard library, only a tzinfo baseclass, and since Python 3.2, one concrete +time zone: UTC. To properly support time zones you need to include a database +over all time zones, both current and historical, including daylight saving +changes. But such information changes frequently, so even if we include the +last information in a Python release, that information would be outdated just +a few months later. + +Timezone support has therefore only been available through two third-party +modules, ``pytz`` and ``dateutil``, both who include and wrap the "zoneinfo" +database. This database, also called "tz" or "The Olsen database", is the +de-facto standard time zone database over time zones, and it is included in +most variants of Unix operating systems, including OS X. + +This gives us the opportunity to include only the code that supports the +zoneinfo data in the standard library, but by default use the operating +systems copy of the data, which typically will be kept updated by the +updating mechanism of the operating system or distribution. + +For those who have an operating system that does not include the tz database, +for example Windows, a distribution containing the latest tz database should +also be available at the Python Package Index, so it can be easily installed +with the Python packaging tools such as ``easy_install`` or ``pip``. This +could also be done on Unices that are no longer recieving updates and +therefore has an outdated database. + +With such a mechanism Python would have full time zone support in the +standard library on most platforms, and a simple package installation would +provide time zone support on those platforms where the tz database isn't +included, such as Windows. + +The time zone support will be implemented by a new module called `timezone``, +based on Stuart Bishop's ``pytz`` module. + + +Getting the local time zone +--------------------------- + +On Unix there is no standard way of finding the name of the time zone that is +being used. All the information that is available is the time zone +abbreviations, such as ``EST`` and ``PDT``, but many of those abbreviations +are ambigious and therefore you can't rely on them to figure out which time +zone you are located in. + +There is however a standard for finding the compiled time zone information +since it's located in ``/etc/localtime``. Therefore it is possible to create +a local time zone object with the correct time zone information even though +you don't know the name of the time zone. A function in ``datetime`` should +be provided to return the local time zone. + +The support for this will be made by integrating Lennart Regebro's +``tzlocal`` module into the new ``timezone`` module. + + +Ambiguous times +--------------- + +When changing over from daylight savings time the clock is turned back one +hour. This means that the times during that hour happens twice, once without +DST and then once with DST. Similarily, when changing to daylight savings +time, one hour goes missing. + +The current time zone API can not differentiating between the two ambiguous +times during a change from DST. For example, in Stockholm the time of +2012-11-28 02:00:00 happens twice, both at UTC 2012-11-28 00:00:00 and also +at 2012-11-28 01:00:00. + +The current time zone API can not disambiguate this and therefore it's +unclear which time should be returned:: + + # This could be either 00:00 or 01:00 UTC: + >>> dt = datetime(2012, 11, 28, 2, 0, tzinfo=timezone('Europe/Stockholm')) + # But we can not specify which: + >>> dt.astimezone(timezone('UTC')) + datetime.datetime(2012, 11, 28, 1, 0, tzinfo=) + +``pytz`` solved this problem by adding ``is_dst`` parameters to several +methods of the tzinfo objects to make it possible to disambiguate times when +this is desired. + +This PEP proposes to add these ``is_dst`` parameters to the relevant methods +of the ``datetime`` API, and therefore add this functionality directly to +``datetime``. This is likely the hardest part of this PEP as this involves +updating the + + +Implementation API +================== + +The new ``timezone``-module +--------------------------- + +The public API of the new ``timezone``-module contains one new class, one new +function and one new exception. + +* New class: ``DstTzInfo`` + + This class provides a concrete implementation of the ``zoneinfo`` base + class that implements DST support. + + +* New function :``get_timezone(name=None, db=None)`` + + This function takes a name string that must be a string specifying a + valid zoneinfo timezone, ie "US/Eastern", "Europe/Warsaw" or "Etc/GMT+11". + If not given, the local timezone will be looked up. If an invalid zone name + are given, or the local timezone can not be retrieved, the function raises + `UnknownTimeZoneError`. + + The function also takes an optional path to the location of the zoneinfo + database which should be used. If not specified, the function will check if + the `timezonedata` module is installed, and then use that location or + otherwise use the database in ``/usr/share/zoneinfo``. + + If no database is found an ``UnknownTimeZoneError`` or subclass thereof will + be raised with a message explaining that no zoneinfo database can be found, + but that you can install one with the ``timezonedata`` package. + +* New Exception: ``UnknownTimeZoneError`` + + This exception is raised when giving a time zone specification that can't be + found:: + + >>> datetime.Timezone('Europe/New_York') + Traceback (most recent call last): + ... + UnknownTimeZoneError: There is no time zone called 'Europe/New_York' + + +Changes in the ``datetime``-module +-------------------------------------- + +A new ``is_dst`` parameter is added to several of the `tzinfo` methods to +handle time ambiguity during DST changeovers. + +* ``tzinfo.utcoffset(self, dt, is_dst=True)`` + +* ``tzinfo.dst(self, dt, is_dst=True)`` + +* ``tzinfo.tzname(self, dt, is_dst=True)`` + +The ``is_dst`` parameter can be ``True`` (default), ``False``, or ``None``. + +``True`` will specify that the given datetime should be interpreted as +happening during daylight savings time, ie that the time specified is before +the change from DST. + +``False`` will specify that the given datetime should be interpreted as not +happening during daylight savings time, ie that the time specified is after +the change from DST. + +``None`` will raise an ``AmbiguousTimeError`` exception if the time specified +was during a DST change over. It will also raise a ``NonExistentTimeError`` +if a time is specified during the "missing time" in a change to DST. + +There are also two new exceptions: + +* ``AmbiguousTimeError`` + + This exception is raised when giving a datetime specification that are + ambigious while setting ``is_dst`` to None:: + + >>> datetime(2012, 11, 28, 2, 0, tzinfo=timezone('Europe/Stockholm'), is_dst=None) + >>> + Traceback (most recent call last): + ... + AmbiguousTimeError: 2012-10-28 02:00:00 is ambiguous in time zone Europe/Stockholm + + +* ``NonExistentTimeError`` + + This exception is raised when giving a datetime specification that are + ambigious while setting ``is_dst`` to None:: + + >>> datetime(2012, 3, 25, 2, 0, tzinfo=timezone('Europe/Stockholm'), is_dst=None) + >>> + Traceback (most recent call last): + ... + NonExistentTimeError: 2012-03-25 02:00:00 does not exist in time zone Europe/Stockholm + + +The ``timezonedata``-package +----------------------------- + +The zoneinfo database will be packaged for easy installation with +``easy_install``/``pip``/``buildout``. This package will not install any +Python code, and will not contain any Python code except that which is needed +for installation. + + +Differences from the ``pytz`` API +================================= + +* ``pytz`` has the functions ``localize()`` and ``normalize()`` to work + around that ``tzinfo`` doesn't have is_dst. When ``is_dst`` is + implemented directly in ``datetime.tzinfo`` they are no longer needed. + +* The ``pytz`` method ``timezone()`` is instead called ``get_timezone()`` for + clarity. + +* ``get_timezone()`` will return the local time zone if called without + parameters. + +* The class ``pytz.StaticTzInfo`` is there to provide the ``is_dst`` support + for static timezones. When ``is_dst`` support is included in + ``datetime.tzinfo`` it is no longer needed. + + +Discussion +========== + +Should the windows installer include the data package? +------------------------------------------------------ + +It has been suggested that the Windows installer should include the data +package. This would mean that an explicit installation no longer would be +needed on Windows. On the other hand, that would mean that many using Windows +would not be aware that the database quickly becomes outdated and would not +keep it updated. + + +Resources +========= + +* http://pytz.sourceforge.net/ + +* http://pypi.python.org/pypi/tzlocal + +* http://pypi.python.org/pypi/python-dateutil + +Copyright +========= + +This document has been placed in the public domain. -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Wed Dec 12 05:59:44 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 12 Dec 2012 05:59:44 +0100 Subject: [Python-checkins] Daily reference leaks (bc322469a7a8): sum=-1 Message-ID: results for bc322469a7a8 on branch "default" -------------------------------------------- test_support leaked [0, 0, -1] references, sum=-1 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflognzT0j7', '-x'] From python-checkins at python.org Wed Dec 12 11:24:17 2012 From: python-checkins at python.org (christian.heimes) Date: Wed, 12 Dec 2012 11:24:17 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Fixed_PEP_type?= Message-ID: <3YLvJd6rdTzRgL@mail.python.org> http://hg.python.org/peps/rev/67a80e960344 changeset: 4598:67a80e960344 user: Christian Heimes date: Wed Dec 12 11:23:58 2012 +0100 summary: Fixed PEP type excluding: PEP 431: "u'Standards Track ' is not a valid Type value" files: pep-0431.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0431.txt b/pep-0431.txt --- a/pep-0431.txt +++ b/pep-0431.txt @@ -5,7 +5,7 @@ Author: Lennart Regebro BDFL-Delegate: Barry Warsaw Status: Draft -Type: Standards Track +Type: Standards Track Content-Type: text/x-rst Created: 11-Dec-2012 Post-History: 11-Dec-2012 -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Wed Dec 12 12:42:01 2012 From: python-checkins at python.org (christian.heimes) Date: Wed, 12 Dec 2012 12:42:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Fix_cross_comp?= =?utf-8?q?iling_issue_in_setup=2Epy=2C_ensure_that_lib=5Fdirs_and_inc=5Fd?= =?utf-8?q?irs_are?= Message-ID: <3YLx2K1mr4zRgr@mail.python.org> http://hg.python.org/cpython/rev/9f1f27c5e5b2 changeset: 80828:9f1f27c5e5b2 branch: 3.3 parent: 80826:757cc49ced54 user: Christian Heimes date: Wed Dec 12 12:41:00 2012 +0100 summary: Fix cross compiling issue in setup.py, ensure that lib_dirs and inc_dirs are defined in cross compiling mode, too. files: Misc/NEWS | 3 +++ setup.py | 3 +++ 2 files changed, 6 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -316,6 +316,9 @@ Build ----- +- Fix cross compiling issue in setup.py, ensure that lib_dirs and inc_dirs are + defined in cross compiling mode, too. + - Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf - Issue #16262: fix out-of-src-tree builds, if mercurial is not installed. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -506,6 +506,9 @@ '/lib', '/usr/lib', ] inc_dirs = self.compiler.include_dirs + ['/usr/include'] + else: + lib_dirs = [] + inc_dirs = [] exts = [] missing = [] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 12 12:42:02 2012 From: python-checkins at python.org (christian.heimes) Date: Wed, 12 Dec 2012 12:42:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_cross_compiling_issue_in_setup=2Epy=2C_ensure_that_l?= =?utf-8?q?ib=5Fdirs_and_inc=5Fdirs_are?= Message-ID: <3YLx2L4TLRzRkp@mail.python.org> http://hg.python.org/cpython/rev/08113a9e954c changeset: 80829:08113a9e954c parent: 80827:bc322469a7a8 parent: 80828:9f1f27c5e5b2 user: Christian Heimes date: Wed Dec 12 12:41:50 2012 +0100 summary: Fix cross compiling issue in setup.py, ensure that lib_dirs and inc_dirs are defined in cross compiling mode, too. files: Misc/NEWS | 3 +++ setup.py | 3 +++ 2 files changed, 6 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -467,6 +467,9 @@ Build ----- +- Fix cross compiling issue in setup.py, ensure that lib_dirs and inc_dirs are + defined in cross compiling mode, too. + - Issue #16593: Have BSD 'make -s' do the right thing, thanks to Daniel Shahaf - Issue #16262: fix out-of-src-tree builds, if mercurial is not installed. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -506,6 +506,9 @@ '/lib', '/usr/lib', ] inc_dirs = self.compiler.include_dirs + ['/usr/include'] + else: + lib_dirs = [] + inc_dirs = [] exts = [] missing = [] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 12 12:57:11 2012 From: python-checkins at python.org (christian.heimes) Date: Wed, 12 Dec 2012 12:57:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Just_to_be_sur?= =?utf-8?q?e=2C_initialize_with_a_copy_of_the_compiler=27s_lib_and_inc_dir?= =?utf-8?q?s=2E?= Message-ID: <3YLxMq66ndzRjc@mail.python.org> http://hg.python.org/cpython/rev/9e63d99bff64 changeset: 80830:9e63d99bff64 branch: 3.3 parent: 80828:9f1f27c5e5b2 user: Christian Heimes date: Wed Dec 12 12:56:51 2012 +0100 summary: Just to be sure, initialize with a copy of the compiler's lib and inc dirs. files: setup.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -507,8 +507,8 @@ ] inc_dirs = self.compiler.include_dirs + ['/usr/include'] else: - lib_dirs = [] - inc_dirs = [] + lib_dirs = self.compiler.library_dirs[:] + inc_dirs = self.compiler.include_dirs[:] exts = [] missing = [] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 12 12:57:13 2012 From: python-checkins at python.org (christian.heimes) Date: Wed, 12 Dec 2012 12:57:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Just_to_be_sure=2C_initialize_with_a_copy_of_the_compile?= =?utf-8?q?r=27s_lib_and_inc_dirs=2E?= Message-ID: <3YLxMs1Jv1zRjc@mail.python.org> http://hg.python.org/cpython/rev/76abdc4b3795 changeset: 80831:76abdc4b3795 parent: 80829:08113a9e954c parent: 80830:9e63d99bff64 user: Christian Heimes date: Wed Dec 12 12:57:03 2012 +0100 summary: Just to be sure, initialize with a copy of the compiler's lib and inc dirs. files: setup.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -507,8 +507,8 @@ ] inc_dirs = self.compiler.include_dirs + ['/usr/include'] else: - lib_dirs = [] - inc_dirs = [] + lib_dirs = self.compiler.library_dirs[:] + inc_dirs = self.compiler.include_dirs[:] exts = [] missing = [] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 12 13:10:41 2012 From: python-checkins at python.org (christian.heimes) Date: Wed, 12 Dec 2012 13:10:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Cross_compilin?= =?utf-8?q?g_needs_host_and_build_settings=2E_configure_no_longer?= Message-ID: <3YLxgP6MxkzRkr@mail.python.org> http://hg.python.org/cpython/rev/bdd4ec5eb621 changeset: 80832:bdd4ec5eb621 branch: 3.3 parent: 80830:9e63d99bff64 user: Christian Heimes date: Wed Dec 12 13:10:21 2012 +0100 summary: Cross compiling needs host and build settings. configure no longer creates a broken PYTHON_FOR_BUILD variable when --build is missing. files: Misc/NEWS | 3 +++ configure | 2 ++ configure.ac | 2 ++ 3 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -316,6 +316,9 @@ Build ----- +- Cross compiling needs host and build settings. configure no longer + creates a broken PYTHON_FOR_BUILD variable when --build is missing. + - Fix cross compiling issue in setup.py, ensure that lib_dirs and inc_dirs are defined in cross compiling mode, too. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -2943,6 +2943,8 @@ $as_echo "$interp" >&6; } PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp fi +elif test "$cross_compiling" = maybe; then + as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5 else PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E' fi diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -67,6 +67,8 @@ AC_MSG_RESULT($interp) PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp fi +elif test "$cross_compiling" = maybe; then + AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH]) else PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E' fi -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 12 13:10:43 2012 From: python-checkins at python.org (christian.heimes) Date: Wed, 12 Dec 2012 13:10:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Cross_compiling_needs_host_and_build_settings=2E_configu?= =?utf-8?q?re_no_longer?= Message-ID: <3YLxgR1yhVzRlr@mail.python.org> http://hg.python.org/cpython/rev/e680202e5603 changeset: 80833:e680202e5603 parent: 80831:76abdc4b3795 parent: 80832:bdd4ec5eb621 user: Christian Heimes date: Wed Dec 12 13:10:32 2012 +0100 summary: Cross compiling needs host and build settings. configure no longer creates a broken PYTHON_FOR_BUILD variable when --build is missing. files: Misc/NEWS | 3 +++ configure | 2 ++ configure.ac | 2 ++ 3 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -467,6 +467,9 @@ Build ----- +- Cross compiling needs host and build settings. configure no longer + creates a broken PYTHON_FOR_BUILD variable when --build is missing. + - Fix cross compiling issue in setup.py, ensure that lib_dirs and inc_dirs are defined in cross compiling mode, too. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -2943,6 +2943,8 @@ $as_echo "$interp" >&6; } PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp fi +elif test "$cross_compiling" = maybe; then + as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5 else PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E' fi diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -67,6 +67,8 @@ AC_MSG_RESULT($interp) PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp fi +elif test "$cross_compiling" = maybe; then + AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH]) else PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E' fi -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 02:35:22 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 02:35:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Reserve_PEP_3156=2E?= Message-ID: <3YMHWt14YMzRXp@mail.python.org> http://hg.python.org/peps/rev/cc530679af46 changeset: 4599:cc530679af46 user: Guido van Rossum date: Wed Dec 12 17:35:17 2012 -0800 summary: Reserve PEP 3156. files: pep-3156.txt | 59 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt new file mode 100644 --- /dev/null +++ b/pep-3156.txt @@ -0,0 +1,59 @@ +PEP: 3156 +Title: Asynchronous IO Support Rebooted +Version: $Revision$ +Last-Modified: $Date$ +Author: Guido van Rossum +Status: Draft +Type: Standards Track +Content-Type: text/x-rst +Created: 12-Dec-2012 +Post-History: TBD + +Abstract +======== + +A concrete proposal for asynchronous I/O in Python 3, starting with +Python 3.3. Consider this the concrete proposal that is missing from +PEP 3153. The proposal includes a pluggable event loop API, transport +and protocol abstractions similar to those in Twisted, and a +higher-level scheduler based on yield-from (PEP 380). A reference +implementation is in the works under the code name tulip. + + +Introduction +============ + +TBD. I'm just committing this now to reserve the PEP number. (I am +using the 3000 range because this proposal is very closely tied to +Python 3, and to emphasise the connection with PEP 3153, which +provides the motivation but falls short of proposing concrete APIs.) + + +Acknowledgments +=============== + +Apart from PEP 3153, influences include PEP 380 and Greg Ewing's +tutorial for yield-from, Twisted, Tornado, ZeroMQ, pyftpdlib, tulip +(the author's attempts at synthesis of all these), wattle (Steve +Dower's counter-proposal), numerous discussions on python-ideas from +September through December 2012, a Skype session with Steve Dower and +Dino Viehland, email exchanges with Ben Darnell, and two in-person +meetings with several Twisted developers, including Glyph, Brian +Warner, David Reid, and Duncan McGreggor. + + +Copyright +========= + +This document has been placed in the public domain. + + + +.. + Local Variables: + mode: indented-text + indent-tabs-mode: nil + sentence-end-double-space: t + fill-column: 70 + coding: utf-8 + End: -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 13 03:30:37 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 03:30:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Added_an_introduction=2E?= Message-ID: <3YMJld1y3qzRqH@mail.python.org> http://hg.python.org/peps/rev/9432926b41dd changeset: 4600:9432926b41dd user: Guido van Rossum date: Wed Dec 12 18:30:32 2012 -0800 summary: Added an introduction. files: pep-3156.txt | 75 ++++++++++++++++++++++++++++++++++++--- 1 files changed, 68 insertions(+), 7 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -23,10 +23,70 @@ Introduction ============ -TBD. I'm just committing this now to reserve the PEP number. (I am -using the 3000 range because this proposal is very closely tied to -Python 3, and to emphasise the connection with PEP 3153, which -provides the motivation but falls short of proposing concrete APIs.) +The event loop is the place where most interoperability occurs. It +should be easy for (Python 3.3 ports of) frameworks like Twisted, +Tornado, or ZeroMQ to either adapt the default event loop +implementation to their needs using a lightweight wrapper or proxy, or +to replace the default event loop implementation with an adaptation of +their own event loop implementation. (Some frameworks, like Twisted, +have multiple event loop implementations. This should not be a +problem since these all have the same interface.) + +It should even be possible for two different third-party frameworks to +interoperate, either by sharing the default event loop implementation +(each using its own adapter), or by sharing the event loop +implementation of either framework. In the latter case two levels of +adaptation would occur (from framework A's event loop to the standard +event loop interface, and from there to framework B's event loop). +Which event loop implementation is used should be under control of the +main program (though a default policy for event loop selection is +provided). + +Thus, two separate APIs are defined: + +- getting and setting the current event loop object +- the interface of a conforming event loop and its minimum guarantees + +An event loop implementation may provide additional methods and +guarantees. + +The event loop interface does not depend on yield-from. Rather, it +uses a combination of callbacks, additional interfaces (transports and +protocols), and Futures. The latter are similar to those defined in +PEP 3148, but have a different implementation and are not tied to +threads. In particular, they have no wait() method; the user is +expected to use callbacks. + +For users (like myself) who don't like using callbacks, a scheduler is +provided for writing asynchronous I/O code as coroutines using the PEP +380 yield-from expressions. The scheduler is not pluggable; +pluggability occurs at the event loop level, and the scheduler should +work with any conforming event loop implementation. + +For interoperability between code written using coroutines and other +async frameworks, the scheduler has a Task class that behaves like a +Future. A framework that interoperates at the event loop level can +wait for a Future to complete by adding a callback to the Future. +Likewise, the scheduler offers an operation to suspend a coroutine +until a callback is called. + +Limited interoperability with threads is provided by the event loop +interface; there is an API to submit a function to an executor (see +PEP 3148) which returns a Future that is compatible with the event +loop. + + +Non-goals +========= + +Interoperability with systems like Stackless Python or +greenlets/gevent is not a goal of this PEP. + + +Specification +============= + +TBD. Acknowledgments @@ -37,9 +97,10 @@ (the author's attempts at synthesis of all these), wattle (Steve Dower's counter-proposal), numerous discussions on python-ideas from September through December 2012, a Skype session with Steve Dower and -Dino Viehland, email exchanges with Ben Darnell, and two in-person -meetings with several Twisted developers, including Glyph, Brian -Warner, David Reid, and Duncan McGreggor. +Dino Viehland, email exchanges with Ben Darnell, an audience with +Niels Provos (original author of libevent), and two in-person meetings +with several Twisted developers, including Glyph, Brian Warner, David +Reid, and Duncan McGreggor. Copyright -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 13 04:24:54 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 13 Dec 2012 04:24:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_expose_TCP=5FFASTOPEN_and_?= =?utf-8?q?MSG=5FFASTOPEN?= Message-ID: <3YMKyG14mkzRnn@mail.python.org> http://hg.python.org/cpython/rev/5435a9278028 changeset: 80834:5435a9278028 user: Benjamin Peterson date: Wed Dec 12 22:24:47 2012 -0500 summary: expose TCP_FASTOPEN and MSG_FASTOPEN files: Misc/NEWS | 3 +++ Modules/socketmodule.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -163,6 +163,9 @@ Library ------- +- Expose the TCP_FASTOPEN and MSG_FASTOPEN flags in socket when they're + available. + - Issue #15701: Add a .headers attribute to urllib.error.HTTPError. Patch contributed by Berker Peksag. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -5971,6 +5971,9 @@ #ifdef MSG_MCAST PyModule_AddIntConstant(m, "MSG_MCAST", MSG_MCAST); #endif +#ifdef MSG_FASTOPEN + PyModule_AddIntConstant(m, "MSG_FASTOPEN", MSG_FASTOPEN); +#endif /* Protocol level and numbers, usable for [gs]etsockopt */ #ifdef SOL_SOCKET @@ -6401,7 +6404,9 @@ #ifdef TCP_QUICKACK PyModule_AddIntConstant(m, "TCP_QUICKACK", TCP_QUICKACK); #endif - +#ifdef TCP_FASTOPEN + PyModule_AddIntConstant(m, "TCP_FASTOPEN", TCP_FASTOPEN); +#endif /* IPX options */ #ifdef IPX_TYPE -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 05:26:31 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 05:26:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_subsections_about_depende?= =?utf-8?q?ncies=2C_namespace_and_event_loop_policy=2E?= Message-ID: <3YMMKM2tTJzRq7@mail.python.org> http://hg.python.org/peps/rev/5736321433fc changeset: 4601:5736321433fc user: Guido van Rossum date: Wed Dec 12 20:26:20 2012 -0800 summary: Add subsections about dependencies, namespace and event loop policy. files: pep-3156.txt | 53 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 52 insertions(+), 1 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -12,7 +12,7 @@ Abstract ======== -A concrete proposal for asynchronous I/O in Python 3, starting with +This is a proposal for asynchronous I/O in Python 3, starting with Python 3.3. Consider this the concrete proposal that is missing from PEP 3153. The proposal includes a pluggable event loop API, transport and protocol abstractions similar to those in Twisted, and a @@ -86,6 +86,57 @@ Specification ============= +Dependencies +------------ + +Python 3.3 is required. No new language or standard library features +beyond Python 3.3 are required. No third-party modules or packages +are required. + +Module Namespace +---------------- + +The specification here will live in a new toplevel package. Different +components will live in separate submodules of that package. The +package will import common APIs from their respective submodules and +make them available as package attributes (similar to the way the +email package works). + +The name of the toplevel package is currently unspecified. The +reference implementation uses the name 'tulip', but the name will +change to something more boring if and when the implementation is +moved into the standard library (hopefully for Python 3.4). + +Until the boring name is chosen, this PEP will use 'tulip' as the +toplevel package name. Classes and functions given without a module +name are assumed to be accessed via the toplevel package. + +Getting and Setting the Event Loop +---------------------------------- + +To get the current event loop, use ``get_event_loop()``. This returns +an instance of the ``EventLoop`` class defined below or an equivalent +object. It is possible that ``get_event_loop()`` returns a different +object depending on the current thread, or depending on some other +notion of context. + +To set the current event loop, use ``set_event_loop(eventloop)``, +where ``eventloop`` is an instance of the ``EventLoop`` class or +equivalent. This uses the same notion of context as +``get_event_loop()``. + +To change the way ``get_event_loop()`` and ``set_event_loop()`` work +(including their notion of context), call +``set_event_loop_policy(policy)``, where ``policy`` is an event loop +policy object. The policy object can be any object that has methods +``get_event_loop()`` and ``set_event_loop(eventloop)`` behaving like +the functions described above. The default event loop policy is an +instance of the class ``EventLoopPolicy``. The current event loop +policy object can be retrieved by calling ``get_event_loop_policy()``. + +Event Loop Interface +-------------------- + TBD. -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Thu Dec 13 06:04:14 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 13 Dec 2012 06:04:14 +0100 Subject: [Python-checkins] Daily reference leaks (e680202e5603): sum=0 Message-ID: results for e680202e5603 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogFq4v7u', '-x'] From python-checkins at python.org Thu Dec 13 07:47:22 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 07:47:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_More_about_event_loops=2E?= Message-ID: <3YMQRt3mmSzMZh@mail.python.org> http://hg.python.org/peps/rev/88669a2eedd8 changeset: 4602:88669a2eedd8 user: Guido van Rossum date: Wed Dec 12 22:47:17 2012 -0800 summary: More about event loops. files: pep-3156.txt | 175 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 172 insertions(+), 3 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -111,8 +111,8 @@ toplevel package name. Classes and functions given without a module name are assumed to be accessed via the toplevel package. -Getting and Setting the Event Loop ----------------------------------- +Event Loop Policy: Getting and Setting the Event Loop +----------------------------------------------------- To get the current event loop, use ``get_event_loop()``. This returns an instance of the ``EventLoop`` class defined below or an equivalent @@ -131,14 +131,183 @@ policy object. The policy object can be any object that has methods ``get_event_loop()`` and ``set_event_loop(eventloop)`` behaving like the functions described above. The default event loop policy is an -instance of the class ``EventLoopPolicy``. The current event loop +instance of the class ``DefaultEventLoopPolicy``. The current event loop policy object can be retrieved by calling ``get_event_loop_policy()``. +An event loop policy may but does not have to enforce that there is +only one event loop in existence. The default event loop policy does +not enforce this, but it does enforce that there is only one event +loop per thread. + Event Loop Interface -------------------- +A conforming event loop object has the following methods: + +.. + Look for a better way to format method docs. PEP 12 doesn't + seem to have one. PEP 418 uses ^^^, which makes sub-headings. + +- ``run()``. Runs the event loop until there is nothing left to do. + This means, in particular: + + - No more calls scheduled with ``call_later()`` (except for canceled + calls). + + - No more registered file descriptors. It is up to the registering + party to unregister a file descriptor when it is closed. + +- ``call_later(when, callback, *args)``. Arrange for + ``callback(*args)`` to be called approximately ``when`` seconds in + the future, once, unless canceled. As usual in Python, ``when`` may + be a floating point number to represent smaller intervals. Returns + a ``DelayedCall`` object representing the callback, whose + ``cancel()`` method can be used to cancel the callback. + +- ``call_soon(callback, *args)``. Equivalent to ``call_later(0, + callback, *args)``. + +- ``call_soon_threadsafe(callback, *args)``. Like + ``call_soon(callback, *args)``, but when called from another thread + while the event loop is blocked waiting for I/O, unblocks the event + loop. This is the _only_ method that is safe to call from another + thread or from a signal handler. (To schedule a callback for a + later time in a threadsafe manner, you can use + ``ev.call_soon_threadsafe(ev.call_later, when, callback, *args)``.) + +- ``add_reader(fd, callback, *args)``. Arrange for + ``callback(*args)`` to be called whenever file descriptor ``fd`` is + ready for reading. Returns a ``DelayedCall`` object which can be + used to cancel the callback. Note that, unlike ``call_later()``, + the callback may be called many times. Calling ``add_reader()`` + again for the same file descriptor implicitly cancels the previous + callback for that file descriptor. + +- ``add_writer(fd, callback, *args)``. Like ``add_reader()``, + but registers the callback for writing instead of for reading. + +- ``remove_reader(fd)``. Cancels the current read callback for file + descriptor ``fd``, if one is set. A no-op if no callback is + currently set for the file descriptor. (The reason for providing + this alternate interface is that it is often more convenient to + remember the file descriptor than to remember the ``DelayedCall`` + object.) + +- ``remove_writer(fd)``. This is to ``add_writer()`` as + ``remove_reader()`` is to ``add_reader()``. + +- TBD: A method to submit a call to a PEP 3148 executor. Or a method + to wait for a PEP 3148 Future. Or both. + +- TBD: Methods that return ``Futures``, in particular to make a + connection and to set up a listener. + +Callback Sequencing +------------------- + +When two callbacks are scheduled for the same time, they are run +in the order in which they are registered. For example:: + + ev.call_soon(foo) + ev.call_soon(bar) + +guarantees that ``foo()`` is called before ``bar()``. + +If ``call_soon()`` is used, this guarantee is even true if the system +clock were to run backwards. This is also the case for +``call_later(0, callback, *args)``. However, if ``call_later()`` is +used with a nonzero ``when`` argument, all bets are off if the system +clock were to runs backwards. (A good event loop implementation +should use ``time.monotonic()`` to avoid problems when the clock runs +backward. See PEP 418.) + +Context +------- + +All event loops have a notion of context. For the default event loop +implementation, the context is a thread. An event loop implementation +should run all callbacks in the same context. An event loop +implementation should run only one callback at a time, so callbacks +can assume automatic mutual exclusion with other callbacks scheduled +in the same event loop. + +The DelayedCall Class +--------------------- + +TBD. (Only one method, ``cancel()``, and a read-only property, +``canceled``. Perhaps also ``callback`` and ``args`` properties.) + +Futures +------- + TBD. +Transports +---------- + +TBD. + +Protocols +--------- + +TBD. + +Coroutines and the Scheduler +---------------------------- + +TBD. + +Callback Style +-------------- + +Most interfaces taking a callback also take positional arguments. For +instance, to arrange for ``foo("abc", 42)`` to be called soon, you +call ``ev.call_soon(foo, "abc", 42)``. To schedule the call +``foo()``, use ``ev.call_soon(foo)``. This convention greatly reduces +the number of small lambdas required in typical callback programming. + +This convention specifically does _not_ support keyword arguments. +Keyword arguments are used to pass optional extra information about +the callback. This allows graceful evolution of the API without +having to worry about whether a keyword might be significant to a +callee somewhere. If you have a callback that _must_ be called with a +keyword argument, you can use a lambda or ``functools.partial``. For +example:: + + ev.call_soon(functools.partial(foo, "abc", repeat=42)) + +Choosing an Event Loop Implementation +------------------------------------- + +TBD. (This is about the choice to use e.g. select vs. poll vs. epoll, +and how to override the choice. Probably belongs in the event loop +policy.) + + +Open Issues +=========== + +- What have I missed that hasn't been marked with TBD yet? + +- A better name for ``DelayedCall`` (I really don't like adjectives. :-) + +- Do we need an API for stopping the event loop, given that we have + the termination condition? Is the termination condition compatible + with other frameworks? + +- Do we need an API to run the event loop for a little while? + +- Should we have ``future.add_callback(callback, *args)``, using the + convention from the section "Callback Style" above, or should we + stick with the PEP 3148 specification of + ``future.add_done_callback(callback)`` which calls + ``callback(future)``? (Glyph suggested using a different method + name since add_done_callback() does not guarantee that the callback + will be called in the right context.) + +- Do we need introspection APIs? E.g. asking for the read callback + given a file descriptor. + Acknowledgments =============== -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 13 08:03:38 2012 From: python-checkins at python.org (trent.nelson) Date: Thu, 13 Dec 2012 08:03:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSVJJWDogZm9yY2Ug?= =?utf-8?q?MIPSpro_to_treat_=23errors_as_errors=2C_not_warnings=2E?= Message-ID: <3YMQpf3tz9zRrC@mail.python.org> http://hg.python.org/cpython/rev/3e33e4e1c85b changeset: 80835:3e33e4e1c85b branch: 2.7 parent: 80818:6c8a7469670b user: Trent Nelson date: Thu Dec 13 06:46:39 2012 +0000 summary: IRIX: force MIPSpro to treat #errors as errors, not warnings. files: configure | 33 +++++++++++++++++++++++++++++++++ configure.ac | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 0 deletions(-) diff --git a/configure b/configure --- a/configure +++ b/configure @@ -3238,6 +3238,39 @@ (it is also a good idea to do 'make clean' before compiling)" "$LINENO" 5 fi +if test "$MACHDEP" = "irix6" && test "$CC" != "gcc"; then + # Normally, MIPSpro CC treats #error directives as warnings, which means + # a successful exit code is returned (0). This is a problem because IRIX + # has a bunch of system headers with this guard at the top: + # + # #ifndef __c99 + # #error This header file is to be used only for c99 mode compilations + # #else + # + # When autoconf tests for such a header, like stdint.h, this happens: + # + # configure:4619: cc -c conftest.c >&5 + # cc-1035 cc: WARNING File = /usr/include/stdint.h, Line = 5 + # #error directive: This header file is to be used only for c99 mode + # compilations + # + # #error This header file is to be used only for c99 mode compilations + # ^ + # + # configure:4619: $? = 0 + # configure:4619: result: yes + # + # Therefore, we use `-diag_error 1035` to have the compiler treat the + # warning as an error, which causes cc to return a non-zero result, + # which autoconf can interpret correctly. + CFLAGS="$CFLAGS -diag_error 1035" + # Whilst we're here, we might as well make sure CXX defaults to something + # sensible if we're not using gcc. + if test -z "$CXX"; then + CXX="CC" + fi +fi + # If the user set CFLAGS, use this instead of the automatically # determined setting preset_cflags="$CFLAGS" diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -507,6 +507,39 @@ (it is also a good idea to do 'make clean' before compiling)]) fi +if test "$MACHDEP" = "irix6" && test "$CC" != "gcc"; then + # Normally, MIPSpro CC treats #error directives as warnings, which means + # a successful exit code is returned (0). This is a problem because IRIX + # has a bunch of system headers with this guard at the top: + # + # #ifndef __c99 + # #error This header file is to be used only for c99 mode compilations + # #else + # + # When autoconf tests for such a header, like stdint.h, this happens: + # + # configure:4619: cc -c conftest.c >&5 + # cc-1035 cc: WARNING File = /usr/include/stdint.h, Line = 5 + # #error directive: This header file is to be used only for c99 mode + # compilations + # + # #error This header file is to be used only for c99 mode compilations + # ^ + # + # configure:4619: $? = 0 + # configure:4619: result: yes + # + # Therefore, we use `-diag_error 1035` to have the compiler treat the + # warning as an error, which causes cc to return a non-zero result, + # which autoconf can interpret correctly. + CFLAGS="$CFLAGS -diag_error 1035" + # Whilst we're here, we might as well make sure CXX defaults to something + # sensible if we're not using gcc. + if test -z "$CXX"; then + CXX="CC" + fi +fi + # If the user set CFLAGS, use this instead of the automatically # determined setting preset_cflags="$CFLAGS" -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 08:13:43 2012 From: python-checkins at python.org (trent.nelson) Date: Thu, 13 Dec 2012 08:13:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogTWFrZSBQeUFTVF9v?= =?utf-8?q?bj2mod_C89_compliant=2E?= Message-ID: <3YMR2H3rCzzRq7@mail.python.org> http://hg.python.org/cpython/rev/0cd6b8005890 changeset: 80836:0cd6b8005890 branch: 2.7 user: Trent Nelson date: Thu Dec 13 07:13:18 2012 +0000 summary: Make PyAST_obj2mod C89 compliant. files: Parser/asdl_c.py | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -1117,10 +1117,18 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) { mod_ty res; - PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, - (PyObject*)Interactive_type}; - char *req_name[] = {"Module", "Expression", "Interactive"}; + PyObject *req_type[3]; + char *req_name[3]; int isinstance; + + req_type[0] = (PyObject*)Module_type; + req_type[1] = (PyObject*)Expression_type; + req_type[2] = (PyObject*)Interactive_type; + + req_name[0] = "Module"; + req_name[1] = "Expression"; + req_name[2] = "Interactive"; + assert(0 <= mode && mode <= 2); init_types(); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 08:22:40 2012 From: python-checkins at python.org (trent.nelson) Date: Thu, 13 Dec 2012 08:22:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogTWFrZSBQeUFTVF9v?= =?utf-8?q?bj2mod_C89_compliant=2E__=28Follow-up_commit_from_asdl=5Fc=2Epy?= =?utf-8?b?Lik=?= Message-ID: <3YMRDc3G10zRs9@mail.python.org> http://hg.python.org/cpython/rev/a9341ce35abc changeset: 80837:a9341ce35abc branch: 2.7 user: Trent Nelson date: Thu Dec 13 07:22:16 2012 +0000 summary: Make PyAST_obj2mod C89 compliant. (Follow-up commit from asdl_c.py.) files: Python/Python-ast.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Python/Python-ast.c b/Python/Python-ast.c --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -6749,10 +6749,18 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) { mod_ty res; - PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type, - (PyObject*)Interactive_type}; - char *req_name[] = {"Module", "Expression", "Interactive"}; + PyObject *req_type[3]; + char *req_name[3]; int isinstance; + + req_type[0] = (PyObject*)Module_type; + req_type[1] = (PyObject*)Expression_type; + req_type[2] = (PyObject*)Interactive_type; + + req_name[0] = "Module"; + req_name[1] = "Expression"; + req_name[2] = "Interactive"; + assert(0 <= mode && mode <= 2); init_types(); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 16:24:56 2012 From: python-checkins at python.org (ross.lagerwall) Date: Thu, 13 Dec 2012 16:24:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NjYx?= =?utf-8?q?=3A_Fix_the_os=2Egetgrouplist=28=29_test_by_not_assuming_that_i?= =?utf-8?q?t?= Message-ID: <3YMdx42wYfzN5J@mail.python.org> http://hg.python.org/cpython/rev/ce85fe971e0a changeset: 80838:ce85fe971e0a branch: 3.3 parent: 80832:bdd4ec5eb621 user: Ross Lagerwall date: Thu Dec 13 15:20:26 2012 +0000 summary: Issue #16661: Fix the os.getgrouplist() test by not assuming that it gives the same output as "id -G". files: Lib/test/test_posix.py | 13 +++---------- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -647,17 +647,10 @@ @unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()") @unittest.skipUnless(hasattr(os, 'getuid'), "test needs os.getuid()") def test_getgrouplist(self): - with os.popen('id -G') as idg: - groups = idg.read().strip() - ret = idg.close() + user = pwd.getpwuid(os.getuid())[0] + group = pwd.getpwuid(os.getuid())[3] + self.assertIn(group, posix.getgrouplist(user, group)) - if ret is not None or not groups: - raise unittest.SkipTest("need working 'id -G'") - - self.assertEqual( - set([int(x) for x in groups.split()]), - set(posix.getgrouplist(pwd.getpwuid(os.getuid())[0], - pwd.getpwuid(os.getuid())[3]))) @unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()") def test_getgroups(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -301,6 +301,9 @@ - Issue #16559: Add more tests for the json module, including some from the official test suite at json.org. Patch by Serhiy Storchaka. +- Issue #16661: Fix the `os.getgrouplist()` test by not assuming that it gives + the same output as :command:`id -G`. + - Issue #16115: Add some tests for the executable argument to subprocess.Popen(). Initial patch by Kushal Das. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 16:24:57 2012 From: python-checkins at python.org (ross.lagerwall) Date: Thu, 13 Dec 2012 16:24:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E3_for_=2316661?= Message-ID: <3YMdx55gQZzRTW@mail.python.org> http://hg.python.org/cpython/rev/05a37954a30c changeset: 80839:05a37954a30c parent: 80834:5435a9278028 parent: 80838:ce85fe971e0a user: Ross Lagerwall date: Thu Dec 13 15:21:16 2012 +0000 summary: Merge with 3.3 for #16661 files: Lib/test/test_posix.py | 13 +++---------- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -647,17 +647,10 @@ @unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()") @unittest.skipUnless(hasattr(os, 'getuid'), "test needs os.getuid()") def test_getgrouplist(self): - with os.popen('id -G') as idg: - groups = idg.read().strip() - ret = idg.close() + user = pwd.getpwuid(os.getuid())[0] + group = pwd.getpwuid(os.getuid())[3] + self.assertIn(group, posix.getgrouplist(user, group)) - if ret is not None or not groups: - raise unittest.SkipTest("need working 'id -G'") - - self.assertEqual( - set([int(x) for x in groups.split()]), - set(posix.getgrouplist(pwd.getpwuid(os.getuid())[0], - pwd.getpwuid(os.getuid())[3]))) @unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()") def test_getgroups(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -455,6 +455,9 @@ - Issue #16559: Add more tests for the json module, including some from the official test suite at json.org. Patch by Serhiy Storchaka. +- Issue #16661: Fix the `os.getgrouplist()` test by not assuming that it gives + the same output as :command:`id -G`. + - Issue #16115: Add some tests for the executable argument to subprocess.Popen(). Initial patch by Kushal Das. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 16:54:14 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 16:54:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Make_fd_methods_optional=2E?= Message-ID: <3YMfZt3GvvzRb8@mail.python.org> http://hg.python.org/peps/rev/6594476717d5 changeset: 4603:6594476717d5 user: Guido van Rossum date: Thu Dec 13 07:54:08 2012 -0800 summary: Make fd methods optional. files: pep-3156.txt | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -175,6 +175,11 @@ later time in a threadsafe manner, you can use ``ev.call_soon_threadsafe(ev.call_later, when, callback, *args)``.) +The following methods for registering callbacks for file descriptors +are optional. The default implementation provides them but the user +normally doesn't use these directly -- they are used by the transport +implementations exclusively: + - ``add_reader(fd, callback, *args)``. Arrange for ``callback(*args)`` to be called whenever file descriptor ``fd`` is ready for reading. Returns a ``DelayedCall`` object which can be -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 13 18:09:46 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 13 Dec 2012 18:09:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316049=3A_add_abc?= =?utf-8?q?=2EABC_helper_class=2E?= Message-ID: <3YMhG258Y2zRRl@mail.python.org> http://hg.python.org/cpython/rev/9347869d1066 changeset: 80840:9347869d1066 user: Andrew Svetlov date: Thu Dec 13 19:09:33 2012 +0200 summary: Issue #16049: add abc.ABC helper class. Patch by Bruno Dupuis. files: Doc/library/abc.rst | 18 ++++++++++++++---- Lib/abc.py | 6 ++++++ Lib/test/test_abc.py | 13 +++++++++++++ Misc/NEWS | 3 +++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -12,9 +12,9 @@ -------------- This module provides the infrastructure for defining :term:`abstract base -classes ` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this -was added to Python. (See also :pep:`3141` and the :mod:`numbers` module -regarding a type hierarchy for numbers based on ABCs.) +classes ` (ABCs) in Python, as outlined in :pep:`3119`; +see the PEP for why this was added to Python. (See also :pep:`3141` and the +:mod:`numbers` module regarding a type hierarchy for numbers based on ABCs.) The :mod:`collections` module has some concrete classes that derive from ABCs; these can, of course, be further derived. In addition the @@ -23,7 +23,7 @@ hashable or a mapping. -This module provides the following class: +This module provides the following classes: .. class:: ABCMeta @@ -127,6 +127,16 @@ available as a method of ``Foo``, so it is provided separately. +.. class:: ABC + + A helper class that has :class:`ABCMeta` as metaclass. :class:`ABC` is the + standard class to inherit from in order to create an abstract base class, + avoiding sometimes confusing metaclass usage. + + Note that :class:`ABC` type is still :class:`ABCMeta`, therefore inheriting + from :class:`ABC` requires usual precautions regarding metaclasses usage + as multiple inheritance may lead to metaclass conflicts. + The :mod:`abc` module also provides the following decorators: .. decorator:: abstractmethod diff --git a/Lib/abc.py b/Lib/abc.py --- a/Lib/abc.py +++ b/Lib/abc.py @@ -226,3 +226,9 @@ # No dice; update negative cache cls._abc_negative_cache.add(subclass) return False + +class ABC(metaclass=ABCMeta): + """Helper class that provides a standard way to create an ABC using + inheritance. + """ + pass diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py --- a/Lib/test/test_abc.py +++ b/Lib/test/test_abc.py @@ -96,6 +96,19 @@ class TestABC(unittest.TestCase): + def test_ABC_helper(self): + # create an ABC using the helper class and perform basic checks + class C(abc.ABC): + @classmethod + @abc.abstractmethod + def foo(cls): return cls.__name__ + self.assertEqual(type(C), abc.ABCMeta) + self.assertRaises(TypeError, C) + class D(C): + @classmethod + def foo(cls): return super().foo() + self.assertEqual(D.foo(), 'D') + def test_abstractmethod_basics(self): @abc.abstractmethod def foo(self): pass diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -163,6 +163,9 @@ Library ------- +- Add abc.ABC class to use inheritance rather than a direct invocation of + ABCMeta metaclass. Patch by Bruno Dupuis. + - Expose the TCP_FASTOPEN and MSG_FASTOPEN flags in socket when they're available. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 13 19:30:46 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 19:30:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_optional_socket_calls_ret?= =?utf-8?q?urning_a_Future=2E__Some_TBD_rearrangements=2E?= Message-ID: <3YMk3V5r7fzNl2@mail.python.org> http://hg.python.org/peps/rev/5ad6b9863c21 changeset: 4604:5ad6b9863c21 user: Guido van Rossum date: Thu Dec 13 10:30:42 2012 -0800 summary: Add optional socket calls returning a Future. Some TBD rearrangements. files: pep-3156.txt | 76 +++++++++++++++++++++++++++++++-------- 1 files changed, 60 insertions(+), 16 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -157,6 +157,13 @@ - No more registered file descriptors. It is up to the registering party to unregister a file descriptor when it is closed. +- TBD: Do we need an API for stopping the event loop, given that we + have the termination condition? Is the termination condition + compatible with other frameworks? + +- TBD: Do we need an API to run the event loop for a little while + (e.g. a single iteration)? If so, exactly what should it do? + - ``call_later(when, callback, *args)``. Arrange for ``callback(*args)`` to be called approximately ``when`` seconds in the future, once, unless canceled. As usual in Python, ``when`` may @@ -176,9 +183,15 @@ ``ev.call_soon_threadsafe(ev.call_later, when, callback, *args)``.) The following methods for registering callbacks for file descriptors -are optional. The default implementation provides them but the user -normally doesn't use these directly -- they are used by the transport -implementations exclusively: +are optional. If they are not implemented, accessing the method +(without calling it) returns AttributeError. The default +implementation provides them but the user normally doesn't use these +directly -- they are used by the transport implementations +exclusively. Also, on Windows these may be present or not depending +on whether a select-based or IOCP-based event loop is used. These +take integer file descriptors only, not objects with a fileno() +method. The file descriptor should represent something pollable -- +i.e. no disk files. - ``add_reader(fd, callback, *args)``. Arrange for ``callback(*args)`` to be called whenever file descriptor ``fd`` is @@ -201,12 +214,41 @@ - ``remove_writer(fd)``. This is to ``add_writer()`` as ``remove_reader()`` is to ``add_reader()``. +The following methods for doing async I/O on sockets are optional. +They are alternative to the previous set of optional methods, intended +for transport implementations on Windows using IOCP (if the event loop +supports it). The socket argument has to be a non-blocking socket. + +- ``sock_recv(sock, n)``. Receive up to ``n`` bytes from socket + ``sock``. Returns a ``Future`` whose result on success will be a + bytes object on success. + +- ``sock_sendall(sock, data)``. Send bytes ``data`` to the socket + ``sock``. Returns a ``Future`` whose result on success will be + ``None``. (TBD: Is it better to emulate ``sendall()`` or ``send()`` + semantics?) + +- ``sock_connect(sock, address)``. Connect to the given address. + Returns a ``Future`` whose result on success will be ``None``. + +- ``sock_accept(sock)``. Accept a connection from a socket. The + socket must be in listening mode and bound to an address. Returns a + ``Future`` whose result on success will be a tuple ``(conn, peer)`` + where ``conn`` is a connected non-blocking socket and ``peer`` is + the peer address. + +Other TBD: + - TBD: A method to submit a call to a PEP 3148 executor. Or a method to wait for a PEP 3148 Future. Or both. - TBD: Methods that return ``Futures``, in particular to make a connection and to set up a listener. +- TBD: Do we need introspection APIs? E.g. asking for the read + callback given a file descriptor. Or when the next scheduled call + is. Or the list of file descriptors registered with callbacks. + Callback Sequencing ------------------- @@ -218,7 +260,7 @@ guarantees that ``foo()`` is called before ``bar()``. -If ``call_soon()`` is used, this guarantee is even true if the system +If ``call_soon()`` is used, this guarantee is true even if the system clock were to run backwards. This is also the case for ``call_later(0, callback, *args)``. However, if ``call_later()`` is used with a nonzero ``when`` argument, all bets are off if the system @@ -242,6 +284,8 @@ TBD. (Only one method, ``cancel()``, and a read-only property, ``canceled``. Perhaps also ``callback`` and ``args`` properties.) +TBD: Find a better name? + Futures ------- @@ -292,16 +336,6 @@ Open Issues =========== -- What have I missed that hasn't been marked with TBD yet? - -- A better name for ``DelayedCall`` (I really don't like adjectives. :-) - -- Do we need an API for stopping the event loop, given that we have - the termination condition? Is the termination condition compatible - with other frameworks? - -- Do we need an API to run the event loop for a little while? - - Should we have ``future.add_callback(callback, *args)``, using the convention from the section "Callback Style" above, or should we stick with the PEP 3148 specification of @@ -310,8 +344,18 @@ name since add_done_callback() does not guarantee that the callback will be called in the right context.) -- Do we need introspection APIs? E.g. asking for the read callback - given a file descriptor. +- Returning a Future is relatively expensive, and it is quite possible + that some types of calls _usually_ complete immediately + (e.g. writing small amounts of data to a socket). A trick used by + Richard Oudkerk in the tulip project's proactor branch makes calls + like recv() either return a regular result or _raise_ a Future. The + caller (likely a transport) must then write code like this:: + + try: + res = ev.sock_recv(sock, 8192) + except Future as f: + yield from sch.block_future(f) + res = f.result() Acknowledgments -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 13 20:05:58 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 20:05:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_some_event_loop_methods_r?= =?utf-8?q?eturning_Futures=2E__Lots_of_TBD=2E?= Message-ID: <3YMkr60PybzMTt@mail.python.org> http://hg.python.org/peps/rev/8d817ef8eadd changeset: 4605:8d817ef8eadd user: Guido van Rossum date: Thu Dec 13 11:05:52 2012 -0800 summary: Add some event loop methods returning Futures. Lots of TBD. files: pep-3156.txt | 63 ++++++++++++++++++++++++++++++++------- 1 files changed, 51 insertions(+), 12 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -147,6 +147,7 @@ .. Look for a better way to format method docs. PEP 12 doesn't seem to have one. PEP 418 uses ^^^, which makes sub-headings. + Also think of adding subheadings. - ``run()``. Runs the event loop until there is nothing left to do. This means, in particular: @@ -177,11 +178,53 @@ - ``call_soon_threadsafe(callback, *args)``. Like ``call_soon(callback, *args)``, but when called from another thread while the event loop is blocked waiting for I/O, unblocks the event - loop. This is the _only_ method that is safe to call from another + loop. This is the *only* method that is safe to call from another thread or from a signal handler. (To schedule a callback for a later time in a threadsafe manner, you can use ``ev.call_soon_threadsafe(ev.call_later, when, callback, *args)``.) +Some methods return Futures: + +- ``wrap_future(future)``. This takes a PEP 3148 Future (i.e., an + instance of ``concurrent.futures.Future``) and returns a Future + compatible with this event loop. + +- ``run_in_executor(executor, function, *args)``. Arrange to call + ``function(*args)`` in an executor (see PEP 3148). Returns a Future + whose result on success is the return value that call. This is + equivalent to ``wrap_future(executor.submit(function, *args))``. If + ``executor`` is ``None``, a default ``ThreadPoolExecutor`` with 5 + threads is used. (TBD: Should the default executor be shared + between different event loops? Should we even have a default + executor? Should be be able to set its thread count? Shoul we even + have this method?) + +- ``getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)``. + Similar to the ``socket.getaddrinfo()`` function but returns a + Future. The Future's result on success will be a list of the same + format as returned by ``socket.getaddrinfo()``. The default + implementation calls ``socket.getaddrinfo()`` using + ``run_in_executor()``, but other implementations may choose to + implement their own DNS lookup. + +- ``getnameinfo(sockaddr, flags)``. Similar to + ``socket.getnameinfo()`` but returns a Future. The Future's result + on success will be a tuple ``(host, port)``. Same implementation + remarks as for ``getaddrinfo()``. + +- ``create_transport(...)``. Creates a transport. Returns a Future. + TBD: Signature. Do we pass in a protocol or protocol class? + +- ``start_serving(...)``. Enters a loop that accepts connections. + TBD: Signature. This definitely takes a protocol class. Do we pass + in a non-blocking socket that's already bound and listening, or do + we pass in arguments that let it create and configure the socket + properly? (E.g. the event loop may know a better default backlog + value for ``listen()`` than the typical application developer.) + TBD: What does it return? Something we can use to stop accepting + without stopping the event loop? A Future that completes when the + socket is successfully accepting connections? + The following methods for registering callbacks for file descriptors are optional. If they are not implemented, accessing the method (without calling it) returns AttributeError. The default @@ -235,16 +278,12 @@ socket must be in listening mode and bound to an address. Returns a ``Future`` whose result on success will be a tuple ``(conn, peer)`` where ``conn`` is a connected non-blocking socket and ``peer`` is - the peer address. + the peer address. (TBD: People tell me that this style of API is + too slow for high-volume servers. So there's also + ``start_serving()`` above.) Other TBD: -- TBD: A method to submit a call to a PEP 3148 executor. Or a method - to wait for a PEP 3148 Future. Or both. - -- TBD: Methods that return ``Futures``, in particular to make a - connection and to set up a listener. - - TBD: Do we need introspection APIs? E.g. asking for the read callback given a file descriptor. Or when the next scheduled call is. Or the list of file descriptors registered with callbacks. @@ -315,11 +354,11 @@ ``foo()``, use ``ev.call_soon(foo)``. This convention greatly reduces the number of small lambdas required in typical callback programming. -This convention specifically does _not_ support keyword arguments. +This convention specifically does *not* support keyword arguments. Keyword arguments are used to pass optional extra information about the callback. This allows graceful evolution of the API without having to worry about whether a keyword might be significant to a -callee somewhere. If you have a callback that _must_ be called with a +callee somewhere. If you have a callback that *must* be called with a keyword argument, you can use a lambda or ``functools.partial``. For example:: @@ -345,10 +384,10 @@ will be called in the right context.) - Returning a Future is relatively expensive, and it is quite possible - that some types of calls _usually_ complete immediately + that some types of calls *usually* complete immediately (e.g. writing small amounts of data to a socket). A trick used by Richard Oudkerk in the tulip project's proactor branch makes calls - like recv() either return a regular result or _raise_ a Future. The + like recv() either return a regular result or *raise* a Future. The caller (likely a transport) must then write code like this:: try: -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 13 20:58:54 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 20:58:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Specify_Futures=2E_Minor_clea?= =?utf-8?q?nup=2E?= Message-ID: <3YMm1B1NKpzQ4V@mail.python.org> http://hg.python.org/peps/rev/c716fef27fa0 changeset: 4606:c716fef27fa0 user: Guido van Rossum date: Thu Dec 13 11:58:47 2012 -0800 summary: Specify Futures. Minor cleanup. files: pep-3156.txt | 111 ++++++++++++++++++++++++++++++++------ 1 files changed, 92 insertions(+), 19 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -145,9 +145,12 @@ A conforming event loop object has the following methods: .. - Look for a better way to format method docs. PEP 12 doesn't - seem to have one. PEP 418 uses ^^^, which makes sub-headings. - Also think of adding subheadings. + Look for a better way to format method docs. PEP 12 doesn't seem to + have one. PEP 418 uses ^^^, which makes sub-headings. PEP 3148 + uses a markup which generates rather heavy layout using blockquote, + causing a blank line between each method heading and its + description. Also think of adding subheadings for different + categories of methods. - ``run()``. Runs the event loop until there is nothing left to do. This means, in particular: @@ -183,11 +186,16 @@ later time in a threadsafe manner, you can use ``ev.call_soon_threadsafe(ev.call_later, when, callback, *args)``.) +- TBD: A way to register a callback that is already wrapped in a + ``DelayedCall``. Maybe ``call_soon()`` could just check + ``isinstance(callback, DelayedCall)``? It should silently skip + a canceled callback. + Some methods return Futures: - ``wrap_future(future)``. This takes a PEP 3148 Future (i.e., an instance of ``concurrent.futures.Future``) and returns a Future - compatible with this event loop. + compatible with the event loop (i.e., a ``tulip.Future`` instance). - ``run_in_executor(executor, function, *args)``. Arrange to call ``function(*args)`` in an executor (see PEP 3148). Returns a Future @@ -263,30 +271,24 @@ supports it). The socket argument has to be a non-blocking socket. - ``sock_recv(sock, n)``. Receive up to ``n`` bytes from socket - ``sock``. Returns a ``Future`` whose result on success will be a + ``sock``. Returns a Future whose result on success will be a bytes object on success. - ``sock_sendall(sock, data)``. Send bytes ``data`` to the socket - ``sock``. Returns a ``Future`` whose result on success will be + ``sock``. Returns a Future whose result on success will be ``None``. (TBD: Is it better to emulate ``sendall()`` or ``send()`` semantics?) - ``sock_connect(sock, address)``. Connect to the given address. - Returns a ``Future`` whose result on success will be ``None``. + Returns a Future whose result on success will be ``None``. - ``sock_accept(sock)``. Accept a connection from a socket. The socket must be in listening mode and bound to an address. Returns a - ``Future`` whose result on success will be a tuple ``(conn, peer)`` + Future whose result on success will be a tuple ``(conn, peer)`` where ``conn`` is a connected non-blocking socket and ``peer`` is the peer address. (TBD: People tell me that this style of API is too slow for high-volume servers. So there's also - ``start_serving()`` above.) - -Other TBD: - -- TBD: Do we need introspection APIs? E.g. asking for the read - callback given a file descriptor. Or when the next scheduled call - is. Or the list of file descriptors registered with callbacks. + ``start_serving()`` above. Then do we still need this?) Callback Sequencing ------------------- @@ -320,15 +322,76 @@ The DelayedCall Class --------------------- -TBD. (Only one method, ``cancel()``, and a read-only property, -``canceled``. Perhaps also ``callback`` and ``args`` properties.) +The various methods for registering callbacks (e.g. ``call_later()``) +all return an object representing the registration that can be used to +cancel the callback. For want of a better name this object is called +a ``DelayedCall``, although the user never needs to instantiate +instances of this class. There is one public method: -TBD: Find a better name? +- ``cancel()``. Attempt to cancel the callback. + +Read-only public attributes: + +- ``callback``. The callback function to be called. + +- ``args``. The argument tuple with which to call the callback function. + +- ``canceled``. True if ``cancel()`` has been called. + +Note that some callbacks (e.g. those registered with ``call_later()``) +are meant to be called only once. Others (e.g. those registered with +``add_reader()``) are meant to be called multiple times. + +TBD: An API to call the callback (encapsulating the exception handling +necessary)? Should it record how many times it has been called? +Maybe this API should just be ``__call__()``? (But it should suppress +exceptions.) + +TBD: Public attribute recording the realtime value when the callback +is scheduled? (Since this is needed anyway for storing it in a heap.) + +TBD: A better name for the class? Futures ------- -TBD. +The ``tulip.Future`` class here is intentionally similar to the +``concurrent.futures.Future`` class specified by PEP 3148, but there +are slight differences. The supported public API is as follows, +indicating the differences with PEP 3148: + +- ``cancel()``. + +- ``cancelled()``. + +- ``running()``. Note that the meaning of this method is essentially + "cannot be cancelled and isn't done yet". + +- ``done()``. + +- ``result()``. Difference with PEP 3148: This has no timeout + argument and does *not* wait; if the future is not yet done, it + raises an exception. + +- ``exception()``. Difference with PEP 3148: This has no timeout + argument and does *not* wait; if the future is not yet done, it + raises an exception. + +- ``add_done_callback(fn)``. Difference with PEP 3148: The callback + is never called immediately, and always in the context of the + caller. (Typically, a context is a thread.) You can think of this + as calling the callback through ``call_soon_threadsafe()``. Note + that the callback (unlike all other callbacks defined in this PEP) + is always called with a single argument, the Future object. + +The internal methods defined in PEP 3148 are not supported. + +A ``tulip.Future`` object is not acceptable to the ``wait()`` and +``as_completed()`` functions in the ``concurrent.futures`` package. + +A ``tulip.Future`` object is acceptable to a yield-from expression +when used in a coroutine. See the section "Coroutines and the +Scheduler" below. Transports ---------- @@ -375,6 +438,16 @@ Open Issues =========== +- How to spell the past tense of 'cancel'? American usage prefers + (though not absolutely dictates) 'canceled' (one ell), but outside + the US 'cancelled' (two ells) prevails. PEP 3148, whose author + currently lives in Australia, uses ``cancelled()`` as a method name + on its Future class. + +- Do we need introspection APIs? E.g. asking for the read callback + given a file descriptor. Or when the next scheduled call is. Or + the list of file descriptors registered with callbacks. + - Should we have ``future.add_callback(callback, *args)``, using the convention from the section "Callback Style" above, or should we stick with the PEP 3148 specification of -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 13 23:40:28 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 13 Dec 2012 23:40:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Transports_and_protocols=2E?= Message-ID: <3YMqbc6Xn6zRTy@mail.python.org> http://hg.python.org/peps/rev/3b447f846b36 changeset: 4607:3b447f846b36 user: Guido van Rossum date: Thu Dec 13 14:40:23 2012 -0800 summary: Transports and protocols. files: pep-3156.txt | 154 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 151 insertions(+), 3 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -319,6 +319,22 @@ can assume automatic mutual exclusion with other callbacks scheduled in the same event loop. +Exceptions +---------- + +There are two categories of exceptions in Python: those that derive +from the ``Exception`` class and those that derive from +``BaseException``. Exceptions deriving from ``Exception`` will +generally be caught and handled appropriately; for example, they will +be passed through by Futures, and they will be logged and ignored when +they occur in a callback. + +However, exceptions deriving only from ``BaseException`` are never +caught, and will usually cause the program to terminate with a +traceback. (Examples of this category include ``KeyboardInterrupt`` +and ``SystemExit``; it is usually unwise to treat these the same as +most other exceptions.) + The DelayedCall Class --------------------- @@ -381,7 +397,8 @@ is never called immediately, and always in the context of the caller. (Typically, a context is a thread.) You can think of this as calling the callback through ``call_soon_threadsafe()``. Note - that the callback (unlike all other callbacks defined in this PEP) + that the callback (unlike all other callbacks defined in this PEP, + and ignoring the convention from the section "Callback Style" below) is always called with a single argument, the Future object. The internal methods defined in PEP 3148 are not supported. @@ -396,12 +413,143 @@ Transports ---------- -TBD. +A transport is an abstraction on top of a socket or something similar +(for example, a UNIX pipe or an SSL connection). Transports are +strongly influenced by Twisted and PEP 3153. Users rarely implement +or instantiate transports -- rather, event loops offer utility methods +to set up transports. + +Transports work in conjunction with protocols. Protocols are +typically written without knowing or caring about the exact type of +transport used, and transports can be used with a wide variety of +protocols. For example, an HTTP client protocol implementation may be +used with either a plain socket transport or an SSL transport. The +plain socket transport can be used with many different protocols +besides HTTP (e.g. SMTP, IMAP, POP, FTP, IRC, SPDY). + +Most connections have an asymmetric nature: the client and server +usually have very different roles and behaviors. Hence, the interface +between transport and protocol is also asymmetric. From the +protocol's point of view, *writing* data is done by calling the +``write()`` method on the transport object; this buffers the data and +returns immediately. However, the transport takes a more active role +in *reading* data: whenever some data is read from the socket (or +other data source), the transport calls the protocol's +``data_received()`` method. + +Transports have the following public methods: + +- ``write(data)``. Write some bytes. The argument must be a bytes + object. Returns ``None``. The transport is free to buffer the + bytes, but it must eventually cause the bytes to be transferred to + the entity at the other end, and it must maintain stream behavior. + That is, ``t.write(b'abc'); t.write(b'def')`` is equivalent to + ``t.write(b'abcdef')``, as well as to:: + + t.write(b'a') + t.write(b'b') + t.write(b'c') + t.write(b'd') + t.write(b'e') + t.write(b'f') + + (TBD: What about datagram transports?) + +- ``writelines(iterable)``. Equivalent to:: + + for data in iterable: + self.write(data) + +- ``write_eof()``. Close the writing end of the connection. + Subsequent calls to ``write()`` are not allowed. Once all buffered + data is transferred, the transport signals to the other end that no + more data will be received. Some protocols don't support this + operation; in that case, calling ``write_eof()`` will raise an + exception. (Note: This used to be called ``half_close()``, but + unless you already know what it is for, that name doesn't indicate + *which* end is closed.) + +- ``can_write_eof()``. Return ``True`` if the protocol supports + ``write_eof()``, ``False`` if it does not. (This method is needed + because some protocols need to change their behavior when + ``write_eof()`` is unavailable. For example, in HTTP, to send data + whose size is not known ahead of time, the end of the data is + typically indicated using ``write_eof()``; however, SSL does not + support this, and an HTTP protocol implementation would have to use + the "chunked" transfer encoding in this case. But if the data size + is known ahead of time, the best approach in both cases is to use + the Content-Length header.) + +- ``pause()``. Suspend delivery of data to the protocol until a + subsequent ``resume()`` call. Between ``pause()`` and ``resume()``, + the protocol's ``data_received()`` method will not be called. This + has no effect on ``write()``. + +- ``resume()``. Restart delivery of data to the protocol via + ``data_received()``. + +- ``close()``. Sever the connection with the entity at the other end. + Any data buffered by ``write()`` will (eventually) be transferred + before the connection is actually closed. The protocol's + ``data_received()`` method will not be called again. Once all + buffered data has been flushed, the protocol's ``connection_lost()`` + method will be called with ``None`` as the argument. Note that + this method does not wait for all that to happen. + +- ``abort()``. Immediately sever the connection. Any data still + buffered by the transport is thrown away. Soon, the protocol's + ``connection_lost()`` method will be called with ``None`` as + argument. (TBD: Distinguish in the ``connection_lost()`` argument + between ``close()``, ``abort()`` or a close initated by the other + end? Or add a transport method to inquire about this? Glyph's + proposal was to pass different exceptions for this purpose.) + +TBD: Provide flow control the other way -- the transport may need to +suspend the protocol if the amount of data buffered becomes a burden. +One option: let the transport call ``protocol.pause()`` and +``protocol.resume()`` if they exist; if they don't exist, the protocol +doesn't support flow control. Protocols --------- -TBD. +Protocols are always used in conjunction with transports. While a few +common protocols are provided (e.g. decent though not necessary +excellent HTTP client and server implementations), most protocols will +be implemented by user code or third-party libraries. + +A protocol must implement the following methods, which will be called +by the transport. Consider these callbacks that are always called by +the event loop in the right context. (See the "Context" section +above.) + +- ``connection_made(transport)``. Indicates that the transport is + ready and connected to the entity at the other end. The protocol + should probably save the transport reference as an instance variable + (so it can call its ``write()`` and other methods later), and may + write an initial greeting or request at this point. + +- ``data_received(data)``. The transport has read some bytes from the + connection. The argument is always a non-empty bytes object. There + are no guarantees about the minimum or maximum size of the data + passed along this way. ``p.data_received(b'abcdef')`` should be + treated exactly equivalent to:: + + p.data_received(b'abc') + p.data_received(b'def') + + (TBD: What about datagram transports?) + +- ``connection_lost(exc)``. The transport has been closed or aborted, + has detected that the other end has closed the connection cleanly, + or has encountered an unexpected error. In the first three cases + the argument is ``None``; for an unexpected error, the argument is + the exception that caused the transport to give up. (TBD: Do we + need to distinguish between the first three cases?) + +TBD: How do we detect a half-close (``write_eof()`` in our parlance) +initiated by the other end? Does this call connection_lost()? Is the +protocol then allowed to write more? (I think it should be!) Coroutines and the Scheduler ---------------------------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Fri Dec 14 00:44:31 2012 From: python-checkins at python.org (philip.jenvey) Date: Fri, 14 Dec 2012 00:44:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_compile_doesn=27t_accept_c?= =?utf-8?q?ode_objects?= Message-ID: <3YMs1W5tNWzQH1@mail.python.org> http://hg.python.org/cpython/rev/76bc92fb90c1 changeset: 80841:76bc92fb90c1 user: Philip Jenvey date: Thu Dec 13 15:44:18 2012 -0800 summary: compile doesn't accept code objects files: Python/bltinmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -657,7 +657,7 @@ goto finally; } - str = source_as_string(cmd, "compile", "string, bytes, AST or code", &cf); + str = source_as_string(cmd, "compile", "string, bytes or AST", &cf); if (str == NULL) goto error; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 02:47:45 2012 From: python-checkins at python.org (guido.van.rossum) Date: Fri, 14 Dec 2012 02:47:45 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_section_on_coroutines_and?= =?utf-8?q?_the_scheduler=2E?= Message-ID: <3YMvlj1gXXzRW8@mail.python.org> http://hg.python.org/peps/rev/dcf4e647f4d2 changeset: 4608:dcf4e647f4d2 user: Guido van Rossum date: Thu Dec 13 17:47:40 2012 -0800 summary: Add section on coroutines and the scheduler. files: pep-3156.txt | 135 +++++++++++++++++++++++++++++++++++--- 1 files changed, 122 insertions(+), 13 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -16,7 +16,7 @@ Python 3.3. Consider this the concrete proposal that is missing from PEP 3153. The proposal includes a pluggable event loop API, transport and protocol abstractions similar to those in Twisted, and a -higher-level scheduler based on yield-from (PEP 380). A reference +higher-level scheduler based on ``yield from`` (PEP 380). A reference implementation is in the works under the code name tulip. @@ -50,7 +50,7 @@ An event loop implementation may provide additional methods and guarantees. -The event loop interface does not depend on yield-from. Rather, it +The event loop interface does not depend on ``yield from``. Rather, it uses a combination of callbacks, additional interfaces (transports and protocols), and Futures. The latter are similar to those defined in PEP 3148, but have a different implementation and are not tied to @@ -59,7 +59,7 @@ For users (like myself) who don't like using callbacks, a scheduler is provided for writing asynchronous I/O code as coroutines using the PEP -380 yield-from expressions. The scheduler is not pluggable; +380 ``yield from`` expressions. The scheduler is not pluggable; pluggability occurs at the event loop level, and the scheduler should work with any conforming event loop implementation. @@ -406,9 +406,10 @@ A ``tulip.Future`` object is not acceptable to the ``wait()`` and ``as_completed()`` functions in the ``concurrent.futures`` package. -A ``tulip.Future`` object is acceptable to a yield-from expression -when used in a coroutine. See the section "Coroutines and the -Scheduler" below. +A ``tulip.Future`` object is acceptable to a ``yield from`` expression +when used in a coroutine. This is implemented through the +``__iter__()`` interface on the Future. See the section "Coroutines +and the Scheduler" below. Transports ---------- @@ -551,11 +552,6 @@ initiated by the other end? Does this call connection_lost()? Is the protocol then allowed to write more? (I think it should be!) -Coroutines and the Scheduler ----------------------------- - -TBD. - Callback Style -------------- @@ -583,6 +579,106 @@ policy.) +Coroutines and the Scheduler +============================ + +This is a separate toplevel section because its status is different +from the event loop interface. Usage of coroutines is optional, and +it is perfectly fine to write code using callbacks only. On the other +hand, there is only one implementation of the scheduler/coroutine API, +and if you're using coroutines, that's the one you're using. + +A coroutine is a generator that follows certain conventions. For +documentation purposes, all coroutines should be decorated with +``@tulip.coroutine``, but this cannot be strictly enforced. + +Coroutines use the ``yield from`` syntax introduced in PEP 380, +instead of the original ``yield`` syntax. + +Unfortunately, the word "coroutine", like the word "generator", is +used for two different (though related) concepts: + +- The function that defines a coroutine (a function definition + decorated with ``tulip.coroutine``). If disambiguation is needed, + we call this a *coroutine function*. + +- The object obtained by calling a coroutine function. This object + represents a computation or an I/O operation (usually a combination) + that will complete eventually. For disambiguation we call it a + *coroutine object*. + +Things a coroutine can do: + +- ``result = yield from future`` -- suspends the coroutine until the + future is done, then returns the future's result, or raises its + exception, which will be propagated. + +- ``result = yield from coroutine`` -- wait for another coroutine to + produce a result (or raise an exception, which will be propagated). + The ``coroutine`` expression must be a *call* to another coroutine. + +- ``results = yield from tulip.par(futures_and_coroutines)`` -- Wait + for a list of futures and/or coroutines to complete and return a + list of their results. If one of the futures or coroutines raises + an exception, that exception is propagated, after attempting to + cancel all other futures and coroutines in the list. + +- ``return result`` -- produce a result to the coroutine that is + waiting for this one using ``yield from``. + +- ``raise exception`` -- raise an exception in the coroutine that is + waiting for this one using ``yield from``. + +Calling a coroutine does not start its code running -- it is just a +generator, and the coroutine object returned by the call is really a +generator object, which doesn't do anything until you iterate over it. +In the case of a coroutine object, there are two basic ways to start +it running: call ``yield from coroutine`` from another coroutine +(assuming the other coroutine is already running!), or convert it to a +Task. + +Coroutines can only run when the event loop is running. + +Tasks +----- + +A Task is an object that manages an independently running coroutine. +The Task interface is the same as the Future interface. The task +becomes done when its coroutine returns or raises an exception; if it +returns a result, that becomes the task's result, if it raises an +exception, that becomes the task's exception. + +Canceling a task that's not done yet prevents its coroutine from +completing; in this case an exception is thrown into the coroutine +that it may catch to further handle cancelation, but it doesn't have +to (this is done using the standard ``close()`` method on generators, +described in PEP 342). + +The ``par()`` function described above runs coroutines in parallel by +converting them to Tasks. (Arguments that are already Tasks or +Futures are not converted.) + +Tasks are also useful for interoperating between coroutines and +callback-based frameworks like Twisted. After converting a coroutine +into a Task, callbacks can be added to the Task. + +You may ask, why not convert all coroutines to Tasks? The +``@tulip.coroutine`` decorator could do this. This would slow things +down considerably in the case where one coroutine calls another (and +so on), as waiting for a "bare" coroutine has much less overhead than +waiting for a Future. + +The Scheduler +------------- + +The scheduler has no public interface. You interact with it by using +``yield from future`` and ``yield from task``. In fact, there is no +single object representing the scheduler -- its behavior is +implemented by the ``Task`` and ``Future`` classes using only the +public interface of the event loop, so it will work with third-party +event loop implementations, too. + + Open Issues =========== @@ -617,19 +713,32 @@ yield from sch.block_future(f) res = f.result() +- Do we need a larger vocabulary of operations for combining + coroutines and/or futures? E.g. in addition to par() we could have + a way to run several coroutines sequentially (returning all results + or passing the result of one to the next and returning the final + result?). We might also introduce explicit locks (though these will + be a bit of a pain to use, as we can't use the ``with lock: block`` + syntax). Anyway, I think all of these are easy enough to write + using ``Task``. + +- Priorities? + Acknowledgments =============== Apart from PEP 3153, influences include PEP 380 and Greg Ewing's -tutorial for yield-from, Twisted, Tornado, ZeroMQ, pyftpdlib, tulip +tutorial for ``yield from``, Twisted, Tornado, ZeroMQ, pyftpdlib, tulip (the author's attempts at synthesis of all these), wattle (Steve Dower's counter-proposal), numerous discussions on python-ideas from September through December 2012, a Skype session with Steve Dower and Dino Viehland, email exchanges with Ben Darnell, an audience with Niels Provos (original author of libevent), and two in-person meetings with several Twisted developers, including Glyph, Brian Warner, David -Reid, and Duncan McGreggor. +Reid, and Duncan McGreggor. Also, the author's previous work on async +support in the NDB library for Google App Engine was an important +influence. Copyright -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Fri Dec 14 05:58:52 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 14 Dec 2012 05:58:52 +0100 Subject: [Python-checkins] Daily reference leaks (76bc92fb90c1): sum=0 Message-ID: results for 76bc92fb90c1 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogKlHcMb', '-x'] From python-checkins at python.org Fri Dec 14 16:05:10 2012 From: python-checkins at python.org (andrew.svetlov) Date: Fri, 14 Dec 2012 16:05:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316421=3A_allow_to?= =?utf-8?q?_load_multiple_modules_from_the_same_shared_object=2E?= Message-ID: <3YNFRp5QhqzRZX@mail.python.org> http://hg.python.org/cpython/rev/6eefe4d537b3 changeset: 80842:6eefe4d537b3 user: Andrew Svetlov date: Fri Dec 14 17:04:59 2012 +0200 summary: Issue #16421: allow to load multiple modules from the same shared object. Patch by V?clav ?milauer. files: Lib/test/test_imp.py | 14 + Misc/ACKS | 1 + Misc/NEWS | 4 + Modules/_testimportmultiple.c | 57 + PC/VS9.0/_testimportmultiple.vcproj | 521 ++++++++++ PC/VS9.0/pcbuild.sln | 21 + PCbuild/_testimportmultiple.vcxproj | 218 ++++ PCbuild/_testimportmultiple.vcxproj.filters | 13 + PCbuild/pcbuild.sln | 18 + Python/import.c | 27 +- Tools/msi/msi.py | 1 + setup.py | 2 + 12 files changed, 887 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -217,6 +217,20 @@ mod = imp.load_module(example, *x) self.assertEqual(mod.__name__, example) + def test_issue16421_multiple_modules_in_one_dll(self): + # Issue 16421: loading several modules from the same compiled file fails + m = '_testimportmultiple' + fileobj, pathname, description = imp.find_module(m) + fileobj.close() + mod0 = imp.load_dynamic(m, pathname) + mod1 = imp.load_dynamic('foo', pathname) + mod2 = imp.load_dynamic('bar', pathname) + self.assertEqual(mod0.__name__, m) + self.assertEqual(mod1.__name__, 'foo') + self.assertEqual(mod2.__name__, 'bar') + with self.assertRaises(ImportError): + imp.load_dynamic('nonexistent', pathname) + def test_load_dynamic_ImportError_path(self): # Issue #1559549 added `name` and `path` attributes to ImportError # in order to provide better detail. Issue #10854 implemented those diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1109,6 +1109,7 @@ J. Sipprell Kragen Sitaker Michael Sloan +V?clav ?milauer Christopher Smith Eric V. Smith Gregory P. Smith diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16421: loading multiple modules from one shared object is now + handled correctly (previously, the first module loaded from that file + was silently returned). Patch by V?clav ?milauer. + - Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero. diff --git a/Modules/_testimportmultiple.c b/Modules/_testimportmultiple.c new file mode 100644 --- /dev/null +++ b/Modules/_testimportmultiple.c @@ -0,0 +1,57 @@ +/* + * C extensions module to test importing multiple modules from one compiled + * file (issue16421). This file defines 3 modules (_testimportmodule, + * foo, bar), only the first one is called the same as the compiled file. + */ +#include + +static struct PyModuleDef _testimportmultiple = { + PyModuleDef_HEAD_INIT, + "_testimportmultiple", + "_testimportmultiple doc", + -1, + NULL, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC PyInit__testimportmultiple() +{ + return PyModule_Create(&_testimportmultiple); +} + +static struct PyModuleDef _foomodule = { + PyModuleDef_HEAD_INIT, + "foo", + "foo doc", + -1, + NULL, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC PyInit_foo() +{ + return PyModule_Create(&_foomodule); +} + +static struct PyModuleDef _barmodule = { + PyModuleDef_HEAD_INIT, + "bar", + "bar doc", + -1, + NULL, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC PyInit_bar(){ + return PyModule_Create(&_barmodule); +} + diff --git a/PC/VS9.0/_testimportmultiple.vcproj b/PC/VS9.0/_testimportmultiple.vcproj new file mode 100644 --- /dev/null +++ b/PC/VS9.0/_testimportmultiple.vcproj @@ -0,0 +1,521 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PC/VS9.0/pcbuild.sln b/PC/VS9.0/pcbuild.sln --- a/PC/VS9.0/pcbuild.sln +++ b/PC/VS9.0/pcbuild.sln @@ -87,6 +87,11 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testimportmultiple", "_testimportmultiple.vcproj", "{36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}" + ProjectSection(ProjectDependencies) = postProject + {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_tkinter", "_tkinter.vcproj", "{4946ECAC-2E69-4BF8-A90A-F5136F5094DF}" ProjectSection(ProjectDependencies) = postProject {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} @@ -422,6 +427,22 @@ {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|Win32.Build.0 = Release|Win32 {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|x64.ActiveCfg = Release|x64 {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|x64.Build.0 = Release|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|Win32.ActiveCfg = Debug|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|Win32.Build.0 = Debug|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|x64.ActiveCfg = Debug|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|x64.Build.0 = Debug|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|Win32.ActiveCfg = Release|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|Win32.Build.0 = Release|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|x64.ActiveCfg = Release|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|x64.Build.0 = Release|x64 {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|Win32.ActiveCfg = Debug|Win32 {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|Win32.Build.0 = Debug|Win32 {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/PCbuild/_testimportmultiple.vcxproj b/PCbuild/_testimportmultiple.vcxproj new file mode 100644 --- /dev/null +++ b/PCbuild/_testimportmultiple.vcxproj @@ -0,0 +1,218 @@ +? + + + + Debug + Win32 + + + Debug + x64 + + + PGInstrument + Win32 + + + PGInstrument + x64 + + + PGUpdate + Win32 + + + PGUpdate + x64 + + + Release + Win32 + + + Release + x64 + + + + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781} + _testimportmultiple + Win32Proj + + + + DynamicLibrary + NotSet + true + + + DynamicLibrary + NotSet + true + + + DynamicLibrary + NotSet + true + + + DynamicLibrary + NotSet + + + DynamicLibrary + NotSet + true + + + DynamicLibrary + NotSet + true + + + DynamicLibrary + NotSet + true + + + DynamicLibrary + NotSet + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + AllRules.ruleset + + + + + + 0x1e1F0000 + + + + + X64 + + + 0x1e1F0000 + + + + + 0x1e1F0000 + + + + + X64 + + + 0x1e1F0000 + + + + + 0x1e1F0000 + + + + + X64 + + + 0x1e1F0000 + MachineX64 + + + + + 0x1e1F0000 + + + + + X64 + + + 0x1e1F0000 + MachineX64 + + + + + + + + {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} + false + + + + + + diff --git a/PCbuild/_testimportmultiple.vcxproj.filters b/PCbuild/_testimportmultiple.vcxproj.filters new file mode 100644 --- /dev/null +++ b/PCbuild/_testimportmultiple.vcxproj.filters @@ -0,0 +1,13 @@ +? + + + + {1ec38ad9-1abf-4b80-8628-ac43ccba324b} + + + + + Source Files + + + diff --git a/PCbuild/pcbuild.sln b/PCbuild/pcbuild.sln --- a/PCbuild/pcbuild.sln +++ b/PCbuild/pcbuild.sln @@ -38,6 +38,8 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testcapi", "_testcapi.vcxproj", "{6901D91C-6E48-4BB7-9FEC-700C8131DF1D}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_testimportmultiple", "_testimportmultiple.vcxproj", "{36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_tkinter", "_tkinter.vcxproj", "{4946ECAC-2E69-4BF8-A90A-F5136F5094DF}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "_bz2", "_bz2.vcxproj", "{73FCD2BD-F133-46B7-8EC1-144CD82A59D5}" @@ -344,6 +346,22 @@ {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|Win32.Build.0 = Release|Win32 {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|x64.ActiveCfg = Release|x64 {6901D91C-6E48-4BB7-9FEC-700C8131DF1D}.Release|x64.Build.0 = Release|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|Win32.ActiveCfg = Debug|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|Win32.Build.0 = Debug|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|x64.ActiveCfg = Debug|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Debug|x64.Build.0 = Debug|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|Win32.ActiveCfg = PGInstrument|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|Win32.Build.0 = PGInstrument|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|x64.ActiveCfg = PGInstrument|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGInstrument|x64.Build.0 = PGInstrument|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|x64.ActiveCfg = PGUpdate|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.PGUpdate|x64.Build.0 = PGUpdate|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|Win32.ActiveCfg = Release|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|Win32.Build.0 = Release|Win32 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|x64.ActiveCfg = Release|x64 + {36D0C52C-DF4E-45D0-8BC7-E294C3ABC781}.Release|x64.Build.0 = Release|x64 {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|Win32.ActiveCfg = Debug|Win32 {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|Win32.Build.0 = Debug|Win32 {4946ECAC-2E69-4BF8-A90A-F5136F5094DF}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -452,12 +452,12 @@ /* Magic for extension modules (built-in as well as dynamically loaded). To prevent initializing an extension module more than - once, we keep a static dictionary 'extensions' keyed by module name - (for built-in modules) or by filename (for dynamically loaded - modules), containing these modules. A copy of the module's - dictionary is stored by calling _PyImport_FixupExtensionObject() - immediately after the module initialization function succeeds. A - copy can be retrieved from there by calling + once, we keep a static dictionary 'extensions' keyed by the tuple + (module name, module name) (for built-in modules) or by + (filename, module name) (for dynamically loaded modules), containing these + modules. A copy of the module's dictionary is stored by calling + _PyImport_FixupExtensionObject() immediately after the module initialization + function succeeds. A copy can be retrieved from there by calling _PyImport_FindExtensionObject(). Modules which do support multiple initialization set their m_size @@ -470,7 +470,7 @@ _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name, PyObject *filename) { - PyObject *modules, *dict; + PyObject *modules, *dict, *filename_name; struct PyModuleDef *def; if (extensions == NULL) { extensions = PyDict_New(); @@ -508,7 +508,11 @@ if (def->m_base.m_copy == NULL) return -1; } - PyDict_SetItem(extensions, filename, (PyObject*)def); + filename_name = PyTuple_Pack(2,filename, name); + if (filename_name == NULL) + return -1; + if (PyDict_SetItem(extensions, filename_name, (PyObject*)def) < 0) + return -1; return 0; } @@ -528,11 +532,14 @@ PyObject * _PyImport_FindExtensionObject(PyObject *name, PyObject *filename) { - PyObject *mod, *mdict; + PyObject *mod, *mdict, *filename_name; PyModuleDef* def; if (extensions == NULL) return NULL; - def = (PyModuleDef*)PyDict_GetItem(extensions, filename); + filename_name = PyTuple_Pack(2,filename, name); + if (filename_name == NULL) + return NULL; + def = (PyModuleDef*)PyDict_GetItem(extensions, filename_name); if (def == NULL) return NULL; if (def->m_size == -1) { diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -101,6 +101,7 @@ '_decimal.pyd', '_testbuffer.pyd', '_sha3.pyd', + '_testimportmultiple.pyd', ] # Well-known component UUIDs diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -594,6 +594,8 @@ depends=['testcapi_long.h']) ) # Python PEP-3118 (buffer protocol) test module exts.append( Extension('_testbuffer', ['_testbuffer.c']) ) + # Test loading multiple modules from one compiled file (http://bugs.python.org/issue16421) + exts.append( Extension('_testimportmultiple', ['_testimportmultiple.c']) ) # profiler (_lsprof is for cProfile.py) exts.append( Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']) ) # static Unicode character database -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 17:02:39 2012 From: python-checkins at python.org (andrew.svetlov) Date: Fri, 14 Dec 2012 17:02:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Cleanup_filecmp=3A_startin?= =?utf-8?q?g_from_3=2E3_os=2Eerror_is_alias_for_OSError?= Message-ID: <3YNGk754qbzRSS@mail.python.org> http://hg.python.org/cpython/rev/091e68e08c3c changeset: 80843:091e68e08c3c user: Andrew Svetlov date: Fri Dec 14 18:02:27 2012 +0200 summary: Cleanup filecmp: starting from 3.3 os.error is alias for OSError files: Lib/filecmp.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/filecmp.py b/Lib/filecmp.py --- a/Lib/filecmp.py +++ b/Lib/filecmp.py @@ -147,12 +147,12 @@ ok = 1 try: a_stat = os.stat(a_path) - except os.error as why: + except OSError as why: # print('Can\'t stat', a_path, ':', why.args[1]) ok = 0 try: b_stat = os.stat(b_path) - except os.error as why: + except OSError as why: # print('Can\'t stat', b_path, ':', why.args[1]) ok = 0 @@ -268,7 +268,7 @@ def _cmp(a, b, sh, abs=abs, cmp=cmp): try: return not abs(cmp(a, b, sh)) - except os.error: + except OSError: return 2 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:13:25 2012 From: python-checkins at python.org (guido.van.rossum) Date: Fri, 14 Dec 2012 19:13:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Clarify_start=5Fserving=28=29?= =?utf-8?q?=2E__Add_a_section_on_coroutines_and_protocols=2E?= Message-ID: <3YNKd15ssXzQ2l@mail.python.org> http://hg.python.org/peps/rev/8d3145a2e7a9 changeset: 4609:8d3145a2e7a9 user: Guido van Rossum date: Fri Dec 14 10:13:20 2012 -0800 summary: Clarify start_serving(). Add a section on coroutines and protocols. files: pep-3156.txt | 65 ++++++++++++++++++++++++++++++++------- 1 files changed, 53 insertions(+), 12 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -224,14 +224,35 @@ TBD: Signature. Do we pass in a protocol or protocol class? - ``start_serving(...)``. Enters a loop that accepts connections. - TBD: Signature. This definitely takes a protocol class. Do we pass - in a non-blocking socket that's already bound and listening, or do - we pass in arguments that let it create and configure the socket - properly? (E.g. the event loop may know a better default backlog - value for ``listen()`` than the typical application developer.) - TBD: What does it return? Something we can use to stop accepting - without stopping the event loop? A Future that completes when the - socket is successfully accepting connections? + TBD: Signature. There are two possibilities: + + 1. You pass it a non-blocking socket that you have already prepared + with ``bind()`` and ``listen()`` (these system calls do not block + AFAIK), a protocol factory (I hesitate to use this word :-), and + optional flags that control the transport creation (e.g. ssl). + + 2. Instead of a socket, you pass it a host and port, and some more + optional flags (e.g. to control IPv4 vs IPv6, or to set the + backlog value to be passed to ``listen()``). + + In either case, once it has a socket, it will wrap it in a + transport, and then enter a loop accepting connections (the best way + to implement such a loop depends on the platform). Each time a + connection is accepted, a transport and protocol are created for it. + + This should return an object that can be used to control the serving + loop, e.g. to stop serving, abort all active connections, and (if + supported) adjust the backlog or other parameters. It may also have + an API to inquire about active connections. If version (2) is + selected, it should probably return a Future whose result on success + will be that control object, and which becomes done once the accept + loop is started. + + TBD: It may be best to use version (2), since on some platforms the + best way to start a server may not involve sockets (but will still + involve transports and protocols). + + TBD: Be more specific. The following methods for registering callbacks for file descriptors are optional. If they are not implemented, accessing the method @@ -515,7 +536,7 @@ --------- Protocols are always used in conjunction with transports. While a few -common protocols are provided (e.g. decent though not necessary +common protocols are provided (e.g. decent though not necessarily excellent HTTP client and server implementations), most protocols will be implemented by user code or third-party libraries. @@ -588,6 +609,9 @@ hand, there is only one implementation of the scheduler/coroutine API, and if you're using coroutines, that's the one you're using. +Coroutines +---------- + A coroutine is a generator that follows certain conventions. For documentation purposes, all coroutines should be decorated with ``@tulip.coroutine``, but this cannot be strictly enforced. @@ -595,8 +619,8 @@ Coroutines use the ``yield from`` syntax introduced in PEP 380, instead of the original ``yield`` syntax. -Unfortunately, the word "coroutine", like the word "generator", is -used for two different (though related) concepts: +The word "coroutine", like the word "generator", is used for two +different (though related) concepts: - The function that defines a coroutine (a function definition decorated with ``tulip.coroutine``). If disambiguation is needed, @@ -678,6 +702,23 @@ public interface of the event loop, so it will work with third-party event loop implementations, too. +Coroutines and Protocols +------------------------ + +The best way to use coroutines to implement protocols is probably to +use a streaming buffer that gets filled by ``data_received()`` and can +be read asynchronously using methods like ``read(n)`` and +``readline()`` that return a Future. When the connection is closed, +``read()`` should return a Future whose result is ``b''``, or raise an +exception if ``connection_closed()`` is called with an exception. + +To write, the ``write()`` method (and friends) on the transport can be +used -- these do not return Futures. A standard protocol +implementation should be provided that sets this up and kicks off the +coroutine when ``connection_made()`` is called. + +TBD: Be more specific. + Open Issues =========== @@ -722,7 +763,7 @@ syntax). Anyway, I think all of these are easy enough to write using ``Task``. -- Priorities? +- Task or callback priorities? (I hope not.) Acknowledgments -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Fri Dec 14 19:14:47 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:14:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NjgxOiB1c2Ug?= =?utf-8?q?=22bidirectional_class=22_instead_of_=22bidirectional_category?= =?utf-8?b?Ii4=?= Message-ID: <3YNKfb707LzRcS@mail.python.org> http://hg.python.org/cpython/rev/02de73bae814 changeset: 80844:02de73bae814 branch: 2.7 parent: 80837:a9341ce35abc user: Ezio Melotti date: Fri Dec 14 20:06:43 2012 +0200 summary: #16681: use "bidirectional class" instead of "bidirectional category". files: Doc/library/unicodedata.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst --- a/Doc/library/unicodedata.rst +++ b/Doc/library/unicodedata.rst @@ -66,7 +66,7 @@ .. function:: bidirectional(unichr) - Returns the bidirectional category assigned to the Unicode character *unichr* as + Returns the bidirectional class assigned to the Unicode character *unichr* as string. If no such value is defined, an empty string is returned. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:14:49 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:14:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2NjgxOiB1c2Ug?= =?utf-8?q?=22bidirectional_class=22_instead_of_=22bidirectional_category?= =?utf-8?b?Ii4=?= Message-ID: <3YNKfd2McCzQC3@mail.python.org> http://hg.python.org/cpython/rev/97688292bfe5 changeset: 80845:97688292bfe5 branch: 3.2 parent: 80825:88dcccb46298 user: Ezio Melotti date: Fri Dec 14 20:06:43 2012 +0200 summary: #16681: use "bidirectional class" instead of "bidirectional category". files: Doc/library/unicodedata.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst --- a/Doc/library/unicodedata.rst +++ b/Doc/library/unicodedata.rst @@ -66,7 +66,7 @@ .. function:: bidirectional(chr) - Returns the bidirectional category assigned to the character *chr* as + Returns the bidirectional class assigned to the character *chr* as string. If no such value is defined, an empty string is returned. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:14:50 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:14:50 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NjgxOiB1c2Ug?= =?utf-8?q?=22bidirectional_class=22_instead_of_=22bidirectional_category?= =?utf-8?q?=22_in_the?= Message-ID: <3YNKff4jylzRdB@mail.python.org> http://hg.python.org/cpython/rev/e9d59cca31fc changeset: 80846:e9d59cca31fc branch: 2.7 parent: 80844:02de73bae814 user: Ezio Melotti date: Fri Dec 14 20:12:25 2012 +0200 summary: #16681: use "bidirectional class" instead of "bidirectional category" in the docstring too. files: Modules/unicodedata.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -274,7 +274,7 @@ PyDoc_STRVAR(unicodedata_bidirectional__doc__, "bidirectional(unichr)\n\ \n\ -Returns the bidirectional category assigned to the Unicode character\n\ +Returns the bidirectional class assigned to the Unicode character\n\ unichr as string. If no such value is defined, an empty string is\n\ returned."); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:14:51 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:14:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2NjgxOiB1c2Ug?= =?utf-8?q?=22bidirectional_class=22_instead_of_=22bidirectional_category?= =?utf-8?q?=22_in_the?= Message-ID: <3YNKfg71pmzRcS@mail.python.org> http://hg.python.org/cpython/rev/f34d3ba955d1 changeset: 80847:f34d3ba955d1 branch: 3.2 parent: 80845:97688292bfe5 user: Ezio Melotti date: Fri Dec 14 20:12:25 2012 +0200 summary: #16681: use "bidirectional class" instead of "bidirectional category" in the docstring too. files: Modules/unicodedata.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -276,7 +276,7 @@ PyDoc_STRVAR(unicodedata_bidirectional__doc__, "bidirectional(unichr)\n\ \n\ -Returns the bidirectional category assigned to the Unicode character\n\ +Returns the bidirectional class assigned to the Unicode character\n\ unichr as string. If no such value is defined, an empty string is\n\ returned."); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:14:53 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:14:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2316681=3A_merge_with_3=2E2=2E?= Message-ID: <3YNKfj274YzRfh@mail.python.org> http://hg.python.org/cpython/rev/d8218745c24a changeset: 80848:d8218745c24a branch: 3.3 parent: 80838:ce85fe971e0a parent: 80847:f34d3ba955d1 user: Ezio Melotti date: Fri Dec 14 20:13:39 2012 +0200 summary: #16681: merge with 3.2. files: Doc/library/unicodedata.rst | 2 +- Modules/unicodedata.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst --- a/Doc/library/unicodedata.rst +++ b/Doc/library/unicodedata.rst @@ -69,7 +69,7 @@ .. function:: bidirectional(chr) - Returns the bidirectional category assigned to the character *chr* as + Returns the bidirectional class assigned to the character *chr* as string. If no such value is defined, an empty string is returned. diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -273,7 +273,7 @@ PyDoc_STRVAR(unicodedata_bidirectional__doc__, "bidirectional(unichr)\n\ \n\ -Returns the bidirectional category assigned to the Unicode character\n\ +Returns the bidirectional class assigned to the Unicode character\n\ unichr as string. If no such value is defined, an empty string is\n\ returned."); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:14:54 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:14:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogIzE2NjgxOiBtZXJnZSB3aXRoIDMuMy4=?= Message-ID: <3YNKfk4XPzzRdb@mail.python.org> http://hg.python.org/cpython/rev/39263bb0ef4c changeset: 80849:39263bb0ef4c parent: 80843:091e68e08c3c parent: 80848:d8218745c24a user: Ezio Melotti date: Fri Dec 14 20:14:17 2012 +0200 summary: #16681: merge with 3.3. files: Doc/library/unicodedata.rst | 2 +- Modules/unicodedata.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst --- a/Doc/library/unicodedata.rst +++ b/Doc/library/unicodedata.rst @@ -69,7 +69,7 @@ .. function:: bidirectional(chr) - Returns the bidirectional category assigned to the character *chr* as + Returns the bidirectional class assigned to the character *chr* as string. If no such value is defined, an empty string is returned. diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -273,7 +273,7 @@ PyDoc_STRVAR(unicodedata_bidirectional__doc__, "bidirectional(unichr)\n\ \n\ -Returns the bidirectional category assigned to the Unicode character\n\ +Returns the bidirectional class assigned to the Unicode character\n\ unichr as string. If no such value is defined, an empty string is\n\ returned."); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:20:25 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:20:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NjgzOiByZXN0?= =?utf-8?q?ore_alphabetical_order_in_audioop_docs=2E__Patch_by_Serhiy_Stor?= =?utf-8?q?chaka=2E?= Message-ID: <3YNKn54JfzzNjb@mail.python.org> http://hg.python.org/cpython/rev/e451901e6243 changeset: 80850:e451901e6243 branch: 2.7 parent: 80846:e9d59cca31fc user: Ezio Melotti date: Fri Dec 14 20:18:46 2012 +0200 summary: #16683: restore alphabetical order in audioop docs. Patch by Serhiy Storchaka. files: Doc/library/audioop.rst | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/audioop.rst b/Doc/library/audioop.rst --- a/Doc/library/audioop.rst +++ b/Doc/library/audioop.rst @@ -162,22 +162,22 @@ hardware, among others. +.. function:: max(fragment, width) + + Return the maximum of the *absolute value* of all samples in a fragment. + + +.. function:: maxpp(fragment, width) + + Return the maximum peak-peak value in the sound fragment. + + .. function:: minmax(fragment, width) Return a tuple consisting of the minimum and maximum values of all samples in the sound fragment. -.. function:: max(fragment, width) - - Return the maximum of the *absolute value* of all samples in a fragment. - - -.. function:: maxpp(fragment, width) - - Return the maximum peak-peak value in the sound fragment. - - .. function:: mul(fragment, width, factor) Return a fragment that has all samples in the original fragment multiplied by -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:20:26 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:20:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2NjgzOiByZXN0?= =?utf-8?q?ore_alphabetical_order_in_audioop_docs=2E__Patch_by_Serhiy_Stor?= =?utf-8?q?chaka=2E?= Message-ID: <3YNKn66vjMzQC3@mail.python.org> http://hg.python.org/cpython/rev/5777ac884919 changeset: 80851:5777ac884919 branch: 3.2 parent: 80847:f34d3ba955d1 user: Ezio Melotti date: Fri Dec 14 20:18:46 2012 +0200 summary: #16683: restore alphabetical order in audioop docs. Patch by Serhiy Storchaka. files: Doc/library/audioop.rst | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/audioop.rst b/Doc/library/audioop.rst --- a/Doc/library/audioop.rst +++ b/Doc/library/audioop.rst @@ -156,22 +156,22 @@ hardware, among others. +.. function:: max(fragment, width) + + Return the maximum of the *absolute value* of all samples in a fragment. + + +.. function:: maxpp(fragment, width) + + Return the maximum peak-peak value in the sound fragment. + + .. function:: minmax(fragment, width) Return a tuple consisting of the minimum and maximum values of all samples in the sound fragment. -.. function:: max(fragment, width) - - Return the maximum of the *absolute value* of all samples in a fragment. - - -.. function:: maxpp(fragment, width) - - Return the maximum peak-peak value in the sound fragment. - - .. function:: mul(fragment, width, factor) Return a fragment that has all samples in the original fragment multiplied by -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:20:28 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:20:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2316683=3A_merge_with_3=2E2=2E?= Message-ID: <3YNKn828KJzRb2@mail.python.org> http://hg.python.org/cpython/rev/a1ffb6c68711 changeset: 80852:a1ffb6c68711 branch: 3.3 parent: 80848:d8218745c24a parent: 80851:5777ac884919 user: Ezio Melotti date: Fri Dec 14 20:19:49 2012 +0200 summary: #16683: merge with 3.2. files: Doc/library/audioop.rst | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/audioop.rst b/Doc/library/audioop.rst --- a/Doc/library/audioop.rst +++ b/Doc/library/audioop.rst @@ -156,22 +156,22 @@ hardware, among others. +.. function:: max(fragment, width) + + Return the maximum of the *absolute value* of all samples in a fragment. + + +.. function:: maxpp(fragment, width) + + Return the maximum peak-peak value in the sound fragment. + + .. function:: minmax(fragment, width) Return a tuple consisting of the minimum and maximum values of all samples in the sound fragment. -.. function:: max(fragment, width) - - Return the maximum of the *absolute value* of all samples in a fragment. - - -.. function:: maxpp(fragment, width) - - Return the maximum peak-peak value in the sound fragment. - - .. function:: mul(fragment, width, factor) Return a fragment that has all samples in the original fragment multiplied by -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 14 19:20:29 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 14 Dec 2012 19:20:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogIzE2NjgzOiBtZXJnZSB3aXRoIDMuMy4=?= Message-ID: <3YNKn9598dzQKH@mail.python.org> http://hg.python.org/cpython/rev/f32f67d26035 changeset: 80853:f32f67d26035 parent: 80849:39263bb0ef4c parent: 80852:a1ffb6c68711 user: Ezio Melotti date: Fri Dec 14 20:20:07 2012 +0200 summary: #16683: merge with 3.3. files: Doc/library/audioop.rst | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/audioop.rst b/Doc/library/audioop.rst --- a/Doc/library/audioop.rst +++ b/Doc/library/audioop.rst @@ -156,22 +156,22 @@ hardware, among others. +.. function:: max(fragment, width) + + Return the maximum of the *absolute value* of all samples in a fragment. + + +.. function:: maxpp(fragment, width) + + Return the maximum peak-peak value in the sound fragment. + + .. function:: minmax(fragment, width) Return a tuple consisting of the minimum and maximum values of all samples in the sound fragment. -.. function:: max(fragment, width) - - Return the maximum of the *absolute value* of all samples in a fragment. - - -.. function:: maxpp(fragment, width) - - Return the maximum peak-peak value in the sound fragment. - - .. function:: mul(fragment, width, factor) Return a fragment that has all samples in the original fragment multiplied by -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 00:36:32 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 15 Dec 2012 00:36:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Sprinkle_some_clarifications_?= =?utf-8?q?and_TBDs_in_response_to_some_private_feedback=2E?= Message-ID: <3YNSnr60t8zQWK@mail.python.org> http://hg.python.org/peps/rev/fb179e83d0f6 changeset: 4610:fb179e83d0f6 user: Guido van Rossum date: Fri Dec 14 11:39:26 2012 -0800 summary: Sprinkle some clarifications and TBDs in response to some private feedback. files: pep-3156.txt | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -161,6 +161,10 @@ - No more registered file descriptors. It is up to the registering party to unregister a file descriptor when it is closed. + Note: run() blocks until the termination condition is met. + + TBD: run() may need an argument to start some work. + - TBD: Do we need an API for stopping the event loop, given that we have the termination condition? Is the termination condition compatible with other frameworks? @@ -191,7 +195,7 @@ ``isinstance(callback, DelayedCall)``? It should silently skip a canceled callback. -Some methods return Futures: +Some methods in the standard conforming interface return Futures: - ``wrap_future(future)``. This takes a PEP 3148 Future (i.e., an instance of ``concurrent.futures.Future``) and returns a Future @@ -254,6 +258,10 @@ TBD: Be more specific. +TBD: Some platforms may not be interested in implementing all of +these, e.g. start_serving() may be of no interest to mobile apps. +(Although, there's a Minecraft server on my iPad...) + The following methods for registering callbacks for file descriptors are optional. If they are not implemented, accessing the method (without calling it) returns AttributeError. The default @@ -366,6 +374,7 @@ instances of this class. There is one public method: - ``cancel()``. Attempt to cancel the callback. + TBD: Exact specification. Read-only public attributes: @@ -398,6 +407,7 @@ indicating the differences with PEP 3148: - ``cancel()``. + TBD: Exact specification. - ``cancelled()``. @@ -432,6 +442,16 @@ ``__iter__()`` interface on the Future. See the section "Coroutines and the Scheduler" below. +In the future (pun intended) we may unify ``tulip.Future`` and +``concurrent.futures.Future``, e.g. by adding an ``__iter__()`` method +to the latter that works with ``yield from``. To prevent accidentally +blocking the event loop by calling e.g. ``result()`` on a Future +that's not don yet, the blocking operation may detect that an event +loop is active in the current thread and raise an exception instead. +However the current PEP strives to have no dependencies beyond Python +3.3, so changes to ``concurrent.futures.Future`` are off the table for +now. + Transports ---------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 15 00:36:34 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 15 Dec 2012 00:36:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_Protocol=2Eeof=5Freceived?= =?utf-8?q?=28=29_and_protocol_call_sequence_chart=2E?= Message-ID: <3YNSnt1LbzzQh6@mail.python.org> http://hg.python.org/peps/rev/01dd5725807e changeset: 4611:01dd5725807e user: Guido van Rossum date: Fri Dec 14 15:36:20 2012 -0800 summary: Add Protocol.eof_received() and protocol call sequence chart. files: pep-3156.txt | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -582,6 +582,11 @@ (TBD: What about datagram transports?) +- ``eof_received()``. This is called when the other end called + ``write_eof()`` (or something equivalent). The default + implementation calls ``close()`` on the transport, which causes + ``connection_lost()`` to be called (eventually) on the protocol. + - ``connection_lost(exc)``. The transport has been closed or aborted, has detected that the other end has closed the connection cleanly, or has encountered an unexpected error. In the first three cases @@ -589,9 +594,15 @@ the exception that caused the transport to give up. (TBD: Do we need to distinguish between the first three cases?) -TBD: How do we detect a half-close (``write_eof()`` in our parlance) -initiated by the other end? Does this call connection_lost()? Is the -protocol then allowed to write more? (I think it should be!) +Here is a chart indicating the order and multiplicity of calls: + + 1. ``connection_made()`` -- exactly once + 2. ``data_received()`` -- zero or more times + 3. ``eof_received()`` -- at most once + 4. ``connection_lost()`` -- exactly once + +TBD: Discuss whether user code needs to do anything to make sure that +protocol and transport aren't garbage-collected prematurely. Callback Style -------------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 15 00:49:34 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 15 Dec 2012 00:49:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Slight_wording_change_suggest?= =?utf-8?q?ed_by_Steve_Dower=2E?= Message-ID: <3YNT4t5B7zzQjN@mail.python.org> http://hg.python.org/peps/rev/c0a1b22c92ab changeset: 4612:c0a1b22c92ab user: Guido van Rossum date: Fri Dec 14 15:49:29 2012 -0800 summary: Slight wording change suggested by Steve Dower. files: pep-3156.txt | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -154,7 +154,7 @@ - ``run()``. Runs the event loop until there is nothing left to do. This means, in particular: - + - No more calls scheduled with ``call_later()`` (except for canceled calls). @@ -720,8 +720,8 @@ You may ask, why not convert all coroutines to Tasks? The ``@tulip.coroutine`` decorator could do this. This would slow things down considerably in the case where one coroutine calls another (and -so on), as waiting for a "bare" coroutine has much less overhead than -waiting for a Future. +so on), as switching to a "bare" coroutine has much less overhead than +switching to a Task. The Scheduler ------------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 15 05:09:53 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 15 Dec 2012 05:09:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_TBD_about_cancellation=2E?= Message-ID: <3YNZsF3kVXzRPk@mail.python.org> http://hg.python.org/peps/rev/d68ee9af89e3 changeset: 4613:d68ee9af89e3 user: Guido van Rossum date: Fri Dec 14 20:09:48 2012 -0800 summary: Add TBD about cancellation. files: pep-3156.txt | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -750,6 +750,14 @@ TBD: Be more specific. +Cancellation +------------ + +TBD. When a Task is canceled its coroutine may see an exception at +any point where it is yielding to the scheduler (i.e., potentially at +any ``yield from`` operation). We need to spell out which exception +is raised. + Open Issues =========== @@ -758,7 +766,8 @@ (though not absolutely dictates) 'canceled' (one ell), but outside the US 'cancelled' (two ells) prevails. PEP 3148, whose author currently lives in Australia, uses ``cancelled()`` as a method name - on its Future class. + on its Future class. Also, even in the US, 'cancellation' seems + to be preferred over cancelation. - Do we need introspection APIs? E.g. asking for the read callback given a file descriptor. Or when the next scheduled call is. Or -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Sat Dec 15 06:00:14 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 15 Dec 2012 06:00:14 +0100 Subject: [Python-checkins] Daily reference leaks (f32f67d26035): sum=590 Message-ID: results for f32f67d26035 on branch "default" -------------------------------------------- test_capi leaked [63, 63, 63] references, sum=189 test_capi leaked [29, 31, 31] memory blocks, sum=91 test_imp leaked [30, 30, 30] references, sum=90 test_imp leaked [14, 16, 16] memory blocks, sum=46 test_importhooks leaked [3, 3, 3] references, sum=9 test_importhooks leaked [1, 3, 3] memory blocks, sum=7 test_importlib leaked [30, 30, 30] references, sum=90 test_importlib leaked [10, 12, 12] memory blocks, sum=34 test_site leaked [6, 6, 6] references, sum=18 test_site leaked [4, 6, 6] memory blocks, sum=16 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogr6uOe1', '-x'] From python-checkins at python.org Sat Dec 15 06:05:25 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 15 Dec 2012 06:05:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_cleanup_and_fix_refleaks?= Message-ID: <3YNc5K4JhpzNk4@mail.python.org> http://hg.python.org/cpython/rev/4c8d756196a4 changeset: 80854:4c8d756196a4 user: Benjamin Peterson date: Sat Dec 15 00:05:16 2012 -0500 summary: cleanup and fix refleaks files: Python/import.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -470,8 +470,9 @@ _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name, PyObject *filename) { - PyObject *modules, *dict, *filename_name; + PyObject *modules, *dict, *key; struct PyModuleDef *def; + int res; if (extensions == NULL) { extensions = PyDict_New(); if (extensions == NULL) @@ -508,10 +509,12 @@ if (def->m_base.m_copy == NULL) return -1; } - filename_name = PyTuple_Pack(2,filename, name); - if (filename_name == NULL) + key = PyTuple_Pack(2, filename, name); + if (key == NULL) return -1; - if (PyDict_SetItem(extensions, filename_name, (PyObject*)def) < 0) + res = PyDict_SetItem(extensions, key, (PyObject *)def); + Py_DECREF(key); + if (res < 0) return -1; return 0; } @@ -532,14 +535,15 @@ PyObject * _PyImport_FindExtensionObject(PyObject *name, PyObject *filename) { - PyObject *mod, *mdict, *filename_name; + PyObject *mod, *mdict, *key; PyModuleDef* def; if (extensions == NULL) return NULL; - filename_name = PyTuple_Pack(2,filename, name); - if (filename_name == NULL) + key = PyTuple_Pack(2, filename, name); + if (key == NULL) return NULL; - def = (PyModuleDef*)PyDict_GetItem(extensions, filename_name); + def = (PyModuleDef *)PyDict_GetItem(extensions, key); + Py_DECREF(key); if (def == NULL) return NULL; if (def->m_size == -1) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 06:05:28 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 15 Dec 2012 06:05:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_TBD_about_the_=28un=29des?= =?utf-8?q?irability_of_optional_APIs=2E?= Message-ID: <3YNc5N3qclzRV4@mail.python.org> http://hg.python.org/peps/rev/7ea848150df7 changeset: 4614:7ea848150df7 user: Guido van Rossum date: Fri Dec 14 21:05:22 2012 -0800 summary: Add TBD about the (un)desirability of optional APIs. files: pep-3156.txt | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -319,6 +319,10 @@ too slow for high-volume servers. So there's also ``start_serving()`` above. Then do we still need this?) +TBD: Optional methods are not so good. Perhaps these should be +required? It may still depend on the platform which set is more +efficient. + Callback Sequencing ------------------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 15 16:23:11 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 15 Dec 2012 16:23:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Rename_test_module_names_f?= =?utf-8?q?or_=2316421_to_don=27t_clash_with_other_tests=2E?= Message-ID: <3YNsp739Z0zRcp@mail.python.org> http://hg.python.org/cpython/rev/2e492a9a1845 changeset: 80855:2e492a9a1845 user: Andrew Svetlov date: Sat Dec 15 17:22:59 2012 +0200 summary: Rename test module names for #16421 to don't clash with other tests. files: Lib/test/test_imp.py | 8 ++++---- Modules/_testimportmultiple.c | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -223,11 +223,11 @@ fileobj, pathname, description = imp.find_module(m) fileobj.close() mod0 = imp.load_dynamic(m, pathname) - mod1 = imp.load_dynamic('foo', pathname) - mod2 = imp.load_dynamic('bar', pathname) + mod1 = imp.load_dynamic('_testimportmultiple_foo', pathname) + mod2 = imp.load_dynamic('_testimportmultiple_bar', pathname) self.assertEqual(mod0.__name__, m) - self.assertEqual(mod1.__name__, 'foo') - self.assertEqual(mod2.__name__, 'bar') + self.assertEqual(mod1.__name__, '_testimportmultiple_foo') + self.assertEqual(mod2.__name__, '_testimportmultiple_bar') with self.assertRaises(ImportError): imp.load_dynamic('nonexistent', pathname) diff --git a/Modules/_testimportmultiple.c b/Modules/_testimportmultiple.c --- a/Modules/_testimportmultiple.c +++ b/Modules/_testimportmultiple.c @@ -24,8 +24,8 @@ static struct PyModuleDef _foomodule = { PyModuleDef_HEAD_INIT, - "foo", - "foo doc", + "_testimportmultiple_foo", + "_testimportmultiple_foo doc", -1, NULL, NULL, @@ -34,15 +34,15 @@ NULL }; -PyMODINIT_FUNC PyInit_foo() +PyMODINIT_FUNC PyInit__testimportmultiple_foo() { return PyModule_Create(&_foomodule); } static struct PyModuleDef _barmodule = { PyModuleDef_HEAD_INIT, - "bar", - "bar doc", + "_testimportmultiple_bar", + "_testimportmultiple_bar doc", -1, NULL, NULL, @@ -51,7 +51,7 @@ NULL }; -PyMODINIT_FUNC PyInit_bar(){ +PyMODINIT_FUNC PyInit__testimportmultiple_bar(){ return PyModule_Create(&_barmodule); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 17:17:19 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 15 Dec 2012 17:17:19 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_compile_warnings_fo?= =?utf-8?q?r_=5Ftestimportmodule?= Message-ID: <3YNv0b194lzRXs@mail.python.org> http://hg.python.org/cpython/rev/16b1fde2275c changeset: 80856:16b1fde2275c user: Andrew Svetlov date: Sat Dec 15 18:16:47 2012 +0200 summary: Remove compile warnings for _testimportmodule files: Modules/_testimportmultiple.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_testimportmultiple.c b/Modules/_testimportmultiple.c --- a/Modules/_testimportmultiple.c +++ b/Modules/_testimportmultiple.c @@ -17,7 +17,7 @@ NULL }; -PyMODINIT_FUNC PyInit__testimportmultiple() +PyMODINIT_FUNC PyInit__testimportmultiple(void) { return PyModule_Create(&_testimportmultiple); } @@ -34,7 +34,7 @@ NULL }; -PyMODINIT_FUNC PyInit__testimportmultiple_foo() +PyMODINIT_FUNC PyInit__testimportmultiple_foo(void) { return PyModule_Create(&_foomodule); } @@ -51,7 +51,7 @@ NULL }; -PyMODINIT_FUNC PyInit__testimportmultiple_bar(){ +PyMODINIT_FUNC PyInit__testimportmultiple_bar(void){ return PyModule_Create(&_barmodule); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 18:51:18 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 15 Dec 2012 18:51:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_use_error_label_instead_of?= =?utf-8?q?_breaking_eval_loop_=28closes_=2316693=29?= Message-ID: <3YNx523M75zRZf@mail.python.org> http://hg.python.org/cpython/rev/bb6fd6f021e7 changeset: 80857:bb6fd6f021e7 user: Benjamin Peterson date: Sat Dec 15 12:51:05 2012 -0500 summary: use error label instead of breaking eval loop (closes #16693) files: Lib/test/test_builtin.py | 5 +++++ Python/ceval.c | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -462,6 +462,11 @@ self.assertRaises(TypeError, eval, ()) self.assertRaises(SyntaxError, eval, bom[:2] + b'a') + class X: + def __getitem__(self, key): + raise ValueError + self.assertRaises(ValueError, eval, "foo", {}, X()) + def test_general_eval(self): # Tests that general mappings can be used for the locals argument diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2162,9 +2162,8 @@ else { v = PyObject_GetItem(locals, name); if (v == NULL && PyErr_Occurred()) { - if (!PyErr_ExceptionMatches( - PyExc_KeyError)) - break; + if (!PyErr_ExceptionMatches(PyExc_KeyError)) + goto error; PyErr_Clear(); } } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 19:28:24 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 15 Dec 2012 19:28:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2Mjk4?= =?utf-8?q?=3A_In_HTTPResponse=2Eread=28=29=2C_close_the_socket_when_there?= =?utf-8?q?_is_no?= Message-ID: <3YNxvr0Y1KzRdv@mail.python.org> http://hg.python.org/cpython/rev/2186f7b99c28 changeset: 80858:2186f7b99c28 branch: 2.7 parent: 80850:e451901e6243 user: Antoine Pitrou date: Sat Dec 15 19:11:54 2012 +0100 summary: Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. files: Lib/httplib.py | 4 ++++ Lib/test/test_httplib.py | 15 ++++++++++++++- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 4 files changed, 23 insertions(+), 1 deletions(-) diff --git a/Lib/httplib.py b/Lib/httplib.py --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -565,6 +565,10 @@ self.length -= len(s) if not self.length: self.close() + else: + if not s: + self.close() + return s def _read_chunked(self, amt): diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -166,7 +166,7 @@ self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''') def test_partial_reads(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -177,6 +177,19 @@ self.assertEqual(resp.read(2), 'xt') self.assertTrue(resp.isclosed()) + def test_partial_reads_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\r\n\r\nText" + sock = FakeSocket(body) + resp = httplib.HTTPResponse(sock) + resp.begin() + self.assertEqual(resp.read(2), 'Te') + self.assertFalse(resp.isclosed()) + self.assertEqual(resp.read(2), 'xt') + self.assertEqual(resp.read(1), '') + self.assertTrue(resp.isclosed()) + def test_host_port(self): # Check invalid host_port diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -849,6 +849,7 @@ Paul Rubin Sam Ruby Audun S. Runde +Eran Rundstein Rauli Ruohonen Jeff Rush Sam Rushing diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -160,6 +160,10 @@ Library ------- +- Issue #16298: In HTTPResponse.read(), close the socket when there is no + Content-Length and the incoming stream is finished. Patch by Eran + Rundstein. + - Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 19:28:25 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 15 Dec 2012 19:28:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2Mjk4?= =?utf-8?q?=3A_In_HTTPResponse=2Eread=28=29=2C_close_the_socket_when_there?= =?utf-8?q?_is_no?= Message-ID: <3YNxvs30KZzRfr@mail.python.org> http://hg.python.org/cpython/rev/b47d342c449b changeset: 80859:b47d342c449b branch: 3.2 parent: 80851:5777ac884919 user: Antoine Pitrou date: Sat Dec 15 19:11:54 2012 +0100 summary: Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. files: Lib/http/client.py | 4 ++++ Lib/test/test_httplib.py | 15 ++++++++++++++- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 4 files changed, 23 insertions(+), 1 deletions(-) diff --git a/Lib/http/client.py b/Lib/http/client.py --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -511,6 +511,10 @@ self.length -= len(s) if not self.length: self.close() + else: + if not s: + self.close() + return s def _read_chunked(self, amt): diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -175,7 +175,7 @@ self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''') def test_partial_reads(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -186,6 +186,19 @@ self.assertEqual(resp.read(2), b'xt') self.assertTrue(resp.isclosed()) + def test_partial_reads_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\r\n\r\nText" + sock = FakeSocket(body) + resp = client.HTTPResponse(sock) + resp.begin() + self.assertEqual(resp.read(2), b'Te') + self.assertFalse(resp.isclosed()) + self.assertEqual(resp.read(2), b'xt') + self.assertEqual(resp.read(1), b'') + self.assertTrue(resp.isclosed()) + def test_host_port(self): # Check invalid host_port diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -917,6 +917,7 @@ Sam Ruby Demur Rumed Audun S. Runde +Eran Rundstein Rauli Ruohonen Jeff Rush Sam Rushing diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,10 @@ Library ------- +- Issue #16298: In HTTPResponse.read(), close the socket when there is no + Content-Length and the incoming stream is finished. Patch by Eran + Rundstein. + - Issue #16248: Disable code execution from the user's home directory by tkinter when the -E flag is passed to Python. Patch by Zachary Ware. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 19:28:26 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 15 Dec 2012 19:28:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316298=3A_In_HTTPResponse=2Eread=28=29=2C_close_the_so?= =?utf-8?q?cket_when_there_is_no?= Message-ID: <3YNxvt6YTzzRfB@mail.python.org> http://hg.python.org/cpython/rev/59358f991c00 changeset: 80860:59358f991c00 branch: 3.3 parent: 80852:a1ffb6c68711 parent: 80859:b47d342c449b user: Antoine Pitrou date: Sat Dec 15 19:22:30 2012 +0100 summary: Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. files: Lib/http/client.py | 3 ++ Lib/test/test_httplib.py | 36 ++++++++++++++++++++++++++- Misc/ACKS | 1 + Misc/NEWS | 4 +++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Lib/http/client.py b/Lib/http/client.py --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -536,6 +536,9 @@ self.length -= n if not self.length: self.close() + else: + if not n: + self.close() return n def _read_next_chunk_size(self): diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -175,7 +175,7 @@ self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''') def test_partial_reads(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -187,7 +187,7 @@ self.assertTrue(resp.isclosed()) def test_partial_readintos(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -203,6 +203,38 @@ self.assertEqual(bytes(b), b'xt') self.assertTrue(resp.isclosed()) + def test_partial_reads_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\r\n\r\nText" + sock = FakeSocket(body) + resp = client.HTTPResponse(sock) + resp.begin() + self.assertEqual(resp.read(2), b'Te') + self.assertFalse(resp.isclosed()) + self.assertEqual(resp.read(2), b'xt') + self.assertEqual(resp.read(1), b'') + self.assertTrue(resp.isclosed()) + + def test_partial_readintos_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\r\n\r\nText" + sock = FakeSocket(body) + resp = client.HTTPResponse(sock) + resp.begin() + b = bytearray(2) + n = resp.readinto(b) + self.assertEqual(n, 2) + self.assertEqual(bytes(b), b'Te') + self.assertFalse(resp.isclosed()) + n = resp.readinto(b) + self.assertEqual(n, 2) + self.assertEqual(bytes(b), b'xt') + n = resp.readinto(b) + self.assertEqual(n, 0) + self.assertTrue(resp.isclosed()) + def test_host_port(self): # Check invalid host_port diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1016,6 +1016,7 @@ Sam Ruby Demur Rumed Audun S. Runde +Eran Rundstein Rauli Ruohonen Jeff Rush Sam Rushing diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,10 @@ Library ------- +- Issue #16298: In HTTPResponse.read(), close the socket when there is no + Content-Length and the incoming stream is finished. Patch by Eran + Rundstein. + - Issue #15872: Fix 3.3 regression introduced by the new fd-based shutil.rmtree that caused it to not ignore certain errors when ignore_errors was set. Patch by Alessandro Moura and Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 19:28:28 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 15 Dec 2012 19:28:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316298=3A_In_HTTPResponse=2Eread=28=29=2C_close_?= =?utf-8?q?the_socket_when_there_is_no?= Message-ID: <3YNxvw382GzRfp@mail.python.org> http://hg.python.org/cpython/rev/5d6c2c7bc5d4 changeset: 80861:5d6c2c7bc5d4 parent: 80856:16b1fde2275c parent: 80860:59358f991c00 user: Antoine Pitrou date: Sat Dec 15 19:23:34 2012 +0100 summary: Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. files: Lib/http/client.py | 3 ++ Lib/test/test_httplib.py | 36 ++++++++++++++++++++++++++- Misc/ACKS | 1 + Misc/NEWS | 4 +++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Lib/http/client.py b/Lib/http/client.py --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -536,6 +536,9 @@ self.length -= n if not self.length: self.close() + else: + if not n: + self.close() return n def _read_next_chunk_size(self): diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -175,7 +175,7 @@ self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''') def test_partial_reads(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -187,7 +187,7 @@ self.assertTrue(resp.isclosed()) def test_partial_readintos(self): - # if we have a lenght, the system knows when to close itself + # if we have a length, the system knows when to close itself # same behaviour than when we read the whole thing with read() body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" sock = FakeSocket(body) @@ -203,6 +203,38 @@ self.assertEqual(bytes(b), b'xt') self.assertTrue(resp.isclosed()) + def test_partial_reads_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\r\n\r\nText" + sock = FakeSocket(body) + resp = client.HTTPResponse(sock) + resp.begin() + self.assertEqual(resp.read(2), b'Te') + self.assertFalse(resp.isclosed()) + self.assertEqual(resp.read(2), b'xt') + self.assertEqual(resp.read(1), b'') + self.assertTrue(resp.isclosed()) + + def test_partial_readintos_no_content_length(self): + # when no length is present, the socket should be gracefully closed when + # all data was read + body = "HTTP/1.1 200 Ok\r\n\r\nText" + sock = FakeSocket(body) + resp = client.HTTPResponse(sock) + resp.begin() + b = bytearray(2) + n = resp.readinto(b) + self.assertEqual(n, 2) + self.assertEqual(bytes(b), b'Te') + self.assertFalse(resp.isclosed()) + n = resp.readinto(b) + self.assertEqual(n, 2) + self.assertEqual(bytes(b), b'xt') + n = resp.readinto(b) + self.assertEqual(n, 0) + self.assertTrue(resp.isclosed()) + def test_host_port(self): # Check invalid host_port diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1022,6 +1022,7 @@ Sam Ruby Demur Rumed Audun S. Runde +Eran Rundstein Rauli Ruohonen Jeff Rush Sam Rushing diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -167,6 +167,10 @@ Library ------- +- Issue #16298: In HTTPResponse.read(), close the socket when there is no + Content-Length and the incoming stream is finished. Patch by Eran + Rundstein. + - Add abc.ABC class to use inheritance rather than a direct invocation of ABCMeta metaclass. Patch by Bruno Dupuis. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 19:28:29 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 15 Dec 2012 19:28:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge?= Message-ID: <3YNxvx5RXCzRg7@mail.python.org> http://hg.python.org/cpython/rev/64b5c4a9bb3e changeset: 80862:64b5c4a9bb3e parent: 80861:5d6c2c7bc5d4 parent: 80857:bb6fd6f021e7 user: Antoine Pitrou date: Sat Dec 15 19:26:38 2012 +0100 summary: Merge files: Lib/test/test_builtin.py | 5 +++++ Python/ceval.c | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -462,6 +462,11 @@ self.assertRaises(TypeError, eval, ()) self.assertRaises(SyntaxError, eval, bom[:2] + b'a') + class X: + def __getitem__(self, key): + raise ValueError + self.assertRaises(ValueError, eval, "foo", {}, X()) + def test_general_eval(self): # Tests that general mappings can be used for the locals argument diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2162,9 +2162,8 @@ else { v = PyObject_GetItem(locals, name); if (v == NULL && PyErr_Occurred()) { - if (!PyErr_ExceptionMatches( - PyExc_KeyError)) - break; + if (!PyErr_ExceptionMatches(PyExc_KeyError)) + goto error; PyErr_Clear(); } } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 20:50:21 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 15 Dec 2012 20:50:21 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Issue_=2316501=3A_record_the_?= =?utf-8?q?removal_of_RISC_OS_support_in_PEP_11=2E?= Message-ID: <3YNzkP1LVKzQhr@mail.python.org> http://hg.python.org/peps/rev/3abdc6b075fb changeset: 4615:3abdc6b075fb user: Antoine Pitrou date: Sat Dec 15 20:48:37 2012 +0100 summary: Issue #16501: record the removal of RISC OS support in PEP 11. RISC OS support was actually partially removed in 3.0 (whether or not a build still worked is not obvious, but unlikely). files: pep-0011.txt | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/pep-0011.txt b/pep-0011.txt --- a/pep-0011.txt +++ b/pep-0011.txt @@ -215,6 +215,10 @@ | Unsupported in: Python 3.3 | Code removed in: Python 3.4 +* | Name: RISC OS + | Unsupported in: Python 3.0 (some code actually removed) + | Code removed in: Python 3.4 + References ---------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 15 21:16:28 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 15 Dec 2012 21:16:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316488=3A_epoll=28?= =?utf-8?q?=29_objects_now_support_the_=60with=60_statement=2E?= Message-ID: <3YP0JX6MzBzQmB@mail.python.org> http://hg.python.org/cpython/rev/d6f61cd364d9 changeset: 80863:d6f61cd364d9 user: Antoine Pitrou date: Sat Dec 15 21:14:21 2012 +0100 summary: Issue #16488: epoll() objects now support the `with` statement. Patch by Serhiy Storchaka. files: Doc/library/select.rst | 5 ++++- Lib/test/test_epoll.py | 7 +++++++ Misc/NEWS | 3 +++ Modules/selectmodule.c | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletions(-) diff --git a/Doc/library/select.rst b/Doc/library/select.rst --- a/Doc/library/select.rst +++ b/Doc/library/select.rst @@ -47,11 +47,14 @@ to :const:`EPOLL_CLOEXEC`, which causes the epoll descriptor to be closed automatically when :func:`os.execve` is called. See section :ref:`epoll-objects` below for the methods supported by epolling objects. - + They also support the :keyword:`with` statement. .. versionchanged:: 3.3 Added the *flags* parameter. + .. versionchanged:: 3.4 + Support for the :keyword:`with` statement was added. + .. function:: poll() diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py --- a/Lib/test/test_epoll.py +++ b/Lib/test/test_epoll.py @@ -87,6 +87,13 @@ self.assertRaises(TypeError, select.epoll, ['foo']) self.assertRaises(TypeError, select.epoll, {}) + def test_context_manager(self): + with select.epoll(16) as ep: + self.assertGreater(ep.fileno(), 0) + self.assertFalse(ep.closed) + self.assertTrue(ep.closed) + self.assertRaises(ValueError, ep.fileno) + def test_add(self): server, client = self._connected_pair() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -167,6 +167,9 @@ Library ------- +- Issue #16488: epoll() objects now support the `with` statement. Patch + by Serhiy Storchaka. + - Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1394,6 +1394,24 @@ in seconds (as float). -1 makes poll wait indefinitely.\n\ Up to maxevents are returned to the caller."); +static PyObject * +pyepoll_enter(pyEpoll_Object *self, PyObject *args) +{ + if (self->epfd < 0) + return pyepoll_err_closed(); + + Py_INCREF(self); + return (PyObject *)self; +} + +static PyObject * +pyepoll_exit(PyObject *self, PyObject *args) +{ + _Py_IDENTIFIER(close); + + return _PyObject_CallMethodId(self, &PyId_close, NULL); +} + static PyMethodDef pyepoll_methods[] = { {"fromfd", (PyCFunction)pyepoll_fromfd, METH_VARARGS | METH_CLASS, pyepoll_fromfd_doc}, @@ -1409,6 +1427,10 @@ METH_VARARGS | METH_KEYWORDS, pyepoll_unregister_doc}, {"poll", (PyCFunction)pyepoll_poll, METH_VARARGS | METH_KEYWORDS, pyepoll_poll_doc}, + {"__enter__", (PyCFunction)pyepoll_enter, METH_NOARGS, + NULL}, + {"__exit__", (PyCFunction)pyepoll_exit, METH_VARARGS, + NULL}, {NULL, NULL}, }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 21:44:03 2012 From: python-checkins at python.org (petri.lehtinen) Date: Sat, 15 Dec 2012 21:44:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=2311175=3A_argparse=2EFil?= =?utf-8?q?eType_now_accepts_encoding_and_errors_arguments=2E?= Message-ID: <3YP0wM2DpkzRbW@mail.python.org> http://hg.python.org/cpython/rev/d5a0698a8354 changeset: 80864:d5a0698a8354 user: Petri Lehtinen date: Sat Dec 15 22:39:32 2012 +0200 summary: #11175: argparse.FileType now accepts encoding and errors arguments. Patch by Lucas Maystre. files: Doc/library/argparse.rst | 20 +++++++++------- Lib/argparse.py | 16 ++++++++++-- Lib/test/test_argparse.py | 32 +++++++++++++++++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 ++ 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -976,9 +976,9 @@ ``type`` argument is applied to default arguments. To ease the use of various types of files, the argparse module provides the -factory FileType which takes the ``mode=`` and ``bufsize=`` arguments of the -:func:`open` function. For example, ``FileType('w')`` can be used to create a -writable file:: +factory FileType which takes the ``mode=``, ``bufsize=``, ``encoding=`` and +``errors=`` arguments of the :func:`open` function. For example, +``FileType('w')`` can be used to create a writable file:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('bar', type=argparse.FileType('w')) @@ -1617,17 +1617,19 @@ FileType objects ^^^^^^^^^^^^^^^^ -.. class:: FileType(mode='r', bufsize=None) +.. class:: FileType(mode='r', bufsize=-1, encoding=None, errors=None) The :class:`FileType` factory creates objects that can be passed to the type argument of :meth:`ArgumentParser.add_argument`. Arguments that have - :class:`FileType` objects as their type will open command-line arguments as files - with the requested modes and buffer sizes:: + :class:`FileType` objects as their type will open command-line arguments as + files with the requested modes, buffer sizes, encodings and error handling + (see the :func:`open` function for more details):: >>> parser = argparse.ArgumentParser() - >>> parser.add_argument('--output', type=argparse.FileType('wb', 0)) - >>> parser.parse_args(['--output', 'out']) - Namespace(output=<_io.BufferedWriter name='out'>) + >>> parser.add_argument('--raw', type=argparse.FileType('wb', 0)) + >>> parser.add_argument('out', type=argparse.FileType('w', encoding='UTF-8')) + >>> parser.parse_args(['--raw', 'raw.dat', 'file.txt']) + Namespace(out=<_io.TextIOWrapper name='file.txt' mode='w' encoding='UTF-8'>, raw=<_io.FileIO name='raw.dat' mode='wb'>) FileType objects understand the pseudo-argument ``'-'`` and automatically convert this into ``sys.stdin`` for readable :class:`FileType` objects and diff --git a/Lib/argparse.py b/Lib/argparse.py --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1140,11 +1140,17 @@ same values as the builtin open() function. - bufsize -- The file's desired buffer size. Accepts the same values as the builtin open() function. + - encoding -- The file's encoding. Accepts the same values as the + the builtin open() function. + - errors -- A string indicating how encoding and decoding errors are to + be handled. Accepts the same value as the builtin open() function. """ - def __init__(self, mode='r', bufsize=-1): + def __init__(self, mode='r', bufsize=-1, encoding=None, errors=None): self._mode = mode self._bufsize = bufsize + self._encoding = encoding + self._errors = errors def __call__(self, string): # the special argument "-" means sys.std{in,out} @@ -1159,14 +1165,18 @@ # all other arguments are used as file names try: - return open(string, self._mode, self._bufsize) + return open(string, self._mode, self._bufsize, self._encoding, + self._errors) except IOError as e: message = _("can't open '%s': %s") raise ArgumentTypeError(message % (string, e)) def __repr__(self): args = self._mode, self._bufsize - args_str = ', '.join(repr(arg) for arg in args if arg != -1) + kwargs = [('encoding', self._encoding), ('errors', self._errors)] + args_str = ', '.join([repr(arg) for arg in args if arg != -1] + + ['%s=%r' % (kw, arg) for kw, arg in kwargs + if arg is not None]) return '%s(%s)' % (type(self).__name__, args_str) # =========================== diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -14,6 +14,7 @@ from io import StringIO from test import support +from unittest import mock class StdIOBuffer(StringIO): pass @@ -1421,6 +1422,19 @@ type = argparse.FileType('wb', 1) self.assertEqual("FileType('wb', 1)", repr(type)) + def test_r_latin(self): + type = argparse.FileType('r', encoding='latin_1') + self.assertEqual("FileType('r', encoding='latin_1')", repr(type)) + + def test_w_big5_ignore(self): + type = argparse.FileType('w', encoding='big5', errors='ignore') + self.assertEqual("FileType('w', encoding='big5', errors='ignore')", + repr(type)) + + def test_r_1_replace(self): + type = argparse.FileType('r', 1, errors='replace') + self.assertEqual("FileType('r', 1, errors='replace')", repr(type)) + class RFile(object): seen = {} @@ -1557,6 +1571,24 @@ ] +class TestFileTypeOpenArgs(TestCase): + """Test that open (the builtin) is correctly called""" + + def test_open_args(self): + FT = argparse.FileType + cases = [ + (FT('rb'), ('rb', -1, None, None)), + (FT('w', 1), ('w', 1, None, None)), + (FT('w', errors='replace'), ('w', -1, None, 'replace')), + (FT('wb', encoding='big5'), ('wb', -1, 'big5', None)), + (FT('w', 0, 'l1', 'strict'), ('w', 0, 'l1', 'strict')), + ] + with mock.patch('builtins.open') as m: + for type, args in cases: + type('foo') + m.assert_called_with('foo', *args) + + class TestTypeCallable(ParserTestCase): """Test some callables as option/argument types""" diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -768,6 +768,7 @@ Graham Matthews Dieter Maurer Daniel May +Lucas Maystre Arnaud Mazin Rebecca McCreary Kirk McDonald diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -167,6 +167,9 @@ Library ------- +- Issue #11175: argparse.FileType now accepts encoding and errors + arguments. Patch by Lucas Maystre. + - Issue #16488: epoll() objects now support the `with` statement. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 21:46:26 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 15 Dec 2012 21:46:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_remove_dead_co?= =?utf-8?q?de?= Message-ID: <3YP0z659fLzRbW@mail.python.org> http://hg.python.org/cpython/rev/8ba5a34e103e changeset: 80865:8ba5a34e103e branch: 3.2 parent: 80859:b47d342c449b user: Benjamin Peterson date: Sat Dec 15 15:43:58 2012 -0500 summary: remove dead code files: Modules/_ctypes/_ctypes.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2438,8 +2438,6 @@ static int PyCData_clear(CDataObject *self) { - StgDictObject *dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) && _CDataObject_HasExternalBuffer(self)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 21:46:28 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 15 Dec 2012 21:46:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_merge_3=2E2?= Message-ID: <3YP0z80Lm1zRdS@mail.python.org> http://hg.python.org/cpython/rev/313225e42f99 changeset: 80866:313225e42f99 branch: 3.3 parent: 80860:59358f991c00 parent: 80865:8ba5a34e103e user: Benjamin Peterson date: Sat Dec 15 15:44:08 2012 -0500 summary: merge 3.2 files: Modules/_ctypes/_ctypes.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2442,8 +2442,6 @@ static int PyCData_clear(CDataObject *self) { - StgDictObject *dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) && _CDataObject_HasExternalBuffer(self)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 21:46:29 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 15 Dec 2012 21:46:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4z?= Message-ID: <3YP0z92hwRzRdF@mail.python.org> http://hg.python.org/cpython/rev/590caab5d6c7 changeset: 80867:590caab5d6c7 parent: 80863:d6f61cd364d9 parent: 80866:313225e42f99 user: Benjamin Peterson date: Sat Dec 15 15:44:18 2012 -0500 summary: merge 3.3 files: Modules/_ctypes/_ctypes.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2442,8 +2442,6 @@ static int PyCData_clear(CDataObject *self) { - StgDictObject *dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) && _CDataObject_HasExternalBuffer(self)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 21:46:30 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 15 Dec 2012 21:46:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_remove_dead_co?= =?utf-8?q?de?= Message-ID: <3YP0zB5K9PzRgW@mail.python.org> http://hg.python.org/cpython/rev/3d518ef4eae7 changeset: 80868:3d518ef4eae7 branch: 2.7 parent: 80858:2186f7b99c28 user: Benjamin Peterson date: Sat Dec 15 15:43:58 2012 -0500 summary: remove dead code files: Modules/_ctypes/_ctypes.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2526,8 +2526,6 @@ static int PyCData_clear(CDataObject *self) { - StgDictObject *dict = PyObject_stgdict((PyObject *)self); - assert(dict); /* Cannot be NULL for CDataObject instances */ Py_CLEAR(self->b_objects); if ((self->b_needsfree) && _CDataObject_HasExternalBuffer(self)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 21:46:32 2012 From: python-checkins at python.org (benjamin.peterson) Date: Sat, 15 Dec 2012 21:46:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3YP0zD1t3LzRbW@mail.python.org> http://hg.python.org/cpython/rev/3829339ee675 changeset: 80869:3829339ee675 parent: 80867:590caab5d6c7 parent: 80864:d5a0698a8354 user: Benjamin Peterson date: Sat Dec 15 15:46:20 2012 -0500 summary: merge heads files: Doc/library/argparse.rst | 20 +++++++++------- Lib/argparse.py | 16 ++++++++++-- Lib/test/test_argparse.py | 32 +++++++++++++++++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 ++ 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -976,9 +976,9 @@ ``type`` argument is applied to default arguments. To ease the use of various types of files, the argparse module provides the -factory FileType which takes the ``mode=`` and ``bufsize=`` arguments of the -:func:`open` function. For example, ``FileType('w')`` can be used to create a -writable file:: +factory FileType which takes the ``mode=``, ``bufsize=``, ``encoding=`` and +``errors=`` arguments of the :func:`open` function. For example, +``FileType('w')`` can be used to create a writable file:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('bar', type=argparse.FileType('w')) @@ -1617,17 +1617,19 @@ FileType objects ^^^^^^^^^^^^^^^^ -.. class:: FileType(mode='r', bufsize=None) +.. class:: FileType(mode='r', bufsize=-1, encoding=None, errors=None) The :class:`FileType` factory creates objects that can be passed to the type argument of :meth:`ArgumentParser.add_argument`. Arguments that have - :class:`FileType` objects as their type will open command-line arguments as files - with the requested modes and buffer sizes:: + :class:`FileType` objects as their type will open command-line arguments as + files with the requested modes, buffer sizes, encodings and error handling + (see the :func:`open` function for more details):: >>> parser = argparse.ArgumentParser() - >>> parser.add_argument('--output', type=argparse.FileType('wb', 0)) - >>> parser.parse_args(['--output', 'out']) - Namespace(output=<_io.BufferedWriter name='out'>) + >>> parser.add_argument('--raw', type=argparse.FileType('wb', 0)) + >>> parser.add_argument('out', type=argparse.FileType('w', encoding='UTF-8')) + >>> parser.parse_args(['--raw', 'raw.dat', 'file.txt']) + Namespace(out=<_io.TextIOWrapper name='file.txt' mode='w' encoding='UTF-8'>, raw=<_io.FileIO name='raw.dat' mode='wb'>) FileType objects understand the pseudo-argument ``'-'`` and automatically convert this into ``sys.stdin`` for readable :class:`FileType` objects and diff --git a/Lib/argparse.py b/Lib/argparse.py --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1140,11 +1140,17 @@ same values as the builtin open() function. - bufsize -- The file's desired buffer size. Accepts the same values as the builtin open() function. + - encoding -- The file's encoding. Accepts the same values as the + the builtin open() function. + - errors -- A string indicating how encoding and decoding errors are to + be handled. Accepts the same value as the builtin open() function. """ - def __init__(self, mode='r', bufsize=-1): + def __init__(self, mode='r', bufsize=-1, encoding=None, errors=None): self._mode = mode self._bufsize = bufsize + self._encoding = encoding + self._errors = errors def __call__(self, string): # the special argument "-" means sys.std{in,out} @@ -1159,14 +1165,18 @@ # all other arguments are used as file names try: - return open(string, self._mode, self._bufsize) + return open(string, self._mode, self._bufsize, self._encoding, + self._errors) except IOError as e: message = _("can't open '%s': %s") raise ArgumentTypeError(message % (string, e)) def __repr__(self): args = self._mode, self._bufsize - args_str = ', '.join(repr(arg) for arg in args if arg != -1) + kwargs = [('encoding', self._encoding), ('errors', self._errors)] + args_str = ', '.join([repr(arg) for arg in args if arg != -1] + + ['%s=%r' % (kw, arg) for kw, arg in kwargs + if arg is not None]) return '%s(%s)' % (type(self).__name__, args_str) # =========================== diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -14,6 +14,7 @@ from io import StringIO from test import support +from unittest import mock class StdIOBuffer(StringIO): pass @@ -1421,6 +1422,19 @@ type = argparse.FileType('wb', 1) self.assertEqual("FileType('wb', 1)", repr(type)) + def test_r_latin(self): + type = argparse.FileType('r', encoding='latin_1') + self.assertEqual("FileType('r', encoding='latin_1')", repr(type)) + + def test_w_big5_ignore(self): + type = argparse.FileType('w', encoding='big5', errors='ignore') + self.assertEqual("FileType('w', encoding='big5', errors='ignore')", + repr(type)) + + def test_r_1_replace(self): + type = argparse.FileType('r', 1, errors='replace') + self.assertEqual("FileType('r', 1, errors='replace')", repr(type)) + class RFile(object): seen = {} @@ -1557,6 +1571,24 @@ ] +class TestFileTypeOpenArgs(TestCase): + """Test that open (the builtin) is correctly called""" + + def test_open_args(self): + FT = argparse.FileType + cases = [ + (FT('rb'), ('rb', -1, None, None)), + (FT('w', 1), ('w', 1, None, None)), + (FT('w', errors='replace'), ('w', -1, None, 'replace')), + (FT('wb', encoding='big5'), ('wb', -1, 'big5', None)), + (FT('w', 0, 'l1', 'strict'), ('w', 0, 'l1', 'strict')), + ] + with mock.patch('builtins.open') as m: + for type, args in cases: + type('foo') + m.assert_called_with('foo', *args) + + class TestTypeCallable(ParserTestCase): """Test some callables as option/argument types""" diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -768,6 +768,7 @@ Graham Matthews Dieter Maurer Daniel May +Lucas Maystre Arnaud Mazin Rebecca McCreary Kirk McDonald diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -167,6 +167,9 @@ Library ------- +- Issue #11175: argparse.FileType now accepts encoding and errors + arguments. Patch by Lucas Maystre. + - Issue #16488: epoll() objects now support the `with` statement. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 22:00:05 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 15 Dec 2012 22:00:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Use_OSError_in?= =?utf-8?q?stead_of_os=2Eerror_in_the_docs=2E?= Message-ID: <3YP1Gs0RfzzRbW@mail.python.org> http://hg.python.org/cpython/rev/f05c0087c47d changeset: 80870:f05c0087c47d branch: 3.3 parent: 80866:313225e42f99 user: Andrew Svetlov date: Sat Dec 15 22:59:24 2012 +0200 summary: Use OSError instead of os.error in the docs. files: Doc/library/os.path.rst | 8 ++++---- Doc/library/shutil.rst | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst --- a/Doc/library/os.path.rst +++ b/Doc/library/os.path.rst @@ -126,7 +126,7 @@ Return the time of last access of *path*. The return value is a number giving the number of seconds since the epoch (see the :mod:`time` module). Raise - :exc:`os.error` if the file does not exist or is inaccessible. + :exc:`OSError` if the file does not exist or is inaccessible. If :func:`os.stat_float_times` returns True, the result is a floating point number. @@ -136,7 +136,7 @@ Return the time of last modification of *path*. The return value is a number giving the number of seconds since the epoch (see the :mod:`time` module). - Raise :exc:`os.error` if the file does not exist or is inaccessible. + Raise :exc:`OSError` if the file does not exist or is inaccessible. If :func:`os.stat_float_times` returns True, the result is a floating point number. @@ -147,13 +147,13 @@ Return the system's ctime which, on some systems (like Unix) is the time of the last change, and, on others (like Windows), is the creation time for *path*. The return value is a number giving the number of seconds since the epoch (see - the :mod:`time` module). Raise :exc:`os.error` if the file does not exist or + the :mod:`time` module). Raise :exc:`OSError` if the file does not exist or is inaccessible. .. function:: getsize(path) - Return the size, in bytes, of *path*. Raise :exc:`os.error` if the file does + Return the size, in bytes, of *path*. Raise :exc:`OSError` if the file does not exist or is inaccessible. diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -372,7 +372,7 @@ else: copy2(srcname, dstname) # XXX What about devices, sockets etc.? - except (IOError, os.error) as why: + except OSError as why: errors.append((srcname, dstname, str(why))) # catch the Error from the recursive copytree so that we can # continue with other files -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 22:00:06 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 15 Dec 2012 22:00:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge=3A_use_OSError_instead_of_os=2Eerror_in_the_docs?= =?utf-8?q?=2E?= Message-ID: <3YP1Gt2vRNzN1r@mail.python.org> http://hg.python.org/cpython/rev/cd75923a102a changeset: 80871:cd75923a102a parent: 80869:3829339ee675 parent: 80870:f05c0087c47d user: Andrew Svetlov date: Sat Dec 15 22:59:55 2012 +0200 summary: Merge: use OSError instead of os.error in the docs. files: Doc/library/os.path.rst | 8 ++++---- Doc/library/shutil.rst | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst --- a/Doc/library/os.path.rst +++ b/Doc/library/os.path.rst @@ -125,7 +125,7 @@ Return the time of last access of *path*. The return value is a number giving the number of seconds since the epoch (see the :mod:`time` module). Raise - :exc:`os.error` if the file does not exist or is inaccessible. + :exc:`OSError` if the file does not exist or is inaccessible. If :func:`os.stat_float_times` returns True, the result is a floating point number. @@ -135,7 +135,7 @@ Return the time of last modification of *path*. The return value is a number giving the number of seconds since the epoch (see the :mod:`time` module). - Raise :exc:`os.error` if the file does not exist or is inaccessible. + Raise :exc:`OSError` if the file does not exist or is inaccessible. If :func:`os.stat_float_times` returns True, the result is a floating point number. @@ -146,13 +146,13 @@ Return the system's ctime which, on some systems (like Unix) is the time of the last change, and, on others (like Windows), is the creation time for *path*. The return value is a number giving the number of seconds since the epoch (see - the :mod:`time` module). Raise :exc:`os.error` if the file does not exist or + the :mod:`time` module). Raise :exc:`OSError` if the file does not exist or is inaccessible. .. function:: getsize(path) - Return the size, in bytes, of *path*. Raise :exc:`os.error` if the file does + Return the size, in bytes, of *path*. Raise :exc:`OSError` if the file does not exist or is inaccessible. diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -385,7 +385,7 @@ else: copy2(srcname, dstname) # XXX What about devices, sockets etc.? - except (IOError, os.error) as why: + except OSError as why: errors.append((srcname, dstname, str(why))) # catch the Error from the recursive copytree so that we can # continue with other files -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 22:40:31 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 15 Dec 2012 22:40:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE1Nzgz?= =?utf-8?q?=3A_Except_for_the_number_methods=2C_the_C_version_of_decimal_n?= =?utf-8?q?ow?= Message-ID: <3YP29W689YzRgG@mail.python.org> http://hg.python.org/cpython/rev/29becac5dd9b changeset: 80872:29becac5dd9b branch: 3.3 parent: 80870:f05c0087c47d user: Stefan Krah date: Sat Dec 15 22:33:33 2012 +0100 summary: Issue #15783: Except for the number methods, the C version of decimal now supports all None default values present in decimal.py. These values were largely undocumented. files: Doc/library/decimal.rst | 97 +++-- Lib/decimal.py | 12 +- Lib/test/test_decimal.py | 302 ++++++++++++++++- Misc/NEWS | 4 + Modules/_decimal/_decimal.c | 197 ++++++----- Modules/_decimal/docstrings.h | 206 ++++++----- Modules/_decimal/tests/deccheck.py | 34 + Modules/_decimal/tests/randdec.py | 18 + 8 files changed, 631 insertions(+), 239 deletions(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -459,7 +459,7 @@ a :class:`Decimal` instance is always canonical, so this operation returns its argument unchanged. - .. method:: compare(other[, context]) + .. method:: compare(other, context=None) Compare the values of two Decimal instances. :meth:`compare` returns a Decimal instance, and if either operand is a NaN then the result is a @@ -470,13 +470,13 @@ a == b ==> Decimal('0') a > b ==> Decimal('1') - .. method:: compare_signal(other[, context]) + .. method:: compare_signal(other, context=None) This operation is identical to the :meth:`compare` method, except that all NaNs signal. That is, if neither operand is a signaling NaN then any quiet NaN operand is treated as though it were a signaling NaN. - .. method:: compare_total(other) + .. method:: compare_total(other, context=None) Compare two operands using their abstract representation rather than their numerical value. Similar to the :meth:`compare` method, but the result @@ -494,13 +494,21 @@ higher in the total order than the second operand. See the specification for details of the total order. - .. method:: compare_total_mag(other) + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + + .. method:: compare_total_mag(other, context=None) Compare two operands using their abstract representation rather than their value as in :meth:`compare_total`, but ignoring the sign of each operand. ``x.compare_total_mag(y)`` is equivalent to ``x.copy_abs().compare_total(y.copy_abs())``. + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + .. method:: conjugate() Just returns self, this method is only to comply with the Decimal @@ -517,7 +525,7 @@ Return the negation of the argument. This operation is unaffected by the context and is quiet: no flags are changed and no rounding is performed. - .. method:: copy_sign(other) + .. method:: copy_sign(other, context=None) Return a copy of the first operand with the sign set to be the same as the sign of the second operand. For example: @@ -525,10 +533,11 @@ >>> Decimal('2.3').copy_sign(Decimal('-1.5')) Decimal('-2.3') - This operation is unaffected by the context and is quiet: no flags are - changed and no rounding is performed. - - .. method:: exp([context]) + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + + .. method:: exp(context=None) Return the value of the (natural) exponential function ``e**x`` at the given number. The result is correctly rounded using the @@ -565,7 +574,7 @@ .. versionadded:: 3.1 - .. method:: fma(other, third[, context]) + .. method:: fma(other, third, context=None) Fused multiply-add. Return self*other+third with no rounding of the intermediate product self*other. @@ -594,7 +603,7 @@ Return :const:`True` if the argument is a (quiet or signaling) NaN and :const:`False` otherwise. - .. method:: is_normal() + .. method:: is_normal(context=None) Return :const:`True` if the argument is a *normal* finite number. Return :const:`False` if the argument is zero, subnormal, infinite or a NaN. @@ -614,7 +623,7 @@ Return :const:`True` if the argument is a signaling NaN and :const:`False` otherwise. - .. method:: is_subnormal() + .. method:: is_subnormal(context=None) Return :const:`True` if the argument is subnormal, and :const:`False` otherwise. @@ -624,17 +633,17 @@ Return :const:`True` if the argument is a (positive or negative) zero and :const:`False` otherwise. - .. method:: ln([context]) + .. method:: ln(context=None) Return the natural (base e) logarithm of the operand. The result is correctly rounded using the :const:`ROUND_HALF_EVEN` rounding mode. - .. method:: log10([context]) + .. method:: log10(context=None) Return the base ten logarithm of the operand. The result is correctly rounded using the :const:`ROUND_HALF_EVEN` rounding mode. - .. method:: logb([context]) + .. method:: logb(context=None) For a nonzero number, return the adjusted exponent of its operand as a :class:`Decimal` instance. If the operand is a zero then @@ -642,73 +651,73 @@ is raised. If the operand is an infinity then ``Decimal('Infinity')`` is returned. - .. method:: logical_and(other[, context]) + .. method:: logical_and(other, context=None) :meth:`logical_and` is a logical operation which takes two *logical operands* (see :ref:`logical_operands_label`). The result is the digit-wise ``and`` of the two operands. - .. method:: logical_invert([context]) + .. method:: logical_invert(context=None) :meth:`logical_invert` is a logical operation. The result is the digit-wise inversion of the operand. - .. method:: logical_or(other[, context]) + .. method:: logical_or(other, context=None) :meth:`logical_or` is a logical operation which takes two *logical operands* (see :ref:`logical_operands_label`). The result is the digit-wise ``or`` of the two operands. - .. method:: logical_xor(other[, context]) + .. method:: logical_xor(other, context=None) :meth:`logical_xor` is a logical operation which takes two *logical operands* (see :ref:`logical_operands_label`). The result is the digit-wise exclusive or of the two operands. - .. method:: max(other[, context]) + .. method:: max(other, context=None) Like ``max(self, other)`` except that the context rounding rule is applied before returning and that :const:`NaN` values are either signaled or ignored (depending on the context and whether they are signaling or quiet). - .. method:: max_mag(other[, context]) + .. method:: max_mag(other, context=None) Similar to the :meth:`.max` method, but the comparison is done using the absolute values of the operands. - .. method:: min(other[, context]) + .. method:: min(other, context=None) Like ``min(self, other)`` except that the context rounding rule is applied before returning and that :const:`NaN` values are either signaled or ignored (depending on the context and whether they are signaling or quiet). - .. method:: min_mag(other[, context]) + .. method:: min_mag(other, context=None) Similar to the :meth:`.min` method, but the comparison is done using the absolute values of the operands. - .. method:: next_minus([context]) + .. method:: next_minus(context=None) Return the largest number representable in the given context (or in the current thread's context if no context is given) that is smaller than the given operand. - .. method:: next_plus([context]) + .. method:: next_plus(context=None) Return the smallest number representable in the given context (or in the current thread's context if no context is given) that is larger than the given operand. - .. method:: next_toward(other[, context]) + .. method:: next_toward(other, context=None) If the two operands are unequal, return the number closest to the first operand in the direction of the second operand. If both operands are numerically equal, return a copy of the first operand with the sign set to be the same as the sign of the second operand. - .. method:: normalize([context]) + .. method:: normalize(context=None) Normalize the number by stripping the rightmost trailing zeros and converting any result equal to :const:`Decimal('0')` to @@ -717,7 +726,7 @@ ``Decimal('0.321000e+2')`` both normalize to the equivalent value ``Decimal('32.1')``. - .. method:: number_class([context]) + .. method:: number_class(context=None) Return a string describing the *class* of the operand. The returned value is one of the following ten strings. @@ -733,7 +742,7 @@ * ``"NaN"``, indicating that the operand is a quiet NaN (Not a Number). * ``"sNaN"``, indicating that the operand is a signaling NaN. - .. method:: quantize(exp[, rounding[, context[, watchexp]]]) + .. method:: quantize(exp, rounding=None, context=None, watchexp=True) Return a value equal to the first operand after rounding and having the exponent of the second operand. @@ -771,7 +780,7 @@ class does all its arithmetic. Included for compatibility with the specification. - .. method:: remainder_near(other[, context]) + .. method:: remainder_near(other, context=None) Return the remainder from dividing *self* by *other*. This differs from ``self % other`` in that the sign of the remainder is chosen so as to @@ -789,7 +798,7 @@ >>> Decimal(35).remainder_near(Decimal(10)) Decimal('-5') - .. method:: rotate(other[, context]) + .. method:: rotate(other, context=None) Return the result of rotating the digits of the first operand by an amount specified by the second operand. The second operand must be an integer in @@ -800,18 +809,22 @@ length precision if necessary. The sign and exponent of the first operand are unchanged. - .. method:: same_quantum(other[, context]) + .. method:: same_quantum(other, context=None) Test whether self and other have the same exponent or whether both are :const:`NaN`. - .. method:: scaleb(other[, context]) + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + + .. method:: scaleb(other, context=None) Return the first operand with exponent adjusted by the second. Equivalently, return the first operand multiplied by ``10**other``. The second operand must be an integer. - .. method:: shift(other[, context]) + .. method:: shift(other, context=None) Return the result of shifting the digits of the first operand by an amount specified by the second operand. The second operand must be an integer in @@ -821,12 +834,12 @@ right. Digits shifted into the coefficient are zeros. The sign and exponent of the first operand are unchanged. - .. method:: sqrt([context]) + .. method:: sqrt(context=None) Return the square root of the argument to full precision. - .. method:: to_eng_string([context]) + .. method:: to_eng_string(context=None) Convert to an engineering-type string. @@ -834,12 +847,12 @@ are up to 3 digits left of the decimal place. For example, converts ``Decimal('123E+1')`` to ``Decimal('1.23E+3')`` - .. method:: to_integral([rounding[, context]]) + .. method:: to_integral(rounding=None, context=None) Identical to the :meth:`to_integral_value` method. The ``to_integral`` name has been kept for compatibility with older versions. - .. method:: to_integral_exact([rounding[, context]]) + .. method:: to_integral_exact(rounding=None, context=None) Round to the nearest integer, signaling :const:`Inexact` or :const:`Rounded` as appropriate if rounding occurs. The rounding mode is @@ -847,7 +860,7 @@ ``context``. If neither parameter is given then the rounding mode of the current context is used. - .. method:: to_integral_value([rounding[, context]]) + .. method:: to_integral_value(rounding=None, context=None) Round to the nearest integer without signaling :const:`Inexact` or :const:`Rounded`. If given, applies *rounding*; otherwise, uses the @@ -893,10 +906,10 @@ You can also use the :keyword:`with` statement and the :func:`localcontext` function to temporarily change the active context. -.. function:: localcontext([c]) +.. function:: localcontext(ctx=None) Return a context manager that will set the current context for the active thread - to a copy of *c* on entry to the with-statement and restore the previous context + to a copy of *ctx* on entry to the with-statement and restore the previous context when exiting the with-statement. If no context is specified, a copy of the current context is used. @@ -1315,7 +1328,7 @@ identity operation. - .. method:: power(x, y[, modulo]) + .. method:: power(x, y, modulo=None) Return ``x`` to the power of ``y``, reduced modulo ``modulo`` if given. diff --git a/Lib/decimal.py b/Lib/decimal.py --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -2596,7 +2596,7 @@ ans = ans._fix(context) return ans - def same_quantum(self, other): + def same_quantum(self, other, context=None): """Return True if self and other have the same exponent; otherwise return False. @@ -2914,7 +2914,7 @@ except TypeError: return 0 - def canonical(self, context=None): + def canonical(self): """Returns the same Decimal object. As we do not have different encodings for the same number, the @@ -2934,7 +2934,7 @@ return ans return self.compare(other, context=context) - def compare_total(self, other): + def compare_total(self, other, context=None): """Compares self to other using the abstract representations. This is not like the standard compare, which use their numerical @@ -3007,7 +3007,7 @@ return _Zero - def compare_total_mag(self, other): + def compare_total_mag(self, other, context=None): """Compares self to other using abstract repr., ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. @@ -3029,7 +3029,7 @@ else: return _dec_from_triple(1, self._int, self._exp, self._is_special) - def copy_sign(self, other): + def copy_sign(self, other, context=None): """Returns self with the sign of other.""" other = _convert_other(other, raiseit=True) return _dec_from_triple(other._sign, self._int, @@ -4182,7 +4182,7 @@ """ if not isinstance(a, Decimal): raise TypeError("canonical requires a Decimal as an argument.") - return a.canonical(context=self) + return a.canonical() def compare(self, a, b): """Compares values numerically. diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -2089,6 +2089,248 @@ self.assertEqual(str(Decimal(0).sqrt()), str(c.sqrt(Decimal(0)))) + def test_none_args(self): + Decimal = self.decimal.Decimal + Context = self.decimal.Context + localcontext = self.decimal.localcontext + InvalidOperation = self.decimal.InvalidOperation + DivisionByZero = self.decimal.DivisionByZero + Overflow = self.decimal.Overflow + Underflow = self.decimal.Underflow + Subnormal = self.decimal.Subnormal + Inexact = self.decimal.Inexact + Rounded = self.decimal.Rounded + Clamped = self.decimal.Clamped + ROUND_HALF_EVEN = self.decimal.ROUND_HALF_EVEN + ROUND_DOWN = self.decimal.ROUND_DOWN + ROUND_UP = self.decimal.ROUND_UP + + with localcontext(Context()) as c: + c.prec = 7 + c.Emax = 999 + c.Emin = -999 + + x = Decimal("111") + y = Decimal("1e9999") + z = Decimal("1e-9999") + + ##### Unary functions + c.clear_flags() + self.assertEqual(str(x.exp(context=None)), '1.609487E+48') + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + c.clear_flags() + self.assertRaises(Overflow, y.exp, context=None) + self.assertTrue(c.flags[Overflow]) + + self.assertIs(z.is_normal(context=None), False) + self.assertIs(z.is_subnormal(context=None), True) + + c.clear_flags() + self.assertEqual(str(x.ln(context=None)), '4.709530') + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal(-1).ln, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(x.log10(context=None)), '2.045323') + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal(-1).log10, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(x.logb(context=None)), '2') + self.assertRaises(DivisionByZero, Decimal(0).logb, context=None) + self.assertTrue(c.flags[DivisionByZero]) + + c.clear_flags() + self.assertEqual(str(x.logical_invert(context=None)), '1111000') + self.assertRaises(InvalidOperation, y.logical_invert, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(y.next_minus(context=None)), '9.999999E+999') + self.assertRaises(InvalidOperation, Decimal('sNaN').next_minus, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(y.next_plus(context=None)), 'Infinity') + self.assertRaises(InvalidOperation, Decimal('sNaN').next_plus, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(z.normalize(context=None)), '0') + self.assertRaises(Overflow, y.normalize, context=None) + self.assertTrue(c.flags[Overflow]) + + self.assertEqual(str(z.number_class(context=None)), '+Subnormal') + + c.clear_flags() + self.assertEqual(str(z.sqrt(context=None)), '0E-1005') + self.assertTrue(c.flags[Clamped]) + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + self.assertTrue(c.flags[Subnormal]) + self.assertTrue(c.flags[Underflow]) + c.clear_flags() + self.assertRaises(Overflow, y.sqrt, context=None) + self.assertTrue(c.flags[Overflow]) + + c.capitals = 0 + self.assertEqual(str(z.to_eng_string(context=None)), '1e-9999') + c.capitals = 1 + + + ##### Binary functions + c.clear_flags() + ans = str(x.compare(Decimal('Nan891287828'), context=None)) + self.assertEqual(ans, 'NaN1287828') + self.assertRaises(InvalidOperation, x.compare, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.compare_signal(8224, context=None)) + self.assertEqual(ans, '-1') + self.assertRaises(InvalidOperation, x.compare_signal, Decimal('NaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.logical_and(101, context=None)) + self.assertEqual(ans, '101') + self.assertRaises(InvalidOperation, x.logical_and, 123, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.logical_or(101, context=None)) + self.assertEqual(ans, '111') + self.assertRaises(InvalidOperation, x.logical_or, 123, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.logical_xor(101, context=None)) + self.assertEqual(ans, '10') + self.assertRaises(InvalidOperation, x.logical_xor, 123, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.max(101, context=None)) + self.assertEqual(ans, '111') + self.assertRaises(InvalidOperation, x.max, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.max_mag(101, context=None)) + self.assertEqual(ans, '111') + self.assertRaises(InvalidOperation, x.max_mag, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.min(101, context=None)) + self.assertEqual(ans, '101') + self.assertRaises(InvalidOperation, x.min, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.min_mag(101, context=None)) + self.assertEqual(ans, '101') + self.assertRaises(InvalidOperation, x.min_mag, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.remainder_near(101, context=None)) + self.assertEqual(ans, '10') + self.assertRaises(InvalidOperation, y.remainder_near, 101, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.rotate(2, context=None)) + self.assertEqual(ans, '11100') + self.assertRaises(InvalidOperation, x.rotate, 101, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.scaleb(7, context=None)) + self.assertEqual(ans, '1.11E+9') + self.assertRaises(InvalidOperation, x.scaleb, 10000, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.shift(2, context=None)) + self.assertEqual(ans, '11100') + self.assertRaises(InvalidOperation, x.shift, 10000, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + + ##### Ternary functions + c.clear_flags() + ans = str(x.fma(2, 3, context=None)) + self.assertEqual(ans, '225') + self.assertRaises(Overflow, x.fma, Decimal('1e9999'), 3, context=None) + self.assertTrue(c.flags[Overflow]) + + + ##### Special cases + c.rounding = ROUND_HALF_EVEN + ans = str(Decimal('1.5').to_integral(rounding=None, context=None)) + self.assertEqual(ans, '2') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.5').to_integral(rounding=None, context=None)) + self.assertEqual(ans, '1') + ans = str(Decimal('1.5').to_integral(rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '2') + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal('sNaN').to_integral, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.rounding = ROUND_HALF_EVEN + ans = str(Decimal('1.5').to_integral_value(rounding=None, context=None)) + self.assertEqual(ans, '2') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.5').to_integral_value(rounding=None, context=None)) + self.assertEqual(ans, '1') + ans = str(Decimal('1.5').to_integral_value(rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '2') + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal('sNaN').to_integral_value, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.rounding = ROUND_HALF_EVEN + ans = str(Decimal('1.5').to_integral_exact(rounding=None, context=None)) + self.assertEqual(ans, '2') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.5').to_integral_exact(rounding=None, context=None)) + self.assertEqual(ans, '1') + ans = str(Decimal('1.5').to_integral_exact(rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '2') + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal('sNaN').to_integral_exact, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.rounding = ROUND_UP + ans = str(Decimal('1.50001').quantize(exp=Decimal('1e-3'), rounding=None, context=None)) + self.assertEqual(ans, '1.501') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.50001').quantize(exp=Decimal('1e-3'), rounding=None, context=None)) + self.assertEqual(ans, '1.500') + ans = str(Decimal('1.50001').quantize(exp=Decimal('1e-3'), rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '1.501') + c.clear_flags() + self.assertRaises(InvalidOperation, y.quantize, Decimal('1e-10'), rounding=ROUND_UP, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + with localcontext(Context()) as context: + context.prec = 7 + context.Emax = 999 + context.Emin = -999 + with localcontext(ctx=None) as c: + self.assertEqual(c.prec, 7) + self.assertEqual(c.Emax, 999) + self.assertEqual(c.Emin, -999) + def test_conversions_from_int(self): # Check that methods taking a second Decimal argument will # always accept an integer in place of a Decimal. @@ -2423,14 +2665,11 @@ self.assertRaises(TypeError, D.from_float, 1.1, context=xc) self.assertRaises(TypeError, D(0).as_tuple, context=xc) - if (self.decimal == C): - self.assertRaises(TypeError, D(1).canonical, context=xc) - self.assertEqual(D("-1").copy_abs(context=xc), 1) - self.assertEqual(D("1").copy_negate(context=xc), -1) - else: - self.assertEqual(D(1).canonical(context=xc), 1) - self.assertRaises(TypeError, D("-1").copy_abs, context=xc) - self.assertRaises(TypeError, D("-1").copy_negate, context=xc) + self.assertEqual(D(1).canonical(), 1) + self.assertRaises(TypeError, D("-1").copy_abs, context=xc) + self.assertRaises(TypeError, D("-1").copy_negate, context=xc) + self.assertRaises(TypeError, D(1).canonical, context="x") + self.assertRaises(TypeError, D(1).canonical, xyz="x") def test_exception_hierarchy(self): @@ -4593,6 +4832,9 @@ # Invalid local context self.assertRaises(TypeError, exec, 'with localcontext("xyz"): pass', locals()) + self.assertRaises(TypeError, exec, + 'with localcontext(context=getcontext()): pass', + locals()) # setcontext saved_context = getcontext() @@ -4826,6 +5068,50 @@ c.prec = 2 self.assertRaises(InvalidOperation, pow, Decimal(1000), 1, 501) + def test_va_args_exceptions(self): + Decimal = C.Decimal + Context = C.Context + + x = Decimal("10001111111") + + for attr in ['exp', 'is_normal', 'is_subnormal', 'ln', 'log10', + 'logb', 'logical_invert', 'next_minus', 'next_plus', + 'normalize', 'number_class', 'sqrt', 'to_eng_string']: + func = getattr(x, attr) + self.assertRaises(TypeError, func, context="x") + self.assertRaises(TypeError, func, "x", context=None) + + for attr in ['compare', 'compare_signal', 'logical_and', + 'logical_or', 'max', 'max_mag', 'min', 'min_mag', + 'remainder_near', 'rotate', 'scaleb', 'shift']: + func = getattr(x, attr) + self.assertRaises(TypeError, func, context="x") + self.assertRaises(TypeError, func, "x", context=None) + + self.assertRaises(TypeError, x.to_integral, rounding=None, context=[]) + self.assertRaises(TypeError, x.to_integral, rounding={}, context=[]) + self.assertRaises(TypeError, x.to_integral, [], []) + + self.assertRaises(TypeError, x.to_integral_value, rounding=None, context=[]) + self.assertRaises(TypeError, x.to_integral_value, rounding={}, context=[]) + self.assertRaises(TypeError, x.to_integral_value, [], []) + + self.assertRaises(TypeError, x.to_integral_exact, rounding=None, context=[]) + self.assertRaises(TypeError, x.to_integral_exact, rounding={}, context=[]) + self.assertRaises(TypeError, x.to_integral_exact, [], []) + + self.assertRaises(TypeError, x.fma, 1, 2, context="x") + self.assertRaises(TypeError, x.fma, 1, 2, "x", context=None) + + self.assertRaises(TypeError, x.quantize, 1, [], context=None) + self.assertRaises(TypeError, x.quantize, 1, [], rounding=None) + self.assertRaises(TypeError, x.quantize, 1, [], []) + + c = Context() + self.assertRaises(TypeError, c.power, 1, 2, mod="x") + self.assertRaises(TypeError, c.power, 1, "x", mod=None) + self.assertRaises(TypeError, c.power, "x", 2, mod=None) + @requires_extra_functionality def test_c_context_templates(self): self.assertEqual( diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,10 @@ Library ------- +- Issue #15783: Except for the number methods, the C version of decimal now + supports all None default values present in decimal.py. These values were + largely undocumented. + - Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1486,7 +1486,10 @@ } #define CONTEXT_CHECK_VA(obj) \ - if (!PyDecContext_Check(obj)) { \ + if (obj == Py_None) { \ + CURRENT_CONTEXT(obj); \ + } \ + else if (!PyDecContext_Check(obj)) { \ PyErr_SetString(PyExc_TypeError, \ "optional argument must be a context"); \ return NULL; \ @@ -1715,18 +1718,25 @@ * owns one reference to the global (outer) context and one * to the local (inner) context. */ static PyObject * -ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args) +ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"ctx", NULL}; PyDecContextManagerObject *self; - PyObject *local; + PyObject *local = Py_None; PyObject *global; CURRENT_CONTEXT(global); - local = global; - if (!PyArg_ParseTuple(args, "|O", &local)) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &local)) { return NULL; } - CONTEXT_CHECK_VA(local); + if (local == Py_None) { + local = global; + } + else if (!PyDecContext_Check(local)) { + PyErr_SetString(PyExc_TypeError, + "optional argument must be a context"); + return NULL; + } self = PyObject_New(PyDecContextManagerObject, &PyDecContextManager_Type); @@ -2749,9 +2759,8 @@ { static char *kwlist[] = {"value", "context", NULL}; PyObject *v = NULL; - PyObject *context; - - CURRENT_CONTEXT(context); + PyObject *context = Py_None; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &v, &context)) { return NULL; @@ -3315,20 +3324,23 @@ { static char *kwlist[] = {"rounding", "context", NULL}; PyObject *result; - PyObject *context; + PyObject *rounding = Py_None; + PyObject *context = Py_None; uint32_t status = 0; mpd_context_t workctx; - int round = -1; - - CURRENT_CONTEXT(context); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO", kwlist, - &round, &context)) { + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, + &rounding, &context)) { return NULL; } CONTEXT_CHECK_VA(context); workctx = *CTX(context); - if (round >= 0) { + if (rounding != Py_None) { + int round = getround(rounding); + if (round < 0) { + return NULL; + } if (!mpd_qsetround(&workctx, round)) { return type_error_ptr(invalid_rounding_err); } @@ -3353,20 +3365,23 @@ { static char *kwlist[] = {"rounding", "context", NULL}; PyObject *result; - PyObject *context; + PyObject *rounding = Py_None; + PyObject *context = Py_None; uint32_t status = 0; mpd_context_t workctx; - int round = -1; - - CURRENT_CONTEXT(context); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO", kwlist, - &round, &context)) { + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, + &rounding, &context)) { return NULL; } CONTEXT_CHECK_VA(context); workctx = *CTX(context); - if (round >= 0) { + if (rounding != Py_None) { + int round = getround(rounding); + if (round < 0) { + return NULL; + } if (!mpd_qsetround(&workctx, round)) { return type_error_ptr(invalid_rounding_err); } @@ -3633,9 +3648,8 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"context", NULL}; \ - PyObject *context; \ + PyObject *context = Py_None; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ &context)) { \ return NULL; \ @@ -3652,10 +3666,9 @@ { \ static char *kwlist[] = {"context", NULL}; \ PyObject *result; \ - PyObject *context; \ + PyObject *context = Py_None; \ uint32_t status = 0; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ &context)) { \ return NULL; \ @@ -3675,49 +3688,18 @@ return result; \ } -/* Unary function with an optional context arg. The actual MPDFUNC - only takes a status parameter. */ -#define Dec_UnaryFuncVA_NO_CTX(MPDFUNC) \ -static PyObject * \ -dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ -{ \ - static char *kwlist[] = {"context", NULL}; \ - PyObject *result; \ - PyObject *context; \ - uint32_t status = 0; \ - \ - CURRENT_CONTEXT(context); \ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ - &context)) { \ - return NULL; \ - } \ - CONTEXT_CHECK_VA(context); \ - \ - if ((result = dec_alloc()) == NULL) { \ - return NULL; \ - } \ - \ - MPDFUNC(MPD(result), MPD(self), &status); \ - if (dec_addstatus(context, status)) { \ - Py_DECREF(result); \ - return NULL; \ - } \ - \ - return result; \ -} - /* Binary function with an optional context arg. */ #define Dec_BinaryFuncVA(MPDFUNC) \ static PyObject * \ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"other", "context", NULL}; \ - PyObject *other, *context; \ + PyObject *other; \ PyObject *a, *b; \ PyObject *result; \ + PyObject *context = Py_None; \ uint32_t status = 0; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, \ &other, &context)) { \ return NULL; \ @@ -3750,11 +3732,11 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"other", "context", NULL}; \ - PyObject *other, *context; \ + PyObject *context = Py_None; \ + PyObject *other; \ PyObject *a, *b; \ PyObject *result; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, \ &other, &context)) { \ return NULL; \ @@ -3781,12 +3763,12 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"other", "third", "context", NULL}; \ - PyObject *other, *third, *context; \ + PyObject *other, *third; \ PyObject *a, *b, *c; \ PyObject *result; \ + PyObject *context = Py_None; \ uint32_t status = 0; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O", kwlist, \ &other, &third, &context)) { \ return NULL; \ @@ -4019,9 +4001,45 @@ return result; } -/* Unary functions, optional context arg for conversion errors */ -Dec_UnaryFuncVA_NO_CTX(mpd_qcopy_abs) -Dec_UnaryFuncVA_NO_CTX(mpd_qcopy_negate) +static PyObject * +dec_mpd_qcopy_abs(PyObject *self, PyObject *dummy UNUSED) +{ + PyObject *result; + uint32_t status = 0; + + if ((result = dec_alloc()) == NULL) { + return NULL; + } + + mpd_qcopy_abs(MPD(result), MPD(self), &status); + if (status & MPD_Malloc_error) { + Py_DECREF(result); + PyErr_NoMemory(); + return NULL; + } + + return result; +} + +static PyObject * +dec_mpd_qcopy_negate(PyObject *self, PyObject *dummy UNUSED) +{ + PyObject *result; + uint32_t status = 0; + + if ((result = dec_alloc()) == NULL) { + return NULL; + } + + mpd_qcopy_negate(MPD(result), MPD(self), &status); + if (status & MPD_Malloc_error) { + Py_DECREF(result); + PyErr_NoMemory(); + return NULL; + } + + return result; +} /* Unary functions, optional context arg */ Dec_UnaryFuncVA(mpd_qinvert) @@ -4031,10 +4049,9 @@ dec_mpd_class(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"context", NULL}; - PyObject *context; + PyObject *context = Py_None; const char *cp; - CURRENT_CONTEXT(context); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &context)) { return NULL; @@ -4050,11 +4067,10 @@ { static char *kwlist[] = {"context", NULL}; PyObject *result; - PyObject *context; + PyObject *context = Py_None; mpd_ssize_t size; char *s; - CURRENT_CONTEXT(context); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &context)) { return NULL; @@ -4081,12 +4097,12 @@ dec_mpd_qcopy_sign(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"other", "context", NULL}; - PyObject *other, *context; + PyObject *other; PyObject *a, *b; PyObject *result; + PyObject *context = Py_None; uint32_t status = 0; - CURRENT_CONTEXT(context); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, &other, &context)) { return NULL; @@ -4116,11 +4132,11 @@ dec_mpd_same_quantum(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"other", "context", NULL}; - PyObject *other, *context; + PyObject *other; PyObject *a, *b; PyObject *result; - - CURRENT_CONTEXT(context); + PyObject *context = Py_None; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, &other, &context)) { return NULL; @@ -4148,22 +4164,25 @@ dec_mpd_qquantize(PyObject *v, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"exp", "rounding", "context", NULL}; - PyObject *w, *context; - PyObject *a, *b; + PyObject *rounding = Py_None; + PyObject *context = Py_None; + PyObject *w, *a, *b; PyObject *result; uint32_t status = 0; mpd_context_t workctx; - int round = -1; - - CURRENT_CONTEXT(context); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO", kwlist, - &w, &round, &context)) { + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, + &w, &rounding, &context)) { return NULL; } CONTEXT_CHECK_VA(context); workctx = *CTX(context); - if (round >= 0) { + if (rounding != Py_None) { + int round = getround(rounding); + if (round < 0) { + return NULL; + } if (!mpd_qsetround(&workctx, round)) { return type_error_ptr(invalid_rounding_err); } @@ -4585,8 +4604,8 @@ { "radix", dec_mpd_radix, METH_NOARGS, doc_radix }, /* Unary functions, optional context arg for conversion errors */ - { "copy_abs", (PyCFunction)dec_mpd_qcopy_abs, METH_VARARGS|METH_KEYWORDS, doc_copy_abs }, - { "copy_negate", (PyCFunction)dec_mpd_qcopy_negate, METH_VARARGS|METH_KEYWORDS, doc_copy_negate }, + { "copy_abs", dec_mpd_qcopy_abs, METH_NOARGS, doc_copy_abs }, + { "copy_negate", dec_mpd_qcopy_negate, METH_NOARGS, doc_copy_negate }, /* Unary functions, optional context arg */ { "logb", (PyCFunction)dec_mpd_qlogb, METH_VARARGS|METH_KEYWORDS, doc_logb }, @@ -4916,7 +4935,7 @@ ctx_mpd_qpow(PyObject *context, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"a", "b", "modulo", NULL}; - PyObject *base, *exp, *mod = NULL; + PyObject *base, *exp, *mod = Py_None; PyObject *a, *b, *c = NULL; PyObject *result; uint32_t status = 0; @@ -4928,7 +4947,7 @@ CONVERT_BINOP_RAISE(&a, &b, base, exp, context); - if (mod != NULL) { + if (mod != Py_None) { if (!convert_op(TYPE_ERR, &c, mod, context)) { Py_DECREF(a); Py_DECREF(b); @@ -5361,7 +5380,7 @@ { { "getcontext", (PyCFunction)PyDec_GetCurrentContext, METH_NOARGS, doc_getcontext}, { "setcontext", (PyCFunction)PyDec_SetCurrentContext, METH_O, doc_setcontext}, - { "localcontext", (PyCFunction)ctxmanager_new, METH_VARARGS, doc_localcontext}, + { "localcontext", (PyCFunction)ctxmanager_new, METH_VARARGS|METH_KEYWORDS, doc_localcontext}, #ifdef EXTRA_FUNCTIONALITY { "IEEEContext", (PyCFunction)ieee_context, METH_O, doc_ieee_context}, #endif diff --git a/Modules/_decimal/docstrings.h b/Modules/_decimal/docstrings.h --- a/Modules/_decimal/docstrings.h +++ b/Modules/_decimal/docstrings.h @@ -28,10 +28,10 @@ \n"); PyDoc_STRVAR(doc_localcontext,"\n\ -localcontext(c) - Return a context manager that will set the default context\n\ -to a copy of c on entry to the with-statement and restore the previous default\n\ -context when exiting the with-statement. If no context is specified, a copy of\n\ -the current default context is used.\n\ +localcontext(ctx=None) - Return a context manager that will set the default\n\ +context to a copy of ctx on entry to the with-statement and restore the\n\ +previous default context when exiting the with-statement. If no context is\n\ +specified, a copy of the current default context is used.\n\ \n"); #ifdef EXTRA_FUNCTIONALITY @@ -49,8 +49,7 @@ /******************************************************************************/ PyDoc_STRVAR(doc_decimal,"\n\ -Decimal([value[, context]]): Construct a new Decimal object from value.\n\ -\n\ +Decimal(value=\"0\", context=None): Construct a new Decimal object.\n\ value can be an integer, string, tuple, or another Decimal object.\n\ If no value is given, return Decimal('0'). The context does not affect\n\ the conversion and is only passed to determine if the InvalidOperation\n\ @@ -74,7 +73,7 @@ \n"); PyDoc_STRVAR(doc_compare,"\n\ -compare(other[, context]) - Compare self to other. Return a decimal value:\n\ +compare(other, context=None) - Compare self to other. Return a decimal value:\n\ \n\ a or b is a NaN ==> Decimal('NaN')\n\ a < b ==> Decimal('-1')\n\ @@ -83,16 +82,16 @@ \n"); PyDoc_STRVAR(doc_compare_signal,"\n\ -compare_signal(other[, context]) - Identical to compare, except that\n\ +compare_signal(other, context=None) - Identical to compare, except that\n\ all NaNs signal.\n\ \n"); PyDoc_STRVAR(doc_compare_total,"\n\ -compare_total(other) - Compare two operands using their abstract representation\n\ -rather than their numerical value. Similar to the compare() method, but the\n\ -result gives a total ordering on Decimal instances. Two Decimal instances with\n\ -the same numeric value but different representations compare unequal in this\n\ -ordering:\n\ +compare_total(other, context=None) - Compare two operands using their\n\ +abstract representation rather than their numerical value. Similar to the\n\ +compare() method, but the result gives a total ordering on Decimal instances.\n\ +Two Decimal instances with the same numeric value but different representations\n\ +compare unequal in this ordering:\n\ \n\ >>> Decimal('12.0').compare_total(Decimal('12'))\n\ Decimal('-1')\n\ @@ -102,13 +101,21 @@ Decimal('-1') if the first operand is lower in the total order than the second,\n\ and Decimal('1') if the first operand is higher in the total order than the\n\ second operand. See the specification for details of the total order.\n\ +\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_compare_total_mag,"\n\ -compare_total_mag(other) - Compare two operands using their abstract\n\ -representation rather than their value as in compare_total(), but\n\ -ignoring the sign of each operand. x.compare_total_mag(y) is\n\ -equivalent to x.copy_abs().compare_total(y.copy_abs()).\n\ +compare_total_mag(other, context=None) - Compare two operands using their\n\ +abstract representation rather than their value as in compare_total(), but\n\ +ignoring the sign of each operand. x.compare_total_mag(y) is equivalent to\n\ +x.copy_abs().compare_total(y.copy_abs()).\n\ +\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_conjugate,"\n\ @@ -117,31 +124,32 @@ PyDoc_STRVAR(doc_copy_abs,"\n\ copy_abs() - Return the absolute value of the argument. This operation\n\ -is unaffected by the context and is quiet: no flags are changed and no\n\ -rounding is performed.\n\ +is unaffected by context and is quiet: no flags are changed and no rounding\n\ +is performed.\n\ \n"); PyDoc_STRVAR(doc_copy_negate,"\n\ copy_negate() - Return the negation of the argument. This operation is\n\ -unaffected by the context and is quiet: no flags are changed and no\n\ -rounding is performed.\n\ +unaffected by context and is quiet: no flags are changed and no rounding\n\ +is performed.\n\ \n"); PyDoc_STRVAR(doc_copy_sign,"\n\ -copy_sign(other) - Return a copy of the first operand with the sign set\n\ -to be the same as the sign of the second operand. For example:\n\ +copy_sign(other, context=None) - Return a copy of the first operand with\n\ +the sign set to be the same as the sign of the second operand. For example:\n\ \n\ >>> Decimal('2.3').copy_sign(Decimal('-1.5'))\n\ Decimal('-2.3')\n\ \n\ -This operation is unaffected by the context and is quiet: no flags are\n\ -changed and no rounding is performed.\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_exp,"\n\ -exp([context]) - Return the value of the (natural) exponential function e**x\n\ -at the given number. The function always uses the ROUND_HALF_EVEN mode and\n\ -the result is correctly rounded.\n\ +exp(context=None) - Return the value of the (natural) exponential function\n\ +e**x at the given number. The function always uses the ROUND_HALF_EVEN mode\n\ +and the result is correctly rounded.\n\ \n"); PyDoc_STRVAR(doc_from_float,"\n\ @@ -161,7 +169,7 @@ \n"); PyDoc_STRVAR(doc_fma,"\n\ -fma(other, third[, context]) - Fused multiply-add. Return self*other+third\n\ +fma(other, third, context=None) - Fused multiply-add. Return self*other+third\n\ with no rounding of the intermediate product self*other.\n\ \n\ >>> Decimal(2).fma(3, 5)\n\ @@ -191,9 +199,9 @@ \n"); PyDoc_STRVAR(doc_is_normal,"\n\ -is_normal([context]) - Return True if the argument is a normal finite non-zero\n\ -number with an adjusted exponent greater than or equal to Emin. Return False\n\ -if the argument is zero, subnormal, infinite or a NaN.\n\ +is_normal(context=None) - Return True if the argument is a normal finite\n\ +non-zero number with an adjusted exponent greater than or equal to Emin.\n\ +Return False if the argument is zero, subnormal, infinite or a NaN.\n\ \n"); PyDoc_STRVAR(doc_is_qnan,"\n\ @@ -210,8 +218,8 @@ \n"); PyDoc_STRVAR(doc_is_subnormal,"\n\ -is_subnormal([context]) - Return True if the argument is subnormal, and False\n\ -otherwise. A number is subnormal if it is non-zero, finite, and has an\n\ +is_subnormal(context=None) - Return True if the argument is subnormal, and\n\ +False otherwise. A number is subnormal if it is non-zero, finite, and has an\n\ adjusted exponent less than Emin.\n\ \n"); @@ -221,94 +229,94 @@ \n"); PyDoc_STRVAR(doc_ln,"\n\ -ln([context]) - Return the natural (base e) logarithm of the operand.\n\ +ln(context=None) - Return the natural (base e) logarithm of the operand.\n\ The function always uses the ROUND_HALF_EVEN mode and the result is\n\ correctly rounded.\n\ \n"); PyDoc_STRVAR(doc_log10,"\n\ -log10([context]) - Return the base ten logarithm of the operand.\n\ +log10(context=None) - Return the base ten logarithm of the operand.\n\ The function always uses the ROUND_HALF_EVEN mode and the result is\n\ correctly rounded.\n\ \n"); PyDoc_STRVAR(doc_logb,"\n\ -logb([context]) - For a non-zero number, return the adjusted exponent\n\ +logb(context=None) - For a non-zero number, return the adjusted exponent\n\ of the operand as a Decimal instance. If the operand is a zero, then\n\ Decimal('-Infinity') is returned and the DivisionByZero condition is\n\ raised. If the operand is an infinity then Decimal('Infinity') is returned.\n\ \n"); PyDoc_STRVAR(doc_logical_and,"\n\ -logical_and(other[, context]) - Return the digit-wise and of the two\n\ +logical_and(other, context=None) - Return the digit-wise and of the two\n\ (logical) operands.\n\ \n"); PyDoc_STRVAR(doc_logical_invert,"\n\ -logical_invert([context]) - Return the digit-wise inversion of the\n\ +logical_invert(context=None) - Return the digit-wise inversion of the\n\ (logical) operand.\n\ \n"); PyDoc_STRVAR(doc_logical_or,"\n\ -logical_or(other[, context]) - Return the digit-wise or of the two\n\ +logical_or(other, context=None) - Return the digit-wise or of the two\n\ (logical) operands.\n\ \n"); PyDoc_STRVAR(doc_logical_xor,"\n\ -logical_xor(other[, context]) - Return the digit-wise exclusive or of the\n\ +logical_xor(other, context=None) - Return the digit-wise exclusive or of the\n\ two (logical) operands.\n\ \n"); PyDoc_STRVAR(doc_max,"\n\ -max(other[, context]) - Maximum of self and other. If one operand is a quiet\n\ -NaN and the other is numeric, the numeric operand is returned.\n\ +max(other, context=None) - Maximum of self and other. If one operand is a\n\ +quiet NaN and the other is numeric, the numeric operand is returned.\n\ \n"); PyDoc_STRVAR(doc_max_mag,"\n\ -max_mag(other[, context]) - Similar to the max() method, but the comparison is\n\ -done using the absolute values of the operands.\n\ +max_mag(other, context=None) - Similar to the max() method, but the\n\ +comparison is done using the absolute values of the operands.\n\ \n"); PyDoc_STRVAR(doc_min,"\n\ -min(other[, context]) - Minimum of self and other. If one operand is a quiet\n\ -NaN and the other is numeric, the numeric operand is returned.\n\ +min(other, context=None) - Minimum of self and other. If one operand is a\n\ +quiet NaN and the other is numeric, the numeric operand is returned.\n\ \n"); PyDoc_STRVAR(doc_min_mag,"\n\ -min_mag(other[, context]) - Similar to the min() method, but the comparison is\n\ -done using the absolute values of the operands.\n\ +min_mag(other, context=None) - Similar to the min() method, but the\n\ +comparison is done using the absolute values of the operands.\n\ \n"); PyDoc_STRVAR(doc_next_minus,"\n\ -next_minus([context]) - Return the largest number representable in the given\n\ -context (or in the current default context if no context is given) that is\n\ -smaller than the given operand.\n\ +next_minus(context=None) - Return the largest number representable in the\n\ +given context (or in the current default context if no context is given) that\n\ +is smaller than the given operand.\n\ \n"); PyDoc_STRVAR(doc_next_plus,"\n\ -next_plus([context]) - Return the smallest number representable in the given\n\ -context (or in the current default context if no context is given) that is\n\ -larger than the given operand.\n\ +next_plus(context=None) - Return the smallest number representable in the\n\ +given context (or in the current default context if no context is given) that\n\ +is larger than the given operand.\n\ \n"); PyDoc_STRVAR(doc_next_toward,"\n\ -next_toward(other[, context]) - If the two operands are unequal, return the\n\ -number closest to the first operand in the direction of the second operand.\n\ +next_toward(other, context=None) - If the two operands are unequal, return\n\ +the number closest to the first operand in the direction of the second operand.\n\ If both operands are numerically equal, return a copy of the first operand\n\ with the sign set to be the same as the sign of the second operand.\n\ \n"); PyDoc_STRVAR(doc_normalize,"\n\ -normalize([context]) - Normalize the number by stripping the rightmost trailing\n\ -zeros and converting any result equal to Decimal('0') to Decimal('0e0'). Used\n\ -for producing canonical values for members of an equivalence class. For example,\n\ -Decimal('32.100') and Decimal('0.321000e+2') both normalize to the equivalent\n\ -value Decimal('32.1').\n\ +normalize(context=None) - Normalize the number by stripping the rightmost\n\ +trailing zeros and converting any result equal to Decimal('0') to Decimal('0e0').\n\ +Used for producing canonical values for members of an equivalence class. For\n\ +example, Decimal('32.100') and Decimal('0.321000e+2') both normalize to the\n\ +equivalent value Decimal('32.1').\n\ \n"); PyDoc_STRVAR(doc_number_class,"\n\ -number_class([context]) - Return a string describing the class of the operand.\n\ -The returned value is one of the following ten strings:\n\ +number_class(context=None) - Return a string describing the class of the\n\ +operand. The returned value is one of the following ten strings:\n\ \n\ * '-Infinity', indicating that the operand is negative infinity.\n\ * '-Normal', indicating that the operand is a negative normal number.\n\ @@ -324,8 +332,8 @@ \n"); PyDoc_STRVAR(doc_quantize,"\n\ -quantize(exp[, rounding[, context]]) - Return a value equal to the first\n\ -operand after rounding and having the exponent of the second operand.\n\ +quantize(exp, rounding=None, context=None) - Return a value equal to the\n\ +first operand after rounding and having the exponent of the second operand.\n\ \n\ >>> Decimal('1.41421356').quantize(Decimal('1.000'))\n\ Decimal('1.414')\n\ @@ -350,16 +358,18 @@ \n"); PyDoc_STRVAR(doc_remainder_near,"\n\ -remainder_near(other[, context]) - Compute the modulo as either a positive\n\ -or negative value depending on which is closest to zero. For instance,\n\ -Decimal(10).remainder_near(6) returns Decimal('-2'), which is closer to zero\n\ -than Decimal('4').\n\ +remainder_near(other, context=None) - Return the remainder from dividing\n\ +self by other. This differs from self % other in that the sign of the\n\ +remainder is chosen so as to minimize its absolute value. More precisely, the\n\ +return value is self - n * other where n is the integer nearest to the exact\n\ +value of self / other, and if two integers are equally near then the even one\n\ +is chosen.\n\ \n\ -If both are equally close, the one chosen will have the same sign as self.\n\ +If the result is zero then its sign will be the sign of self.\n\ \n"); PyDoc_STRVAR(doc_rotate,"\n\ -rotate(other[, context]) - Return the result of rotating the digits of the\n\ +rotate(other, context=None) - Return the result of rotating the digits of the\n\ first operand by an amount specified by the second operand. The second operand\n\ must be an integer in the range -precision through precision. The absolute\n\ value of the second operand gives the number of places to rotate. If the second\n\ @@ -370,18 +380,22 @@ \n"); PyDoc_STRVAR(doc_same_quantum,"\n\ -same_quantum(other[, context]) - Test whether self and other have the\n\ +same_quantum(other, context=None) - Test whether self and other have the\n\ same exponent or whether both are NaN.\n\ +\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_scaleb,"\n\ -scaleb(other[, context]) - Return the first operand with the exponent adjusted\n\ -the second. Equivalently, return the first operand multiplied by 10**other.\n\ -The second operand must be an integer.\n\ +scaleb(other, context=None) - Return the first operand with the exponent\n\ +adjusted the second. Equivalently, return the first operand multiplied by\n\ +10**other. The second operand must be an integer.\n\ \n"); PyDoc_STRVAR(doc_shift,"\n\ -shift(other[, context]) - Return the result of shifting the digits of\n\ +shift(other, context=None) - Return the result of shifting the digits of\n\ the first operand by an amount specified by the second operand. The second\n\ operand must be an integer in the range -precision through precision. The\n\ absolute value of the second operand gives the number of places to shift.\n\ @@ -391,36 +405,40 @@ \n"); PyDoc_STRVAR(doc_sqrt,"\n\ -sqrt([context]) - Return the square root of the argument to full precision.\n\ +sqrt(context=None) - Return the square root of the argument to full precision.\n\ The result is correctly rounded using the ROUND_HALF_EVEN rounding mode.\n\ \n"); PyDoc_STRVAR(doc_to_eng_string,"\n\ -to_eng_string([context]) - Convert to an engineering-type string.\n\ -Engineering notation has an exponent which is a multiple of 3, so\n\ -there are up to 3 digits left of the decimal place. For example,\n\ -Decimal('123E+1') is converted to Decimal('1.23E+3')\n\ +to_eng_string(context=None) - Convert to an engineering-type string.\n\ +Engineering notation has an exponent which is a multiple of 3, so there\n\ +are up to 3 digits left of the decimal place. For example, Decimal('123E+1')\n\ +is converted to Decimal('1.23E+3').\n\ +\n\ +The value of context.capitals determines whether the exponent sign is lower\n\ +or upper case. Otherwise, the context does not affect the operation.\n\ \n"); PyDoc_STRVAR(doc_to_integral,"\n\ -to_integral([rounding[, context]]) - Identical to the to_integral_value()\n\ -method. The to_integral name has been kept for compatibility with older\n\ -versions.\n\ +to_integral(rounding=None, context=None) - Identical to the\n\ +to_integral_value() method. The to_integral() name has been kept\n\ +for compatibility with older versions.\n\ \n"); PyDoc_STRVAR(doc_to_integral_exact,"\n\ -to_integral_exact([rounding[, context]]) - Round to the nearest integer,\n\ -signaling Inexact or Rounded as appropriate if rounding occurs. The rounding\n\ -mode is determined by the rounding parameter if given, else by the given\n\ -context. If neither parameter is given, then the rounding mode of the current\n\ -default context is used.\n\ +to_integral_exact(rounding=None, context=None) - Round to the nearest\n\ +integer, signaling Inexact or Rounded as appropriate if rounding occurs.\n\ +The rounding mode is determined by the rounding parameter if given, else\n\ +by the given context. If neither parameter is given, then the rounding mode\n\ +of the current default context is used.\n\ \n"); PyDoc_STRVAR(doc_to_integral_value,"\n\ -to_integral_value([rounding[, context]]) - Round to the nearest integer without\n\ -signaling Inexact or Rounded. The rounding mode is determined by the rounding\n\ -parameter if given, else by the given context. If neither parameter is given,\n\ -then the rounding mode of the current default context is used.\n\ +to_integral_value(rounding=None, context=None) - Round to the nearest\n\ +integer without signaling Inexact or Rounded. The rounding mode is determined\n\ +by the rounding parameter if given, else by the given context. If neither\n\ +parameter is given, then the rounding mode of the current default context is\n\ +used.\n\ \n"); diff --git a/Modules/_decimal/tests/deccheck.py b/Modules/_decimal/tests/deccheck.py --- a/Modules/_decimal/tests/deccheck.py +++ b/Modules/_decimal/tests/deccheck.py @@ -36,6 +36,7 @@ from collections import defaultdict from test.support import import_fresh_module from randdec import randfloat, all_unary, all_binary, all_ternary +from randdec import unary_optarg, binary_optarg, ternary_optarg from formathelper import rand_format, rand_locale C = import_fresh_module('decimal', fresh=['_decimal']) @@ -834,6 +835,17 @@ except VerifyError as err: log(err) + if not method.startswith('__'): + for op in unary_optarg(prec, exp_range, itr): + t = TestSet(method, op) + try: + if not convert(t): + continue + callfuncs(t) + verify(t, stat) + except VerifyError as err: + log(err) + def test_binary(method, prec, exp_range, restricted_range, itr, stat): """Iterate a binary function through many test cases.""" if method in BinaryRestricted: @@ -848,6 +860,17 @@ except VerifyError as err: log(err) + if not method.startswith('__'): + for op in binary_optarg(prec, exp_range, itr): + t = TestSet(method, op) + try: + if not convert(t): + continue + callfuncs(t) + verify(t, stat) + except VerifyError as err: + log(err) + def test_ternary(method, prec, exp_range, restricted_range, itr, stat): """Iterate a ternary function through many test cases.""" if method in TernaryRestricted: @@ -862,6 +885,17 @@ except VerifyError as err: log(err) + if not method.startswith('__'): + for op in ternary_optarg(prec, exp_range, itr): + t = TestSet(method, op) + try: + if not convert(t): + continue + callfuncs(t) + verify(t, stat) + except VerifyError as err: + log(err) + def test_format(method, prec, exp_range, restricted_range, itr, stat): """Iterate the __format__ method through many test cases.""" for op in all_unary(prec, exp_range, itr): diff --git a/Modules/_decimal/tests/randdec.py b/Modules/_decimal/tests/randdec.py --- a/Modules/_decimal/tests/randdec.py +++ b/Modules/_decimal/tests/randdec.py @@ -527,6 +527,11 @@ for _ in range(100): yield (randtuple(prec, exp_range),) +def unary_optarg(prec, exp_range, itr): + for _ in range(100): + yield randdec(prec, exp_range), None + yield randdec(prec, exp_range), None, None + def all_binary(prec, exp_range, itr): for a, b in bin_close_to_pow10(prec, exp_range, itr): yield a, b @@ -543,6 +548,11 @@ for _ in range(100): yield randdec(prec, exp_range), randdec(prec, exp_range) +def binary_optarg(prec, exp_range, itr): + for _ in range(100): + yield randdec(prec, exp_range), randdec(prec, exp_range), None + yield randdec(prec, exp_range), randdec(prec, exp_range), None, None + def all_ternary(prec, exp_range, itr): for a, b, c in tern_close_numbers(prec, exp_range, -exp_range, itr): yield a, b, c @@ -557,3 +567,11 @@ b = randdec(prec, 2*exp_range) c = randdec(prec, 2*exp_range) yield a, b, c + +def ternary_optarg(prec, exp_range, itr): + for _ in range(100): + a = randdec(prec, 2*exp_range) + b = randdec(prec, 2*exp_range) + c = randdec(prec, 2*exp_range) + yield a, b, c, None + yield a, b, c, None, None -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 15 22:40:33 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 15 Dec 2012 22:40:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4zLg==?= Message-ID: <3YP29Y734xzRgq@mail.python.org> http://hg.python.org/cpython/rev/7c9327ff5de6 changeset: 80873:7c9327ff5de6 parent: 80871:cd75923a102a parent: 80872:29becac5dd9b user: Stefan Krah date: Sat Dec 15 22:36:49 2012 +0100 summary: Merge 3.3. files: Doc/library/decimal.rst | 97 +++-- Lib/decimal.py | 12 +- Lib/test/test_decimal.py | 302 ++++++++++++++++- Misc/NEWS | 4 + Modules/_decimal/_decimal.c | 197 ++++++----- Modules/_decimal/docstrings.h | 206 ++++++----- Modules/_decimal/tests/deccheck.py | 34 + Modules/_decimal/tests/randdec.py | 18 + 8 files changed, 631 insertions(+), 239 deletions(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -459,7 +459,7 @@ a :class:`Decimal` instance is always canonical, so this operation returns its argument unchanged. - .. method:: compare(other[, context]) + .. method:: compare(other, context=None) Compare the values of two Decimal instances. :meth:`compare` returns a Decimal instance, and if either operand is a NaN then the result is a @@ -470,13 +470,13 @@ a == b ==> Decimal('0') a > b ==> Decimal('1') - .. method:: compare_signal(other[, context]) + .. method:: compare_signal(other, context=None) This operation is identical to the :meth:`compare` method, except that all NaNs signal. That is, if neither operand is a signaling NaN then any quiet NaN operand is treated as though it were a signaling NaN. - .. method:: compare_total(other) + .. method:: compare_total(other, context=None) Compare two operands using their abstract representation rather than their numerical value. Similar to the :meth:`compare` method, but the result @@ -494,13 +494,21 @@ higher in the total order than the second operand. See the specification for details of the total order. - .. method:: compare_total_mag(other) + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + + .. method:: compare_total_mag(other, context=None) Compare two operands using their abstract representation rather than their value as in :meth:`compare_total`, but ignoring the sign of each operand. ``x.compare_total_mag(y)`` is equivalent to ``x.copy_abs().compare_total(y.copy_abs())``. + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + .. method:: conjugate() Just returns self, this method is only to comply with the Decimal @@ -517,7 +525,7 @@ Return the negation of the argument. This operation is unaffected by the context and is quiet: no flags are changed and no rounding is performed. - .. method:: copy_sign(other) + .. method:: copy_sign(other, context=None) Return a copy of the first operand with the sign set to be the same as the sign of the second operand. For example: @@ -525,10 +533,11 @@ >>> Decimal('2.3').copy_sign(Decimal('-1.5')) Decimal('-2.3') - This operation is unaffected by the context and is quiet: no flags are - changed and no rounding is performed. - - .. method:: exp([context]) + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + + .. method:: exp(context=None) Return the value of the (natural) exponential function ``e**x`` at the given number. The result is correctly rounded using the @@ -565,7 +574,7 @@ .. versionadded:: 3.1 - .. method:: fma(other, third[, context]) + .. method:: fma(other, third, context=None) Fused multiply-add. Return self*other+third with no rounding of the intermediate product self*other. @@ -594,7 +603,7 @@ Return :const:`True` if the argument is a (quiet or signaling) NaN and :const:`False` otherwise. - .. method:: is_normal() + .. method:: is_normal(context=None) Return :const:`True` if the argument is a *normal* finite number. Return :const:`False` if the argument is zero, subnormal, infinite or a NaN. @@ -614,7 +623,7 @@ Return :const:`True` if the argument is a signaling NaN and :const:`False` otherwise. - .. method:: is_subnormal() + .. method:: is_subnormal(context=None) Return :const:`True` if the argument is subnormal, and :const:`False` otherwise. @@ -624,17 +633,17 @@ Return :const:`True` if the argument is a (positive or negative) zero and :const:`False` otherwise. - .. method:: ln([context]) + .. method:: ln(context=None) Return the natural (base e) logarithm of the operand. The result is correctly rounded using the :const:`ROUND_HALF_EVEN` rounding mode. - .. method:: log10([context]) + .. method:: log10(context=None) Return the base ten logarithm of the operand. The result is correctly rounded using the :const:`ROUND_HALF_EVEN` rounding mode. - .. method:: logb([context]) + .. method:: logb(context=None) For a nonzero number, return the adjusted exponent of its operand as a :class:`Decimal` instance. If the operand is a zero then @@ -642,73 +651,73 @@ is raised. If the operand is an infinity then ``Decimal('Infinity')`` is returned. - .. method:: logical_and(other[, context]) + .. method:: logical_and(other, context=None) :meth:`logical_and` is a logical operation which takes two *logical operands* (see :ref:`logical_operands_label`). The result is the digit-wise ``and`` of the two operands. - .. method:: logical_invert([context]) + .. method:: logical_invert(context=None) :meth:`logical_invert` is a logical operation. The result is the digit-wise inversion of the operand. - .. method:: logical_or(other[, context]) + .. method:: logical_or(other, context=None) :meth:`logical_or` is a logical operation which takes two *logical operands* (see :ref:`logical_operands_label`). The result is the digit-wise ``or`` of the two operands. - .. method:: logical_xor(other[, context]) + .. method:: logical_xor(other, context=None) :meth:`logical_xor` is a logical operation which takes two *logical operands* (see :ref:`logical_operands_label`). The result is the digit-wise exclusive or of the two operands. - .. method:: max(other[, context]) + .. method:: max(other, context=None) Like ``max(self, other)`` except that the context rounding rule is applied before returning and that :const:`NaN` values are either signaled or ignored (depending on the context and whether they are signaling or quiet). - .. method:: max_mag(other[, context]) + .. method:: max_mag(other, context=None) Similar to the :meth:`.max` method, but the comparison is done using the absolute values of the operands. - .. method:: min(other[, context]) + .. method:: min(other, context=None) Like ``min(self, other)`` except that the context rounding rule is applied before returning and that :const:`NaN` values are either signaled or ignored (depending on the context and whether they are signaling or quiet). - .. method:: min_mag(other[, context]) + .. method:: min_mag(other, context=None) Similar to the :meth:`.min` method, but the comparison is done using the absolute values of the operands. - .. method:: next_minus([context]) + .. method:: next_minus(context=None) Return the largest number representable in the given context (or in the current thread's context if no context is given) that is smaller than the given operand. - .. method:: next_plus([context]) + .. method:: next_plus(context=None) Return the smallest number representable in the given context (or in the current thread's context if no context is given) that is larger than the given operand. - .. method:: next_toward(other[, context]) + .. method:: next_toward(other, context=None) If the two operands are unequal, return the number closest to the first operand in the direction of the second operand. If both operands are numerically equal, return a copy of the first operand with the sign set to be the same as the sign of the second operand. - .. method:: normalize([context]) + .. method:: normalize(context=None) Normalize the number by stripping the rightmost trailing zeros and converting any result equal to :const:`Decimal('0')` to @@ -717,7 +726,7 @@ ``Decimal('0.321000e+2')`` both normalize to the equivalent value ``Decimal('32.1')``. - .. method:: number_class([context]) + .. method:: number_class(context=None) Return a string describing the *class* of the operand. The returned value is one of the following ten strings. @@ -733,7 +742,7 @@ * ``"NaN"``, indicating that the operand is a quiet NaN (Not a Number). * ``"sNaN"``, indicating that the operand is a signaling NaN. - .. method:: quantize(exp[, rounding[, context[, watchexp]]]) + .. method:: quantize(exp, rounding=None, context=None, watchexp=True) Return a value equal to the first operand after rounding and having the exponent of the second operand. @@ -771,7 +780,7 @@ class does all its arithmetic. Included for compatibility with the specification. - .. method:: remainder_near(other[, context]) + .. method:: remainder_near(other, context=None) Return the remainder from dividing *self* by *other*. This differs from ``self % other`` in that the sign of the remainder is chosen so as to @@ -789,7 +798,7 @@ >>> Decimal(35).remainder_near(Decimal(10)) Decimal('-5') - .. method:: rotate(other[, context]) + .. method:: rotate(other, context=None) Return the result of rotating the digits of the first operand by an amount specified by the second operand. The second operand must be an integer in @@ -800,18 +809,22 @@ length precision if necessary. The sign and exponent of the first operand are unchanged. - .. method:: same_quantum(other[, context]) + .. method:: same_quantum(other, context=None) Test whether self and other have the same exponent or whether both are :const:`NaN`. - .. method:: scaleb(other[, context]) + This operation is unaffected by context and is quiet: no flags are changed + and no rounding is performed. As an exception, the C version may raise + InvalidOperation if the second operand cannot be converted exactly. + + .. method:: scaleb(other, context=None) Return the first operand with exponent adjusted by the second. Equivalently, return the first operand multiplied by ``10**other``. The second operand must be an integer. - .. method:: shift(other[, context]) + .. method:: shift(other, context=None) Return the result of shifting the digits of the first operand by an amount specified by the second operand. The second operand must be an integer in @@ -821,12 +834,12 @@ right. Digits shifted into the coefficient are zeros. The sign and exponent of the first operand are unchanged. - .. method:: sqrt([context]) + .. method:: sqrt(context=None) Return the square root of the argument to full precision. - .. method:: to_eng_string([context]) + .. method:: to_eng_string(context=None) Convert to an engineering-type string. @@ -834,12 +847,12 @@ are up to 3 digits left of the decimal place. For example, converts ``Decimal('123E+1')`` to ``Decimal('1.23E+3')`` - .. method:: to_integral([rounding[, context]]) + .. method:: to_integral(rounding=None, context=None) Identical to the :meth:`to_integral_value` method. The ``to_integral`` name has been kept for compatibility with older versions. - .. method:: to_integral_exact([rounding[, context]]) + .. method:: to_integral_exact(rounding=None, context=None) Round to the nearest integer, signaling :const:`Inexact` or :const:`Rounded` as appropriate if rounding occurs. The rounding mode is @@ -847,7 +860,7 @@ ``context``. If neither parameter is given then the rounding mode of the current context is used. - .. method:: to_integral_value([rounding[, context]]) + .. method:: to_integral_value(rounding=None, context=None) Round to the nearest integer without signaling :const:`Inexact` or :const:`Rounded`. If given, applies *rounding*; otherwise, uses the @@ -893,10 +906,10 @@ You can also use the :keyword:`with` statement and the :func:`localcontext` function to temporarily change the active context. -.. function:: localcontext([c]) +.. function:: localcontext(ctx=None) Return a context manager that will set the current context for the active thread - to a copy of *c* on entry to the with-statement and restore the previous context + to a copy of *ctx* on entry to the with-statement and restore the previous context when exiting the with-statement. If no context is specified, a copy of the current context is used. @@ -1315,7 +1328,7 @@ identity operation. - .. method:: power(x, y[, modulo]) + .. method:: power(x, y, modulo=None) Return ``x`` to the power of ``y``, reduced modulo ``modulo`` if given. diff --git a/Lib/decimal.py b/Lib/decimal.py --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -2594,7 +2594,7 @@ ans = ans._fix(context) return ans - def same_quantum(self, other): + def same_quantum(self, other, context=None): """Return True if self and other have the same exponent; otherwise return False. @@ -2912,7 +2912,7 @@ except TypeError: return 0 - def canonical(self, context=None): + def canonical(self): """Returns the same Decimal object. As we do not have different encodings for the same number, the @@ -2932,7 +2932,7 @@ return ans return self.compare(other, context=context) - def compare_total(self, other): + def compare_total(self, other, context=None): """Compares self to other using the abstract representations. This is not like the standard compare, which use their numerical @@ -3005,7 +3005,7 @@ return _Zero - def compare_total_mag(self, other): + def compare_total_mag(self, other, context=None): """Compares self to other using abstract repr., ignoring sign. Like compare_total, but with operand's sign ignored and assumed to be 0. @@ -3027,7 +3027,7 @@ else: return _dec_from_triple(1, self._int, self._exp, self._is_special) - def copy_sign(self, other): + def copy_sign(self, other, context=None): """Returns self with the sign of other.""" other = _convert_other(other, raiseit=True) return _dec_from_triple(other._sign, self._int, @@ -4180,7 +4180,7 @@ """ if not isinstance(a, Decimal): raise TypeError("canonical requires a Decimal as an argument.") - return a.canonical(context=self) + return a.canonical() def compare(self, a, b): """Compares values numerically. diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -2089,6 +2089,248 @@ self.assertEqual(str(Decimal(0).sqrt()), str(c.sqrt(Decimal(0)))) + def test_none_args(self): + Decimal = self.decimal.Decimal + Context = self.decimal.Context + localcontext = self.decimal.localcontext + InvalidOperation = self.decimal.InvalidOperation + DivisionByZero = self.decimal.DivisionByZero + Overflow = self.decimal.Overflow + Underflow = self.decimal.Underflow + Subnormal = self.decimal.Subnormal + Inexact = self.decimal.Inexact + Rounded = self.decimal.Rounded + Clamped = self.decimal.Clamped + ROUND_HALF_EVEN = self.decimal.ROUND_HALF_EVEN + ROUND_DOWN = self.decimal.ROUND_DOWN + ROUND_UP = self.decimal.ROUND_UP + + with localcontext(Context()) as c: + c.prec = 7 + c.Emax = 999 + c.Emin = -999 + + x = Decimal("111") + y = Decimal("1e9999") + z = Decimal("1e-9999") + + ##### Unary functions + c.clear_flags() + self.assertEqual(str(x.exp(context=None)), '1.609487E+48') + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + c.clear_flags() + self.assertRaises(Overflow, y.exp, context=None) + self.assertTrue(c.flags[Overflow]) + + self.assertIs(z.is_normal(context=None), False) + self.assertIs(z.is_subnormal(context=None), True) + + c.clear_flags() + self.assertEqual(str(x.ln(context=None)), '4.709530') + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal(-1).ln, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(x.log10(context=None)), '2.045323') + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal(-1).log10, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(x.logb(context=None)), '2') + self.assertRaises(DivisionByZero, Decimal(0).logb, context=None) + self.assertTrue(c.flags[DivisionByZero]) + + c.clear_flags() + self.assertEqual(str(x.logical_invert(context=None)), '1111000') + self.assertRaises(InvalidOperation, y.logical_invert, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(y.next_minus(context=None)), '9.999999E+999') + self.assertRaises(InvalidOperation, Decimal('sNaN').next_minus, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(y.next_plus(context=None)), 'Infinity') + self.assertRaises(InvalidOperation, Decimal('sNaN').next_plus, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + self.assertEqual(str(z.normalize(context=None)), '0') + self.assertRaises(Overflow, y.normalize, context=None) + self.assertTrue(c.flags[Overflow]) + + self.assertEqual(str(z.number_class(context=None)), '+Subnormal') + + c.clear_flags() + self.assertEqual(str(z.sqrt(context=None)), '0E-1005') + self.assertTrue(c.flags[Clamped]) + self.assertTrue(c.flags[Inexact]) + self.assertTrue(c.flags[Rounded]) + self.assertTrue(c.flags[Subnormal]) + self.assertTrue(c.flags[Underflow]) + c.clear_flags() + self.assertRaises(Overflow, y.sqrt, context=None) + self.assertTrue(c.flags[Overflow]) + + c.capitals = 0 + self.assertEqual(str(z.to_eng_string(context=None)), '1e-9999') + c.capitals = 1 + + + ##### Binary functions + c.clear_flags() + ans = str(x.compare(Decimal('Nan891287828'), context=None)) + self.assertEqual(ans, 'NaN1287828') + self.assertRaises(InvalidOperation, x.compare, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.compare_signal(8224, context=None)) + self.assertEqual(ans, '-1') + self.assertRaises(InvalidOperation, x.compare_signal, Decimal('NaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.logical_and(101, context=None)) + self.assertEqual(ans, '101') + self.assertRaises(InvalidOperation, x.logical_and, 123, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.logical_or(101, context=None)) + self.assertEqual(ans, '111') + self.assertRaises(InvalidOperation, x.logical_or, 123, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.logical_xor(101, context=None)) + self.assertEqual(ans, '10') + self.assertRaises(InvalidOperation, x.logical_xor, 123, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.max(101, context=None)) + self.assertEqual(ans, '111') + self.assertRaises(InvalidOperation, x.max, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.max_mag(101, context=None)) + self.assertEqual(ans, '111') + self.assertRaises(InvalidOperation, x.max_mag, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.min(101, context=None)) + self.assertEqual(ans, '101') + self.assertRaises(InvalidOperation, x.min, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.min_mag(101, context=None)) + self.assertEqual(ans, '101') + self.assertRaises(InvalidOperation, x.min_mag, Decimal('sNaN'), context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.remainder_near(101, context=None)) + self.assertEqual(ans, '10') + self.assertRaises(InvalidOperation, y.remainder_near, 101, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.rotate(2, context=None)) + self.assertEqual(ans, '11100') + self.assertRaises(InvalidOperation, x.rotate, 101, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.scaleb(7, context=None)) + self.assertEqual(ans, '1.11E+9') + self.assertRaises(InvalidOperation, x.scaleb, 10000, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.clear_flags() + ans = str(x.shift(2, context=None)) + self.assertEqual(ans, '11100') + self.assertRaises(InvalidOperation, x.shift, 10000, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + + ##### Ternary functions + c.clear_flags() + ans = str(x.fma(2, 3, context=None)) + self.assertEqual(ans, '225') + self.assertRaises(Overflow, x.fma, Decimal('1e9999'), 3, context=None) + self.assertTrue(c.flags[Overflow]) + + + ##### Special cases + c.rounding = ROUND_HALF_EVEN + ans = str(Decimal('1.5').to_integral(rounding=None, context=None)) + self.assertEqual(ans, '2') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.5').to_integral(rounding=None, context=None)) + self.assertEqual(ans, '1') + ans = str(Decimal('1.5').to_integral(rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '2') + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal('sNaN').to_integral, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.rounding = ROUND_HALF_EVEN + ans = str(Decimal('1.5').to_integral_value(rounding=None, context=None)) + self.assertEqual(ans, '2') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.5').to_integral_value(rounding=None, context=None)) + self.assertEqual(ans, '1') + ans = str(Decimal('1.5').to_integral_value(rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '2') + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal('sNaN').to_integral_value, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.rounding = ROUND_HALF_EVEN + ans = str(Decimal('1.5').to_integral_exact(rounding=None, context=None)) + self.assertEqual(ans, '2') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.5').to_integral_exact(rounding=None, context=None)) + self.assertEqual(ans, '1') + ans = str(Decimal('1.5').to_integral_exact(rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '2') + c.clear_flags() + self.assertRaises(InvalidOperation, Decimal('sNaN').to_integral_exact, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + c.rounding = ROUND_UP + ans = str(Decimal('1.50001').quantize(exp=Decimal('1e-3'), rounding=None, context=None)) + self.assertEqual(ans, '1.501') + c.rounding = ROUND_DOWN + ans = str(Decimal('1.50001').quantize(exp=Decimal('1e-3'), rounding=None, context=None)) + self.assertEqual(ans, '1.500') + ans = str(Decimal('1.50001').quantize(exp=Decimal('1e-3'), rounding=ROUND_UP, context=None)) + self.assertEqual(ans, '1.501') + c.clear_flags() + self.assertRaises(InvalidOperation, y.quantize, Decimal('1e-10'), rounding=ROUND_UP, context=None) + self.assertTrue(c.flags[InvalidOperation]) + + with localcontext(Context()) as context: + context.prec = 7 + context.Emax = 999 + context.Emin = -999 + with localcontext(ctx=None) as c: + self.assertEqual(c.prec, 7) + self.assertEqual(c.Emax, 999) + self.assertEqual(c.Emin, -999) + def test_conversions_from_int(self): # Check that methods taking a second Decimal argument will # always accept an integer in place of a Decimal. @@ -2423,14 +2665,11 @@ self.assertRaises(TypeError, D.from_float, 1.1, context=xc) self.assertRaises(TypeError, D(0).as_tuple, context=xc) - if (self.decimal == C): - self.assertRaises(TypeError, D(1).canonical, context=xc) - self.assertEqual(D("-1").copy_abs(context=xc), 1) - self.assertEqual(D("1").copy_negate(context=xc), -1) - else: - self.assertEqual(D(1).canonical(context=xc), 1) - self.assertRaises(TypeError, D("-1").copy_abs, context=xc) - self.assertRaises(TypeError, D("-1").copy_negate, context=xc) + self.assertEqual(D(1).canonical(), 1) + self.assertRaises(TypeError, D("-1").copy_abs, context=xc) + self.assertRaises(TypeError, D("-1").copy_negate, context=xc) + self.assertRaises(TypeError, D(1).canonical, context="x") + self.assertRaises(TypeError, D(1).canonical, xyz="x") def test_exception_hierarchy(self): @@ -4593,6 +4832,9 @@ # Invalid local context self.assertRaises(TypeError, exec, 'with localcontext("xyz"): pass', locals()) + self.assertRaises(TypeError, exec, + 'with localcontext(context=getcontext()): pass', + locals()) # setcontext saved_context = getcontext() @@ -4826,6 +5068,50 @@ c.prec = 2 self.assertRaises(InvalidOperation, pow, Decimal(1000), 1, 501) + def test_va_args_exceptions(self): + Decimal = C.Decimal + Context = C.Context + + x = Decimal("10001111111") + + for attr in ['exp', 'is_normal', 'is_subnormal', 'ln', 'log10', + 'logb', 'logical_invert', 'next_minus', 'next_plus', + 'normalize', 'number_class', 'sqrt', 'to_eng_string']: + func = getattr(x, attr) + self.assertRaises(TypeError, func, context="x") + self.assertRaises(TypeError, func, "x", context=None) + + for attr in ['compare', 'compare_signal', 'logical_and', + 'logical_or', 'max', 'max_mag', 'min', 'min_mag', + 'remainder_near', 'rotate', 'scaleb', 'shift']: + func = getattr(x, attr) + self.assertRaises(TypeError, func, context="x") + self.assertRaises(TypeError, func, "x", context=None) + + self.assertRaises(TypeError, x.to_integral, rounding=None, context=[]) + self.assertRaises(TypeError, x.to_integral, rounding={}, context=[]) + self.assertRaises(TypeError, x.to_integral, [], []) + + self.assertRaises(TypeError, x.to_integral_value, rounding=None, context=[]) + self.assertRaises(TypeError, x.to_integral_value, rounding={}, context=[]) + self.assertRaises(TypeError, x.to_integral_value, [], []) + + self.assertRaises(TypeError, x.to_integral_exact, rounding=None, context=[]) + self.assertRaises(TypeError, x.to_integral_exact, rounding={}, context=[]) + self.assertRaises(TypeError, x.to_integral_exact, [], []) + + self.assertRaises(TypeError, x.fma, 1, 2, context="x") + self.assertRaises(TypeError, x.fma, 1, 2, "x", context=None) + + self.assertRaises(TypeError, x.quantize, 1, [], context=None) + self.assertRaises(TypeError, x.quantize, 1, [], rounding=None) + self.assertRaises(TypeError, x.quantize, 1, [], []) + + c = Context() + self.assertRaises(TypeError, c.power, 1, 2, mod="x") + self.assertRaises(TypeError, c.power, 1, "x", mod=None) + self.assertRaises(TypeError, c.power, "x", 2, mod=None) + @requires_extra_functionality def test_c_context_templates(self): self.assertEqual( diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -167,6 +167,10 @@ Library ------- +- Issue #15783: Except for the number methods, the C version of decimal now + supports all None default values present in decimal.py. These values were + largely undocumented. + - Issue #11175: argparse.FileType now accepts encoding and errors arguments. Patch by Lucas Maystre. diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1486,7 +1486,10 @@ } #define CONTEXT_CHECK_VA(obj) \ - if (!PyDecContext_Check(obj)) { \ + if (obj == Py_None) { \ + CURRENT_CONTEXT(obj); \ + } \ + else if (!PyDecContext_Check(obj)) { \ PyErr_SetString(PyExc_TypeError, \ "optional argument must be a context"); \ return NULL; \ @@ -1715,18 +1718,25 @@ * owns one reference to the global (outer) context and one * to the local (inner) context. */ static PyObject * -ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args) +ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"ctx", NULL}; PyDecContextManagerObject *self; - PyObject *local; + PyObject *local = Py_None; PyObject *global; CURRENT_CONTEXT(global); - local = global; - if (!PyArg_ParseTuple(args, "|O", &local)) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &local)) { return NULL; } - CONTEXT_CHECK_VA(local); + if (local == Py_None) { + local = global; + } + else if (!PyDecContext_Check(local)) { + PyErr_SetString(PyExc_TypeError, + "optional argument must be a context"); + return NULL; + } self = PyObject_New(PyDecContextManagerObject, &PyDecContextManager_Type); @@ -2749,9 +2759,8 @@ { static char *kwlist[] = {"value", "context", NULL}; PyObject *v = NULL; - PyObject *context; - - CURRENT_CONTEXT(context); + PyObject *context = Py_None; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &v, &context)) { return NULL; @@ -3315,20 +3324,23 @@ { static char *kwlist[] = {"rounding", "context", NULL}; PyObject *result; - PyObject *context; + PyObject *rounding = Py_None; + PyObject *context = Py_None; uint32_t status = 0; mpd_context_t workctx; - int round = -1; - - CURRENT_CONTEXT(context); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO", kwlist, - &round, &context)) { + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, + &rounding, &context)) { return NULL; } CONTEXT_CHECK_VA(context); workctx = *CTX(context); - if (round >= 0) { + if (rounding != Py_None) { + int round = getround(rounding); + if (round < 0) { + return NULL; + } if (!mpd_qsetround(&workctx, round)) { return type_error_ptr(invalid_rounding_err); } @@ -3353,20 +3365,23 @@ { static char *kwlist[] = {"rounding", "context", NULL}; PyObject *result; - PyObject *context; + PyObject *rounding = Py_None; + PyObject *context = Py_None; uint32_t status = 0; mpd_context_t workctx; - int round = -1; - - CURRENT_CONTEXT(context); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO", kwlist, - &round, &context)) { + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, + &rounding, &context)) { return NULL; } CONTEXT_CHECK_VA(context); workctx = *CTX(context); - if (round >= 0) { + if (rounding != Py_None) { + int round = getround(rounding); + if (round < 0) { + return NULL; + } if (!mpd_qsetround(&workctx, round)) { return type_error_ptr(invalid_rounding_err); } @@ -3633,9 +3648,8 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"context", NULL}; \ - PyObject *context; \ + PyObject *context = Py_None; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ &context)) { \ return NULL; \ @@ -3652,10 +3666,9 @@ { \ static char *kwlist[] = {"context", NULL}; \ PyObject *result; \ - PyObject *context; \ + PyObject *context = Py_None; \ uint32_t status = 0; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ &context)) { \ return NULL; \ @@ -3675,49 +3688,18 @@ return result; \ } -/* Unary function with an optional context arg. The actual MPDFUNC - only takes a status parameter. */ -#define Dec_UnaryFuncVA_NO_CTX(MPDFUNC) \ -static PyObject * \ -dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ -{ \ - static char *kwlist[] = {"context", NULL}; \ - PyObject *result; \ - PyObject *context; \ - uint32_t status = 0; \ - \ - CURRENT_CONTEXT(context); \ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ - &context)) { \ - return NULL; \ - } \ - CONTEXT_CHECK_VA(context); \ - \ - if ((result = dec_alloc()) == NULL) { \ - return NULL; \ - } \ - \ - MPDFUNC(MPD(result), MPD(self), &status); \ - if (dec_addstatus(context, status)) { \ - Py_DECREF(result); \ - return NULL; \ - } \ - \ - return result; \ -} - /* Binary function with an optional context arg. */ #define Dec_BinaryFuncVA(MPDFUNC) \ static PyObject * \ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"other", "context", NULL}; \ - PyObject *other, *context; \ + PyObject *other; \ PyObject *a, *b; \ PyObject *result; \ + PyObject *context = Py_None; \ uint32_t status = 0; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, \ &other, &context)) { \ return NULL; \ @@ -3750,11 +3732,11 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"other", "context", NULL}; \ - PyObject *other, *context; \ + PyObject *context = Py_None; \ + PyObject *other; \ PyObject *a, *b; \ PyObject *result; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, \ &other, &context)) { \ return NULL; \ @@ -3781,12 +3763,12 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ { \ static char *kwlist[] = {"other", "third", "context", NULL}; \ - PyObject *other, *third, *context; \ + PyObject *other, *third; \ PyObject *a, *b, *c; \ PyObject *result; \ + PyObject *context = Py_None; \ uint32_t status = 0; \ \ - CURRENT_CONTEXT(context); \ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O", kwlist, \ &other, &third, &context)) { \ return NULL; \ @@ -4019,9 +4001,45 @@ return result; } -/* Unary functions, optional context arg for conversion errors */ -Dec_UnaryFuncVA_NO_CTX(mpd_qcopy_abs) -Dec_UnaryFuncVA_NO_CTX(mpd_qcopy_negate) +static PyObject * +dec_mpd_qcopy_abs(PyObject *self, PyObject *dummy UNUSED) +{ + PyObject *result; + uint32_t status = 0; + + if ((result = dec_alloc()) == NULL) { + return NULL; + } + + mpd_qcopy_abs(MPD(result), MPD(self), &status); + if (status & MPD_Malloc_error) { + Py_DECREF(result); + PyErr_NoMemory(); + return NULL; + } + + return result; +} + +static PyObject * +dec_mpd_qcopy_negate(PyObject *self, PyObject *dummy UNUSED) +{ + PyObject *result; + uint32_t status = 0; + + if ((result = dec_alloc()) == NULL) { + return NULL; + } + + mpd_qcopy_negate(MPD(result), MPD(self), &status); + if (status & MPD_Malloc_error) { + Py_DECREF(result); + PyErr_NoMemory(); + return NULL; + } + + return result; +} /* Unary functions, optional context arg */ Dec_UnaryFuncVA(mpd_qinvert) @@ -4031,10 +4049,9 @@ dec_mpd_class(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"context", NULL}; - PyObject *context; + PyObject *context = Py_None; const char *cp; - CURRENT_CONTEXT(context); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &context)) { return NULL; @@ -4050,11 +4067,10 @@ { static char *kwlist[] = {"context", NULL}; PyObject *result; - PyObject *context; + PyObject *context = Py_None; mpd_ssize_t size; char *s; - CURRENT_CONTEXT(context); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &context)) { return NULL; @@ -4081,12 +4097,12 @@ dec_mpd_qcopy_sign(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"other", "context", NULL}; - PyObject *other, *context; + PyObject *other; PyObject *a, *b; PyObject *result; + PyObject *context = Py_None; uint32_t status = 0; - CURRENT_CONTEXT(context); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, &other, &context)) { return NULL; @@ -4116,11 +4132,11 @@ dec_mpd_same_quantum(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"other", "context", NULL}; - PyObject *other, *context; + PyObject *other; PyObject *a, *b; PyObject *result; - - CURRENT_CONTEXT(context); + PyObject *context = Py_None; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, &other, &context)) { return NULL; @@ -4148,22 +4164,25 @@ dec_mpd_qquantize(PyObject *v, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"exp", "rounding", "context", NULL}; - PyObject *w, *context; - PyObject *a, *b; + PyObject *rounding = Py_None; + PyObject *context = Py_None; + PyObject *w, *a, *b; PyObject *result; uint32_t status = 0; mpd_context_t workctx; - int round = -1; - - CURRENT_CONTEXT(context); - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO", kwlist, - &w, &round, &context)) { + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, + &w, &rounding, &context)) { return NULL; } CONTEXT_CHECK_VA(context); workctx = *CTX(context); - if (round >= 0) { + if (rounding != Py_None) { + int round = getround(rounding); + if (round < 0) { + return NULL; + } if (!mpd_qsetround(&workctx, round)) { return type_error_ptr(invalid_rounding_err); } @@ -4585,8 +4604,8 @@ { "radix", dec_mpd_radix, METH_NOARGS, doc_radix }, /* Unary functions, optional context arg for conversion errors */ - { "copy_abs", (PyCFunction)dec_mpd_qcopy_abs, METH_VARARGS|METH_KEYWORDS, doc_copy_abs }, - { "copy_negate", (PyCFunction)dec_mpd_qcopy_negate, METH_VARARGS|METH_KEYWORDS, doc_copy_negate }, + { "copy_abs", dec_mpd_qcopy_abs, METH_NOARGS, doc_copy_abs }, + { "copy_negate", dec_mpd_qcopy_negate, METH_NOARGS, doc_copy_negate }, /* Unary functions, optional context arg */ { "logb", (PyCFunction)dec_mpd_qlogb, METH_VARARGS|METH_KEYWORDS, doc_logb }, @@ -4916,7 +4935,7 @@ ctx_mpd_qpow(PyObject *context, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"a", "b", "modulo", NULL}; - PyObject *base, *exp, *mod = NULL; + PyObject *base, *exp, *mod = Py_None; PyObject *a, *b, *c = NULL; PyObject *result; uint32_t status = 0; @@ -4928,7 +4947,7 @@ CONVERT_BINOP_RAISE(&a, &b, base, exp, context); - if (mod != NULL) { + if (mod != Py_None) { if (!convert_op(TYPE_ERR, &c, mod, context)) { Py_DECREF(a); Py_DECREF(b); @@ -5361,7 +5380,7 @@ { { "getcontext", (PyCFunction)PyDec_GetCurrentContext, METH_NOARGS, doc_getcontext}, { "setcontext", (PyCFunction)PyDec_SetCurrentContext, METH_O, doc_setcontext}, - { "localcontext", (PyCFunction)ctxmanager_new, METH_VARARGS, doc_localcontext}, + { "localcontext", (PyCFunction)ctxmanager_new, METH_VARARGS|METH_KEYWORDS, doc_localcontext}, #ifdef EXTRA_FUNCTIONALITY { "IEEEContext", (PyCFunction)ieee_context, METH_O, doc_ieee_context}, #endif diff --git a/Modules/_decimal/docstrings.h b/Modules/_decimal/docstrings.h --- a/Modules/_decimal/docstrings.h +++ b/Modules/_decimal/docstrings.h @@ -28,10 +28,10 @@ \n"); PyDoc_STRVAR(doc_localcontext,"\n\ -localcontext(c) - Return a context manager that will set the default context\n\ -to a copy of c on entry to the with-statement and restore the previous default\n\ -context when exiting the with-statement. If no context is specified, a copy of\n\ -the current default context is used.\n\ +localcontext(ctx=None) - Return a context manager that will set the default\n\ +context to a copy of ctx on entry to the with-statement and restore the\n\ +previous default context when exiting the with-statement. If no context is\n\ +specified, a copy of the current default context is used.\n\ \n"); #ifdef EXTRA_FUNCTIONALITY @@ -49,8 +49,7 @@ /******************************************************************************/ PyDoc_STRVAR(doc_decimal,"\n\ -Decimal([value[, context]]): Construct a new Decimal object from value.\n\ -\n\ +Decimal(value=\"0\", context=None): Construct a new Decimal object.\n\ value can be an integer, string, tuple, or another Decimal object.\n\ If no value is given, return Decimal('0'). The context does not affect\n\ the conversion and is only passed to determine if the InvalidOperation\n\ @@ -74,7 +73,7 @@ \n"); PyDoc_STRVAR(doc_compare,"\n\ -compare(other[, context]) - Compare self to other. Return a decimal value:\n\ +compare(other, context=None) - Compare self to other. Return a decimal value:\n\ \n\ a or b is a NaN ==> Decimal('NaN')\n\ a < b ==> Decimal('-1')\n\ @@ -83,16 +82,16 @@ \n"); PyDoc_STRVAR(doc_compare_signal,"\n\ -compare_signal(other[, context]) - Identical to compare, except that\n\ +compare_signal(other, context=None) - Identical to compare, except that\n\ all NaNs signal.\n\ \n"); PyDoc_STRVAR(doc_compare_total,"\n\ -compare_total(other) - Compare two operands using their abstract representation\n\ -rather than their numerical value. Similar to the compare() method, but the\n\ -result gives a total ordering on Decimal instances. Two Decimal instances with\n\ -the same numeric value but different representations compare unequal in this\n\ -ordering:\n\ +compare_total(other, context=None) - Compare two operands using their\n\ +abstract representation rather than their numerical value. Similar to the\n\ +compare() method, but the result gives a total ordering on Decimal instances.\n\ +Two Decimal instances with the same numeric value but different representations\n\ +compare unequal in this ordering:\n\ \n\ >>> Decimal('12.0').compare_total(Decimal('12'))\n\ Decimal('-1')\n\ @@ -102,13 +101,21 @@ Decimal('-1') if the first operand is lower in the total order than the second,\n\ and Decimal('1') if the first operand is higher in the total order than the\n\ second operand. See the specification for details of the total order.\n\ +\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_compare_total_mag,"\n\ -compare_total_mag(other) - Compare two operands using their abstract\n\ -representation rather than their value as in compare_total(), but\n\ -ignoring the sign of each operand. x.compare_total_mag(y) is\n\ -equivalent to x.copy_abs().compare_total(y.copy_abs()).\n\ +compare_total_mag(other, context=None) - Compare two operands using their\n\ +abstract representation rather than their value as in compare_total(), but\n\ +ignoring the sign of each operand. x.compare_total_mag(y) is equivalent to\n\ +x.copy_abs().compare_total(y.copy_abs()).\n\ +\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_conjugate,"\n\ @@ -117,31 +124,32 @@ PyDoc_STRVAR(doc_copy_abs,"\n\ copy_abs() - Return the absolute value of the argument. This operation\n\ -is unaffected by the context and is quiet: no flags are changed and no\n\ -rounding is performed.\n\ +is unaffected by context and is quiet: no flags are changed and no rounding\n\ +is performed.\n\ \n"); PyDoc_STRVAR(doc_copy_negate,"\n\ copy_negate() - Return the negation of the argument. This operation is\n\ -unaffected by the context and is quiet: no flags are changed and no\n\ -rounding is performed.\n\ +unaffected by context and is quiet: no flags are changed and no rounding\n\ +is performed.\n\ \n"); PyDoc_STRVAR(doc_copy_sign,"\n\ -copy_sign(other) - Return a copy of the first operand with the sign set\n\ -to be the same as the sign of the second operand. For example:\n\ +copy_sign(other, context=None) - Return a copy of the first operand with\n\ +the sign set to be the same as the sign of the second operand. For example:\n\ \n\ >>> Decimal('2.3').copy_sign(Decimal('-1.5'))\n\ Decimal('-2.3')\n\ \n\ -This operation is unaffected by the context and is quiet: no flags are\n\ -changed and no rounding is performed.\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_exp,"\n\ -exp([context]) - Return the value of the (natural) exponential function e**x\n\ -at the given number. The function always uses the ROUND_HALF_EVEN mode and\n\ -the result is correctly rounded.\n\ +exp(context=None) - Return the value of the (natural) exponential function\n\ +e**x at the given number. The function always uses the ROUND_HALF_EVEN mode\n\ +and the result is correctly rounded.\n\ \n"); PyDoc_STRVAR(doc_from_float,"\n\ @@ -161,7 +169,7 @@ \n"); PyDoc_STRVAR(doc_fma,"\n\ -fma(other, third[, context]) - Fused multiply-add. Return self*other+third\n\ +fma(other, third, context=None) - Fused multiply-add. Return self*other+third\n\ with no rounding of the intermediate product self*other.\n\ \n\ >>> Decimal(2).fma(3, 5)\n\ @@ -191,9 +199,9 @@ \n"); PyDoc_STRVAR(doc_is_normal,"\n\ -is_normal([context]) - Return True if the argument is a normal finite non-zero\n\ -number with an adjusted exponent greater than or equal to Emin. Return False\n\ -if the argument is zero, subnormal, infinite or a NaN.\n\ +is_normal(context=None) - Return True if the argument is a normal finite\n\ +non-zero number with an adjusted exponent greater than or equal to Emin.\n\ +Return False if the argument is zero, subnormal, infinite or a NaN.\n\ \n"); PyDoc_STRVAR(doc_is_qnan,"\n\ @@ -210,8 +218,8 @@ \n"); PyDoc_STRVAR(doc_is_subnormal,"\n\ -is_subnormal([context]) - Return True if the argument is subnormal, and False\n\ -otherwise. A number is subnormal if it is non-zero, finite, and has an\n\ +is_subnormal(context=None) - Return True if the argument is subnormal, and\n\ +False otherwise. A number is subnormal if it is non-zero, finite, and has an\n\ adjusted exponent less than Emin.\n\ \n"); @@ -221,94 +229,94 @@ \n"); PyDoc_STRVAR(doc_ln,"\n\ -ln([context]) - Return the natural (base e) logarithm of the operand.\n\ +ln(context=None) - Return the natural (base e) logarithm of the operand.\n\ The function always uses the ROUND_HALF_EVEN mode and the result is\n\ correctly rounded.\n\ \n"); PyDoc_STRVAR(doc_log10,"\n\ -log10([context]) - Return the base ten logarithm of the operand.\n\ +log10(context=None) - Return the base ten logarithm of the operand.\n\ The function always uses the ROUND_HALF_EVEN mode and the result is\n\ correctly rounded.\n\ \n"); PyDoc_STRVAR(doc_logb,"\n\ -logb([context]) - For a non-zero number, return the adjusted exponent\n\ +logb(context=None) - For a non-zero number, return the adjusted exponent\n\ of the operand as a Decimal instance. If the operand is a zero, then\n\ Decimal('-Infinity') is returned and the DivisionByZero condition is\n\ raised. If the operand is an infinity then Decimal('Infinity') is returned.\n\ \n"); PyDoc_STRVAR(doc_logical_and,"\n\ -logical_and(other[, context]) - Return the digit-wise and of the two\n\ +logical_and(other, context=None) - Return the digit-wise and of the two\n\ (logical) operands.\n\ \n"); PyDoc_STRVAR(doc_logical_invert,"\n\ -logical_invert([context]) - Return the digit-wise inversion of the\n\ +logical_invert(context=None) - Return the digit-wise inversion of the\n\ (logical) operand.\n\ \n"); PyDoc_STRVAR(doc_logical_or,"\n\ -logical_or(other[, context]) - Return the digit-wise or of the two\n\ +logical_or(other, context=None) - Return the digit-wise or of the two\n\ (logical) operands.\n\ \n"); PyDoc_STRVAR(doc_logical_xor,"\n\ -logical_xor(other[, context]) - Return the digit-wise exclusive or of the\n\ +logical_xor(other, context=None) - Return the digit-wise exclusive or of the\n\ two (logical) operands.\n\ \n"); PyDoc_STRVAR(doc_max,"\n\ -max(other[, context]) - Maximum of self and other. If one operand is a quiet\n\ -NaN and the other is numeric, the numeric operand is returned.\n\ +max(other, context=None) - Maximum of self and other. If one operand is a\n\ +quiet NaN and the other is numeric, the numeric operand is returned.\n\ \n"); PyDoc_STRVAR(doc_max_mag,"\n\ -max_mag(other[, context]) - Similar to the max() method, but the comparison is\n\ -done using the absolute values of the operands.\n\ +max_mag(other, context=None) - Similar to the max() method, but the\n\ +comparison is done using the absolute values of the operands.\n\ \n"); PyDoc_STRVAR(doc_min,"\n\ -min(other[, context]) - Minimum of self and other. If one operand is a quiet\n\ -NaN and the other is numeric, the numeric operand is returned.\n\ +min(other, context=None) - Minimum of self and other. If one operand is a\n\ +quiet NaN and the other is numeric, the numeric operand is returned.\n\ \n"); PyDoc_STRVAR(doc_min_mag,"\n\ -min_mag(other[, context]) - Similar to the min() method, but the comparison is\n\ -done using the absolute values of the operands.\n\ +min_mag(other, context=None) - Similar to the min() method, but the\n\ +comparison is done using the absolute values of the operands.\n\ \n"); PyDoc_STRVAR(doc_next_minus,"\n\ -next_minus([context]) - Return the largest number representable in the given\n\ -context (or in the current default context if no context is given) that is\n\ -smaller than the given operand.\n\ +next_minus(context=None) - Return the largest number representable in the\n\ +given context (or in the current default context if no context is given) that\n\ +is smaller than the given operand.\n\ \n"); PyDoc_STRVAR(doc_next_plus,"\n\ -next_plus([context]) - Return the smallest number representable in the given\n\ -context (or in the current default context if no context is given) that is\n\ -larger than the given operand.\n\ +next_plus(context=None) - Return the smallest number representable in the\n\ +given context (or in the current default context if no context is given) that\n\ +is larger than the given operand.\n\ \n"); PyDoc_STRVAR(doc_next_toward,"\n\ -next_toward(other[, context]) - If the two operands are unequal, return the\n\ -number closest to the first operand in the direction of the second operand.\n\ +next_toward(other, context=None) - If the two operands are unequal, return\n\ +the number closest to the first operand in the direction of the second operand.\n\ If both operands are numerically equal, return a copy of the first operand\n\ with the sign set to be the same as the sign of the second operand.\n\ \n"); PyDoc_STRVAR(doc_normalize,"\n\ -normalize([context]) - Normalize the number by stripping the rightmost trailing\n\ -zeros and converting any result equal to Decimal('0') to Decimal('0e0'). Used\n\ -for producing canonical values for members of an equivalence class. For example,\n\ -Decimal('32.100') and Decimal('0.321000e+2') both normalize to the equivalent\n\ -value Decimal('32.1').\n\ +normalize(context=None) - Normalize the number by stripping the rightmost\n\ +trailing zeros and converting any result equal to Decimal('0') to Decimal('0e0').\n\ +Used for producing canonical values for members of an equivalence class. For\n\ +example, Decimal('32.100') and Decimal('0.321000e+2') both normalize to the\n\ +equivalent value Decimal('32.1').\n\ \n"); PyDoc_STRVAR(doc_number_class,"\n\ -number_class([context]) - Return a string describing the class of the operand.\n\ -The returned value is one of the following ten strings:\n\ +number_class(context=None) - Return a string describing the class of the\n\ +operand. The returned value is one of the following ten strings:\n\ \n\ * '-Infinity', indicating that the operand is negative infinity.\n\ * '-Normal', indicating that the operand is a negative normal number.\n\ @@ -324,8 +332,8 @@ \n"); PyDoc_STRVAR(doc_quantize,"\n\ -quantize(exp[, rounding[, context]]) - Return a value equal to the first\n\ -operand after rounding and having the exponent of the second operand.\n\ +quantize(exp, rounding=None, context=None) - Return a value equal to the\n\ +first operand after rounding and having the exponent of the second operand.\n\ \n\ >>> Decimal('1.41421356').quantize(Decimal('1.000'))\n\ Decimal('1.414')\n\ @@ -350,16 +358,18 @@ \n"); PyDoc_STRVAR(doc_remainder_near,"\n\ -remainder_near(other[, context]) - Compute the modulo as either a positive\n\ -or negative value depending on which is closest to zero. For instance,\n\ -Decimal(10).remainder_near(6) returns Decimal('-2'), which is closer to zero\n\ -than Decimal('4').\n\ +remainder_near(other, context=None) - Return the remainder from dividing\n\ +self by other. This differs from self % other in that the sign of the\n\ +remainder is chosen so as to minimize its absolute value. More precisely, the\n\ +return value is self - n * other where n is the integer nearest to the exact\n\ +value of self / other, and if two integers are equally near then the even one\n\ +is chosen.\n\ \n\ -If both are equally close, the one chosen will have the same sign as self.\n\ +If the result is zero then its sign will be the sign of self.\n\ \n"); PyDoc_STRVAR(doc_rotate,"\n\ -rotate(other[, context]) - Return the result of rotating the digits of the\n\ +rotate(other, context=None) - Return the result of rotating the digits of the\n\ first operand by an amount specified by the second operand. The second operand\n\ must be an integer in the range -precision through precision. The absolute\n\ value of the second operand gives the number of places to rotate. If the second\n\ @@ -370,18 +380,22 @@ \n"); PyDoc_STRVAR(doc_same_quantum,"\n\ -same_quantum(other[, context]) - Test whether self and other have the\n\ +same_quantum(other, context=None) - Test whether self and other have the\n\ same exponent or whether both are NaN.\n\ +\n\ +This operation is unaffected by context and is quiet: no flags are changed\n\ +and no rounding is performed. As an exception, the C version may raise\n\ +InvalidOperation if the second operand cannot be converted exactly.\n\ \n"); PyDoc_STRVAR(doc_scaleb,"\n\ -scaleb(other[, context]) - Return the first operand with the exponent adjusted\n\ -the second. Equivalently, return the first operand multiplied by 10**other.\n\ -The second operand must be an integer.\n\ +scaleb(other, context=None) - Return the first operand with the exponent\n\ +adjusted the second. Equivalently, return the first operand multiplied by\n\ +10**other. The second operand must be an integer.\n\ \n"); PyDoc_STRVAR(doc_shift,"\n\ -shift(other[, context]) - Return the result of shifting the digits of\n\ +shift(other, context=None) - Return the result of shifting the digits of\n\ the first operand by an amount specified by the second operand. The second\n\ operand must be an integer in the range -precision through precision. The\n\ absolute value of the second operand gives the number of places to shift.\n\ @@ -391,36 +405,40 @@ \n"); PyDoc_STRVAR(doc_sqrt,"\n\ -sqrt([context]) - Return the square root of the argument to full precision.\n\ +sqrt(context=None) - Return the square root of the argument to full precision.\n\ The result is correctly rounded using the ROUND_HALF_EVEN rounding mode.\n\ \n"); PyDoc_STRVAR(doc_to_eng_string,"\n\ -to_eng_string([context]) - Convert to an engineering-type string.\n\ -Engineering notation has an exponent which is a multiple of 3, so\n\ -there are up to 3 digits left of the decimal place. For example,\n\ -Decimal('123E+1') is converted to Decimal('1.23E+3')\n\ +to_eng_string(context=None) - Convert to an engineering-type string.\n\ +Engineering notation has an exponent which is a multiple of 3, so there\n\ +are up to 3 digits left of the decimal place. For example, Decimal('123E+1')\n\ +is converted to Decimal('1.23E+3').\n\ +\n\ +The value of context.capitals determines whether the exponent sign is lower\n\ +or upper case. Otherwise, the context does not affect the operation.\n\ \n"); PyDoc_STRVAR(doc_to_integral,"\n\ -to_integral([rounding[, context]]) - Identical to the to_integral_value()\n\ -method. The to_integral name has been kept for compatibility with older\n\ -versions.\n\ +to_integral(rounding=None, context=None) - Identical to the\n\ +to_integral_value() method. The to_integral() name has been kept\n\ +for compatibility with older versions.\n\ \n"); PyDoc_STRVAR(doc_to_integral_exact,"\n\ -to_integral_exact([rounding[, context]]) - Round to the nearest integer,\n\ -signaling Inexact or Rounded as appropriate if rounding occurs. The rounding\n\ -mode is determined by the rounding parameter if given, else by the given\n\ -context. If neither parameter is given, then the rounding mode of the current\n\ -default context is used.\n\ +to_integral_exact(rounding=None, context=None) - Round to the nearest\n\ +integer, signaling Inexact or Rounded as appropriate if rounding occurs.\n\ +The rounding mode is determined by the rounding parameter if given, else\n\ +by the given context. If neither parameter is given, then the rounding mode\n\ +of the current default context is used.\n\ \n"); PyDoc_STRVAR(doc_to_integral_value,"\n\ -to_integral_value([rounding[, context]]) - Round to the nearest integer without\n\ -signaling Inexact or Rounded. The rounding mode is determined by the rounding\n\ -parameter if given, else by the given context. If neither parameter is given,\n\ -then the rounding mode of the current default context is used.\n\ +to_integral_value(rounding=None, context=None) - Round to the nearest\n\ +integer without signaling Inexact or Rounded. The rounding mode is determined\n\ +by the rounding parameter if given, else by the given context. If neither\n\ +parameter is given, then the rounding mode of the current default context is\n\ +used.\n\ \n"); diff --git a/Modules/_decimal/tests/deccheck.py b/Modules/_decimal/tests/deccheck.py --- a/Modules/_decimal/tests/deccheck.py +++ b/Modules/_decimal/tests/deccheck.py @@ -36,6 +36,7 @@ from collections import defaultdict from test.support import import_fresh_module from randdec import randfloat, all_unary, all_binary, all_ternary +from randdec import unary_optarg, binary_optarg, ternary_optarg from formathelper import rand_format, rand_locale C = import_fresh_module('decimal', fresh=['_decimal']) @@ -834,6 +835,17 @@ except VerifyError as err: log(err) + if not method.startswith('__'): + for op in unary_optarg(prec, exp_range, itr): + t = TestSet(method, op) + try: + if not convert(t): + continue + callfuncs(t) + verify(t, stat) + except VerifyError as err: + log(err) + def test_binary(method, prec, exp_range, restricted_range, itr, stat): """Iterate a binary function through many test cases.""" if method in BinaryRestricted: @@ -848,6 +860,17 @@ except VerifyError as err: log(err) + if not method.startswith('__'): + for op in binary_optarg(prec, exp_range, itr): + t = TestSet(method, op) + try: + if not convert(t): + continue + callfuncs(t) + verify(t, stat) + except VerifyError as err: + log(err) + def test_ternary(method, prec, exp_range, restricted_range, itr, stat): """Iterate a ternary function through many test cases.""" if method in TernaryRestricted: @@ -862,6 +885,17 @@ except VerifyError as err: log(err) + if not method.startswith('__'): + for op in ternary_optarg(prec, exp_range, itr): + t = TestSet(method, op) + try: + if not convert(t): + continue + callfuncs(t) + verify(t, stat) + except VerifyError as err: + log(err) + def test_format(method, prec, exp_range, restricted_range, itr, stat): """Iterate the __format__ method through many test cases.""" for op in all_unary(prec, exp_range, itr): diff --git a/Modules/_decimal/tests/randdec.py b/Modules/_decimal/tests/randdec.py --- a/Modules/_decimal/tests/randdec.py +++ b/Modules/_decimal/tests/randdec.py @@ -527,6 +527,11 @@ for _ in range(100): yield (randtuple(prec, exp_range),) +def unary_optarg(prec, exp_range, itr): + for _ in range(100): + yield randdec(prec, exp_range), None + yield randdec(prec, exp_range), None, None + def all_binary(prec, exp_range, itr): for a, b in bin_close_to_pow10(prec, exp_range, itr): yield a, b @@ -543,6 +548,11 @@ for _ in range(100): yield randdec(prec, exp_range), randdec(prec, exp_range) +def binary_optarg(prec, exp_range, itr): + for _ in range(100): + yield randdec(prec, exp_range), randdec(prec, exp_range), None + yield randdec(prec, exp_range), randdec(prec, exp_range), None, None + def all_ternary(prec, exp_range, itr): for a, b, c in tern_close_numbers(prec, exp_range, -exp_range, itr): yield a, b, c @@ -557,3 +567,11 @@ b = randdec(prec, 2*exp_range) c = randdec(prec, 2*exp_range) yield a, b, c + +def ternary_optarg(prec, exp_range, itr): + for _ in range(100): + a = randdec(prec, 2*exp_range) + b = randdec(prec, 2*exp_range) + c = randdec(prec, 2*exp_range) + yield a, b, c, None + yield a, b, c, None, None -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sun Dec 16 05:57:33 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 16 Dec 2012 05:57:33 +0100 Subject: [Python-checkins] Daily reference leaks (7c9327ff5de6): sum=-2 Message-ID: results for 7c9327ff5de6 on branch "default" -------------------------------------------- test_concurrent_futures leaked [0, 0, -2] memory blocks, sum=-2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogylGKKq', '-x'] From python-checkins at python.org Sun Dec 16 12:49:04 2012 From: python-checkins at python.org (hynek.schlawack) Date: Sun, 16 Dec 2012 12:49:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NjY0OiBBZGQg?= =?utf-8?q?regression_tests_for_glob=27s_behaviour_concerning_=22=2E=22-en?= =?utf-8?q?tries?= Message-ID: <3YPP0c2pgdzNk4@mail.python.org> http://hg.python.org/cpython/rev/028ecc3900f5 changeset: 80874:028ecc3900f5 branch: 2.7 parent: 80868:3d518ef4eae7 user: Hynek Schlawack date: Sun Dec 16 12:30:57 2012 +0100 summary: #16664: Add regression tests for glob's behaviour concerning "."-entries Patch by Sebastian Kreft. files: Lib/test/test_glob.py | 7 ++++++- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -4,6 +4,7 @@ import os import shutil + class GlobTests(unittest.TestCase): def norm(self, *parts): @@ -18,9 +19,11 @@ f.close() def setUp(self): - self.tempdir = TESTFN+"_dir" + self.tempdir = TESTFN + "_dir" self.mktemp('a', 'D') self.mktemp('aab', 'F') + self.mktemp('.aa', 'G') + self.mktemp('.bb', 'H') self.mktemp('aaa', 'zzzF') self.mktemp('ZZZ') self.mktemp('a', 'bcd', 'EF') @@ -66,6 +69,8 @@ eq = self.assertSequencesEqual_noorder eq(self.glob('a*'), map(self.norm, ['a', 'aab', 'aaa'])) eq(self.glob('*a'), map(self.norm, ['a', 'aaa'])) + eq(self.glob('.*'), map(self.norm, ['.aa', '.bb'])) + eq(self.glob('?aa'), map(self.norm, ['aaa'])) eq(self.glob('aa?'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('aa[ab]'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('*q'), []) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -540,6 +540,7 @@ Maksim Kozyarchuk Stefan Krah Bob Kras +Sebastian Kreft Holger Krekel Michael Kremer Fabian Kreutz diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -548,6 +548,9 @@ Tests ----- +- Issue #16664: Add regression tests for glob's behaviour concerning entries + starting with a ".". Patch by Sebastian Kreft. + - Issue #15747: ZFS always returns EOPNOTSUPP when attempting to set the UF_IMMUTABLE flag (via either chflags or lchflags); refactor affected tests in test_posix.py to account for this. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 12:49:05 2012 From: python-checkins at python.org (hynek.schlawack) Date: Sun, 16 Dec 2012 12:49:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2NjY0OiBBZGQg?= =?utf-8?q?regression_tests_for_glob=27s_behaviour_concerning_=22=2E=22-en?= =?utf-8?q?tries?= Message-ID: <3YPP0d58MLzNl2@mail.python.org> http://hg.python.org/cpython/rev/29f0c45ce576 changeset: 80875:29f0c45ce576 branch: 3.2 parent: 80865:8ba5a34e103e user: Hynek Schlawack date: Sun Dec 16 12:39:11 2012 +0100 summary: #16664: Add regression tests for glob's behaviour concerning "."-entries Patch by Sebastian Kreft. files: Lib/test/test_glob.py | 7 ++++++- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -4,6 +4,7 @@ import os import shutil + class GlobTests(unittest.TestCase): def norm(self, *parts): @@ -18,9 +19,11 @@ f.close() def setUp(self): - self.tempdir = TESTFN+"_dir" + self.tempdir = TESTFN + "_dir" self.mktemp('a', 'D') self.mktemp('aab', 'F') + self.mktemp('.aa', 'G') + self.mktemp('.bb', 'H') self.mktemp('aaa', 'zzzF') self.mktemp('ZZZ') self.mktemp('a', 'bcd', 'EF') @@ -66,6 +69,8 @@ eq = self.assertSequencesEqual_noorder eq(self.glob('a*'), map(self.norm, ['a', 'aab', 'aaa'])) eq(self.glob('*a'), map(self.norm, ['a', 'aaa'])) + eq(self.glob('.*'), map(self.norm, ['.aa', '.bb'])) + eq(self.glob('?aa'), map(self.norm, ['aaa'])) eq(self.glob('aa?'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('aa[ab]'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('*q'), []) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -587,6 +587,7 @@ Maksim Kozyarchuk Stefan Krah Bob Kras +Sebastian Kreft Holger Krekel Michael Kremer Fabian Kreutz diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -689,6 +689,9 @@ Tests ----- +- Issue #16664: Add regression tests for glob's behaviour concerning entries + starting with a ".". Patch by Sebastian Kreft. + - Issue #15872: Add tests for a 3.3 regression which caused the new fd-based shutil.rmtree not ignore all errors. Also add a test ensuring that rmtree fails when being called on a symlink. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 12:49:07 2012 From: python-checkins at python.org (hynek.schlawack) Date: Sun, 16 Dec 2012 12:49:07 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2316664=3A_Add_regression_tests_for_glob=27s_behaviour_concer?= =?utf-8?q?ning_=22=2E=22-entries?= Message-ID: <3YPP0g0QBCzNpZ@mail.python.org> http://hg.python.org/cpython/rev/f646842023b3 changeset: 80876:f646842023b3 branch: 3.3 parent: 80872:29becac5dd9b parent: 80875:29f0c45ce576 user: Hynek Schlawack date: Sun Dec 16 12:44:07 2012 +0100 summary: #16664: Add regression tests for glob's behaviour concerning "."-entries Patch by Sebastian Kreft. files: Lib/test/test_glob.py | 7 ++++++- Misc/ACKS | 1 + Misc/NEWS | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -5,6 +5,7 @@ import os import shutil + class GlobTests(unittest.TestCase): def norm(self, *parts): @@ -18,9 +19,11 @@ create_empty_file(filename) def setUp(self): - self.tempdir = TESTFN+"_dir" + self.tempdir = TESTFN + "_dir" self.mktemp('a', 'D') self.mktemp('aab', 'F') + self.mktemp('.aa', 'G') + self.mktemp('.bb', 'H') self.mktemp('aaa', 'zzzF') self.mktemp('ZZZ') self.mktemp('a', 'bcd', 'EF') @@ -66,6 +69,8 @@ eq = self.assertSequencesEqual_noorder eq(self.glob('a*'), map(self.norm, ['a', 'aab', 'aaa'])) eq(self.glob('*a'), map(self.norm, ['a', 'aaa'])) + eq(self.glob('.*'), map(self.norm, ['.aa', '.bb'])) + eq(self.glob('?aa'), map(self.norm, ['aaa'])) eq(self.glob('aa?'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('aa[ab]'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('*q'), []) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -647,6 +647,7 @@ Maksim Kozyarchuk Stefan Krah Bob Kras +Sebastian Kreft Holger Krekel Michael Kremer Fabian Kreutz diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,7 +40,7 @@ - Issue #9535: Fix pending signals that have been received but not yet handled by Python to not persist after os.fork() in the child process. -- Issue #15001: fix segfault on "del sys.module['__main__']". Patch by Victor +- Issue #15001: fix segfault on "del sys.modules['__main__']". Patch by Victor Stinner. - Issue #8271: the utf-8 decoder now outputs the correct number of U+FFFD @@ -306,6 +306,9 @@ Tests ----- +- Issue #16664: Add regression tests for glob's behaviour concerning entries + starting with a ".". Patch by Sebastian Kreft. + - Issue #16559: Add more tests for the json module, including some from the official test suite at json.org. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 12:49:08 2012 From: python-checkins at python.org (hynek.schlawack) Date: Sun, 16 Dec 2012 12:49:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=2316664=3A_Add_regression_tests_for_glob=27s_behaviour_?= =?utf-8?q?concerning_=22=2E=22-entries?= Message-ID: <3YPP0h2rVqzNl4@mail.python.org> http://hg.python.org/cpython/rev/1fb39efcc3dd changeset: 80877:1fb39efcc3dd parent: 80873:7c9327ff5de6 parent: 80876:f646842023b3 user: Hynek Schlawack date: Sun Dec 16 12:46:58 2012 +0100 summary: #16664: Add regression tests for glob's behaviour concerning "."-entries Patch by Sebastian Kreft. files: Lib/test/test_glob.py | 7 ++++++- Misc/ACKS | 1 + Misc/NEWS | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -5,6 +5,7 @@ import os import shutil + class GlobTests(unittest.TestCase): def norm(self, *parts): @@ -18,9 +19,11 @@ create_empty_file(filename) def setUp(self): - self.tempdir = TESTFN+"_dir" + self.tempdir = TESTFN + "_dir" self.mktemp('a', 'D') self.mktemp('aab', 'F') + self.mktemp('.aa', 'G') + self.mktemp('.bb', 'H') self.mktemp('aaa', 'zzzF') self.mktemp('ZZZ') self.mktemp('a', 'bcd', 'EF') @@ -66,6 +69,8 @@ eq = self.assertSequencesEqual_noorder eq(self.glob('a*'), map(self.norm, ['a', 'aab', 'aaa'])) eq(self.glob('*a'), map(self.norm, ['a', 'aaa'])) + eq(self.glob('.*'), map(self.norm, ['.aa', '.bb'])) + eq(self.glob('?aa'), map(self.norm, ['aaa'])) eq(self.glob('aa?'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('aa[ab]'), map(self.norm, ['aaa', 'aab'])) eq(self.glob('*q'), []) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -650,6 +650,7 @@ Maksim Kozyarchuk Stefan Krah Bob Kras +Sebastian Kreft Holger Krekel Michael Kremer Fabian Kreutz diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -67,7 +67,7 @@ - Issue #14794: Fix slice.indices to return correct results for huge values, rather than raising OverflowError. -- Issue #15001: fix segfault on "del sys.module['__main__']". Patch by Victor +- Issue #15001: fix segfault on "del sys.modules['__main__']". Patch by Victor Stinner. - Issue #8271: the utf-8 decoder now outputs the correct number of U+FFFD @@ -470,6 +470,9 @@ Tests ----- +- Issue #16664: Add regression tests for glob's behaviour concerning entries + starting with a ".". Patch by Sebastian Kreft. + - Issue #13390: The ``-R`` option to regrtest now also checks for memory allocation leaks, using :func:`sys.getallocatedblocks()`. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 13:32:04 2012 From: python-checkins at python.org (georg.brandl) Date: Sun, 16 Dec 2012 13:32:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fixup_abc=2EABC_wording_an?= =?utf-8?q?d_add_versionadded=2E?= Message-ID: <3YPPyD6jv3zMt0@mail.python.org> http://hg.python.org/cpython/rev/9e6cf246ca4e changeset: 80878:9e6cf246ca4e user: Georg Brandl date: Sun Dec 16 13:32:33 2012 +0100 summary: Fixup abc.ABC wording and add versionadded. files: Doc/library/abc.rst | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/abc.rst b/Doc/library/abc.rst --- a/Doc/library/abc.rst +++ b/Doc/library/abc.rst @@ -129,13 +129,16 @@ .. class:: ABC - A helper class that has :class:`ABCMeta` as metaclass. :class:`ABC` is the - standard class to inherit from in order to create an abstract base class, + A helper class that has :class:`ABCMeta` as its metaclass. With this class, + an abstract base class can be created by simply deriving from :class:`ABC`, avoiding sometimes confusing metaclass usage. - Note that :class:`ABC` type is still :class:`ABCMeta`, therefore inheriting - from :class:`ABC` requires usual precautions regarding metaclasses usage - as multiple inheritance may lead to metaclass conflicts. + Note that the type of :class:`ABC` is still :class:`ABCMeta`, therefore + inheriting from :class:`ABC` requires the usual precautions regarding metaclass + usage, as multiple inheritance may lead to metaclass conflicts. + + .. versionadded:: 3.4 + The :mod:`abc` module also provides the following decorators: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 13:56:00 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 13:56:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NjI2?= =?utf-8?q?=3A_Fix_infinite_recursion_in_glob=2Eglob=28=29_on_Windows_when?= =?utf-8?q?_the_pattern?= Message-ID: <3YPQTr1czDzN8Q@mail.python.org> http://hg.python.org/cpython/rev/4af260a54e05 changeset: 80879:4af260a54e05 branch: 3.2 parent: 80875:29f0c45ce576 user: Antoine Pitrou date: Sun Dec 16 13:49:37 2012 +0100 summary: Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. files: Lib/glob.py | 5 ++++- Lib/test/test_glob.py | 13 +++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 21 insertions(+), 1 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -29,7 +29,10 @@ for name in glob1(None, basename): yield name return - if has_magic(dirname): + # `os.path.split()` returns the argument itself as a dirname if it is a + # drive or UNC path. Prevent an infinite recursion if a drive or UNC path + # contains magic characters (i.e. r'\\?\C:'). + if dirname != pathname and has_magic(dirname): dirs = iglob(dirname) else: dirs = [dirname] diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -3,6 +3,7 @@ import glob import os import shutil +import sys class GlobTests(unittest.TestCase): @@ -110,6 +111,18 @@ eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym2'), [self.norm('sym2')]) + @unittest.skipUnless(sys.platform == "win32", "Win32 specific test") + def test_glob_magic_in_drive(self): + eq = self.assertSequencesEqual_noorder + eq(glob.glob('*:'), []) + eq(glob.glob(b'*:'), []) + eq(glob.glob('?:'), []) + eq(glob.glob(b'?:'), []) + eq(glob.glob('\\\\?\\c:\\'), ['\\\\?\\c:\\']) + eq(glob.glob(b'\\\\?\\c:\\'), [b'\\\\?\\c:\\']) + eq(glob.glob('\\\\*\\*\\'), []) + eq(glob.glob(b'\\\\*\\*\\'), []) + def test_main(): run_unittest(GlobTests) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,10 @@ Library ------- +- Issue #16626: Fix infinite recursion in glob.glob() on Windows when the + pattern contains a wildcard in the drive or UNC path. Patch by Serhiy + Storchaka. + - Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 13:56:01 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 13:56:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316626=3A_Fix_infinite_recursion_in_glob=2Eglob=28=29_?= =?utf-8?q?on_Windows_when_the_pattern?= Message-ID: <3YPQTs4QQ7zNXS@mail.python.org> http://hg.python.org/cpython/rev/b90aa7f66e4a changeset: 80880:b90aa7f66e4a branch: 3.3 parent: 80876:f646842023b3 parent: 80879:4af260a54e05 user: Antoine Pitrou date: Sun Dec 16 13:50:19 2012 +0100 summary: Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. files: Lib/glob.py | 5 ++++- Lib/test/test_glob.py | 13 +++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 21 insertions(+), 1 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -29,7 +29,10 @@ for name in glob1(None, basename): yield name return - if has_magic(dirname): + # `os.path.split()` returns the argument itself as a dirname if it is a + # drive or UNC path. Prevent an infinite recursion if a drive or UNC path + # contains magic characters (i.e. r'\\?\C:'). + if dirname != pathname and has_magic(dirname): dirs = iglob(dirname) else: dirs = [dirname] diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -4,6 +4,7 @@ import glob import os import shutil +import sys class GlobTests(unittest.TestCase): @@ -110,6 +111,18 @@ eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym2'), [self.norm('sym2')]) + @unittest.skipUnless(sys.platform == "win32", "Win32 specific test") + def test_glob_magic_in_drive(self): + eq = self.assertSequencesEqual_noorder + eq(glob.glob('*:'), []) + eq(glob.glob(b'*:'), []) + eq(glob.glob('?:'), []) + eq(glob.glob(b'?:'), []) + eq(glob.glob('\\\\?\\c:\\'), ['\\\\?\\c:\\']) + eq(glob.glob(b'\\\\?\\c:\\'), [b'\\\\?\\c:\\']) + eq(glob.glob('\\\\*\\*\\'), []) + eq(glob.glob(b'\\\\*\\*\\'), []) + def test_main(): run_unittest(GlobTests) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,10 @@ Library ------- +- Issue #16626: Fix infinite recursion in glob.glob() on Windows when the + pattern contains a wildcard in the drive or UNC path. Patch by Serhiy + Storchaka. + - Issue #15783: Except for the number methods, the C version of decimal now supports all None default values present in decimal.py. These values were largely undocumented. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 13:56:02 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 13:56:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316626=3A_Fix_infinite_recursion_in_glob=2Eglob?= =?utf-8?q?=28=29_on_Windows_when_the_pattern?= Message-ID: <3YPQTt6m2QzNhl@mail.python.org> http://hg.python.org/cpython/rev/bfb39fb93af7 changeset: 80881:bfb39fb93af7 parent: 80878:9e6cf246ca4e parent: 80880:b90aa7f66e4a user: Antoine Pitrou date: Sun Dec 16 13:54:14 2012 +0100 summary: Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. files: Lib/glob.py | 5 ++++- Lib/test/test_glob.py | 13 +++++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 21 insertions(+), 1 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -28,7 +28,10 @@ if not dirname: yield from glob1(None, basename) return - if has_magic(dirname): + # `os.path.split()` returns the argument itself as a dirname if it is a + # drive or UNC path. Prevent an infinite recursion if a drive or UNC path + # contains magic characters (i.e. r'\\?\C:'). + if dirname != pathname and has_magic(dirname): dirs = iglob(dirname) else: dirs = [dirname] diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -4,6 +4,7 @@ import glob import os import shutil +import sys class GlobTests(unittest.TestCase): @@ -110,6 +111,18 @@ eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym2'), [self.norm('sym2')]) + @unittest.skipUnless(sys.platform == "win32", "Win32 specific test") + def test_glob_magic_in_drive(self): + eq = self.assertSequencesEqual_noorder + eq(glob.glob('*:'), []) + eq(glob.glob(b'*:'), []) + eq(glob.glob('?:'), []) + eq(glob.glob(b'?:'), []) + eq(glob.glob('\\\\?\\c:\\'), ['\\\\?\\c:\\']) + eq(glob.glob(b'\\\\?\\c:\\'), [b'\\\\?\\c:\\']) + eq(glob.glob('\\\\*\\*\\'), []) + eq(glob.glob(b'\\\\*\\*\\'), []) + def test_main(): run_unittest(GlobTests) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -167,6 +167,10 @@ Library ------- +- Issue #16626: Fix infinite recursion in glob.glob() on Windows when the + pattern contains a wildcard in the drive or UNC path. Patch by Serhiy + Storchaka. + - Issue #15783: Except for the number methods, the C version of decimal now supports all None default values present in decimal.py. These values were largely undocumented. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 13:57:34 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 13:57:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NjI2?= =?utf-8?q?=3A_Fix_infinite_recursion_in_glob=2Eglob=28=29_on_Windows_when?= =?utf-8?q?_the_pattern?= Message-ID: <3YPQWf4RCHzNDK@mail.python.org> http://hg.python.org/cpython/rev/b0935ef48186 changeset: 80882:b0935ef48186 branch: 2.7 parent: 80874:028ecc3900f5 user: Antoine Pitrou date: Sun Dec 16 13:55:47 2012 +0100 summary: Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. files: Lib/glob.py | 5 ++++- Lib/test/test_glob.py | 9 +++++++++ Misc/NEWS | 4 ++++ 3 files changed, 17 insertions(+), 1 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -38,7 +38,10 @@ for name in glob1(os.curdir, basename): yield name return - if has_magic(dirname): + # `os.path.split()` returns the argument itself as a dirname if it is a + # drive or UNC path. Prevent an infinite recursion if a drive or UNC path + # contains magic characters (i.e. r'\\?\C:'). + if dirname != pathname and has_magic(dirname): dirs = iglob(dirname) else: dirs = [dirname] diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -3,6 +3,7 @@ import glob import os import shutil +import sys class GlobTests(unittest.TestCase): @@ -110,6 +111,14 @@ eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym2'), [self.norm('sym2')]) + @unittest.skipUnless(sys.platform == "win32", "Win32 specific test") + def test_glob_magic_in_drive(self): + eq = self.assertSequencesEqual_noorder + eq(glob.glob('*:'), []) + eq(glob.glob(u'*:'), []) + eq(glob.glob('?:'), []) + eq(glob.glob(u'?:'), []) + def test_main(): run_unittest(GlobTests) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -160,6 +160,10 @@ Library ------- +- Issue #16626: Fix infinite recursion in glob.glob() on Windows when the + pattern contains a wildcard in the drive or UNC path. Patch by Serhiy + Storchaka. + - Issue #16298: In HTTPResponse.read(), close the socket when there is no Content-Length and the incoming stream is finished. Patch by Eran Rundstein. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:05:46 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:05:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2Njk2?= =?utf-8?q?=3A_fix_comparison_between_bytes_and_string=2E_Also=2C_improve_?= =?utf-8?q?glob_tests=2E?= Message-ID: <3YPTMZ0z31zNjq@mail.python.org> http://hg.python.org/cpython/rev/96f19274de18 changeset: 80883:96f19274de18 branch: 3.2 parent: 80879:4af260a54e05 user: Antoine Pitrou date: Sun Dec 16 16:03:01 2012 +0100 summary: Issue #16696: fix comparison between bytes and string. Also, improve glob tests. files: Lib/glob.py | 2 +- Lib/test/test_glob.py | 33 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -63,7 +63,7 @@ return fnmatch.filter(names, pattern) def glob0(dirname, basename): - if basename == '': + if not basename: # `os.path.split()` returns an empty basename for paths ending with a # directory separator. 'q*x/' should match only directories. if os.path.isdir(dirname): diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -97,12 +97,35 @@ os.path.join('aab', 'F')])) def test_glob_directory_with_trailing_slash(self): - # We are verifying that when there is wildcard pattern which - # ends with os.sep doesn't blow up. - res = glob.glob(self.tempdir + '*' + os.sep) - self.assertEqual(len(res), 1) + # Patterns ending with a slash shouldn't match non-dirs + res = glob.glob(os.path.join(self.tempdir, 'Z*Z') + os.sep) + self.assertEqual(res, []) + res = glob.glob(os.path.join(self.tempdir, 'ZZZ') + os.sep) + self.assertEqual(res, []) + # When there is wildcard pattern which ends with os.sep, glob() + # doesn't blow up. + res = glob.glob(os.path.join(self.tempdir, 'aa*') + os.sep) + self.assertEqual(len(res), 2) # either of these results are reasonable - self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep]) + self.assertIn(set(res), [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) + + def test_glob_bytes_directory_with_trailing_slash(self): + # Same as test_glob_directory_with_trailing_slash, but with a + # bytes argument. + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'Z*Z') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'ZZZ') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'aa*') + os.sep)) + self.assertEqual(len(res), 2) + # either of these results are reasonable + self.assertIn({os.fsdecode(x) for x in res}, [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) @skip_unless_symlink def test_glob_broken_symlinks(self): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:05:47 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:05:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316696=3A_fix_comparison_between_bytes_and_string=2E_A?= =?utf-8?q?lso=2C_improve_glob_tests=2E?= Message-ID: <3YPTMb3cp7zPJh@mail.python.org> http://hg.python.org/cpython/rev/ed8134df30e4 changeset: 80884:ed8134df30e4 branch: 3.3 parent: 80880:b90aa7f66e4a parent: 80883:96f19274de18 user: Antoine Pitrou date: Sun Dec 16 16:03:42 2012 +0100 summary: Issue #16696: fix comparison between bytes and string. Also, improve glob tests. files: Lib/glob.py | 2 +- Lib/test/test_glob.py | 33 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -63,7 +63,7 @@ return fnmatch.filter(names, pattern) def glob0(dirname, basename): - if basename == '': + if not basename: # `os.path.split()` returns an empty basename for paths ending with a # directory separator. 'q*x/' should match only directories. if os.path.isdir(dirname): diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -97,12 +97,35 @@ os.path.join('aab', 'F')])) def test_glob_directory_with_trailing_slash(self): - # We are verifying that when there is wildcard pattern which - # ends with os.sep doesn't blow up. - res = glob.glob(self.tempdir + '*' + os.sep) - self.assertEqual(len(res), 1) + # Patterns ending with a slash shouldn't match non-dirs + res = glob.glob(os.path.join(self.tempdir, 'Z*Z') + os.sep) + self.assertEqual(res, []) + res = glob.glob(os.path.join(self.tempdir, 'ZZZ') + os.sep) + self.assertEqual(res, []) + # When there is wildcard pattern which ends with os.sep, glob() + # doesn't blow up. + res = glob.glob(os.path.join(self.tempdir, 'aa*') + os.sep) + self.assertEqual(len(res), 2) # either of these results are reasonable - self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep]) + self.assertIn(set(res), [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) + + def test_glob_bytes_directory_with_trailing_slash(self): + # Same as test_glob_directory_with_trailing_slash, but with a + # bytes argument. + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'Z*Z') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'ZZZ') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'aa*') + os.sep)) + self.assertEqual(len(res), 2) + # either of these results are reasonable + self.assertIn({os.fsdecode(x) for x in res}, [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) @skip_unless_symlink def test_glob_broken_symlinks(self): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:05:48 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:05:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316696=3A_fix_comparison_between_bytes_and_strin?= =?utf-8?q?g=2E_Also=2C_improve_glob_tests=2E?= Message-ID: <3YPTMc5y5RzQ8k@mail.python.org> http://hg.python.org/cpython/rev/9e898ee68388 changeset: 80885:9e898ee68388 parent: 80881:bfb39fb93af7 parent: 80884:ed8134df30e4 user: Antoine Pitrou date: Sun Dec 16 16:03:57 2012 +0100 summary: Issue #16696: fix comparison between bytes and string. Also, improve glob tests. files: Lib/glob.py | 2 +- Lib/test/test_glob.py | 33 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -62,7 +62,7 @@ return fnmatch.filter(names, pattern) def glob0(dirname, basename): - if basename == '': + if not basename: # `os.path.split()` returns an empty basename for paths ending with a # directory separator. 'q*x/' should match only directories. if os.path.isdir(dirname): diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -97,12 +97,35 @@ os.path.join('aab', 'F')])) def test_glob_directory_with_trailing_slash(self): - # We are verifying that when there is wildcard pattern which - # ends with os.sep doesn't blow up. - res = glob.glob(self.tempdir + '*' + os.sep) - self.assertEqual(len(res), 1) + # Patterns ending with a slash shouldn't match non-dirs + res = glob.glob(os.path.join(self.tempdir, 'Z*Z') + os.sep) + self.assertEqual(res, []) + res = glob.glob(os.path.join(self.tempdir, 'ZZZ') + os.sep) + self.assertEqual(res, []) + # When there is wildcard pattern which ends with os.sep, glob() + # doesn't blow up. + res = glob.glob(os.path.join(self.tempdir, 'aa*') + os.sep) + self.assertEqual(len(res), 2) # either of these results are reasonable - self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep]) + self.assertIn(set(res), [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) + + def test_glob_bytes_directory_with_trailing_slash(self): + # Same as test_glob_directory_with_trailing_slash, but with a + # bytes argument. + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'Z*Z') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'ZZZ') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'aa*') + os.sep)) + self.assertEqual(len(res), 2) + # either of these results are reasonable + self.assertIn({os.fsdecode(x) for x in res}, [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) @skip_unless_symlink def test_glob_broken_symlinks(self): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:13:36 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:13:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_ResourceWa?= =?utf-8?q?rnings_in_test=5Fpty?= Message-ID: <3YPTXc6JMRzNpZ@mail.python.org> http://hg.python.org/cpython/rev/2ecea81adab0 changeset: 80886:2ecea81adab0 branch: 3.2 parent: 80883:96f19274de18 user: Antoine Pitrou date: Sun Dec 16 16:09:11 2012 +0100 summary: Fix ResourceWarnings in test_pty files: Lib/test/test_pty.py | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -215,7 +215,7 @@ for fd in self.fds: try: os.close(fd) - except: + except OSError: pass def _pipe(self): @@ -235,8 +235,9 @@ mock_stdin_fd, write_to_stdin_fd = self._pipe() pty.STDIN_FILENO = mock_stdin_fd socketpair = socket.socketpair() + for s in socketpair: + self.addCleanup(s.close) masters = [s.fileno() for s in socketpair] - self.fds.extend(masters) # Feed data. Smaller than PIPEBUF. These writes will not block. os.write(masters[1], b'from master') @@ -264,8 +265,9 @@ mock_stdin_fd, write_to_stdin_fd = self._pipe() pty.STDIN_FILENO = mock_stdin_fd socketpair = socket.socketpair() + for s in socketpair: + self.addCleanup(s.close) masters = [s.fileno() for s in socketpair] - self.fds.extend(masters) os.close(masters[1]) socketpair[1].close() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:13:38 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:13:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Null_merge?= Message-ID: <3YPTXf1fk2zP48@mail.python.org> http://hg.python.org/cpython/rev/5279b8db793a changeset: 80887:5279b8db793a branch: 3.3 parent: 80884:ed8134df30e4 parent: 80886:2ecea81adab0 user: Antoine Pitrou date: Sun Dec 16 16:11:31 2012 +0100 summary: Null merge files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:13:39 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:13:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Null_merge?= Message-ID: <3YPTXg3z1DzP6j@mail.python.org> http://hg.python.org/cpython/rev/31223665f750 changeset: 80888:31223665f750 parent: 80885:9e898ee68388 parent: 80887:5279b8db793a user: Antoine Pitrou date: Sun Dec 16 16:11:51 2012 +0100 summary: Null merge files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:42:54 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:42:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Silence_sporad?= =?utf-8?q?ic_failure_in_RecvmsgSCTPStreamTest=2EtestRecvmsgEOF_=28issue_?= =?utf-8?q?=2313876=29?= Message-ID: <3YPVBQ1DnkzP6j@mail.python.org> http://hg.python.org/cpython/rev/391bda06fa65 changeset: 80889:391bda06fa65 branch: 3.3 parent: 80887:5279b8db793a user: Antoine Pitrou date: Sun Dec 16 16:40:04 2012 +0100 summary: Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related. files: Lib/test/test_socket.py | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -3291,7 +3291,14 @@ @unittest.skipUnless(thread, 'Threading required for this test.') class RecvmsgSCTPStreamTest(RecvmsgTests, RecvmsgGenericStreamTests, SendrecvmsgSCTPStreamTestBase): - pass + + def testRecvmsgEOF(self): + try: + super(RecvmsgSCTPStreamTest, self).testRecvmsgEOF() + except OSError as e: + if e.errno != errno.ENOTCONN: + raise + self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876") @requireAttrs(socket.socket, "recvmsg_into") @requireSocket("AF_INET", "SOCK_STREAM", "IPPROTO_SCTP") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 16:42:55 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 16 Dec 2012 16:42:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Silence_sporadic_failure_in_RecvmsgSCTPStreamTest=2Etest?= =?utf-8?q?RecvmsgEOF_=28issue_=2313876=29?= Message-ID: <3YPVBR3Y3CzQPB@mail.python.org> http://hg.python.org/cpython/rev/2d2d4807a3ed changeset: 80890:2d2d4807a3ed parent: 80888:31223665f750 parent: 80889:391bda06fa65 user: Antoine Pitrou date: Sun Dec 16 16:40:22 2012 +0100 summary: Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related. files: Lib/test/test_socket.py | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -3291,7 +3291,14 @@ @unittest.skipUnless(thread, 'Threading required for this test.') class RecvmsgSCTPStreamTest(RecvmsgTests, RecvmsgGenericStreamTests, SendrecvmsgSCTPStreamTestBase): - pass + + def testRecvmsgEOF(self): + try: + super(RecvmsgSCTPStreamTest, self).testRecvmsgEOF() + except OSError as e: + if e.errno != errno.ENOTCONN: + raise + self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876") @requireAttrs(socket.socket, "recvmsg_into") @requireSocket("AF_INET", "SOCK_STREAM", "IPPROTO_SCTP") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 21:12:43 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 16 Dec 2012 21:12:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE1Nzgz?= =?utf-8?q?=3A_Support_None_default_values_in_the_Context=28=29_constructo?= =?utf-8?q?r=2E?= Message-ID: <3YPc9l5dxgzQXv@mail.python.org> http://hg.python.org/cpython/rev/907d71668d3c changeset: 80891:907d71668d3c branch: 3.3 parent: 80889:391bda06fa65 user: Stefan Krah date: Sun Dec 16 21:10:35 2012 +0100 summary: Issue #15783: Support None default values in the Context() constructor. files: Lib/test/test_decimal.py | 21 +++++++ Modules/_decimal/_decimal.c | 73 +++++++++++++----------- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -2718,6 +2718,27 @@ class ContextAPItests(unittest.TestCase): + def test_none_args(self): + Context = self.decimal.Context + InvalidOperation = self.decimal.InvalidOperation + DivisionByZero = self.decimal.DivisionByZero + Overflow = self.decimal.Overflow + ROUND_HALF_EVEN = self.decimal.ROUND_HALF_EVEN + + c1 = Context() + c2 = Context(prec=None, rounding=None, Emax=None, Emin=None, + capitals=None, clamp=None, flags=None, traps=None) + for c in [c1, c2]: + self.assertEqual(c.prec, 28) + self.assertEqual(c.rounding, ROUND_HALF_EVEN) + self.assertEqual(c.Emax, 999999) + self.assertEqual(c.Emin, -999999) + self.assertEqual(c.capitals, 1) + self.assertEqual(c.clamp, 0) + assert_signals(self, c, 'flags', []) + assert_signals(self, c, 'traps', [InvalidOperation, DivisionByZero, + Overflow]) + def test_pickle(self): Context = self.decimal.Context diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1241,50 +1241,53 @@ "prec", "rounding", "Emin", "Emax", "capitals", "clamp", "flags", "traps", NULL }; - PyObject *rounding = NULL; - PyObject *traps = NULL; - PyObject *status = NULL; - mpd_context_t *ctx, t; - int capitals = 1; + PyObject *prec = Py_None; + PyObject *rounding = Py_None; + PyObject *emin = Py_None; + PyObject *emax = Py_None; + PyObject *capitals = Py_None; + PyObject *clamp = Py_None; + PyObject *status = Py_None; + PyObject *traps = Py_None; int ret; assert(PyTuple_Check(args)); - ctx = CTX(self); - - t = *ctx; + if (!PyArg_ParseTupleAndKeywords( args, kwds, - "|nOnniiOO", kwlist, - &t.prec, &rounding, &t.emin, &t.emax, &capitals, &t.clamp, - &status, &traps + "|OOOOOOOO", kwlist, + &prec, &rounding, &emin, &emax, &capitals, &clamp, &status, &traps )) { return -1; } - if (rounding != NULL) { - t.round = getround(rounding); - if (t.round < 0) { + + if (prec != Py_None && context_setprec(self, prec, NULL) < 0) { + return -1; + } + if (emin != Py_None && context_setemin(self, emin, NULL) < 0) { + return -1; + } + if (emax != Py_None && context_setemax(self, emax, NULL) < 0) { + return -1; + } + if (capitals != Py_None && context_setcapitals(self, capitals, NULL) < 0) { + return -1; + } + if (clamp != Py_None && context_setclamp(self, clamp, NULL) < 0) { + return -1; + } + + if (rounding != Py_None) { + int x = getround(rounding); + if (x < 0) { return -1; } - } - - if (!mpd_qsetprec(ctx, t.prec) || - !mpd_qsetemin(ctx, t.emin) || - !mpd_qsetemax(ctx, t.emax) || - !mpd_qsetclamp(ctx, t.clamp)) { - return value_error_int("invalid context"); - } - if (!mpd_qsetround(ctx, t.round) || - !mpd_qsettraps(ctx, t.traps) || - !mpd_qsetstatus(ctx, t.status)) { - return type_error_int("invalid context"); - } - - if (capitals != 0 && capitals != 1) { - return value_error_int("invalid context"); - } - CtxCaps(self) = capitals; - - if (traps != NULL) { + if (!mpd_qsetround(CTX(self), x)) { + return type_error_int(invalid_rounding_err); + } + } + + if (traps != Py_None) { if (PyList_Check(traps)) { ret = context_settraps_list(self, traps); } @@ -1300,7 +1303,7 @@ return ret; } } - if (status != NULL) { + if (status != Py_None) { if (PyList_Check(status)) { ret = context_setstatus_list(self, status); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 21:12:45 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 16 Dec 2012 21:12:45 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4zLg==?= Message-ID: <3YPc9n2LVpzRJK@mail.python.org> http://hg.python.org/cpython/rev/9d5122548096 changeset: 80892:9d5122548096 parent: 80890:2d2d4807a3ed parent: 80891:907d71668d3c user: Stefan Krah date: Sun Dec 16 21:11:35 2012 +0100 summary: Merge 3.3. files: Lib/test/test_decimal.py | 21 +++++++ Modules/_decimal/_decimal.c | 73 +++++++++++++----------- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -2718,6 +2718,27 @@ class ContextAPItests(unittest.TestCase): + def test_none_args(self): + Context = self.decimal.Context + InvalidOperation = self.decimal.InvalidOperation + DivisionByZero = self.decimal.DivisionByZero + Overflow = self.decimal.Overflow + ROUND_HALF_EVEN = self.decimal.ROUND_HALF_EVEN + + c1 = Context() + c2 = Context(prec=None, rounding=None, Emax=None, Emin=None, + capitals=None, clamp=None, flags=None, traps=None) + for c in [c1, c2]: + self.assertEqual(c.prec, 28) + self.assertEqual(c.rounding, ROUND_HALF_EVEN) + self.assertEqual(c.Emax, 999999) + self.assertEqual(c.Emin, -999999) + self.assertEqual(c.capitals, 1) + self.assertEqual(c.clamp, 0) + assert_signals(self, c, 'flags', []) + assert_signals(self, c, 'traps', [InvalidOperation, DivisionByZero, + Overflow]) + def test_pickle(self): Context = self.decimal.Context diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1241,50 +1241,53 @@ "prec", "rounding", "Emin", "Emax", "capitals", "clamp", "flags", "traps", NULL }; - PyObject *rounding = NULL; - PyObject *traps = NULL; - PyObject *status = NULL; - mpd_context_t *ctx, t; - int capitals = 1; + PyObject *prec = Py_None; + PyObject *rounding = Py_None; + PyObject *emin = Py_None; + PyObject *emax = Py_None; + PyObject *capitals = Py_None; + PyObject *clamp = Py_None; + PyObject *status = Py_None; + PyObject *traps = Py_None; int ret; assert(PyTuple_Check(args)); - ctx = CTX(self); - - t = *ctx; + if (!PyArg_ParseTupleAndKeywords( args, kwds, - "|nOnniiOO", kwlist, - &t.prec, &rounding, &t.emin, &t.emax, &capitals, &t.clamp, - &status, &traps + "|OOOOOOOO", kwlist, + &prec, &rounding, &emin, &emax, &capitals, &clamp, &status, &traps )) { return -1; } - if (rounding != NULL) { - t.round = getround(rounding); - if (t.round < 0) { + + if (prec != Py_None && context_setprec(self, prec, NULL) < 0) { + return -1; + } + if (emin != Py_None && context_setemin(self, emin, NULL) < 0) { + return -1; + } + if (emax != Py_None && context_setemax(self, emax, NULL) < 0) { + return -1; + } + if (capitals != Py_None && context_setcapitals(self, capitals, NULL) < 0) { + return -1; + } + if (clamp != Py_None && context_setclamp(self, clamp, NULL) < 0) { + return -1; + } + + if (rounding != Py_None) { + int x = getround(rounding); + if (x < 0) { return -1; } - } - - if (!mpd_qsetprec(ctx, t.prec) || - !mpd_qsetemin(ctx, t.emin) || - !mpd_qsetemax(ctx, t.emax) || - !mpd_qsetclamp(ctx, t.clamp)) { - return value_error_int("invalid context"); - } - if (!mpd_qsetround(ctx, t.round) || - !mpd_qsettraps(ctx, t.traps) || - !mpd_qsetstatus(ctx, t.status)) { - return type_error_int("invalid context"); - } - - if (capitals != 0 && capitals != 1) { - return value_error_int("invalid context"); - } - CtxCaps(self) = capitals; - - if (traps != NULL) { + if (!mpd_qsetround(CTX(self), x)) { + return type_error_int(invalid_rounding_err); + } + } + + if (traps != Py_None) { if (PyList_Check(traps)) { ret = context_settraps_list(self, traps); } @@ -1300,7 +1303,7 @@ return ret; } } - if (status != NULL) { + if (status != Py_None) { if (PyList_Check(status)) { ret = context_setstatus_list(self, status); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 16 23:26:54 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sun, 16 Dec 2012 23:26:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Various_small_updates=2E?= Message-ID: <3YPg8Z4WKbzMlY@mail.python.org> http://hg.python.org/peps/rev/0d6b37097336 changeset: 4616:0d6b37097336 user: Guido van Rossum date: Sun Dec 16 14:26:48 2012 -0800 summary: Various small updates. files: pep-3156.txt | 38 ++++++++++++++++++++++++++++++++------ 1 files changed, 32 insertions(+), 6 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -120,16 +120,22 @@ object depending on the current thread, or depending on some other notion of context. -To set the current event loop, use ``set_event_loop(eventloop)``, -where ``eventloop`` is an instance of the ``EventLoop`` class or +To set the current event loop, use ``set_event_loop(event_loop)``, +where ``event_loop`` is an instance of the ``EventLoop`` class or equivalent. This uses the same notion of context as ``get_event_loop()``. -To change the way ``get_event_loop()`` and ``set_event_loop()`` work +For the benefit of unit tests and other special cases there's a third +policy function: ``init_event_loop()``, which creates a new EventLoop +instance and calls ``set_event_loop()`` with it. TBD: Maybe we should +have a ``create_default_event_loop_instance()`` function instead? + +To change the way the above three functions work (including their notion of context), call ``set_event_loop_policy(policy)``, where ``policy`` is an event loop policy object. The policy object can be any object that has methods -``get_event_loop()`` and ``set_event_loop(eventloop)`` behaving like +``get_event_loop()``, ``set_event_loop(event_loop)`` +and ``init_event_loop()`` behaving like the functions described above. The default event loop policy is an instance of the class ``DefaultEventLoopPolicy``. The current event loop policy object can be retrieved by calling ``get_event_loop_policy()``. @@ -219,7 +225,7 @@ ``run_in_executor()``, but other implementations may choose to implement their own DNS lookup. -- ``getnameinfo(sockaddr, flags)``. Similar to +- ``getnameinfo(sockaddr, flags=0)``. Similar to ``socket.getnameinfo()`` but returns a Future. The Future's result on success will be a tuple ``(host, port)``. Same implementation remarks as for ``getaddrinfo()``. @@ -436,7 +442,9 @@ and ignoring the convention from the section "Callback Style" below) is always called with a single argument, the Future object. -The internal methods defined in PEP 3148 are not supported. +The internal methods defined in PEP 3148 are not supported. (TBD: +Maybe we do need to support these, in order to make it easy to write +user code that returns a Future?) A ``tulip.Future`` object is not acceptable to the ``wait()`` and ``as_completed()`` functions in the ``concurrent.futures`` package. @@ -446,6 +454,11 @@ ``__iter__()`` interface on the Future. See the section "Coroutines and the Scheduler" below. +When a Future is garbage-collected, if it has an associated exception +but neither ``result()`` nor ``exception()`` nor ``__iter__()`` has +ever been called (or the latter hasn't raised the exception yet -- +details TBD), the exception should be logged. TBD: At what level? + In the future (pun intended) we may unify ``tulip.Future`` and ``concurrent.futures.Future``, e.g. by adding an ``__iter__()`` method to the latter that works with ``yield from``. To prevent accidentally @@ -737,6 +750,17 @@ public interface of the event loop, so it will work with third-party event loop implementations, too. +Sleeping +-------- + +TBD: ``yield sleep(seconds)``. Can use ``sleep(0)`` to suspend to +poll for I/O. + +Wait for First +-------------- + +TBD: Need an interface to wait for the first of a collection of Futures. + Coroutines and Protocols ------------------------ @@ -762,6 +786,8 @@ any ``yield from`` operation). We need to spell out which exception is raised. +Also TBD: timeouts. + Open Issues =========== -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Mon Dec 17 05:02:00 2012 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 17 Dec 2012 05:02:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_set=5Fdefault=5Fexecutor?= =?utf-8?b?KCku?= Message-ID: <3YPpbD6P7XzN68@mail.python.org> http://hg.python.org/peps/rev/cbd52096d415 changeset: 4617:cbd52096d415 user: Guido van Rossum date: Sun Dec 16 20:01:54 2012 -0800 summary: Add set_default_executor(). files: pep-3156.txt | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -217,6 +217,9 @@ executor? Should be be able to set its thread count? Shoul we even have this method?) +- ``set_default_executor(executor)``. Set the default executor used + by ``run_in_executor()``. + - ``getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)``. Similar to the ``socket.getaddrinfo()`` function but returns a Future. The Future's result on success will be a list of the same -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Mon Dec 17 05:56:42 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 17 Dec 2012 05:56:42 +0100 Subject: [Python-checkins] Daily reference leaks (9d5122548096): sum=8 Message-ID: results for 9d5122548096 on branch "default" -------------------------------------------- test_concurrent_futures leaked [-2, 3, 1] memory blocks, sum=2 test_dbm leaked [0, 2, 0] references, sum=2 test_dbm leaked [0, 2, 2] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogzmrJ2A', '-x'] From python-checkins at python.org Mon Dec 17 07:18:57 2012 From: python-checkins at python.org (brian.curtin) Date: Mon, 17 Dec 2012 07:18:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4ICMxNDkwMS4g?= =?utf-8?q?Update_the_Windows_FAQ=2E?= Message-ID: <3YPsdF6y1WzNjb@mail.python.org> http://hg.python.org/cpython/rev/5edbd93509b8 changeset: 80893:5edbd93509b8 branch: 3.2 parent: 80886:2ecea81adab0 user: Brian Curtin date: Sun Dec 16 23:58:09 2012 -0600 summary: Fix #14901. Update the Windows FAQ. Patch by Ashish Nitin Patil. files: Doc/faq/windows.rst | 332 ++----------------------------- Misc/NEWS | 3 + 2 files changed, 30 insertions(+), 305 deletions(-) diff --git a/Doc/faq/windows.rst b/Doc/faq/windows.rst --- a/Doc/faq/windows.rst +++ b/Doc/faq/windows.rst @@ -17,9 +17,7 @@ This is not necessarily a straightforward question. If you are already familiar with running programs from the Windows command line then everything will seem -obvious; otherwise, you might need a little more guidance. There are also -differences between Windows 95, 98, NT, ME, 2000 and XP which can add to the -confusion. +obvious; otherwise, you might need a little more guidance. .. sidebar:: |Python Development on XP|_ :subtitle: `Python Development on XP`_ @@ -36,7 +34,7 @@ Unless you use some sort of integrated development environment, you will end up *typing* Windows commands into what is variously referred to as a "DOS window" or "Command prompt window". Usually you can create such a window from your -Start menu; under Windows 2000 the menu selection is :menuselection:`Start --> +Start menu; under Windows 7 the menu selection is :menuselection:`Start --> Programs --> Accessories --> Command Prompt`. You should be able to recognize when you have started such a window because you will see a Windows "command prompt", which usually looks like this:: @@ -46,23 +44,27 @@ The letter may be different, and there might be other things after it, so you might just as easily see something like:: - D:\Steve\Projects\Python> + D:\YourName\Projects\Python> depending on how your computer has been set up and what else you have recently done with it. Once you have started such a window, you are well on the way to running Python programs. You need to realize that your Python scripts have to be processed by another -program called the Python interpreter. The interpreter reads your script, +program called the Python *interpreter*. The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program. So, how do you arrange for the interpreter to handle your Python? First, you need to make sure that your command window recognises the word "python" as an instruction to start the interpreter. If you have opened a command window, you should try entering the command ``python`` and hitting -return. You should then see something like:: +return.:: - Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 + C:\Users\YourName> python + +You should then see something like:: + + Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> @@ -82,7 +84,7 @@ Windows command prompt. You may also find that you have a Start-menu entry such as :menuselection:`Start ---> Programs --> Python 2.2 --> Python (command line)` that results in you +--> Programs --> Python 3.3 --> Python (command line)` that results in you seeing the ``>>>`` prompt in a new window. If so, the window will disappear after you enter the Ctrl-Z character; Windows is running a single "python" command in the window, and closes it when you terminate the interpreter. @@ -90,8 +92,7 @@ If the ``python`` command, instead of displaying the interpreter prompt ``>>>``, gives you a message like:: - 'python' is not recognized as an internal or external command, - operable program or batch file. + 'python' is not recognized as an internal or external command, operable program or batch file. .. sidebar:: |Adding Python to DOS Path|_ :subtitle: `Adding Python to DOS Path`_ @@ -120,115 +121,33 @@ dir C:\py* will probably tell you where it is installed; the usual location is something -like ``C:\Python23``. Otherwise you will be reduced to a search of your whole +like ``C:\Python33``. Otherwise you will be reduced to a search of your whole disk ... use :menuselection:`Tools --> Find` or hit the :guilabel:`Search` button and look for "python.exe". Supposing you discover that Python is -installed in the ``C:\Python23`` directory (the default at the time of writing), +installed in the ``C:\Python33`` directory (the default at the time of writing), you should make sure that entering the command :: - c:\Python23\python + c:\Python33\python starts up the interpreter as above (and don't forget you'll need a "CTRL-Z" and -an "Enter" to get out of it). Once you have verified the directory, you need to -add it to the start-up routines your computer goes through. For older versions -of Windows the easiest way to do this is to edit the ``C:\AUTOEXEC.BAT`` -file. You would want to add a line like the following to ``AUTOEXEC.BAT``:: +an "Enter" to get out of it). Once you have verified the directory, you can +add it to the system path to make it easier to start Python by just running +the ``python`` command. This is currently an option in the installer as of +CPython 3.3. - PATH C:\Python23;%PATH% - -For Windows NT, 2000 and (I assume) XP, you will need to add a string such as :: - - ;C:\Python23 - -to the current setting for the PATH environment variable, which you will find in -the properties window of "My Computer" under the "Advanced" tab. Note that if -you have sufficient privilege you might get a choice of installing the settings -either for the Current User or for System. The latter is preferred if you want -everybody to be able to run Python on the machine. - -If you aren't confident doing any of these manipulations yourself, ask for help! -At this stage you may want to reboot your system to make absolutely sure the new -setting has taken effect. You probably won't need to reboot for Windows NT, XP -or 2000. You can also avoid it in earlier versions by editing the file -``C:\WINDOWS\COMMAND\CMDINIT.BAT`` instead of ``AUTOEXEC.BAT``. - -You should now be able to start a new command window, enter ``python`` at the -``C:\>`` (or whatever) prompt, and see the ``>>>`` prompt that indicates the -Python interpreter is reading interactive commands. - -Let's suppose you have a program called ``pytest.py`` in directory -``C:\Steve\Projects\Python``. A session to run that program might look like -this:: - - C:\> cd \Steve\Projects\Python - C:\Steve\Projects\Python> python pytest.py - -Because you added a file name to the command to start the interpreter, when it -starts up it reads the Python script in the named file, compiles it, executes -it, and terminates, so you see another ``C:\>`` prompt. You might also have -entered :: - - C:\> python \Steve\Projects\Python\pytest.py - -if you hadn't wanted to change your current directory. - -Under NT, 2000 and XP you may well find that the installation process has also -arranged that the command ``pytest.py`` (or, if the file isn't in the current -directory, ``C:\Steve\Projects\Python\pytest.py``) will automatically recognize -the ".py" extension and run the Python interpreter on the named file. Using this -feature is fine, but *some* versions of Windows have bugs which mean that this -form isn't exactly equivalent to using the interpreter explicitly, so be -careful. - -The important things to remember are: - -1. Start Python from the Start Menu, or make sure the PATH is set correctly so - Windows can find the Python interpreter. :: - - python - - should give you a '>>>' prompt from the Python interpreter. Don't forget the - CTRL-Z and ENTER to terminate the interpreter (and, if you started the window - from the Start Menu, make the window disappear). - -2. Once this works, you run programs with commands:: - - python {program-file} - -3. When you know the commands to use you can build Windows shortcuts to run the - Python interpreter on any of your scripts, naming particular working - directories, and adding them to your menus. Take a look at :: - - python --help - - if your needs are complex. - -4. Interactive mode (where you see the ``>>>`` prompt) is best used for checking - that individual statements and expressions do what you think they will, and - for developing code by experiment. - +More information about environment variables can be found on the +:ref:`Using Python on Windows ` page. How do I make Python scripts executable? ---------------------------------------- -On Windows 2000, the standard Python installer already associates the .py +On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (``D:\Program Files\Python\python.exe "%1" %*``). This is enough to make scripts executable from the command prompt as 'foo.py'. If you'd rather be able to execute the script by simple typing 'foo' with no extension you need to add .py to the PATHEXT environment variable. -On Windows NT, the steps taken by the installer as described above allow you to -run a script with 'foo.py', but a longtime bug in the NT command processor -prevents you from redirecting the input or output of any script executed in this -way. This is often important. - -The incantation for making a Python script executable under WinNT is to give the -file an extension of .cmd and add the following as the first line:: - - @setlocal enableextensions & python -x %~f0 %* & goto :EOF - - Why does Python sometimes take so long to start? ------------------------------------------------ @@ -246,22 +165,11 @@ offender. -Where is Freeze for Windows? ----------------------------- +How do I make an executable from a Python script? +------------------------------------------------- -"Freeze" is a program that allows you to ship a Python program as a single -stand-alone executable file. It is *not* a compiler; your programs don't run -any faster, but they are more easily distributable, at least to platforms with -the same OS and CPU. Read the README file of the freeze program for more -disclaimers. - -You can use freeze on Windows, but you must download the source tree (see -http://www.python.org/download/source). The freeze program is in the -``Tools\freeze`` subdirectory of the source tree. - -You need the Microsoft VC++ compiler, and you probably need to build Python. -The required project files are in the PCbuild directory. - +See http://www.py2exe.org/ for a distutils extension that allows you +to create console and GUI executables from Python code. Is a ``*.pyd`` file the same as a DLL? -------------------------------------- @@ -292,7 +200,7 @@ be a DLL to handle importing modules that are themselves DLL's. (This is the first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is typically installed in ``C:\Windows\System``. *NN* is the Python version, a - number such as "23" for Python 2.3. + number such as "33" for Python 3.3. You can link to Python in two different ways. Load-time linking means linking against :file:`python{NN}.lib`, while run-time linking means linking @@ -376,47 +284,6 @@ object that supports read and write, so all you need is a Python object (defined in your extension module) that contains read() and write() methods. - -How do I use Python for CGI? ----------------------------- - -On the Microsoft IIS server or on the Win95 MS Personal Web Server you set up -Python in the same way that you would set up any other scripting engine. - -Run regedt32 and go to:: - - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap - -and enter the following line (making any specific changes that your system may -need):: - - .py :REG_SZ: c:\\python.exe -u %s %s - -This line will allow you to call your script with a simple reference like: -``http://yourserver/scripts/yourscript.py`` provided "scripts" is an -"executable" directory for your server (which it usually is by default). The -:option:`-u` flag specifies unbuffered and binary mode for stdin - needed when -working with binary data. - -In addition, it is recommended that using ".py" may not be a good idea for the -file extensions when used in this context (you might want to reserve ``*.py`` -for support modules and use ``*.cgi`` or ``*.cgp`` for "main program" scripts). - -In order to set up Internet Information Services 5 to use Python for CGI -processing, please see the following links: - - http://www.e-coli.net/pyiis_server.html (for Win2k Server) - http://www.e-coli.net/pyiis.html (for Win2k pro) - -Configuring Apache is much simpler. In the Apache configuration file -``httpd.conf``, add the following line at the end of the file:: - - ScriptInterpreterSource Registry - -Then, give your Python CGI-scripts the extension .py and put them in the cgi-bin -directory. - - How do I keep editors from inserting tabs into my Python source? ---------------------------------------------------------------- @@ -460,116 +327,6 @@ to console subprocesses which are designed to handle those signals. See :func:`os.kill` for further details. - -Why does os.path.isdir() fail on NT shared directories? -------------------------------------------------------- - -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') - 0 - >>> os.path.isdir('\\\\rorschach\\public\\') - 1 - -It helps to think of share points as being like drive letters. Example:: - - k: is not a directory - k:\ is a directory - k:\media is a directory - k:\media\ is not a directory - -The same rules apply if you substitute ``"k:"`` with ``"\\conky\foo"``:: - - \\conky\foo is not a directory - \\conky\foo\ is a directory - \\conky\foo\media is a directory - \\conky\foo\media\ is not a directory - - -cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! ------------------------------------------------------------------------- - -Be sure you have the latest python.exe, that you are using python.exe rather -than a GUI version of Python and that you have configured the server to execute -:: - - "...\python.exe -u ..." - -for the CGI execution. The :option:`-u` (unbuffered) option on NT and Win95 -prevents the interpreter from altering newlines in the standard input and -output. Without it post/multipart requests will seem to have the wrong length -and binary (e.g. GIF) responses may get garbled (resulting in broken images, PDF -files, and other binary downloads failing). - - -Why doesn't os.popen() work in PythonWin on NT? ------------------------------------------------ - -The reason that os.popen() doesn't work from within PythonWin is due to a bug in -Microsoft's C Runtime Library (CRT). The CRT assumes you have a Win32 console -attached to the process. - -You should use the win32pipe module's popen() instead which doesn't depend on -having an attached Win32 console. - -Example:: - - import win32pipe - f = win32pipe.popen('dir /c c:\\') - print(f.readlines()) - f.close() - - -Why doesn't os.popen()/win32pipe.popen() work on Win9x? -------------------------------------------------------- - -There is a bug in Win9x that prevents os.popen/win32pipe.popen* from -working. The good news is there is a way to work around this problem. The -Microsoft Knowledge Base article that you need to lookup is: Q150956. You will -find links to the knowledge base at: http://support.microsoft.com/. - - -PyRun_SimpleFile() crashes on Windows but not on Unix; why? ------------------------------------------------------------ - -This is very sensitive to the compiler vendor, version and (perhaps) even -options. If the FILE* structure in your embedding program isn't the same as is -assumed by the Python interpreter it won't work. - -The Python 1.5.* DLLs (``python15.dll``) are all compiled with MS VC++ 5.0 and -with multithreading-DLL options (``/MD``). - -If you can't change compilers or flags, try using :c:func:`Py_RunSimpleString`. -A trick to get it to run an arbitrary file is to construct a call to -:func:`exec` and :func:`open` with the name of your file as argument. - -Also note that you can not mix-and-match Debug and Release versions. If you -wish to use the Debug Multithreaded DLL, then your module *must* have ``_d`` -appended to the base name. - - -Importing _tkinter fails on Windows 95/98: why? ------------------------------------------------- - -Sometimes, the import of _tkinter fails on Windows 95 or 98, complaining with a -message like the following:: - - ImportError: DLL load failed: One of the library files needed - to run this application cannot be found. - -It could be that you haven't installed Tcl/Tk, but if you did install Tcl/Tk, -and the Wish application works correctly, the problem may be that its installer -didn't manage to edit the autoexec.bat file correctly. It tries to add a -statement that changes the PATH environment variable to include the Tcl/Tk 'bin' -subdirectory, but sometimes this edit doesn't quite work. Opening it with -notepad usually reveals what the problem is. - -(One additional hint, noted by David Szafranski: you can't use long filenames -here; e.g. use ``C:\PROGRA~1\Tcl\bin`` instead of ``C:\Program Files\Tcl\bin``.) - - How do I extract the downloaded documentation on Windows? --------------------------------------------------------- @@ -581,38 +338,3 @@ able to handle it. (If your copy of WinZip doesn't, get a newer one from http://www.winzip.com.) - -Missing cw3215mt.dll (or missing cw3215.dll) --------------------------------------------- - -Sometimes, when using Tkinter on Windows, you get an error that cw3215mt.dll or -cw3215.dll is missing. - -Cause: you have an old Tcl/Tk DLL built with cygwin in your path (probably -``C:\Windows``). You must use the Tcl/Tk DLLs from the standard Tcl/Tk -installation (Python 1.5.2 comes with one). - - -Warning about CTL3D32 version from installer --------------------------------------------- - -The Python installer issues a warning like this:: - - This version uses CTL3D32.DLL which is not the correct version. - This version is used for windows NT applications only. - -Tim Peters: - - This is a Microsoft DLL, and a notorious source of problems. The message - means what it says: you have the wrong version of this DLL for your operating - system. The Python installation did not cause this -- something else you - installed previous to this overwrote the DLL that came with your OS (probably - older shareware of some sort, but there's no way to tell now). If you search - for "CTL3D32" using any search engine (AltaVista, for example), you'll find - hundreds and hundreds of web pages complaining about the same problem with - all sorts of installation programs. They'll point you to ways to get the - correct version reinstalled on your system (since Python doesn't cause this, - we can't fix it). - -David A Burton has written a little program to fix this. Go to -http://www.burtonsys.com/downloads.html and click on "ctl3dfix.zip". diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -799,6 +799,9 @@ Documentation ------------- +- Issue #14901: Update portions of the Windows FAQ. + Patch by Ashish Nitin Patil. + - Issue #15990: Improve argument/parameter documentation. - Issue #13538: Improve str() and object.__str__() documentation. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 07:18:59 2012 From: python-checkins at python.org (brian.curtin) Date: Mon, 17 Dec 2012 07:18:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_3=2E2?= Message-ID: <3YPsdH4pfdzNp9@mail.python.org> http://hg.python.org/cpython/rev/bd7c8631a89d changeset: 80894:bd7c8631a89d branch: 3.3 parent: 80891:907d71668d3c parent: 80893:5edbd93509b8 user: Brian Curtin date: Mon Dec 17 00:04:30 2012 -0600 summary: Merge 3.2 files: Doc/faq/windows.rst | 332 ++----------------------------- Misc/NEWS | 3 + 2 files changed, 30 insertions(+), 305 deletions(-) diff --git a/Doc/faq/windows.rst b/Doc/faq/windows.rst --- a/Doc/faq/windows.rst +++ b/Doc/faq/windows.rst @@ -17,9 +17,7 @@ This is not necessarily a straightforward question. If you are already familiar with running programs from the Windows command line then everything will seem -obvious; otherwise, you might need a little more guidance. There are also -differences between Windows 95, 98, NT, ME, 2000 and XP which can add to the -confusion. +obvious; otherwise, you might need a little more guidance. .. sidebar:: |Python Development on XP|_ :subtitle: `Python Development on XP`_ @@ -36,7 +34,7 @@ Unless you use some sort of integrated development environment, you will end up *typing* Windows commands into what is variously referred to as a "DOS window" or "Command prompt window". Usually you can create such a window from your -Start menu; under Windows 2000 the menu selection is :menuselection:`Start --> +Start menu; under Windows 7 the menu selection is :menuselection:`Start --> Programs --> Accessories --> Command Prompt`. You should be able to recognize when you have started such a window because you will see a Windows "command prompt", which usually looks like this:: @@ -46,23 +44,27 @@ The letter may be different, and there might be other things after it, so you might just as easily see something like:: - D:\Steve\Projects\Python> + D:\YourName\Projects\Python> depending on how your computer has been set up and what else you have recently done with it. Once you have started such a window, you are well on the way to running Python programs. You need to realize that your Python scripts have to be processed by another -program called the Python interpreter. The interpreter reads your script, +program called the Python *interpreter*. The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program. So, how do you arrange for the interpreter to handle your Python? First, you need to make sure that your command window recognises the word "python" as an instruction to start the interpreter. If you have opened a command window, you should try entering the command ``python`` and hitting -return. You should then see something like:: +return.:: - Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 + C:\Users\YourName> python + +You should then see something like:: + + Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> @@ -82,7 +84,7 @@ Windows command prompt. You may also find that you have a Start-menu entry such as :menuselection:`Start ---> Programs --> Python 2.2 --> Python (command line)` that results in you +--> Programs --> Python 3.3 --> Python (command line)` that results in you seeing the ``>>>`` prompt in a new window. If so, the window will disappear after you enter the Ctrl-Z character; Windows is running a single "python" command in the window, and closes it when you terminate the interpreter. @@ -90,8 +92,7 @@ If the ``python`` command, instead of displaying the interpreter prompt ``>>>``, gives you a message like:: - 'python' is not recognized as an internal or external command, - operable program or batch file. + 'python' is not recognized as an internal or external command, operable program or batch file. .. sidebar:: |Adding Python to DOS Path|_ :subtitle: `Adding Python to DOS Path`_ @@ -120,115 +121,33 @@ dir C:\py* will probably tell you where it is installed; the usual location is something -like ``C:\Python23``. Otherwise you will be reduced to a search of your whole +like ``C:\Python33``. Otherwise you will be reduced to a search of your whole disk ... use :menuselection:`Tools --> Find` or hit the :guilabel:`Search` button and look for "python.exe". Supposing you discover that Python is -installed in the ``C:\Python23`` directory (the default at the time of writing), +installed in the ``C:\Python33`` directory (the default at the time of writing), you should make sure that entering the command :: - c:\Python23\python + c:\Python33\python starts up the interpreter as above (and don't forget you'll need a "CTRL-Z" and -an "Enter" to get out of it). Once you have verified the directory, you need to -add it to the start-up routines your computer goes through. For older versions -of Windows the easiest way to do this is to edit the ``C:\AUTOEXEC.BAT`` -file. You would want to add a line like the following to ``AUTOEXEC.BAT``:: +an "Enter" to get out of it). Once you have verified the directory, you can +add it to the system path to make it easier to start Python by just running +the ``python`` command. This is currently an option in the installer as of +CPython 3.3. - PATH C:\Python23;%PATH% - -For Windows NT, 2000 and (I assume) XP, you will need to add a string such as :: - - ;C:\Python23 - -to the current setting for the PATH environment variable, which you will find in -the properties window of "My Computer" under the "Advanced" tab. Note that if -you have sufficient privilege you might get a choice of installing the settings -either for the Current User or for System. The latter is preferred if you want -everybody to be able to run Python on the machine. - -If you aren't confident doing any of these manipulations yourself, ask for help! -At this stage you may want to reboot your system to make absolutely sure the new -setting has taken effect. You probably won't need to reboot for Windows NT, XP -or 2000. You can also avoid it in earlier versions by editing the file -``C:\WINDOWS\COMMAND\CMDINIT.BAT`` instead of ``AUTOEXEC.BAT``. - -You should now be able to start a new command window, enter ``python`` at the -``C:\>`` (or whatever) prompt, and see the ``>>>`` prompt that indicates the -Python interpreter is reading interactive commands. - -Let's suppose you have a program called ``pytest.py`` in directory -``C:\Steve\Projects\Python``. A session to run that program might look like -this:: - - C:\> cd \Steve\Projects\Python - C:\Steve\Projects\Python> python pytest.py - -Because you added a file name to the command to start the interpreter, when it -starts up it reads the Python script in the named file, compiles it, executes -it, and terminates, so you see another ``C:\>`` prompt. You might also have -entered :: - - C:\> python \Steve\Projects\Python\pytest.py - -if you hadn't wanted to change your current directory. - -Under NT, 2000 and XP you may well find that the installation process has also -arranged that the command ``pytest.py`` (or, if the file isn't in the current -directory, ``C:\Steve\Projects\Python\pytest.py``) will automatically recognize -the ".py" extension and run the Python interpreter on the named file. Using this -feature is fine, but *some* versions of Windows have bugs which mean that this -form isn't exactly equivalent to using the interpreter explicitly, so be -careful. - -The important things to remember are: - -1. Start Python from the Start Menu, or make sure the PATH is set correctly so - Windows can find the Python interpreter. :: - - python - - should give you a '>>>' prompt from the Python interpreter. Don't forget the - CTRL-Z and ENTER to terminate the interpreter (and, if you started the window - from the Start Menu, make the window disappear). - -2. Once this works, you run programs with commands:: - - python {program-file} - -3. When you know the commands to use you can build Windows shortcuts to run the - Python interpreter on any of your scripts, naming particular working - directories, and adding them to your menus. Take a look at :: - - python --help - - if your needs are complex. - -4. Interactive mode (where you see the ``>>>`` prompt) is best used for checking - that individual statements and expressions do what you think they will, and - for developing code by experiment. - +More information about environment variables can be found on the +:ref:`Using Python on Windows ` page. How do I make Python scripts executable? ---------------------------------------- -On Windows 2000, the standard Python installer already associates the .py +On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (``D:\Program Files\Python\python.exe "%1" %*``). This is enough to make scripts executable from the command prompt as 'foo.py'. If you'd rather be able to execute the script by simple typing 'foo' with no extension you need to add .py to the PATHEXT environment variable. -On Windows NT, the steps taken by the installer as described above allow you to -run a script with 'foo.py', but a longtime bug in the NT command processor -prevents you from redirecting the input or output of any script executed in this -way. This is often important. - -The incantation for making a Python script executable under WinNT is to give the -file an extension of .cmd and add the following as the first line:: - - @setlocal enableextensions & python -x %~f0 %* & goto :EOF - - Why does Python sometimes take so long to start? ------------------------------------------------ @@ -246,22 +165,11 @@ offender. -Where is Freeze for Windows? ----------------------------- +How do I make an executable from a Python script? +------------------------------------------------- -"Freeze" is a program that allows you to ship a Python program as a single -stand-alone executable file. It is *not* a compiler; your programs don't run -any faster, but they are more easily distributable, at least to platforms with -the same OS and CPU. Read the README file of the freeze program for more -disclaimers. - -You can use freeze on Windows, but you must download the source tree (see -http://www.python.org/download/source). The freeze program is in the -``Tools\freeze`` subdirectory of the source tree. - -You need the Microsoft VC++ compiler, and you probably need to build Python. -The required project files are in the PCbuild directory. - +See http://www.py2exe.org/ for a distutils extension that allows you +to create console and GUI executables from Python code. Is a ``*.pyd`` file the same as a DLL? -------------------------------------- @@ -292,7 +200,7 @@ be a DLL to handle importing modules that are themselves DLL's. (This is the first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is typically installed in ``C:\Windows\System``. *NN* is the Python version, a - number such as "23" for Python 2.3. + number such as "33" for Python 3.3. You can link to Python in two different ways. Load-time linking means linking against :file:`python{NN}.lib`, while run-time linking means linking @@ -376,47 +284,6 @@ object that supports read and write, so all you need is a Python object (defined in your extension module) that contains read() and write() methods. - -How do I use Python for CGI? ----------------------------- - -On the Microsoft IIS server or on the Win95 MS Personal Web Server you set up -Python in the same way that you would set up any other scripting engine. - -Run regedt32 and go to:: - - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap - -and enter the following line (making any specific changes that your system may -need):: - - .py :REG_SZ: c:\\python.exe -u %s %s - -This line will allow you to call your script with a simple reference like: -``http://yourserver/scripts/yourscript.py`` provided "scripts" is an -"executable" directory for your server (which it usually is by default). The -:option:`-u` flag specifies unbuffered and binary mode for stdin - needed when -working with binary data. - -In addition, it is recommended that using ".py" may not be a good idea for the -file extensions when used in this context (you might want to reserve ``*.py`` -for support modules and use ``*.cgi`` or ``*.cgp`` for "main program" scripts). - -In order to set up Internet Information Services 5 to use Python for CGI -processing, please see the following links: - - http://www.e-coli.net/pyiis_server.html (for Win2k Server) - http://www.e-coli.net/pyiis.html (for Win2k pro) - -Configuring Apache is much simpler. In the Apache configuration file -``httpd.conf``, add the following line at the end of the file:: - - ScriptInterpreterSource Registry - -Then, give your Python CGI-scripts the extension .py and put them in the cgi-bin -directory. - - How do I keep editors from inserting tabs into my Python source? ---------------------------------------------------------------- @@ -460,116 +327,6 @@ to console subprocesses which are designed to handle those signals. See :func:`os.kill` for further details. - -Why does os.path.isdir() fail on NT shared directories? -------------------------------------------------------- - -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') - 0 - >>> os.path.isdir('\\\\rorschach\\public\\') - 1 - -It helps to think of share points as being like drive letters. Example:: - - k: is not a directory - k:\ is a directory - k:\media is a directory - k:\media\ is not a directory - -The same rules apply if you substitute ``"k:"`` with ``"\\conky\foo"``:: - - \\conky\foo is not a directory - \\conky\foo\ is a directory - \\conky\foo\media is a directory - \\conky\foo\media\ is not a directory - - -cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! ------------------------------------------------------------------------- - -Be sure you have the latest python.exe, that you are using python.exe rather -than a GUI version of Python and that you have configured the server to execute -:: - - "...\python.exe -u ..." - -for the CGI execution. The :option:`-u` (unbuffered) option on NT and Win95 -prevents the interpreter from altering newlines in the standard input and -output. Without it post/multipart requests will seem to have the wrong length -and binary (e.g. GIF) responses may get garbled (resulting in broken images, PDF -files, and other binary downloads failing). - - -Why doesn't os.popen() work in PythonWin on NT? ------------------------------------------------ - -The reason that os.popen() doesn't work from within PythonWin is due to a bug in -Microsoft's C Runtime Library (CRT). The CRT assumes you have a Win32 console -attached to the process. - -You should use the win32pipe module's popen() instead which doesn't depend on -having an attached Win32 console. - -Example:: - - import win32pipe - f = win32pipe.popen('dir /c c:\\') - print(f.readlines()) - f.close() - - -Why doesn't os.popen()/win32pipe.popen() work on Win9x? -------------------------------------------------------- - -There is a bug in Win9x that prevents os.popen/win32pipe.popen* from -working. The good news is there is a way to work around this problem. The -Microsoft Knowledge Base article that you need to lookup is: Q150956. You will -find links to the knowledge base at: http://support.microsoft.com/. - - -PyRun_SimpleFile() crashes on Windows but not on Unix; why? ------------------------------------------------------------ - -This is very sensitive to the compiler vendor, version and (perhaps) even -options. If the FILE* structure in your embedding program isn't the same as is -assumed by the Python interpreter it won't work. - -The Python 1.5.* DLLs (``python15.dll``) are all compiled with MS VC++ 5.0 and -with multithreading-DLL options (``/MD``). - -If you can't change compilers or flags, try using :c:func:`Py_RunSimpleString`. -A trick to get it to run an arbitrary file is to construct a call to -:func:`exec` and :func:`open` with the name of your file as argument. - -Also note that you can not mix-and-match Debug and Release versions. If you -wish to use the Debug Multithreaded DLL, then your module *must* have ``_d`` -appended to the base name. - - -Importing _tkinter fails on Windows 95/98: why? ------------------------------------------------- - -Sometimes, the import of _tkinter fails on Windows 95 or 98, complaining with a -message like the following:: - - ImportError: DLL load failed: One of the library files needed - to run this application cannot be found. - -It could be that you haven't installed Tcl/Tk, but if you did install Tcl/Tk, -and the Wish application works correctly, the problem may be that its installer -didn't manage to edit the autoexec.bat file correctly. It tries to add a -statement that changes the PATH environment variable to include the Tcl/Tk 'bin' -subdirectory, but sometimes this edit doesn't quite work. Opening it with -notepad usually reveals what the problem is. - -(One additional hint, noted by David Szafranski: you can't use long filenames -here; e.g. use ``C:\PROGRA~1\Tcl\bin`` instead of ``C:\Program Files\Tcl\bin``.) - - How do I extract the downloaded documentation on Windows? --------------------------------------------------------- @@ -581,38 +338,3 @@ able to handle it. (If your copy of WinZip doesn't, get a newer one from http://www.winzip.com.) - -Missing cw3215mt.dll (or missing cw3215.dll) --------------------------------------------- - -Sometimes, when using Tkinter on Windows, you get an error that cw3215mt.dll or -cw3215.dll is missing. - -Cause: you have an old Tcl/Tk DLL built with cygwin in your path (probably -``C:\Windows``). You must use the Tcl/Tk DLLs from the standard Tcl/Tk -installation (Python 1.5.2 comes with one). - - -Warning about CTL3D32 version from installer --------------------------------------------- - -The Python installer issues a warning like this:: - - This version uses CTL3D32.DLL which is not the correct version. - This version is used for windows NT applications only. - -Tim Peters: - - This is a Microsoft DLL, and a notorious source of problems. The message - means what it says: you have the wrong version of this DLL for your operating - system. The Python installation did not cause this -- something else you - installed previous to this overwrote the DLL that came with your OS (probably - older shareware of some sort, but there's no way to tell now). If you search - for "CTL3D32" using any search engine (AltaVista, for example), you'll find - hundreds and hundreds of web pages complaining about the same problem with - all sorts of installation programs. They'll point you to ways to get the - correct version reinstalled on your system (since Python doesn't cause this, - we can't fix it). - -David A Burton has written a little program to fix this. Go to -http://www.burtonsys.com/downloads.html and click on "ctl3dfix.zip". diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -366,6 +366,9 @@ Documentation ------------- +- Issue #14901: Update portions of the Windows FAQ. + Patch by Ashish Nitin Patil. + - Issue #16267: Better document the 3.3+ approach to combining @abstractmethod with @staticmethod, @classmethod and @property -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 07:19:01 2012 From: python-checkins at python.org (brian.curtin) Date: Mon, 17 Dec 2012 07:19:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4z?= Message-ID: <3YPsdK2PZ7zNl4@mail.python.org> http://hg.python.org/cpython/rev/8bf576155d7c changeset: 80895:8bf576155d7c parent: 80892:9d5122548096 parent: 80894:bd7c8631a89d user: Brian Curtin date: Mon Dec 17 00:06:02 2012 -0600 summary: Merge 3.3 files: Doc/faq/windows.rst | 332 ++----------------------------- Misc/NEWS | 3 + 2 files changed, 30 insertions(+), 305 deletions(-) diff --git a/Doc/faq/windows.rst b/Doc/faq/windows.rst --- a/Doc/faq/windows.rst +++ b/Doc/faq/windows.rst @@ -17,9 +17,7 @@ This is not necessarily a straightforward question. If you are already familiar with running programs from the Windows command line then everything will seem -obvious; otherwise, you might need a little more guidance. There are also -differences between Windows 95, 98, NT, ME, 2000 and XP which can add to the -confusion. +obvious; otherwise, you might need a little more guidance. .. sidebar:: |Python Development on XP|_ :subtitle: `Python Development on XP`_ @@ -36,7 +34,7 @@ Unless you use some sort of integrated development environment, you will end up *typing* Windows commands into what is variously referred to as a "DOS window" or "Command prompt window". Usually you can create such a window from your -Start menu; under Windows 2000 the menu selection is :menuselection:`Start --> +Start menu; under Windows 7 the menu selection is :menuselection:`Start --> Programs --> Accessories --> Command Prompt`. You should be able to recognize when you have started such a window because you will see a Windows "command prompt", which usually looks like this:: @@ -46,23 +44,27 @@ The letter may be different, and there might be other things after it, so you might just as easily see something like:: - D:\Steve\Projects\Python> + D:\YourName\Projects\Python> depending on how your computer has been set up and what else you have recently done with it. Once you have started such a window, you are well on the way to running Python programs. You need to realize that your Python scripts have to be processed by another -program called the Python interpreter. The interpreter reads your script, +program called the Python *interpreter*. The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program. So, how do you arrange for the interpreter to handle your Python? First, you need to make sure that your command window recognises the word "python" as an instruction to start the interpreter. If you have opened a command window, you should try entering the command ``python`` and hitting -return. You should then see something like:: +return.:: - Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 + C:\Users\YourName> python + +You should then see something like:: + + Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> @@ -82,7 +84,7 @@ Windows command prompt. You may also find that you have a Start-menu entry such as :menuselection:`Start ---> Programs --> Python 2.2 --> Python (command line)` that results in you +--> Programs --> Python 3.3 --> Python (command line)` that results in you seeing the ``>>>`` prompt in a new window. If so, the window will disappear after you enter the Ctrl-Z character; Windows is running a single "python" command in the window, and closes it when you terminate the interpreter. @@ -90,8 +92,7 @@ If the ``python`` command, instead of displaying the interpreter prompt ``>>>``, gives you a message like:: - 'python' is not recognized as an internal or external command, - operable program or batch file. + 'python' is not recognized as an internal or external command, operable program or batch file. .. sidebar:: |Adding Python to DOS Path|_ :subtitle: `Adding Python to DOS Path`_ @@ -120,115 +121,33 @@ dir C:\py* will probably tell you where it is installed; the usual location is something -like ``C:\Python23``. Otherwise you will be reduced to a search of your whole +like ``C:\Python33``. Otherwise you will be reduced to a search of your whole disk ... use :menuselection:`Tools --> Find` or hit the :guilabel:`Search` button and look for "python.exe". Supposing you discover that Python is -installed in the ``C:\Python23`` directory (the default at the time of writing), +installed in the ``C:\Python33`` directory (the default at the time of writing), you should make sure that entering the command :: - c:\Python23\python + c:\Python33\python starts up the interpreter as above (and don't forget you'll need a "CTRL-Z" and -an "Enter" to get out of it). Once you have verified the directory, you need to -add it to the start-up routines your computer goes through. For older versions -of Windows the easiest way to do this is to edit the ``C:\AUTOEXEC.BAT`` -file. You would want to add a line like the following to ``AUTOEXEC.BAT``:: +an "Enter" to get out of it). Once you have verified the directory, you can +add it to the system path to make it easier to start Python by just running +the ``python`` command. This is currently an option in the installer as of +CPython 3.3. - PATH C:\Python23;%PATH% - -For Windows NT, 2000 and (I assume) XP, you will need to add a string such as :: - - ;C:\Python23 - -to the current setting for the PATH environment variable, which you will find in -the properties window of "My Computer" under the "Advanced" tab. Note that if -you have sufficient privilege you might get a choice of installing the settings -either for the Current User or for System. The latter is preferred if you want -everybody to be able to run Python on the machine. - -If you aren't confident doing any of these manipulations yourself, ask for help! -At this stage you may want to reboot your system to make absolutely sure the new -setting has taken effect. You probably won't need to reboot for Windows NT, XP -or 2000. You can also avoid it in earlier versions by editing the file -``C:\WINDOWS\COMMAND\CMDINIT.BAT`` instead of ``AUTOEXEC.BAT``. - -You should now be able to start a new command window, enter ``python`` at the -``C:\>`` (or whatever) prompt, and see the ``>>>`` prompt that indicates the -Python interpreter is reading interactive commands. - -Let's suppose you have a program called ``pytest.py`` in directory -``C:\Steve\Projects\Python``. A session to run that program might look like -this:: - - C:\> cd \Steve\Projects\Python - C:\Steve\Projects\Python> python pytest.py - -Because you added a file name to the command to start the interpreter, when it -starts up it reads the Python script in the named file, compiles it, executes -it, and terminates, so you see another ``C:\>`` prompt. You might also have -entered :: - - C:\> python \Steve\Projects\Python\pytest.py - -if you hadn't wanted to change your current directory. - -Under NT, 2000 and XP you may well find that the installation process has also -arranged that the command ``pytest.py`` (or, if the file isn't in the current -directory, ``C:\Steve\Projects\Python\pytest.py``) will automatically recognize -the ".py" extension and run the Python interpreter on the named file. Using this -feature is fine, but *some* versions of Windows have bugs which mean that this -form isn't exactly equivalent to using the interpreter explicitly, so be -careful. - -The important things to remember are: - -1. Start Python from the Start Menu, or make sure the PATH is set correctly so - Windows can find the Python interpreter. :: - - python - - should give you a '>>>' prompt from the Python interpreter. Don't forget the - CTRL-Z and ENTER to terminate the interpreter (and, if you started the window - from the Start Menu, make the window disappear). - -2. Once this works, you run programs with commands:: - - python {program-file} - -3. When you know the commands to use you can build Windows shortcuts to run the - Python interpreter on any of your scripts, naming particular working - directories, and adding them to your menus. Take a look at :: - - python --help - - if your needs are complex. - -4. Interactive mode (where you see the ``>>>`` prompt) is best used for checking - that individual statements and expressions do what you think they will, and - for developing code by experiment. - +More information about environment variables can be found on the +:ref:`Using Python on Windows ` page. How do I make Python scripts executable? ---------------------------------------- -On Windows 2000, the standard Python installer already associates the .py +On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (``D:\Program Files\Python\python.exe "%1" %*``). This is enough to make scripts executable from the command prompt as 'foo.py'. If you'd rather be able to execute the script by simple typing 'foo' with no extension you need to add .py to the PATHEXT environment variable. -On Windows NT, the steps taken by the installer as described above allow you to -run a script with 'foo.py', but a longtime bug in the NT command processor -prevents you from redirecting the input or output of any script executed in this -way. This is often important. - -The incantation for making a Python script executable under WinNT is to give the -file an extension of .cmd and add the following as the first line:: - - @setlocal enableextensions & python -x %~f0 %* & goto :EOF - - Why does Python sometimes take so long to start? ------------------------------------------------ @@ -246,22 +165,11 @@ offender. -Where is Freeze for Windows? ----------------------------- +How do I make an executable from a Python script? +------------------------------------------------- -"Freeze" is a program that allows you to ship a Python program as a single -stand-alone executable file. It is *not* a compiler; your programs don't run -any faster, but they are more easily distributable, at least to platforms with -the same OS and CPU. Read the README file of the freeze program for more -disclaimers. - -You can use freeze on Windows, but you must download the source tree (see -http://www.python.org/download/source). The freeze program is in the -``Tools\freeze`` subdirectory of the source tree. - -You need the Microsoft VC++ compiler, and you probably need to build Python. -The required project files are in the PCbuild directory. - +See http://www.py2exe.org/ for a distutils extension that allows you +to create console and GUI executables from Python code. Is a ``*.pyd`` file the same as a DLL? -------------------------------------- @@ -292,7 +200,7 @@ be a DLL to handle importing modules that are themselves DLL's. (This is the first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is typically installed in ``C:\Windows\System``. *NN* is the Python version, a - number such as "23" for Python 2.3. + number such as "33" for Python 3.3. You can link to Python in two different ways. Load-time linking means linking against :file:`python{NN}.lib`, while run-time linking means linking @@ -376,47 +284,6 @@ object that supports read and write, so all you need is a Python object (defined in your extension module) that contains read() and write() methods. - -How do I use Python for CGI? ----------------------------- - -On the Microsoft IIS server or on the Win95 MS Personal Web Server you set up -Python in the same way that you would set up any other scripting engine. - -Run regedt32 and go to:: - - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap - -and enter the following line (making any specific changes that your system may -need):: - - .py :REG_SZ: c:\\python.exe -u %s %s - -This line will allow you to call your script with a simple reference like: -``http://yourserver/scripts/yourscript.py`` provided "scripts" is an -"executable" directory for your server (which it usually is by default). The -:option:`-u` flag specifies unbuffered and binary mode for stdin - needed when -working with binary data. - -In addition, it is recommended that using ".py" may not be a good idea for the -file extensions when used in this context (you might want to reserve ``*.py`` -for support modules and use ``*.cgi`` or ``*.cgp`` for "main program" scripts). - -In order to set up Internet Information Services 5 to use Python for CGI -processing, please see the following links: - - http://www.e-coli.net/pyiis_server.html (for Win2k Server) - http://www.e-coli.net/pyiis.html (for Win2k pro) - -Configuring Apache is much simpler. In the Apache configuration file -``httpd.conf``, add the following line at the end of the file:: - - ScriptInterpreterSource Registry - -Then, give your Python CGI-scripts the extension .py and put them in the cgi-bin -directory. - - How do I keep editors from inserting tabs into my Python source? ---------------------------------------------------------------- @@ -460,116 +327,6 @@ to console subprocesses which are designed to handle those signals. See :func:`os.kill` for further details. - -Why does os.path.isdir() fail on NT shared directories? -------------------------------------------------------- - -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') - 0 - >>> os.path.isdir('\\\\rorschach\\public\\') - 1 - -It helps to think of share points as being like drive letters. Example:: - - k: is not a directory - k:\ is a directory - k:\media is a directory - k:\media\ is not a directory - -The same rules apply if you substitute ``"k:"`` with ``"\\conky\foo"``:: - - \\conky\foo is not a directory - \\conky\foo\ is a directory - \\conky\foo\media is a directory - \\conky\foo\media\ is not a directory - - -cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! ------------------------------------------------------------------------- - -Be sure you have the latest python.exe, that you are using python.exe rather -than a GUI version of Python and that you have configured the server to execute -:: - - "...\python.exe -u ..." - -for the CGI execution. The :option:`-u` (unbuffered) option on NT and Win95 -prevents the interpreter from altering newlines in the standard input and -output. Without it post/multipart requests will seem to have the wrong length -and binary (e.g. GIF) responses may get garbled (resulting in broken images, PDF -files, and other binary downloads failing). - - -Why doesn't os.popen() work in PythonWin on NT? ------------------------------------------------ - -The reason that os.popen() doesn't work from within PythonWin is due to a bug in -Microsoft's C Runtime Library (CRT). The CRT assumes you have a Win32 console -attached to the process. - -You should use the win32pipe module's popen() instead which doesn't depend on -having an attached Win32 console. - -Example:: - - import win32pipe - f = win32pipe.popen('dir /c c:\\') - print(f.readlines()) - f.close() - - -Why doesn't os.popen()/win32pipe.popen() work on Win9x? -------------------------------------------------------- - -There is a bug in Win9x that prevents os.popen/win32pipe.popen* from -working. The good news is there is a way to work around this problem. The -Microsoft Knowledge Base article that you need to lookup is: Q150956. You will -find links to the knowledge base at: http://support.microsoft.com/. - - -PyRun_SimpleFile() crashes on Windows but not on Unix; why? ------------------------------------------------------------ - -This is very sensitive to the compiler vendor, version and (perhaps) even -options. If the FILE* structure in your embedding program isn't the same as is -assumed by the Python interpreter it won't work. - -The Python 1.5.* DLLs (``python15.dll``) are all compiled with MS VC++ 5.0 and -with multithreading-DLL options (``/MD``). - -If you can't change compilers or flags, try using :c:func:`Py_RunSimpleString`. -A trick to get it to run an arbitrary file is to construct a call to -:func:`exec` and :func:`open` with the name of your file as argument. - -Also note that you can not mix-and-match Debug and Release versions. If you -wish to use the Debug Multithreaded DLL, then your module *must* have ``_d`` -appended to the base name. - - -Importing _tkinter fails on Windows 95/98: why? ------------------------------------------------- - -Sometimes, the import of _tkinter fails on Windows 95 or 98, complaining with a -message like the following:: - - ImportError: DLL load failed: One of the library files needed - to run this application cannot be found. - -It could be that you haven't installed Tcl/Tk, but if you did install Tcl/Tk, -and the Wish application works correctly, the problem may be that its installer -didn't manage to edit the autoexec.bat file correctly. It tries to add a -statement that changes the PATH environment variable to include the Tcl/Tk 'bin' -subdirectory, but sometimes this edit doesn't quite work. Opening it with -notepad usually reveals what the problem is. - -(One additional hint, noted by David Szafranski: you can't use long filenames -here; e.g. use ``C:\PROGRA~1\Tcl\bin`` instead of ``C:\Program Files\Tcl\bin``.) - - How do I extract the downloaded documentation on Windows? --------------------------------------------------------- @@ -581,38 +338,3 @@ able to handle it. (If your copy of WinZip doesn't, get a newer one from http://www.winzip.com.) - -Missing cw3215mt.dll (or missing cw3215.dll) --------------------------------------------- - -Sometimes, when using Tkinter on Windows, you get an error that cw3215mt.dll or -cw3215.dll is missing. - -Cause: you have an old Tcl/Tk DLL built with cygwin in your path (probably -``C:\Windows``). You must use the Tcl/Tk DLLs from the standard Tcl/Tk -installation (Python 1.5.2 comes with one). - - -Warning about CTL3D32 version from installer --------------------------------------------- - -The Python installer issues a warning like this:: - - This version uses CTL3D32.DLL which is not the correct version. - This version is used for windows NT applications only. - -Tim Peters: - - This is a Microsoft DLL, and a notorious source of problems. The message - means what it says: you have the wrong version of this DLL for your operating - system. The Python installation did not cause this -- something else you - installed previous to this overwrote the DLL that came with your OS (probably - older shareware of some sort, but there's no way to tell now). If you search - for "CTL3D32" using any search engine (AltaVista, for example), you'll find - hundreds and hundreds of web pages complaining about the same problem with - all sorts of installation programs. They'll point you to ways to get the - correct version reinstalled on your system (since Python doesn't cause this, - we can't fix it). - -David A Burton has written a little program to fix this. Go to -http://www.burtonsys.com/downloads.html and click on "ctl3dfix.zip". diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -529,6 +529,9 @@ Documentation ------------- +- Issue #14901: Update portions of the Windows FAQ. + Patch by Ashish Nitin Patil. + - Issue #16267: Better document the 3.3+ approach to combining @abstractmethod with @staticmethod, @classmethod and @property -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 07:19:02 2012 From: python-checkins at python.org (brian.curtin) Date: Mon, 17 Dec 2012 07:19:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_Ashish_Nitin_Patil_for?= =?utf-8?q?_work_on_Issue_=2314901?= Message-ID: <3YPsdL4WQ5zN68@mail.python.org> http://hg.python.org/cpython/rev/fe20d5bf0c93 changeset: 80896:fe20d5bf0c93 user: Brian Curtin date: Mon Dec 17 00:08:28 2012 -0600 summary: Add Ashish Nitin Patil for work on Issue #14901 files: Misc/ACKS | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -900,6 +900,7 @@ William Park Harri Pasanen Ga?l Pasgrimaud +Ashish Nitin Patil Berker Peksag Bo Peng Joe Peterson -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 07:19:04 2012 From: python-checkins at python.org (brian.curtin) Date: Mon, 17 Dec 2012 07:19:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogRml4ICMxNDkwMS4g?= =?utf-8?q?Update_some_sections_of_Windows_FAQ=2E?= Message-ID: <3YPsdN2KQXzNl4@mail.python.org> http://hg.python.org/cpython/rev/81d1df1f512a changeset: 80897:81d1df1f512a branch: 2.7 parent: 80882:b0935ef48186 user: Brian Curtin date: Mon Dec 17 00:17:49 2012 -0600 summary: Fix #14901. Update some sections of Windows FAQ. Patch by Ashish Nitin Patil. files: Doc/faq/windows.rst | 332 ++----------------------------- Misc/NEWS | 3 + 2 files changed, 30 insertions(+), 305 deletions(-) diff --git a/Doc/faq/windows.rst b/Doc/faq/windows.rst --- a/Doc/faq/windows.rst +++ b/Doc/faq/windows.rst @@ -13,9 +13,7 @@ This is not necessarily a straightforward question. If you are already familiar with running programs from the Windows command line then everything will seem -obvious; otherwise, you might need a little more guidance. There are also -differences between Windows 95, 98, NT, ME, 2000 and XP which can add to the -confusion. +obvious; otherwise, you might need a little more guidance. .. sidebar:: |Python Development on XP|_ :subtitle: `Python Development on XP`_ @@ -32,7 +30,7 @@ Unless you use some sort of integrated development environment, you will end up *typing* Windows commands into what is variously referred to as a "DOS window" or "Command prompt window". Usually you can create such a window from your -Start menu; under Windows 2000 the menu selection is :menuselection:`Start --> +Start menu; under Windows 7 the menu selection is :menuselection:`Start --> Programs --> Accessories --> Command Prompt`. You should be able to recognize when you have started such a window because you will see a Windows "command prompt", which usually looks like this:: @@ -42,23 +40,27 @@ The letter may be different, and there might be other things after it, so you might just as easily see something like:: - D:\Steve\Projects\Python> + D:\YourName\Projects\Python> depending on how your computer has been set up and what else you have recently done with it. Once you have started such a window, you are well on the way to running Python programs. You need to realize that your Python scripts have to be processed by another -program called the Python interpreter. The interpreter reads your script, +program called the Python *interpreter*. The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program. So, how do you arrange for the interpreter to handle your Python? First, you need to make sure that your command window recognises the word "python" as an instruction to start the interpreter. If you have opened a command window, you should try entering the command ``python`` and hitting -return. You should then see something like:: +return.:: - Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 + C:\Users\YourName> python + +You should then see something like:: + + Python 2.7.3 (default, Apr 10 2012, 22.71:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> @@ -78,7 +80,7 @@ Windows command prompt. You may also find that you have a Start-menu entry such as :menuselection:`Start ---> Programs --> Python 2.2 --> Python (command line)` that results in you +--> Programs --> Python 2.7 --> Python (command line)` that results in you seeing the ``>>>`` prompt in a new window. If so, the window will disappear after you enter the Ctrl-Z character; Windows is running a single "python" command in the window, and closes it when you terminate the interpreter. @@ -86,8 +88,7 @@ If the ``python`` command, instead of displaying the interpreter prompt ``>>>``, gives you a message like:: - 'python' is not recognized as an internal or external command, - operable program or batch file. + 'python' is not recognized as an internal or external command, operable program or batch file. .. sidebar:: |Adding Python to DOS Path|_ :subtitle: `Adding Python to DOS Path`_ @@ -116,115 +117,33 @@ dir C:\py* will probably tell you where it is installed; the usual location is something -like ``C:\Python23``. Otherwise you will be reduced to a search of your whole +like ``C:\Python27``. Otherwise you will be reduced to a search of your whole disk ... use :menuselection:`Tools --> Find` or hit the :guilabel:`Search` button and look for "python.exe". Supposing you discover that Python is -installed in the ``C:\Python23`` directory (the default at the time of writing), +installed in the ``C:\Python27`` directory (the default at the time of writing), you should make sure that entering the command :: - c:\Python23\python + c:\Python27\python starts up the interpreter as above (and don't forget you'll need a "CTRL-Z" and -an "Enter" to get out of it). Once you have verified the directory, you need to -add it to the start-up routines your computer goes through. For older versions -of Windows the easiest way to do this is to edit the ``C:\AUTOEXEC.BAT`` -file. You would want to add a line like the following to ``AUTOEXEC.BAT``:: +an "Enter" to get out of it). Once you have verified the directory, you can +add it to the system path to make it easier to start Python by just running +the ``python`` command. This is currently an option in the installer as of +CPython 2.7. - PATH C:\Python23;%PATH% - -For Windows NT, 2000 and (I assume) XP, you will need to add a string such as :: - - ;C:\Python23 - -to the current setting for the PATH environment variable, which you will find in -the properties window of "My Computer" under the "Advanced" tab. Note that if -you have sufficient privilege you might get a choice of installing the settings -either for the Current User or for System. The latter is preferred if you want -everybody to be able to run Python on the machine. - -If you aren't confident doing any of these manipulations yourself, ask for help! -At this stage you may want to reboot your system to make absolutely sure the new -setting has taken effect. You probably won't need to reboot for Windows NT, XP -or 2000. You can also avoid it in earlier versions by editing the file -``C:\WINDOWS\COMMAND\CMDINIT.BAT`` instead of ``AUTOEXEC.BAT``. - -You should now be able to start a new command window, enter ``python`` at the -``C:\>`` (or whatever) prompt, and see the ``>>>`` prompt that indicates the -Python interpreter is reading interactive commands. - -Let's suppose you have a program called ``pytest.py`` in directory -``C:\Steve\Projects\Python``. A session to run that program might look like -this:: - - C:\> cd \Steve\Projects\Python - C:\Steve\Projects\Python> python pytest.py - -Because you added a file name to the command to start the interpreter, when it -starts up it reads the Python script in the named file, compiles it, executes -it, and terminates, so you see another ``C:\>`` prompt. You might also have -entered :: - - C:\> python \Steve\Projects\Python\pytest.py - -if you hadn't wanted to change your current directory. - -Under NT, 2000 and XP you may well find that the installation process has also -arranged that the command ``pytest.py`` (or, if the file isn't in the current -directory, ``C:\Steve\Projects\Python\pytest.py``) will automatically recognize -the ".py" extension and run the Python interpreter on the named file. Using this -feature is fine, but *some* versions of Windows have bugs which mean that this -form isn't exactly equivalent to using the interpreter explicitly, so be -careful. - -The important things to remember are: - -1. Start Python from the Start Menu, or make sure the PATH is set correctly so - Windows can find the Python interpreter. :: - - python - - should give you a '>>>' prompt from the Python interpreter. Don't forget the - CTRL-Z and ENTER to terminate the interpreter (and, if you started the window - from the Start Menu, make the window disappear). - -2. Once this works, you run programs with commands:: - - python {program-file} - -3. When you know the commands to use you can build Windows shortcuts to run the - Python interpreter on any of your scripts, naming particular working - directories, and adding them to your menus. Take a look at :: - - python --help - - if your needs are complex. - -4. Interactive mode (where you see the ``>>>`` prompt) is best used for checking - that individual statements and expressions do what you think they will, and - for developing code by experiment. - +More information about environment variables can be found on the +:ref:`Using Python on Windows ` page. How do I make Python scripts executable? ---------------------------------------- -On Windows 2000, the standard Python installer already associates the .py +On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (``D:\Program Files\Python\python.exe "%1" %*``). This is enough to make scripts executable from the command prompt as 'foo.py'. If you'd rather be able to execute the script by simple typing 'foo' with no extension you need to add .py to the PATHEXT environment variable. -On Windows NT, the steps taken by the installer as described above allow you to -run a script with 'foo.py', but a longtime bug in the NT command processor -prevents you from redirecting the input or output of any script executed in this -way. This is often important. - -The incantation for making a Python script executable under WinNT is to give the -file an extension of .cmd and add the following as the first line:: - - @setlocal enableextensions & python -x %~f0 %* & goto :EOF - - Why does Python sometimes take so long to start? ------------------------------------------------ @@ -242,22 +161,11 @@ offender. -Where is Freeze for Windows? ----------------------------- +How do I make an executable from a Python script? +------------------------------------------------- -"Freeze" is a program that allows you to ship a Python program as a single -stand-alone executable file. It is *not* a compiler; your programs don't run -any faster, but they are more easily distributable, at least to platforms with -the same OS and CPU. Read the README file of the freeze program for more -disclaimers. - -You can use freeze on Windows, but you must download the source tree (see -http://www.python.org/download/source). The freeze program is in the -``Tools\freeze`` subdirectory of the source tree. - -You need the Microsoft VC++ compiler, and you probably need to build Python. -The required project files are in the PCbuild directory. - +See http://www.py2exe.org/ for a distutils extension that allows you +to create console and GUI executables from Python code. Is a ``*.pyd`` file the same as a DLL? -------------------------------------- @@ -288,7 +196,7 @@ be a DLL to handle importing modules that are themselves DLL's. (This is the first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is typically installed in ``C:\Windows\System``. *NN* is the Python version, a - number such as "23" for Python 2.3. + number such as "27" for Python 2.7. You can link to Python in two different ways. Load-time linking means linking against :file:`python{NN}.lib`, while run-time linking means linking @@ -372,47 +280,6 @@ object that supports read and write, so all you need is a Python object (defined in your extension module) that contains read() and write() methods. - -How do I use Python for CGI? ----------------------------- - -On the Microsoft IIS server or on the Win95 MS Personal Web Server you set up -Python in the same way that you would set up any other scripting engine. - -Run regedt32 and go to:: - - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap - -and enter the following line (making any specific changes that your system may -need):: - - .py :REG_SZ: c:\\python.exe -u %s %s - -This line will allow you to call your script with a simple reference like: -``http://yourserver/scripts/yourscript.py`` provided "scripts" is an -"executable" directory for your server (which it usually is by default). The -:option:`-u` flag specifies unbuffered and binary mode for stdin - needed when -working with binary data. - -In addition, it is recommended that using ".py" may not be a good idea for the -file extensions when used in this context (you might want to reserve ``*.py`` -for support modules and use ``*.cgi`` or ``*.cgp`` for "main program" scripts). - -In order to set up Internet Information Services 5 to use Python for CGI -processing, please see the following links: - - http://www.e-coli.net/pyiis_server.html (for Win2k Server) - http://www.e-coli.net/pyiis.html (for Win2k pro) - -Configuring Apache is much simpler. In the Apache configuration file -``httpd.conf``, add the following line at the end of the file:: - - ScriptInterpreterSource Registry - -Then, give your Python CGI-scripts the extension .py and put them in the cgi-bin -directory. - - How do I keep editors from inserting tabs into my Python source? ---------------------------------------------------------------- @@ -456,116 +323,6 @@ to console subprocesses which are designed to handle those signals. See :func:`os.kill` for further details. - -Why does os.path.isdir() fail on NT shared directories? -------------------------------------------------------- - -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') - 0 - >>> os.path.isdir('\\\\rorschach\\public\\') - 1 - -It helps to think of share points as being like drive letters. Example:: - - k: is not a directory - k:\ is a directory - k:\media is a directory - k:\media\ is not a directory - -The same rules apply if you substitute ``"k:"`` with ``"\\conky\foo"``:: - - \\conky\foo is not a directory - \\conky\foo\ is a directory - \\conky\foo\media is a directory - \\conky\foo\media\ is not a directory - - -cgi.py (or other CGI programming) doesn't work sometimes on NT or win95! ------------------------------------------------------------------------- - -Be sure you have the latest python.exe, that you are using python.exe rather -than a GUI version of Python and that you have configured the server to execute -:: - - "...\python.exe -u ..." - -for the CGI execution. The :option:`-u` (unbuffered) option on NT and Win95 -prevents the interpreter from altering newlines in the standard input and -output. Without it post/multipart requests will seem to have the wrong length -and binary (e.g. GIF) responses may get garbled (resulting in broken images, PDF -files, and other binary downloads failing). - - -Why doesn't os.popen() work in PythonWin on NT? ------------------------------------------------ - -The reason that os.popen() doesn't work from within PythonWin is due to a bug in -Microsoft's C Runtime Library (CRT). The CRT assumes you have a Win32 console -attached to the process. - -You should use the win32pipe module's popen() instead which doesn't depend on -having an attached Win32 console. - -Example:: - - import win32pipe - f = win32pipe.popen('dir /c c:\\') - print f.readlines() - f.close() - - -Why doesn't os.popen()/win32pipe.popen() work on Win9x? -------------------------------------------------------- - -There is a bug in Win9x that prevents os.popen/win32pipe.popen* from -working. The good news is there is a way to work around this problem. The -Microsoft Knowledge Base article that you need to lookup is: Q150956. You will -find links to the knowledge base at: http://support.microsoft.com/. - - -PyRun_SimpleFile() crashes on Windows but not on Unix; why? ------------------------------------------------------------ - -This is very sensitive to the compiler vendor, version and (perhaps) even -options. If the FILE* structure in your embedding program isn't the same as is -assumed by the Python interpreter it won't work. - -The Python 1.5.* DLLs (``python15.dll``) are all compiled with MS VC++ 5.0 and -with multithreading-DLL options (``/MD``). - -If you can't change compilers or flags, try using :c:func:`Py_RunSimpleString`. -A trick to get it to run an arbitrary file is to construct a call to -:func:`execfile` with the name of your file as argument. - -Also note that you can not mix-and-match Debug and Release versions. If you -wish to use the Debug Multithreaded DLL, then your module *must* have ``_d`` -appended to the base name. - - -Importing _tkinter fails on Windows 95/98: why? ------------------------------------------------- - -Sometimes, the import of _tkinter fails on Windows 95 or 98, complaining with a -message like the following:: - - ImportError: DLL load failed: One of the library files needed - to run this application cannot be found. - -It could be that you haven't installed Tcl/Tk, but if you did install Tcl/Tk, -and the Wish application works correctly, the problem may be that its installer -didn't manage to edit the autoexec.bat file correctly. It tries to add a -statement that changes the PATH environment variable to include the Tcl/Tk 'bin' -subdirectory, but sometimes this edit doesn't quite work. Opening it with -notepad usually reveals what the problem is. - -(One additional hint, noted by David Szafranski: you can't use long filenames -here; e.g. use ``C:\PROGRA~1\Tcl\bin`` instead of ``C:\Program Files\Tcl\bin``.) - - How do I extract the downloaded documentation on Windows? --------------------------------------------------------- @@ -577,38 +334,3 @@ able to handle it. (If your copy of WinZip doesn't, get a newer one from http://www.winzip.com.) - -Missing cw3215mt.dll (or missing cw3215.dll) --------------------------------------------- - -Sometimes, when using Tkinter on Windows, you get an error that cw3215mt.dll or -cw3215.dll is missing. - -Cause: you have an old Tcl/Tk DLL built with cygwin in your path (probably -``C:\Windows``). You must use the Tcl/Tk DLLs from the standard Tcl/Tk -installation (Python 1.5.2 comes with one). - - -Warning about CTL3D32 version from installer --------------------------------------------- - -The Python installer issues a warning like this:: - - This version uses CTL3D32.DLL which is not the correct version. - This version is used for windows NT applications only. - -Tim Peters: - - This is a Microsoft DLL, and a notorious source of problems. The message - means what it says: you have the wrong version of this DLL for your operating - system. The Python installation did not cause this -- something else you - installed previous to this overwrote the DLL that came with your OS (probably - older shareware of some sort, but there's no way to tell now). If you search - for "CTL3D32" using any search engine (AltaVista, for example), you'll find - hundreds and hundreds of web pages complaining about the same problem with - all sorts of installation programs. They'll point you to ways to get the - correct version reinstalled on your system (since Python doesn't cause this, - we can't fix it). - -David A Burton has written a little program to fix this. Go to -http://www.burtonsys.com/downloads.html and click on "ctl3dfix.zip". diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -626,6 +626,9 @@ Documentation ------------- +- Issue #14901: Update portions of the Windows FAQ. + Patch by Ashish Nitin Patil. + - Issue #15990: Improve argument/parameter documentation. - Issue #16400: Update the description of which versions of a given package -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 12:43:08 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 12:43:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_typo?= Message-ID: <3YQ0qJ4DC4zNDK@mail.python.org> http://hg.python.org/cpython/rev/8b9a7e65caf2 changeset: 80898:8b9a7e65caf2 branch: 3.2 parent: 80893:5edbd93509b8 user: Andrew Svetlov date: Mon Dec 17 13:42:04 2012 +0200 summary: Fix typo files: Doc/library/datetime.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1359,7 +1359,7 @@ instantiated directly. You need to derive a concrete subclass, and (at least) supply implementations of the standard :class:`tzinfo` methods needed by the :class:`.datetime` methods you use. The :mod:`datetime` module supplies -a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can reprsent +a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can represent timezones with fixed offset from UTC such as UTC itself or North American EST and EDT. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 12:43:09 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 12:43:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Fix_typo?= Message-ID: <3YQ0qK6Ws5zNDK@mail.python.org> http://hg.python.org/cpython/rev/472365a4bd1b changeset: 80899:472365a4bd1b branch: 3.3 parent: 80894:bd7c8631a89d parent: 80898:8b9a7e65caf2 user: Andrew Svetlov date: Mon Dec 17 13:42:40 2012 +0200 summary: Fix typo files: Doc/library/datetime.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1442,7 +1442,7 @@ instantiated directly. You need to derive a concrete subclass, and (at least) supply implementations of the standard :class:`tzinfo` methods needed by the :class:`.datetime` methods you use. The :mod:`datetime` module supplies -a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can reprsent +a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can represent timezones with fixed offset from UTC such as UTC itself or North American EST and EDT. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 12:43:11 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 12:43:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_typo?= Message-ID: <3YQ0qM1pKfzNNP@mail.python.org> http://hg.python.org/cpython/rev/49160bb35871 changeset: 80900:49160bb35871 parent: 80896:fe20d5bf0c93 parent: 80899:472365a4bd1b user: Andrew Svetlov date: Mon Dec 17 13:42:57 2012 +0200 summary: Fix typo files: Doc/library/datetime.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1442,7 +1442,7 @@ instantiated directly. You need to derive a concrete subclass, and (at least) supply implementations of the standard :class:`tzinfo` methods needed by the :class:`.datetime` methods you use. The :mod:`datetime` module supplies -a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can reprsent +a simple concrete subclass of :class:`tzinfo` :class:`timezone` which can represent timezones with fixed offset from UTC such as UTC itself or North American EST and EDT. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 13:01:56 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 13:01:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Update_example?= =?utf-8?q?=3A_Counter=2Esubtract_returns_None=2C_not_self?= Message-ID: <3YQ1F02HTKzMVh@mail.python.org> http://hg.python.org/cpython/rev/542cfc75c043 changeset: 80901:542cfc75c043 branch: 2.7 parent: 80897:81d1df1f512a user: Andrew Svetlov date: Mon Dec 17 14:01:03 2012 +0200 summary: Update example: Counter.subtract returns None, not self files: Doc/library/collections.rst | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -120,6 +120,7 @@ >>> c = Counter(a=4, b=2, c=0, d=-2) >>> d = Counter(a=1, b=2, c=3, d=4) >>> c.subtract(d) + >>> c Counter({'a': 3, 'b': 0, 'c': -3, 'd': -6}) The usual dictionary methods are available for :class:`Counter` objects -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 13:01:57 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 13:01:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Update_example?= =?utf-8?q?=3A_Counter=2Esubtract_returns_None=2C_not_self?= Message-ID: <3YQ1F14X0VzMVh@mail.python.org> http://hg.python.org/cpython/rev/248359588f89 changeset: 80902:248359588f89 branch: 3.2 parent: 80898:8b9a7e65caf2 user: Andrew Svetlov date: Mon Dec 17 14:01:16 2012 +0200 summary: Update example: Counter.subtract returns None, not self files: Doc/library/collections.rst | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -121,6 +121,7 @@ >>> c = Counter(a=4, b=2, c=0, d=-2) >>> d = Counter(a=1, b=2, c=3, d=4) >>> c.subtract(d) + >>> c Counter({'a': 3, 'b': 0, 'c': -3, 'd': -6}) .. versionadded:: 3.2 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 13:01:58 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 13:01:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Update_example=3A_Counter=2Esubtract_returns_None=2C_not_self?= Message-ID: <3YQ1F2751WzNQZ@mail.python.org> http://hg.python.org/cpython/rev/fefe2fe93232 changeset: 80903:fefe2fe93232 branch: 3.3 parent: 80899:472365a4bd1b parent: 80902:248359588f89 user: Andrew Svetlov date: Mon Dec 17 14:01:29 2012 +0200 summary: Update example: Counter.subtract returns None, not self files: Doc/library/collections.rst | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -279,6 +279,7 @@ >>> c = Counter(a=4, b=2, c=0, d=-2) >>> d = Counter(a=1, b=2, c=3, d=4) >>> c.subtract(d) + >>> c Counter({'a': 3, 'b': 0, 'c': -3, 'd': -6}) .. versionadded:: 3.2 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 13:02:00 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 13:02:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Update_example=3A_Counter=2Esubtract_returns_None=2C_not?= =?utf-8?q?_self?= Message-ID: <3YQ1F42DyfzNJc@mail.python.org> http://hg.python.org/cpython/rev/45dfb657b430 changeset: 80904:45dfb657b430 parent: 80900:49160bb35871 parent: 80903:fefe2fe93232 user: Andrew Svetlov date: Mon Dec 17 14:01:45 2012 +0200 summary: Update example: Counter.subtract returns None, not self files: Doc/library/collections.rst | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -279,6 +279,7 @@ >>> c = Counter(a=4, b=2, c=0, d=-2) >>> d = Counter(a=1, b=2, c=3, d=4) >>> c.subtract(d) + >>> c Counter({'a': 3, 'b': 0, 'c': -3, 'd': -6}) .. versionadded:: 3.2 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 14:24:56 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 17 Dec 2012 14:24:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4IGlzc3VlICMx?= =?utf-8?q?6646=3A_ftplib=2EFTP=2Emakeport=28=29_might_lose_socket_error_d?= =?utf-8?q?etails=2E?= Message-ID: <3YQ34m6S6vzN1m@mail.python.org> http://hg.python.org/cpython/rev/b7419f88c628 changeset: 80905:b7419f88c628 branch: 3.2 parent: 80902:248359588f89 user: Giampaolo Rodola' date: Mon Dec 17 14:20:27 2012 +0100 summary: Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) files: Lib/ftplib.py | 10 +++++++--- Misc/NEWS | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -284,20 +284,24 @@ def makeport(self): '''Create a new socket and send a PORT command for it.''' - msg = "getaddrinfo returns an empty list" + err = None sock = None for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): af, socktype, proto, canonname, sa = res try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error as msg: + except socket.error as err: if sock: sock.close() sock = None continue break - if not sock: + if sock is None: + if err is not None: + raise err + else: + raise socket.error("getaddrinfo returns an empty list") raise socket.error(msg) sock.listen(1) port = sock.getsockname()[1] # Get proper port diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,9 @@ Library ------- +- Issue #16646: ftplib.FTP.makeport() might lose socket error details. + (patch by Serhiy Storchaka) + - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 14:24:58 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 17 Dec 2012 14:24:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Fix_issue_=2316646=3A_ftplib=2EFTP=2Emakeport=28=29_might_lose?= =?utf-8?q?_socket_error_details=2E?= Message-ID: <3YQ34p1d6LzN1m@mail.python.org> http://hg.python.org/cpython/rev/b8289a08d720 changeset: 80906:b8289a08d720 branch: 3.3 parent: 80903:fefe2fe93232 parent: 80905:b7419f88c628 user: Giampaolo Rodola' date: Mon Dec 17 14:22:19 2012 +0100 summary: Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) files: Lib/ftplib.py | 10 +++++++--- Misc/NEWS | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -288,20 +288,24 @@ def makeport(self): '''Create a new socket and send a PORT command for it.''' - msg = "getaddrinfo returns an empty list" + err = None sock = None for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): af, socktype, proto, canonname, sa = res try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error as msg: + except socket.error as err: if sock: sock.close() sock = None continue break - if not sock: + if sock is None: + if err is not None: + raise err + else: + raise socket.error("getaddrinfo returns an empty list") raise socket.error(msg) sock.listen(1) port = sock.getsockname()[1] # Get proper port diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,9 @@ Library ------- +- Issue #16646: ftplib.FTP.makeport() might lose socket error details. + (patch by Serhiy Storchaka) + - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 14:24:59 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 17 Dec 2012 14:24:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_issue_=2316646=3A_ftplib=2EFTP=2Emakeport=28=29_migh?= =?utf-8?q?t_lose_socket_error_details=2E?= Message-ID: <3YQ34q4NnwzNQZ@mail.python.org> http://hg.python.org/cpython/rev/a0b1942600a2 changeset: 80907:a0b1942600a2 parent: 80904:45dfb657b430 parent: 80906:b8289a08d720 user: Giampaolo Rodola' date: Mon Dec 17 14:23:41 2012 +0100 summary: Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) files: Lib/ftplib.py | 10 +++++++--- Misc/NEWS | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -288,20 +288,24 @@ def makeport(self): '''Create a new socket and send a PORT command for it.''' - msg = "getaddrinfo returns an empty list" + err = None sock = None for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): af, socktype, proto, canonname, sa = res try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error as msg: + except socket.error as err: if sock: sock.close() sock = None continue break - if not sock: + if sock is None: + if err is not None: + raise err + else: + raise socket.error("getaddrinfo returns an empty list") raise socket.error(msg) sock.listen(1) port = sock.getsockname()[1] # Get proper port diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -167,6 +167,9 @@ Library ------- +- Issue #16646: ftplib.FTP.makeport() might lose socket error details. + (patch by Serhiy Storchaka) + - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 14:30:58 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 17 Dec 2012 14:30:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogRml4IGlzc3VlICMx?= =?utf-8?q?6646=3A_ftplib=2EFTP=2Emakeport=28=29_might_lose_socket_error_d?= =?utf-8?q?etails=2E?= Message-ID: <3YQ3Ck17NfzN3q@mail.python.org> http://hg.python.org/cpython/rev/6e07be3dfb6b changeset: 80908:6e07be3dfb6b branch: 2.7 parent: 80901:542cfc75c043 user: Giampaolo Rodola' date: Mon Dec 17 14:30:48 2012 +0100 summary: Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) files: Lib/ftplib.py | 11 +++++++---- Misc/NEWS | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -273,21 +273,24 @@ def makeport(self): '''Create a new socket and send a PORT command for it.''' - msg = "getaddrinfo returns an empty list" + err = None sock = None for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): af, socktype, proto, canonname, sa = res try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error, msg: + except socket.error, err: if sock: sock.close() sock = None continue break - if not sock: - raise socket.error, msg + if sock is None: + if err is not None: + raise err + else: + raise socket.error("getaddrinfo returns an empty list") sock.listen(1) port = sock.getsockname()[1] # Get proper port host = self.sock.getsockname()[0] # Get proper host diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -160,6 +160,9 @@ Library ------- +- Issue #16646: ftplib.FTP.makeport() might lose socket error details. + (patch by Serhiy Storchaka) + - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the pattern contains a wildcard in the drive or UNC path. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 15:15:43 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 15:15:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_obsolete_code=3A_no?= =?utf-8?q?w_IOError_and_WindowsError_are_aliases_for_OSError?= Message-ID: <3YQ4CM30dmzMg0@mail.python.org> http://hg.python.org/cpython/rev/a50b409ee89f changeset: 80909:a50b409ee89f parent: 80907:a0b1942600a2 user: Andrew Svetlov date: Mon Dec 17 16:15:35 2012 +0200 summary: Remove obsolete code: now IOError and WindowsError are aliases for OSError files: Lib/subprocess.py | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -396,8 +396,6 @@ hStdOutput = None hStdError = None wShowWindow = 0 - class pywintypes: - error = IOError else: import select _has_poll = hasattr(select, 'poll') @@ -1102,12 +1100,6 @@ env, cwd, startupinfo) - except pywintypes.error as e: - # Translate pywintypes.error to WindowsError, which is - # a subclass of OSError. FIXME: We should really - # translate errno using _sys_errlist (or similar), but - # how can this be done from Python? - raise WindowsError(*e.args) finally: # Child is launched. Close the parent's copy of those pipe # handles that only the child should have open. You need -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:08:11 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 18:08:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NjQ3?= =?utf-8?q?=3A_save_socket_error_details_in_LMTP=2Econnect=28=29?= Message-ID: <3YQ82M1R9qzPYM@mail.python.org> http://hg.python.org/cpython/rev/1a2ead9faa3f changeset: 80910:1a2ead9faa3f branch: 3.2 parent: 80905:b7419f88c628 user: Andrew Svetlov date: Mon Dec 17 18:54:53 2012 +0200 summary: Issue #16647: save socket error details in LMTP.connect() Patch by Serhiy Storchaka. files: Lib/smtplib.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -892,13 +892,13 @@ try: self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.connect(host) - except socket.error as msg: + except socket.error: if self.debuglevel > 0: print('connect fail:', host, file=stderr) if self.sock: self.sock.close() self.sock = None - raise socket.error(msg) + raise (code, msg) = self.getreply() if self.debuglevel > 0: print('connect:', msg, file=stderr) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:08:12 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 18:08:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316647=3A_save_socket_error_details_in_LMTP=2Econnect?= =?utf-8?b?KCk=?= Message-ID: <3YQ82N3pjlzQS5@mail.python.org> http://hg.python.org/cpython/rev/6d805653843a changeset: 80911:6d805653843a branch: 3.3 parent: 80906:b8289a08d720 parent: 80910:1a2ead9faa3f user: Andrew Svetlov date: Mon Dec 17 18:55:10 2012 +0200 summary: Issue #16647: save socket error details in LMTP.connect() Patch by Serhiy Storchaka. files: Lib/smtplib.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -920,13 +920,13 @@ self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.file = None self.sock.connect(host) - except socket.error as msg: + except socket.error: if self.debuglevel > 0: print('connect fail:', host, file=stderr) if self.sock: self.sock.close() self.sock = None - raise socket.error(msg) + raise (code, msg) = self.getreply() if self.debuglevel > 0: print('connect:', msg, file=stderr) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:08:13 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 18:08:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316647=3A_save_socket_error_details_in_LMTP=2Eco?= =?utf-8?q?nnect=28=29?= Message-ID: <3YQ82P66gwzQQN@mail.python.org> http://hg.python.org/cpython/rev/ddf0fbff94d8 changeset: 80912:ddf0fbff94d8 parent: 80909:a50b409ee89f parent: 80911:6d805653843a user: Andrew Svetlov date: Mon Dec 17 18:57:16 2012 +0200 summary: Issue #16647: save socket error details in LMTP.connect() Initial patch by Serhiy Storchaka. files: Lib/smtplib.py | 10 +++++----- Lib/test/mock_socket.py | 8 ++------ Lib/test/test_smtplib.py | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -309,7 +309,7 @@ try: port = int(port) except ValueError: - raise socket.error("nonnumeric port") + raise OSError("nonnumeric port") if not port: port = self.default_port if self.debuglevel > 0: @@ -330,7 +330,7 @@ s = s.encode("ascii") try: self.sock.sendall(s) - except socket.error: + except OSError: self.close() raise SMTPServerDisconnected('Server not connected') else: @@ -363,7 +363,7 @@ while 1: try: line = self.file.readline() - except socket.error as e: + except OSError as e: self.close() raise SMTPServerDisconnected("Connection unexpectedly closed: " + str(e)) @@ -920,13 +920,13 @@ self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.file = None self.sock.connect(host) - except socket.error as msg: + except OSError: if self.debuglevel > 0: print('connect fail:', host, file=stderr) if self.sock: self.sock.close() self.sock = None - raise socket.error(msg) + raise (code, msg) = self.getreply() if self.debuglevel > 0: print('connect:', msg, file=stderr) diff --git a/Lib/test/mock_socket.py b/Lib/test/mock_socket.py --- a/Lib/test/mock_socket.py +++ b/Lib/test/mock_socket.py @@ -140,12 +140,8 @@ return "" -class gaierror(Exception): - pass - - -class error(Exception): - pass +gaierror = socket_module.gaierror +error = socket_module.error # Constants diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -542,9 +542,9 @@ def testNonnumericPort(self): # check that non-numeric port raises socket.error - self.assertRaises(mock_socket.error, smtplib.SMTP, + self.assertRaises(OSError, smtplib.SMTP, "localhost", "bogus") - self.assertRaises(mock_socket.error, smtplib.SMTP, + self.assertRaises(OSError, smtplib.SMTP, "localhost:bogus") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:08:15 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 18:08:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NjQ3?= =?utf-8?q?=3A_save_socket_error_details_in_LMTP=2Econnect=28=29?= Message-ID: <3YQ82R1NhqzQZy@mail.python.org> http://hg.python.org/cpython/rev/98b73c0103d9 changeset: 80913:98b73c0103d9 branch: 2.7 parent: 80901:542cfc75c043 user: Andrew Svetlov date: Mon Dec 17 19:06:43 2012 +0200 summary: Issue #16647: save socket error details in LMTP.connect() Patch by Serhiy Storchaka. files: Lib/smtplib.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -818,13 +818,13 @@ try: self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.connect(host) - except socket.error, msg: + except socket.error: if self.debuglevel > 0: print>>stderr, 'connect fail:', host if self.sock: self.sock.close() self.sock = None - raise socket.error, msg + raise (code, msg) = self.getreply() if self.debuglevel > 0: print>>stderr, "connect:", msg -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:08:16 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 18:08:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMi43IC0+IDIuNyk6?= =?utf-8?q?_merge_heads?= Message-ID: <3YQ82S3Yf2zQjB@mail.python.org> http://hg.python.org/cpython/rev/fd57dbfa5765 changeset: 80914:fd57dbfa5765 branch: 2.7 parent: 80908:6e07be3dfb6b parent: 80913:98b73c0103d9 user: Andrew Svetlov date: Mon Dec 17 19:07:57 2012 +0200 summary: merge heads files: Lib/smtplib.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/smtplib.py b/Lib/smtplib.py --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -818,13 +818,13 @@ try: self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.connect(host) - except socket.error, msg: + except socket.error: if self.debuglevel > 0: print>>stderr, 'connect fail:', host if self.sock: self.sock.close() self.sock = None - raise socket.error, msg + raise (code, msg) = self.getreply() if self.debuglevel > 0: print>>stderr, "connect:", msg -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:27:19 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 18:27:19 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Cleanup=3A_remove_not_need?= =?utf-8?q?ed_mocks=2E?= Message-ID: <3YQ8SR66gWzQjB@mail.python.org> http://hg.python.org/cpython/rev/1bd6563be3e4 changeset: 80915:1bd6563be3e4 parent: 80912:ddf0fbff94d8 user: Andrew Svetlov date: Mon Dec 17 19:27:10 2012 +0200 summary: Cleanup: remove not needed mocks. files: Lib/test/test_smtplib.py | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -524,12 +524,6 @@ class NonConnectingTests(unittest.TestCase): - def setUp(self): - smtplib.socket = mock_socket - - def tearDown(self): - smtplib.socket = socket - def testNotConnected(self): # Test various operations on an unconnected SMTP object that # should raise exceptions (at present the attempt in SMTP.send -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:51:25 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 18:51:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Replace_os=2Eerror_with_OS?= =?utf-8?q?Error_in_tkinter_and_IDLE?= Message-ID: <3YQ90F2NZzzRRc@mail.python.org> http://hg.python.org/cpython/rev/bf92327eeda8 changeset: 80916:bf92327eeda8 user: Andrew Svetlov date: Mon Dec 17 19:51:15 2012 +0200 summary: Replace os.error with OSError in tkinter and IDLE files: Lib/idlelib/FileList.py | 2 +- Lib/idlelib/GrepDialog.py | 2 +- Lib/idlelib/IOBinding.py | 2 +- Lib/idlelib/PathBrowser.py | 2 +- Lib/idlelib/TreeWidget.py | 4 ++-- Lib/tkinter/filedialog.py | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/idlelib/FileList.py b/Lib/idlelib/FileList.py --- a/Lib/idlelib/FileList.py +++ b/Lib/idlelib/FileList.py @@ -103,7 +103,7 @@ if not os.path.isabs(filename): try: pwd = os.getcwd() - except os.error: + except OSError: pass else: filename = os.path.join(pwd, filename) diff --git a/Lib/idlelib/GrepDialog.py b/Lib/idlelib/GrepDialog.py --- a/Lib/idlelib/GrepDialog.py +++ b/Lib/idlelib/GrepDialog.py @@ -110,7 +110,7 @@ def findfiles(self, dir, base, rec): try: names = os.listdir(dir or os.curdir) - except os.error as msg: + except OSError as msg: print(msg) return [] list = [] diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py +++ b/Lib/idlelib/IOBinding.py @@ -503,7 +503,7 @@ else: try: pwd = os.getcwd() - except os.error: + except OSError: pwd = "" return pwd, "" diff --git a/Lib/idlelib/PathBrowser.py b/Lib/idlelib/PathBrowser.py --- a/Lib/idlelib/PathBrowser.py +++ b/Lib/idlelib/PathBrowser.py @@ -45,7 +45,7 @@ def GetSubList(self): try: names = os.listdir(self.dir or os.curdir) - except os.error: + except OSError: return [] packages = [] for name in names: diff --git a/Lib/idlelib/TreeWidget.py b/Lib/idlelib/TreeWidget.py --- a/Lib/idlelib/TreeWidget.py +++ b/Lib/idlelib/TreeWidget.py @@ -382,7 +382,7 @@ try: os.rename(self.path, newpath) self.path = newpath - except os.error: + except OSError: pass def GetIconName(self): @@ -395,7 +395,7 @@ def GetSubList(self): try: names = os.listdir(self.path) - except os.error: + except OSError: return [] names.sort(key = os.path.normcase) sublist = [] diff --git a/Lib/tkinter/filedialog.py b/Lib/tkinter/filedialog.py --- a/Lib/tkinter/filedialog.py +++ b/Lib/tkinter/filedialog.py @@ -166,7 +166,7 @@ dir, pat = self.get_filter() try: names = os.listdir(dir) - except os.error: + except OSError: self.master.bell() return self.directory = dir @@ -209,7 +209,7 @@ if not os.path.isabs(dir): try: pwd = os.getcwd() - except os.error: + except OSError: pwd = None if pwd: dir = os.path.join(pwd, dir) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 18:55:37 2012 From: python-checkins at python.org (guido.van.rossum) Date: Mon, 17 Dec 2012 18:55:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Rename_call=5Flater=28=29_arg?= =?utf-8?q?_when_to_delay=2E?= Message-ID: <3YQ95554m9zQlm@mail.python.org> http://hg.python.org/peps/rev/f1373855ebe1 changeset: 4618:f1373855ebe1 user: Guido van Rossum date: Mon Dec 17 09:55:32 2012 -0800 summary: Rename call_later() arg when to delay. files: pep-3156.txt | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -169,7 +169,7 @@ Note: run() blocks until the termination condition is met. - TBD: run() may need an argument to start some work. + TBD: run() may need an argument to start some work? - TBD: Do we need an API for stopping the event loop, given that we have the termination condition? Is the termination condition @@ -178,9 +178,9 @@ - TBD: Do we need an API to run the event loop for a little while (e.g. a single iteration)? If so, exactly what should it do? -- ``call_later(when, callback, *args)``. Arrange for - ``callback(*args)`` to be called approximately ``when`` seconds in - the future, once, unless canceled. As usual in Python, ``when`` may +- ``call_later(delay, callback, *args)``. Arrange for + ``callback(*args)`` to be called approximately ``delay`` seconds in + the future, once, unless canceled. As usual in Python, ``delay`` may be a floating point number to represent smaller intervals. Returns a ``DelayedCall`` object representing the callback, whose ``cancel()`` method can be used to cancel the callback. @@ -201,6 +201,8 @@ ``isinstance(callback, DelayedCall)``? It should silently skip a canceled callback. +- TBD: Repeatable timers. + Some methods in the standard conforming interface return Futures: - ``wrap_future(future)``. This takes a PEP 3148 Future (i.e., an @@ -346,7 +348,7 @@ If ``call_soon()`` is used, this guarantee is true even if the system clock were to run backwards. This is also the case for ``call_later(0, callback, *args)``. However, if ``call_later()`` is -used with a nonzero ``when`` argument, all bets are off if the system +used with a nonzero delay, all bets are off if the system clock were to runs backwards. (A good event loop implementation should use ``time.monotonic()`` to avoid problems when the clock runs backward. See PEP 418.) -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Mon Dec 17 20:47:34 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 17 Dec 2012 20:47:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Issue_16646_?= =?utf-8?q?=28ftplib=29=3A_deliberately_use_intermediate_variable_after_ca?= =?utf-8?q?tching?= Message-ID: <3YQCZG5qBLzNjb@mail.python.org> http://hg.python.org/cpython/rev/dcefa2c8386b changeset: 80917:dcefa2c8386b branch: 3.2 parent: 80910:1a2ead9faa3f user: Giampaolo Rodola' date: Mon Dec 17 20:46:16 2012 +0100 summary: Issue 16646 (ftplib): deliberately use intermediate variable after catching exception files: Lib/ftplib.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -291,7 +291,8 @@ try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error as err: + except socket.error as _: + err = _ if sock: sock.close() sock = None -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 20:47:36 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 17 Dec 2012 20:47:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_16646_=28ftplib=29=3A_deliberately_use_intermediate_vari?= =?utf-8?q?able_after_catching?= Message-ID: <3YQCZJ1R60zQ8k@mail.python.org> http://hg.python.org/cpython/rev/da161499d0c0 changeset: 80918:da161499d0c0 branch: 3.3 parent: 80911:6d805653843a parent: 80917:dcefa2c8386b user: Giampaolo Rodola' date: Mon Dec 17 20:46:29 2012 +0100 summary: Issue 16646 (ftplib): deliberately use intermediate variable after catching exception files: Lib/ftplib.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -295,7 +295,8 @@ try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error as err: + except socket.error as _: + err = _ if sock: sock.close() sock = None -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 20:47:37 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 17 Dec 2012 20:47:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_16646_=28ftplib=29=3A_deliberately_use_intermediat?= =?utf-8?q?e_variable_after_catching?= Message-ID: <3YQCZK48r5zQVV@mail.python.org> http://hg.python.org/cpython/rev/0845a3dbee38 changeset: 80919:0845a3dbee38 parent: 80916:bf92327eeda8 parent: 80918:da161499d0c0 user: Giampaolo Rodola' date: Mon Dec 17 20:46:45 2012 +0100 summary: Issue 16646 (ftplib): deliberately use intermediate variable after catching exception files: Lib/ftplib.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -295,7 +295,8 @@ try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error as err: + except socket.error as _: + err = _ if sock: sock.close() sock = None -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 21:23:57 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 21:23:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316704=3A_Get_rid_?= =?utf-8?q?of_select=2Eerror_in_stdlib=2E_Use_OSError_instead=2E?= Message-ID: <3YQDNF1m4GzNmG@mail.python.org> http://hg.python.org/cpython/rev/eb8032781eba changeset: 80920:eb8032781eba user: Andrew Svetlov date: Mon Dec 17 22:23:46 2012 +0200 summary: Issue #16704: Get rid of select.error in stdlib. Use OSError instead. files: Lib/subprocess.py | 4 ++-- Lib/telnetlib.py | 4 ++-- Lib/test/test_logging.py | 2 +- Lib/test/test_select.py | 2 +- Lib/test/test_signal.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1614,7 +1614,7 @@ raise TimeoutExpired(self.args, orig_timeout) try: ready = poller.poll(timeout) - except select.error as e: + except OSError as e: if e.args[0] == errno.EINTR: continue raise @@ -1682,7 +1682,7 @@ (rlist, wlist, xlist) = \ select.select(self._read_set, self._write_set, [], timeout) - except select.error as e: + except OSError as e: if e.args[0] == errno.EINTR: continue raise diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py --- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -313,7 +313,7 @@ while i < 0 and not self.eof: try: ready = poller.poll(call_timeout) - except select.error as e: + except OSError as e: if e.errno == errno.EINTR: if timeout is not None: elapsed = time() - time_start @@ -683,7 +683,7 @@ while not m and not self.eof: try: ready = poller.poll(call_timeout) - except select.error as e: + except OSError as e: if e.errno == errno.EINTR: if timeout is not None: elapsed = time() - time_start diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -773,7 +773,7 @@ """ try: asyncore.loop(poll_interval, map=self.sockmap) - except select.error: + except OSError: # On FreeBSD 8, closing the server repeatably # raises this error. We swallow it if the # server has been closed. diff --git a/Lib/test/test_select.py b/Lib/test/test_select.py --- a/Lib/test/test_select.py +++ b/Lib/test/test_select.py @@ -32,7 +32,7 @@ fp.close() try: select.select([fd], [], [], 0) - except select.error as err: + except OSError as err: self.assertEqual(err.errno, errno.EBADF) else: self.fail("exception not raised") diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -299,10 +299,10 @@ # We attempt to get a signal during the select call try: select.select([read], [], [], TIMEOUT_FULL) - except select.error: + except OSError: pass else: - raise Exception("select.error not raised") + raise Exception("OSError not raised") after_time = time.time() dt = after_time - before_time if dt >= TIMEOUT_HALF: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 21:55:42 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 21:55:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Replace_mmap=2Eerror_with_?= =?utf-8?q?OSError=2C_=2316705?= Message-ID: <3YQF4t6LmwzLtK@mail.python.org> http://hg.python.org/cpython/rev/7aa2ccc5aef1 changeset: 80921:7aa2ccc5aef1 user: Andrew Svetlov date: Mon Dec 17 22:55:31 2012 +0200 summary: Replace mmap.error with OSError, #16705 files: Lib/test/test_mmap.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -245,7 +245,7 @@ def test_bad_file_desc(self): # Try opening a bad file descriptor... - self.assertRaises(mmap.error, mmap.mmap, -2, 4096) + self.assertRaises(OSError, mmap.mmap, -2, 4096) def test_tougher_find(self): # Do a tougher .find() test. SF bug 515943 pointed out that, in 2.2, @@ -673,7 +673,7 @@ # parameters to _get_osfhandle. s = socket.socket() try: - with self.assertRaises(mmap.error): + with self.assertRaises(OSError): m = mmap.mmap(s.fileno(), 10) finally: s.close() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 22:35:33 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 17 Dec 2012 22:35:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Get_rig_of_EnvironmentErro?= =?utf-8?q?r_=28=2316705=29?= Message-ID: <3YQFys4CyfzNhB@mail.python.org> http://hg.python.org/cpython/rev/061e9a439f54 changeset: 80922:061e9a439f54 user: Andrew Svetlov date: Mon Dec 17 23:35:18 2012 +0200 summary: Get rig of EnvironmentError (#16705) files: Lib/compileall.py | 2 +- Lib/getpass.py | 2 +- Lib/mimetypes.py | 4 ++-- Lib/shutil.py | 10 +++++----- Lib/subprocess.py | 4 ++-- Lib/tarfile.py | 8 ++++---- Lib/test/test_exceptions.py | 6 +++--- Lib/test/test_fileio.py | 2 +- Lib/test/test_io.py | 2 +- Lib/test/test_signal.py | 2 +- Lib/test/test_subprocess.py | 7 +++---- Lib/test/test_tarfile.py | 4 ++-- Lib/test/test_tempfile.py | 2 +- Lib/test/test_urllib2net.py | 2 +- Lib/test/test_winreg.py | 10 +++++----- Lib/urllib/request.py | 2 +- 16 files changed, 34 insertions(+), 35 deletions(-) diff --git a/Lib/compileall.py b/Lib/compileall.py --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -209,7 +209,7 @@ with (sys.stdin if args.flist=='-' else open(args.flist)) as f: for line in f: compile_dests.append(line.strip()) - except EnvironmentError: + except OSError: print("Error reading file list {}".format(args.flist)) return False diff --git a/Lib/getpass.py b/Lib/getpass.py --- a/Lib/getpass.py +++ b/Lib/getpass.py @@ -47,7 +47,7 @@ input = tty if not stream: stream = tty - except EnvironmentError as e: + except OSError as e: # If that fails, see if stdin can be controlled. try: fd = sys.stdin.fileno() diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -243,7 +243,7 @@ while True: try: ctype = _winreg.EnumKey(mimedb, i) - except EnvironmentError: + except OSError: break else: yield ctype @@ -256,7 +256,7 @@ with _winreg.OpenKey(mimedb, ctype) as key: suffix, datatype = _winreg.QueryValueEx(key, 'Extension') - except EnvironmentError: + except OSError: continue if datatype != _winreg.REG_SZ: continue diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -39,20 +39,20 @@ "ignore_patterns", "chown", "which"] # disk_usage is added later, if available on the platform -class Error(EnvironmentError): +class Error(OSError): pass class SameFileError(Error): """Raised when source and destination are the same file.""" -class SpecialFileError(EnvironmentError): +class SpecialFileError(OSError): """Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)""" -class ExecError(EnvironmentError): +class ExecError(OSError): """Raised when a command could not be executed""" -class ReadError(EnvironmentError): +class ReadError(OSError): """Raised when an archive cannot be read""" class RegistryError(Exception): @@ -329,7 +329,7 @@ # continue with other files except Error as err: errors.extend(err.args[0]) - except EnvironmentError as why: + except OSError as why: errors.append((srcname, dstname, str(why))) try: copystat(src, dst) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -819,7 +819,7 @@ for f in filter(None, (self.stdin, self.stdout, self.stderr)): try: f.close() - except EnvironmentError: + except OSError: pass # Ignore EBADF or other errors. # Make sure the child pipes are closed as well. @@ -833,7 +833,7 @@ for fd in to_close: try: os.close(fd) - except EnvironmentError: + except OSError: pass raise diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2022,7 +2022,7 @@ try: self._extract_member(tarinfo, os.path.join(path, tarinfo.name), set_attrs=set_attrs) - except EnvironmentError as e: + except OSError as e: if self.errorlevel > 0: raise else: @@ -2212,7 +2212,7 @@ os.lchown(targetpath, u, g) else: os.chown(targetpath, u, g) - except EnvironmentError as e: + except OSError as e: raise ExtractError("could not change owner") def chmod(self, tarinfo, targetpath): @@ -2221,7 +2221,7 @@ if hasattr(os, 'chmod'): try: os.chmod(targetpath, tarinfo.mode) - except EnvironmentError as e: + except OSError as e: raise ExtractError("could not change mode") def utime(self, tarinfo, targetpath): @@ -2231,7 +2231,7 @@ return try: os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime)) - except EnvironmentError as e: + except OSError as e: raise ExtractError("could not change modification time") #-------------------------------------------------------------------------- diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -255,11 +255,11 @@ 'errno' : 'foo', 'strerror' : 'bar'}), (IOError, ('foo', 'bar', 'baz', 'quux'), {'args' : ('foo', 'bar', 'baz', 'quux')}), - (EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'), + (OSError, ('errnoStr', 'strErrorStr', 'filenameStr'), {'args' : ('errnoStr', 'strErrorStr'), 'strerror' : 'strErrorStr', 'errno' : 'errnoStr', 'filename' : 'filenameStr'}), - (EnvironmentError, (1, 'strErrorStr', 'filenameStr'), + (OSError, (1, 'strErrorStr', 'filenameStr'), {'args' : (1, 'strErrorStr'), 'errno' : 1, 'strerror' : 'strErrorStr', 'filename' : 'filenameStr'}), (SyntaxError, (), {'msg' : None, 'text' : None, @@ -409,7 +409,7 @@ self.assertIsNone(e.__context__) self.assertIsNone(e.__cause__) - class MyException(EnvironmentError): + class MyException(OSError): pass e = MyException() diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -285,7 +285,7 @@ if sys.platform != "win32": try: f = _FileIO("/dev/tty", "a") - except EnvironmentError: + except OSError: # When run in a cron job there just aren't any # ttys, so skip the test. This also handles other # OS'es that don't support /dev/tty. diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2825,7 +2825,7 @@ for fd in fds: try: os.close(fd) - except EnvironmentError as e: + except OSError as e: if e.errno != errno.EBADF: raise self.addCleanup(cleanup_fds) diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -33,7 +33,7 @@ def ignoring_eintr(__func, *args, **kwargs): try: return __func(*args, **kwargs) - except EnvironmentError as e: + except OSError as e: if e.errno != errno.EINTR: raise return None diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -925,8 +925,7 @@ # value for that limit, but Windows has 2048, so we loop # 1024 times (each call leaked two fds). for i in range(1024): - # Windows raises IOError. Others raise OSError. - with self.assertRaises(EnvironmentError) as c: + with self.assertRaises(OSError) as c: subprocess.Popen(['nonexisting_i_hope'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -1874,7 +1873,7 @@ # let some time for the process to exit, and create a new Popen: this # should trigger the wait() of p time.sleep(0.2) - with self.assertRaises(EnvironmentError) as c: + with self.assertRaises(OSError) as c: with subprocess.Popen(['nonexisting_i_hope'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: @@ -2155,7 +2154,7 @@ self.assertEqual(proc.returncode, 1) def test_invalid_args(self): - with self.assertRaises(EnvironmentError) as c: + with self.assertRaises(OSError) as c: with subprocess.Popen(['nonexisting_i_hope'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: 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 @@ -342,7 +342,7 @@ tar.extract("ustar/regtype", TEMPDIR) try: tar.extract("ustar/lnktype", TEMPDIR) - except EnvironmentError as e: + except OSError as e: if e.errno == errno.ENOENT: self.fail("hardlink not extracted properly") @@ -352,7 +352,7 @@ try: tar.extract("ustar/symtype", TEMPDIR) - except EnvironmentError as e: + except OSError as e: if e.errno == errno.ENOENT: self.fail("symlink not extracted properly") diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -149,7 +149,7 @@ # via any bugs above try: os.kill(pid, signal.SIGKILL) - except EnvironmentError: + except OSError: pass os.close(read_fd) os.close(write_fd) diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -216,7 +216,7 @@ debug(url) try: f = urlopen(url, req, TIMEOUT) - except EnvironmentError as err: + except OSError as err: debug(err) if expected_err: msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" % diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -97,7 +97,7 @@ QueryInfoKey(int_sub_key) self.fail("It appears the CloseKey() function does " "not close the actual key!") - except EnvironmentError: + except OSError: pass # ... and close that key that way :-) int_key = int(key) @@ -106,7 +106,7 @@ QueryInfoKey(int_key) self.fail("It appears the key.Close() function " "does not close the actual key!") - except EnvironmentError: + except OSError: pass def _read_test_data(self, root_key, subkeystr="sub_key", OpenKey=OpenKey): @@ -123,7 +123,7 @@ while 1: try: data = EnumValue(sub_key, index) - except EnvironmentError: + except OSError: break self.assertEqual(data in test_data, True, "Didn't read back the correct test data") @@ -144,7 +144,7 @@ try: EnumKey(key, 1) self.fail("Was able to get a second key when I only have one!") - except EnvironmentError: + except OSError: pass key.Close() @@ -168,7 +168,7 @@ # Shouldnt be able to delete it twice! DeleteKey(key, subkeystr) self.fail("Deleting the key twice succeeded") - except EnvironmentError: + except OSError: pass key.Close() DeleteKey(root_key, test_key_name) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -232,7 +232,7 @@ for temp_file in _url_tempfiles: try: os.unlink(temp_file) - except EnvironmentError: + except OSError: pass del _url_tempfiles[:] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 17 23:07:47 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 17 Dec 2012 23:07:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Following_issue_=2313390?= =?utf-8?q?=2C_fix_compilation_--without-pymalloc=2C_and_make?= Message-ID: <3YQGh3369WzNhB@mail.python.org> http://hg.python.org/cpython/rev/a85673b55177 changeset: 80923:a85673b55177 user: Antoine Pitrou date: Mon Dec 17 23:05:59 2012 +0100 summary: Following issue #13390, fix compilation --without-pymalloc, and make sys.getallocatedblocks() return 0 in that situation. files: Doc/library/sys.rst | 15 ++++++++------- Lib/test/test_sys.py | 7 ++++++- Objects/obmalloc.c | 7 +++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -396,16 +396,17 @@ .. function:: getallocatedblocks() Return the number of memory blocks currently allocated by the interpreter, - regardless of their size. This function is mainly useful for debugging - small memory leaks. Because of the interpreter's internal caches, the - result can vary from call to call; you may have to call - :func:`_clear_type_cache()` to get more predictable results. + regardless of their size. This function is mainly useful for tracking + and debugging memory leaks. Because of the interpreter's internal + caches, the result can vary from call to call; you may have to call + :func:`_clear_type_cache()` and :func:`gc.collect()` to get more + predictable results. + + If a Python build or implementation cannot reasonably compute this + information, :func:`getallocatedblocks()` is allowed to return 0 instead. .. versionadded:: 3.4 - .. impl-detail:: - Not all Python implementations may be able to return this information. - .. function:: getcheckinterval() diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -7,6 +7,7 @@ import operator import codecs import gc +import sysconfig # count the number of test runs, used to create unique # strings to intern in test_intern() @@ -616,9 +617,13 @@ "sys.getallocatedblocks unavailable on this build") def test_getallocatedblocks(self): # Some sanity checks + with_pymalloc = sysconfig.get_config_var('WITH_PYMALLOC') a = sys.getallocatedblocks() self.assertIs(type(a), int) - self.assertGreater(a, 0) + if with_pymalloc: + self.assertGreater(a, 0) + else: + self.assertEqual(a, 0) try: # While we could imagine a Python session where the number of # multiple buffer objects would exceed the sharing of references, diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -1316,6 +1316,13 @@ { PyMem_FREE(p); } + +Py_ssize_t +_Py_GetAllocatedBlocks(void) +{ + return 0; +} + #endif /* WITH_PYMALLOC */ #ifdef PYMALLOC_DEBUG -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 01:46:59 2012 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 18 Dec 2012 01:46:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Tweaks=2E?= Message-ID: <3YQLCl5575zN1m@mail.python.org> http://hg.python.org/peps/rev/afd42b077500 changeset: 4619:afd42b077500 user: Guido van Rossum date: Mon Dec 17 16:46:54 2012 -0800 summary: Tweaks. files: pep-3156.txt | 24 +++++++++++++++++++----- 1 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -236,7 +236,8 @@ remarks as for ``getaddrinfo()``. - ``create_transport(...)``. Creates a transport. Returns a Future. - TBD: Signature. Do we pass in a protocol or protocol class? + TBD: Signature. Do we pass in a protocol or protocol factory? + TBD: Should this be called create_connection()? - ``start_serving(...)``. Enters a loop that accepts connections. TBD: Signature. There are two possibilities: @@ -290,7 +291,10 @@ used to cancel the callback. Note that, unlike ``call_later()``, the callback may be called many times. Calling ``add_reader()`` again for the same file descriptor implicitly cancels the previous - callback for that file descriptor. + callback for that file descriptor. (TBD: Returning a + ``DelayedCall`` that can be cancelled seems awkward. Let's forget + about that.) (TBD: Change this to raise an exception if a handler + is already set.) - ``add_writer(fd, callback, *args)``. Like ``add_reader()``, but registers the callback for writing instead of for reading. @@ -300,11 +304,19 @@ currently set for the file descriptor. (The reason for providing this alternate interface is that it is often more convenient to remember the file descriptor than to remember the ``DelayedCall`` - object.) + object.) (TBD: Return ``True`` if a handler was removed, ``False`` + if not.) - ``remove_writer(fd)``. This is to ``add_writer()`` as ``remove_reader()`` is to ``add_reader()``. +TBD: What about multiple callbacks per fd? The current semantics is +that ``add_reader()/add_writer()`` replace a previously registered +callback. + +TBD: Should ``remove_*()`` return a bool telling is whether it removed +anything? + The following methods for doing async I/O on sockets are optional. They are alternative to the previous set of optional methods, intended for transport implementations on Windows using IOCP (if the event loop @@ -411,7 +423,8 @@ TBD: Public attribute recording the realtime value when the callback is scheduled? (Since this is needed anyway for storing it in a heap.) -TBD: A better name for the class? +TBD: A better name for the class? Reasonable suggestions so far: +``Callback``, ``Call``, ``Handler`` (my current favorite). Futures ------- @@ -427,7 +440,8 @@ - ``cancelled()``. - ``running()``. Note that the meaning of this method is essentially - "cannot be cancelled and isn't done yet". + "cannot be cancelled and isn't done yet". (TBD: Would be nice if + this could be set *and* cleared in some cases, e.g. sock_recv().) - ``done()``. -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Tue Dec 18 06:00:03 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 18 Dec 2012 06:00:03 +0100 Subject: [Python-checkins] Daily reference leaks (a85673b55177): sum=0 Message-ID: results for a85673b55177 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/refloguxFcMr', '-x'] From andrew.svetlov at gmail.com Tue Dec 18 13:28:59 2012 From: andrew.svetlov at gmail.com (Andrew Svetlov) Date: Tue, 18 Dec 2012 14:28:59 +0200 Subject: [Python-checkins] cpython: Following issue #13390, fix compilation --without-pymalloc, and make In-Reply-To: <3YQGh3369WzNhB@mail.python.org> References: <3YQGh3369WzNhB@mail.python.org> Message-ID: Looks like Windows buildbots broken by this commit. On Tue, Dec 18, 2012 at 12:07 AM, antoine.pitrou wrote: > http://hg.python.org/cpython/rev/a85673b55177 > changeset: 80923:a85673b55177 > user: Antoine Pitrou > date: Mon Dec 17 23:05:59 2012 +0100 > summary: > Following issue #13390, fix compilation --without-pymalloc, and make sys.getallocatedblocks() return 0 in that situation. > > files: > Doc/library/sys.rst | 15 ++++++++------- > Lib/test/test_sys.py | 7 ++++++- > Objects/obmalloc.c | 7 +++++++ > 3 files changed, 21 insertions(+), 8 deletions(-) > > > diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst > --- a/Doc/library/sys.rst > +++ b/Doc/library/sys.rst > @@ -396,16 +396,17 @@ > .. function:: getallocatedblocks() > > Return the number of memory blocks currently allocated by the interpreter, > - regardless of their size. This function is mainly useful for debugging > - small memory leaks. Because of the interpreter's internal caches, the > - result can vary from call to call; you may have to call > - :func:`_clear_type_cache()` to get more predictable results. > + regardless of their size. This function is mainly useful for tracking > + and debugging memory leaks. Because of the interpreter's internal > + caches, the result can vary from call to call; you may have to call > + :func:`_clear_type_cache()` and :func:`gc.collect()` to get more > + predictable results. > + > + If a Python build or implementation cannot reasonably compute this > + information, :func:`getallocatedblocks()` is allowed to return 0 instead. > > .. versionadded:: 3.4 > > - .. impl-detail:: > - Not all Python implementations may be able to return this information. > - > > .. function:: getcheckinterval() > > diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py > --- a/Lib/test/test_sys.py > +++ b/Lib/test/test_sys.py > @@ -7,6 +7,7 @@ > import operator > import codecs > import gc > +import sysconfig > > # count the number of test runs, used to create unique > # strings to intern in test_intern() > @@ -616,9 +617,13 @@ > "sys.getallocatedblocks unavailable on this build") > def test_getallocatedblocks(self): > # Some sanity checks > + with_pymalloc = sysconfig.get_config_var('WITH_PYMALLOC') > a = sys.getallocatedblocks() > self.assertIs(type(a), int) > - self.assertGreater(a, 0) > + if with_pymalloc: > + self.assertGreater(a, 0) > + else: > + self.assertEqual(a, 0) > try: > # While we could imagine a Python session where the number of > # multiple buffer objects would exceed the sharing of references, > diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c > --- a/Objects/obmalloc.c > +++ b/Objects/obmalloc.c > @@ -1316,6 +1316,13 @@ > { > PyMem_FREE(p); > } > + > +Py_ssize_t > +_Py_GetAllocatedBlocks(void) > +{ > + return 0; > +} > + > #endif /* WITH_PYMALLOC */ > > #ifdef PYMALLOC_DEBUG > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > -- Thanks, Andrew Svetlov From python-checkins at python.org Tue Dec 18 14:53:51 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 14:53:51 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NzEx?= =?utf-8?q?=3A_Fix_required_method_names_for_collections=2EIterator?= Message-ID: <3YQggg0wPFzQMy@mail.python.org> http://hg.python.org/cpython/rev/259516fddb6c changeset: 80924:259516fddb6c branch: 3.2 parent: 80917:dcefa2c8386b user: Andrew Svetlov date: Tue Dec 18 15:48:10 2012 +0200 summary: Issue #16711: Fix required method names for collections.Iterator Thanks to Inada Naoki files: Doc/library/collections.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -1057,7 +1057,7 @@ .. class:: Iterator - ABC for classes that provide the :meth:`__iter__` and :meth:`next` methods. + ABC for classes that provide the :meth:`__iter__` and :meth:`__next__` methods. See also the definition of :term:`iterator`. .. class:: Sequence -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 14:53:52 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 14:53:52 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316711=3A_Fix_required_method_names_for_collections=2E?= =?utf-8?q?Iterator?= Message-ID: <3YQggh3FfmzQMy@mail.python.org> http://hg.python.org/cpython/rev/864bb05be215 changeset: 80925:864bb05be215 branch: 3.3 parent: 80918:da161499d0c0 parent: 80924:259516fddb6c user: Andrew Svetlov date: Tue Dec 18 15:53:15 2012 +0200 summary: Issue #16711: Fix required method names for collections.Iterator Thanks to Inada Naoki files: Doc/library/collections.abc.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst --- a/Doc/library/collections.abc.rst +++ b/Doc/library/collections.abc.rst @@ -90,7 +90,7 @@ .. class:: Iterator - ABC for classes that provide the :meth:`__iter__` and :meth:`next` methods. + ABC for classes that provide the :meth:`__iter__` and :meth:`__next__` methods. See also the definition of :term:`iterator`. .. class:: Sequence -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 14:53:53 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 14:53:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316711=3A_Fix_required_method_names_for_collecti?= =?utf-8?q?ons=2EIterator?= Message-ID: <3YQggj5NkrzQPB@mail.python.org> http://hg.python.org/cpython/rev/85127ec7d724 changeset: 80926:85127ec7d724 parent: 80923:a85673b55177 parent: 80925:864bb05be215 user: Andrew Svetlov date: Tue Dec 18 15:53:39 2012 +0200 summary: Issue #16711: Fix required method names for collections.Iterator Thanks to Inada Naoki files: Doc/library/collections.abc.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst --- a/Doc/library/collections.abc.rst +++ b/Doc/library/collections.abc.rst @@ -90,7 +90,7 @@ .. class:: Iterator - ABC for classes that provide the :meth:`__iter__` and :meth:`next` methods. + ABC for classes that provide the :meth:`__iter__` and :meth:`__next__` methods. See also the definition of :term:`iterator`. .. class:: Sequence -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Tue Dec 18 19:26:56 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 18 Dec 2012 19:26:56 +0100 Subject: [Python-checkins] cpython: Following issue #13390, fix compilation --without-pymalloc, and make References: <3YQGh3369WzNhB@mail.python.org> Message-ID: <20121218192656.2f257770@pitrou.net> On Tue, 18 Dec 2012 14:28:59 +0200 Andrew Svetlov wrote: > Looks like Windows buildbots broken by this commit. Yet WITH_PYMALLOC is defined in PC/pyconfig.h... Looks like it isn't picked up by sysconfig. Regards Antoine. > > On Tue, Dec 18, 2012 at 12:07 AM, antoine.pitrou > wrote: > > http://hg.python.org/cpython/rev/a85673b55177 > > changeset: 80923:a85673b55177 > > user: Antoine Pitrou > > date: Mon Dec 17 23:05:59 2012 +0100 > > summary: > > Following issue #13390, fix compilation --without-pymalloc, and make sys.getallocatedblocks() return 0 in that situation. > > > > files: > > Doc/library/sys.rst | 15 ++++++++------- > > Lib/test/test_sys.py | 7 ++++++- > > Objects/obmalloc.c | 7 +++++++ > > 3 files changed, 21 insertions(+), 8 deletions(-) > > > > > > diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst > > --- a/Doc/library/sys.rst > > +++ b/Doc/library/sys.rst > > @@ -396,16 +396,17 @@ > > .. function:: getallocatedblocks() > > > > Return the number of memory blocks currently allocated by the interpreter, > > - regardless of their size. This function is mainly useful for debugging > > - small memory leaks. Because of the interpreter's internal caches, the > > - result can vary from call to call; you may have to call > > - :func:`_clear_type_cache()` to get more predictable results. > > + regardless of their size. This function is mainly useful for tracking > > + and debugging memory leaks. Because of the interpreter's internal > > + caches, the result can vary from call to call; you may have to call > > + :func:`_clear_type_cache()` and :func:`gc.collect()` to get more > > + predictable results. > > + > > + If a Python build or implementation cannot reasonably compute this > > + information, :func:`getallocatedblocks()` is allowed to return 0 instead. > > > > .. versionadded:: 3.4 > > > > - .. impl-detail:: > > - Not all Python implementations may be able to return this information. > > - > > > > .. function:: getcheckinterval() > > > > diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py > > --- a/Lib/test/test_sys.py > > +++ b/Lib/test/test_sys.py > > @@ -7,6 +7,7 @@ > > import operator > > import codecs > > import gc > > +import sysconfig > > > > # count the number of test runs, used to create unique > > # strings to intern in test_intern() > > @@ -616,9 +617,13 @@ > > "sys.getallocatedblocks unavailable on this build") > > def test_getallocatedblocks(self): > > # Some sanity checks > > + with_pymalloc = sysconfig.get_config_var('WITH_PYMALLOC') > > a = sys.getallocatedblocks() > > self.assertIs(type(a), int) > > - self.assertGreater(a, 0) > > + if with_pymalloc: > > + self.assertGreater(a, 0) > > + else: > > + self.assertEqual(a, 0) > > try: > > # While we could imagine a Python session where the number of > > # multiple buffer objects would exceed the sharing of references, > > diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c > > --- a/Objects/obmalloc.c > > +++ b/Objects/obmalloc.c > > @@ -1316,6 +1316,13 @@ > > { > > PyMem_FREE(p); > > } > > + > > +Py_ssize_t > > +_Py_GetAllocatedBlocks(void) > > +{ > > + return 0; > > +} > > + > > #endif /* WITH_PYMALLOC */ > > > > #ifdef PYMALLOC_DEBUG > > > > -- > > Repository URL: http://hg.python.org/cpython > > > > _______________________________________________ > > Python-checkins mailing list > > Python-checkins at python.org > > http://mail.python.org/mailman/listinfo/python-checkins > > > > > From python-checkins at python.org Tue Dec 18 19:52:46 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 19:52:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Relax_test_when_WITH=5FPYM?= =?utf-8?q?ALLOC_is_false_or_undefined=2E?= Message-ID: <3YQpJZ4rTVzMxP@mail.python.org> http://hg.python.org/cpython/rev/b6ced7bd7d96 changeset: 80927:b6ced7bd7d96 user: Antoine Pitrou date: Tue Dec 18 19:50:58 2012 +0100 summary: Relax test when WITH_PYMALLOC is false or undefined. files: Lib/test/test_sys.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -623,7 +623,10 @@ if with_pymalloc: self.assertGreater(a, 0) else: - self.assertEqual(a, 0) + # When WITH_PYMALLOC isn't available, we don't know anything + # about the underlying implementation: the function might + # return 0 or something greater. + self.assertGreaterEqual(a, 0) try: # While we could imagine a Python session where the number of # multiple buffer objects would exceed the sharing of references, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 20:11:33 2012 From: python-checkins at python.org (guido.van.rossum) Date: Tue, 18 Dec 2012 20:11:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_Thunk_to_the_alternatives?= =?utf-8?q?_for_DelayedCall=2E?= Message-ID: <3YQpkF2RW1zNhB@mail.python.org> http://hg.python.org/peps/rev/fbda38201681 changeset: 4620:fbda38201681 user: Guido van Rossum date: Tue Dec 18 11:11:29 2012 -0800 summary: Add Thunk to the alternatives for DelayedCall. files: pep-3156.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -424,7 +424,7 @@ is scheduled? (Since this is needed anyway for storing it in a heap.) TBD: A better name for the class? Reasonable suggestions so far: -``Callback``, ``Call``, ``Handler`` (my current favorite). +``Callback``, ``Call``, ``Handler`` (my current favorite), ``Thunk``. Futures ------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Tue Dec 18 20:27:58 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 20:27:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NzE0?= =?utf-8?q?=3A_use_=27raise=27_exceptions=2C_don=27t_=27throw=27=2E?= Message-ID: <3YQq5B2v7szNm2@mail.python.org> http://hg.python.org/cpython/rev/fdf907708f49 changeset: 80928:fdf907708f49 branch: 3.2 parent: 80924:259516fddb6c user: Andrew Svetlov date: Tue Dec 18 21:14:22 2012 +0200 summary: Issue #16714: use 'raise' exceptions, don't 'throw'. Patch by Serhiy Storchaka. files: Doc/howto/cporting.rst | 2 +- Lib/asyncore.py | 2 +- Lib/distutils/tests/test_msvc9compiler.py | 2 +- Lib/email/feedparser.py | 4 +- Lib/email/header.py | 2 +- Lib/importlib/_bootstrap.py | 2 +- Lib/importlib/test/import_/test_fromlist.py | 2 +- Lib/io.py | 2 +- Lib/logging/__init__.py | 2 +- Lib/multiprocessing/util.py | 2 +- Lib/runpy.py | 2 +- Lib/tempfile.py | 2 +- Lib/test/test_codeop.py | 2 +- Lib/test/test_docxmlrpc.py | 2 +- Lib/test/test_imaplib.py | 2 +- Lib/test/test_minidom.py | 2 +- Lib/test/test_os.py | 16 +++++----- Lib/test/test_pty.py | 2 +- Lib/test/test_sax.py | 4 +- Lib/test/test_signal.py | 4 +- Lib/test/test_socketserver.py | 2 +- Lib/test/test_sys_settrace.py | 2 +- Lib/test/test_time.py | 2 +- Lib/test/test_uu.py | 4 +- Lib/test/test_winreg.py | 4 +- Lib/test/test_zipfile.py | 2 +- Lib/tkinter/__init__.py | 2 +- Lib/unittest/case.py | 4 +- Lib/wsgiref/validate.py | 4 +- Lib/xml/sax/_exceptions.py | 6 +- Lib/xml/sax/xmlreader.py | 2 +- Lib/xmlrpc/client.py | 2 +- Modules/_io/_iomodule.c | 2 +- Modules/parsermodule.c | 6 +- Modules/posixmodule.c | 2 +- Tools/scripts/serve.py | 2 +- 36 files changed, 54 insertions(+), 54 deletions(-) diff --git a/Doc/howto/cporting.rst b/Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst +++ b/Doc/howto/cporting.rst @@ -253,7 +253,7 @@ * :c:func:`PyCapsule_GetName` always returns NULL. - * :c:func:`PyCapsule_SetName` always throws an exception and + * :c:func:`PyCapsule_SetName` always raises an exception and returns failure. (Since there's no way to store a name in a CObject, noisy failure of :c:func:`PyCapsule_SetName` was deemed preferable to silent failure here. If this is diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -393,7 +393,7 @@ else: return data except socket.error as why: - # winsock sometimes throws ENOTCONN + # winsock sometimes raises ENOTCONN if why.args[0] in _DISCONNECTED: self.handle_close() return b'' diff --git a/Lib/distutils/tests/test_msvc9compiler.py b/Lib/distutils/tests/test_msvc9compiler.py --- a/Lib/distutils/tests/test_msvc9compiler.py +++ b/Lib/distutils/tests/test_msvc9compiler.py @@ -104,7 +104,7 @@ unittest.TestCase): def test_no_compiler(self): - # makes sure query_vcvarsall throws + # makes sure query_vcvarsall raises # a DistutilsPlatformError if the compiler # is not found from distutils.msvc9compiler import query_vcvarsall diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py --- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -13,7 +13,7 @@ data. When you have no more data to push into the parser, call .close(). This completes the parsing and returns the root message object. -The other advantage of this parser is that it will never throw a parsing +The other advantage of this parser is that it will never raise a parsing exception. Instead, when it finds something unexpected, it adds a 'defect' to the current message. Defects are just instances that live on the message object's .defects attribute. @@ -214,7 +214,7 @@ # supposed to see in the body of the message. self._parse_headers(headers) # Headers-only parsing is a backwards compatibility hack, which was - # necessary in the older parser, which could throw errors. All + # necessary in the older parser, which could raise errors. All # remaining lines in the input are thrown into the message body. if self._headersonly: lines = [] diff --git a/Lib/email/header.py b/Lib/email/header.py --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -280,7 +280,7 @@ else: s = s.decode(input_charset, errors) # Ensure that the bytes we're storing can be decoded to the output - # character set, otherwise an early error is thrown. + # character set, otherwise an early error is raised. output_charset = charset.output_codec or 'us-ascii' if output_charset != _charset.UNKNOWN8BIT: try: diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -415,7 +415,7 @@ source_mtime is not None): # If e.g. Jython ever implements imp.cache_from_source to have # their own cached file format, this block of code will most likely - # throw an exception. + # raise an exception. data = bytearray(imp.get_magic()) data.extend(marshal._w_long(source_mtime)) data.extend(marshal.dumps(code_object)) diff --git a/Lib/importlib/test/import_/test_fromlist.py b/Lib/importlib/test/import_/test_fromlist.py --- a/Lib/importlib/test/import_/test_fromlist.py +++ b/Lib/importlib/test/import_/test_fromlist.py @@ -39,7 +39,7 @@ If a package is being imported, then what is listed in fromlist may be treated as a module to be imported [module]. But once again, even if - something in fromlist does not exist as a module, no error is thrown + something in fromlist does not exist as a module, no error is raised [no module]. And this extends to what is contained in __all__ when '*' is imported [using *]. And '*' does not need to be the only name in the fromlist [using * with others]. diff --git a/Lib/io.py b/Lib/io.py --- a/Lib/io.py +++ b/Lib/io.py @@ -4,7 +4,7 @@ At the top of the I/O hierarchy is the abstract base class IOBase. It defines the basic interface to a stream. Note, however, that there is no separation between reading and writing to streams; implementations are -allowed to throw an IOError if they do not support a given operation. +allowed to raise an IOError if they do not support a given operation. Extending IOBase is RawIOBase which deals simply with the reading and writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1355,7 +1355,7 @@ """ sinfo = None if _srcfile: - #IronPython doesn't track Python frames, so findCaller throws an + #IronPython doesn't track Python frames, so findCaller raises an #exception on some versions of IronPython. We trap it here so that #IronPython can use logging. try: diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py +++ b/Lib/multiprocessing/util.py @@ -301,7 +301,7 @@ _run_finalizers(0) if current_process() is not None: # We check if the current process is None here because if - # it's None, any call to ``active_children()`` will throw an + # it's None, any call to ``active_children()`` will raise an # AttributeError (active_children winds up trying to get # attributes from util._current_process). This happens in a # variety of shutdown circumstances that are not well-understood diff --git a/Lib/runpy.py b/Lib/runpy.py --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -211,7 +211,7 @@ pass else: # The following check looks a bit odd. The trick is that - # NullImporter throws ImportError if the supplied path is a + # NullImporter raises ImportError if the supplied path is a # *valid* directory entry (and hence able to be handled # by the standard import machinery) try: diff --git a/Lib/tempfile.py b/Lib/tempfile.py --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -625,7 +625,7 @@ def __init__(self, suffix="", prefix=template, dir=None): self._closed = False - self.name = None # Handle mkdtemp throwing an exception + self.name = None # Handle mkdtemp raising an exception self.name = mkdtemp(suffix, prefix, dir) def __repr__(self): diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -50,7 +50,7 @@ '''succeed iff str is the start of an invalid piece of code''' try: compile_command(str,symbol=symbol) - self.fail("No exception thrown for invalid code") + self.fail("No exception raised for invalid code") except SyntaxError: self.assertTrue(is_syntax) except OverflowError: diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -100,7 +100,7 @@ self.assertEqual(response.status, 200) self.assertEqual(response.getheader("Content-type"), "text/html") - # Server throws an exception if we don't start to read the data + # Server raises an exception if we don't start to read the data response.read() def test_invalid_get_response(self): diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -99,7 +99,7 @@ return line += part except IOError: - # ..but SSLSockets throw exceptions. + # ..but SSLSockets raise exceptions. return if line.endswith(b'\r\n'): break diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -1085,7 +1085,7 @@ self.assertEqual(doc.toxml('iso-8859-15'), b'\xa4') - # Verify that character decoding errors throw exceptions instead + # Verify that character decoding errors raise exceptions instead # of crashing self.assertRaises(UnicodeDecodeError, parseString, b'Comment \xe7a va ? Tr\xe8s bien ?') diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -164,33 +164,33 @@ try: result[200] - self.fail("No exception thrown") + self.fail("No exception raised") except IndexError: pass # Make sure that assignment fails try: result.st_mode = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass try: result.st_rdev = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except (AttributeError, TypeError): pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the stat_result constructor with a too-short tuple. try: result2 = os.stat_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass @@ -233,20 +233,20 @@ # Make sure that assignment really fails try: result.f_bfree = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the constructor with a too-short tuple. try: result2 = os.statvfs_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -152,7 +152,7 @@ # platform-dependent amount of data is written to its fd. On # Linux 2.6, it's 4000 bytes and the child won't block, but on OS # X even the small writes in the child above will block it. Also - # on Linux, the read() will throw an OSError (input/output error) + # on Linux, the read() will raise an OSError (input/output error) # when it tries to read past the end of the buffer but the child's # already exited, so catch and discard those exceptions. It's not # worth checking for EIO. diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -389,7 +389,7 @@ def test_5027_1(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by parsing a document. @@ -415,7 +415,7 @@ def test_5027_2(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by direct manipulation of the diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -113,7 +113,7 @@ # This wait should be interrupted by the signal's exception. self.wait(child) time.sleep(1) # Give the signal time to be delivered. - self.fail('HandlerBCalled exception not thrown') + self.fail('HandlerBCalled exception not raised') except HandlerBCalled: self.assertTrue(self.b_called) self.assertFalse(self.a_called) @@ -152,7 +152,7 @@ # test-running process from all the signals. It then # communicates with that child process over a pipe and # re-raises information about any exceptions the child - # throws. The real work happens in self.run_test(). + # raises. The real work happens in self.run_test(). os_done_r, os_done_w = os.pipe() with closing(os.fdopen(os_done_r, 'rb')) as done_r, \ closing(os.fdopen(os_done_w, 'wb')) as done_w: diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -58,7 +58,7 @@ def simple_subprocess(testcase): pid = os.fork() if pid == 0: - # Don't throw an exception; it would be caught by the test harness. + # Don't raise an exception; it would be caught by the test harness. os._exit(72) yield None pid2, status = os.waitpid(pid, 0) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -418,7 +418,7 @@ except ValueError: pass else: - self.fail("exception not thrown!") + self.fail("exception not raised!") except RuntimeError: self.fail("recursion counter not reset") diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -106,7 +106,7 @@ def test_strptime(self): # Should be able to go round-trip from strftime to strptime without - # throwing an exception. + # raising an exception. tt = time.gmtime(self.t) for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', 'j', 'm', 'M', 'p', 'S', diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -80,7 +80,7 @@ out = io.BytesIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error as e: self.assertEqual(str(e), "Truncated input file") @@ -89,7 +89,7 @@ out = io.BytesIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error as e: self.assertEqual(str(e), "No valid begin line found in input file") diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -245,7 +245,7 @@ def test_changing_value(self): # Issue2810: A race condition in 2.6 and 3.1 may cause - # EnumValue or QueryValue to throw "WindowsError: More data is + # EnumValue or QueryValue to raise "WindowsError: More data is # available" done = False @@ -291,7 +291,7 @@ def test_dynamic_key(self): # Issue2810, when the value is dynamically generated, these - # throw "WindowsError: More data is available" in 2.6 and 3.1 + # raise "WindowsError: More data is available" in 2.6 and 3.1 try: EnumValue(HKEY_PERFORMANCE_DATA, 0) except OSError as e: diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -873,7 +873,7 @@ with zipfile.ZipFile(data, mode="w") as zipf: zipf.writestr("foo.txt", "O, for a Muse of Fire!") - # This is correct; calling .read on a closed ZipFile should throw + # This is correct; calling .read on a closed ZipFile should raise # a RuntimeError, and so should calling .testzip. An earlier # version of .testzip would swallow this exception (and any other) # and report that the first file in the archive was corrupt. diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -147,7 +147,7 @@ pass def _exit(code=0): - """Internal function. Calling it will throw the exception SystemExit.""" + """Internal function. Calling it will raise the exception SystemExit.""" try: code = int(code) except ValueError: diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -528,10 +528,10 @@ def assertRaises(self, excClass, callableObj=None, *args, **kwargs): - """Fail unless an exception of class excClass is thrown + """Fail unless an exception of class excClass is raised by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is - thrown, it will not be caught, and the test case will be + raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception. diff --git a/Lib/wsgiref/validate.py b/Lib/wsgiref/validate.py --- a/Lib/wsgiref/validate.py +++ b/Lib/wsgiref/validate.py @@ -139,9 +139,9 @@ When applied between a WSGI server and a WSGI application, this middleware will check for WSGI compliancy on a number of levels. This middleware does not modify the request or response in any - way, but will throw an AssertionError if anything seems off + way, but will raise an AssertionError if anything seems off (except for a failure to close the application iterator, which - will be printed to stderr -- there's no way to throw an exception + will be printed to stderr -- there's no way to raise an exception at that point). """ diff --git a/Lib/xml/sax/_exceptions.py b/Lib/xml/sax/_exceptions.py --- a/Lib/xml/sax/_exceptions.py +++ b/Lib/xml/sax/_exceptions.py @@ -12,7 +12,7 @@ the application: you can subclass it to provide additional functionality, or to add localization. Note that although you will receive a SAXException as the argument to the handlers in the - ErrorHandler interface, you are not actually required to throw + ErrorHandler interface, you are not actually required to raise the exception; instead, you can simply read the information in it.""" @@ -50,7 +50,7 @@ the original XML document. Note that although the application will receive a SAXParseException as the argument to the handlers in the ErrorHandler interface, the application is not actually required - to throw the exception; instead, it can simply read the + to raise the exception; instead, it can simply read the information in it and take a different action. Since this exception is a subclass of SAXException, it inherits @@ -62,7 +62,7 @@ self._locator = locator # We need to cache this stuff at construction time. - # If this exception is thrown, the objects through which we must + # If this exception is raised, the objects through which we must # traverse to get this information may be deleted by the time # it gets caught. self._systemId = self._locator.getSystemId() diff --git a/Lib/xml/sax/xmlreader.py b/Lib/xml/sax/xmlreader.py --- a/Lib/xml/sax/xmlreader.py +++ b/Lib/xml/sax/xmlreader.py @@ -68,7 +68,7 @@ SAX parsers are not required to provide localization for errors and warnings; if they cannot support the requested locale, - however, they must throw a SAX exception. Applications may + however, they must raise a SAX exception. Applications may request a locale change in the middle of a parse.""" raise SAXNotSupportedException("Locale support not implemented") diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -800,7 +800,7 @@ class MultiCallIterator: """Iterates over the results of a multicall. Exceptions are - thrown in response to xmlrpc faults.""" + raised in response to xmlrpc faults.""" def __init__(self, results): self.results = results diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -59,7 +59,7 @@ "At the top of the I/O hierarchy is the abstract base class IOBase. It\n" "defines the basic interface to a stream. Note, however, that there is no\n" "separation between reading and writing to streams; implementations are\n" -"allowed to throw an IOError if they do not support a given operation.\n" +"allowed to raise an IOError if they do not support a given operation.\n" "\n" "Extending IOBase is RawIOBase which deals simply with the reading and\n" "writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide\n" diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -718,7 +718,7 @@ err_string("parse tree does not use a valid start symbol"); } } - /* Make sure we throw an exception on all errors. We should never + /* Make sure we raise an exception on all errors. We should never * get this, but we'd do well to be sure something is done. */ if (st == NULL && !PyErr_Occurred()) @@ -824,7 +824,7 @@ else if (!ISNONTERMINAL(type)) { /* * It has to be one or the other; this is an error. - * Throw an exception. + * Raise an exception. */ PyObject *err = Py_BuildValue("os", elem, "unknown node type."); PyErr_SetObject(parser_error, err); @@ -876,7 +876,7 @@ if (ISTERMINAL(num)) { /* * The tuple is simple, but it doesn't start with a start symbol. - * Throw an exception now and be done with it. + * Raise an exception now and be done with it. */ tuple = Py_BuildValue("os", tuple, "Illegal syntax-tree; cannot start with terminal symbol."); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -349,7 +349,7 @@ #if defined _MSC_VER && _MSC_VER >= 1400 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is - * valid and throw an assertion if it isn't. + * valid and raise an assertion if it isn't. * Normally, an invalid fd is likely to be a C program error and therefore * an assertion can be useful, but it does contradict the POSIX standard * which for write(2) states: diff --git a/Tools/scripts/serve.py b/Tools/scripts/serve.py --- a/Tools/scripts/serve.py +++ b/Tools/scripts/serve.py @@ -2,7 +2,7 @@ ''' Small wsgiref based web server. Takes a path to serve from and an optional port number (defaults to 8000), then tries to serve files. -Mime types are guessed from the file names, 404 errors are thrown +Mime types are guessed from the file names, 404 errors are raised if the file is not found. Used for the make serve target in Doc. ''' import sys -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 20:28:00 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 20:28:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316714=3A_use_=27raise=27_exceptions=2C_don=27t_=27thr?= =?utf-8?q?ow=27=2E?= Message-ID: <3YQq5D34D6zQhR@mail.python.org> http://hg.python.org/cpython/rev/15a391919deb changeset: 80929:15a391919deb branch: 3.3 parent: 80925:864bb05be215 parent: 80928:fdf907708f49 user: Andrew Svetlov date: Tue Dec 18 21:26:36 2012 +0200 summary: Issue #16714: use 'raise' exceptions, don't 'throw'. Patch by Serhiy Storchaka. files: Doc/howto/cporting.rst | 2 +- Doc/library/contextlib.rst | 2 +- Doc/library/imaplib.rst | 2 +- Doc/library/os.rst | 8 ++-- Lib/asyncore.py | 2 +- Lib/contextlib.py | 2 +- Lib/distutils/tests/test_msvc9compiler.py | 2 +- Lib/email/feedparser.py | 4 +- Lib/email/header.py | 2 +- Lib/email/utils.py | 2 +- Lib/imaplib.py | 2 +- Lib/io.py | 2 +- Lib/logging/__init__.py | 2 +- Lib/multiprocessing/util.py | 2 +- Lib/pkgutil.py | 2 +- Lib/tempfile.py | 2 +- Lib/test/test_codeop.py | 2 +- Lib/test/test_docxmlrpc.py | 2 +- Lib/test/test_imaplib.py | 2 +- Lib/test/test_minidom.py | 2 +- Lib/test/test_os.py | 16 +++++----- Lib/test/test_posix.py | 4 +- Lib/test/test_pty.py | 2 +- Lib/test/test_sax.py | 4 +- Lib/test/test_signal.py | 4 +- Lib/test/test_socketserver.py | 2 +- Lib/test/test_sys_settrace.py | 2 +- Lib/test/test_time.py | 2 +- Lib/test/test_uu.py | 4 +- Lib/test/test_winreg.py | 4 +- Lib/test/test_zipfile.py | 2 +- Lib/tkinter/__init__.py | 2 +- Lib/unittest/case.py | 4 +- Lib/wsgiref/validate.py | 4 +- Lib/xml/sax/_exceptions.py | 6 ++-- Lib/xml/sax/xmlreader.py | 2 +- Lib/xmlrpc/client.py | 2 +- Modules/_io/_iomodule.c | 2 +- Modules/parsermodule.c | 6 ++-- Modules/posixmodule.c | 2 +- Tools/scripts/find_recursionlimit.py | 2 +- Tools/scripts/serve.py | 2 +- 42 files changed, 64 insertions(+), 64 deletions(-) diff --git a/Doc/howto/cporting.rst b/Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst +++ b/Doc/howto/cporting.rst @@ -253,7 +253,7 @@ * :c:func:`PyCapsule_GetName` always returns NULL. - * :c:func:`PyCapsule_SetName` always throws an exception and + * :c:func:`PyCapsule_SetName` always raises an exception and returns failure. (Since there's no way to store a name in a CObject, noisy failure of :c:func:`PyCapsule_SetName` was deemed preferable to silent failure here. If this is diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -184,7 +184,7 @@ files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later - # in the list throw an exception + # in the list raise an exception Each instance maintains a stack of registered callbacks that are called in reverse order when the instance is closed (either explicitly or implicitly diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst --- a/Doc/library/imaplib.rst +++ b/Doc/library/imaplib.rst @@ -75,7 +75,7 @@ :class:`ssl.SSLContext` object which allows bundling SSL configuration options, certificates and private keys into a single (potentially long-lived) structure. Note that the *keyfile*/*certfile* parameters are mutually exclusive with *ssl_context*, - a :class:`ValueError` is thrown if *keyfile*/*certfile* is provided along with *ssl_context*. + a :class:`ValueError` is raised if *keyfile*/*certfile* is provided along with *ssl_context*. .. versionchanged:: 3.3 *ssl_context* parameter added. diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1171,7 +1171,7 @@ output) specifies which file descriptor should be queried. If the file descriptor is not connected to a terminal, an :exc:`OSError` - is thrown. + is raised. :func:`shutil.get_terminal_size` is the high-level function which should normally be used, ``os.get_terminal_size`` is the low-level @@ -1945,7 +1945,7 @@ :mod:`os` module permit use of their *dir_fd* parameter. Different platforms provide different functionality, and an option that might work on one might be unsupported on another. For consistency's sakes, functions that support - *dir_fd* always allow specifying the parameter, but will throw an exception + *dir_fd* always allow specifying the parameter, but will raise an exception if the functionality is not actually available. To check whether a particular function permits use of its *dir_fd* @@ -1986,7 +1986,7 @@ descriptor. Different platforms provide different functionality, and an option that might work on one might be unsupported on another. For consistency's sakes, functions that support *fd* always allow specifying - the parameter, but will throw an exception if the functionality is not + the parameter, but will raise an exception if the functionality is not actually available. To check whether a particular function permits specifying an open file @@ -2007,7 +2007,7 @@ platforms provide different functionality, and an option that might work on one might be unsupported on another. For consistency's sakes, functions that support *follow_symlinks* always allow specifying the parameter, but will - throw an exception if the functionality is not actually available. + raise an exception if the functionality is not actually available. To check whether a particular function permits use of its *follow_symlinks* parameter, use the ``in`` operator on ``supports_follow_symlinks``. As an diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -385,7 +385,7 @@ else: return data except socket.error as why: - # winsock sometimes throws ENOTCONN + # winsock sometimes raises ENOTCONN if why.args[0] in _DISCONNECTED: self.handle_close() return b'' diff --git a/Lib/contextlib.py b/Lib/contextlib.py --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -151,7 +151,7 @@ files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later - # in the list throw an exception + # in the list raise an exception """ def __init__(self): diff --git a/Lib/distutils/tests/test_msvc9compiler.py b/Lib/distutils/tests/test_msvc9compiler.py --- a/Lib/distutils/tests/test_msvc9compiler.py +++ b/Lib/distutils/tests/test_msvc9compiler.py @@ -104,7 +104,7 @@ unittest.TestCase): def test_no_compiler(self): - # makes sure query_vcvarsall throws + # makes sure query_vcvarsall raises # a DistutilsPlatformError if the compiler # is not found from distutils.msvc9compiler import query_vcvarsall diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py --- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -13,7 +13,7 @@ data. When you have no more data to push into the parser, call .close(). This completes the parsing and returns the root message object. -The other advantage of this parser is that it will never throw a parsing +The other advantage of this parser is that it will never raise a parsing exception. Instead, when it finds something unexpected, it adds a 'defect' to the current message. Defects are just instances that live on the message object's .defects attribute. @@ -228,7 +228,7 @@ # supposed to see in the body of the message. self._parse_headers(headers) # Headers-only parsing is a backwards compatibility hack, which was - # necessary in the older parser, which could throw errors. All + # necessary in the older parser, which could raise errors. All # remaining lines in the input are thrown into the message body. if self._headersonly: lines = [] diff --git a/Lib/email/header.py b/Lib/email/header.py --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -298,7 +298,7 @@ else: s = s.decode(input_charset, errors) # Ensure that the bytes we're storing can be decoded to the output - # character set, otherwise an early error is thrown. + # character set, otherwise an early error is raised. output_charset = charset.output_codec or 'us-ascii' if output_charset != _charset.UNKNOWN8BIT: try: diff --git a/Lib/email/utils.py b/Lib/email/utils.py --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -83,7 +83,7 @@ 'utf-8'. """ name, address = pair - # The address MUST (per RFC) be ascii, so throw a UnicodeError if it isn't. + # The address MUST (per RFC) be ascii, so raise an UnicodeError if it isn't. address.encode('ascii') if name: try: diff --git a/Lib/imaplib.py b/Lib/imaplib.py --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1178,7 +1178,7 @@ ssl_context - a SSLContext object that contains your certificate chain and private key (default: None) Note: if ssl_context is provided, then parameters keyfile or - certfile should not be set otherwise ValueError is thrown. + certfile should not be set otherwise ValueError is raised. for more documentation see the docstring of the parent class IMAP4. """ diff --git a/Lib/io.py b/Lib/io.py --- a/Lib/io.py +++ b/Lib/io.py @@ -4,7 +4,7 @@ At the top of the I/O hierarchy is the abstract base class IOBase. It defines the basic interface to a stream. Note, however, that there is no separation between reading and writing to streams; implementations are -allowed to throw an IOError if they do not support a given operation. +allowed to raise an IOError if they do not support a given operation. Extending IOBase is RawIOBase which deals simply with the reading and writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1349,7 +1349,7 @@ """ sinfo = None if _srcfile: - #IronPython doesn't track Python frames, so findCaller throws an + #IronPython doesn't track Python frames, so findCaller raises an #exception on some versions of IronPython. We trap it here so that #IronPython can use logging. try: diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py +++ b/Lib/multiprocessing/util.py @@ -290,7 +290,7 @@ if current_process() is not None: # We check if the current process is None here because if - # it's None, any call to ``active_children()`` will throw + # it's None, any call to ``active_children()`` will raise # an AttributeError (active_children winds up trying to # get attributes from util._current_process). One # situation where this can happen is if someone has diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -504,7 +504,7 @@ return importlib.find_loader(fullname, path) except (ImportError, AttributeError, TypeError, ValueError) as ex: # This hack fixes an impedance mismatch between pkgutil and - # importlib, where the latter throws other errors for cases where + # importlib, where the latter raises other errors for cases where # pkgutil previously threw ImportError msg = "Error while finding loader for {!r} ({}: {})" raise ImportError(msg.format(fullname, type(ex), ex)) from ex diff --git a/Lib/tempfile.py b/Lib/tempfile.py --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -621,7 +621,7 @@ def __init__(self, suffix="", prefix=template, dir=None): self._closed = False - self.name = None # Handle mkdtemp throwing an exception + self.name = None # Handle mkdtemp raising an exception self.name = mkdtemp(suffix, prefix, dir) def __repr__(self): diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -50,7 +50,7 @@ '''succeed iff str is the start of an invalid piece of code''' try: compile_command(str,symbol=symbol) - self.fail("No exception thrown for invalid code") + self.fail("No exception raised for invalid code") except SyntaxError: self.assertTrue(is_syntax) except OverflowError: diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -100,7 +100,7 @@ self.assertEqual(response.status, 200) self.assertEqual(response.getheader("Content-type"), "text/html") - # Server throws an exception if we don't start to read the data + # Server raises an exception if we don't start to read the data response.read() def test_invalid_get_response(self): diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -115,7 +115,7 @@ return line += part except IOError: - # ..but SSLSockets throw exceptions. + # ..but SSLSockets raise exceptions. return if line.endswith(b'\r\n'): break diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -1073,7 +1073,7 @@ '' '\u20ac'.encode('utf-16')) - # Verify that character decoding errors throw exceptions instead + # Verify that character decoding errors raise exceptions instead # of crashing self.assertRaises(UnicodeDecodeError, parseString, b'Comment \xe7a va ? Tr\xe8s bien ?') diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -202,33 +202,33 @@ try: result[200] - self.fail("No exception thrown") + self.fail("No exception raised") except IndexError: pass # Make sure that assignment fails try: result.st_mode = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass try: result.st_rdev = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except (AttributeError, TypeError): pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the stat_result constructor with a too-short tuple. try: result2 = os.stat_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass @@ -273,20 +273,20 @@ # Make sure that assignment really fails try: result.f_bfree = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the constructor with a too-short tuple. try: result2 = os.statvfs_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -824,7 +824,7 @@ posix.rename(support.TESTFN + 'ren', support.TESTFN) raise else: - posix.stat(support.TESTFN) # should not throw exception + posix.stat(support.TESTFN) # should not raise exception finally: posix.close(f) @@ -842,7 +842,7 @@ def test_unlink_dir_fd(self): f = posix.open(posix.getcwd(), posix.O_RDONLY) support.create_empty_file(support.TESTFN + 'del') - posix.stat(support.TESTFN + 'del') # should not throw exception + posix.stat(support.TESTFN + 'del') # should not raise exception try: posix.unlink(support.TESTFN + 'del', dir_fd=f) except: diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -152,7 +152,7 @@ # platform-dependent amount of data is written to its fd. On # Linux 2.6, it's 4000 bytes and the child won't block, but on OS # X even the small writes in the child above will block it. Also - # on Linux, the read() will throw an OSError (input/output error) + # on Linux, the read() will raise an OSError (input/output error) # when it tries to read past the end of the buffer but the child's # already exited, so catch and discard those exceptions. It's not # worth checking for EIO. diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -389,7 +389,7 @@ def test_5027_1(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by parsing a document. @@ -415,7 +415,7 @@ def test_5027_2(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by direct manipulation of the diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -107,7 +107,7 @@ # This wait should be interrupted by the signal's exception. self.wait(child) time.sleep(1) # Give the signal time to be delivered. - self.fail('HandlerBCalled exception not thrown') + self.fail('HandlerBCalled exception not raised') except HandlerBCalled: self.assertTrue(self.b_called) self.assertFalse(self.a_called) @@ -143,7 +143,7 @@ # test-running process from all the signals. It then # communicates with that child process over a pipe and # re-raises information about any exceptions the child - # throws. The real work happens in self.run_test(). + # raises. The real work happens in self.run_test(). os_done_r, os_done_w = os.pipe() with closing(os.fdopen(os_done_r, 'rb')) as done_r, \ closing(os.fdopen(os_done_w, 'wb')) as done_w: diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -58,7 +58,7 @@ def simple_subprocess(testcase): pid = os.fork() if pid == 0: - # Don't throw an exception; it would be caught by the test harness. + # Don't raise an exception; it would be caught by the test harness. os._exit(72) yield None pid2, status = os.waitpid(pid, 0) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -422,7 +422,7 @@ except ValueError: pass else: - self.fail("exception not thrown!") + self.fail("exception not raised!") except RuntimeError: self.fail("recursion counter not reset") diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -175,7 +175,7 @@ def test_strptime(self): # Should be able to go round-trip from strftime to strptime without - # throwing an exception. + # raising an exception. tt = time.gmtime(self.t) for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', 'j', 'm', 'M', 'p', 'S', diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -80,7 +80,7 @@ out = io.BytesIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error as e: self.assertEqual(str(e), "Truncated input file") @@ -89,7 +89,7 @@ out = io.BytesIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error as e: self.assertEqual(str(e), "No valid begin line found in input file") diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -245,7 +245,7 @@ def test_changing_value(self): # Issue2810: A race condition in 2.6 and 3.1 may cause - # EnumValue or QueryValue to throw "WindowsError: More data is + # EnumValue or QueryValue to raise "WindowsError: More data is # available" done = False @@ -291,7 +291,7 @@ def test_dynamic_key(self): # Issue2810, when the value is dynamically generated, these - # throw "WindowsError: More data is available" in 2.6 and 3.1 + # raise "WindowsError: More data is available" in 2.6 and 3.1 try: EnumValue(HKEY_PERFORMANCE_DATA, 0) except OSError as e: diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -1024,7 +1024,7 @@ with zipfile.ZipFile(data, mode="w") as zipf: zipf.writestr("foo.txt", "O, for a Muse of Fire!") - # This is correct; calling .read on a closed ZipFile should throw + # This is correct; calling .read on a closed ZipFile should raise # a RuntimeError, and so should calling .testzip. An earlier # version of .testzip would swallow this exception (and any other) # and report that the first file in the archive was corrupt. diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -149,7 +149,7 @@ pass def _exit(code=0): - """Internal function. Calling it will throw the exception SystemExit.""" + """Internal function. Calling it will raise the exception SystemExit.""" try: code = int(code) except ValueError: diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -542,10 +542,10 @@ return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg)) def assertRaises(self, excClass, callableObj=None, *args, **kwargs): - """Fail unless an exception of class excClass is thrown + """Fail unless an exception of class excClass is raised by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is - thrown, it will not be caught, and the test case will be + raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception. diff --git a/Lib/wsgiref/validate.py b/Lib/wsgiref/validate.py --- a/Lib/wsgiref/validate.py +++ b/Lib/wsgiref/validate.py @@ -139,9 +139,9 @@ When applied between a WSGI server and a WSGI application, this middleware will check for WSGI compliancy on a number of levels. This middleware does not modify the request or response in any - way, but will throw an AssertionError if anything seems off + way, but will raise an AssertionError if anything seems off (except for a failure to close the application iterator, which - will be printed to stderr -- there's no way to throw an exception + will be printed to stderr -- there's no way to raise an exception at that point). """ diff --git a/Lib/xml/sax/_exceptions.py b/Lib/xml/sax/_exceptions.py --- a/Lib/xml/sax/_exceptions.py +++ b/Lib/xml/sax/_exceptions.py @@ -12,7 +12,7 @@ the application: you can subclass it to provide additional functionality, or to add localization. Note that although you will receive a SAXException as the argument to the handlers in the - ErrorHandler interface, you are not actually required to throw + ErrorHandler interface, you are not actually required to raise the exception; instead, you can simply read the information in it.""" @@ -50,7 +50,7 @@ the original XML document. Note that although the application will receive a SAXParseException as the argument to the handlers in the ErrorHandler interface, the application is not actually required - to throw the exception; instead, it can simply read the + to raise the exception; instead, it can simply read the information in it and take a different action. Since this exception is a subclass of SAXException, it inherits @@ -62,7 +62,7 @@ self._locator = locator # We need to cache this stuff at construction time. - # If this exception is thrown, the objects through which we must + # If this exception is raised, the objects through which we must # traverse to get this information may be deleted by the time # it gets caught. self._systemId = self._locator.getSystemId() diff --git a/Lib/xml/sax/xmlreader.py b/Lib/xml/sax/xmlreader.py --- a/Lib/xml/sax/xmlreader.py +++ b/Lib/xml/sax/xmlreader.py @@ -68,7 +68,7 @@ SAX parsers are not required to provide localization for errors and warnings; if they cannot support the requested locale, - however, they must throw a SAX exception. Applications may + however, they must raise a SAX exception. Applications may request a locale change in the middle of a parse.""" raise SAXNotSupportedException("Locale support not implemented") diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -811,7 +811,7 @@ class MultiCallIterator: """Iterates over the results of a multicall. Exceptions are - thrown in response to xmlrpc faults.""" + raised in response to xmlrpc faults.""" def __init__(self, results): self.results = results diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -60,7 +60,7 @@ "At the top of the I/O hierarchy is the abstract base class IOBase. It\n" "defines the basic interface to a stream. Note, however, that there is no\n" "separation between reading and writing to streams; implementations are\n" -"allowed to throw an IOError if they do not support a given operation.\n" +"allowed to raise an IOError if they do not support a given operation.\n" "\n" "Extending IOBase is RawIOBase which deals simply with the reading and\n" "writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide\n" diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -696,7 +696,7 @@ err_string("parse tree does not use a valid start symbol"); } } - /* Make sure we throw an exception on all errors. We should never + /* Make sure we raise an exception on all errors. We should never * get this, but we'd do well to be sure something is done. */ if (st == NULL && !PyErr_Occurred()) @@ -802,7 +802,7 @@ else if (!ISNONTERMINAL(type)) { /* * It has to be one or the other; this is an error. - * Throw an exception. + * Raise an exception. */ PyObject *err = Py_BuildValue("os", elem, "unknown node type."); PyErr_SetObject(parser_error, err); @@ -854,7 +854,7 @@ if (ISTERMINAL(num)) { /* * The tuple is simple, but it doesn't start with a start symbol. - * Throw an exception now and be done with it. + * Raise an exception now and be done with it. */ tuple = Py_BuildValue("os", tuple, "Illegal syntax-tree; cannot start with terminal symbol."); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -798,7 +798,7 @@ #if defined _MSC_VER && _MSC_VER >= 1400 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is - * valid and throw an assertion if it isn't. + * valid and raise an assertion if it isn't. * Normally, an invalid fd is likely to be a C program error and therefore * an assertion can be useful, but it does contradict the POSIX standard * which for write(2) states: diff --git a/Tools/scripts/find_recursionlimit.py b/Tools/scripts/find_recursionlimit.py --- a/Tools/scripts/find_recursionlimit.py +++ b/Tools/scripts/find_recursionlimit.py @@ -92,7 +92,7 @@ def test_compiler_recursion(): # The compiler uses a scaling factor to support additional levels # of recursion. This is a sanity check of that scaling to ensure - # it still throws RuntimeError even at higher recursion limits + # it still raises RuntimeError even at higher recursion limits compile("()" * (10 * sys.getrecursionlimit()), "", "single") def check_limit(n, test_func_name): diff --git a/Tools/scripts/serve.py b/Tools/scripts/serve.py --- a/Tools/scripts/serve.py +++ b/Tools/scripts/serve.py @@ -2,7 +2,7 @@ ''' Small wsgiref based web server. Takes a path to serve from and an optional port number (defaults to 8000), then tries to serve files. -Mime types are guessed from the file names, 404 errors are thrown +Mime types are guessed from the file names, 404 errors are raised if the file is not found. Used for the make serve target in Doc. ''' import sys -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 20:28:02 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 20:28:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316714=3A_use_=27raise=27_exceptions=2C_don=27t_?= =?utf-8?b?J3Rocm93Jy4=?= Message-ID: <3YQq5G3KRSzQXC@mail.python.org> http://hg.python.org/cpython/rev/7260cf668dd7 changeset: 80930:7260cf668dd7 parent: 80927:b6ced7bd7d96 parent: 80929:15a391919deb user: Andrew Svetlov date: Tue Dec 18 21:27:16 2012 +0200 summary: Issue #16714: use 'raise' exceptions, don't 'throw'. Patch by Serhiy Storchaka. files: Doc/howto/cporting.rst | 2 +- Doc/library/contextlib.rst | 2 +- Doc/library/imaplib.rst | 2 +- Doc/library/os.rst | 8 ++-- Lib/asyncore.py | 2 +- Lib/contextlib.py | 2 +- Lib/distutils/tests/test_msvc9compiler.py | 2 +- Lib/email/feedparser.py | 4 +- Lib/email/header.py | 2 +- Lib/email/utils.py | 2 +- Lib/imaplib.py | 2 +- Lib/io.py | 2 +- Lib/logging/__init__.py | 2 +- Lib/multiprocessing/util.py | 2 +- Lib/pkgutil.py | 2 +- Lib/tempfile.py | 2 +- Lib/test/test_codeop.py | 2 +- Lib/test/test_docxmlrpc.py | 2 +- Lib/test/test_imaplib.py | 2 +- Lib/test/test_minidom.py | 2 +- Lib/test/test_os.py | 16 +++++----- Lib/test/test_posix.py | 4 +- Lib/test/test_pty.py | 2 +- Lib/test/test_sax.py | 4 +- Lib/test/test_signal.py | 4 +- Lib/test/test_socketserver.py | 2 +- Lib/test/test_sys_settrace.py | 2 +- Lib/test/test_time.py | 2 +- Lib/test/test_uu.py | 4 +- Lib/test/test_winreg.py | 4 +- Lib/test/test_zipfile.py | 2 +- Lib/tkinter/__init__.py | 2 +- Lib/unittest/case.py | 4 +- Lib/wsgiref/validate.py | 4 +- Lib/xml/sax/_exceptions.py | 6 ++-- Lib/xml/sax/xmlreader.py | 2 +- Lib/xmlrpc/client.py | 2 +- Modules/_io/_iomodule.c | 2 +- Modules/parsermodule.c | 6 ++-- Modules/posixmodule.c | 2 +- Tools/scripts/find_recursionlimit.py | 2 +- Tools/scripts/serve.py | 2 +- 42 files changed, 64 insertions(+), 64 deletions(-) diff --git a/Doc/howto/cporting.rst b/Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst +++ b/Doc/howto/cporting.rst @@ -253,7 +253,7 @@ * :c:func:`PyCapsule_GetName` always returns NULL. - * :c:func:`PyCapsule_SetName` always throws an exception and + * :c:func:`PyCapsule_SetName` always raises an exception and returns failure. (Since there's no way to store a name in a CObject, noisy failure of :c:func:`PyCapsule_SetName` was deemed preferable to silent failure here. If this is diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -184,7 +184,7 @@ files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later - # in the list throw an exception + # in the list raise an exception Each instance maintains a stack of registered callbacks that are called in reverse order when the instance is closed (either explicitly or implicitly diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst --- a/Doc/library/imaplib.rst +++ b/Doc/library/imaplib.rst @@ -75,7 +75,7 @@ :class:`ssl.SSLContext` object which allows bundling SSL configuration options, certificates and private keys into a single (potentially long-lived) structure. Note that the *keyfile*/*certfile* parameters are mutually exclusive with *ssl_context*, - a :class:`ValueError` is thrown if *keyfile*/*certfile* is provided along with *ssl_context*. + a :class:`ValueError` is raised if *keyfile*/*certfile* is provided along with *ssl_context*. .. versionchanged:: 3.3 *ssl_context* parameter added. diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1171,7 +1171,7 @@ output) specifies which file descriptor should be queried. If the file descriptor is not connected to a terminal, an :exc:`OSError` - is thrown. + is raised. :func:`shutil.get_terminal_size` is the high-level function which should normally be used, ``os.get_terminal_size`` is the low-level @@ -1945,7 +1945,7 @@ :mod:`os` module permit use of their *dir_fd* parameter. Different platforms provide different functionality, and an option that might work on one might be unsupported on another. For consistency's sakes, functions that support - *dir_fd* always allow specifying the parameter, but will throw an exception + *dir_fd* always allow specifying the parameter, but will raise an exception if the functionality is not actually available. To check whether a particular function permits use of its *dir_fd* @@ -1986,7 +1986,7 @@ descriptor. Different platforms provide different functionality, and an option that might work on one might be unsupported on another. For consistency's sakes, functions that support *fd* always allow specifying - the parameter, but will throw an exception if the functionality is not + the parameter, but will raise an exception if the functionality is not actually available. To check whether a particular function permits specifying an open file @@ -2007,7 +2007,7 @@ platforms provide different functionality, and an option that might work on one might be unsupported on another. For consistency's sakes, functions that support *follow_symlinks* always allow specifying the parameter, but will - throw an exception if the functionality is not actually available. + raise an exception if the functionality is not actually available. To check whether a particular function permits use of its *follow_symlinks* parameter, use the ``in`` operator on ``supports_follow_symlinks``. As an diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -385,7 +385,7 @@ else: return data except socket.error as why: - # winsock sometimes throws ENOTCONN + # winsock sometimes raises ENOTCONN if why.args[0] in _DISCONNECTED: self.handle_close() return b'' diff --git a/Lib/contextlib.py b/Lib/contextlib.py --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -151,7 +151,7 @@ files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later - # in the list throw an exception + # in the list raise an exception """ def __init__(self): diff --git a/Lib/distutils/tests/test_msvc9compiler.py b/Lib/distutils/tests/test_msvc9compiler.py --- a/Lib/distutils/tests/test_msvc9compiler.py +++ b/Lib/distutils/tests/test_msvc9compiler.py @@ -104,7 +104,7 @@ unittest.TestCase): def test_no_compiler(self): - # makes sure query_vcvarsall throws + # makes sure query_vcvarsall raises # a DistutilsPlatformError if the compiler # is not found from distutils.msvc9compiler import query_vcvarsall diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py --- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -13,7 +13,7 @@ data. When you have no more data to push into the parser, call .close(). This completes the parsing and returns the root message object. -The other advantage of this parser is that it will never throw a parsing +The other advantage of this parser is that it will never raise a parsing exception. Instead, when it finds something unexpected, it adds a 'defect' to the current message. Defects are just instances that live on the message object's .defects attribute. @@ -228,7 +228,7 @@ # supposed to see in the body of the message. self._parse_headers(headers) # Headers-only parsing is a backwards compatibility hack, which was - # necessary in the older parser, which could throw errors. All + # necessary in the older parser, which could raise errors. All # remaining lines in the input are thrown into the message body. if self._headersonly: lines = [] diff --git a/Lib/email/header.py b/Lib/email/header.py --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -298,7 +298,7 @@ else: s = s.decode(input_charset, errors) # Ensure that the bytes we're storing can be decoded to the output - # character set, otherwise an early error is thrown. + # character set, otherwise an early error is raised. output_charset = charset.output_codec or 'us-ascii' if output_charset != _charset.UNKNOWN8BIT: try: diff --git a/Lib/email/utils.py b/Lib/email/utils.py --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -83,7 +83,7 @@ 'utf-8'. """ name, address = pair - # The address MUST (per RFC) be ascii, so throw a UnicodeError if it isn't. + # The address MUST (per RFC) be ascii, so raise an UnicodeError if it isn't. address.encode('ascii') if name: try: diff --git a/Lib/imaplib.py b/Lib/imaplib.py --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1178,7 +1178,7 @@ ssl_context - a SSLContext object that contains your certificate chain and private key (default: None) Note: if ssl_context is provided, then parameters keyfile or - certfile should not be set otherwise ValueError is thrown. + certfile should not be set otherwise ValueError is raised. for more documentation see the docstring of the parent class IMAP4. """ diff --git a/Lib/io.py b/Lib/io.py --- a/Lib/io.py +++ b/Lib/io.py @@ -4,7 +4,7 @@ At the top of the I/O hierarchy is the abstract base class IOBase. It defines the basic interface to a stream. Note, however, that there is no separation between reading and writing to streams; implementations are -allowed to throw an IOError if they do not support a given operation. +allowed to raise an IOError if they do not support a given operation. Extending IOBase is RawIOBase which deals simply with the reading and writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1358,7 +1358,7 @@ """ sinfo = None if _srcfile: - #IronPython doesn't track Python frames, so findCaller throws an + #IronPython doesn't track Python frames, so findCaller raises an #exception on some versions of IronPython. We trap it here so that #IronPython can use logging. try: diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py +++ b/Lib/multiprocessing/util.py @@ -290,7 +290,7 @@ if current_process() is not None: # We check if the current process is None here because if - # it's None, any call to ``active_children()`` will throw + # it's None, any call to ``active_children()`` will raise # an AttributeError (active_children winds up trying to # get attributes from util._current_process). One # situation where this can happen is if someone has diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -502,7 +502,7 @@ return importlib.find_loader(fullname, path) except (ImportError, AttributeError, TypeError, ValueError) as ex: # This hack fixes an impedance mismatch between pkgutil and - # importlib, where the latter throws other errors for cases where + # importlib, where the latter raises other errors for cases where # pkgutil previously threw ImportError msg = "Error while finding loader for {!r} ({}: {})" raise ImportError(msg.format(fullname, type(ex), ex)) from ex diff --git a/Lib/tempfile.py b/Lib/tempfile.py --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -621,7 +621,7 @@ def __init__(self, suffix="", prefix=template, dir=None): self._closed = False - self.name = None # Handle mkdtemp throwing an exception + self.name = None # Handle mkdtemp raising an exception self.name = mkdtemp(suffix, prefix, dir) def __repr__(self): diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -50,7 +50,7 @@ '''succeed iff str is the start of an invalid piece of code''' try: compile_command(str,symbol=symbol) - self.fail("No exception thrown for invalid code") + self.fail("No exception raised for invalid code") except SyntaxError: self.assertTrue(is_syntax) except OverflowError: diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -100,7 +100,7 @@ self.assertEqual(response.status, 200) self.assertEqual(response.getheader("Content-type"), "text/html") - # Server throws an exception if we don't start to read the data + # Server raises an exception if we don't start to read the data response.read() def test_invalid_get_response(self): diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -115,7 +115,7 @@ return line += part except IOError: - # ..but SSLSockets throw exceptions. + # ..but SSLSockets raise exceptions. return if line.endswith(b'\r\n'): break diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -1073,7 +1073,7 @@ '' '\u20ac'.encode('utf-16')) - # Verify that character decoding errors throw exceptions instead + # Verify that character decoding errors raise exceptions instead # of crashing self.assertRaises(UnicodeDecodeError, parseString, b'Comment \xe7a va ? Tr\xe8s bien ?') diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -202,33 +202,33 @@ try: result[200] - self.fail("No exception thrown") + self.fail("No exception raised") except IndexError: pass # Make sure that assignment fails try: result.st_mode = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass try: result.st_rdev = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except (AttributeError, TypeError): pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the stat_result constructor with a too-short tuple. try: result2 = os.stat_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass @@ -273,20 +273,20 @@ # Make sure that assignment really fails try: result.f_bfree = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the constructor with a too-short tuple. try: result2 = os.statvfs_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -824,7 +824,7 @@ posix.rename(support.TESTFN + 'ren', support.TESTFN) raise else: - posix.stat(support.TESTFN) # should not throw exception + posix.stat(support.TESTFN) # should not raise exception finally: posix.close(f) @@ -842,7 +842,7 @@ def test_unlink_dir_fd(self): f = posix.open(posix.getcwd(), posix.O_RDONLY) support.create_empty_file(support.TESTFN + 'del') - posix.stat(support.TESTFN + 'del') # should not throw exception + posix.stat(support.TESTFN + 'del') # should not raise exception try: posix.unlink(support.TESTFN + 'del', dir_fd=f) except: diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -152,7 +152,7 @@ # platform-dependent amount of data is written to its fd. On # Linux 2.6, it's 4000 bytes and the child won't block, but on OS # X even the small writes in the child above will block it. Also - # on Linux, the read() will throw an OSError (input/output error) + # on Linux, the read() will raise an OSError (input/output error) # when it tries to read past the end of the buffer but the child's # already exited, so catch and discard those exceptions. It's not # worth checking for EIO. diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -389,7 +389,7 @@ def test_5027_1(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by parsing a document. @@ -415,7 +415,7 @@ def test_5027_2(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by direct manipulation of the diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -104,7 +104,7 @@ # This wait should be interrupted by the signal's exception. self.wait(child) time.sleep(1) # Give the signal time to be delivered. - self.fail('HandlerBCalled exception not thrown') + self.fail('HandlerBCalled exception not raised') except HandlerBCalled: self.assertTrue(self.b_called) self.assertFalse(self.a_called) @@ -140,7 +140,7 @@ # test-running process from all the signals. It then # communicates with that child process over a pipe and # re-raises information about any exceptions the child - # throws. The real work happens in self.run_test(). + # raises. The real work happens in self.run_test(). os_done_r, os_done_w = os.pipe() with closing(os.fdopen(os_done_r, 'rb')) as done_r, \ closing(os.fdopen(os_done_w, 'wb')) as done_w: diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -58,7 +58,7 @@ def simple_subprocess(testcase): pid = os.fork() if pid == 0: - # Don't throw an exception; it would be caught by the test harness. + # Don't raise an exception; it would be caught by the test harness. os._exit(72) yield None pid2, status = os.waitpid(pid, 0) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -422,7 +422,7 @@ except ValueError: pass else: - self.fail("exception not thrown!") + self.fail("exception not raised!") except RuntimeError: self.fail("recursion counter not reset") diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -175,7 +175,7 @@ def test_strptime(self): # Should be able to go round-trip from strftime to strptime without - # throwing an exception. + # raising an exception. tt = time.gmtime(self.t) for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', 'j', 'm', 'M', 'p', 'S', diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -80,7 +80,7 @@ out = io.BytesIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error as e: self.assertEqual(str(e), "Truncated input file") @@ -89,7 +89,7 @@ out = io.BytesIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error as e: self.assertEqual(str(e), "No valid begin line found in input file") diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -245,7 +245,7 @@ def test_changing_value(self): # Issue2810: A race condition in 2.6 and 3.1 may cause - # EnumValue or QueryValue to throw "WindowsError: More data is + # EnumValue or QueryValue to raise "WindowsError: More data is # available" done = False @@ -291,7 +291,7 @@ def test_dynamic_key(self): # Issue2810, when the value is dynamically generated, these - # throw "WindowsError: More data is available" in 2.6 and 3.1 + # raise "WindowsError: More data is available" in 2.6 and 3.1 try: EnumValue(HKEY_PERFORMANCE_DATA, 0) except OSError as e: diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -1024,7 +1024,7 @@ with zipfile.ZipFile(data, mode="w") as zipf: zipf.writestr("foo.txt", "O, for a Muse of Fire!") - # This is correct; calling .read on a closed ZipFile should throw + # This is correct; calling .read on a closed ZipFile should raise # a RuntimeError, and so should calling .testzip. An earlier # version of .testzip would swallow this exception (and any other) # and report that the first file in the archive was corrupt. diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -149,7 +149,7 @@ pass def _exit(code=0): - """Internal function. Calling it will throw the exception SystemExit.""" + """Internal function. Calling it will raise the exception SystemExit.""" try: code = int(code) except ValueError: diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -542,10 +542,10 @@ return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg)) def assertRaises(self, excClass, callableObj=None, *args, **kwargs): - """Fail unless an exception of class excClass is thrown + """Fail unless an exception of class excClass is raised by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is - thrown, it will not be caught, and the test case will be + raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception. diff --git a/Lib/wsgiref/validate.py b/Lib/wsgiref/validate.py --- a/Lib/wsgiref/validate.py +++ b/Lib/wsgiref/validate.py @@ -139,9 +139,9 @@ When applied between a WSGI server and a WSGI application, this middleware will check for WSGI compliancy on a number of levels. This middleware does not modify the request or response in any - way, but will throw an AssertionError if anything seems off + way, but will raise an AssertionError if anything seems off (except for a failure to close the application iterator, which - will be printed to stderr -- there's no way to throw an exception + will be printed to stderr -- there's no way to raise an exception at that point). """ diff --git a/Lib/xml/sax/_exceptions.py b/Lib/xml/sax/_exceptions.py --- a/Lib/xml/sax/_exceptions.py +++ b/Lib/xml/sax/_exceptions.py @@ -12,7 +12,7 @@ the application: you can subclass it to provide additional functionality, or to add localization. Note that although you will receive a SAXException as the argument to the handlers in the - ErrorHandler interface, you are not actually required to throw + ErrorHandler interface, you are not actually required to raise the exception; instead, you can simply read the information in it.""" @@ -50,7 +50,7 @@ the original XML document. Note that although the application will receive a SAXParseException as the argument to the handlers in the ErrorHandler interface, the application is not actually required - to throw the exception; instead, it can simply read the + to raise the exception; instead, it can simply read the information in it and take a different action. Since this exception is a subclass of SAXException, it inherits @@ -62,7 +62,7 @@ self._locator = locator # We need to cache this stuff at construction time. - # If this exception is thrown, the objects through which we must + # If this exception is raised, the objects through which we must # traverse to get this information may be deleted by the time # it gets caught. self._systemId = self._locator.getSystemId() diff --git a/Lib/xml/sax/xmlreader.py b/Lib/xml/sax/xmlreader.py --- a/Lib/xml/sax/xmlreader.py +++ b/Lib/xml/sax/xmlreader.py @@ -68,7 +68,7 @@ SAX parsers are not required to provide localization for errors and warnings; if they cannot support the requested locale, - however, they must throw a SAX exception. Applications may + however, they must raise a SAX exception. Applications may request a locale change in the middle of a parse.""" raise SAXNotSupportedException("Locale support not implemented") diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -811,7 +811,7 @@ class MultiCallIterator: """Iterates over the results of a multicall. Exceptions are - thrown in response to xmlrpc faults.""" + raised in response to xmlrpc faults.""" def __init__(self, results): self.results = results diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -60,7 +60,7 @@ "At the top of the I/O hierarchy is the abstract base class IOBase. It\n" "defines the basic interface to a stream. Note, however, that there is no\n" "separation between reading and writing to streams; implementations are\n" -"allowed to throw an IOError if they do not support a given operation.\n" +"allowed to raise an IOError if they do not support a given operation.\n" "\n" "Extending IOBase is RawIOBase which deals simply with the reading and\n" "writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide\n" diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -696,7 +696,7 @@ err_string("parse tree does not use a valid start symbol"); } } - /* Make sure we throw an exception on all errors. We should never + /* Make sure we raise an exception on all errors. We should never * get this, but we'd do well to be sure something is done. */ if (st == NULL && !PyErr_Occurred()) @@ -802,7 +802,7 @@ else if (!ISNONTERMINAL(type)) { /* * It has to be one or the other; this is an error. - * Throw an exception. + * Raise an exception. */ PyObject *err = Py_BuildValue("os", elem, "unknown node type."); PyErr_SetObject(parser_error, err); @@ -854,7 +854,7 @@ if (ISTERMINAL(num)) { /* * The tuple is simple, but it doesn't start with a start symbol. - * Throw an exception now and be done with it. + * Raise an exception now and be done with it. */ tuple = Py_BuildValue("os", tuple, "Illegal syntax-tree; cannot start with terminal symbol."); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -767,7 +767,7 @@ #if defined _MSC_VER && _MSC_VER >= 1400 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is - * valid and throw an assertion if it isn't. + * valid and raise an assertion if it isn't. * Normally, an invalid fd is likely to be a C program error and therefore * an assertion can be useful, but it does contradict the POSIX standard * which for write(2) states: diff --git a/Tools/scripts/find_recursionlimit.py b/Tools/scripts/find_recursionlimit.py --- a/Tools/scripts/find_recursionlimit.py +++ b/Tools/scripts/find_recursionlimit.py @@ -92,7 +92,7 @@ def test_compiler_recursion(): # The compiler uses a scaling factor to support additional levels # of recursion. This is a sanity check of that scaling to ensure - # it still throws RuntimeError even at higher recursion limits + # it still raises RuntimeError even at higher recursion limits compile("()" * (10 * sys.getrecursionlimit()), "", "single") def check_limit(n, test_func_name): diff --git a/Tools/scripts/serve.py b/Tools/scripts/serve.py --- a/Tools/scripts/serve.py +++ b/Tools/scripts/serve.py @@ -2,7 +2,7 @@ ''' Small wsgiref based web server. Takes a path to serve from and an optional port number (defaults to 8000), then tries to serve files. -Mime types are guessed from the file names, 404 errors are thrown +Mime types are guessed from the file names, 404 errors are raised if the file is not found. Used for the make serve target in Doc. ''' import sys -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 20:28:04 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 20:28:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NzE0?= =?utf-8?q?=3A_use_=27raise=27_exceptions=2C_don=27t_=27throw=27=2E?= Message-ID: <3YQq5J21HJzNwY@mail.python.org> http://hg.python.org/cpython/rev/8c2635afbfe1 changeset: 80931:8c2635afbfe1 branch: 2.7 parent: 80914:fd57dbfa5765 user: Andrew Svetlov date: Tue Dec 18 21:27:37 2012 +0200 summary: Issue #16714: use 'raise' exceptions, don't 'throw'. Patch by Serhiy Storchaka. files: Doc/howto/cporting.rst | 2 +- Lib/asyncore.py | 2 +- Lib/distutils/tests/test_msvc9compiler.py | 2 +- Lib/email/feedparser.py | 4 +- Lib/email/header.py | 2 +- Lib/httplib.py | 2 +- Lib/io.py | 2 +- Lib/lib-tk/Tkinter.py | 2 +- Lib/logging/__init__.py | 2 +- Lib/runpy.py | 2 +- Lib/test/test_codeop.py | 2 +- Lib/test/test_docxmlrpc.py | 2 +- Lib/test/test_imaplib.py | 2 +- Lib/test/test_minidom.py | 2 +- Lib/test/test_os.py | 16 +++++----- Lib/test/test_pty.py | 2 +- Lib/test/test_sax.py | 4 +- Lib/test/test_signal.py | 4 +- Lib/test/test_socketserver.py | 2 +- Lib/test/test_sys_settrace.py | 2 +- Lib/test/test_time.py | 2 +- Lib/test/test_uu.py | 4 +- Lib/test/test_winreg.py | 4 +- Lib/test/test_zipfile.py | 2 +- Lib/traceback.py | 2 +- Lib/unittest/case.py | 4 +- Lib/wsgiref/validate.py | 4 +- Lib/xml/sax/_exceptions.py | 6 ++-- Lib/xml/sax/xmlreader.py | 2 +- Lib/xmlrpclib.py | 2 +- Modules/_io/_iomodule.c | 2 +- Modules/parsermodule.c | 6 ++-- Modules/posixmodule.c | 2 +- Tools/scripts/serve.py | 2 +- 34 files changed, 52 insertions(+), 52 deletions(-) diff --git a/Doc/howto/cporting.rst b/Doc/howto/cporting.rst --- a/Doc/howto/cporting.rst +++ b/Doc/howto/cporting.rst @@ -253,7 +253,7 @@ * :c:func:`PyCapsule_GetName` always returns NULL. - * :c:func:`PyCapsule_SetName` always throws an exception and + * :c:func:`PyCapsule_SetName` always raises an exception and returns failure. (Since there's no way to store a name in a CObject, noisy failure of :c:func:`PyCapsule_SetName` was deemed preferable to silent failure here. If this is diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -393,7 +393,7 @@ else: return data except socket.error, why: - # winsock sometimes throws ENOTCONN + # winsock sometimes raises ENOTCONN if why.args[0] in _DISCONNECTED: self.handle_close() return '' diff --git a/Lib/distutils/tests/test_msvc9compiler.py b/Lib/distutils/tests/test_msvc9compiler.py --- a/Lib/distutils/tests/test_msvc9compiler.py +++ b/Lib/distutils/tests/test_msvc9compiler.py @@ -104,7 +104,7 @@ unittest.TestCase): def test_no_compiler(self): - # makes sure query_vcvarsall throws + # makes sure query_vcvarsall raises # a DistutilsPlatformError if the compiler # is not found from distutils.msvc9compiler import query_vcvarsall diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py --- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -13,7 +13,7 @@ data. When you have no more data to push into the parser, call .close(). This completes the parsing and returns the root message object. -The other advantage of this parser is that it will never throw a parsing +The other advantage of this parser is that it will never raise a parsing exception. Instead, when it finds something unexpected, it adds a 'defect' to the current message. Defects are just instances that live on the message object's .defects attribute. @@ -214,7 +214,7 @@ # supposed to see in the body of the message. self._parse_headers(headers) # Headers-only parsing is a backwards compatibility hack, which was - # necessary in the older parser, which could throw errors. All + # necessary in the older parser, which could raise errors. All # remaining lines in the input are thrown into the message body. if self._headersonly: lines = [] diff --git a/Lib/email/header.py b/Lib/email/header.py --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -103,7 +103,7 @@ dec = email.base64mime.decode(encoded) except binascii.Error: # Turn this into a higher level exception. BAW: Right - # now we throw the lower level exception away but + # now we raise the lower level exception away but # when/if we get exception chaining, we'll preserve it. raise HeaderParseError if dec is None: diff --git a/Lib/httplib.py b/Lib/httplib.py --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -1068,7 +1068,7 @@ if port == 0: port = None - # Note that we may pass an empty string as the host; this will throw + # Note that we may pass an empty string as the host; this will raise # an error when we attempt to connect. Presumably, the client code # will call connect before then, with a proper host. self._setup(self._connection_class(host, port, strict)) diff --git a/Lib/io.py b/Lib/io.py --- a/Lib/io.py +++ b/Lib/io.py @@ -4,7 +4,7 @@ At the top of the I/O hierarchy is the abstract base class IOBase. It defines the basic interface to a stream. Note, however, that there is no separation between reading and writing to streams; implementations are -allowed to throw an IOError if they do not support a given operation. +allowed to raise an IOError if they do not support a given operation. Extending IOBase is RawIOBase which deals simply with the reading and writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -155,7 +155,7 @@ pass def _exit(code=0): - """Internal function. Calling it will throw the exception SystemExit.""" + """Internal function. Calling it will raise the exception SystemExit.""" try: code = int(code) except ValueError: diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1251,7 +1251,7 @@ all the handlers of this logger to handle the record. """ if _srcfile: - #IronPython doesn't track Python frames, so findCaller throws an + #IronPython doesn't track Python frames, so findCaller raises an #exception on some versions of IronPython. We trap it here so that #IronPython can use logging. try: diff --git a/Lib/runpy.py b/Lib/runpy.py --- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -200,7 +200,7 @@ pass else: # The following check looks a bit odd. The trick is that - # NullImporter throws ImportError if the supplied path is a + # NullImporter raises ImportError if the supplied path is a # *valid* directory entry (and hence able to be handled # by the standard import machinery) try: diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -50,7 +50,7 @@ '''succeed iff str is the start of an invalid piece of code''' try: compile_command(str,symbol=symbol) - self.fail("No exception thrown for invalid code") + self.fail("No exception raised for invalid code") except SyntaxError: self.assertTrue(is_syntax) except OverflowError: diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -100,7 +100,7 @@ self.assertEqual(response.status, 200) self.assertEqual(response.getheader("Content-type"), "text/html") - # Server throws an exception if we don't start to read the data + # Server raises an exception if we don't start to read the data response.read() def test_invalid_get_response(self): diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -79,7 +79,7 @@ return line += part except IOError: - # ..but SSLSockets throw exceptions. + # ..but SSLSockets raise exceptions. return if line.endswith('\r\n'): break diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -1060,7 +1060,7 @@ '\xa4', "testEncodings - encoding EURO SIGN") - # Verify that character decoding errors throw exceptions instead + # Verify that character decoding errors raise exceptions instead # of crashing self.assertRaises(UnicodeDecodeError, parseString, 'Comment \xe7a va ? Tr\xe8s bien ?') diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -214,33 +214,33 @@ try: result[200] - self.fail("No exception thrown") + self.fail("No exception raised") except IndexError: pass # Make sure that assignment fails try: result.st_mode = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except (AttributeError, TypeError): pass try: result.st_rdev = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except (AttributeError, TypeError): pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the stat_result constructor with a too-short tuple. try: result2 = os.stat_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass @@ -274,20 +274,20 @@ # Make sure that assignment really fails try: result.f_bfree = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass try: result.parrot = 1 - self.fail("No exception thrown") + self.fail("No exception raised") except AttributeError: pass # Use the constructor with a too-short tuple. try: result2 = os.statvfs_result((10,)) - self.fail("No exception thrown") + self.fail("No exception raised") except TypeError: pass diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -152,7 +152,7 @@ # platform-dependent amount of data is written to its fd. On # Linux 2.6, it's 4000 bytes and the child won't block, but on OS # X even the small writes in the child above will block it. Also - # on Linux, the read() will throw an OSError (input/output error) + # on Linux, the read() will raise an OSError (input/output error) # when it tries to read past the end of the buffer but the child's # already exited, so catch and discard those exceptions. It's not # worth checking for EIO. diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -294,7 +294,7 @@ def test_5027_1(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by parsing a document. @@ -320,7 +320,7 @@ def test_5027_2(self): # The xml prefix (as in xml:lang below) is reserved and bound by # definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had - # a bug whereby a KeyError is thrown because this namespace is missing + # a bug whereby a KeyError is raised because this namespace is missing # from a dictionary. # # This test demonstrates the bug by direct manipulation of the diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -109,7 +109,7 @@ # This wait should be interrupted by the signal's exception. self.wait(child) time.sleep(1) # Give the signal time to be delivered. - self.fail('HandlerBCalled exception not thrown') + self.fail('HandlerBCalled exception not raised') except HandlerBCalled: self.assertTrue(self.b_called) self.assertFalse(self.a_called) @@ -148,7 +148,7 @@ # test-running process from all the signals. It then # communicates with that child process over a pipe and # re-raises information about any exceptions the child - # throws. The real work happens in self.run_test(). + # raises. The real work happens in self.run_test(). os_done_r, os_done_w = os.pipe() with closing(os.fdopen(os_done_r)) as done_r, \ closing(os.fdopen(os_done_w, 'w')) as done_w: diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -58,7 +58,7 @@ def simple_subprocess(testcase): pid = os.fork() if pid == 0: - # Don't throw an exception; it would be caught by the test harness. + # Don't raise an exception; it would be caught by the test harness. os._exit(72) yield None pid2, status = os.waitpid(pid, 0) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -417,7 +417,7 @@ except ValueError: pass else: - self.fail("exception not thrown!") + self.fail("exception not raised!") except RuntimeError: self.fail("recursion counter not reset") diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -106,7 +106,7 @@ def test_strptime(self): # Should be able to go round-trip from strftime to strptime without - # throwing an exception. + # raising an exception. tt = time.gmtime(self.t) for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', 'j', 'm', 'M', 'p', 'S', diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -48,7 +48,7 @@ out = cStringIO.StringIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error, e: self.assertEqual(str(e), "Truncated input file") @@ -57,7 +57,7 @@ out = cStringIO.StringIO() try: uu.decode(inp, out) - self.fail("No exception thrown") + self.fail("No exception raised") except uu.Error, e: self.assertEqual(str(e), "No valid begin line found in input file") diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -234,7 +234,7 @@ def test_changing_value(self): # Issue2810: A race condition in 2.6 and 3.1 may cause - # EnumValue or QueryValue to throw "WindowsError: More data is + # EnumValue or QueryValue to raise "WindowsError: More data is # available" done = False @@ -282,7 +282,7 @@ def test_dynamic_key(self): # Issue2810, when the value is dynamically generated, these - # throw "WindowsError: More data is available" in 2.6 and 3.1 + # raise "WindowsError: More data is available" in 2.6 and 3.1 try: EnumValue(HKEY_PERFORMANCE_DATA, 0) except OSError as e: diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -811,7 +811,7 @@ with zipfile.ZipFile(data, mode="w") as zipf: zipf.writestr("foo.txt", "O, for a Muse of Fire!") - # This is correct; calling .read on a closed ZipFile should throw + # This is correct; calling .read on a closed ZipFile should raise # a RuntimeError, and so should calling .testzip. An earlier # version of .testzip would swallow this exception (and any other) # and report that the first file in the archive was corrupt. diff --git a/Lib/traceback.py b/Lib/traceback.py --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -166,7 +166,7 @@ # >>> raise string1, string2 # deprecated # # Clear these out first because issubtype(string1, SyntaxError) - # would throw another exception and mask the original problem. + # would raise another exception and mask the original problem. if (isinstance(etype, BaseException) or isinstance(etype, types.InstanceType) or etype is None or type(etype) is str): diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -447,10 +447,10 @@ def assertRaises(self, excClass, callableObj=None, *args, **kwargs): - """Fail unless an exception of class excClass is thrown + """Fail unless an exception of class excClass is raised by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is - thrown, it will not be caught, and the test case will be + raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception. diff --git a/Lib/wsgiref/validate.py b/Lib/wsgiref/validate.py --- a/Lib/wsgiref/validate.py +++ b/Lib/wsgiref/validate.py @@ -134,9 +134,9 @@ When applied between a WSGI server and a WSGI application, this middleware will check for WSGI compliancy on a number of levels. This middleware does not modify the request or response in any - way, but will throw an AssertionError if anything seems off + way, but will raise an AssertionError if anything seems off (except for a failure to close the application iterator, which - will be printed to stderr -- there's no way to throw an exception + will be printed to stderr -- there's no way to raise an exception at that point). """ diff --git a/Lib/xml/sax/_exceptions.py b/Lib/xml/sax/_exceptions.py --- a/Lib/xml/sax/_exceptions.py +++ b/Lib/xml/sax/_exceptions.py @@ -12,7 +12,7 @@ the application: you can subclass it to provide additional functionality, or to add localization. Note that although you will receive a SAXException as the argument to the handlers in the - ErrorHandler interface, you are not actually required to throw + ErrorHandler interface, you are not actually required to raise the exception; instead, you can simply read the information in it.""" @@ -50,7 +50,7 @@ the original XML document. Note that although the application will receive a SAXParseException as the argument to the handlers in the ErrorHandler interface, the application is not actually required - to throw the exception; instead, it can simply read the + to raise the exception; instead, it can simply read the information in it and take a different action. Since this exception is a subclass of SAXException, it inherits @@ -62,7 +62,7 @@ self._locator = locator # We need to cache this stuff at construction time. - # If this exception is thrown, the objects through which we must + # If this exception is raised, the objects through which we must # traverse to get this information may be deleted by the time # it gets caught. self._systemId = self._locator.getSystemId() diff --git a/Lib/xml/sax/xmlreader.py b/Lib/xml/sax/xmlreader.py --- a/Lib/xml/sax/xmlreader.py +++ b/Lib/xml/sax/xmlreader.py @@ -68,7 +68,7 @@ SAX parsers are not required to provide localization for errors and warnings; if they cannot support the requested locale, - however, they must throw a SAX exception. Applications may + however, they must raise a SAX exception. Applications may request a locale change in the middle of a parse.""" raise SAXNotSupportedException("Locale support not implemented") diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py --- a/Lib/xmlrpclib.py +++ b/Lib/xmlrpclib.py @@ -945,7 +945,7 @@ class MultiCallIterator: """Iterates over the results of a multicall. Exceptions are - thrown in response to xmlrpc faults.""" + raised in response to xmlrpc faults.""" def __init__(self, results): self.results = results diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -59,7 +59,7 @@ "At the top of the I/O hierarchy is the abstract base class IOBase. It\n" "defines the basic interface to a stream. Note, however, that there is no\n" "separation between reading and writing to streams; implementations are\n" -"allowed to throw an IOError if they do not support a given operation.\n" +"allowed to raise an IOError if they do not support a given operation.\n" "\n" "Extending IOBase is RawIOBase which deals simply with the reading and\n" "writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide\n" diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -698,7 +698,7 @@ err_string("parse tree does not use a valid start symbol"); } } - /* Make sure we throw an exception on all errors. We should never + /* Make sure we raise an exception on all errors. We should never * get this, but we'd do well to be sure something is done. */ if (st == NULL && !PyErr_Occurred()) @@ -813,7 +813,7 @@ else if (!ISNONTERMINAL(type)) { /* * It has to be one or the other; this is an error. - * Throw an exception. + * Raise an exception. */ PyObject *err = Py_BuildValue("os", elem, "unknown node type."); PyErr_SetObject(parser_error, err); @@ -863,7 +863,7 @@ if (ISTERMINAL(num)) { /* * The tuple is simple, but it doesn't start with a start symbol. - * Throw an exception now and be done with it. + * Raise an exception now and be done with it. */ tuple = Py_BuildValue("os", tuple, "Illegal syntax-tree; cannot start with terminal symbol."); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -349,7 +349,7 @@ #if defined _MSC_VER && _MSC_VER >= 1400 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is - * valid and throw an assertion if it isn't. + * valid and raise an assertion if it isn't. * Normally, an invalid fd is likely to be a C program error and therefore * an assertion can be useful, but it does contradict the POSIX standard * which for write(2) states: diff --git a/Tools/scripts/serve.py b/Tools/scripts/serve.py --- a/Tools/scripts/serve.py +++ b/Tools/scripts/serve.py @@ -2,7 +2,7 @@ ''' Small wsgiref based web server. Takes a path to serve from and an optional port number (defaults to 8000), then tries to serve files. -Mime types are guessed from the file names, 404 errors are thrown +Mime types are guessed from the file names, 404 errors are raised if the file is not found. Used for the make serve target in Doc. ''' import sys -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 21:02:54 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 21:02:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316706=3A_get_rid_?= =?utf-8?q?of_os=2Eerror?= Message-ID: <3YQqsV1wYPzPHy@mail.python.org> http://hg.python.org/cpython/rev/47f98a550d42 changeset: 80932:47f98a550d42 parent: 80930:7260cf668dd7 user: Andrew Svetlov date: Tue Dec 18 22:02:39 2012 +0200 summary: Issue #16706: get rid of os.error files: Lib/_pyio.py | 2 +- Lib/cgi.py | 2 +- Lib/compileall.py | 2 +- Lib/dbm/dumb.py | 4 +- Lib/distutils/core.py | 2 +- Lib/distutils/dir_util.py | 2 +- Lib/distutils/file_util.py | 16 +- Lib/fileinput.py | 6 +- Lib/genericpath.py | 6 +- Lib/glob.py | 2 +- Lib/http/server.py | 4 +- Lib/lib2to3/main.py | 4 +- Lib/lib2to3/refactor.py | 4 +- Lib/lib2to3/tests/pytree_idempotency.py | 2 +- Lib/linecache.py | 4 +- Lib/macpath.py | 2 +- Lib/modulefinder.py | 2 +- Lib/multiprocessing/forking.py | 2 +- Lib/ntpath.py | 4 +- Lib/os.py | 2 +- Lib/platform.py | 10 +- Lib/posixpath.py | 6 +- Lib/pty.py | 6 +- Lib/shutil.py | 10 +- Lib/site.py | 2 +- Lib/socketserver.py | 4 +- Lib/subprocess.py | 4 +- Lib/tempfile.py | 7 +- Lib/test/sortperf.py | 2 +- Lib/test/test_socketserver.py | 2 +- Lib/test/test_tempfile.py | 4 +- Lib/test/tf_inherit_check.py | 2 +- Python/importlib.h | 8057 +++++----- 33 files changed, 4078 insertions(+), 4112 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -200,7 +200,7 @@ buffering = DEFAULT_BUFFER_SIZE try: bs = os.fstat(raw.fileno()).st_blksize - except (os.error, AttributeError): + except (OSError, AttributeError): pass else: if bs > 1: diff --git a/Lib/cgi.py b/Lib/cgi.py --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -949,7 +949,7 @@ print("

Current Working Directory:

") try: pwd = os.getcwd() - except os.error as msg: + except OSError as msg: print("os.error:", html.escape(str(msg))) else: print(html.escape(pwd)) diff --git a/Lib/compileall.py b/Lib/compileall.py --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -38,7 +38,7 @@ print('Listing {!r}...'.format(dir)) try: names = os.listdir(dir) - except os.error: + except OSError: print("Can't list {!r}".format(dir)) names = [] names.sort() diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py --- a/Lib/dbm/dumb.py +++ b/Lib/dbm/dumb.py @@ -100,12 +100,12 @@ try: self._os.unlink(self._bakfile) - except self._os.error: + except OSError: pass try: self._os.rename(self._dirfile, self._bakfile) - except self._os.error: + except OSError: pass f = self._io.open(self._dirfile, 'w', encoding="Latin-1") diff --git a/Lib/distutils/core.py b/Lib/distutils/core.py --- a/Lib/distutils/core.py +++ b/Lib/distutils/core.py @@ -148,7 +148,7 @@ dist.run_commands() except KeyboardInterrupt: raise SystemExit("interrupted") - except (IOError, os.error) as exc: + except (IOError, OSError) as exc: error = grok_environment_error(exc) if DEBUG: diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -124,7 +124,7 @@ "cannot copy tree '%s': not a directory" % src) try: names = os.listdir(src) - except os.error as e: + except OSError as e: (errno, errstr) = e if dry_run: names = [] diff --git a/Lib/distutils/file_util.py b/Lib/distutils/file_util.py --- a/Lib/distutils/file_util.py +++ b/Lib/distutils/file_util.py @@ -27,26 +27,26 @@ try: try: fsrc = open(src, 'rb') - except os.error as e: + except OSError as e: raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror)) if os.path.exists(dst): try: os.unlink(dst) - except os.error as e: + except OSError as e: raise DistutilsFileError( "could not delete '%s': %s" % (dst, e.strerror)) try: fdst = open(dst, 'wb') - except os.error as e: + except OSError as e: raise DistutilsFileError( "could not create '%s': %s" % (dst, e.strerror)) while True: try: buf = fsrc.read(buffer_size) - except os.error as e: + except OSError as e: raise DistutilsFileError( "could not read from '%s': %s" % (src, e.strerror)) @@ -55,7 +55,7 @@ try: fdst.write(buf) - except os.error as e: + except OSError as e: raise DistutilsFileError( "could not write to '%s': %s" % (dst, e.strerror)) finally: @@ -193,7 +193,7 @@ copy_it = False try: os.rename(src, dst) - except os.error as e: + except OSError as e: (num, msg) = e if num == errno.EXDEV: copy_it = True @@ -205,11 +205,11 @@ copy_file(src, dst, verbose=verbose) try: os.unlink(src) - except os.error as e: + except OSError as e: (num, msg) = e try: os.unlink(dst) - except os.error: + except OSError: pass raise DistutilsFileError( "couldn't move '%s' to '%s' by copy/delete: " diff --git a/Lib/fileinput.py b/Lib/fileinput.py --- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -324,8 +324,10 @@ if self._inplace: self._backupfilename = ( self._filename + (self._backup or ".bak")) - try: os.unlink(self._backupfilename) - except os.error: pass + try: + os.unlink(self._backupfilename) + except OSError: + pass # The next few lines may raise IOError os.rename(self._filename, self._backupfilename) self._file = open(self._backupfilename, self._mode) diff --git a/Lib/genericpath.py b/Lib/genericpath.py --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -16,7 +16,7 @@ """Test whether a path exists. Returns False for broken symbolic links""" try: os.stat(path) - except os.error: + except OSError: return False return True @@ -27,7 +27,7 @@ """Test whether a path is a regular file""" try: st = os.stat(path) - except os.error: + except OSError: return False return stat.S_ISREG(st.st_mode) @@ -39,7 +39,7 @@ """Return true if the pathname refers to an existing directory.""" try: st = os.stat(s) - except os.error: + except OSError: return False return stat.S_ISDIR(st.st_mode) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -55,7 +55,7 @@ dirname = os.curdir try: names = os.listdir(dirname) - except os.error: + except OSError: return [] if pattern[0] != '.': names = [x for x in names if x[0] != '.'] diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -732,7 +732,7 @@ """ try: list = os.listdir(path) - except os.error: + except OSError: self.send_error(404, "No permission to list directory") return None list.sort(key=lambda a: a.lower()) @@ -1123,7 +1123,7 @@ try: try: os.setuid(nobody) - except os.error: + except OSError: pass os.dup2(self.rfile.fileno(), 0) os.dup2(self.wfile.fileno(), 1) diff --git a/Lib/lib2to3/main.py b/Lib/lib2to3/main.py --- a/Lib/lib2to3/main.py +++ b/Lib/lib2to3/main.py @@ -90,11 +90,11 @@ if os.path.lexists(backup): try: os.remove(backup) - except os.error as err: + except OSError as err: self.log_message("Can't remove backup %s", backup) try: os.rename(filename, backup) - except os.error as err: + except OSError as err: self.log_message("Can't rename %s to %s", filename, backup) # Actually write the new file write = super(StdoutRefactoringTool, self).write_file diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -534,12 +534,12 @@ """ try: f = _open_with_encoding(filename, "w", encoding=encoding) - except os.error as err: + except OSError as err: self.log_error("Can't create %s: %s", filename, err) return try: f.write(_to_system_newlines(new_text)) - except os.error as err: + except OSError as err: self.log_error("Can't write %s: %s", filename, err) finally: f.close() diff --git a/Lib/lib2to3/tests/pytree_idempotency.py b/Lib/lib2to3/tests/pytree_idempotency.py --- a/Lib/lib2to3/tests/pytree_idempotency.py +++ b/Lib/lib2to3/tests/pytree_idempotency.py @@ -53,7 +53,7 @@ for dir in sys.path: try: names = os.listdir(dir) - except os.error: + except OSError: continue print("Scanning", dir, "...", file=sys.stderr) for name in names: diff --git a/Lib/linecache.py b/Lib/linecache.py --- a/Lib/linecache.py +++ b/Lib/linecache.py @@ -59,7 +59,7 @@ continue # no-op for files loaded via a __loader__ try: stat = os.stat(fullname) - except os.error: + except OSError: del cache[filename] continue if size != stat.st_size or mtime != stat.st_mtime: @@ -118,7 +118,7 @@ try: stat = os.stat(fullname) break - except os.error: + except OSError: pass else: return [] diff --git a/Lib/macpath.py b/Lib/macpath.py --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -127,7 +127,7 @@ try: st = os.lstat(path) - except os.error: + except OSError: return False return True diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py --- a/Lib/modulefinder.py +++ b/Lib/modulefinder.py @@ -228,7 +228,7 @@ for dir in m.__path__: try: names = os.listdir(dir) - except os.error: + except OSError: self.msg(2, "can't list directory", dir) continue for name in names: diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py +++ b/Lib/multiprocessing/forking.py @@ -111,7 +111,7 @@ if self.returncode is None: try: pid, sts = os.waitpid(self.pid, flag) - except os.error: + except OSError: # Child process not yet created. See #1731717 # e.errno == errno.ECHILD == 10 return None diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -321,7 +321,7 @@ """ try: st = os.lstat(path) - except (os.error, AttributeError): + except (OSError, AttributeError): return False return stat.S_ISLNK(st.st_mode) @@ -331,7 +331,7 @@ """Test whether a path exists. Returns True for broken symbolic links""" try: st = os.lstat(path) - except (os.error, WindowsError): + except (OSError, WindowsError): return False return True diff --git a/Lib/os.py b/Lib/os.py --- a/Lib/os.py +++ b/Lib/os.py @@ -338,7 +338,7 @@ By default errors from the os.listdir() call are ignored. If optional arg 'onerror' is specified, it should be a function; it - will be called with one argument, an os.error instance. It can + will be called with one argument, an OSError instance. It can report the error to continue with the walk, or raise the exception to abort the walk. Note that the filename is available as the filename attribute of the exception object. diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -316,7 +316,7 @@ """ try: etc = os.listdir('/etc') - except os.error: + except OSError: # Probably not a Unix system return distname,version,id etc.sort() @@ -424,10 +424,10 @@ pipe = popen(cmd) info = pipe.read() if pipe.close(): - raise os.error('command failed') + raise OSError('command failed') # XXX How can I suppress shell errors from being written # to stderr ? - except os.error as why: + except OSError as why: #print 'Command %s failed: %s' % (cmd,why) continue except IOError as why: @@ -906,7 +906,7 @@ return default try: f = os.popen('uname %s 2> %s' % (option, DEV_NULL)) - except (AttributeError,os.error): + except (AttributeError, OSError): return default output = f.read().strip() rc = f.close() @@ -932,7 +932,7 @@ proc = subprocess.Popen(['file', target], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - except (AttributeError,os.error): + except (AttributeError, OSError): return default output = proc.communicate()[0].decode('latin-1') rc = proc.wait() diff --git a/Lib/posixpath.py b/Lib/posixpath.py --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -162,7 +162,7 @@ """Test whether a path is a symbolic link""" try: st = os.lstat(path) - except (os.error, AttributeError): + except (OSError, AttributeError): return False return stat.S_ISLNK(st.st_mode) @@ -172,7 +172,7 @@ """Test whether a path exists. Returns True for broken symbolic links""" try: os.lstat(path) - except os.error: + except OSError: return False return True @@ -220,7 +220,7 @@ else: parent = join(path, '..') s2 = os.lstat(parent) - except os.error: + except OSError: return False # It doesn't exist -- so not a mount point :-) dev1 = s1.st_dev dev2 = s2.st_dev diff --git a/Lib/pty.py b/Lib/pty.py --- a/Lib/pty.py +++ b/Lib/pty.py @@ -57,17 +57,17 @@ try: tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0) except IOError as msg: - raise os.error(msg) + raise OSError(msg) return master_fd, tty_name for x in 'pqrstuvwxyzPQRST': for y in '0123456789abcdef': pty_name = '/dev/pty' + x + y try: fd = os.open(pty_name, os.O_RDWR) - except os.error: + except OSError: continue return (fd, '/dev/tty' + x + y) - raise os.error('out of pty devices') + raise OSError('out of pty devices') def slave_open(tty_name): """slave_open(tty_name) -> slave_fd diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -356,24 +356,24 @@ names = [] try: names = os.listdir(path) - except os.error: + except OSError: onerror(os.listdir, path, sys.exc_info()) for name in names: fullname = os.path.join(path, name) try: mode = os.lstat(fullname).st_mode - except os.error: + except OSError: mode = 0 if stat.S_ISDIR(mode): _rmtree_unsafe(fullname, onerror) else: try: os.unlink(fullname) - except os.error: + except OSError: onerror(os.unlink, fullname, sys.exc_info()) try: os.rmdir(path) - except os.error: + except OSError: onerror(os.rmdir, path, sys.exc_info()) # Version using fd-based APIs to protect against races @@ -464,7 +464,7 @@ _rmtree_safe_fd(fd, path, onerror) try: os.rmdir(path) - except os.error: + except OSError: onerror(os.rmdir, path, sys.exc_info()) else: try: diff --git a/Lib/site.py b/Lib/site.py --- a/Lib/site.py +++ b/Lib/site.py @@ -196,7 +196,7 @@ known_paths.add(sitedircase) try: names = os.listdir(sitedir) - except os.error: + except OSError: return names = [name for name in names if name.endswith(".pth")] for name in sorted(names): diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -532,7 +532,7 @@ # children. try: pid, status = os.waitpid(0, 0) - except os.error: + except OSError: pid = None if pid not in self.active_children: continue self.active_children.remove(pid) @@ -545,7 +545,7 @@ for child in self.active_children: try: pid, status = os.waitpid(child, os.WNOHANG) - except os.error: + except OSError: pid = None if not pid: continue try: diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1444,7 +1444,7 @@ def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid, - _WNOHANG=os.WNOHANG, _os_error=os.error): + _WNOHANG=os.WNOHANG): """Check if child process has terminated. Returns returncode attribute. @@ -1457,7 +1457,7 @@ pid, sts = _waitpid(self.pid, _WNOHANG) if pid == self.pid: self._handle_exitstatus(sts) - except _os_error as e: + except OSError as e: if _deadstate is not None: self.returncode = _deadstate elif e.errno == errno.ECHILD: diff --git a/Lib/tempfile.py b/Lib/tempfile.py --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -665,7 +665,6 @@ _islink = staticmethod(_os.path.islink) _remove = staticmethod(_os.remove) _rmdir = staticmethod(_os.rmdir) - _os_error = OSError _warn = _warnings.warn def _rmtree(self, path): @@ -675,16 +674,16 @@ fullname = self._path_join(path, name) try: isdir = self._isdir(fullname) and not self._islink(fullname) - except self._os_error: + except OSError: isdir = False if isdir: self._rmtree(fullname) else: try: self._remove(fullname) - except self._os_error: + except OSError: pass try: self._rmdir(path) - except self._os_error: + except OSError: pass diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py --- a/Lib/test/sortperf.py +++ b/Lib/test/sortperf.py @@ -35,7 +35,7 @@ if fp: try: os.unlink(fn) - except os.error: + except OSError: pass except IOError as msg: print("can't write", fn, ":", msg) diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -82,7 +82,7 @@ for fn in self.test_files: try: os.remove(fn) - except os.error: + except OSError: pass self.test_files[:] = [] diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -188,7 +188,7 @@ try: dirname = os.getcwd() - except (AttributeError, os.error): + except (AttributeError, OSError): dirname = os.curdir self.assertIn(dirname, cand) @@ -924,7 +924,7 @@ # (noted as part of Issue #10188) with tempfile.TemporaryDirectory() as nonexistent: pass - with self.assertRaises(os.error): + with self.assertRaises(OSError): tempfile.TemporaryDirectory(dir=nonexistent) def test_explicit_cleanup(self): diff --git a/Lib/test/tf_inherit_check.py b/Lib/test/tf_inherit_check.py --- a/Lib/test/tf_inherit_check.py +++ b/Lib/test/tf_inherit_check.py @@ -11,7 +11,7 @@ try: os.write(fd, b"blat") - except os.error: + except OSError: # Success -- could not write to fd. sys.exit(0) else: diff --git a/Python/importlib.h b/Python/importlib.h --- a/Python/importlib.h +++ b/Python/importlib.h [stripped] -- Repository URL: http://hg.python.org/cpython From tjreedy at udel.edu Tue Dec 18 21:55:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 18 Dec 2012 15:55:41 -0500 Subject: [Python-checkins] peps: Add Thunk to the alternatives for DelayedCall. In-Reply-To: <3YQpkF2RW1zNhB@mail.python.org> References: <3YQpkF2RW1zNhB@mail.python.org> Message-ID: <50D0D84D.80705@udel.edu> On 12/18/2012 2:11 PM, guido.van.rossum wrote: > Add Thunk to the alternatives for DelayedCall. After investigation, I can see how you can call it 'reasonable'. But I think 'thunk' is a 'thunky' word, in the common cartoonish slang meaning of 'thunk' as 'clunky thud' (as of something falling, since the 1940s, at least). As a 'sound' word, it is meant to be as unpleasant as the sound it imitates. I find the CS meaning to also be 'thunky' in its coinage. '''Thunks were invented by Peter Zilahy Ingerman[1] in 1961. According to the inventor, the name "thunk" came about because it could be optimized by the compiler by "thinking about it", so "thunk", according to its inventor, "is the past tense of 'think' at two in the morning"[2]''' https://en.wikipedia.org/wiki/Thunk_%28functional_programming%29 I never would have guessed ;-). So I prefer most anything else. Terry From python-checkins at python.org Tue Dec 18 22:11:03 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 22:11:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316717=3A_get_rid_?= =?utf-8?q?of_socket=2Eerror=2C_replace_with_OSError?= Message-ID: <3YQsN74K5qzQhh@mail.python.org> http://hg.python.org/cpython/rev/50d19c2fac82 changeset: 80933:50d19c2fac82 user: Andrew Svetlov date: Tue Dec 18 23:10:48 2012 +0200 summary: Issue #16717: get rid of socket.error, replace with OSError files: Doc/library/nntplib.rst | 3 +- Lib/asynchat.py | 4 +- Lib/asyncore.py | 18 +- Lib/distutils/command/upload.py | 2 +- Lib/ftplib.py | 8 +- Lib/http/client.py | 4 +- Lib/idlelib/PyShell.py | 2 +- Lib/idlelib/rpc.py | 8 +- Lib/idlelib/run.py | 4 +- Lib/imaplib.py | 8 +- Lib/logging/config.py | 2 +- Lib/logging/handlers.py | 8 +- Lib/nntplib.py | 2 +- Lib/platform.py | 2 +- Lib/poplib.py | 2 +- Lib/smtpd.py | 4 +- Lib/socketserver.py | 4 +- Lib/ssl.py | 10 +- Lib/telnetlib.py | 2 +- Lib/test/ssl_servers.py | 2 +- Lib/test/support.py | 6 +- Lib/test/test_asyncore.py | 6 +- Lib/test/test_epoll.py | 2 +- Lib/test/test_ftplib.py | 6 +- Lib/test/test_httplib.py | 4 +- Lib/test/test_kqueue.py | 2 +- Lib/test/test_logging.py | 8 +- Lib/test/test_nntplib.py | 2 +- Lib/test/test_poplib.py | 2 +- Lib/test/test_smtplib.py | 2 +- Lib/test/test_socket.py | 112 ++++++++++---------- Lib/test/test_ssl.py | 28 ++-- Lib/test/test_urllib2.py | 4 +- Lib/test/test_xmlrpc.py | 28 ++-- Lib/test/test_xmlrpc_net.py | 4 +- Lib/urllib/request.py | 12 +- Lib/webbrowser.py | 2 +- Lib/xmlrpc/client.py | 5 +- Modules/socketmodule.c | 2 +- 39 files changed, 169 insertions(+), 167 deletions(-) diff --git a/Doc/library/nntplib.rst b/Doc/library/nntplib.rst --- a/Doc/library/nntplib.rst +++ b/Doc/library/nntplib.rst @@ -1,4 +1,3 @@ - :mod:`nntplib` --- NNTP protocol client ======================================= @@ -71,7 +70,7 @@ reader-specific commands, such as ``group``. If you get unexpected :exc:`NNTPPermanentError`\ s, you might need to set *readermode*. :class:`NNTP` class supports the :keyword:`with` statement to - unconditionally consume :exc:`socket.error` exceptions and to close the NNTP + unconditionally consume :exc:`OSError` exceptions and to close the NNTP connection when done. Here is a sample on how using it: >>> from nntplib import NNTP diff --git a/Lib/asynchat.py b/Lib/asynchat.py --- a/Lib/asynchat.py +++ b/Lib/asynchat.py @@ -114,7 +114,7 @@ try: data = self.recv (self.ac_in_buffer_size) - except socket.error as why: + except OSError as why: self.handle_error() return @@ -243,7 +243,7 @@ # send the data try: num_sent = self.send(data) - except socket.error: + except OSError: self.handle_error() return diff --git a/Lib/asyncore.py b/Lib/asyncore.py --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -112,7 +112,7 @@ obj.handle_expt_event() if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL): obj.handle_close() - except socket.error as e: + except OSError as e: if e.args[0] not in _DISCONNECTED: obj.handle_error() else: @@ -240,7 +240,7 @@ # passed be connected. try: self.addr = sock.getpeername() - except socket.error as err: + except OSError as err: if err.args[0] in (ENOTCONN, EINVAL): # To handle the case where we got an unconnected # socket. @@ -304,7 +304,7 @@ self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) | 1 ) - except socket.error: + except OSError: pass # ================================================== @@ -345,7 +345,7 @@ self.addr = address self.handle_connect_event() else: - raise socket.error(err, errorcode[err]) + raise OSError(err, errorcode[err]) def accept(self): # XXX can return either an address pair or None @@ -353,7 +353,7 @@ conn, addr = self.socket.accept() except TypeError: return None - except socket.error as why: + except OSError as why: if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN): return None else: @@ -365,7 +365,7 @@ try: result = self.socket.send(data) return result - except socket.error as why: + except OSError as why: if why.args[0] == EWOULDBLOCK: return 0 elif why.args[0] in _DISCONNECTED: @@ -384,7 +384,7 @@ return b'' else: return data - except socket.error as why: + except OSError as why: # winsock sometimes raises ENOTCONN if why.args[0] in _DISCONNECTED: self.handle_close() @@ -399,7 +399,7 @@ self.del_channel() try: self.socket.close() - except socket.error as why: + except OSError as why: if why.args[0] not in (ENOTCONN, EBADF): raise @@ -443,7 +443,7 @@ def handle_connect_event(self): err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) if err != 0: - raise socket.error(err, _strerror(err)) + raise OSError(err, _strerror(err)) self.handle_connect() self.connected = True self.connecting = False diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py --- a/Lib/distutils/command/upload.py +++ b/Lib/distutils/command/upload.py @@ -186,7 +186,7 @@ http.putheader('Authorization', auth) http.endheaders() http.send(body) - except socket.error as e: + except OSError as e: self.announce(str(e), log.ERROR) return diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -123,7 +123,7 @@ if self.sock is not None: try: self.quit() - except (socket.error, EOFError): + except (OSError, EOFError): pass finally: if self.sock is not None: @@ -295,7 +295,7 @@ try: sock = socket.socket(af, socktype, proto) sock.bind(sa) - except socket.error as _: + except OSError as _: err = _ if sock: sock.close() @@ -306,8 +306,8 @@ if err is not None: raise err else: - raise socket.error("getaddrinfo returns an empty list") - raise socket.error(msg) + raise OSError("getaddrinfo returns an empty list") + raise OSError(msg) sock.listen(1) port = sock.getsockname()[1] # Get proper port host = self.sock.getsockname()[0] # Get proper host diff --git a/Lib/http/client.py b/Lib/http/client.py --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -791,8 +791,8 @@ if code != 200: self.close() - raise socket.error("Tunnel connection failed: %d %s" % (code, - message.strip())) + raise OSError("Tunnel connection failed: %d %s" % (code, + message.strip())) while True: line = response.fp.readline(_MAXLINE + 1) if len(line) > _MAXLINE: diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -393,7 +393,7 @@ try: self.rpcclt = MyRPCClient(addr) break - except socket.error as err: + except OSError as err: pass else: self.display_port_binding_error() diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py --- a/Lib/idlelib/rpc.py +++ b/Lib/idlelib/rpc.py @@ -199,7 +199,7 @@ raise except KeyboardInterrupt: raise - except socket.error: + except OSError: raise except Exception as ex: return ("CALLEXC", ex) @@ -340,7 +340,7 @@ n = self.sock.send(s[:BUFSIZE]) except (AttributeError, TypeError): raise IOError("socket no longer exists") - except socket.error: + except OSError: raise else: s = s[n:] @@ -357,7 +357,7 @@ return None try: s = self.sock.recv(BUFSIZE) - except socket.error: + except OSError: raise EOFError if len(s) == 0: raise EOFError @@ -537,7 +537,7 @@ SocketIO.__init__(self, working_sock) else: print("** Invalid host: ", address, file=sys.__stderr__) - raise socket.error + raise OSError def get_remote_proxy(self, oid): return RPCProxy(self, oid) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -135,8 +135,8 @@ try: server = MyRPCServer(address, MyHandler) break - except socket.error as err: - print("IDLE Subprocess: socket error: " + err.args[1] + + except OSError as err: + print("IDLE Subprocess: OSError: " + err.args[1] + ", retrying....", file=sys.__stderr__) socket_error = err else: diff --git a/Lib/imaplib.py b/Lib/imaplib.py --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -174,7 +174,7 @@ except Exception: try: self.shutdown() - except socket.error: + except OSError: pass raise @@ -267,7 +267,7 @@ self.file.close() try: self.sock.shutdown(socket.SHUT_RDWR) - except socket.error as e: + except OSError as e: # The server might already have closed the connection if e.errno != errno.ENOTCONN: raise @@ -899,7 +899,7 @@ try: self.send(data + CRLF) - except (socket.error, OSError) as val: + except OSError as val: raise self.abort('socket error: %s' % val) if literal is None: @@ -924,7 +924,7 @@ try: self.send(literal) self.send(CRLF) - except (socket.error, OSError) as val: + except OSError as val: raise self.abort('socket error: %s' % val) if not literator: diff --git a/Lib/logging/config.py b/Lib/logging/config.py --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -844,7 +844,7 @@ traceback.print_exc() if self.server.ready: self.server.ready.set() - except socket.error as e: + except OSError as e: if not isinstance(e.args, tuple): raise else: diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -514,7 +514,7 @@ try: self.sock = self.makeSocket() self.retryTime = None # next time, no delay before trying - except socket.error: + except OSError: #Creation failed, so set the retry time and return. if self.retryTime is None: self.retryPeriod = self.retryStart @@ -539,7 +539,7 @@ if self.sock: try: self.sock.sendall(s) - except socket.error: #pragma: no cover + except OSError: #pragma: no cover self.sock.close() self.sock = None # so we can call createSocket next time @@ -775,7 +775,7 @@ self.socket = socket.socket(socket.AF_UNIX, self.socktype) try: self.socket.connect(address) - except socket.error: + except OSError: self.socket.close() raise @@ -842,7 +842,7 @@ if self.unixsocket: try: self.socket.send(msg) - except socket.error: + except OSError: self._connect_unixsocket(self.address) self.socket.send(msg) elif self.socktype == socket.SOCK_DGRAM: diff --git a/Lib/nntplib.py b/Lib/nntplib.py --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -359,7 +359,7 @@ if is_connected(): try: self.quit() - except (socket.error, EOFError): + except (OSError, EOFError): pass finally: if is_connected(): diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -882,7 +882,7 @@ return default try: return socket.gethostname() - except socket.error: + except OSError: # Still not working... return default diff --git a/Lib/poplib.py b/Lib/poplib.py --- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -272,7 +272,7 @@ if self.sock is not None: try: self.sock.shutdown(socket.SHUT_RDWR) - except socket.error as e: + except OSError as e: # The server might already have closed the connection if e.errno != errno.ENOTCONN: raise diff --git a/Lib/smtpd.py b/Lib/smtpd.py --- a/Lib/smtpd.py +++ b/Lib/smtpd.py @@ -137,7 +137,7 @@ self.num_bytes = 0 try: self.peer = conn.getpeername() - except socket.error as err: + except OSError as err: # a race condition may occur if the other end is closing # before we can get the peername self.close() @@ -668,7 +668,7 @@ except smtplib.SMTPRecipientsRefused as e: print('got SMTPRecipientsRefused', file=DEBUGSTREAM) refused = e.recipients - except (socket.error, smtplib.SMTPException) as e: + except (OSError, smtplib.SMTPException) as e: print('got', e.__class__, file=DEBUGSTREAM) # All recipients were refused. If the exception had an associated # error code, use it. Otherwise,fake it with a non-triggering diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -299,7 +299,7 @@ """ try: request, client_address = self.get_request() - except socket.error: + except OSError: return if self.verify_request(request, client_address): try: @@ -479,7 +479,7 @@ #explicitly shutdown. socket.close() merely releases #the socket and waits for GC to perform the actual close. request.shutdown(socket.SHUT_WR) - except socket.error: + except OSError: pass #some platforms may raise ENOTCONN here self.close_request(request) diff --git a/Lib/ssl.py b/Lib/ssl.py --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -109,12 +109,14 @@ _PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2" from socket import getnameinfo as _getnameinfo -from socket import error as socket_error from socket import socket, AF_INET, SOCK_STREAM, create_connection import base64 # for DER-to-PEM translation import traceback import errno + +socket_error = OSError # keep that public name in module namespace + if _ssl.HAS_TLS_UNIQUE: CHANNEL_BINDING_TYPES = ['tls-unique'] else: @@ -279,7 +281,7 @@ # see if it's connected try: sock.getpeername() - except socket_error as e: + except OSError as e: if e.errno != errno.ENOTCONN: raise else: @@ -305,7 +307,7 @@ raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets") self.do_handshake() - except socket_error as x: + except OSError as x: self.close() raise x @@ -533,7 +535,7 @@ self.do_handshake() self._connected = True return rc - except socket_error: + except OSError: self._sslobj = None raise diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py --- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -273,7 +273,7 @@ """Write a string to the socket, doubling any IAC characters. Can block if the connection is blocked. May raise - socket.error if the connection is closed. + OSError if the connection is closed. """ if IAC in buffer: diff --git a/Lib/test/ssl_servers.py b/Lib/test/ssl_servers.py --- a/Lib/test/ssl_servers.py +++ b/Lib/test/ssl_servers.py @@ -35,7 +35,7 @@ try: sock, addr = self.socket.accept() sslconn = self.context.wrap_socket(sock, server_side=True) - except socket.error as e: + except OSError as e: # socket errors are silenced by the caller, print them here if support.verbose: sys.stderr.write("Got an error:\n%s\n" % e) diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -496,7 +496,7 @@ the SO_REUSEADDR socket option having different semantics on Windows versus Unix/Linux. On Unix, you can't have two AF_INET SOCK_STREAM sockets bind, listen and then accept connections on identical host/ports. An EADDRINUSE - socket.error will be raised at some point (depending on the platform and + OSError will be raised at some point (depending on the platform and the order bind and listen were called on each socket). However, on Windows, if SO_REUSEADDR is set on the sockets, no EADDRINUSE @@ -570,7 +570,7 @@ sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) sock.bind(('::1', 0)) return True - except (socket.error, socket.gaierror): + except OSError: pass finally: if sock: @@ -1098,7 +1098,7 @@ # with the Internet connection manifest themselves as exceptions. # XXX deprecate these and use transient_internet() instead time_out = TransientResource(IOError, errno=errno.ETIMEDOUT) -socket_peer_reset = TransientResource(socket.error, errno=errno.ECONNRESET) +socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) ioerror_peer_reset = TransientResource(IOError, errno=errno.ECONNRESET) diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -756,7 +756,7 @@ s2 = asyncore.dispatcher() s2.create_socket(self.family) # EADDRINUSE indicates the socket was correctly bound - self.assertRaises(socket.error, s2.bind, (self.addr[0], port)) + self.assertRaises(OSError, s2.bind, (self.addr[0], port)) def test_set_reuse_addr(self): if HAS_UNIX_SOCKETS and self.family == socket.AF_UNIX: @@ -764,7 +764,7 @@ sock = socket.socket(self.family) try: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - except socket.error: + except OSError: unittest.skip("SO_REUSEADDR not supported on this platform") else: # if SO_REUSEADDR succeeded for sock we expect asyncore @@ -797,7 +797,7 @@ struct.pack('ii', 1, 0)) try: s.connect(server.address) - except socket.error: + except OSError: pass finally: s.close() diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py --- a/Lib/test/test_epoll.py +++ b/Lib/test/test_epoll.py @@ -56,7 +56,7 @@ client.setblocking(False) try: client.connect(('127.0.0.1', self.serverSocket.getsockname()[1])) - except socket.error as e: + except OSError as e: self.assertEqual(e.args[0], errno.EINPROGRESS) else: raise AssertionError("Connect should have raised EINPROGRESS") diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -321,7 +321,7 @@ elif err.args[0] == ssl.SSL_ERROR_EOF: return self.handle_close() raise - except socket.error as err: + except OSError as err: if err.args[0] == errno.ECONNABORTED: return self.handle_close() else: @@ -335,7 +335,7 @@ if err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE): return - except socket.error as err: + except OSError as err: # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return # from OpenSSL's SSL_shutdown(), corresponding to a # closed socket condition. See also: @@ -676,7 +676,7 @@ return False try: self.client.sendcmd('noop') - except (socket.error, EOFError): + except (OSError, EOFError): return False return True diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -45,7 +45,7 @@ def sendall(self, data): if self.pipe_trigger in data: - raise socket.error(errno.EPIPE, "gotcha") + raise OSError(errno.EPIPE, "gotcha") self.data += data def close(self): @@ -515,7 +515,7 @@ b"Content-Length") conn = client.HTTPConnection("example.com") conn.sock = sock - self.assertRaises(socket.error, + self.assertRaises(OSError, lambda: conn.request("PUT", "/url", "body")) resp = conn.getresponse() self.assertEqual(401, resp.status) diff --git a/Lib/test/test_kqueue.py b/Lib/test/test_kqueue.py --- a/Lib/test/test_kqueue.py +++ b/Lib/test/test_kqueue.py @@ -94,7 +94,7 @@ client.setblocking(False) try: client.connect(('127.0.0.1', serverSocket.getsockname()[1])) - except socket.error as e: + except OSError as e: self.assertEqual(e.args[0], errno.EINPROGRESS) else: #raise AssertionError("Connect should have raised EINPROGRESS") diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -569,7 +569,7 @@ self.assertEqual(h.facility, h.LOG_USER) self.assertTrue(h.unixsocket) h.close() - except socket.error: # syslogd might not be available + except OSError: # syslogd might not be available pass for method in ('GET', 'POST', 'PUT'): if method == 'PUT': @@ -679,7 +679,7 @@ self.num_bytes = 0 try: self.peer = conn.getpeername() - except socket.error as err: + except OSError as err: # a race condition may occur if the other end is closing # before we can get the peername self.close() @@ -880,7 +880,7 @@ sock, addr = self.socket.accept() if self.sslctx: sock = self.sslctx.wrap_socket(sock, server_side=True) - except socket.error as e: + except OSError as e: # socket errors are silenced by the caller, print them here sys.stderr.write("Got an error:\n%s\n" % e) raise @@ -946,7 +946,7 @@ if data: try: super(DelegatingUDPRequestHandler, self).finish() - except socket.error: + except OSError: if not self.server._closed: raise diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py --- a/Lib/test/test_nntplib.py +++ b/Lib/test/test_nntplib.py @@ -264,7 +264,7 @@ return False try: server.help() - except (socket.error, EOFError): + except (OSError, EOFError): return False return True diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py --- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -167,7 +167,7 @@ elif err.args[0] == ssl.SSL_ERROR_EOF: return self.handle_close() raise - except socket.error as err: + except OSError as err: if err.args[0] == errno.ECONNABORTED: return self.handle_close() else: diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -535,7 +535,7 @@ smtp.send, 'test msg') def testNonnumericPort(self): - # check that non-numeric port raises socket.error + # check that non-numeric port raises OSError self.assertRaises(OSError, smtplib.SMTP, "localhost", "bogus") self.assertRaises(OSError, smtplib.SMTP, diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -46,7 +46,7 @@ """Check whether CAN sockets are supported on this host.""" try: s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) - except (AttributeError, socket.error, OSError): + except (AttributeError, OSError): return False else: s.close() @@ -126,7 +126,7 @@ self.addCleanup(self.s.close) try: self.s.bind((self.interface,)) - except socket.error: + except OSError: self.skipTest('network interface `%s` does not exist' % self.interface) @@ -295,7 +295,7 @@ self.cli = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) try: self.cli.bind((self.interface,)) - except socket.error: + except OSError: # skipTest should not be called here, and will be called in the # server instead pass @@ -608,7 +608,7 @@ for obj in args] try: s = socket.socket(*callargs) - except socket.error as e: + except OSError as e: # XXX: check errno? err = str(e) else: @@ -645,11 +645,11 @@ def testSocketError(self): # Testing socket module exceptions msg = "Error raising socket exception (%s)." - with self.assertRaises(socket.error, msg=msg % 'socket.error'): - raise socket.error - with self.assertRaises(socket.error, msg=msg % 'socket.herror'): + with self.assertRaises(OSError, msg=msg % 'OSError'): + raise OSError + with self.assertRaises(OSError, msg=msg % 'socket.herror'): raise socket.herror - with self.assertRaises(socket.error, msg=msg % 'socket.gaierror'): + with self.assertRaises(OSError, msg=msg % 'socket.gaierror'): raise socket.gaierror def testSendtoErrors(self): @@ -712,13 +712,13 @@ hostname = socket.gethostname() try: ip = socket.gethostbyname(hostname) - except socket.error: + except OSError: # Probably name lookup wasn't set up right; skip this test return self.assertTrue(ip.find('.') >= 0, "Error resolving host to ip.") try: hname, aliases, ipaddrs = socket.gethostbyaddr(ip) - except socket.error: + except OSError: # Probably a similar problem as above; skip this test return all_host_names = [hostname, hname] + aliases @@ -732,7 +732,7 @@ oldhn = socket.gethostname() try: socket.sethostname('new') - except socket.error as e: + except OSError as e: if e.errno == errno.EPERM: self.skipTest("test should be run as root") else: @@ -766,8 +766,8 @@ 'socket.if_nameindex() not available.') def testInvalidInterfaceNameIndex(self): # test nonexistent interface index/name - self.assertRaises(socket.error, socket.if_indextoname, 0) - self.assertRaises(socket.error, socket.if_nametoindex, '_DEADBEEF') + self.assertRaises(OSError, socket.if_indextoname, 0) + self.assertRaises(OSError, socket.if_nametoindex, '_DEADBEEF') # test with invalid values self.assertRaises(TypeError, socket.if_nametoindex, 0) self.assertRaises(TypeError, socket.if_indextoname, '_DEADBEEF') @@ -788,7 +788,7 @@ try: # On some versions, this crashes the interpreter. socket.getnameinfo(('x', 0, 0, 0), 0) - except socket.error: + except OSError: pass def testNtoH(self): @@ -835,17 +835,17 @@ try: port = socket.getservbyname(service, 'tcp') break - except socket.error: + except OSError: pass else: - raise socket.error + raise OSError # Try same call with optional protocol omitted port2 = socket.getservbyname(service) eq(port, port2) # Try udp, but don't barf it it doesn't exist try: udpport = socket.getservbyname(service, 'udp') - except socket.error: + except OSError: udpport = None else: eq(udpport, port) @@ -901,7 +901,7 @@ g = lambda a: inet_pton(AF_INET, a) assertInvalid = lambda func,a: self.assertRaises( - (socket.error, ValueError), func, a + (OSError, ValueError), func, a ) self.assertEqual(b'\x00\x00\x00\x00', f('0.0.0.0')) @@ -936,7 +936,7 @@ return f = lambda a: inet_pton(AF_INET6, a) assertInvalid = lambda a: self.assertRaises( - (socket.error, ValueError), f, a + (OSError, ValueError), f, a ) self.assertEqual(b'\x00' * 16, f('::')) @@ -985,7 +985,7 @@ from socket import inet_ntoa as f, inet_ntop, AF_INET g = lambda a: inet_ntop(AF_INET, a) assertInvalid = lambda func,a: self.assertRaises( - (socket.error, ValueError), func, a + (OSError, ValueError), func, a ) self.assertEqual('1.0.1.0', f(b'\x01\x00\x01\x00')) @@ -1014,7 +1014,7 @@ return f = lambda a: inet_ntop(AF_INET6, a) assertInvalid = lambda a: self.assertRaises( - (socket.error, ValueError), f, a + (OSError, ValueError), f, a ) self.assertEqual('::', f(b'\x00' * 16)) @@ -1042,7 +1042,7 @@ # At least for eCos. This is required for the S/390 to pass. try: my_ip_addr = socket.gethostbyname(socket.gethostname()) - except socket.error: + except OSError: # Probably name lookup wasn't set up right; skip this test return self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0]) @@ -1069,7 +1069,7 @@ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) sock.close() - self.assertRaises(socket.error, sock.send, b"spam") + self.assertRaises(OSError, sock.send, b"spam") def testNewAttributes(self): # testing .family, .type and .protocol @@ -1168,7 +1168,7 @@ def test_getnameinfo(self): # only IP addresses are allowed - self.assertRaises(socket.error, socket.getnameinfo, ('mail.python.org',0), 0) + self.assertRaises(OSError, socket.getnameinfo, ('mail.python.org',0), 0) @unittest.skipUnless(support.is_resource_enabled('network'), 'network is not enabled') @@ -1296,7 +1296,7 @@ def testTooLongInterfaceName(self): # most systems limit IFNAMSIZ to 16, take 1024 to be sure with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: - self.assertRaisesRegex(socket.error, 'interface name too long', + self.assertRaisesRegex(OSError, 'interface name too long', s.bind, ('x' * 1024,)) @unittest.skipUnless(hasattr(socket, "CAN_RAW_LOOPBACK"), @@ -1591,7 +1591,7 @@ self.assertEqual(f, fileno) # cli_conn cannot be used anymore... self.assertTrue(self.cli_conn._closed) - self.assertRaises(socket.error, self.cli_conn.recv, 1024) + self.assertRaises(OSError, self.cli_conn.recv, 1024) self.cli_conn.close() # ...but we can create another socket using the (still open) # file descriptor @@ -1960,7 +1960,7 @@ def _testSendmsgExcessCmsgReject(self): if not hasattr(socket, "CMSG_SPACE"): # Can only send one item - with self.assertRaises(socket.error) as cm: + with self.assertRaises(OSError) as cm: self.sendmsgToServer([MSG], [(0, 0, b""), (0, 0, b"")]) self.assertIsNone(cm.exception.errno) self.sendToServer(b"done") @@ -1971,7 +1971,7 @@ def _testSendmsgAfterClose(self): self.cli_sock.close() - self.assertRaises(socket.error, self.sendmsgToServer, [MSG]) + self.assertRaises(OSError, self.sendmsgToServer, [MSG]) class SendmsgStreamTests(SendmsgTests): @@ -2015,7 +2015,7 @@ @testSendmsgDontWait.client_skip def _testSendmsgDontWait(self): try: - with self.assertRaises(socket.error) as cm: + with self.assertRaises(OSError) as cm: while True: self.sendmsgToServer([b"a"*512], [], socket.MSG_DONTWAIT) self.assertIn(cm.exception.errno, @@ -2035,9 +2035,9 @@ pass def _testSendmsgNoDestAddr(self): - self.assertRaises(socket.error, self.cli_sock.sendmsg, + self.assertRaises(OSError, self.cli_sock.sendmsg, [MSG]) - self.assertRaises(socket.error, self.cli_sock.sendmsg, + self.assertRaises(OSError, self.cli_sock.sendmsg, [MSG], [], 0, None) @@ -2123,7 +2123,7 @@ def testRecvmsgAfterClose(self): # Check that recvmsg[_into]() fails on a closed socket. self.serv_sock.close() - self.assertRaises(socket.error, self.doRecvmsg, self.serv_sock, 1024) + self.assertRaises(OSError, self.doRecvmsg, self.serv_sock, 1024) def _testRecvmsgAfterClose(self): pass @@ -2571,7 +2571,7 @@ # call fails, just send msg with no ancillary data. try: nbytes = self.sendmsgToServer([msg], ancdata) - except socket.error as e: + except OSError as e: # Check that it was the system call that failed self.assertIsInstance(e.errno, int) nbytes = self.sendmsgToServer([msg]) @@ -2949,7 +2949,7 @@ array.array("i", [self.traffic_class]).tobytes() + b"\x00"), (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, array.array("i", [self.hop_limit]))]) - except socket.error as e: + except OSError as e: self.assertIsInstance(e.errno, int) nbytes = self.sendmsgToServer( [MSG], @@ -3396,10 +3396,10 @@ self.serv.settimeout(self.timeout) def checkInterruptedRecv(self, func, *args, **kwargs): - # Check that func(*args, **kwargs) raises socket.error with an + # Check that func(*args, **kwargs) raises OSError with an # errno of EINTR when interrupted by a signal. self.setAlarm(self.alarm_time) - with self.assertRaises(socket.error) as cm: + with self.assertRaises(OSError) as cm: func(*args, **kwargs) self.assertNotIsInstance(cm.exception, socket.timeout) self.assertEqual(cm.exception.errno, errno.EINTR) @@ -3456,9 +3456,9 @@ def checkInterruptedSend(self, func, *args, **kwargs): # Check that func(*args, **kwargs), run in a loop, raises - # socket.error with an errno of EINTR when interrupted by a + # OSError with an errno of EINTR when interrupted by a # signal. - with self.assertRaises(socket.error) as cm: + with self.assertRaises(OSError) as cm: while True: self.setAlarm(self.alarm_time) func(*args, **kwargs) @@ -3552,7 +3552,7 @@ start = time.time() try: self.serv.accept() - except socket.error: + except OSError: pass end = time.time() self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.") @@ -3573,7 +3573,7 @@ start = time.time() try: self.serv.accept() - except socket.error: + except OSError: pass end = time.time() self.assertTrue((end - start) < 1.0, "Error creating with non-blocking mode.") @@ -3603,7 +3603,7 @@ self.serv.setblocking(0) try: conn, addr = self.serv.accept() - except socket.error: + except OSError: pass else: self.fail("Error trying to do non-blocking accept.") @@ -3633,7 +3633,7 @@ conn.setblocking(0) try: msg = conn.recv(len(MSG)) - except socket.error: + except OSError: pass else: self.fail("Error trying to do non-blocking recv.") @@ -3808,7 +3808,7 @@ self.read_file.close() self.assertRaises(ValueError, self.read_file.fileno) self.cli_conn.close() - self.assertRaises(socket.error, self.cli_conn.getsockname) + self.assertRaises(OSError, self.cli_conn.getsockname) def _testRealClose(self): pass @@ -3845,7 +3845,7 @@ @staticmethod def _raise_eintr(): - raise socket.error(errno.EINTR, "interrupted") + raise OSError(errno.EINTR, "interrupted") def _textiowrap_mock_socket(self, mock, buffering=-1): raw = socket.SocketIO(mock, "r") @@ -3957,7 +3957,7 @@ self.assertEqual(msg, self.read_msg) # ...until the file is itself closed self.read_file.close() - self.assertRaises(socket.error, self.cli_conn.recv, 1024) + self.assertRaises(OSError, self.cli_conn.recv, 1024) def _testMakefileClose(self): self.write_file.write(self.write_msg) @@ -4106,7 +4106,7 @@ port = support.find_unused_port() cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.addCleanup(cli.close) - with self.assertRaises(socket.error) as cm: + with self.assertRaises(OSError) as cm: cli.connect((HOST, port)) self.assertEqual(cm.exception.errno, errno.ECONNREFUSED) @@ -4114,7 +4114,7 @@ # Issue #9792: errors raised by create_connection() should have # a proper errno attribute. port = support.find_unused_port() - with self.assertRaises(socket.error) as cm: + with self.assertRaises(OSError) as cm: socket.create_connection((HOST, port)) # Issue #16257: create_connection() calls getaddrinfo() against @@ -4262,7 +4262,7 @@ foo = self.serv.accept() except socket.timeout: self.fail("caught timeout instead of error (TCP)") - except socket.error: + except OSError: ok = True except: self.fail("caught unexpected exception (TCP)") @@ -4319,7 +4319,7 @@ foo = self.serv.recv(1024) except socket.timeout: self.fail("caught timeout instead of error (UDP)") - except socket.error: + except OSError: ok = True except: self.fail("caught unexpected exception (UDP)") @@ -4329,10 +4329,10 @@ class TestExceptions(unittest.TestCase): def testExceptionTree(self): - self.assertTrue(issubclass(socket.error, Exception)) - self.assertTrue(issubclass(socket.herror, socket.error)) - self.assertTrue(issubclass(socket.gaierror, socket.error)) - self.assertTrue(issubclass(socket.timeout, socket.error)) + self.assertTrue(issubclass(OSError, Exception)) + self.assertTrue(issubclass(socket.herror, OSError)) + self.assertTrue(issubclass(socket.gaierror, OSError)) + self.assertTrue(issubclass(socket.timeout, OSError)) class TestLinuxAbstractNamespace(unittest.TestCase): @@ -4358,7 +4358,7 @@ def testNameOverflow(self): address = "\x00" + "h" * self.UNIX_PATH_MAX with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: - self.assertRaises(socket.error, s.bind, address) + self.assertRaises(OSError, s.bind, address) def testStrName(self): # Check that an abstract name can be passed as a string. @@ -4597,7 +4597,7 @@ self.assertTrue(sock._closed) # exception inside with block with socket.socket() as sock: - self.assertRaises(socket.error, sock.sendall, b'foo') + self.assertRaises(OSError, sock.sendall, b'foo') self.assertTrue(sock._closed) def testCreateConnectionBase(self): @@ -4625,7 +4625,7 @@ with socket.create_connection(address) as sock: sock.close() self.assertTrue(sock._closed) - self.assertRaises(socket.error, sock.sendall, b'foo') + self.assertRaises(OSError, sock.sendall, b'foo') @unittest.skipUnless(hasattr(socket, "SOCK_CLOEXEC"), diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -213,15 +213,15 @@ def test_wrapped_unconnected(self): # Methods on an unconnected SSLSocket propagate the original - # socket.error raise by the underlying socket object. + # OSError raise by the underlying socket object. s = socket.socket(socket.AF_INET) ss = ssl.wrap_socket(s) - self.assertRaises(socket.error, ss.recv, 1) - self.assertRaises(socket.error, ss.recv_into, bytearray(b'x')) - self.assertRaises(socket.error, ss.recvfrom, 1) - self.assertRaises(socket.error, ss.recvfrom_into, bytearray(b'x'), 1) - self.assertRaises(socket.error, ss.send, b'x') - self.assertRaises(socket.error, ss.sendto, b'x', ('0.0.0.0', 0)) + self.assertRaises(OSError, ss.recv, 1) + self.assertRaises(OSError, ss.recv_into, bytearray(b'x')) + self.assertRaises(OSError, ss.recvfrom, 1) + self.assertRaises(OSError, ss.recvfrom_into, bytearray(b'x'), 1) + self.assertRaises(OSError, ss.send, b'x') + self.assertRaises(OSError, ss.sendto, b'x', ('0.0.0.0', 0)) def test_timeout(self): # Issue #8524: when creating an SSL socket, the timeout of the @@ -1012,7 +1012,7 @@ sys.stdout.write(" server: read %r (%s), sending back %r (%s)...\n" % (msg, ctype, msg.lower(), ctype)) self.write(msg.lower()) - except socket.error: + except OSError: if self.server.chatty: handle_error("Test server failure:\n") self.close() @@ -1122,7 +1122,7 @@ return self.handle_close() except ssl.SSLError: raise - except socket.error as err: + except OSError as err: if err.args[0] == errno.ECONNABORTED: return self.handle_close() else: @@ -1226,9 +1226,9 @@ except ssl.SSLError as x: if support.verbose: sys.stdout.write("\nSSLError is %s\n" % x.args[1]) - except socket.error as x: + except OSError as x: if support.verbose: - sys.stdout.write("\nsocket.error is %s\n" % x.args[1]) + sys.stdout.write("\nOSError is %s\n" % x.args[1]) except IOError as x: if x.errno != errno.ENOENT: raise @@ -1313,7 +1313,7 @@ except ssl.SSLError: if expect_success: raise - except socket.error as e: + except OSError as e: if expect_success or e.errno != errno.ECONNRESET: raise else: @@ -1458,7 +1458,7 @@ if hasattr(ssl, 'PROTOCOL_SSLv2'): try: try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv2, True) - except (ssl.SSLError, socket.error) as x: + except OSError as x: # this fails on some older versions of OpenSSL (0.9.7l, for instance) if support.verbose: sys.stdout.write( @@ -1844,7 +1844,7 @@ chatty=False) as server: with socket.socket() as sock: s = context.wrap_socket(sock) - with self.assertRaises((OSError, ssl.SSLError)): + with self.assertRaises(OSError): s.connect((HOST, server.port)) self.assertIn("no shared cipher", str(server.conn_errors[0])) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -344,7 +344,7 @@ self.data = body if self.raise_on_endheaders: import socket - raise socket.error() + raise OSError() def getresponse(self): return MockHTTPResponse(MockFile(), {}, 200, "OK") @@ -845,7 +845,7 @@ ("Foo", "bar"), ("Spam", "eggs")]) self.assertEqual(http.data, data) - # check socket.error converted to URLError + # check OSError converted to URLError http.raise_on_endheaders = True self.assertRaises(urllib.error.URLError, h.do_open, http, req) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -215,7 +215,7 @@ xmlrpc.client.ServerProxy('https://localhost:9999').bad_function() except NotImplementedError: self.assertFalse(has_ssl, "xmlrpc client's error with SSL support") - except socket.error: + except OSError: self.assertTrue(has_ssl) class HelperTestCase(unittest.TestCase): @@ -492,7 +492,7 @@ return True exc_mess = e.headers.get('X-exception') except AttributeError: - # Ignore socket.errors here. + # Ignore OSErrors here. exc_mess = str(e) if exc_mess and 'temporarily unavailable' in exc_mess.lower(): @@ -507,7 +507,7 @@ def make_request_and_skip(self): try: xmlrpclib.ServerProxy(URL).my_function() - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: if not is_unavailable_exception(e): raise raise unittest.SkipTest(reason) @@ -545,7 +545,7 @@ try: p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -558,7 +558,7 @@ p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.add(start_string, end_string), start_string + end_string) - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -584,7 +584,7 @@ p = xmlrpclib.ServerProxy(URL) meth = p.system.listMethods() self.assertEqual(set(meth), expected_methods) - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -597,7 +597,7 @@ p = xmlrpclib.ServerProxy(URL) divhelp = p.system.methodHelp('div') self.assertEqual(divhelp, 'This is the div function') - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -611,7 +611,7 @@ p = xmlrpclib.ServerProxy(URL) myfunction = p.system.methodHelp('my_function') self.assertEqual(myfunction, 'This is my function') - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -624,7 +624,7 @@ p = xmlrpclib.ServerProxy(URL) divsig = p.system.methodSignature('div') self.assertEqual(divsig, 'signatures not supported') - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -641,7 +641,7 @@ self.assertEqual(add_result, 2+3) self.assertEqual(pow_result, 6**8) self.assertEqual(div_result, 127//42) - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -662,7 +662,7 @@ self.assertEqual(result.results[0]['faultString'], ':method "this_is_not_exists" ' 'is not supported') - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -915,7 +915,7 @@ try: p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): # protocol error; provide additional information in test output @@ -928,7 +928,7 @@ try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e) and hasattr(e, "headers"): # The two server-side error headers shouldn't be sent back in this case @@ -948,7 +948,7 @@ try: p = xmlrpclib.ServerProxy(URL) p.pow(6,8) - except (xmlrpclib.ProtocolError, socket.error) as e: + except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e) and hasattr(e, "headers"): # We should get error info in the response diff --git a/Lib/test/test_xmlrpc_net.py b/Lib/test/test_xmlrpc_net.py --- a/Lib/test/test_xmlrpc_net.py +++ b/Lib/test/test_xmlrpc_net.py @@ -18,7 +18,7 @@ server = xmlrpclib.ServerProxy("http://time.xmlrpc.com/RPC2") try: t0 = server.currentTime.getCurrentTime() - except socket.error as e: + except OSError as e: self.skipTest("network error: %s" % e) return @@ -42,7 +42,7 @@ server = xmlrpclib.ServerProxy("http://buildbot.python.org/all/xmlrpc/") try: builders = server.getAllBuilders() - except socket.error as e: + except OSError as e: self.skipTest("network error: %s" % e) return self.addCleanup(lambda: server('close')()) diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1275,7 +1275,7 @@ try: h.request(req.get_method(), req.selector, req.data, headers) - except socket.error as err: # timeout error + except OSError as err: # timeout error h.close() raise URLError(err) else: @@ -1480,7 +1480,7 @@ try: host = socket.gethostbyname(host) - except socket.error as msg: + except OSError as msg: raise URLError(msg) path, attrs = splitattr(req.selector) dirs = path.split('/') @@ -1721,7 +1721,7 @@ return getattr(self, name)(url, data) except (HTTPError, URLError): raise - except socket.error as msg: + except OSError as msg: raise IOError('socket error', msg).with_traceback(sys.exc_info()[2]) def open_unknown(self, fullurl, data=None): @@ -2487,7 +2487,7 @@ try: hostIP = socket.gethostbyname(hostonly) hostIP = ip2num(hostIP) - except socket.error: + except OSError: continue base = ip2num(m.group(1)) @@ -2614,13 +2614,13 @@ addr = socket.gethostbyname(rawHost) if addr != rawHost: host.append(addr) - except socket.error: + except OSError: pass try: fqdn = socket.getfqdn(rawHost) if fqdn != rawHost: host.append(fqdn) - except socket.error: + except OSError: pass # make a check value list from the registry entry: replace the # '' string by the localhost entry and the corresponding diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -418,7 +418,7 @@ # need to PING each one until we find one that's live try: s.connect(fn) - except socket.error: + except OSError: # no good; attempt to clean it out, but don't fail: try: os.unlink(fn) diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1130,8 +1130,9 @@ for i in (0, 1): try: return self.single_request(host, handler, request_body, verbose) - except socket.error as e: - if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): + except OSError as e: + if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, + errno.EPIPE): raise except http.client.BadStatusLine: #close after we sent request if i: diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -15,7 +15,7 @@ Module interface: -- socket.error: exception raised for socket specific errors +- socket.error: exception raised for socket specific errors, alias for OSError - socket.gaierror: exception raised for getaddrinfo/getnameinfo errors, a subclass of socket.error - socket.herror: exception raised for gethostby* errors, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 22:16:53 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 18 Dec 2012 22:16:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Mention_OSError_instead_of?= =?utf-8?q?_IOError_in_the_docs=2E?= Message-ID: <3YQsVs2mGnzQl0@mail.python.org> http://hg.python.org/cpython/rev/a6ea6f803017 changeset: 80934:a6ea6f803017 user: Andrew Svetlov date: Tue Dec 18 23:16:44 2012 +0200 summary: Mention OSError instead of IOError in the docs. files: Doc/faq/library.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/faq/library.rst b/Doc/faq/library.rst --- a/Doc/faq/library.rst +++ b/Doc/faq/library.rst @@ -209,7 +209,7 @@ try: c = sys.stdin.read(1) print("Got character", repr(c)) - except IOError: + except OSError: pass finally: termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) @@ -222,7 +222,7 @@ :func:`termios.tcsetattr` turns off stdin's echoing and disables canonical mode. :func:`fcntl.fnctl` is used to obtain stdin's file descriptor flags and modify them for non-blocking mode. Since reading stdin when it is empty - results in an :exc:`IOError`, this error is caught and ignored. + results in an :exc:`OSError`, this error is caught and ignored. Threads -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 22:23:41 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 22:23:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Add_sanity_ass?= =?utf-8?q?ertions_in_some_import_lock_code_=28issue_=2315599=29=2E?= Message-ID: <3YQsfj5PWGzQhR@mail.python.org> http://hg.python.org/cpython/rev/1ee9cf5a5351 changeset: 80935:1ee9cf5a5351 branch: 3.3 parent: 80929:15a391919deb user: Antoine Pitrou date: Tue Dec 18 22:18:17 2012 +0100 summary: Add sanity assertions in some import lock code (issue #15599). files: Lib/test/test_threaded_import.py | 1 + Python/import.c | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -68,6 +68,7 @@ # Simulate some thread-unsafe behaviour. If calls to find_module() # are properly serialized, `x` will end up the same as `numcalls`. # Otherwise not. + assert imp.lock_held() with self.lock: self.numcalls += 1 x = self.x diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -169,6 +169,7 @@ PyThread_acquire_lock(import_lock, 1); PyEval_RestoreThread(tstate); } + assert(import_lock_level == 0); import_lock_thread = me; import_lock_level = 1; } @@ -182,6 +183,7 @@ if (import_lock_thread != me) return -1; import_lock_level--; + assert(import_lock_level >= 0); if (import_lock_level == 0) { import_lock_thread = -1; PyThread_release_lock(import_lock); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 22:23:43 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 22:23:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Add_sanity_assertions_in_some_import_lock_code_=28issue_?= =?utf-8?b?IzE1NTk5KS4=?= Message-ID: <3YQsfl0fP9zQl0@mail.python.org> http://hg.python.org/cpython/rev/7cfca9ede861 changeset: 80936:7cfca9ede861 parent: 80934:a6ea6f803017 parent: 80935:1ee9cf5a5351 user: Antoine Pitrou date: Tue Dec 18 22:18:58 2012 +0100 summary: Add sanity assertions in some import lock code (issue #15599). files: Lib/test/test_threaded_import.py | 1 + Python/import.c | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -68,6 +68,7 @@ # Simulate some thread-unsafe behaviour. If calls to find_module() # are properly serialized, `x` will end up the same as `numcalls`. # Otherwise not. + assert imp.lock_held() with self.lock: self.numcalls += 1 x = self.x diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -169,6 +169,7 @@ PyThread_acquire_lock(import_lock, 1); PyEval_RestoreThread(tstate); } + assert(import_lock_level == 0); import_lock_thread = me; import_lock_level = 1; } @@ -182,6 +183,7 @@ if (import_lock_thread != me) return -1; import_lock_level--; + assert(import_lock_level >= 0); if (import_lock_level == 0) { import_lock_thread = -1; PyThread_release_lock(import_lock); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 23:06:02 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 23:06:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Try_to_make_te?= =?utf-8?q?st=5Fthreaded=5Fimport_faster_and_safer_=28issue_=2315599=29=2E?= Message-ID: <3YQtbZ1GWTzQn7@mail.python.org> http://hg.python.org/cpython/rev/67d6bb557d67 changeset: 80937:67d6bb557d67 branch: 3.3 parent: 80935:1ee9cf5a5351 user: Antoine Pitrou date: Tue Dec 18 23:03:42 2012 +0100 summary: Try to make test_threaded_import faster and safer (issue #15599). files: Lib/test/test_threaded_import.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -72,7 +72,7 @@ with self.lock: self.numcalls += 1 x = self.x - time.sleep(0.1) + time.sleep(0.01) self.x = x + 1 class FlushingFinder: @@ -117,7 +117,7 @@ t = threading.Thread(target=task, args=(N, done, done_tasks, errors,)) t.start() - done.wait(60) + self.assertTrue(done.wait(60)) self.assertFalse(errors) if verbose: print("OK.") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 23:06:03 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 23:06:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Try_to_make_test=5Fthreaded=5Fimport_faster_and_safer_?= =?utf-8?b?KGlzc3VlICMxNTU5OSku?= Message-ID: <3YQtbb3XX1zQXC@mail.python.org> http://hg.python.org/cpython/rev/30c7cc62303a changeset: 80938:30c7cc62303a parent: 80936:7cfca9ede861 parent: 80937:67d6bb557d67 user: Antoine Pitrou date: Tue Dec 18 23:04:10 2012 +0100 summary: Try to make test_threaded_import faster and safer (issue #15599). files: Lib/test/test_threaded_import.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -72,7 +72,7 @@ with self.lock: self.numcalls += 1 x = self.x - time.sleep(0.1) + time.sleep(0.01) self.x = x + 1 class FlushingFinder: @@ -117,7 +117,7 @@ t = threading.Thread(target=task, args=(N, done, done_tasks, errors,)) t.start() - done.wait(60) + self.assertTrue(done.wait(60)) self.assertFalse(errors) if verbose: print("OK.") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 23:32:10 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 23:32:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Call_importlib?= =?utf-8?q?=2Einvalidate=5Fcaches=28=29_after_creating_module_files_in?= Message-ID: <3YQv9k0t2YzQq4@mail.python.org> http://hg.python.org/cpython/rev/4332b51076e2 changeset: 80939:4332b51076e2 branch: 3.3 parent: 80937:67d6bb557d67 user: Antoine Pitrou date: Tue Dec 18 23:28:04 2012 +0100 summary: Call importlib.invalidate_caches() after creating module files in test_threaded_import. files: Lib/test/test_threaded_import.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -7,6 +7,7 @@ import os import imp +import importlib import sys import time import shutil @@ -190,6 +191,7 @@ f.write(contents.encode('utf-8')) self.addCleanup(forget, name) + importlib.invalidate_caches() results = [] def import_ab(): import A @@ -220,6 +222,7 @@ f.write(code.encode('utf-8')) self.addCleanup(unlink, filename) self.addCleanup(forget, TESTFN) + importlib.invalidate_caches() __import__(TESTFN) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 23:32:11 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 23:32:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Call_importlib=2Einvalidate=5Fcaches=28=29_after_creatin?= =?utf-8?q?g_module_files_in?= Message-ID: <3YQv9l33x8zQnQ@mail.python.org> http://hg.python.org/cpython/rev/da8637b54f8c changeset: 80940:da8637b54f8c parent: 80938:30c7cc62303a parent: 80939:4332b51076e2 user: Antoine Pitrou date: Tue Dec 18 23:28:24 2012 +0100 summary: Call importlib.invalidate_caches() after creating module files in test_threaded_import. files: Lib/test/test_threaded_import.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -7,6 +7,7 @@ import os import imp +import importlib import sys import time import shutil @@ -190,6 +191,7 @@ f.write(contents.encode('utf-8')) self.addCleanup(forget, name) + importlib.invalidate_caches() results = [] def import_ab(): import A @@ -220,6 +222,7 @@ f.write(code.encode('utf-8')) self.addCleanup(unlink, filename) self.addCleanup(forget, TESTFN) + importlib.invalidate_caches() __import__(TESTFN) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 23:47:43 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 23:47:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Silence_sporad?= =?utf-8?q?ic_failure_in_RecvmsgIntoSCTPStreamTest=2EtestRecvmsgEOF_=28iss?= =?utf-8?q?ue?= Message-ID: <3YQvWg534pzQgW@mail.python.org> http://hg.python.org/cpython/rev/13d8c33de8ff changeset: 80941:13d8c33de8ff branch: 3.3 parent: 80939:4332b51076e2 user: Antoine Pitrou date: Tue Dec 18 23:44:36 2012 +0100 summary: Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related. files: Lib/test/test_socket.py | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -3305,7 +3305,14 @@ @unittest.skipUnless(thread, 'Threading required for this test.') class RecvmsgIntoSCTPStreamTest(RecvmsgIntoTests, RecvmsgGenericStreamTests, SendrecvmsgSCTPStreamTestBase): - pass + + def testRecvmsgEOF(self): + try: + super(RecvmsgIntoSCTPStreamTest, self).testRecvmsgEOF() + except OSError as e: + if e.errno != errno.ENOTCONN: + raise + self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876") class SendrecvmsgUnixStreamTestBase(SendrecvmsgConnectedBase, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 18 23:47:45 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 18 Dec 2012 23:47:45 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Silence_sporadic_failure_in_RecvmsgIntoSCTPStreamTest=2E?= =?utf-8?q?testRecvmsgEOF_=28issue?= Message-ID: <3YQvWj0W0ZzQn7@mail.python.org> http://hg.python.org/cpython/rev/900ee4a04f5e changeset: 80942:900ee4a04f5e parent: 80940:da8637b54f8c parent: 80941:13d8c33de8ff user: Antoine Pitrou date: Tue Dec 18 23:44:59 2012 +0100 summary: Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related. files: Lib/test/test_socket.py | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -3305,7 +3305,14 @@ @unittest.skipUnless(thread, 'Threading required for this test.') class RecvmsgIntoSCTPStreamTest(RecvmsgIntoTests, RecvmsgGenericStreamTests, SendrecvmsgSCTPStreamTestBase): - pass + + def testRecvmsgEOF(self): + try: + super(RecvmsgIntoSCTPStreamTest, self).testRecvmsgEOF() + except OSError as e: + if e.errno != errno.ENOTCONN: + raise + self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876") class SendrecvmsgUnixStreamTestBase(SendrecvmsgConnectedBase, -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Dec 19 05:57:47 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 19 Dec 2012 05:57:47 +0100 Subject: [Python-checkins] Daily reference leaks (900ee4a04f5e): sum=-1 Message-ID: results for 900ee4a04f5e on branch "default" -------------------------------------------- test_support leaked [0, 0, -1] references, sum=-1 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog66NYmQ', '-x'] From python-checkins at python.org Wed Dec 19 06:40:22 2012 From: python-checkins at python.org (guido.van.rossum) Date: Wed, 19 Dec 2012 06:40:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Strawman_proposal_for_a_flexi?= =?utf-8?q?ble_primitive_to_wait_for_one_of_a_set_of_Futures=2E?= Message-ID: <3YR4gp5sNbzQhR@mail.python.org> http://hg.python.org/peps/rev/827d116d0a35 changeset: 4621:827d116d0a35 user: Guido van Rossum date: Tue Dec 18 21:40:17 2012 -0800 summary: Strawman proposal for a flexible primitive to wait for one of a set of Futures. files: pep-3156.txt | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -536,7 +536,7 @@ - ``writelines(iterable)``. Equivalent to:: for data in iterable: - self.write(data) + self.write(data) - ``write_eof()``. Close the writing end of the connection. Subsequent calls to ``write()`` are not allowed. Once all buffered @@ -838,10 +838,10 @@ caller (likely a transport) must then write code like this:: try: - res = ev.sock_recv(sock, 8192) + res = ev.sock_recv(sock, 8192) except Future as f: - yield from sch.block_future(f) - res = f.result() + yield from sch.block_future(f) + res = f.result() - Do we need a larger vocabulary of operations for combining coroutines and/or futures? E.g. in addition to par() we could have @@ -852,6 +852,15 @@ syntax). Anyway, I think all of these are easy enough to write using ``Task``. + Proposal: ``f = yield from wait_one(fs)`` takes a set of Futures and + sets f to the first of those that is done. (Yes, this requires an + intermediate Future to wait for.) You can then write:: + + while fs: + f = tulip.wait_one(fs) + fs.remove(f) + + - Task or callback priorities? (I hope not.) -- Repository URL: http://hg.python.org/peps From ncoghlan at gmail.com Wed Dec 19 08:24:43 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Wed, 19 Dec 2012 17:24:43 +1000 Subject: [Python-checkins] cpython: Mention OSError instead of IOError in the docs. In-Reply-To: <3YQsVs2mGnzQl0@mail.python.org> References: <3YQsVs2mGnzQl0@mail.python.org> Message-ID: On Wed, Dec 19, 2012 at 7:16 AM, andrew.svetlov wrote: > http://hg.python.org/cpython/rev/a6ea6f803017 > changeset: 80934:a6ea6f803017 > user: Andrew Svetlov > date: Tue Dec 18 23:16:44 2012 +0200 > summary: > Mention OSError instead of IOError in the docs. > > files: > Doc/faq/library.rst | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > > diff --git a/Doc/faq/library.rst b/Doc/faq/library.rst > --- a/Doc/faq/library.rst > +++ b/Doc/faq/library.rst > @@ -209,7 +209,7 @@ > try: > c = sys.stdin.read(1) > print("Got character", repr(c)) > - except IOError: > + except OSError: > pass > finally: > termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) > @@ -222,7 +222,7 @@ > :func:`termios.tcsetattr` turns off stdin's echoing and disables > canonical > mode. :func:`fcntl.fnctl` is used to obtain stdin's file descriptor > flags > and modify them for non-blocking mode. Since reading stdin when it is > empty > - results in an :exc:`IOError`, this error is caught and ignored. > + results in an :exc:`OSError`, this error is caught and ignored. > With any of these changes in the docs, please don't forget to include appropriate "versionchanged" directives. Many people using the Python 3 docs at "docs.python.org/3/" will still be on Python 3.2, and thus relying on the presence of such directives to let them know that while the various OS-related exception names are now just aliases for OSError in 3.3+, the distinctions still matter in 3.2. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Wed Dec 19 12:45:39 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 19 Dec 2012 12:45:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_versionchanged_tag_to_?= =?utf-8?q?faq_=28useless_btw_because_changed_text_is_commented?= Message-ID: <3YRDnH4k2LzQR3@mail.python.org> http://hg.python.org/cpython/rev/e5958a4e52ef changeset: 80943:e5958a4e52ef user: Andrew Svetlov date: Wed Dec 19 13:45:30 2012 +0200 summary: Add versionchanged tag to faq (useless btw because changed text is commented out) files: Doc/faq/library.rst | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Doc/faq/library.rst b/Doc/faq/library.rst --- a/Doc/faq/library.rst +++ b/Doc/faq/library.rst @@ -224,6 +224,10 @@ and modify them for non-blocking mode. Since reading stdin when it is empty results in an :exc:`OSError`, this error is caught and ignored. + .. versionchanged:: 3.3 + *sys.stdin.read* used to raise :exc:`IOError`. Starting from Python 3.3 + :exc:`IOError` is alias for :exc:`OSError`. + Threads ======= -- Repository URL: http://hg.python.org/cpython From andrew.svetlov at gmail.com Wed Dec 19 12:46:07 2012 From: andrew.svetlov at gmail.com (Andrew Svetlov) Date: Wed, 19 Dec 2012 13:46:07 +0200 Subject: [Python-checkins] cpython: Mention OSError instead of IOError in the docs. In-Reply-To: References: <3YQsVs2mGnzQl0@mail.python.org> Message-ID: Done in #e5958a4e52ef On Wed, Dec 19, 2012 at 9:24 AM, Nick Coghlan wrote: > On Wed, Dec 19, 2012 at 7:16 AM, andrew.svetlov > wrote: >> >> http://hg.python.org/cpython/rev/a6ea6f803017 >> changeset: 80934:a6ea6f803017 >> user: Andrew Svetlov >> date: Tue Dec 18 23:16:44 2012 +0200 >> summary: >> Mention OSError instead of IOError in the docs. >> >> files: >> Doc/faq/library.rst | 4 ++-- >> 1 files changed, 2 insertions(+), 2 deletions(-) >> >> >> diff --git a/Doc/faq/library.rst b/Doc/faq/library.rst >> --- a/Doc/faq/library.rst >> +++ b/Doc/faq/library.rst >> @@ -209,7 +209,7 @@ >> try: >> c = sys.stdin.read(1) >> print("Got character", repr(c)) >> - except IOError: >> + except OSError: >> pass >> finally: >> termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) >> @@ -222,7 +222,7 @@ >> :func:`termios.tcsetattr` turns off stdin's echoing and disables >> canonical >> mode. :func:`fcntl.fnctl` is used to obtain stdin's file descriptor >> flags >> and modify them for non-blocking mode. Since reading stdin when it is >> empty >> - results in an :exc:`IOError`, this error is caught and ignored. >> + results in an :exc:`OSError`, this error is caught and ignored. > > > With any of these changes in the docs, please don't forget to include > appropriate "versionchanged" directives. Many people using the Python 3 docs > at "docs.python.org/3/" will still be on Python 3.2, and thus relying on the > presence of such directives to let them know that while the various > OS-related exception names are now just aliases for OSError in 3.3+, the > distinctions still matter in 3.2. > > Cheers, > Nick. > > > -- > Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > -- Thanks, Andrew Svetlov From python-checkins at python.org Wed Dec 19 13:33:46 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 19 Dec 2012 13:33:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316719=3A_Get_rid_?= =?utf-8?q?of_WindowsError=2E_Use_OSError_instead?= Message-ID: <3YRFrp5j01zQmS@mail.python.org> http://hg.python.org/cpython/rev/bb94f6222fef changeset: 80944:bb94f6222fef user: Andrew Svetlov date: Wed Dec 19 14:33:35 2012 +0200 summary: Issue #16719: Get rid of WindowsError. Use OSError instead Patch by Serhiy Storchaka. files: Doc/library/shutil.rst | 7 +- Lib/ctypes/__init__.py | 6 +- Lib/ctypes/test/test_checkretval.py | 2 +- Lib/ctypes/test/test_win32.py | 2 +- Lib/idlelib/EditorWindow.py | 4 +- Lib/importlib/_bootstrap.py | 4 +- Lib/multiprocessing/connection.py | 2 +- Lib/ntpath.py | 4 +- Lib/platform.py | 2 +- Lib/shutil.py | 11 +-- Lib/tarfile.py | 4 +- Lib/test/test_codecs.py | 4 +- Lib/test/test_mmap.py | 2 +- Lib/test/test_os.py | 18 ++-- Lib/test/test_winreg.py | 16 ++-- Lib/test/test_winsound.py | 2 +- Lib/urllib/request.py | 4 +- Lib/webbrowser.py | 2 +- Modules/_ctypes/callproc.c | 36 +++++----- Modules/_multiprocessing/multiprocessing.c | 4 +- Modules/posixmodule.c | 2 +- Objects/unicodeobject.c | 10 +- PC/VC6/build_ssl.py | 2 +- PC/VS7.1/build_ssl.py | 2 +- PC/VS8.0/build_ssl.py | 2 +- PC/winreg.c | 4 +- Python/errors.c | 6 +- Tools/scripts/win_add2path.py | 2 +- 28 files changed, 79 insertions(+), 87 deletions(-) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -393,11 +393,10 @@ errors.extend(err.args[0]) try: copystat(src, dst) - except WindowsError: + except OSError as why: # can't copy file access times on Windows - pass - except OSError as why: - errors.extend((src, dst, str(why))) + if why.winerror is None: + errors.extend((src, dst, str(why))) if errors: raise Error(errors) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -395,7 +395,7 @@ _type_ = "l" # _check_retval_ is called with the function's result when it # is used as restype. It checks for the FAILED bit, and - # raises a WindowsError if it is set. + # raises an OSError if it is set. # # The _check_retval_ method is implemented in C, so that the # method definition itself is not included in the traceback @@ -407,7 +407,7 @@ class OleDLL(CDLL): """This class represents a dll exporting functions using the Windows stdcall calling convention, and returning HRESULT. - HRESULT error values are automatically raised as WindowsError + HRESULT error values are automatically raised as OSError exceptions. """ _func_flags_ = _FUNCFLAG_STDCALL @@ -456,7 +456,7 @@ code = GetLastError() if descr is None: descr = FormatError(code).strip() - return WindowsError(None, descr, None, code) + return OSError(None, descr, None, code) if sizeof(c_uint) == sizeof(c_void_p): c_size_t = c_uint diff --git a/Lib/ctypes/test/test_checkretval.py b/Lib/ctypes/test/test_checkretval.py --- a/Lib/ctypes/test/test_checkretval.py +++ b/Lib/ctypes/test/test_checkretval.py @@ -31,7 +31,7 @@ pass else: def test_oledll(self): - self.assertRaises(WindowsError, + self.assertRaises(OSError, oledll.oleaut32.CreateTypeLib2, 0, None, None) diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py --- a/Lib/ctypes/test/test_win32.py +++ b/Lib/ctypes/test/test_win32.py @@ -40,7 +40,7 @@ # Call functions with invalid arguments, and make sure # that access violations are trapped and raise an # exception. - self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32) + self.assertRaises(OSError, windll.kernel32.GetModuleHandleA, 32) def test_noargs(self): # This is a special case on win32 x64 diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -536,7 +536,7 @@ if sys.platform[:3] == 'win': try: os.startfile(self.help_url) - except WindowsError as why: + except OSError as why: tkMessageBox.showerror(title='Document Start Failure', message=str(why), parent=self.text) else: @@ -845,7 +845,7 @@ if sys.platform[:3] == 'win': try: os.startfile(helpfile) - except WindowsError as why: + except OSError as why: tkMessageBox.showerror(title='Document Start Failure', message=str(why), parent=self.text) else: diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -755,7 +755,7 @@ def _open_registry(cls, key): try: return _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key) - except WindowsError: + except OSError: return _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key) @classmethod @@ -769,7 +769,7 @@ try: with cls._open_registry(key) as hkey: filepath = _winreg.QueryValue(hkey, "") - except WindowsError: + except OSError: return None return filepath diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -676,7 +676,7 @@ 0, _winapi.NULL, _winapi.OPEN_EXISTING, _winapi.FILE_FLAG_OVERLAPPED, _winapi.NULL ) - except WindowsError as e: + except OSError as e: if e.winerror not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY) or _check_timeout(t): raise diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -331,7 +331,7 @@ """Test whether a path exists. Returns True for broken symbolic links""" try: st = os.lstat(path) - except (OSError, WindowsError): + except OSError: return False return True @@ -584,7 +584,7 @@ if path: # Empty path must return current working directory. try: path = _getfullpathname(path) - except WindowsError: + except OSError: pass # Bad path - return unchanged. elif isinstance(path, bytes): path = os.getcwdb() diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -581,7 +581,7 @@ # Discard any type that isn't REG_SZ if type == REG_SZ and name.find("Server") != -1: product_type = VER_NT_SERVER - except WindowsError: + except OSError: # Use default of VER_NT_WORKSTATION pass diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -60,11 +60,6 @@ and unpacking registeries fails""" -try: - WindowsError -except NameError: - WindowsError = None - def copyfileobj(fsrc, fdst, length=16*1024): """copy data from file-like object fsrc to file-like object fdst""" while 1: @@ -334,10 +329,8 @@ try: copystat(src, dst) except OSError as why: - if WindowsError is not None and isinstance(why, WindowsError): - # Copying file access times may fail on Windows - pass - else: + # Copying file access times may fail on Windows + if why.winerror is None: errors.append((src, dst, str(why))) if errors: raise Error(errors) diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -56,9 +56,9 @@ # os.symlink on Windows prior to 6.0 raises NotImplementedError symlink_exception = (AttributeError, NotImplementedError) try: - # WindowsError (1314) will be raised if the caller does not hold the + # OSError (winerror=1314) will be raised if the caller does not hold the # SeCreateSymbolicLinkPrivilege privilege - symlink_exception += (WindowsError,) + symlink_exception += (OSError,) except NameError: pass diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -2035,8 +2035,8 @@ def test_invalid_code_page(self): self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a') self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a') - self.assertRaises(WindowsError, codecs.code_page_encode, 123, 'a') - self.assertRaises(WindowsError, codecs.code_page_decode, 123, b'a') + self.assertRaises(OSError, codecs.code_page_encode, 123, 'a') + self.assertRaises(OSError, codecs.code_page_decode, 123, b'a') def test_code_page_name(self): self.assertRaisesRegex(UnicodeEncodeError, 'cp932', diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -658,7 +658,7 @@ m = mmap.mmap(f.fileno(), 0) f.close() try: - m.resize(0) # will raise WindowsError + m.resize(0) # will raise OSError except: pass try: diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -468,9 +468,9 @@ # Verify that an open file can be stat'ed try: os.stat(r"c:\pagefile.sys") - except WindowsError as e: - if e.errno == 2: # file does not exist; cannot run test - return + except FileNotFoundError: + pass # file does not exist; cannot run test + except OSError as e: self.fail("Could not stat pagefile.sys") @unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()") @@ -1042,27 +1042,27 @@ class Win32ErrorTests(unittest.TestCase): def test_rename(self): - self.assertRaises(WindowsError, os.rename, support.TESTFN, support.TESTFN+".bak") + self.assertRaises(OSError, os.rename, support.TESTFN, support.TESTFN+".bak") def test_remove(self): - self.assertRaises(WindowsError, os.remove, support.TESTFN) + self.assertRaises(OSError, os.remove, support.TESTFN) def test_chdir(self): - self.assertRaises(WindowsError, os.chdir, support.TESTFN) + self.assertRaises(OSError, os.chdir, support.TESTFN) def test_mkdir(self): f = open(support.TESTFN, "w") try: - self.assertRaises(WindowsError, os.mkdir, support.TESTFN) + self.assertRaises(OSError, os.mkdir, support.TESTFN) finally: f.close() os.unlink(support.TESTFN) def test_utime(self): - self.assertRaises(WindowsError, os.utime, support.TESTFN, None) + self.assertRaises(OSError, os.utime, support.TESTFN, None) def test_chmod(self): - self.assertRaises(WindowsError, os.chmod, support.TESTFN, 0) + self.assertRaises(OSError, os.chmod, support.TESTFN, 0) class TestInvalidFD(unittest.TestCase): singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat", diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -54,13 +54,13 @@ def delete_tree(self, root, subkey): try: hkey = OpenKey(root, subkey, KEY_ALL_ACCESS) - except WindowsError: + except OSError: # subkey does not exist return while True: try: subsubkey = EnumKey(hkey, 0) - except WindowsError: + except OSError: # no more subkeys break self.delete_tree(hkey, subsubkey) @@ -176,7 +176,7 @@ try: key = OpenKey(root_key, test_key_name) self.fail("Could open the non-existent key") - except WindowsError: # Use this error name this time + except OSError: # Use this error name this time pass def _test_all(self, root_key, subkeystr="sub_key"): @@ -227,7 +227,7 @@ def test_inexistant_remote_registry(self): connect = lambda: ConnectRegistry("abcdefghijkl", HKEY_CURRENT_USER) - self.assertRaises(WindowsError, connect) + self.assertRaises(OSError, connect) def testExpandEnvironmentStrings(self): r = ExpandEnvironmentStrings("%windir%\\test") @@ -239,8 +239,8 @@ try: with ConnectRegistry(None, HKEY_LOCAL_MACHINE) as h: self.assertNotEqual(h.handle, 0) - raise WindowsError - except WindowsError: + raise OSError + except OSError: self.assertEqual(h.handle, 0) def test_changing_value(self): @@ -375,7 +375,7 @@ open_fail = lambda: OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0, KEY_READ | KEY_WOW64_64KEY) - self.assertRaises(WindowsError, open_fail) + self.assertRaises(OSError, open_fail) # Now explicitly open the 64-bit version of the key with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0, @@ -415,7 +415,7 @@ open_fail = lambda: OpenKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0, KEY_READ | KEY_WOW64_64KEY) - self.assertRaises(WindowsError, open_fail) + self.assertRaises(OSError, open_fail) # Make sure the 32-bit key is actually there with OpenKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0, diff --git a/Lib/test/test_winsound.py b/Lib/test/test_winsound.py --- a/Lib/test/test_winsound.py +++ b/Lib/test/test_winsound.py @@ -22,7 +22,7 @@ key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound)) return winreg.EnumValue(key, 0)[1] != "" - except WindowsError: + except OSError: return False class BeepTest(unittest.TestCase): diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2573,7 +2573,7 @@ proxies['https'] = 'https://%s' % proxyServer proxies['ftp'] = 'ftp://%s' % proxyServer internetSettings.Close() - except (WindowsError, ValueError, TypeError): + except (OSError, ValueError, TypeError): # Either registry key not found etc, or the value in an # unexpected format. # proxies already set up to be empty so nothing to do @@ -2603,7 +2603,7 @@ proxyOverride = str(winreg.QueryValueEx(internetSettings, 'ProxyOverride')[0]) # ^^^^ Returned as Unicode but problems if not converted to ASCII - except WindowsError: + except OSError: return 0 if not proxyEnable or not proxyOverride: return 0 diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -534,7 +534,7 @@ def open(self, url, new=0, autoraise=True): try: os.startfile(url) - except WindowsError: + except OSError: # [Error 22] No application is associated with the specified # file for this operation: '' return False diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -257,18 +257,18 @@ to a virtual address for which it does not have the appropriate access. */ if (pr->ExceptionInformation[0] == 0) - PyErr_Format(PyExc_WindowsError, + PyErr_Format(PyExc_OSError, "exception: access violation reading %p", pr->ExceptionInformation[1]); else - PyErr_Format(PyExc_WindowsError, + PyErr_Format(PyExc_OSError, "exception: access violation writing %p", pr->ExceptionInformation[1]); break; case EXCEPTION_BREAKPOINT: /* A breakpoint was encountered. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: breakpoint encountered"); break; @@ -278,14 +278,14 @@ alignment. For example, 16-bit values must be aligned on 2-byte boundaries, 32-bit values on 4-byte boundaries, and so on. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: datatype misalignment"); break; case EXCEPTION_SINGLE_STEP: /* A trace trap or other single-instruction mechanism signaled that one instruction has been executed. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: single step"); break; @@ -293,7 +293,7 @@ /* The thread attempted to access an array element that is out of bounds, and the underlying hardware supports bounds checking. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: array bounds exceeded"); break; @@ -302,28 +302,28 @@ is denormal. A denormal value is one that is too small to represent as a standard floating-point value. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: floating-point operand denormal"); break; case EXCEPTION_FLT_DIVIDE_BY_ZERO: /* The thread attempted to divide a floating-point value by a floating-point divisor of zero. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: float divide by zero"); break; case EXCEPTION_FLT_INEXACT_RESULT: /* The result of a floating-point operation cannot be represented exactly as a decimal fraction. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: float inexact"); break; case EXCEPTION_FLT_INVALID_OPERATION: /* This exception represents any floating-point exception not included in this list. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: float invalid operation"); break; @@ -331,21 +331,21 @@ /* The exponent of a floating-point operation is greater than the magnitude allowed by the corresponding type. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: float overflow"); break; case EXCEPTION_FLT_STACK_CHECK: /* The stack overflowed or underflowed as the result of a floating-point operation. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: stack over/underflow"); break; case EXCEPTION_STACK_OVERFLOW: /* The stack overflowed or underflowed as the result of a floating-point operation. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: stack overflow"); break; @@ -353,21 +353,21 @@ /* The exponent of a floating-point operation is less than the magnitude allowed by the corresponding type. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: float underflow"); break; case EXCEPTION_INT_DIVIDE_BY_ZERO: /* The thread attempted to divide an integer value by an integer divisor of zero. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: integer divide by zero"); break; case EXCEPTION_INT_OVERFLOW: /* The result of an integer operation caused a carry out of the most significant bit of the result. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: integer overflow"); break; @@ -375,14 +375,14 @@ /* The thread attempted to execute an instruction whose operation is not allowed in the current machine mode. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: priviledged instruction"); break; case EXCEPTION_NONCONTINUABLE_EXCEPTION: /* The thread attempted to continue execution after a noncontinuable exception occurred. */ - PyErr_SetString(PyExc_WindowsError, + PyErr_SetString(PyExc_OSError, "exception: nocontinuable"); break; diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c --- a/Modules/_multiprocessing/multiprocessing.c +++ b/Modules/_multiprocessing/multiprocessing.c @@ -21,12 +21,12 @@ #ifdef MS_WINDOWS case MP_STANDARD_ERROR: if (Type == NULL) - Type = PyExc_WindowsError; + Type = PyExc_OSError; PyErr_SetExcFromWindowsErr(Type, 0); break; case MP_SOCKET_ERROR: if (Type == NULL) - Type = PyExc_WindowsError; + Type = PyExc_OSError; PyErr_SetExcFromWindowsErr(Type, WSAGetLastError()); break; #else /* !MS_WINDOWS */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1041,7 +1041,7 @@ errno = GetLastError(); if (filename) return PyErr_SetExcFromWindowsErrWithFilenameObject( - PyExc_WindowsError, + PyExc_OSError, errno, filename); else diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -6589,8 +6589,8 @@ * Decode a byte string from a Windows code page into unicode object in strict * mode. * - * Returns consumed size if succeed, returns -2 on decode error, or raise a - * WindowsError and returns -1 on other error. + * Returns consumed size if succeed, returns -2 on decode error, or raise an + * OSError and returns -1 on other error. */ static int decode_code_page_strict(UINT code_page, @@ -6641,7 +6641,7 @@ * Decode a byte string from a code page into unicode object with an error * handler. * - * Returns consumed size if succeed, or raise a WindowsError or + * Returns consumed size if succeed, or raise an OSError or * UnicodeDecodeError exception and returns -1 on error. */ static int @@ -6897,7 +6897,7 @@ * mode. * * Returns consumed characters if succeed, returns -2 on encode error, or raise - * a WindowsError and returns -1 on other error. + * an OSError and returns -1 on other error. */ static int encode_code_page_strict(UINT code_page, PyObject **outbytes, @@ -6993,7 +6993,7 @@ * Encode a Unicode string to a Windows code page into a byte string using a * error handler. * - * Returns consumed characters if succeed, or raise a WindowsError and returns + * Returns consumed characters if succeed, or raise an OSError and returns * -1 on other error. */ static int diff --git a/PC/VC6/build_ssl.py b/PC/VC6/build_ssl.py --- a/PC/VC6/build_ssl.py +++ b/PC/VC6/build_ssl.py @@ -66,7 +66,7 @@ # note: do not abspath s; the build will fail if any # higher up directory name has spaces in it. fnames = os.listdir(s) - except os.error: + except OSError: fnames = [] for fname in fnames: fqn = os.path.join(s, fname) diff --git a/PC/VS7.1/build_ssl.py b/PC/VS7.1/build_ssl.py --- a/PC/VS7.1/build_ssl.py +++ b/PC/VS7.1/build_ssl.py @@ -62,7 +62,7 @@ # note: do not abspath s; the build will fail if any # higher up directory name has spaces in it. fnames = os.listdir(s) - except os.error: + except OSError: fnames = [] for fname in fnames: fqn = os.path.join(s, fname) diff --git a/PC/VS8.0/build_ssl.py b/PC/VS8.0/build_ssl.py --- a/PC/VS8.0/build_ssl.py +++ b/PC/VS8.0/build_ssl.py @@ -71,7 +71,7 @@ # note: do not abspath s; the build will fail if any # higher up directory name has spaces in it. fnames = os.listdir(s) - except os.error: + except OSError: fnames = [] for fname in fnames: fqn = os.path.join(s, fname) diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -1794,9 +1794,9 @@ if (PyDict_SetItemString(d, "HKEYType", (PyObject *)&PyHKEY_Type) != 0) return NULL; - Py_INCREF(PyExc_WindowsError); + Py_INCREF(PyExc_OSError); if (PyDict_SetItemString(d, "error", - PyExc_WindowsError) != 0) + PyExc_OSError) != 0) return NULL; /* Add the relevant constants */ diff --git a/Python/errors.c b/Python/errors.c --- a/Python/errors.c +++ b/Python/errors.c @@ -588,7 +588,7 @@ PyObject *PyErr_SetFromWindowsErr(int ierr) { - return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError, + return PyErr_SetExcFromWindowsErrWithFilename(PyExc_OSError, ierr, NULL); } PyObject *PyErr_SetFromWindowsErrWithFilename( @@ -597,7 +597,7 @@ { PyObject *name = filename ? PyUnicode_DecodeFSDefault(filename) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( - PyExc_WindowsError, + PyExc_OSError, ierr, name); Py_XDECREF(name); return result; @@ -611,7 +611,7 @@ PyUnicode_FromUnicode(filename, wcslen(filename)) : NULL; PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( - PyExc_WindowsError, + PyExc_OSError, ierr, name); Py_XDECREF(name); return result; diff --git a/Tools/scripts/win_add2path.py b/Tools/scripts/win_add2path.py --- a/Tools/scripts/win_add2path.py +++ b/Tools/scripts/win_add2path.py @@ -30,7 +30,7 @@ with winreg.CreateKey(HKCU, ENV) as key: try: envpath = winreg.QueryValueEx(key, PATH)[0] - except WindowsError: + except OSError: envpath = DEFAULT paths = [envpath] -- Repository URL: http://hg.python.org/cpython From storchaka at gmail.com Wed Dec 19 18:05:28 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 19 Dec 2012 19:05:28 +0200 Subject: [Python-checkins] cpython: Mention OSError instead of IOError in the docs. In-Reply-To: References: <3YQsVs2mGnzQl0@mail.python.org> Message-ID: On 19.12.12 09:24, Nick Coghlan wrote: > With any of these changes in the docs, please don't forget to include > appropriate "versionchanged" directives. Many people using the Python 3 > docs at "docs.python.org/3/ " will still be > on Python 3.2, and thus relying on the presence of such directives to > let them know that while the various OS-related exception names are now > just aliases for OSError in 3.3+, the distinctions still matter in 3.2. I also propose to apply all this documentation changes to 3.3. From python-checkins at python.org Wed Dec 19 19:00:02 2012 From: python-checkins at python.org (guido.van.rossum) Date: Wed, 19 Dec 2012 19:00:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?cGVwczogQWRkIHN0b3AoKSwgcnVuX29uY2Uo?= =?utf-8?b?KSwgcnVuX3VudGlsX2NvbXBsZXRlKCksIGNhbGxfcmVwZWF0ZWRseSgpLg==?= Message-ID: <3YRP5G51PczRgL@mail.python.org> http://hg.python.org/peps/rev/842c42cfd1c7 changeset: 4622:842c42cfd1c7 user: Guido van Rossum date: Wed Dec 19 09:59:50 2012 -0800 summary: Add stop(), run_once(), run_until_complete(), call_repeatedly(). Rename DelayedCall to Handler. files: pep-3156.txt | 57 +++++++++++++++++++++++++++------------ 1 files changed, 39 insertions(+), 18 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -169,22 +169,46 @@ Note: run() blocks until the termination condition is met. - TBD: run() may need an argument to start some work? +- ``stop()``. Stops the event loop as soon as it is convenient. It + is fine to restart the loop with ``run()`` (or one of its variants) + subsequently. (TBD: How should this interact with ``run_once()`` + and ``run_until_complete()``?) -- TBD: Do we need an API for stopping the event loop, given that we - have the termination condition? Is the termination condition - compatible with other frameworks? + Note: How soon exactly is up to the implementation. It is + reasonable to implement this so that ``run()`` simply stops calling + ``run_once()`` when this is called. -- TBD: Do we need an API to run the event loop for a little while - (e.g. a single iteration)? If so, exactly what should it do? +- ``run_until_complete(future, timeout=None)``. Runs the event loop + until a Future is done. If a timeout is given, it waits at most + that long. If the Future is done, its result is returned, or its + exception is raised; if the timeout expires before the Future is + done, TimeoutError is raised (but the Future is not cancelled). + This cannot be called when the event loop is already running. + + Note: This API is most useful for tests and the like. It should not + be used as a substitute for ``yield from future`` or other ways to + wait for a Future (e.g. registering a done callback). + +- ``run_once(timeout=None)``. Run the event loop for a little while. + If a timeout is given, an I/O poll will be given at most that timeout; + otherwise, an I/O poll is not constrained in time. + + Note: Exactlly what this does is up to the implementation. One + constraint: if a callback immediately schedules itself using + ``call_soon()``, ``run_once()`` should still return. - ``call_later(delay, callback, *args)``. Arrange for ``callback(*args)`` to be called approximately ``delay`` seconds in the future, once, unless canceled. As usual in Python, ``delay`` may be a floating point number to represent smaller intervals. Returns - a ``DelayedCall`` object representing the callback, whose + a ``Handler`` object representing the callback, whose ``cancel()`` method can be used to cancel the callback. +- ``call_repeatedly(interval, callback, **args)``. Like ``call_later()`` + but calls the callback repeatedly, every ``interval`` seconds, + until the ``Handler`` returned is cancelled. The first call is in + ``interval`` seconds. May be a float. + - ``call_soon(callback, *args)``. Equivalent to ``call_later(0, callback, *args)``. @@ -197,8 +221,8 @@ ``ev.call_soon_threadsafe(ev.call_later, when, callback, *args)``.) - TBD: A way to register a callback that is already wrapped in a - ``DelayedCall``. Maybe ``call_soon()`` could just check - ``isinstance(callback, DelayedCall)``? It should silently skip + ``Handler``. Maybe ``call_soon()`` could just check + ``isinstance(callback, Handler)``? It should silently skip a canceled callback. - TBD: Repeatable timers. @@ -287,12 +311,12 @@ - ``add_reader(fd, callback, *args)``. Arrange for ``callback(*args)`` to be called whenever file descriptor ``fd`` is - ready for reading. Returns a ``DelayedCall`` object which can be + ready for reading. Returns a ``Handler`` object which can be used to cancel the callback. Note that, unlike ``call_later()``, the callback may be called many times. Calling ``add_reader()`` again for the same file descriptor implicitly cancels the previous callback for that file descriptor. (TBD: Returning a - ``DelayedCall`` that can be cancelled seems awkward. Let's forget + ``Handler`` that can be cancelled seems awkward. Let's forget about that.) (TBD: Change this to raise an exception if a handler is already set.) @@ -303,7 +327,7 @@ descriptor ``fd``, if one is set. A no-op if no callback is currently set for the file descriptor. (The reason for providing this alternate interface is that it is often more convenient to - remember the file descriptor than to remember the ``DelayedCall`` + remember the file descriptor than to remember the ``Handler`` object.) (TBD: Return ``True`` if a handler was removed, ``False`` if not.) @@ -391,13 +415,13 @@ and ``SystemExit``; it is usually unwise to treat these the same as most other exceptions.) -The DelayedCall Class ---------------------- +The Handler Class +----------------- The various methods for registering callbacks (e.g. ``call_later()``) all return an object representing the registration that can be used to cancel the callback. For want of a better name this object is called -a ``DelayedCall``, although the user never needs to instantiate +a ``Handler``, although the user never needs to instantiate instances of this class. There is one public method: - ``cancel()``. Attempt to cancel the callback. @@ -423,9 +447,6 @@ TBD: Public attribute recording the realtime value when the callback is scheduled? (Since this is needed anyway for storing it in a heap.) -TBD: A better name for the class? Reasonable suggestions so far: -``Callback``, ``Call``, ``Handler`` (my current favorite), ``Thunk``. - Futures ------- -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Wed Dec 19 20:50:48 2012 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 19 Dec 2012 20:50:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Small_cleanup_?= =?utf-8?q?in_test=5Fftplib?= Message-ID: <3YRRY41JQrzRk4@mail.python.org> http://hg.python.org/cpython/rev/62790872a83a changeset: 80945:62790872a83a branch: 3.3 parent: 80941:13d8c33de8ff user: Antoine Pitrou date: Wed Dec 19 20:44:02 2012 +0100 summary: Small cleanup in test_ftplib files: Lib/test/test_ftplib.py | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -896,39 +896,40 @@ def setUp(self): self.evt = threading.Event() self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.settimeout(10) + self.sock.settimeout(20) self.port = support.bind_port(self.sock) - threading.Thread(target=self.server, args=(self.evt,self.sock)).start() + self.server_thread = threading.Thread(target=self.server) + self.server_thread.start() # Wait for the server to be ready. self.evt.wait() self.evt.clear() + self.old_port = ftplib.FTP.port ftplib.FTP.port = self.port def tearDown(self): - self.evt.wait() - self.sock.close() + ftplib.FTP.port = self.old_port + self.server_thread.join() - def server(self, evt, serv): + def server(self): # This method sets the evt 3 times: # 1) when the connection is ready to be accepted. # 2) when it is safe for the caller to close the connection # 3) when we have closed the socket - serv.listen(5) + self.sock.listen(5) # (1) Signal the caller that we are ready to accept the connection. - evt.set() + self.evt.set() try: - conn, addr = serv.accept() + conn, addr = self.sock.accept() except socket.timeout: pass else: - conn.send(b"1 Hola mundo\n") + conn.sendall(b"1 Hola mundo\n") + conn.shutdown(socket.SHUT_WR) # (2) Signal the caller that it is safe to close the socket. - evt.set() + self.evt.set() conn.close() finally: - serv.close() - # (3) Signal the caller that we are done. - evt.set() + self.sock.close() def testTimeoutDefault(self): # default -- use global socket timeout -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 20:50:49 2012 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 19 Dec 2012 20:50:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Small_cleanup_in_test=5Fftplib?= Message-ID: <3YRRY53xmVzRkk@mail.python.org> http://hg.python.org/cpython/rev/e3f481deaed5 changeset: 80946:e3f481deaed5 parent: 80944:bb94f6222fef parent: 80945:62790872a83a user: Antoine Pitrou date: Wed Dec 19 20:44:37 2012 +0100 summary: Small cleanup in test_ftplib files: Lib/test/test_ftplib.py | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -896,39 +896,40 @@ def setUp(self): self.evt = threading.Event() self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.settimeout(10) + self.sock.settimeout(20) self.port = support.bind_port(self.sock) - threading.Thread(target=self.server, args=(self.evt,self.sock)).start() + self.server_thread = threading.Thread(target=self.server) + self.server_thread.start() # Wait for the server to be ready. self.evt.wait() self.evt.clear() + self.old_port = ftplib.FTP.port ftplib.FTP.port = self.port def tearDown(self): - self.evt.wait() - self.sock.close() + ftplib.FTP.port = self.old_port + self.server_thread.join() - def server(self, evt, serv): + def server(self): # This method sets the evt 3 times: # 1) when the connection is ready to be accepted. # 2) when it is safe for the caller to close the connection # 3) when we have closed the socket - serv.listen(5) + self.sock.listen(5) # (1) Signal the caller that we are ready to accept the connection. - evt.set() + self.evt.set() try: - conn, addr = serv.accept() + conn, addr = self.sock.accept() except socket.timeout: pass else: - conn.send(b"1 Hola mundo\n") + conn.sendall(b"1 Hola mundo\n") + conn.shutdown(socket.SHUT_WR) # (2) Signal the caller that it is safe to close the socket. - evt.set() + self.evt.set() conn.close() finally: - serv.close() - # (3) Signal the caller that we are done. - evt.set() + self.sock.close() def testTimeoutDefault(self): # default -- use global socket timeout -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 21:47:15 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 19 Dec 2012 21:47:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_revert_comment?= =?utf-8?q?_wording_=28=2316714=29?= Message-ID: <3YRSpC6pNkzNmy@mail.python.org> http://hg.python.org/cpython/rev/0a5c5399f638 changeset: 80947:0a5c5399f638 branch: 2.7 parent: 80931:8c2635afbfe1 user: Andrew Svetlov date: Wed Dec 19 22:47:05 2012 +0200 summary: revert comment wording (#16714) files: Lib/email/header.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/email/header.py b/Lib/email/header.py --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -103,7 +103,7 @@ dec = email.base64mime.decode(encoded) except binascii.Error: # Turn this into a higher level exception. BAW: Right - # now we raise the lower level exception away but + # now we throw the lower level exception away but # when/if we get exception chaining, we'll preserve it. raise HeaderParseError if dec is None: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 21:55:55 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 19 Dec 2012 21:55:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_replace_threw_?= =?utf-8?q?with_raised_=28=2316714=29?= Message-ID: <3YRT0C1tjtzRkk@mail.python.org> http://hg.python.org/cpython/rev/b227f8f7242d changeset: 80948:b227f8f7242d branch: 2.7 user: Andrew Svetlov date: Wed Dec 19 22:49:01 2012 +0200 summary: replace threw with raised (#16714) files: Lib/test/test_urllib2.py | 2 +- Lib/test/test_winreg.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1148,7 +1148,7 @@ ) def test_basic_and_digest_auth_handlers(self): - # HTTPDigestAuthHandler threw an exception if it couldn't handle a 40* + # HTTPDigestAuthHandler raised an exception if it couldn't handle a 40* # response (http://python.org/sf/1479302), where it should instead # return None to allow another handler (especially # HTTPBasicAuthHandler) to handle the response. diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -267,7 +267,7 @@ def test_long_key(self): # Issue2810, in 2.6 and 3.1 when the key name was exactly 256 - # characters, EnumKey threw "WindowsError: More data is + # characters, EnumKey raised "WindowsError: More data is # available" name = 'x'*256 try: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 21:55:56 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 19 Dec 2012 21:55:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_replace_threw_?= =?utf-8?q?with_raised_=28=2316714=29?= Message-ID: <3YRT0D4FXQzRl9@mail.python.org> http://hg.python.org/cpython/rev/74da2dbb5e50 changeset: 80949:74da2dbb5e50 branch: 3.2 parent: 80928:fdf907708f49 user: Andrew Svetlov date: Wed Dec 19 22:49:25 2012 +0200 summary: replace threw with raised (#16714) files: Lib/test/test_urllib2.py | 2 +- Lib/test/test_winreg.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1252,7 +1252,7 @@ ) def test_basic_and_digest_auth_handlers(self): - # HTTPDigestAuthHandler threw an exception if it couldn't handle a 40* + # HTTPDigestAuthHandler raised an exception if it couldn't handle a 40* # response (http://python.org/sf/1479302), where it should instead # return None to allow another handler (especially # HTTPBasicAuthHandler) to handle the response. diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -277,7 +277,7 @@ def test_long_key(self): # Issue2810, in 2.6 and 3.1 when the key name was exactly 256 - # characters, EnumKey threw "WindowsError: More data is + # characters, EnumKey raised "WindowsError: More data is # available" name = 'x'*256 try: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 21:55:57 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 19 Dec 2012 21:55:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_replace_threw_with_raised_=28=2316714=29?= Message-ID: <3YRT0F6XQjzRlM@mail.python.org> http://hg.python.org/cpython/rev/55d86476d048 changeset: 80950:55d86476d048 branch: 3.3 parent: 80945:62790872a83a parent: 80949:74da2dbb5e50 user: Andrew Svetlov date: Wed Dec 19 22:54:47 2012 +0200 summary: replace threw with raised (#16714) files: Lib/pkgutil.py | 2 +- Lib/test/test_urllib2.py | 2 +- Lib/test/test_winreg.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -505,7 +505,7 @@ except (ImportError, AttributeError, TypeError, ValueError) as ex: # This hack fixes an impedance mismatch between pkgutil and # importlib, where the latter raises other errors for cases where - # pkgutil previously threw ImportError + # pkgutil previously raised ImportError msg = "Error while finding loader for {!r} ({}: {})" raise ImportError(msg.format(fullname, type(ex), ex)) from ex diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1288,7 +1288,7 @@ ) def test_basic_and_digest_auth_handlers(self): - # HTTPDigestAuthHandler threw an exception if it couldn't handle a 40* + # HTTPDigestAuthHandler raised an exception if it couldn't handle a 40* # response (http://python.org/sf/1479302), where it should instead # return None to allow another handler (especially # HTTPBasicAuthHandler) to handle the response. diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -277,7 +277,7 @@ def test_long_key(self): # Issue2810, in 2.6 and 3.1 when the key name was exactly 256 - # characters, EnumKey threw "WindowsError: More data is + # characters, EnumKey raised "WindowsError: More data is # available" name = 'x'*256 try: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 21:55:59 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 19 Dec 2012 21:55:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_replace_threw_with_raised_=28=2316714=29?= Message-ID: <3YRT0H1sP6zRkk@mail.python.org> http://hg.python.org/cpython/rev/3594175c6860 changeset: 80951:3594175c6860 parent: 80946:e3f481deaed5 parent: 80950:55d86476d048 user: Andrew Svetlov date: Wed Dec 19 22:55:40 2012 +0200 summary: replace threw with raised (#16714) files: Lib/pkgutil.py | 2 +- Lib/test/test_urllib2.py | 2 +- Lib/test/test_winreg.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -503,7 +503,7 @@ except (ImportError, AttributeError, TypeError, ValueError) as ex: # This hack fixes an impedance mismatch between pkgutil and # importlib, where the latter raises other errors for cases where - # pkgutil previously threw ImportError + # pkgutil previously raised ImportError msg = "Error while finding loader for {!r} ({}: {})" raise ImportError(msg.format(fullname, type(ex), ex)) from ex diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1302,7 +1302,7 @@ ) def test_basic_and_digest_auth_handlers(self): - # HTTPDigestAuthHandler threw an exception if it couldn't handle a 40* + # HTTPDigestAuthHandler raised an exception if it couldn't handle a 40* # response (http://python.org/sf/1479302), where it should instead # return None to allow another handler (especially # HTTPBasicAuthHandler) to handle the response. diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -277,7 +277,7 @@ def test_long_key(self): # Issue2810, in 2.6 and 3.1 when the key name was exactly 256 - # characters, EnumKey threw "WindowsError: More data is + # characters, EnumKey raised "WindowsError: More data is # available" name = 'x'*256 try: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 22:18:01 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 19 Dec 2012 22:18:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_update_importlib=2Eh?= Message-ID: <3YRTTj6j23zQnB@mail.python.org> http://hg.python.org/cpython/rev/4d9f76cd0439 changeset: 80952:4d9f76cd0439 parent: 80946:e3f481deaed5 user: Benjamin Peterson date: Wed Dec 19 15:16:51 2012 -0600 summary: update importlib.h files: Python/importlib.h | 5307 +++++++++++++++---------------- 1 files changed, 2653 insertions(+), 2654 deletions(-) diff --git a/Python/importlib.h b/Python/importlib.h --- a/Python/importlib.h +++ b/Python/importlib.h [stripped] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 22:18:03 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 19 Dec 2012 22:18:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3YRTTl2CgzzRlM@mail.python.org> http://hg.python.org/cpython/rev/4f3df962c9fb changeset: 80953:4f3df962c9fb parent: 80952:4d9f76cd0439 parent: 80951:3594175c6860 user: Benjamin Peterson date: Wed Dec 19 15:17:43 2012 -0600 summary: merge heads files: Lib/pkgutil.py | 2 +- Lib/test/test_urllib2.py | 2 +- Lib/test/test_winreg.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -503,7 +503,7 @@ except (ImportError, AttributeError, TypeError, ValueError) as ex: # This hack fixes an impedance mismatch between pkgutil and # importlib, where the latter raises other errors for cases where - # pkgutil previously threw ImportError + # pkgutil previously raised ImportError msg = "Error while finding loader for {!r} ({}: {})" raise ImportError(msg.format(fullname, type(ex), ex)) from ex diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1302,7 +1302,7 @@ ) def test_basic_and_digest_auth_handlers(self): - # HTTPDigestAuthHandler threw an exception if it couldn't handle a 40* + # HTTPDigestAuthHandler raised an exception if it couldn't handle a 40* # response (http://python.org/sf/1479302), where it should instead # return None to allow another handler (especially # HTTPBasicAuthHandler) to handle the response. diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -277,7 +277,7 @@ def test_long_key(self): # Issue2810, in 2.6 and 3.1 when the key name was exactly 256 - # characters, EnumKey threw "WindowsError: More data is + # characters, EnumKey raised "WindowsError: More data is # available" name = 'x'*256 try: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 22:29:10 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 19 Dec 2012 22:29:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_try_to_call_?= =?utf-8?b?X19ieXRlc19fIGJlZm9yZSBfX2luZGV4X18gKGNsb3NlcyAjMTY3MjIp?= Message-ID: <3YRTkZ6FmwzMkl@mail.python.org> http://hg.python.org/cpython/rev/c744b6f8a09a changeset: 80954:c744b6f8a09a branch: 3.3 parent: 80950:55d86476d048 user: Benjamin Peterson date: Wed Dec 19 15:27:41 2012 -0600 summary: try to call __bytes__ before __index__ (closes #16722) files: Lib/test/test_bytes.py | 6 +++++ Misc/NEWS | 3 ++ Objects/bytesobject.c | 33 +++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) 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 @@ -701,6 +701,12 @@ def __bytes__(self): return None self.assertRaises(TypeError, bytes, A()) + class A: + def __bytes__(self): + return b'a' + def __index__(self): + return 42 + self.assertEqual(bytes(A()), b'a') # Test PyBytes_FromFormat() def test_from_format(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #16722: In the bytes() constructor, try to call __bytes__ on the + argument before __index__. + - Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero. diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2505,8 +2505,10 @@ const char *encoding = NULL; const char *errors = NULL; PyObject *new = NULL; + PyObject *func; Py_ssize_t size; static char *kwlist[] = {"source", "encoding", "errors", 0}; + _Py_IDENTIFIER(__bytes__); if (type != &PyBytes_Type) return str_subtype_new(type, args, kwds); @@ -2536,6 +2538,28 @@ assert(PyBytes_Check(new)); return new; } + + /* We'd like to call PyObject_Bytes here, but we need to check for an + integer argument before deferring to PyBytes_FromObject, something + PyObject_Bytes doesn't do. */ + func = _PyObject_LookupSpecial(x, &PyId___bytes__); + if (func != NULL) { + new = PyObject_CallFunctionObjArgs(func, NULL); + Py_DECREF(func); + if (new == NULL) + return NULL; + if (!PyBytes_Check(new)) { + PyErr_Format(PyExc_TypeError, + "__bytes__ returned non-bytes (type %.200s)", + Py_TYPE(new)->tp_name); + Py_DECREF(new); + return NULL; + } + return new; + } + else if (PyErr_Occurred()) + return NULL; + /* Is it an integer? */ size = PyNumber_AsSsize_t(x, PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { @@ -2549,12 +2573,10 @@ } else { new = PyBytes_FromStringAndSize(NULL, size); - if (new == NULL) { + if (new == NULL) return NULL; - } - if (size > 0) { + if (size > 0) memset(((PyBytesObject*)new)->ob_sval, 0, size); - } return new; } @@ -2564,7 +2586,8 @@ "encoding or errors without a string argument"); return NULL; } - return PyObject_Bytes(x); + + return PyBytes_FromObject(x); } PyObject * -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 19 22:29:12 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 19 Dec 2012 22:29:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4zICgjMTY3MjIp?= Message-ID: <3YRTkc1hC6zRf4@mail.python.org> http://hg.python.org/cpython/rev/7c717d423160 changeset: 80955:7c717d423160 parent: 80953:4f3df962c9fb parent: 80954:c744b6f8a09a user: Benjamin Peterson date: Wed Dec 19 15:28:46 2012 -0600 summary: merge 3.3 (#16722) files: Lib/test/test_bytes.py | 6 +++++ Misc/NEWS | 3 ++ Objects/bytesobject.c | 33 +++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) 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 @@ -715,6 +715,12 @@ def __bytes__(self): return None self.assertRaises(TypeError, bytes, A()) + class A: + def __bytes__(self): + return b'a' + def __index__(self): + return 42 + self.assertEqual(bytes(A()), b'a') # Test PyBytes_FromFormat() def test_from_format(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #16722: In the bytes() constructor, try to call __bytes__ on the + argument before __index__. + - Issue #16421: loading multiple modules from one shared object is now handled correctly (previously, the first module loaded from that file was silently returned). Patch by V?clav ?milauer. diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2428,8 +2428,10 @@ const char *encoding = NULL; const char *errors = NULL; PyObject *new = NULL; + PyObject *func; Py_ssize_t size; static char *kwlist[] = {"source", "encoding", "errors", 0}; + _Py_IDENTIFIER(__bytes__); if (type != &PyBytes_Type) return str_subtype_new(type, args, kwds); @@ -2459,6 +2461,28 @@ assert(PyBytes_Check(new)); return new; } + + /* We'd like to call PyObject_Bytes here, but we need to check for an + integer argument before deferring to PyBytes_FromObject, something + PyObject_Bytes doesn't do. */ + func = _PyObject_LookupSpecial(x, &PyId___bytes__); + if (func != NULL) { + new = PyObject_CallFunctionObjArgs(func, NULL); + Py_DECREF(func); + if (new == NULL) + return NULL; + if (!PyBytes_Check(new)) { + PyErr_Format(PyExc_TypeError, + "__bytes__ returned non-bytes (type %.200s)", + Py_TYPE(new)->tp_name); + Py_DECREF(new); + return NULL; + } + return new; + } + else if (PyErr_Occurred()) + return NULL; + /* Is it an integer? */ size = PyNumber_AsSsize_t(x, PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { @@ -2472,12 +2496,10 @@ } else { new = PyBytes_FromStringAndSize(NULL, size); - if (new == NULL) { + if (new == NULL) return NULL; - } - if (size > 0) { + if (size > 0) memset(((PyBytesObject*)new)->ob_sval, 0, size); - } return new; } @@ -2487,7 +2509,8 @@ "encoding or errors without a string argument"); return NULL; } - return PyObject_Bytes(x); + + return PyBytes_FromObject(x); } PyObject * -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 20 04:35:48 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 20 Dec 2012 04:35:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Small_tweaks_and_clarificatio?= =?utf-8?b?bnMu?= Message-ID: <3YRdsc45zbzRkB@mail.python.org> http://hg.python.org/peps/rev/1f95b1f65c8c changeset: 4623:1f95b1f65c8c user: Guido van Rossum date: Wed Dec 19 19:35:42 2012 -0800 summary: Small tweaks and clarifications. files: pep-3156.txt | 75 ++++++++++++++++++++------------------- 1 files changed, 38 insertions(+), 37 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -148,66 +148,69 @@ Event Loop Interface -------------------- +(A note about times: as usual in Python, all timeouts, intervals and +delays are measured in seconds, and may be ints or floats. The +accuracy and precision of the clock are up to the implementation; the +default implementation uses ``time.monotonic()``.) + A conforming event loop object has the following methods: -.. - Look for a better way to format method docs. PEP 12 doesn't seem to - have one. PEP 418 uses ^^^, which makes sub-headings. PEP 3148 - uses a markup which generates rather heavy layout using blockquote, - causing a blank line between each method heading and its - description. Also think of adding subheadings for different - categories of methods. - - ``run()``. Runs the event loop until there is nothing left to do. This means, in particular: - - No more calls scheduled with ``call_later()`` (except for canceled - calls). + - No more calls scheduled with ``call_later()``, + ``call_repeatedly()``, ``call_soon()``, or + ``call_soon_threadsafe()``, except for canceled calls. - No more registered file descriptors. It is up to the registering party to unregister a file descriptor when it is closed. - Note: run() blocks until the termination condition is met. + Note: ``run()`` blocks until the termination condition is met, + or until ``stop()`` is called. + + Note: if you schedule a call with ``call_repeatedly()``, ``run()`` + will not exit until you cancel it. - ``stop()``. Stops the event loop as soon as it is convenient. It is fine to restart the loop with ``run()`` (or one of its variants) - subsequently. (TBD: How should this interact with ``run_once()`` - and ``run_until_complete()``?) + subsequently. - Note: How soon exactly is up to the implementation. It is - reasonable to implement this so that ``run()`` simply stops calling - ``run_once()`` when this is called. + Note: How soon exactly is up to the implementation. All immediate + callbacks that were already scheduled to run before ``stop()`` is + called must still be run, but callbacks scheduled after it is called + (or scheduled to be run later) will not be run. - ``run_until_complete(future, timeout=None)``. Runs the event loop - until a Future is done. If a timeout is given, it waits at most + until the Future is done. If a timeout is given, it waits at most that long. If the Future is done, its result is returned, or its exception is raised; if the timeout expires before the Future is - done, TimeoutError is raised (but the Future is not cancelled). - This cannot be called when the event loop is already running. + done, or if ``stop()`` is called, ``TimeoutError`` is raised (but + the Future is not cancelled). This cannot be called when the event + loop is already running. Note: This API is most useful for tests and the like. It should not be used as a substitute for ``yield from future`` or other ways to wait for a Future (e.g. registering a done callback). - ``run_once(timeout=None)``. Run the event loop for a little while. - If a timeout is given, an I/O poll will be given at most that timeout; - otherwise, an I/O poll is not constrained in time. + If a timeout is given, an I/O poll made will block at most that + long; otherwise, an I/O poll is not constrained in time. - Note: Exactlly what this does is up to the implementation. One - constraint: if a callback immediately schedules itself using - ``call_soon()``, ``run_once()`` should still return. + Note: Exactlly how much work this does is up to the implementation. + One constraint: if a callback immediately schedules itself using + ``call_soon()``, causing an infinite loop, ``run_once()`` should + still return. - ``call_later(delay, callback, *args)``. Arrange for ``callback(*args)`` to be called approximately ``delay`` seconds in - the future, once, unless canceled. As usual in Python, ``delay`` may - be a floating point number to represent smaller intervals. Returns + the future, once, unless canceled. Returns a ``Handler`` object representing the callback, whose ``cancel()`` method can be used to cancel the callback. - ``call_repeatedly(interval, callback, **args)``. Like ``call_later()`` but calls the callback repeatedly, every ``interval`` seconds, until the ``Handler`` returned is cancelled. The first call is in - ``interval`` seconds. May be a float. + ``interval`` seconds. - ``call_soon(callback, *args)``. Equivalent to ``call_later(0, callback, *args)``. @@ -225,8 +228,6 @@ ``isinstance(callback, Handler)``? It should silently skip a canceled callback. -- TBD: Repeatable timers. - Some methods in the standard conforming interface return Futures: - ``wrap_future(future)``. This takes a PEP 3148 Future (i.e., an @@ -336,10 +337,8 @@ TBD: What about multiple callbacks per fd? The current semantics is that ``add_reader()/add_writer()`` replace a previously registered -callback. - -TBD: Should ``remove_*()`` return a bool telling is whether it removed -anything? +callback. Change this to raise an exception if a callback is already +registered. The following methods for doing async I/O on sockets are optional. They are alternative to the previous set of optional methods, intended @@ -353,7 +352,8 @@ - ``sock_sendall(sock, data)``. Send bytes ``data`` to the socket ``sock``. Returns a Future whose result on success will be ``None``. (TBD: Is it better to emulate ``sendall()`` or ``send()`` - semantics?) + semantics? I think ``sendall()`` -- but perhaps it should still + be *named* ``send()``?) - ``sock_connect(sock, address)``. Connect to the given address. Returns a Future whose result on success will be ``None``. @@ -605,9 +605,10 @@ TBD: Provide flow control the other way -- the transport may need to suspend the protocol if the amount of data buffered becomes a burden. -One option: let the transport call ``protocol.pause()`` and -``protocol.resume()`` if they exist; if they don't exist, the protocol -doesn't support flow control. +Proposal: let the transport call ``protocol.pause()`` and +``protocol.resume()`` if they exist; if they don't exist, the +protocol doesn't support flow control. (Perhaps different names +to avoid confusion between protocols and transports?) Protocols --------- -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Thu Dec 20 05:57:14 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 20 Dec 2012 05:57:14 +0100 Subject: [Python-checkins] Daily reference leaks (7c717d423160): sum=0 Message-ID: results for 7c717d423160 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog7_m_Eq', '-x'] From python-checkins at python.org Thu Dec 20 18:26:16 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 20 Dec 2012 18:26:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Choose_cancelled=2E_Add/remov?= =?utf-8?q?e_connector=2E_Misc_small_additions=2E?= Message-ID: <3YS0Hr6xlczQtG@mail.python.org> http://hg.python.org/peps/rev/74117f4eaa3d changeset: 4624:74117f4eaa3d user: Guido van Rossum date: Thu Dec 20 09:26:11 2012 -0800 summary: Choose cancelled. Add/remove connector. Misc small additions. files: pep-3156.txt | 42 +++++++++++++++++++++++---------------- 1 files changed, 25 insertions(+), 17 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -160,7 +160,7 @@ - No more calls scheduled with ``call_later()``, ``call_repeatedly()``, ``call_soon()``, or - ``call_soon_threadsafe()``, except for canceled calls. + ``call_soon_threadsafe()``, except for cancelled calls. - No more registered file descriptors. It is up to the registering party to unregister a file descriptor when it is closed. @@ -171,6 +171,8 @@ Note: if you schedule a call with ``call_repeatedly()``, ``run()`` will not exit until you cancel it. + TBD: A method to run the loop forever, i.e. until ``stop()`` is called? + - ``stop()``. Stops the event loop as soon as it is convenient. It is fine to restart the loop with ``run()`` (or one of its variants) subsequently. @@ -203,7 +205,7 @@ - ``call_later(delay, callback, *args)``. Arrange for ``callback(*args)`` to be called approximately ``delay`` seconds in - the future, once, unless canceled. Returns + the future, once, unless cancelled. Returns a ``Handler`` object representing the callback, whose ``cancel()`` method can be used to cancel the callback. @@ -226,7 +228,7 @@ - TBD: A way to register a callback that is already wrapped in a ``Handler``. Maybe ``call_soon()`` could just check ``isinstance(callback, Handler)``? It should silently skip - a canceled callback. + a cancelled callback. Some methods in the standard conforming interface return Futures: @@ -335,6 +337,13 @@ - ``remove_writer(fd)``. This is to ``add_writer()`` as ``remove_reader()`` is to ``add_reader()``. +- ``add_connector(fd, callback, *args)``. Like ``add_writer()`` but + meant to wait for ``connect()`` operations, which on some platforms + require different handling (e.g. ``WSAPoll()`` on Windows). + +- ``remove_connector(fd)``. This is to ``remove_writer()`` as + ``add_connector()`` is to ``add_writer()``. + TBD: What about multiple callbacks per fd? The current semantics is that ``add_reader()/add_writer()`` replace a previously registered callback. Change this to raise an exception if a callback is already @@ -433,7 +442,7 @@ - ``args``. The argument tuple with which to call the callback function. -- ``canceled``. True if ``cancel()`` has been called. +- ``cancelled``. True if ``cancel()`` has been called. Note that some callbacks (e.g. those registered with ``call_later()``) are meant to be called only once. Others (e.g. those registered with @@ -552,8 +561,6 @@ t.write(b'e') t.write(b'f') - (TBD: What about datagram transports?) - - ``writelines(iterable)``. Equivalent to:: for data in iterable: @@ -638,8 +645,6 @@ p.data_received(b'abc') p.data_received(b'def') - (TBD: What about datagram transports?) - - ``eof_received()``. This is called when the other end called ``write_eof()`` (or something equivalent). The default implementation calls ``close()`` on the transport, which causes @@ -761,9 +766,9 @@ returns a result, that becomes the task's result, if it raises an exception, that becomes the task's exception. -Canceling a task that's not done yet prevents its coroutine from +Cancelling a task that's not done yet prevents its coroutine from completing; in this case an exception is thrown into the coroutine -that it may catch to further handle cancelation, but it doesn't have +that it may catch to further handle cancellation, but it doesn't have to (this is done using the standard ``close()`` method on generators, described in PEP 342). @@ -822,7 +827,7 @@ Cancellation ------------ -TBD. When a Task is canceled its coroutine may see an exception at +TBD. When a Task is cancelled its coroutine may see an exception at any point where it is yielding to the scheduler (i.e., potentially at any ``yield from`` operation). We need to spell out which exception is raised. @@ -833,12 +838,9 @@ Open Issues =========== -- How to spell the past tense of 'cancel'? American usage prefers - (though not absolutely dictates) 'canceled' (one ell), but outside - the US 'cancelled' (two ells) prevails. PEP 3148, whose author - currently lives in Australia, uses ``cancelled()`` as a method name - on its Future class. Also, even in the US, 'cancellation' seems - to be preferred over cancelation. +- A debugging API? E.g. something that logs a lot of stuff, or logs + unusual conditions (like queues filling up faster than they drain) + or even callbacks taking too much time... - Do we need introspection APIs? E.g. asking for the read callback given a file descriptor. Or when the next scheduled call is. Or @@ -883,6 +885,12 @@ fs.remove(f) +- Support for datagram protocols, "connected" or otherwise? Probably + need more socket I/O methods, e.g. ``sock_sendto()`` and + ``sock_recvfrom()``. Or users can write their own (it's not rocket + science). Is it reasonable to map ``write()``, ``writelines()``, + ``data_received()`` to single datagrams? + - Task or callback priorities? (I hope not.) -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 20 18:55:29 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 20 Dec 2012 18:55:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_call_close_on_?= =?utf-8?q?the_underlying_stream_even_if_flush_raises_=28closes_=2316597?= =?utf-8?q?=29?= Message-ID: <3YS0xY3Rd5zNs4@mail.python.org> http://hg.python.org/cpython/rev/b0602a1eb3f6 changeset: 80956:b0602a1eb3f6 branch: 3.3 parent: 80954:c744b6f8a09a user: Benjamin Peterson date: Thu Dec 20 11:53:11 2012 -0600 summary: call close on the underlying stream even if flush raises (closes #16597) Patch by Serhiy Storchaka. files: Lib/_pyio.py | 12 ++++++++---- Lib/test/test_io.py | 28 ++++++++++++++++++++++++++++ Misc/NEWS | 3 +++ Modules/_io/bufferedio.c | 26 +++++++++++++++++++++----- Modules/_io/textio.c | 24 ++++++++++++++++++++---- 5 files changed, 80 insertions(+), 13 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -346,8 +346,10 @@ This method has no effect if the file is already closed. """ if not self.__closed: - self.flush() - self.__closed = True + try: + self.flush() + finally: + self.__closed = True def __del__(self): """Destructor. Calls close().""" @@ -1584,8 +1586,10 @@ def close(self): if self.buffer is not None and not self.closed: - self.flush() - self.buffer.close() + try: + self.flush() + finally: + self.buffer.close() @property def closed(self): diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -603,6 +603,7 @@ raise IOError() f.flush = bad_flush self.assertRaises(IOError, f.close) # exception not swallowed + self.assertTrue(f.closed) def test_multi_close(self): f = self.open(support.TESTFN, "wb", buffering=0) @@ -780,6 +781,22 @@ raw.flush = bad_flush b = self.tp(raw) self.assertRaises(IOError, b.close) # exception not swallowed + self.assertTrue(b.closed) + + def test_close_error_on_close(self): + raw = self.MockRawIO() + def bad_flush(): + raise IOError('flush') + def bad_close(): + raise IOError('close') + raw.close = bad_close + b = self.tp(raw) + b.flush = bad_flush + with self.assertRaises(IOError) as err: # exception not swallowed + b.close() + self.assertEqual(err.exception.args, ('close',)) + self.assertEqual(err.exception.__context__.args, ('flush',)) + self.assertFalse(b.closed) def test_multi_close(self): raw = self.MockRawIO() @@ -1296,6 +1313,16 @@ with self.assertRaises(TypeError): self.tp(self.MockRawIO(), 8, 12) + def test_write_error_on_close(self): + raw = self.MockRawIO() + def bad_write(b): + raise IOError() + raw.write = bad_write + b = self.tp(raw) + b.write(b'spam') + self.assertRaises(IOError, b.close) # exception not swallowed + self.assertTrue(b.closed) + class CBufferedWriterTest(BufferedWriterTest, SizeofTest): tp = io.BufferedWriter @@ -2465,6 +2492,7 @@ raise IOError() txt.flush = bad_flush self.assertRaises(IOError, txt.close) # exception not swallowed + self.assertTrue(txt.closed) def test_multi_close(self): txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii") diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #16597: Make BufferedIO.close call close() on the underlying stream if + invoking flush() fails. + - Issue #16722: In the bytes() constructor, try to call __bytes__ on the argument before __index__. diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -484,7 +484,7 @@ static PyObject * buffered_close(buffered *self, PyObject *args) { - PyObject *res = NULL; + PyObject *res = NULL, *exc = NULL, *val, *tb; int r; CHECK_INITIALIZED(self) @@ -512,13 +512,29 @@ res = PyObject_CallMethodObjArgs((PyObject *)self, _PyIO_str_flush, NULL); if (!ENTER_BUFFERED(self)) return NULL; - if (res == NULL) { - goto end; - } - Py_XDECREF(res); + if (res == NULL) + PyErr_Fetch(&exc, &val, &tb); + else + Py_DECREF(res); res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL); + if (exc != NULL) { + if (res != NULL) { + Py_CLEAR(res); + PyErr_Restore(exc, val, tb); + } + else { + PyObject *val2; + Py_DECREF(exc); + Py_XDECREF(tb); + PyErr_Fetch(&exc, &val2, &tb); + PyErr_NormalizeException(&exc, &val2, &tb); + PyException_SetContext(val2, val); + PyErr_Restore(exc, val2, tb); + } + } + end: LEAVE_BUFFERED(self) return res; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2554,6 +2554,7 @@ Py_RETURN_NONE; /* stream already closed */ } else { + PyObject *exc = NULL, *val, *tb; if (self->deallocating) { res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self); if (res) @@ -2562,13 +2563,28 @@ PyErr_Clear(); } res = _PyObject_CallMethodId((PyObject *)self, &PyId_flush, NULL); - if (res == NULL) { - return NULL; - } + if (res == NULL) + PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - return _PyObject_CallMethodId(self->buffer, &PyId_close, NULL); + res = _PyObject_CallMethodId(self->buffer, &PyId_close, NULL); + if (exc != NULL) { + if (res != NULL) { + Py_CLEAR(res); + PyErr_Restore(exc, val, tb); + } + else { + PyObject *val2; + Py_DECREF(exc); + Py_XDECREF(tb); + PyErr_Fetch(&exc, &val2, &tb); + PyErr_NormalizeException(&exc, &val2, &tb); + PyException_SetContext(val2, val); + PyErr_Restore(exc, val2, tb); + } + } + return res; } } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 20 18:55:31 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 20 Dec 2012 18:55:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4zICgjMTY1OTcp?= Message-ID: <3YS0xb04W7zRVj@mail.python.org> http://hg.python.org/cpython/rev/142012e47c3b changeset: 80957:142012e47c3b parent: 80955:7c717d423160 parent: 80956:b0602a1eb3f6 user: Benjamin Peterson date: Thu Dec 20 11:55:16 2012 -0600 summary: merge 3.3 (#16597) files: Lib/_pyio.py | 12 ++++++++---- Lib/test/test_io.py | 28 ++++++++++++++++++++++++++++ Misc/NEWS | 3 +++ Modules/_io/bufferedio.c | 26 +++++++++++++++++++++----- Modules/_io/textio.c | 24 ++++++++++++++++++++---- 5 files changed, 80 insertions(+), 13 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -346,8 +346,10 @@ This method has no effect if the file is already closed. """ if not self.__closed: - self.flush() - self.__closed = True + try: + self.flush() + finally: + self.__closed = True def __del__(self): """Destructor. Calls close().""" @@ -1584,8 +1586,10 @@ def close(self): if self.buffer is not None and not self.closed: - self.flush() - self.buffer.close() + try: + self.flush() + finally: + self.buffer.close() @property def closed(self): diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -603,6 +603,7 @@ raise IOError() f.flush = bad_flush self.assertRaises(IOError, f.close) # exception not swallowed + self.assertTrue(f.closed) def test_multi_close(self): f = self.open(support.TESTFN, "wb", buffering=0) @@ -780,6 +781,22 @@ raw.flush = bad_flush b = self.tp(raw) self.assertRaises(IOError, b.close) # exception not swallowed + self.assertTrue(b.closed) + + def test_close_error_on_close(self): + raw = self.MockRawIO() + def bad_flush(): + raise IOError('flush') + def bad_close(): + raise IOError('close') + raw.close = bad_close + b = self.tp(raw) + b.flush = bad_flush + with self.assertRaises(IOError) as err: # exception not swallowed + b.close() + self.assertEqual(err.exception.args, ('close',)) + self.assertEqual(err.exception.__context__.args, ('flush',)) + self.assertFalse(b.closed) def test_multi_close(self): raw = self.MockRawIO() @@ -1304,6 +1321,16 @@ with self.assertRaises(TypeError): self.tp(self.MockRawIO(), 8, 12) + def test_write_error_on_close(self): + raw = self.MockRawIO() + def bad_write(b): + raise IOError() + raw.write = bad_write + b = self.tp(raw) + b.write(b'spam') + self.assertRaises(IOError, b.close) # exception not swallowed + self.assertTrue(b.closed) + class CBufferedWriterTest(BufferedWriterTest, SizeofTest): tp = io.BufferedWriter @@ -2473,6 +2500,7 @@ raise IOError() txt.flush = bad_flush self.assertRaises(IOError, txt.close) # exception not swallowed + self.assertTrue(txt.closed) def test_multi_close(self): txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii") diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #16597: Make BufferedIO.close call close() on the underlying stream if + invoking flush() fails. + - Issue #16722: In the bytes() constructor, try to call __bytes__ on the argument before __index__. diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -484,7 +484,7 @@ static PyObject * buffered_close(buffered *self, PyObject *args) { - PyObject *res = NULL; + PyObject *res = NULL, *exc = NULL, *val, *tb; int r; CHECK_INITIALIZED(self) @@ -512,10 +512,10 @@ res = PyObject_CallMethodObjArgs((PyObject *)self, _PyIO_str_flush, NULL); if (!ENTER_BUFFERED(self)) return NULL; - if (res == NULL) { - goto end; - } - Py_XDECREF(res); + if (res == NULL) + PyErr_Fetch(&exc, &val, &tb); + else + Py_DECREF(res); res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL); @@ -524,6 +524,22 @@ self->buffer = NULL; } + if (exc != NULL) { + if (res != NULL) { + Py_CLEAR(res); + PyErr_Restore(exc, val, tb); + } + else { + PyObject *val2; + Py_DECREF(exc); + Py_XDECREF(tb); + PyErr_Fetch(&exc, &val2, &tb); + PyErr_NormalizeException(&exc, &val2, &tb); + PyException_SetContext(val2, val); + PyErr_Restore(exc, val2, tb); + } + } + end: LEAVE_BUFFERED(self) return res; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2548,6 +2548,7 @@ Py_RETURN_NONE; /* stream already closed */ } else { + PyObject *exc = NULL, *val, *tb; if (self->deallocating) { res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self); if (res) @@ -2556,13 +2557,28 @@ PyErr_Clear(); } res = _PyObject_CallMethodId((PyObject *)self, &PyId_flush, NULL); - if (res == NULL) { - return NULL; - } + if (res == NULL) + PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - return _PyObject_CallMethodId(self->buffer, &PyId_close, NULL); + res = _PyObject_CallMethodId(self->buffer, &PyId_close, NULL); + if (exc != NULL) { + if (res != NULL) { + Py_CLEAR(res); + PyErr_Restore(exc, val, tb); + } + else { + PyObject *val2; + Py_DECREF(exc); + Py_XDECREF(tb); + PyErr_Fetch(&exc, &val2, &tb); + PyErr_NormalizeException(&exc, &val2, &tb); + PyException_SetContext(val2, val); + PyErr_Restore(exc, val2, tb); + } + } + return res; } } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 20 19:24:23 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 20 Dec 2012 19:24:23 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_call_close_on_?= =?utf-8?q?the_underlying_stream_even_if_flush_raises_=28=2316597=29?= Message-ID: <3YS1Zv6DD9zNW4@mail.python.org> http://hg.python.org/cpython/rev/b6ff6ac1f049 changeset: 80958:b6ff6ac1f049 branch: 2.7 parent: 80948:b227f8f7242d user: Benjamin Peterson date: Thu Dec 20 12:24:10 2012 -0600 summary: call close on the underlying stream even if flush raises (#16597) files: Lib/_pyio.py | 12 ++++++++---- Lib/test/test_io.py | 27 +++++++++++++++++++++++++++ Modules/_io/bufferedio.c | 22 +++++++++++++++++----- Modules/_io/textio.c | 20 ++++++++++++++++---- 4 files changed, 68 insertions(+), 13 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -340,8 +340,10 @@ This method has no effect if the file is already closed. """ if not self.__closed: - self.flush() - self.__closed = True + try: + self.flush() + finally: + self.__closed = True def __del__(self): """Destructor. Calls close().""" @@ -1568,8 +1570,10 @@ def close(self): if self.buffer is not None and not self.closed: - self.flush() - self.buffer.close() + try: + self.flush() + finally: + self.buffer.close() @property def closed(self): diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -573,6 +573,7 @@ raise IOError() f.flush = bad_flush self.assertRaises(IOError, f.close) # exception not swallowed + self.assertTrue(f.closed) def test_multi_close(self): f = self.open(support.TESTFN, "wb", buffering=0) @@ -732,6 +733,21 @@ raw.flush = bad_flush b = self.tp(raw) self.assertRaises(IOError, b.close) # exception not swallowed + self.assertTrue(b.closed) + + def test_close_error_on_close(self): + raw = self.MockRawIO() + def bad_flush(): + raise IOError('flush') + def bad_close(): + raise IOError('close') + raw.close = bad_close + b = self.tp(raw) + b.flush = bad_flush + with self.assertRaises(IOError) as err: # exception not swallowed + b.close() + self.assertEqual(err.exception.args, ('close',)) + self.assertFalse(b.closed) def test_multi_close(self): raw = self.MockRawIO() @@ -1230,6 +1246,16 @@ DeprecationWarning)): self.tp(self.MockRawIO(), 8, 12) + def test_write_error_on_close(self): + raw = self.MockRawIO() + def bad_write(b): + raise IOError() + raw.write = bad_write + b = self.tp(raw) + b.write(b'spam') + self.assertRaises(IOError, b.close) # exception not swallowed + self.assertTrue(b.closed) + class CBufferedWriterTest(BufferedWriterTest, SizeofTest): tp = io.BufferedWriter @@ -2378,6 +2404,7 @@ raise IOError() txt.flush = bad_flush self.assertRaises(IOError, txt.close) # exception not swallowed + self.assertTrue(txt.closed) def test_multi_close(self): txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii") diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -455,7 +455,7 @@ static PyObject * buffered_close(buffered *self, PyObject *args) { - PyObject *res = NULL; + PyObject *res = NULL, *exc = NULL, *val, *tb; int r; CHECK_INITIALIZED(self) @@ -475,13 +475,25 @@ res = PyObject_CallMethodObjArgs((PyObject *)self, _PyIO_str_flush, NULL); if (!ENTER_BUFFERED(self)) return NULL; - if (res == NULL) { - goto end; - } - Py_XDECREF(res); + if (res == NULL) + PyErr_Fetch(&exc, &val, &tb); + else + Py_DECREF(res); res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL); + if (exc != NULL) { + if (res != NULL) { + Py_CLEAR(res); + PyErr_Restore(exc, val, tb); + } + else { + Py_DECREF(exc); + Py_XDECREF(val); + Py_XDECREF(tb); + } + } + end: LEAVE_BUFFERED(self) return res; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2442,14 +2442,26 @@ Py_RETURN_NONE; /* stream already closed */ } else { + PyObject *exc = NULL, *val, *tb; res = PyObject_CallMethod((PyObject *)self, "flush", NULL); - if (res == NULL) { - return NULL; - } + if (res == NULL) + PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - return PyObject_CallMethod(self->buffer, "close", NULL); + res = PyObject_CallMethod(self->buffer, "close", NULL); + if (exc != NULL) { + if (res != NULL) { + Py_CLEAR(res); + PyErr_Restore(exc, val, tb); + } + else { + Py_DECREF(exc); + Py_XDECREF(val); + Py_XDECREF(tb); + } + } + return res; } } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 20 19:56:08 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 20 Dec 2012 19:56:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_improve_messag?= =?utf-8?q?e_=28=2316597=29?= Message-ID: <3YS2HX0TByzMh2@mail.python.org> http://hg.python.org/cpython/rev/54372f38932e changeset: 80959:54372f38932e branch: 3.3 parent: 80956:b0602a1eb3f6 user: Benjamin Peterson date: Thu Dec 20 12:54:59 2012 -0600 summary: improve message (#16597) files: Misc/NEWS | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,8 +12,8 @@ Core and Builtins ----------------- -- Issue #16597: Make BufferedIO.close call close() on the underlying stream if - invoking flush() fails. +- Issue #16597: In buffered and text IO, call close() on the underlying stream + if invoking flush() fails. - Issue #16722: In the bytes() constructor, try to call __bytes__ on the argument before __index__. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 20 19:56:09 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 20 Dec 2012 19:56:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4zICgjMTY1OTcp?= Message-ID: <3YS2HY38RxzRWh@mail.python.org> http://hg.python.org/cpython/rev/faaac6ceffff changeset: 80960:faaac6ceffff parent: 80957:142012e47c3b parent: 80959:54372f38932e user: Benjamin Peterson date: Thu Dec 20 12:55:15 2012 -0600 summary: merge 3.3 (#16597) files: Misc/NEWS | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,8 +10,8 @@ Core and Builtins ----------------- -- Issue #16597: Make BufferedIO.close call close() on the underlying stream if - invoking flush() fails. +- Issue #16597: In buffered and text IO, call close() on the underlying stream + if invoking flush() fails. - Issue #16722: In the bytes() constructor, try to call __bytes__ on the argument before __index__. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 20 19:56:10 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 20 Dec 2012 19:56:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_add_news_note_?= =?utf-8?b?KCMxNjU5Nyk=?= Message-ID: <3YS2HZ5ZhrzRXV@mail.python.org> http://hg.python.org/cpython/rev/a057d9985fb8 changeset: 80961:a057d9985fb8 branch: 2.7 parent: 80958:b6ff6ac1f049 user: Benjamin Peterson date: Thu Dec 20 12:55:52 2012 -0600 summary: add news note (#16597) files: Misc/NEWS | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -160,6 +160,9 @@ Library ------- +- Issue #16597: In buffered and text IO, call close() on the underlying stream + if invoking flush() fails. + - Issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 20 20:11:23 2012 From: python-checkins at python.org (petri.lehtinen) Date: Thu, 20 Dec 2012 20:11:23 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzg4NTM6IEFsbG93?= =?utf-8?q?_port_to_be_of_type_long_for_socket=2Egetaddrinfo=28=29?= Message-ID: <3YS2d72FKGzRTn@mail.python.org> http://hg.python.org/cpython/rev/39803c20c9bf changeset: 80962:39803c20c9bf branch: 2.7 user: Petri Lehtinen date: Thu Dec 20 21:06:14 2012 +0200 summary: #8853: Allow port to be of type long for socket.getaddrinfo() files: Lib/test/test_socket.py | 3 ++- Misc/NEWS | 2 ++ Modules/socketmodule.c | 10 +++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -644,9 +644,10 @@ if SUPPORTS_IPV6: socket.getaddrinfo('::1', 80) # port can be a string service name such as "http", a numeric - # port number or None + # port number (int or long), or None socket.getaddrinfo(HOST, "http") socket.getaddrinfo(HOST, 80) + socket.getaddrinfo(HOST, 80L) socket.getaddrinfo(HOST, None) # test family and socktype filters infos = socket.getaddrinfo(HOST, None, socket.AF_INET) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -160,6 +160,8 @@ Library ------- +- Issue #8853: Allow port to be of type long for socket.getaddrinfo(). + - Issue #16597: In buffered and text IO, call close() on the underlying stream if invoking flush() fails. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -4090,15 +4090,19 @@ "getaddrinfo() argument 1 must be string or None"); return NULL; } - if (PyInt_Check(pobj)) { - PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj)); + if (PyInt_Check(pobj) || PyLong_Check(pobj)) { + long value = PyLong_AsLong(pobj); + if (value == -1 && PyErr_Occurred()) + return NULL; + PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value); pptr = pbuf; } else if (PyString_Check(pobj)) { pptr = PyString_AsString(pobj); } else if (pobj == Py_None) { pptr = (char *)NULL; } else { - PyErr_SetString(socket_error, "Int or String expected"); + PyErr_SetString(socket_error, + "getaddrinfo() argument 2 must be integer or string"); goto err; } memset(&hints, 0, sizeof(hints)); -- Repository URL: http://hg.python.org/cpython From andrew.svetlov at gmail.com Thu Dec 20 22:11:27 2012 From: andrew.svetlov at gmail.com (Andrew Svetlov) Date: Thu, 20 Dec 2012 23:11:27 +0200 Subject: [Python-checkins] cpython: Mention OSError instead of IOError in the docs. In-Reply-To: References: <3YQsVs2mGnzQl0@mail.python.org> Message-ID: Don't sure about applying doc changes to 3.3. They are very minor. The main change will be deprecation of aliases in the docs, that can be applied only to upcoming release. On Wed, Dec 19, 2012 at 7:05 PM, Serhiy Storchaka wrote: > On 19.12.12 09:24, Nick Coghlan wrote: >> >> With any of these changes in the docs, please don't forget to include >> appropriate "versionchanged" directives. Many people using the Python 3 >> docs at "docs.python.org/3/ " will still be >> >> on Python 3.2, and thus relying on the presence of such directives to >> let them know that while the various OS-related exception names are now >> just aliases for OSError in 3.3+, the distinctions still matter in 3.2. > > > I also propose to apply all this documentation changes to 3.3. > > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins -- Thanks, Andrew Svetlov From python-checkins at python.org Thu Dec 20 22:46:41 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 20 Dec 2012 22:46:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_EventEmitter_suggestion_?= =?utf-8?q?=28Mark_Nottingham=29=2E?= Message-ID: <3YS64K44NvzNmJ@mail.python.org> http://hg.python.org/peps/rev/a392d4f5b38f changeset: 4625:a392d4f5b38f user: Guido van Rossum date: Thu Dec 20 13:46:36 2012 -0800 summary: Add EventEmitter suggestion (Mark Nottingham). files: pep-3156.txt | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -893,6 +893,12 @@ - Task or callback priorities? (I hope not.) +- An EventEmitter in the style of NodeJS? Or make this a separate + PEP? It's easy enough to do in user space, though it may benefit + from standardization. (See + https://github.com/mnot/thor/blob/master/thor/events.py and + https://github.com/mnot/thor/blob/master/doc/events.md for examples.) + Acknowledgments =============== -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 20 22:48:29 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 20 Dec 2012 22:48:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?cGVwczogQWRkIHJ1bl9mb3JldmVyKCku?= Message-ID: <3YS66P5jSKzNmJ@mail.python.org> http://hg.python.org/peps/rev/4f4616e62304 changeset: 4626:4f4616e62304 user: Guido van Rossum date: Thu Dec 20 13:48:24 2012 -0800 summary: Add run_forever(). files: pep-3156.txt | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -171,7 +171,7 @@ Note: if you schedule a call with ``call_repeatedly()``, ``run()`` will not exit until you cancel it. - TBD: A method to run the loop forever, i.e. until ``stop()`` is called? + TBD: How many variants of this do we really need? - ``stop()``. Stops the event loop as soon as it is convenient. It is fine to restart the loop with ``run()`` (or one of its variants) @@ -182,6 +182,8 @@ called must still be run, but callbacks scheduled after it is called (or scheduled to be run later) will not be run. +- ``run_forever()``. Runs the event loop until ``stop()`` is called. + - ``run_until_complete(future, timeout=None)``. Runs the event loop until the Future is done. If a timeout is given, it waits at most that long. If the Future is done, its result is returned, or its -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 20 23:41:34 2012 From: python-checkins at python.org (guido.van.rossum) Date: Thu, 20 Dec 2012 23:41:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Specify_create=5Ftransport=28?= =?utf-8?q?=29_signature=2E?= Message-ID: <3YS7Hf4gxPzQjj@mail.python.org> http://hg.python.org/peps/rev/7005ecc2d521 changeset: 4627:7005ecc2d521 user: Guido van Rossum date: Thu Dec 20 14:41:31 2012 -0800 summary: Specify create_transport() signature. files: pep-3156.txt | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -264,8 +264,26 @@ on success will be a tuple ``(host, port)``. Same implementation remarks as for ``getaddrinfo()``. -- ``create_transport(...)``. Creates a transport. Returns a Future. - TBD: Signature. Do we pass in a protocol or protocol factory? +- ``create_transport(protocol_factory, host, port, **kwargs)``. + Creates a transport and a protocol and ties them together. Returns + a Future whose result on success is a (transport, protocol) pair. + Note that when the Future completes, the protocol's + ``connection_made()`` method has not yet been called; that will + happen when the connection handshake is complete. When it is + impossible to connect to the given host and port, the Future will + raise an exception instead. + + Optional keyword arguments: + + - ``family``, ``type``, ``proto``, ``flags``: Address familty, + socket type, protcol, and miscellaneous flags to be passed through + to ``getaddrinfo()``. These all default to ``0`` except ``type`` + which defaults to ``socket.SOCK_STREAM``. + + - ``ssl``: Pass ``True`` to create an SSL transport (by default a + plain TCP is created). Or pass an ``ssl.SSLContext`` object to + override the default SSL context object to be used. + TBD: Should this be called create_connection()? - ``start_serving(...)``. Enters a loop that accepts connections. -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Fri Dec 21 03:25:18 2012 From: python-checkins at python.org (benjamin.peterson) Date: Fri, 21 Dec 2012 03:25:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogZml4IHR5cG8gKCMx?= =?utf-8?q?6687=29?= Message-ID: <3YSDFp22VVzRXK@mail.python.org> http://hg.python.org/cpython/rev/abfd3bc38b5d changeset: 80963:abfd3bc38b5d branch: 3.3 parent: 80959:54372f38932e user: Benjamin Peterson date: Thu Dec 20 20:22:47 2012 -0600 summary: fix typo (#16687) Patch from Jeff Knupp. files: Doc/library/hashlib.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -45,7 +45,7 @@ .. note:: - Feeding string objects is to :meth:`update` is not supported, as hashes work + Feeding string objects into :meth:`update` is not supported, as hashes work on bytes, not on characters. .. index:: single: OpenSSL; (use in module hashlib) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 03:25:19 2012 From: python-checkins at python.org (benjamin.peterson) Date: Fri, 21 Dec 2012 03:25:19 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_link_to_GIL_as?= =?utf-8?q?_a_term?= Message-ID: <3YSDFq4GTrzRXK@mail.python.org> http://hg.python.org/cpython/rev/ccafaabe1a7f changeset: 80964:ccafaabe1a7f branch: 3.3 user: Benjamin Peterson date: Thu Dec 20 20:24:37 2012 -0600 summary: link to GIL as a term Patch from Jeff Knupp. files: Doc/library/hashlib.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -40,7 +40,7 @@ .. note:: - For better multithreading performance, the Python GIL is released for + For better multithreading performance, the Python :term:`GIL` is released for strings of more than 2047 bytes at object creation or on update. .. note:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 03:25:20 2012 From: python-checkins at python.org (benjamin.peterson) Date: Fri, 21 Dec 2012 03:25:20 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_merge_3=2E3_=28closes_=2316687=29?= Message-ID: <3YSDFs05HnzRfG@mail.python.org> http://hg.python.org/cpython/rev/95cb2f09ac50 changeset: 80965:95cb2f09ac50 parent: 80960:faaac6ceffff parent: 80964:ccafaabe1a7f user: Benjamin Peterson date: Thu Dec 20 20:25:00 2012 -0600 summary: merge 3.3 (closes #16687) files: Doc/library/hashlib.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -40,12 +40,12 @@ .. note:: - For better multithreading performance, the Python GIL is released for + For better multithreading performance, the Python :term:`GIL` is released for strings of more than 2047 bytes at object creation or on update. .. note:: - Feeding string objects is to :meth:`update` is not supported, as hashes work + Feeding string objects into :meth:`update` is not supported, as hashes work on bytes, not on characters. .. index:: single: OpenSSL; (use in module hashlib) -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Fri Dec 21 05:57:33 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 21 Dec 2012 05:57:33 +0100 Subject: [Python-checkins] Daily reference leaks (95cb2f09ac50): sum=5 Message-ID: results for 95cb2f09ac50 on branch "default" -------------------------------------------- test_support leaked [1, 0, 0] references, sum=1 test_support leaked [1, 2, 1] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogA3qFnA', '-x'] From python-checkins at python.org Fri Dec 21 12:25:12 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Fri, 21 Dec 2012 12:25:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogY3R5cGVzOiBERUNS?= =?utf-8?q?EF_error=5Fobject_=5Fafter=5F_re-acquiring_GIL?= Message-ID: <3YSSDm369hzRWV@mail.python.org> http://hg.python.org/cpython/rev/5ca63d68792d changeset: 80966:5ca63d68792d branch: 2.7 parent: 80962:39803c20c9bf user: Kristjan Valur Jonsson date: Fri Dec 21 10:32:57 2012 +0000 summary: ctypes: DECREF error_object _after_ re-acquiring GIL files: Modules/_ctypes/callproc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -844,11 +844,11 @@ space[0] = errno; errno = temp; } - Py_XDECREF(error_object); #ifdef WITH_THREAD if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS #endif + Py_XDECREF(error_object); #ifdef MS_WIN32 #ifndef DONT_USE_SEH if (dwExceptionCode) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 12:25:13 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Fri, 21 Dec 2012 12:25:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4xKTogRG9uJ3QgREVDUkVG?= =?utf-8?q?_the_ctypes_error=5Fobject_without_the_GIL_held=2E?= Message-ID: <3YSSDn5nvnzRdv@mail.python.org> http://hg.python.org/cpython/rev/087ce7bbac9f changeset: 80967:087ce7bbac9f branch: 3.1 parent: 80782:03b3124e9ea3 user: Kristjan Valur Jonsson date: Fri Dec 21 09:41:25 2012 +0000 summary: Don't DECREF the ctypes error_object without the GIL held. files: Modules/_ctypes/callproc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -834,11 +834,11 @@ space[0] = errno; errno = temp; } - Py_XDECREF(error_object); #ifdef WITH_THREAD if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS #endif + Py_XDECREF(error_object); #ifdef MS_WIN32 #ifndef DONT_USE_SEH if (dwExceptionCode) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 12:25:15 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Fri, 21 Dec 2012 12:25:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4xIC0+IDMuMik6?= =?utf-8?q?_Merge_with_3=2E1_=3A_Don=27t_DECREF_the_ctypes_error=5Fobject_?= =?utf-8?q?without_the_GIL_held=2E?= Message-ID: <3YSSDq0vX2zRWV@mail.python.org> http://hg.python.org/cpython/rev/0935394069cc changeset: 80968:0935394069cc branch: 3.2 parent: 80949:74da2dbb5e50 parent: 80967:087ce7bbac9f user: Kristjan Valur Jonsson date: Fri Dec 21 11:20:53 2012 +0000 summary: Merge with 3.1 : Don't DECREF the ctypes error_object without the GIL held. files: Modules/_ctypes/callproc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -825,11 +825,11 @@ space[0] = errno; errno = temp; } - Py_XDECREF(error_object); #ifdef WITH_THREAD if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS #endif + Py_XDECREF(error_object); #ifdef MS_WIN32 #ifndef DONT_USE_SEH if (dwExceptionCode) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 12:25:16 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Fri, 21 Dec 2012 12:25:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_with_3=2E2_=3A_Don=27t_DECREF_the_ctypes_error=5Fobject_?= =?utf-8?q?without_the_GIL_held=2E?= Message-ID: <3YSSDr3DrTzRYg@mail.python.org> http://hg.python.org/cpython/rev/6c31a921a569 changeset: 80969:6c31a921a569 branch: 3.3 parent: 80964:ccafaabe1a7f parent: 80968:0935394069cc user: Kristjan Valur Jonsson date: Fri Dec 21 11:22:29 2012 +0000 summary: Merge with 3.2 : Don't DECREF the ctypes error_object without the GIL held. files: Modules/_ctypes/callproc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -817,11 +817,11 @@ space[0] = errno; errno = temp; } - Py_XDECREF(error_object); #ifdef WITH_THREAD if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS #endif + Py_XDECREF(error_object); #ifdef MS_WIN32 #ifndef DONT_USE_SEH if (dwExceptionCode) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 12:25:17 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Fri, 21 Dec 2012 12:25:17 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E3_=3A_Don=27t_DECREF_the_ctypes_error=5Fo?= =?utf-8?q?bject_without_the_GIL_held=2E?= Message-ID: <3YSSDs5tPWzRgZ@mail.python.org> http://hg.python.org/cpython/rev/860ed4bc8d32 changeset: 80970:860ed4bc8d32 parent: 80965:95cb2f09ac50 parent: 80969:6c31a921a569 user: Kristjan Valur Jonsson date: Fri Dec 21 11:23:23 2012 +0000 summary: Merge with 3.3 : Don't DECREF the ctypes error_object without the GIL held. files: Modules/_ctypes/callproc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -817,11 +817,11 @@ space[0] = errno; errno = temp; } - Py_XDECREF(error_object); #ifdef WITH_THREAD if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS #endif + Py_XDECREF(error_object); #ifdef MS_WIN32 #ifndef DONT_USE_SEH if (dwExceptionCode) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 20:34:18 2012 From: python-checkins at python.org (guido.van.rossum) Date: Fri, 21 Dec 2012 20:34:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Specify_start=5Fserving=28=29?= =?utf-8?q?=2E_Add_Post-History=2E?= Message-ID: <3YSg56288VzNZl@mail.python.org> http://hg.python.org/peps/rev/45b5502a5c08 changeset: 4628:45b5502a5c08 user: Guido van Rossum date: Fri Dec 21 11:34:12 2012 -0800 summary: Specify start_serving(). Add Post-History. files: pep-3156.txt | 55 ++++++++++++++++++--------------------- 1 files changed, 26 insertions(+), 29 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -7,7 +7,7 @@ Type: Standards Track Content-Type: text/x-rst Created: 12-Dec-2012 -Post-History: TBD +Post-History: 21-Dec-2012 Abstract ======== @@ -257,7 +257,8 @@ format as returned by ``socket.getaddrinfo()``. The default implementation calls ``socket.getaddrinfo()`` using ``run_in_executor()``, but other implementations may choose to - implement their own DNS lookup. + implement their own DNS lookup. The optional arguments *must* be + specified as keyword arguments. - ``getnameinfo(sockaddr, flags=0)``. Similar to ``socket.getnameinfo()`` but returns a Future. The Future's result @@ -267,7 +268,8 @@ - ``create_transport(protocol_factory, host, port, **kwargs)``. Creates a transport and a protocol and ties them together. Returns a Future whose result on success is a (transport, protocol) pair. - Note that when the Future completes, the protocol's + The protocol is created by calling ``protocol_factory()`` without + arguments. Note that when the Future completes, the protocol's ``connection_made()`` method has not yet been called; that will happen when the connection handshake is complete. When it is impossible to connect to the given host and port, the Future will @@ -286,36 +288,31 @@ TBD: Should this be called create_connection()? -- ``start_serving(...)``. Enters a loop that accepts connections. - TBD: Signature. There are two possibilities: +- ``start_serving(protocol_factory, host, port, **kwds)``. Enters a + loop that accepts connections. Returns a Future that completes once + the loop is set up to serve; its return value is None. Each time a + connection is accepted, ``protocol_factory`` is called without + arguments to create a protocol, a transport is created to represent + the network side of the connection, and the two are tied together by + calling ``protocol.connection_made(transport)``. - 1. You pass it a non-blocking socket that you have already prepared - with ``bind()`` and ``listen()`` (these system calls do not block - AFAIK), a protocol factory (I hesitate to use this word :-), and - optional flags that control the transport creation (e.g. ssl). + Optional keyword arguments: - 2. Instead of a socket, you pass it a host and port, and some more - optional flags (e.g. to control IPv4 vs IPv6, or to set the - backlog value to be passed to ``listen()``). + - ``family``, ``type``, ``proto``, ``flags``: Address familty, + socket type, protcol, and miscellaneous flags to be passed through + to ``getaddrinfo()``. These all default to ``0`` except ``type`` + which defaults to ``socket.SOCK_STREAM``. - In either case, once it has a socket, it will wrap it in a - transport, and then enter a loop accepting connections (the best way - to implement such a loop depends on the platform). Each time a - connection is accepted, a transport and protocol are created for it. + TBD: Support SSL? I don't even know how to do that synchronously, + and I suppose it needs a certificate. - This should return an object that can be used to control the serving - loop, e.g. to stop serving, abort all active connections, and (if - supported) adjust the backlog or other parameters. It may also have - an API to inquire about active connections. If version (2) is - selected, it should probably return a Future whose result on success - will be that control object, and which becomes done once the accept - loop is started. - - TBD: It may be best to use version (2), since on some platforms the - best way to start a server may not involve sockets (but will still - involve transports and protocols). - - TBD: Be more specific. + TBD: Maybe make the Future's result an object that can be used to + control the serving loop, e.g. to stop serving, abort all active + connections, and (if supported) adjust the backlog or other + parameters? It could also have an API to inquire about active + connections. Alternatively, return a Future (subclass?) that only + completes if the loop stops serving due to an error, or if it cannot + be started? Cancelling it might stop the loop. TBD: Some platforms may not be interested in implementing all of these, e.g. start_serving() may be of no interest to mobile apps. -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Fri Dec 21 22:53:09 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 21 Dec 2012 22:53:09 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Simplify_random=5Fseed_to_?= =?utf-8?q?use_=5FPyLong=5FAsByteArray=2E__Closes_issue_=2316496=2E?= Message-ID: <3YSk9K1cTpzNmp@mail.python.org> http://hg.python.org/cpython/rev/db75553ff333 changeset: 80971:db75553ff333 user: Mark Dickinson date: Fri Dec 21 21:52:49 2012 +0000 summary: Simplify random_seed to use _PyLong_AsByteArray. Closes issue #16496. files: Modules/_randommodule.c | 99 ++++++++++------------------ 1 files changed, 35 insertions(+), 64 deletions(-) diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -168,9 +168,9 @@ /* init_key is the array for initializing keys */ /* key_length is its length */ static PyObject * -init_by_array(RandomObject *self, unsigned long init_key[], unsigned long key_length) +init_by_array(RandomObject *self, unsigned long init_key[], size_t key_length) { - unsigned int i, j, k; /* was signed in the original code. RDH 12/16/2002 */ + size_t i, j, k; /* was signed in the original code. RDH 12/16/2002 */ unsigned long *mt; mt = self->state; @@ -207,14 +207,11 @@ random_seed(RandomObject *self, PyObject *args) { PyObject *result = NULL; /* guilty until proved innocent */ - PyObject *masklower = NULL; - PyObject *thirtytwo = NULL; PyObject *n = NULL; - unsigned long *new_key, *key = NULL; - unsigned long keymax; /* # of allocated slots in key */ - unsigned long keyused; /* # of used slots in key */ - int err; - + unsigned long *key = NULL; + unsigned char *key_as_bytes = NULL; + size_t bits, keyused, i; + int res; PyObject *arg = NULL; if (!PyArg_UnpackTuple(args, "seed", 0, 1, &arg)) @@ -243,69 +240,43 @@ if (n == NULL) goto Done; - /* Now split n into 32-bit chunks, from the right. Each piece is - * stored into key, which has a capacity of keymax chunks, of which - * keyused are filled. Alas, the repeated shifting makes this a - * quadratic-time algorithm; we'd really like to use - * _PyLong_AsByteArray here, but then we'd have to break into the - * long representation to figure out how big an array was needed - * in advance. - */ - keymax = 8; /* arbitrary; grows later if needed */ - keyused = 0; - key = (unsigned long *)PyMem_Malloc(keymax * sizeof(*key)); - if (key == NULL) + /* Now split n into 32-bit chunks, from the right. */ + bits = _PyLong_NumBits(n); + if (bits == (size_t)-1 && PyErr_Occurred()) goto Done; - masklower = PyLong_FromUnsignedLong(0xffffffffU); - if (masklower == NULL) + /* Figure out how many 32-bit chunks this gives us. */ + keyused = bits == 0 ? 1 : (bits - 1) / 32 + 1; + + /* Convert seed to byte sequence. */ + key_as_bytes = (unsigned char *)PyMem_Malloc((size_t)4 * keyused); + if (key_as_bytes == NULL) goto Done; - thirtytwo = PyLong_FromLong(32L); - if (thirtytwo == NULL) + res = _PyLong_AsByteArray((PyLongObject *)n, + key_as_bytes, keyused * 4, + 1, /* little-endian */ + 0); /* unsigned */ + if (res == -1) { + PyMem_Free(key_as_bytes); goto Done; - while ((err=PyObject_IsTrue(n))) { - PyObject *newn; - PyObject *pychunk; - unsigned long chunk; - - if (err == -1) - goto Done; - pychunk = PyNumber_And(n, masklower); - if (pychunk == NULL) - goto Done; - chunk = PyLong_AsUnsignedLong(pychunk); - Py_DECREF(pychunk); - if (chunk == (unsigned long)-1 && PyErr_Occurred()) - goto Done; - newn = PyNumber_Rshift(n, thirtytwo); - if (newn == NULL) - goto Done; - Py_DECREF(n); - n = newn; - if (keyused >= keymax) { - unsigned long bigger = keymax << 1; - if ((bigger >> 1) != keymax || - bigger > PY_SSIZE_T_MAX / sizeof(*key)) { - PyErr_NoMemory(); - goto Done; - } - new_key = (unsigned long *)PyMem_Realloc(key, - bigger * sizeof(*key)); - if (new_key == NULL) - goto Done; - key = new_key; - keymax = bigger; - } - assert(keyused < keymax); - key[keyused++] = chunk; } - if (keyused == 0) - key[keyused++] = 0UL; + /* Fill array of unsigned longs from byte sequence. */ + key = (unsigned long *)PyMem_Malloc(sizeof(unsigned long) * keyused); + if (key == NULL) { + PyMem_Free(key_as_bytes); + goto Done; + } + for (i = 0; i < keyused; i++) { + key[i] = + ((unsigned long)key_as_bytes[4*i + 0] << 0) + + ((unsigned long)key_as_bytes[4*i + 1] << 8) + + ((unsigned long)key_as_bytes[4*i + 2] << 16) + + ((unsigned long)key_as_bytes[4*i + 3] << 24); + } + PyMem_Free(key_as_bytes); result = init_by_array(self, key, keyused); Done: - Py_XDECREF(masklower); - Py_XDECREF(thirtytwo); Py_XDECREF(n); PyMem_Free(key); return result; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 23:28:12 2012 From: python-checkins at python.org (stefan.krah) Date: Fri, 21 Dec 2012 23:28:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NzQ1?= =?utf-8?q?=3A_Hide_a_couple_of_symbols_by_making_them_local=2E?= Message-ID: <3YSkxm5hjtzRXK@mail.python.org> http://hg.python.org/cpython/rev/24f6c6f3b7bf changeset: 80972:24f6c6f3b7bf branch: 3.3 parent: 80969:6c31a921a569 user: Stefan Krah date: Fri Dec 21 23:11:05 2012 +0100 summary: Issue #16745: Hide a couple of symbols by making them local. files: Modules/_decimal/_decimal.c | 2 +- Modules/_decimal/libmpdec/mpdecimal.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3484,7 +3484,7 @@ } } -PyObject *DecimalTuple = NULL; +static PyObject *DecimalTuple = NULL; /* Return the DecimalTuple representation of a PyDecObject. */ static PyObject * PyDec_AsTuple(PyObject *dec, PyObject *dummy UNUSED) diff --git a/Modules/_decimal/libmpdec/mpdecimal.c b/Modules/_decimal/libmpdec/mpdecimal.c --- a/Modules/_decimal/libmpdec/mpdecimal.c +++ b/Modules/_decimal/libmpdec/mpdecimal.c @@ -107,7 +107,7 @@ mpd_uint_t exp, uint8_t resultsign, const mpd_context_t *ctx, uint32_t *status); -mpd_uint_t mpd_qsshiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n); +static mpd_uint_t mpd_qsshiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n); /******************************************************************************/ @@ -2301,7 +2301,7 @@ * It is the caller's responsibility to ensure that the coefficient is big * enough. The function cannot fail. */ -mpd_uint_t +static mpd_uint_t mpd_qsshiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n) { mpd_uint_t rnd; @@ -5123,7 +5123,7 @@ * to the result or NULL in case of failure (malloc error). * Conditions: ulen >= vlen, ulen >= 4 */ -mpd_uint_t * +static mpd_uint_t * _mpd_kmul(const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t ulen, mpd_size_t vlen, mpd_size_t *rsize) @@ -5208,7 +5208,7 @@ } #endif -unsigned int +static unsigned int mpd_set_fenv(void) { unsigned int cw; @@ -5228,7 +5228,7 @@ return cw; } -void +static void mpd_restore_fenv(unsigned int cw) { #ifdef _MSC_VER @@ -5246,7 +5246,7 @@ * Multiply u and v, using the fast number theoretic transform. Returns * a pointer to the result or NULL in case of failure (malloc error). */ -mpd_uint_t * +static mpd_uint_t * _mpd_fntmul(const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t ulen, mpd_size_t vlen, mpd_size_t *rsize) @@ -5432,7 +5432,7 @@ * base case. Returns a pointer to the result or NULL in case of failure * (malloc error). Conditions: ulen >= vlen, ulen >= 4. */ -mpd_uint_t * +static mpd_uint_t * _mpd_kmul_fnt(const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t ulen, mpd_size_t vlen, mpd_size_t *rsize) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 23:28:14 2012 From: python-checkins at python.org (stefan.krah) Date: Fri, 21 Dec 2012 23:28:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4zLg==?= Message-ID: <3YSkxp1LZqzQw0@mail.python.org> http://hg.python.org/cpython/rev/b149afa56290 changeset: 80973:b149afa56290 parent: 80970:860ed4bc8d32 parent: 80972:24f6c6f3b7bf user: Stefan Krah date: Fri Dec 21 23:23:25 2012 +0100 summary: Merge 3.3. files: Modules/_decimal/_decimal.c | 2 +- Modules/_decimal/libmpdec/mpdecimal.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3484,7 +3484,7 @@ } } -PyObject *DecimalTuple = NULL; +static PyObject *DecimalTuple = NULL; /* Return the DecimalTuple representation of a PyDecObject. */ static PyObject * PyDec_AsTuple(PyObject *dec, PyObject *dummy UNUSED) diff --git a/Modules/_decimal/libmpdec/mpdecimal.c b/Modules/_decimal/libmpdec/mpdecimal.c --- a/Modules/_decimal/libmpdec/mpdecimal.c +++ b/Modules/_decimal/libmpdec/mpdecimal.c @@ -107,7 +107,7 @@ mpd_uint_t exp, uint8_t resultsign, const mpd_context_t *ctx, uint32_t *status); -mpd_uint_t mpd_qsshiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n); +static mpd_uint_t mpd_qsshiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n); /******************************************************************************/ @@ -2301,7 +2301,7 @@ * It is the caller's responsibility to ensure that the coefficient is big * enough. The function cannot fail. */ -mpd_uint_t +static mpd_uint_t mpd_qsshiftr(mpd_t *result, const mpd_t *a, mpd_ssize_t n) { mpd_uint_t rnd; @@ -5123,7 +5123,7 @@ * to the result or NULL in case of failure (malloc error). * Conditions: ulen >= vlen, ulen >= 4 */ -mpd_uint_t * +static mpd_uint_t * _mpd_kmul(const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t ulen, mpd_size_t vlen, mpd_size_t *rsize) @@ -5208,7 +5208,7 @@ } #endif -unsigned int +static unsigned int mpd_set_fenv(void) { unsigned int cw; @@ -5228,7 +5228,7 @@ return cw; } -void +static void mpd_restore_fenv(unsigned int cw) { #ifdef _MSC_VER @@ -5246,7 +5246,7 @@ * Multiply u and v, using the fast number theoretic transform. Returns * a pointer to the result or NULL in case of failure (malloc error). */ -mpd_uint_t * +static mpd_uint_t * _mpd_fntmul(const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t ulen, mpd_size_t vlen, mpd_size_t *rsize) @@ -5432,7 +5432,7 @@ * base case. Returns a pointer to the result or NULL in case of failure * (malloc error). Conditions: ulen >= vlen, ulen >= 4. */ -mpd_uint_t * +static mpd_uint_t * _mpd_kmul_fnt(const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t ulen, mpd_size_t vlen, mpd_size_t *rsize) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 21 23:28:15 2012 From: python-checkins at python.org (stefan.krah) Date: Fri, 21 Dec 2012 23:28:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?b?KTogTWVyZ2Uu?= Message-ID: <3YSkxq4kkDzRb3@mail.python.org> http://hg.python.org/cpython/rev/324ebe561a0f changeset: 80974:324ebe561a0f parent: 80973:b149afa56290 parent: 80971:db75553ff333 user: Stefan Krah date: Fri Dec 21 23:27:13 2012 +0100 summary: Merge. files: Modules/_randommodule.c | 99 ++++++++++------------------ 1 files changed, 35 insertions(+), 64 deletions(-) diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -168,9 +168,9 @@ /* init_key is the array for initializing keys */ /* key_length is its length */ static PyObject * -init_by_array(RandomObject *self, unsigned long init_key[], unsigned long key_length) +init_by_array(RandomObject *self, unsigned long init_key[], size_t key_length) { - unsigned int i, j, k; /* was signed in the original code. RDH 12/16/2002 */ + size_t i, j, k; /* was signed in the original code. RDH 12/16/2002 */ unsigned long *mt; mt = self->state; @@ -207,14 +207,11 @@ random_seed(RandomObject *self, PyObject *args) { PyObject *result = NULL; /* guilty until proved innocent */ - PyObject *masklower = NULL; - PyObject *thirtytwo = NULL; PyObject *n = NULL; - unsigned long *new_key, *key = NULL; - unsigned long keymax; /* # of allocated slots in key */ - unsigned long keyused; /* # of used slots in key */ - int err; - + unsigned long *key = NULL; + unsigned char *key_as_bytes = NULL; + size_t bits, keyused, i; + int res; PyObject *arg = NULL; if (!PyArg_UnpackTuple(args, "seed", 0, 1, &arg)) @@ -243,69 +240,43 @@ if (n == NULL) goto Done; - /* Now split n into 32-bit chunks, from the right. Each piece is - * stored into key, which has a capacity of keymax chunks, of which - * keyused are filled. Alas, the repeated shifting makes this a - * quadratic-time algorithm; we'd really like to use - * _PyLong_AsByteArray here, but then we'd have to break into the - * long representation to figure out how big an array was needed - * in advance. - */ - keymax = 8; /* arbitrary; grows later if needed */ - keyused = 0; - key = (unsigned long *)PyMem_Malloc(keymax * sizeof(*key)); - if (key == NULL) + /* Now split n into 32-bit chunks, from the right. */ + bits = _PyLong_NumBits(n); + if (bits == (size_t)-1 && PyErr_Occurred()) goto Done; - masklower = PyLong_FromUnsignedLong(0xffffffffU); - if (masklower == NULL) + /* Figure out how many 32-bit chunks this gives us. */ + keyused = bits == 0 ? 1 : (bits - 1) / 32 + 1; + + /* Convert seed to byte sequence. */ + key_as_bytes = (unsigned char *)PyMem_Malloc((size_t)4 * keyused); + if (key_as_bytes == NULL) goto Done; - thirtytwo = PyLong_FromLong(32L); - if (thirtytwo == NULL) + res = _PyLong_AsByteArray((PyLongObject *)n, + key_as_bytes, keyused * 4, + 1, /* little-endian */ + 0); /* unsigned */ + if (res == -1) { + PyMem_Free(key_as_bytes); goto Done; - while ((err=PyObject_IsTrue(n))) { - PyObject *newn; - PyObject *pychunk; - unsigned long chunk; - - if (err == -1) - goto Done; - pychunk = PyNumber_And(n, masklower); - if (pychunk == NULL) - goto Done; - chunk = PyLong_AsUnsignedLong(pychunk); - Py_DECREF(pychunk); - if (chunk == (unsigned long)-1 && PyErr_Occurred()) - goto Done; - newn = PyNumber_Rshift(n, thirtytwo); - if (newn == NULL) - goto Done; - Py_DECREF(n); - n = newn; - if (keyused >= keymax) { - unsigned long bigger = keymax << 1; - if ((bigger >> 1) != keymax || - bigger > PY_SSIZE_T_MAX / sizeof(*key)) { - PyErr_NoMemory(); - goto Done; - } - new_key = (unsigned long *)PyMem_Realloc(key, - bigger * sizeof(*key)); - if (new_key == NULL) - goto Done; - key = new_key; - keymax = bigger; - } - assert(keyused < keymax); - key[keyused++] = chunk; } - if (keyused == 0) - key[keyused++] = 0UL; + /* Fill array of unsigned longs from byte sequence. */ + key = (unsigned long *)PyMem_Malloc(sizeof(unsigned long) * keyused); + if (key == NULL) { + PyMem_Free(key_as_bytes); + goto Done; + } + for (i = 0; i < keyused; i++) { + key[i] = + ((unsigned long)key_as_bytes[4*i + 0] << 0) + + ((unsigned long)key_as_bytes[4*i + 1] << 8) + + ((unsigned long)key_as_bytes[4*i + 2] << 16) + + ((unsigned long)key_as_bytes[4*i + 3] << 24); + } + PyMem_Free(key_as_bytes); result = init_by_array(self, key, keyused); Done: - Py_XDECREF(masklower); - Py_XDECREF(thirtytwo); Py_XDECREF(n); PyMem_Free(key); return result; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 01:52:47 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 22 Dec 2012 01:52:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Mark_3153_as_superseded_by_31?= =?utf-8?b?NTYu?= Message-ID: <3YSp8b1b01zNmy@mail.python.org> http://hg.python.org/peps/rev/309b581f6602 changeset: 4629:309b581f6602 user: Guido van Rossum date: Fri Dec 21 16:52:41 2012 -0800 summary: Mark 3153 as superseded by 3156. files: pep-3153.txt | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/pep-3153.txt b/pep-3153.txt --- a/pep-3153.txt +++ b/pep-3153.txt @@ -3,11 +3,12 @@ Version: $Revision$ Last-Modified: $Date$ Author: Laurens Van Houtven <_ at lvh.cc> -Status: Draft +Status: Superseded Type: Standards Track Content-Type: text/x-rst Created: 29-May-2011 Post-History: TBD +Superseded-By: 3156 Abstract ======== -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Sat Dec 22 05:52:55 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 22 Dec 2012 05:52:55 +0100 Subject: [Python-checkins] Daily reference leaks (324ebe561a0f): sum=2 Message-ID: results for 324ebe561a0f on branch "default" -------------------------------------------- test_concurrent_futures leaked [-2, 3, 1] memory blocks, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogUfwdQa', '-x'] From python-checkins at python.org Sat Dec 22 07:10:55 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 22 Dec 2012 07:10:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Replace_par=28=29_with_wait?= =?utf-8?b?KCkgYW5kIGFzX2NvbXBsZXRlZCgpLA==?= Message-ID: <3YSxCg4qP1zRY1@mail.python.org> http://hg.python.org/peps/rev/2c09d40bf30b changeset: 4630:2c09d40bf30b user: Guido van Rossum date: Fri Dec 21 22:10:48 2012 -0800 summary: Replace par() with wait() and as_completed(), files: pep-3156.txt | 45 ++++++++++++++++++++++++++------------- 1 files changed, 30 insertions(+), 15 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -514,6 +514,8 @@ A ``tulip.Future`` object is not acceptable to the ``wait()`` and ``as_completed()`` functions in the ``concurrent.futures`` package. +However, there are similar APIs ``tulip.wait()`` and +``tulip.as_completed()``, described below. A ``tulip.Future`` object is acceptable to a ``yield from`` expression when used in a coroutine. This is implemented through the @@ -752,18 +754,40 @@ produce a result (or raise an exception, which will be propagated). The ``coroutine`` expression must be a *call* to another coroutine. -- ``results = yield from tulip.par(futures_and_coroutines)`` -- Wait - for a list of futures and/or coroutines to complete and return a - list of their results. If one of the futures or coroutines raises - an exception, that exception is propagated, after attempting to - cancel all other futures and coroutines in the list. - - ``return result`` -- produce a result to the coroutine that is waiting for this one using ``yield from``. - ``raise exception`` -- raise an exception in the coroutine that is waiting for this one using ``yield from``. +To wait for multiple coroutines, two APIs similar to the ``wait()`` +and ``as_completed()`` APIs in the ``concurrent.futures`` package are +provided: + +- ``tulip.wait(fs, ...)``. Wait for the Futures or coroutines given + by ``fs`` to complete. This is a coroutine whose result on success + is a tuple of two sets of Futures, ``(done, not_done)``. Optional + arguments ``timeout`` and ``return_when`` have the same meaning and + defaults as for ``concurrent.futures.wait()``. The constants + ``FIRST_COMPLETED``, ``FIRST_EXCEPTION``, ``ALL_COMPLETED`` are + defined with the same values and the same meanings as in PEP 3148. + +- ``as_completed(fs, ...)``. Return an iterator whose values are + coroutines; waiting for successive values waits until the next + Future or coroutine from the set ``fs`` completes, and returns its + result (or raises its exception). The optional argument ``timeout`` + has the same meaning and default as it does for + ``concurrent.futures.wait()``; if the timeout is reached, the next + coroutine will raise ``concurrent.futures.TimeoutError`` when waited + for. Example of use:: + + for f in as_completed(fs): + result = yield from f + +(TBD: should ``as_completed()`` return an iterator of coroutines or an +iterator of Futures? For ``wait()`` it's clear that the sets should +only contain Futures; but less so for ``as_completed()``.) + Calling a coroutine does not start its code running -- it is just a generator, and the coroutine object returned by the call is really a generator object, which doesn't do anything until you iterate over it. @@ -789,10 +813,6 @@ to (this is done using the standard ``close()`` method on generators, described in PEP 342). -The ``par()`` function described above runs coroutines in parallel by -converting them to Tasks. (Arguments that are already Tasks or -Futures are not converted.) - Tasks are also useful for interoperating between coroutines and callback-based frameworks like Twisted. After converting a coroutine into a Task, callbacks can be added to the Task. @@ -819,11 +839,6 @@ TBD: ``yield sleep(seconds)``. Can use ``sleep(0)`` to suspend to poll for I/O. -Wait for First --------------- - -TBD: Need an interface to wait for the first of a collection of Futures. - Coroutines and Protocols ------------------------ -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 22 07:17:40 2012 From: python-checkins at python.org (guido.van.rossum) Date: Sat, 22 Dec 2012 07:17:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Remove_some_vague_issues_and_?= =?utf-8?q?the_wait=5Fone=28=29_proposal=2E?= Message-ID: <3YSxMS5DFlzRg5@mail.python.org> http://hg.python.org/peps/rev/cc84f0d1a142 changeset: 4631:cc84f0d1a142 user: Guido van Rossum date: Fri Dec 21 22:17:35 2012 -0800 summary: Remove some vague issues and the wait_one() proposal. files: pep-3156.txt | 44 +++------------------------------------ 1 files changed, 4 insertions(+), 40 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -878,44 +878,10 @@ given a file descriptor. Or when the next scheduled call is. Or the list of file descriptors registered with callbacks. -- Should we have ``future.add_callback(callback, *args)``, using the - convention from the section "Callback Style" above, or should we - stick with the PEP 3148 specification of - ``future.add_done_callback(callback)`` which calls - ``callback(future)``? (Glyph suggested using a different method - name since add_done_callback() does not guarantee that the callback - will be called in the right context.) - -- Returning a Future is relatively expensive, and it is quite possible - that some types of calls *usually* complete immediately - (e.g. writing small amounts of data to a socket). A trick used by - Richard Oudkerk in the tulip project's proactor branch makes calls - like recv() either return a regular result or *raise* a Future. The - caller (likely a transport) must then write code like this:: - - try: - res = ev.sock_recv(sock, 8192) - except Future as f: - yield from sch.block_future(f) - res = f.result() - -- Do we need a larger vocabulary of operations for combining - coroutines and/or futures? E.g. in addition to par() we could have - a way to run several coroutines sequentially (returning all results - or passing the result of one to the next and returning the final - result?). We might also introduce explicit locks (though these will - be a bit of a pain to use, as we can't use the ``with lock: block`` - syntax). Anyway, I think all of these are easy enough to write - using ``Task``. - - Proposal: ``f = yield from wait_one(fs)`` takes a set of Futures and - sets f to the first of those that is done. (Yes, this requires an - intermediate Future to wait for.) You can then write:: - - while fs: - f = tulip.wait_one(fs) - fs.remove(f) - +- We might introduce explicit locks, though these will be a bit of a + pain to use, as we can't use the ``with lock: block`` syntax + (because to wait for a lock we'd have to use ``yield from``, which + the ``with`` statement can't do). - Support for datagram protocols, "connected" or otherwise? Probably need more socket I/O methods, e.g. ``sock_sendto()`` and @@ -923,8 +889,6 @@ science). Is it reasonable to map ``write()``, ``writelines()``, ``data_received()`` to single datagrams? -- Task or callback priorities? (I hope not.) - - An EventEmitter in the style of NodeJS? Or make this a separate PEP? It's easy enough to do in user space, though it may benefit from standardization. (See -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 22 10:26:07 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 22 Dec 2012 10:26:07 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Re-add_word_that_got_drop?= =?utf-8?q?ped_in_06225ce4c1d3=2E?= Message-ID: <3YT1Xv4VMnzNNk@mail.python.org> http://hg.python.org/devguide/rev/73740d41027e changeset: 578:73740d41027e user: Georg Brandl date: Sat Dec 22 10:26:43 2012 +0100 summary: Re-add word that got dropped in 06225ce4c1d3. files: buildbots.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/buildbots.rst b/buildbots.rst --- a/buildbots.rst +++ b/buildbots.rst @@ -54,7 +54,7 @@ --------- A subset of the buildbots are marked "stable". They are taken into account -when making a new release. The rule is that all builders must be free of +when making a new release. The rule is that all stable builders must be free of persistent failures when the release is cut. It is absolutely **vital** that core developers fix any issue they introduce on the stable buildbots, as soon as possible. -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Sat Dec 22 10:36:12 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 22 Dec 2012 10:36:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_a_missing_versionadded?= =?utf-8?q?=2E?= Message-ID: <3YT1mX5LQ2zNBB@mail.python.org> http://hg.python.org/cpython/rev/8006110102c5 changeset: 80975:8006110102c5 user: Georg Brandl date: Sat Dec 22 10:36:45 2012 +0100 summary: Add a missing versionadded. files: Doc/library/urllib.request.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -465,6 +465,8 @@ Remove named header from the request instance (both from regular and unredirected headers). + .. versionadded:: 3.4 + .. method:: Request.get_full_url() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 10:43:36 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 22 Dec 2012 10:43:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_indentatio?= =?utf-8?q?n=2E?= Message-ID: <3YT1x46wJjzM9g@mail.python.org> http://hg.python.org/cpython/rev/85de707bc119 changeset: 80976:85de707bc119 branch: 2.7 parent: 80966:5ca63d68792d user: Georg Brandl date: Sat Dec 22 10:43:06 2012 +0100 summary: Fix indentation. files: Doc/library/imp.rst | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/library/imp.rst b/Doc/library/imp.rst --- a/Doc/library/imp.rst +++ b/Doc/library/imp.rst @@ -239,14 +239,14 @@ .. impl-detail:: - The import internals identify extension modules by filename, so doing - ``foo = load_dynamic("foo", "mod.so")`` and - ``bar = load_dynamic("bar", "mod.so")`` will result in both foo and bar - referring to the same module, regardless of whether or not - ``mod.so`` exports an ``initbar`` function. On systems which - support them, symlinks can be used to import multiple modules from - the same shared library, as each reference to the module will use - a different file name. + The import internals identify extension modules by filename, so doing + ``foo = load_dynamic("foo", "mod.so")`` and + ``bar = load_dynamic("bar", "mod.so")`` will result in both foo and bar + referring to the same module, regardless of whether or not + ``mod.so`` exports an ``initbar`` function. On systems which + support them, symlinks can be used to import multiple modules from + the same shared library, as each reference to the module will use + a different file name. .. function:: load_source(name, pathname[, file]) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 10:43:38 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 22 Dec 2012 10:43:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Add_missing_la?= =?utf-8?q?bel=2E?= Message-ID: <3YT1x62SjfzNPR@mail.python.org> http://hg.python.org/cpython/rev/231e4889b117 changeset: 80977:231e4889b117 branch: 2.7 user: Georg Brandl date: Sat Dec 22 10:44:11 2012 +0100 summary: Add missing label. files: Doc/using/windows.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst --- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -84,6 +84,8 @@ settings in Windows. +.. _setting-envvars: + Excursus: Setting environment variables --------------------------------------- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 12:30:25 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 22 Dec 2012 12:30:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Further_updates_to_PEP_1_to_b?= =?utf-8?q?etter_reflect_current_practice?= Message-ID: <3YT4JK0lfGzNcH@mail.python.org> http://hg.python.org/peps/rev/24d5623ab21e changeset: 4632:24d5623ab21e user: Nick Coghlan date: Sat Dec 22 21:30:14 2012 +1000 summary: Further updates to PEP 1 to better reflect current practice - identify the current PEP editors and clarify their role - separate out PEP administrative email from design discussion - reference implementations typically co-evolve with their PEP - it's OK to get a PEP number before a PEP is ready for python-dev - eliminate most of the ambiguous 'we' references (Initial patch by Chris Jerdonek) files: pep-0001.txt | 138 ++++++++++++++++++++------------- pep0/constants.py | 9 +- 2 files changed, 88 insertions(+), 59 deletions(-) diff --git a/pep-0001.txt b/pep-0001.txt --- a/pep-0001.txt +++ b/pep-0001.txt @@ -57,8 +57,8 @@ Any meta-PEP is also considered a Process PEP. -PEP Work Flow -============= +PEP Workflow +============ Python's BDFL @@ -70,19 +70,38 @@ programming language. +PEP Editors +----------- + +The PEP editors are individuals responsible for managing the administrative +and editorial aspects of the PEP workflow (e.g. assigning PEP numbers and +changing their status). See `PEP Editor Responsibilities & Workflow`_ for +details. The current editors are: + +* Anthony Baxter +* Georg Brandl +* Brett Cannon +* David Goodger +* Jesse Noller +* Guido van Rossum +* Barry Warsaw + +PEP editorship is by invitation of the current editors. The address + is a mailing list consisting of PEP editors. All +email related to PEP administration (such as requesting a PEP number +or providing an updated version of a PEP for posting) should be sent to +this address (no cross-posting please). + + Submitting a PEP ---------------- -The PEP editors assign PEP numbers and change their status. Please send -all PEP-related email to (no cross-posting please). -Also see `PEP Editor Responsibilities & Workflow`_ below. - The PEP process begins with a new idea for Python. It is highly recommended that a single PEP contain a single key proposal or new idea. Small enhancements or patches often don't need -a PEP and can be injected into the Python development work flow with a +a PEP and can be injected into the Python development workflow with a patch submission to the Python `issue tracker`_. The more focused the -PEP, the more successful it tends to be. The PEP editor reserves the +PEP, the more successful it tends to be. The PEP editors reserve the right to reject PEP proposals if they appear too unfocused or too broad. If in doubt, split your PEP into several well-focused ones. @@ -111,16 +130,15 @@ PEP to make properly formatted, of high quality, and to address initial concerns about the proposal. -Following a discussion on python-ideas, the proposal should be sent to -the `python-dev list `__ with the draft -PEP and the PEP editors . This -draft must be written in PEP style as described below, else it will be -sent back without further regard until proper formatting rules are -followed. +Following a discussion on python-ideas, the proposal should be sent as a +draft PEP to the PEP editors . The draft must be written +in PEP style as described below, else it will be sent back without further +regard until proper formatting rules are followed (although minor errors +will be corrected by the editors). -If the PEP editor approves, they will assign the PEP a number, label it +If the PEP editors approve, they will assign the PEP a number, label it as Standards Track, Informational, or Process, give it status "Draft", -and create and check-in the initial draft of the PEP. The PEP editor +and create and check-in the initial draft of the PEP. The PEP editors will not unreasonably deny a PEP. Reasons for denying PEP status include duplication of effort, being technically unsound, not providing proper motivation or addressing backwards compatibility, or @@ -138,21 +156,27 @@ hg push privileges and they can guide you through the process of updating the PEP repository directly. -As updates are necessary, the PEP author can check in new versions if -they have hg push privileges, or can email new PEP versions to -the PEP editors for publication. +As updates are necessary, the PEP author can check in new versions if they +(or a collaborating developer) have hg push privileges, or else they can +email new PEP versions to the PEP editors for publication. + +After a PEP number has been assigned, a draft PEP may be discussed further on +python-ideas (getting a PEP number assigned early can be useful for ease of +reference, especially when multiple draft PEPs are being considered at the +same time). Eventually, all Standards Track PEPs must be sent to the +`python-dev list `__ for review as described +in the next section. Standards Track PEPs consist of two parts, a design document and a -reference implementation. The PEP should be reviewed and accepted -before a reference implementation is begun, unless a reference -implementation will aid people in studying the PEP. Standards Track -PEPs must include an implementation -- in the form of code, a patch, -or a URL to same -- before it can be considered Final. +reference implementation. It is generally recommended that at least a +prototype implementation be co-developed with the PEP, as ideas that sound +good in principle sometimes turn out to be impractical when subjected to the +test of implementation. PEP authors are responsible for collecting community feedback on a PEP before submitting it for review. However, wherever possible, long open-ended discussions on public mailing lists should be avoided. -Strategies to keep the discussions efficient include: setting up a +Strategies to keep the discussions efficient include: setting up a separate SIG mailing list for the topic, having the PEP author accept private comments in the early design phases, setting up a wiki page, etc. PEP authors should use their discretion here. @@ -200,9 +224,9 @@ completed. When the reference implementation is complete and incorporated into the main source code repository, the status will be changed to "Final". -A PEP can also be assigned status "Deferred". The PEP author or +A PEP can also be assigned status "Deferred". The PEP author or an editor can assign the PEP this status when no progress is being made -on the PEP. Once a PEP is deferred, the PEP editor can re-assign it +on the PEP. Once a PEP is deferred, a PEP editor can re-assign it to draft status. A PEP can also be "Rejected". Perhaps after all is said and done it @@ -262,8 +286,8 @@ 4. Specification -- The technical specification should describe the syntax and semantics of any new language feature. The specification should be detailed enough to allow competing, - interoperable implementations for any of the current Python - platforms (CPython, Jython, Python .NET). + interoperable implementations for at least the current major Python + platforms (CPython, Jython, IronPython, PyPy). 5. Motivation -- The motivation is critical for PEPs that want to change the Python language. It should clearly explain why the @@ -290,9 +314,11 @@ 8. Reference Implementation -- The reference implementation must be completed before any PEP is given status "Final", but it need not - be completed before the PEP is accepted. It is better to finish - the specification and rationale first and reach consensus on it - before writing code. + be completed before the PEP is accepted. While there is merit + to the approach of reaching consensus on the specification and + rationale before writing code, the principle of "rough consensus + and running code" is still useful when it comes to resolving many + discussions of API details. The final implementation must include test code and documentation appropriate for either the Python language reference or the @@ -429,12 +455,12 @@ directly to the PEP author. For more mature, or finished PEPs you may want to submit corrections to the Python `issue tracker`_ so that your changes don't get lost. If the PEP author is a Python developer, assign the -bug/patch to him, otherwise assign it to the PEP editor. +bug/patch to them, otherwise assign it to a PEP editor. When in doubt about where to send your changes, please check first -with the PEP author and/or PEP editor. +with the PEP author and/or a PEP editor. -PEP authors who are also Python committers can update the +PEP authors with hg push privileges for the PEP repository can update the PEPs themselves by using "hg push" to submit their changes. @@ -442,20 +468,21 @@ ========================== It occasionally becomes necessary to transfer ownership of PEPs to a -new champion. In general, we'd like to retain the original author as +new champion. In general, it is preferable to retain the original author as a co-author of the transferred PEP, but that's really up to the original author. A good reason to transfer ownership is because the original author no longer has the time or interest in updating it or following through with the PEP process, or has fallen off the face of the 'net (i.e. is unreachable or not responding to email). A bad -reason to transfer ownership is because you don't agree with the -direction of the PEP. We try to build consensus around a PEP, but if -that's not possible, you can always submit a competing PEP. +reason to transfer ownership is because the author doesn't agree with the +direction of the PEP. One aim of the PEP process is to try to build +consensus around a PEP, but if that's not possible, an author can always +submit a competing PEP. If you are interested in assuming ownership of a PEP, send a message asking to take over, addressed to both the original author and the PEP -editor . If the original author doesn't respond to -email in a timely manner, the PEP editor will make a unilateral +editors . If the original author doesn't respond to +email in a timely manner, the PEP editors will make a unilateral decision (it's not like such decisions can't be reversed :). @@ -463,7 +490,7 @@ ====================================== A PEP editor must subscribe to the list. All -PEP-related correspondence should be sent (or CC'd) to +correspondence related to PEP administration should be sent (or forwarded) to (but please do not cross-post!). For each new PEP that comes in an editor does the following: @@ -478,20 +505,20 @@ etc.), markup (for reST PEPs), code style (examples should match PEP 8 & 7). -If the PEP isn't ready, the editor will send it back to the author for +If the PEP isn't ready, an editor will send it back to the author for revision, with specific instructions. -Once the PEP is ready for the repository, the PEP editor will: +Once the PEP is ready for the repository, a PEP editor will: * Assign a PEP number (almost always just the next available number, but sometimes it's a special/joke number, like 666 or 3141). - (Clarification: For Python 3, we used numbers in the 3000s for + (Clarification: For Python 3, numbers in the 3000s were used for Py3k-specific proposals. But now that all new features go into - Python 3 only, we're back to using numbers in the 100s again. + Python 3 only, the process is back to using numbers in the 100s again. Remember that numbers below 100 are meta-PEPs.) -* Add the PEP to a local clone of the PEP repository. For mercurial work - flow instructions, follow `The Python Developers Guide `_ +* Add the PEP to a local clone of the PEP repository. For mercurial workflow + instructions, follow `The Python Developers Guide `_ The mercurial repo for the peps is:: @@ -502,9 +529,11 @@ will not be updated to reflect the PEP changes. * Commit and push the new (or updated) PEP - + * Monitor python.org to make sure the PEP gets added to the site - properly. + properly. If it fails to appear, running ``make`` will build all of the + current PEPs. If any of these are triggering errors, they must be + corrected before any PEP will update on the site. * Send email back to the PEP author with next steps (post to python-list & -dev). @@ -515,11 +544,10 @@ Many PEPs are written and maintained by developers with write access to the Python codebase. The PEP editors monitor the python-checkins list for PEP changes, and correct any structure, grammar, spelling, or -markup mistakes we see. +markup mistakes they see. -The editors don't pass judgment on PEPs. We merely do the -administrative & editorial part. Except for times like this, there's -relatively low volume. +PEP editors don't pass judgment on PEPs. They merely do the +administrative & editorial part (which is generally a low volume task). Resources: @@ -572,7 +600,7 @@ This document has been placed in the public domain. - + .. Local Variables: mode: indented-text diff --git a/pep0/constants.py b/pep0/constants.py --- a/pep0/constants.py +++ b/pep0/constants.py @@ -15,14 +15,15 @@ """ intro = u""" - The PEP contains the index of all Python Enhancement Proposals, - known as PEPs. PEP numbers are assigned by the PEP Editor, and - once assigned are never changed. The Mercurial history[1] of + This PEP contains the index of all Python Enhancement Proposals, + known as PEPs. PEP numbers are assigned by the PEP editors, and + once assigned are never changed[1]. The Mercurial history[2] of the PEP texts represent their historical record. """ references = u""" - [1] View PEP history online + [1] PEP 1: PEP Purpose and Guidelines + [2] View PEP history online http://hg.python.org/peps/ """ -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 22 12:33:34 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 22 Dec 2012 12:33:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Eliminate_some_awkward_phrasi?= =?utf-8?q?ng_=28noted_by_Ezio_Melloti=29?= Message-ID: <3YT4My5L40zNcq@mail.python.org> http://hg.python.org/peps/rev/afb5e538297d changeset: 4633:afb5e538297d user: Nick Coghlan date: Sat Dec 22 21:33:26 2012 +1000 summary: Eliminate some awkward phrasing (noted by Ezio Melloti) files: pep-0001.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0001.txt b/pep-0001.txt --- a/pep-0001.txt +++ b/pep-0001.txt @@ -87,7 +87,7 @@ * Barry Warsaw PEP editorship is by invitation of the current editors. The address - is a mailing list consisting of PEP editors. All + is a mailing list for contacting the PEP editors. All email related to PEP administration (such as requesting a PEP number or providing an updated version of a PEP for posting) should be sent to this address (no cross-posting please). -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 22 14:25:59 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 22 Dec 2012 14:25:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NzQ1?= =?utf-8?q?=3A_Hide_symbols_in_=5Fdecimal=2Eso=2E?= Message-ID: <3YT6sg0vhGzNcq@mail.python.org> http://hg.python.org/cpython/rev/51b0a150f8aa changeset: 80978:51b0a150f8aa branch: 3.3 parent: 80972:24f6c6f3b7bf user: Stefan Krah date: Sat Dec 22 14:18:35 2012 +0100 summary: Issue #16745: Hide symbols in _decimal.so. files: Modules/_decimal/libmpdec/basearith.h | 7 ++++ Modules/_decimal/libmpdec/constants.h | 7 ++++ Modules/_decimal/libmpdec/convolute.h | 9 +++++- Modules/_decimal/libmpdec/crt.h | 7 ++++ Modules/_decimal/libmpdec/difradix2.h | 7 ++++ Modules/_decimal/libmpdec/fnt.h | 7 ++++ Modules/_decimal/libmpdec/fourstep.h | 7 ++++ Modules/_decimal/libmpdec/memory.h | 7 ++++ Modules/_decimal/libmpdec/mpdecimal.h | 17 ++++++++++++ Modules/_decimal/libmpdec/numbertheory.h | 7 ++++ Modules/_decimal/libmpdec/sixstep.h | 7 ++++ Modules/_decimal/libmpdec/transpose.h | 7 ++++ 12 files changed, 95 insertions(+), 1 deletions(-) diff --git a/Modules/_decimal/libmpdec/basearith.h b/Modules/_decimal/libmpdec/basearith.h --- a/Modules/_decimal/libmpdec/basearith.h +++ b/Modules/_decimal/libmpdec/basearith.h @@ -35,6 +35,10 @@ #include "typearith.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + mpd_uint_t _mpd_baseadd(mpd_uint_t *w, const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t m, mpd_size_t n); void _mpd_baseaddto(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n); @@ -209,6 +213,9 @@ } +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif /* BASEARITH_H */ diff --git a/Modules/_decimal/libmpdec/constants.h b/Modules/_decimal/libmpdec/constants.h --- a/Modules/_decimal/libmpdec/constants.h +++ b/Modules/_decimal/libmpdec/constants.h @@ -33,6 +33,10 @@ #include "mpdecimal.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + /* choice of optimized functions */ #if defined(CONFIG_64) /* x64 */ @@ -77,6 +81,9 @@ extern const mpd_uint_t UH_P1P2; +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif /* CONSTANTS_H */ diff --git a/Modules/_decimal/libmpdec/convolute.h b/Modules/_decimal/libmpdec/convolute.h --- a/Modules/_decimal/libmpdec/convolute.h +++ b/Modules/_decimal/libmpdec/convolute.h @@ -33,11 +33,18 @@ #include "mpdecimal.h" #include + +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + #define SIX_STEP_THRESHOLD 4096 - int fnt_convolute(mpd_uint_t *c1, mpd_uint_t *c2, mpd_size_t n, int modnum); int fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/crt.h b/Modules/_decimal/libmpdec/crt.h --- a/Modules/_decimal/libmpdec/crt.h +++ b/Modules/_decimal/libmpdec/crt.h @@ -34,7 +34,14 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + void crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t nmemb); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/difradix2.h b/Modules/_decimal/libmpdec/difradix2.h --- a/Modules/_decimal/libmpdec/difradix2.h +++ b/Modules/_decimal/libmpdec/difradix2.h @@ -35,7 +35,14 @@ #include "numbertheory.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + void fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/fnt.h b/Modules/_decimal/libmpdec/fnt.h --- a/Modules/_decimal/libmpdec/fnt.h +++ b/Modules/_decimal/libmpdec/fnt.h @@ -34,9 +34,16 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int std_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); int std_inv_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/fourstep.h b/Modules/_decimal/libmpdec/fourstep.h --- a/Modules/_decimal/libmpdec/fourstep.h +++ b/Modules/_decimal/libmpdec/fourstep.h @@ -34,8 +34,15 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); int inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/memory.h b/Modules/_decimal/libmpdec/memory.h --- a/Modules/_decimal/libmpdec/memory.h +++ b/Modules/_decimal/libmpdec/memory.h @@ -33,11 +33,18 @@ #include "mpdecimal.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_realloc_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -67,10 +67,24 @@ #else #define UNUSED #endif + #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) + #define MPD_PRAGMA(x) _Pragma(x) + #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" + #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" + #else + #define MPD_PRAGMA(x) + #define MPD_HIDE_SYMBOLS_START + #define MPD_HIDE_SYMBOLS_END + #endif #define EXTINLINE #endif +/* This header file is internal for the purpose of building _decimal.so. + * All symbols should have local scope in the DSO. */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + #if !defined(LEGACY_COMPILER) #if !defined(UINT64_MAX) /* The following #error is just a warning. If the compiler indeed does @@ -789,6 +803,9 @@ int mpd_resize_zero(mpd_t *result, mpd_ssize_t size, mpd_context_t *ctx); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #ifdef __cplusplus } /* END extern "C" */ #endif diff --git a/Modules/_decimal/libmpdec/numbertheory.h b/Modules/_decimal/libmpdec/numbertheory.h --- a/Modules/_decimal/libmpdec/numbertheory.h +++ b/Modules/_decimal/libmpdec/numbertheory.h @@ -34,6 +34,10 @@ #include "mpdecimal.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + /* transform parameters */ struct fnt_params { int modnum; @@ -66,6 +70,9 @@ #endif +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/sixstep.h b/Modules/_decimal/libmpdec/sixstep.h --- a/Modules/_decimal/libmpdec/sixstep.h +++ b/Modules/_decimal/libmpdec/sixstep.h @@ -34,8 +34,15 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); int inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/transpose.h b/Modules/_decimal/libmpdec/transpose.h --- a/Modules/_decimal/libmpdec/transpose.h +++ b/Modules/_decimal/libmpdec/transpose.h @@ -34,6 +34,10 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + enum {FORWARD_CYCLE, BACKWARD_CYCLE}; @@ -52,4 +56,7 @@ } +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 14:26:00 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 22 Dec 2012 14:26:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4zLg==?= Message-ID: <3YT6sh4TW4zNvy@mail.python.org> http://hg.python.org/cpython/rev/8ffa8dc4b0f8 changeset: 80979:8ffa8dc4b0f8 parent: 80975:8006110102c5 parent: 80978:51b0a150f8aa user: Stefan Krah date: Sat Dec 22 14:24:55 2012 +0100 summary: Merge 3.3. files: Modules/_decimal/libmpdec/basearith.h | 7 ++++ Modules/_decimal/libmpdec/constants.h | 7 ++++ Modules/_decimal/libmpdec/convolute.h | 9 +++++- Modules/_decimal/libmpdec/crt.h | 7 ++++ Modules/_decimal/libmpdec/difradix2.h | 7 ++++ Modules/_decimal/libmpdec/fnt.h | 7 ++++ Modules/_decimal/libmpdec/fourstep.h | 7 ++++ Modules/_decimal/libmpdec/memory.h | 7 ++++ Modules/_decimal/libmpdec/mpdecimal.h | 17 ++++++++++++ Modules/_decimal/libmpdec/numbertheory.h | 7 ++++ Modules/_decimal/libmpdec/sixstep.h | 7 ++++ Modules/_decimal/libmpdec/transpose.h | 7 ++++ 12 files changed, 95 insertions(+), 1 deletions(-) diff --git a/Modules/_decimal/libmpdec/basearith.h b/Modules/_decimal/libmpdec/basearith.h --- a/Modules/_decimal/libmpdec/basearith.h +++ b/Modules/_decimal/libmpdec/basearith.h @@ -35,6 +35,10 @@ #include "typearith.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + mpd_uint_t _mpd_baseadd(mpd_uint_t *w, const mpd_uint_t *u, const mpd_uint_t *v, mpd_size_t m, mpd_size_t n); void _mpd_baseaddto(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n); @@ -209,6 +213,9 @@ } +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif /* BASEARITH_H */ diff --git a/Modules/_decimal/libmpdec/constants.h b/Modules/_decimal/libmpdec/constants.h --- a/Modules/_decimal/libmpdec/constants.h +++ b/Modules/_decimal/libmpdec/constants.h @@ -33,6 +33,10 @@ #include "mpdecimal.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + /* choice of optimized functions */ #if defined(CONFIG_64) /* x64 */ @@ -77,6 +81,9 @@ extern const mpd_uint_t UH_P1P2; +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif /* CONSTANTS_H */ diff --git a/Modules/_decimal/libmpdec/convolute.h b/Modules/_decimal/libmpdec/convolute.h --- a/Modules/_decimal/libmpdec/convolute.h +++ b/Modules/_decimal/libmpdec/convolute.h @@ -33,11 +33,18 @@ #include "mpdecimal.h" #include + +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + #define SIX_STEP_THRESHOLD 4096 - int fnt_convolute(mpd_uint_t *c1, mpd_uint_t *c2, mpd_size_t n, int modnum); int fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/crt.h b/Modules/_decimal/libmpdec/crt.h --- a/Modules/_decimal/libmpdec/crt.h +++ b/Modules/_decimal/libmpdec/crt.h @@ -34,7 +34,14 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + void crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t nmemb); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/difradix2.h b/Modules/_decimal/libmpdec/difradix2.h --- a/Modules/_decimal/libmpdec/difradix2.h +++ b/Modules/_decimal/libmpdec/difradix2.h @@ -35,7 +35,14 @@ #include "numbertheory.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + void fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/fnt.h b/Modules/_decimal/libmpdec/fnt.h --- a/Modules/_decimal/libmpdec/fnt.h +++ b/Modules/_decimal/libmpdec/fnt.h @@ -34,9 +34,16 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int std_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); int std_inv_fnt(mpd_uint_t a[], mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/fourstep.h b/Modules/_decimal/libmpdec/fourstep.h --- a/Modules/_decimal/libmpdec/fourstep.h +++ b/Modules/_decimal/libmpdec/fourstep.h @@ -34,8 +34,15 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); int inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/memory.h b/Modules/_decimal/libmpdec/memory.h --- a/Modules/_decimal/libmpdec/memory.h +++ b/Modules/_decimal/libmpdec/memory.h @@ -33,11 +33,18 @@ #include "mpdecimal.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_realloc_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -67,10 +67,24 @@ #else #define UNUSED #endif + #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) + #define MPD_PRAGMA(x) _Pragma(x) + #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" + #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" + #else + #define MPD_PRAGMA(x) + #define MPD_HIDE_SYMBOLS_START + #define MPD_HIDE_SYMBOLS_END + #endif #define EXTINLINE #endif +/* This header file is internal for the purpose of building _decimal.so. + * All symbols should have local scope in the DSO. */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + #if !defined(LEGACY_COMPILER) #if !defined(UINT64_MAX) /* The following #error is just a warning. If the compiler indeed does @@ -789,6 +803,9 @@ int mpd_resize_zero(mpd_t *result, mpd_ssize_t size, mpd_context_t *ctx); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #ifdef __cplusplus } /* END extern "C" */ #endif diff --git a/Modules/_decimal/libmpdec/numbertheory.h b/Modules/_decimal/libmpdec/numbertheory.h --- a/Modules/_decimal/libmpdec/numbertheory.h +++ b/Modules/_decimal/libmpdec/numbertheory.h @@ -34,6 +34,10 @@ #include "mpdecimal.h" +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + /* transform parameters */ struct fnt_params { int modnum; @@ -66,6 +70,9 @@ #endif +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/sixstep.h b/Modules/_decimal/libmpdec/sixstep.h --- a/Modules/_decimal/libmpdec/sixstep.h +++ b/Modules/_decimal/libmpdec/sixstep.h @@ -34,8 +34,15 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + int six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); int inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum); +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif diff --git a/Modules/_decimal/libmpdec/transpose.h b/Modules/_decimal/libmpdec/transpose.h --- a/Modules/_decimal/libmpdec/transpose.h +++ b/Modules/_decimal/libmpdec/transpose.h @@ -34,6 +34,10 @@ #include +/* Internal header file: all symbols have local scope in the DSO */ +MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) + + enum {FORWARD_CYCLE, BACKWARD_CYCLE}; @@ -52,4 +56,7 @@ } +MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ + + #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 14:57:58 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 22 Dec 2012 14:57:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Fix_Visual_Stu?= =?utf-8?q?dio_build=2E?= Message-ID: <3YT7ZZ2NmFzNmQ@mail.python.org> http://hg.python.org/cpython/rev/93902bd37f48 changeset: 80980:93902bd37f48 branch: 3.3 parent: 80978:51b0a150f8aa user: Stefan Krah date: Sat Dec 22 14:46:44 2012 +0100 summary: Fix Visual Studio build. files: Modules/_decimal/libmpdec/mpdecimal.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -51,6 +51,9 @@ #ifndef UNUSED #define UNUSED #endif + #define MPD_PRAGMA(x) + #define MPD_HIDE_SYMBOLS_START + #define MPD_HIDE_SYMBOLS_END #define EXTINLINE extern inline #else #ifdef HAVE_STDINT_H -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 14:57:59 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 22 Dec 2012 14:57:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4zLg==?= Message-ID: <3YT7Zb4j71zNsf@mail.python.org> http://hg.python.org/cpython/rev/568019d6bf6b changeset: 80981:568019d6bf6b parent: 80979:8ffa8dc4b0f8 parent: 80980:93902bd37f48 user: Stefan Krah date: Sat Dec 22 14:57:16 2012 +0100 summary: Merge 3.3. files: Modules/_decimal/libmpdec/mpdecimal.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -51,6 +51,9 @@ #ifndef UNUSED #define UNUSED #endif + #define MPD_PRAGMA(x) + #define MPD_HIDE_SYMBOLS_START + #define MPD_HIDE_SYMBOLS_END #define EXTINLINE extern inline #else #ifdef HAVE_STDINT_H -- Repository URL: http://hg.python.org/cpython From root at python.org Sat Dec 22 15:05:02 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:05:02 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: HTTP Error 500: Internal Server Error From root at python.org Sat Dec 22 15:10:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:10:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:15:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:15:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:20:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:20:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:25:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:25:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:30:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:30:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:35:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:35:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:40:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:40:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:45:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:45:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:50:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:50:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 15:55:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 15:55:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:00:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:00:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:05:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:05:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:10:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:10:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:15:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:15:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:20:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:20:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:25:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:25:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:30:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:30:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:35:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:35:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:40:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:40:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:45:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:45:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:50:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:50:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 16:55:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 16:55:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:00:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:00:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:05:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:05:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:10:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:10:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:15:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:15:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:20:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:20:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:25:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:25:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:30:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:30:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:35:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:35:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:40:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:40:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:45:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:45:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:50:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:50:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 17:55:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 17:55:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:00:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:00:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:05:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:05:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:10:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:10:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:15:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:15:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:20:24 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:20:24 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:25:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:25:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:30:25 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:30:25 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:35:25 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:35:25 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:40:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:40:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:45:23 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:45:23 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:50:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:50:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 18:55:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 18:55:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 19:00:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 19:00:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 19:05:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 19:05:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 19:10:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 19:10:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 19:15:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 19:15:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 19:20:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 19:20:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 19:25:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 19:25:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From root at python.org Sat Dec 22 19:30:22 2012 From: root at python.org (Cron Daemon) Date: Sat, 22 Dec 2012 19:30:22 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection timed out From tjreedy at udel.edu Sat Dec 22 21:36:43 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Dec 2012 15:36:43 -0500 Subject: [Python-checkins] Cron /home/docs/build-devguide In-Reply-To: References: Message-ID: <50D619DB.2080304@udel.edu> On 12/22/2012 1:30 PM, Cron Daemon wrote: > abort: error: Connection timed out > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins As a volunteer checkin-list admin, I occasionally get messages like this: ''' As list administrator, your authorization is requested for the following mailing list posting: List: Python-checkins at python.org From: root at python.org Subject: Cron /home/docs/build-devguide Reason: Message has implicit destination At your convenience, visit: http://mail.python.org/mailman/admindb/python-checkins to approve or deny the request. ''' I always reject the requests as I don't believe these messages belong here. I even asked, some months ago, on pydev who was responsible for the robot that sends these but got no answer. Today, apparently, another list admin decided on the opposite response and gave root at python.org blanket permission to flood this list with irrelavancy. It it not my responsibility and I have no idea how to fix it. While people with push priviliges are supposed to subscribe to this list, I know there is at least one who unsubscribed because of the volume. This will only encourage more to leave, so I hope someone can stop it. Terry From barry at python.org Sat Dec 22 21:46:40 2012 From: barry at python.org (Barry Warsaw) Date: Sat, 22 Dec 2012 15:46:40 -0500 Subject: [Python-checkins] Cron /home/docs/build-devguide In-Reply-To: <50D619DB.2080304@udel.edu> References: <50D619DB.2080304@udel.edu> Message-ID: <20121222154640.2d41b24e@limelight.wooz.org> On Dec 22, 2012, at 03:36 PM, Terry Reedy wrote: >I always reject the requests as I don't believe these messages belong here. I >even asked, some months ago, on pydev who was responsible for the robot that >sends these but got no answer. Today, apparently, another list admin decided >on the opposite response and gave root at python.org blanket permission to flood >this list with irrelavancy. It it not my responsibility and I have no idea >how to fix it. > >While people with push priviliges are supposed to subscribe to this list, I >know there is at least one who unsubscribed because of the volume. This will >only encourage more to leave, so I hope someone can stop it. Actually, I made docs at dinsdale.python.org an acceptable alias so these messages won't just fill up the hold queue of the list. It did get the problem fixed, didn't it? ;) I don't remember the previous conversation. If folks really don't want those messages hitting the checkins list, then errors should probably be sent to some address that can do something about the problem when they occur. Maybe that's not docs at dinsdale.python.org, or maybe that alias should point somewhere else (is that address ever used in the good path?). I have no idea where that address is used. As for the noise issue, well, I hope such failures shouldn't happen very often. We can set up an auto-discard, but then I worry that problems will just go unnoticed for days. -Barry From mal at egenix.com Sat Dec 22 22:17:32 2012 From: mal at egenix.com (M.-A. Lemburg) Date: Sat, 22 Dec 2012 22:17:32 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide In-Reply-To: <50D619DB.2080304@udel.edu> References: <50D619DB.2080304@udel.edu> Message-ID: <50D6236C.8040305@egenix.com> On 22.12.2012 21:36, Terry Reedy wrote: > > On 12/22/2012 1:30 PM, Cron Daemon wrote: >> abort: error: Connection timed out >> _______________________________________________ >> Python-checkins mailing list >> Python-checkins at python.org >> http://mail.python.org/mailman/listinfo/python-checkins > > As a volunteer checkin-list admin, I occasionally get messages like this: > ''' > As list administrator, your authorization is requested for the > following mailing list posting: > > List: Python-checkins at python.org > From: root at python.org > Subject: Cron /home/docs/build-devguide > Reason: Message has implicit destination > > At your convenience, visit: > > http://mail.python.org/mailman/admindb/python-checkins > > to approve or deny the request. > ''' > > I always reject the requests as I don't believe these messages belong here. I even asked, some > months ago, on pydev who was responsible for the robot that sends these but got no answer. Today, > apparently, another list admin decided on the opposite response and gave root at python.org blanket > permission to flood this list with irrelavancy. It it not my responsibility and I have no idea how > to fix it. You can add a sender filter to have the messages automatically discarded. > While people with push priviliges are supposed to subscribe to this list, I know there is at least > one who unsubscribed because of the volume. This will only encourage more to leave, so I hope > someone can stop it. I think such messages should go to a sys admin list. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Dec 22 2012) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-12-14: Released mxODBC.Connect 2.0.2 ... http://egenix.com/go38 2013-01-22: Python Meeting Duesseldorf ... 31 days to go ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From python-checkins at python.org Sat Dec 22 23:09:38 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 22 Dec 2012 23:09:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NzQ1?= =?utf-8?q?=3A_The_gcc_visibility_pragma_is_buggy_on_OpenIndiana_and_NetBS?= =?utf-8?q?D=2E?= Message-ID: <3YTLTt2S8vzNpw@mail.python.org> http://hg.python.org/cpython/rev/ccc372b37fbb changeset: 80982:ccc372b37fbb branch: 3.3 parent: 80980:93902bd37f48 user: Stefan Krah date: Sat Dec 22 23:05:51 2012 +0100 summary: Issue #16745: The gcc visibility pragma is buggy on OpenIndiana and NetBSD. files: Modules/_decimal/libmpdec/mpdecimal.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -70,7 +70,8 @@ #else #define UNUSED #endif - #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) + #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \ + defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) #define MPD_PRAGMA(x) _Pragma(x) #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 22 23:09:39 2012 From: python-checkins at python.org (stefan.krah) Date: Sat, 22 Dec 2012 23:09:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4zLg==?= Message-ID: <3YTLTv59GzzQtc@mail.python.org> http://hg.python.org/cpython/rev/3a841240bc10 changeset: 80983:3a841240bc10 parent: 80981:568019d6bf6b parent: 80982:ccc372b37fbb user: Stefan Krah date: Sat Dec 22 23:08:42 2012 +0100 summary: Merge 3.3. files: Modules/_decimal/libmpdec/mpdecimal.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -70,7 +70,8 @@ #else #define UNUSED #endif - #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) + #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \ + defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER) #define MPD_PRAGMA(x) _Pragma(x) #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)" #define MPD_HIDE_SYMBOLS_END "GCC visibility pop" -- Repository URL: http://hg.python.org/cpython From tjreedy at udel.edu Sun Dec 23 00:09:19 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Dec 2012 18:09:19 -0500 Subject: [Python-checkins] Cron /home/docs/build-devguide In-Reply-To: <50D6236C.8040305@egenix.com> References: <50D619DB.2080304@udel.edu> <50D6236C.8040305@egenix.com> Message-ID: On 12/22/2012 4:17 PM, M.-A. Lemburg wrote: > > > On 22.12.2012 21:36, Terry Reedy wrote: >> >> On 12/22/2012 1:30 PM, Cron Daemon wrote: >>> abort: error: Connection timed out ... >> I always reject the requests as I don't believe these messages belong here. I even asked, some >> months ago, on pydev who was responsible for the robot that sends these but got no answer. Today, >> apparently, another list admin decided on the opposite response and gave root at python.org blanket >> permission to flood this list with irrelavancy. It it not my responsibility and I have no idea how >> to fix it. > > You can add a sender filter to have the messages automatically discarded. I don't believe that *I* can. > >> While people with push priviliges are supposed to subscribe to this list, I know there is at least >> one who unsubscribed because of the volume. This will only encourage more to leave, so I hope >> someone can stop it. > > I think such messages should go to a sys admin list. Sending such messages to everyone with push privileges is worse than useless. Thus far, no one has admitted responsibility for the sending source. -- Terry Jan Reedy From tjreedy at udel.edu Sun Dec 23 00:13:44 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 22 Dec 2012 18:13:44 -0500 Subject: [Python-checkins] Cron /home/docs/build-devguide In-Reply-To: <20121222154640.2d41b24e@limelight.wooz.org> References: <50D619DB.2080304@udel.edu> <20121222154640.2d41b24e@limelight.wooz.org> Message-ID: On 12/22/2012 3:46 PM, Barry Warsaw wrote: > On Dec 22, 2012, at 03:36 PM, Terry Reedy wrote: > Actually, I made docs at dinsdale.python.org an acceptable alias so these > messages won't just fill up the hold queue of the list. It did get the > problem fixed, didn't it? ;) It solved the admin problem for we two, but over 100(?) people, including me, got a slew of bogus checkin messages. > I don't remember the previous conversation. If folks really don't want those > messages hitting the checkins list, then errors should probably be sent to > some address that can do something about the problem when they occur. Maybe > that's not docs at dinsdale.python.org, or maybe that alias should point > somewhere else (is that address ever used in the good path?). I have no idea > where that address is used. > > As for the noise issue, well, I hope such failures shouldn't happen very > often. We can set up an auto-discard, but then I worry that problems will > just go unnoticed for days. They should be sent to the small group of people who can usefully respond to them. -- Terry Jan Reedy From python-checkins at python.org Sun Dec 23 01:38:42 2012 From: python-checkins at python.org (brett.cannon) Date: Sun, 23 Dec 2012 01:38:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NzUy?= =?utf-8?q?=3A_Add_a_missing_import_to_modulefinder=2E?= Message-ID: <3YTPnt4HNDzQVx@mail.python.org> http://hg.python.org/cpython/rev/1b9b7cb136db changeset: 80984:1b9b7cb136db branch: 3.3 parent: 80982:ccc372b37fbb user: Brett Cannon date: Sat Dec 22 19:34:21 2012 -0500 summary: Issue #16752: Add a missing import to modulefinder. Also fix Misc/ACKS to put part of it back in alphabetical order and remove some duplicate names. Patch by Berker Peksag. files: Lib/modulefinder.py | 1 + Lib/test/test_modulefinder.py | 15 +++++++++++++++ Misc/ACKS | 4 +--- Misc/NEWS | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py --- a/Lib/modulefinder.py +++ b/Lib/modulefinder.py @@ -2,6 +2,7 @@ import dis import imp +import importlib.machinery import marshal import os import sys diff --git a/Lib/test/test_modulefinder.py b/Lib/test/test_modulefinder.py --- a/Lib/test/test_modulefinder.py +++ b/Lib/test/test_modulefinder.py @@ -196,6 +196,18 @@ from . import bar """] +relative_import_test_4 = [ + "a.module", + ["a", "a.module"], + [], + [], + """\ +a/__init__.py + def foo(): pass +a/module.py + from . import * +"""] + def open_file(path): dirname = os.path.dirname(path) @@ -273,6 +285,9 @@ def test_relative_imports_3(self): self._do_test(relative_import_test_3) + def test_relative_imports_4(self): + self._do_test(relative_import_test_4) + def test_main(): support.run_unittest(ModuleFinderTest) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -894,15 +894,13 @@ William Park Harri Pasanen Ga?l Pasgrimaud -Berker Peksag -Bo Peng -Joe Peterson Randy Pausch Samuele Pedroni Justin Peel Marcel van der Peijl Berker Peksag Steven Pemberton +Bo Peng Santiago Peres?n George Peristerakis Mathieu Perreault diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -114,6 +114,8 @@ Library ------- +- Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag. + - Issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 01:38:43 2012 From: python-checkins at python.org (brett.cannon) Date: Sun, 23 Dec 2012 01:38:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E3?= Message-ID: <3YTPnv6gNXzQXp@mail.python.org> http://hg.python.org/cpython/rev/d22e9e3a3326 changeset: 80985:d22e9e3a3326 parent: 80983:3a841240bc10 parent: 80984:1b9b7cb136db user: Brett Cannon date: Sat Dec 22 19:38:32 2012 -0500 summary: merge with 3.3 files: Lib/modulefinder.py | 1 + Lib/test/test_modulefinder.py | 15 +++++++++++++++ Misc/ACKS | 4 +--- Misc/NEWS | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Lib/modulefinder.py b/Lib/modulefinder.py --- a/Lib/modulefinder.py +++ b/Lib/modulefinder.py @@ -2,6 +2,7 @@ import dis import imp +import importlib.machinery import marshal import os import sys diff --git a/Lib/test/test_modulefinder.py b/Lib/test/test_modulefinder.py --- a/Lib/test/test_modulefinder.py +++ b/Lib/test/test_modulefinder.py @@ -196,6 +196,18 @@ from . import bar """] +relative_import_test_4 = [ + "a.module", + ["a", "a.module"], + [], + [], + """\ +a/__init__.py + def foo(): pass +a/module.py + from . import * +"""] + def open_file(path): dirname = os.path.dirname(path) @@ -273,6 +285,9 @@ def test_relative_imports_3(self): self._do_test(relative_import_test_3) + def test_relative_imports_4(self): + self._do_test(relative_import_test_4) + def test_main(): support.run_unittest(ModuleFinderTest) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -901,15 +901,13 @@ Harri Pasanen Ga?l Pasgrimaud Ashish Nitin Patil -Berker Peksag -Bo Peng -Joe Peterson Randy Pausch Samuele Pedroni Justin Peel Marcel van der Peijl Berker Peksag Steven Pemberton +Bo Peng Santiago Peres?n George Peristerakis Mathieu Perreault diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -173,6 +173,8 @@ Library ------- +- Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag. + - Issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sun Dec 23 05:52:53 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 23 Dec 2012 05:52:53 +0100 Subject: [Python-checkins] Daily reference leaks (d22e9e3a3326): sum=0 Message-ID: results for d22e9e3a3326 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog40Gz3x', '-x'] From python-checkins at python.org Sun Dec 23 11:52:11 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 11:52:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2MDQ1?= =?utf-8?q?=3A_add_more_unit_tests_for_built-in_int=28=29?= Message-ID: <3YTgPl2BxHzR0T@mail.python.org> http://hg.python.org/cpython/rev/c502a2dc0345 changeset: 80986:c502a2dc0345 branch: 2.7 parent: 80977:231e4889b117 user: Andrew Svetlov date: Sun Dec 23 12:44:04 2012 +0200 summary: Issue #16045: add more unit tests for built-in int() Patch by Chris Jerdonek. files: Lib/test/test_builtin.py | 2 + Lib/test/test_int.py | 54 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -680,6 +680,8 @@ # Test input() later, together with raw_input + # test_int(): see test_int.py for int() tests. + def test_intern(self): self.assertRaises(TypeError, intern) # This fails if the test is run twice with a constant string, diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -1,6 +1,7 @@ import sys import unittest +from test import test_support from test.test_support import run_unittest, have_unicode import math @@ -315,6 +316,59 @@ self.assertEqual(int(float(2**54+10)), 2**54+8) self.assertEqual(int(float(2**54+11)), 2**54+12) + def test_no_args(self): + self.assertEquals(int(), 0) + + def test_keyword_args(self): + # Test invoking int() using keyword arguments. + self.assertEquals(int(x=1.2), 1) + self.assertEquals(int('100', base=2), 4) + self.assertEquals(int(x='100', base=2), 4) + + def test_valid_non_numeric_input_types_for_x(self): + # Test possible valid non-numeric types for x, including subclasses + # of the allowed built-in types. + class CustomStr(str): pass + values = ['100', CustomStr('100')] + + if have_unicode: + class CustomUnicode(unicode): pass + values += [unicode('100'), CustomUnicode(unicode('100'))] + + for x in values: + msg = 'x has value %s and type %s' % (x, type(x).__name__) + try: + self.assertEquals(int(x), 100, msg=msg) + self.assertEquals(int(x, 2), 4, msg=msg) + except TypeError, err: + raise AssertionError('For %s got TypeError: %s' % + (type(x).__name__, err)) + + def test_error_on_string_float_for_x(self): + self.assertRaises(ValueError, int, '1.2') + + def test_error_on_bytearray_for_x(self): + self.assertRaises(TypeError, int, bytearray('100'), 2) + + def test_error_on_invalid_int_bases(self): + for base in [-1, 1, 1000]: + self.assertRaises(ValueError, int, '100', base) + + def test_error_on_string_base(self): + self.assertRaises(TypeError, int, 100, base='foo') + # Include the following because in contrast CPython raises no error + # for bad integer bases when x is not given. + self.assertRaises(TypeError, int, base='foo') + + # For example, PyPy 1.9.0 raised TypeError for these cases because it + # expects x to be a string if base is given. + @test_support.cpython_only + def test_int_base_without_x_returns_0(self): + self.assertEquals(int(base=6), 0) + # Even invalid bases don't raise an exception. + self.assertEquals(int(base=1), 0) + self.assertEquals(int(base=1000), 0) + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 11:52:12 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 11:52:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2MDQ1?= =?utf-8?q?=3A_add_more_unit_tests_for_built-in_int=28=29?= Message-ID: <3YTgPm4v0RzRXN@mail.python.org> http://hg.python.org/cpython/rev/a90d7003966e changeset: 80987:a90d7003966e branch: 3.3 parent: 80950:55d86476d048 user: Andrew Svetlov date: Sun Dec 23 12:49:33 2012 +0200 summary: Issue #16045: add more unit tests for built-in int() Patch by Chris Jerdonek. files: Lib/test/test_builtin.py | 2 + Lib/test/test_int.py | 44 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1172,6 +1172,8 @@ # Check stdin/stdout error handler is used when invoking GNU readline self.check_input_tty("prompt?", b"quux\xe9", "ascii") + # test_int(): see test_int.py for tests of built-in function int(). + def test_repr(self): self.assertEqual(repr(''), '\'\'') self.assertEqual(repr(0), '0') diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -1,7 +1,7 @@ import sys import unittest -from test.support import run_unittest +from test import support L = [ ('0', 0), @@ -221,6 +221,46 @@ self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) + def test_no_args(self): + self.assertEquals(int(), 0) + + def test_keyword_args(self): + # Test invoking int() using keyword arguments. + self.assertEquals(int(x=1.2), 1) + self.assertEquals(int('100', base=2), 4) + self.assertEquals(int(x='100', base=2), 4) + + # For example, PyPy 1.9.0 raised TypeError for these cases because it + # expects x to be a string if base is given. + @support.cpython_only + def test_base_arg_with_no_x_arg(self): + self.assertEquals(int(base=6), 0) + # Even invalid bases don't raise an exception. + self.assertEquals(int(base=1), 0) + self.assertEquals(int(base=1000), 0) + self.assertEquals(int(base='foo'), 0) + + def test_non_numeric_input_types(self): + # Test possible non-numeric types for the argument x, including + # subclasses of the explicitly documented accepted types. + class CustomStr(str): pass + class CustomBytes(bytes): pass + class CustomByteArray(bytearray): pass + + values = [b'100', + bytearray(b'100'), + CustomStr('100'), + CustomBytes(b'100'), + CustomByteArray(b'100')] + + for x in values: + msg = 'x has type %s' % type(x).__name__ + self.assertEquals(int(x), 100, msg=msg) + self.assertEquals(int(x, 2), 4, msg=msg) + + def test_string_float(self): + self.assertRaises(ValueError, int, '1.2') + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: @@ -328,7 +368,7 @@ self.fail("Expected int(%r) to raise a ValueError", s) def test_main(): - run_unittest(IntTestCases) + support.run_unittest(IntTestCases) if __name__ == "__main__": test_main() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 11:52:14 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 11:52:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316045=3A_add_more_unit_tests_for_built-in_int?= =?utf-8?b?KCk=?= Message-ID: <3YTgPp07LgzRZX@mail.python.org> http://hg.python.org/cpython/rev/ec7146b18274 changeset: 80988:ec7146b18274 parent: 80985:d22e9e3a3326 parent: 80987:a90d7003966e user: Andrew Svetlov date: Sun Dec 23 12:50:02 2012 +0200 summary: Issue #16045: add more unit tests for built-in int() Patch by Chris Jerdonek. files: Lib/test/test_builtin.py | 2 + Lib/test/test_int.py | 44 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1177,6 +1177,8 @@ # Check stdin/stdout error handler is used when invoking GNU readline self.check_input_tty("prompt?", b"quux\xe9", "ascii") + # test_int(): see test_int.py for tests of built-in function int(). + def test_repr(self): self.assertEqual(repr(''), '\'\'') self.assertEqual(repr(0), '0') diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -1,7 +1,7 @@ import sys import unittest -from test.support import run_unittest +from test import support L = [ ('0', 0), @@ -221,6 +221,46 @@ self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) + def test_no_args(self): + self.assertEquals(int(), 0) + + def test_keyword_args(self): + # Test invoking int() using keyword arguments. + self.assertEquals(int(x=1.2), 1) + self.assertEquals(int('100', base=2), 4) + self.assertEquals(int(x='100', base=2), 4) + + # For example, PyPy 1.9.0 raised TypeError for these cases because it + # expects x to be a string if base is given. + @support.cpython_only + def test_base_arg_with_no_x_arg(self): + self.assertEquals(int(base=6), 0) + # Even invalid bases don't raise an exception. + self.assertEquals(int(base=1), 0) + self.assertEquals(int(base=1000), 0) + self.assertEquals(int(base='foo'), 0) + + def test_non_numeric_input_types(self): + # Test possible non-numeric types for the argument x, including + # subclasses of the explicitly documented accepted types. + class CustomStr(str): pass + class CustomBytes(bytes): pass + class CustomByteArray(bytearray): pass + + values = [b'100', + bytearray(b'100'), + CustomStr('100'), + CustomBytes(b'100'), + CustomByteArray(b'100')] + + for x in values: + msg = 'x has type %s' % type(x).__name__ + self.assertEquals(int(x), 100, msg=msg) + self.assertEquals(int(x, 2), 4, msg=msg) + + def test_string_float(self): + self.assertRaises(ValueError, int, '1.2') + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: @@ -328,7 +368,7 @@ self.fail("Expected int(%r) to raise a ValueError", s) def test_main(): - run_unittest(IntTestCases) + support.run_unittest(IntTestCases) if __name__ == "__main__": test_main() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 11:52:15 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 11:52:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4zIC0+IDMuMyk6?= =?utf-8?q?_merge_heads?= Message-ID: <3YTgPq2SJ7zRb0@mail.python.org> http://hg.python.org/cpython/rev/e684b253fd9d changeset: 80989:e684b253fd9d branch: 3.3 parent: 80984:1b9b7cb136db parent: 80987:a90d7003966e user: Andrew Svetlov date: Sun Dec 23 12:51:40 2012 +0200 summary: merge heads files: Lib/test/test_builtin.py | 2 + Lib/test/test_int.py | 44 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1172,6 +1172,8 @@ # Check stdin/stdout error handler is used when invoking GNU readline self.check_input_tty("prompt?", b"quux\xe9", "ascii") + # test_int(): see test_int.py for tests of built-in function int(). + def test_repr(self): self.assertEqual(repr(''), '\'\'') self.assertEqual(repr(0), '0') diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -1,7 +1,7 @@ import sys import unittest -from test.support import run_unittest +from test import support L = [ ('0', 0), @@ -221,6 +221,46 @@ self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) + def test_no_args(self): + self.assertEquals(int(), 0) + + def test_keyword_args(self): + # Test invoking int() using keyword arguments. + self.assertEquals(int(x=1.2), 1) + self.assertEquals(int('100', base=2), 4) + self.assertEquals(int(x='100', base=2), 4) + + # For example, PyPy 1.9.0 raised TypeError for these cases because it + # expects x to be a string if base is given. + @support.cpython_only + def test_base_arg_with_no_x_arg(self): + self.assertEquals(int(base=6), 0) + # Even invalid bases don't raise an exception. + self.assertEquals(int(base=1), 0) + self.assertEquals(int(base=1000), 0) + self.assertEquals(int(base='foo'), 0) + + def test_non_numeric_input_types(self): + # Test possible non-numeric types for the argument x, including + # subclasses of the explicitly documented accepted types. + class CustomStr(str): pass + class CustomBytes(bytes): pass + class CustomByteArray(bytearray): pass + + values = [b'100', + bytearray(b'100'), + CustomStr('100'), + CustomBytes(b'100'), + CustomByteArray(b'100')] + + for x in values: + msg = 'x has type %s' % type(x).__name__ + self.assertEquals(int(x), 100, msg=msg) + self.assertEquals(int(x, 2), 4, msg=msg) + + def test_string_float(self): + self.assertRaises(ValueError, int, '1.2') + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: @@ -328,7 +368,7 @@ self.fail("Expected int(%r) to raise a ValueError", s) def test_main(): - run_unittest(IntTestCases) + support.run_unittest(IntTestCases) if __name__ == "__main__": test_main() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 11:52:16 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 11:52:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_null_merge?= Message-ID: <3YTgPr4Z01zRb0@mail.python.org> http://hg.python.org/cpython/rev/94aaf95219e3 changeset: 80990:94aaf95219e3 parent: 80988:ec7146b18274 parent: 80989:e684b253fd9d user: Andrew Svetlov date: Sun Dec 23 12:51:59 2012 +0200 summary: null merge files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 13:27:28 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 13:27:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=239856=3A_Replace_d?= =?utf-8?q?eprecation_warinigs_to_raising_TypeError_in?= Message-ID: <3YTjWh1BrtzQwl@mail.python.org> http://hg.python.org/cpython/rev/d91c14788729 changeset: 80991:d91c14788729 user: Andrew Svetlov date: Sun Dec 23 14:27:17 2012 +0200 summary: Issue #9856: Replace deprecation warinigs to raising TypeError in object.__format__ Patch by Florent Xicluna. files: Lib/test/test_builtin.py | 14 ++++---------- Lib/test/test_unicode.py | 8 +++----- Objects/typeobject.c | 17 ++++------------- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1479,17 +1479,11 @@ # -------------------------------------------------------------------- # Issue #7994: object.__format__ with a non-empty format string is # deprecated - def test_deprecated_format_string(obj, fmt_str, should_raise_warning): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always", DeprecationWarning) + def test_deprecated_format_string(obj, fmt_str, should_raise): + if should_raise: + self.assertRaises(TypeError, format, obj, fmt_str) + else: format(obj, fmt_str) - if should_raise_warning: - self.assertEqual(len(w), 1) - self.assertIsInstance(w[0].message, DeprecationWarning) - self.assertIn('object.__format__ with a non-empty format ' - 'string', str(w[0].message)) - else: - self.assertEqual(len(w), 0) fmt_strs = ['', 's'] diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -842,11 +842,9 @@ self.assertEqual('{0:d}'.format(G('data')), 'G(data)') self.assertEqual('{0!s}'.format(G('data')), 'string is data') - msg = 'object.__format__ with a non-empty format string is deprecated' - with support.check_warnings((msg, DeprecationWarning)): - self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ') - self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ') - self.assertEqual('{0:>15s}'.format(G('data')), ' string is data') + self.assertRaises(TypeError, '{0:^10}'.format, E('data')) + self.assertRaises(TypeError, '{0:^10s}'.format, E('data')) + self.assertRaises(TypeError, '{0:>15s}'.format, G('data')) self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007, month=8, diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3654,16 +3654,9 @@ /* Issue 7994: If we're converting to a string, we should reject format specifications */ if (PyUnicode_GET_LENGTH(format_spec) > 0) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "object.__format__ with a non-empty format " - "string is deprecated", 1) < 0) { - goto done; - } - /* Eventually this will become an error: - PyErr_Format(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "non-empty format string passed to object.__format__"); - goto done; - */ + goto done; } result = PyObject_Format(self_as_str, format_spec); @@ -4288,13 +4281,11 @@ /* Warn for a type that implements tp_compare (now known as tp_reserved) but not tp_richcompare. */ if (type->tp_reserved && !type->tp_richcompare) { - int error; - error = PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + PyErr_Format(PyExc_TypeError, "Type %.100s defines tp_reserved (formerly tp_compare) " "but not tp_richcompare. Comparisons may not behave as intended.", type->tp_name); - if (error == -1) - goto error; + goto error; } /* All done -- set the ready flag */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 14:12:31 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 14:12:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_NEWS_and_docs_for_=239?= =?utf-8?q?856?= Message-ID: <3YTkWg6dM5zRXN@mail.python.org> http://hg.python.org/cpython/rev/2f6ec67636b8 changeset: 80992:2f6ec67636b8 user: Andrew Svetlov date: Sun Dec 23 15:12:19 2012 +0200 summary: Add NEWS and docs for #9856 files: Doc/library/functions.rst | 4 ++++ Misc/NEWS | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -543,6 +543,10 @@ :exc:`TypeError` exception is raised if the method is not found or if either the *format_spec* or the return value are not strings. + .. versionadded:: 3.4 + ``object().__format__(format_spec)`` raises :exc:`TypeError` + if *format_spec* is not empty string. + .. _func-frozenset: .. function:: frozenset([iterable]) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #9856: Replace deprecation warinigs with raising TypeError + in object.__format__. Patch by Florent Xicluna. + - Issue #16597: In buffered and text IO, call close() on the underlying stream if invoking flush() fails. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 15:46:48 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 23 Dec 2012 15:46:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NzUz?= =?utf-8?q?=3A_Define_=5F=5FGNUC=5FSTDC=5FINLINE=5F=5F_to_an_integer_=28sa?= =?utf-8?q?me_as_gcc=29=2E?= Message-ID: <3YTmcS1z4xzRXK@mail.python.org> http://hg.python.org/cpython/rev/f05d29353f02 changeset: 80993:f05d29353f02 branch: 3.3 parent: 80989:e684b253fd9d user: Stefan Krah date: Sun Dec 23 15:42:21 2012 +0100 summary: Issue #16753: Define __GNUC_STDC_INLINE__ to an integer (same as gcc). files: Modules/_decimal/libmpdec/mpdecimal.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -63,7 +63,7 @@ #include #endif #ifndef __GNUC_STDC_INLINE__ - #define __GNUC_STDC_INLINE__ + #define __GNUC_STDC_INLINE__ 1 #endif #if defined(__GNUC__) && !defined(__INTEL_COMPILER) #define UNUSED __attribute__((unused)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 15:46:49 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 23 Dec 2012 15:46:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4zLg==?= Message-ID: <3YTmcT4dSwzRb0@mail.python.org> http://hg.python.org/cpython/rev/9377a5e97c41 changeset: 80994:9377a5e97c41 parent: 80992:2f6ec67636b8 parent: 80993:f05d29353f02 user: Stefan Krah date: Sun Dec 23 15:46:03 2012 +0100 summary: Merge 3.3. files: Modules/_decimal/libmpdec/mpdecimal.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_decimal/libmpdec/mpdecimal.h b/Modules/_decimal/libmpdec/mpdecimal.h --- a/Modules/_decimal/libmpdec/mpdecimal.h +++ b/Modules/_decimal/libmpdec/mpdecimal.h @@ -63,7 +63,7 @@ #include #endif #ifndef __GNUC_STDC_INLINE__ - #define __GNUC_STDC_INLINE__ + #define __GNUC_STDC_INLINE__ 1 #endif #if defined(__GNUC__) && !defined(__INTEL_COMPILER) #define UNUSED __attribute__((unused)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 17:15:37 2012 From: python-checkins at python.org (eric.smith) Date: Sun, 23 Dec 2012 17:15:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_a_typo=2E?= Message-ID: <3YTpZx28fdzNpw@mail.python.org> http://hg.python.org/cpython/rev/bf64c3a38556 changeset: 80995:bf64c3a38556 user: Eric V. Smith date: Sun Dec 23 11:15:19 2012 -0500 summary: Fix a typo. files: Misc/NEWS | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,7 +10,7 @@ Core and Builtins ----------------- -- Issue #9856: Replace deprecation warinigs with raising TypeError +- Issue #9856: Replace deprecation warning with raising TypeError in object.__format__. Patch by Florent Xicluna. - Issue #16597: In buffered and text IO, call close() on the underlying stream -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 18:13:58 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 23 Dec 2012 18:13:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_Issue15701?= =?utf-8?q?_-_HTTPError_info_method_call_raises_AttributeError=2E_Fix_that?= =?utf-8?q?_to?= Message-ID: <3YTqtG1gsnzQn6@mail.python.org> http://hg.python.org/cpython/rev/3046bfea59f3 changeset: 80996:3046bfea59f3 branch: 2.7 parent: 80986:c502a2dc0345 user: Senthil Kumaran date: Sun Dec 23 09:00:47 2012 -0800 summary: Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly files: Lib/test/test_urllib2.py | 34 ++++++++++++++++++++------- Lib/urllib2.py | 3 ++ Misc/NEWS | 2 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1336,16 +1336,32 @@ req = Request(url) self.assertEqual(req.get_full_url(), url) -def test_HTTPError_interface(): - """ - Issue 13211 reveals that HTTPError didn't implement the URLError - interface even though HTTPError is a subclass of URLError. + def test_HTTPError_interface(self): + """ + Issue 13211 reveals that HTTPError didn't implement the URLError + interface even though HTTPError is a subclass of URLError. - >>> err = urllib2.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None) - >>> assert hasattr(err, 'reason') - >>> err.reason - 'something bad happened' - """ + >>> err = urllib2.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None) + >>> assert hasattr(err, 'reason') + >>> err.reason + 'something bad happened' + """ + + def test_HTTPError_interface_call(self): + """ + Issue 15701= - HTTPError interface has info method available from URLError. + """ + err = urllib2.HTTPError(msg='something bad happened', url=None, + code=None, hdrs='Content-Length:42', fp=None) + self.assertTrue(hasattr(err, 'reason')) + assert hasattr(err, 'reason') + assert hasattr(err, 'info') + assert callable(err.info) + try: + err.info() + except AttributeError: + self.fail("err.info() failed") + self.assertEqual(err.info(), "Content-Length:42") def test_main(verbose=None): from test import test_urllib2 diff --git a/Lib/urllib2.py b/Lib/urllib2.py --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -173,6 +173,9 @@ def reason(self): return self.msg + def info(self): + return self.hdrs + # copied from cookielib.py _cut_port_re = re.compile(r":\d+$") def request_host(request): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -165,6 +165,8 @@ - Issue #16597: In buffered and text IO, call close() on the underlying stream if invoking flush() fails. +- Issue #15701: Fix HTTPError info method call to return the headers information. + - Issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 18:13:59 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 23 Dec 2012 18:13:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_Issue15701?= =?utf-8?q?_-_HTTPError_info_method_call_raises_AttributeError=2E_Fix_that?= =?utf-8?q?_to?= Message-ID: <3YTqtH49TpzR0T@mail.python.org> http://hg.python.org/cpython/rev/919ebf74bfdb changeset: 80997:919ebf74bfdb branch: 3.2 parent: 80968:0935394069cc user: Senthil Kumaran date: Sun Dec 23 09:04:24 2012 -0800 summary: Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly files: Lib/test/test_urllib2.py | 34 ++++++++++++++++++++------- Lib/urllib/error.py | 4 +++ Misc/NEWS | 2 + 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1438,16 +1438,32 @@ req = Request(url) self.assertEqual(req.get_full_url(), url) -def test_HTTPError_interface(): - """ - Issue 13211 reveals that HTTPError didn't implement the URLError - interface even though HTTPError is a subclass of URLError. + def test_HTTPError_interface(self): + """ + Issue 13211 reveals that HTTPError didn't implement the URLError + interface even though HTTPError is a subclass of URLError. - >>> err = urllib.error.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None) - >>> assert hasattr(err, 'reason') - >>> err.reason - 'something bad happened' - """ + >>> err = urllib.error.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None) + >>> assert hasattr(err, 'reason') + >>> err.reason + 'something bad happened' + """ + + def test_HTTPError_interface_call(self): + """ + Issue 15701 - HTTPError interface has info method available from URLError + """ + err = urllib.request.HTTPError(msg="something bad happened", url=None, + code=None, hdrs='Content-Length:42', fp=None) + self.assertTrue(hasattr(err, 'reason')) + assert hasattr(err, 'reason') + assert hasattr(err, 'info') + assert callable(err.info) + try: + err.info() + except AttributeError: + self.fail('err.info call failed.') + self.assertEqual(err.info(), "Content-Length:42") def test_main(verbose=None): from test import test_urllib2 diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -58,6 +58,10 @@ def reason(self): return self.msg + def info(self): + return self.hdrs + + # exception raised when downloaded size does not match content-length class ContentTooShortError(URLError): def __init__(self, message, content): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,8 @@ Library ------- +- Issue #15701: Fix HTTPError info method call to return the headers information. + - Issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 18:14:00 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 23 Dec 2012 18:14:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_merge_from_3=2E2?= Message-ID: <3YTqtJ6skwzQxN@mail.python.org> http://hg.python.org/cpython/rev/a15109398294 changeset: 80998:a15109398294 branch: 3.3 parent: 80993:f05d29353f02 parent: 80997:919ebf74bfdb user: Senthil Kumaran date: Sun Dec 23 09:12:13 2012 -0800 summary: merge from 3.2 Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly files: Lib/test/test_urllib2.py | 38 +++++++++++++++++++-------- Lib/urllib/error.py | 4 ++ Misc/NEWS | 2 + 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1495,18 +1495,34 @@ req = Request(url) self.assertEqual(req.get_full_url(), url) -def test_HTTPError_interface(): - """ - Issue 13211 reveals that HTTPError didn't implement the URLError - interface even though HTTPError is a subclass of URLError. + def test_HTTPError_interface(self): + """ + Issue 13211 reveals that HTTPError didn't implement the URLError + interface even though HTTPError is a subclass of URLError. - >>> msg = 'something bad happened' - >>> url = code = hdrs = fp = None - >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) - >>> assert hasattr(err, 'reason') - >>> err.reason - 'something bad happened' - """ + >>> msg = 'something bad happened' + >>> url = code = hdrs = fp = None + >>> err = urllib.error.HTTPError(url, code, msg, hdrs, fp) + >>> assert hasattr(err, 'reason') + >>> err.reason + 'something bad happened' + """ + + def test_HTTPError_interface_call(self): + """ + Issue 15701 - HTTPError interface has info method available from URLError + """ + err = urllib.request.HTTPError(msg="something bad happened", url=None, + code=None, hdrs='Content-Length:42', fp=None) + self.assertTrue(hasattr(err, 'reason')) + assert hasattr(err, 'reason') + assert hasattr(err, 'info') + assert callable(err.info) + try: + err.info() + except AttributeError: + self.fail('err.info call failed.') + self.assertEqual(err.info(), "Content-Length:42") def test_main(verbose=None): from test import test_urllib2 diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -61,6 +61,10 @@ def reason(self): return self.msg + def info(self): + return self.hdrs + + # exception raised when downloaded size does not match content-length class ContentTooShortError(URLError): def __init__(self, message, content): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -114,6 +114,8 @@ Library ------- +- Issue #15701: Fix HTTPError info method call to return the headers information. + - Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag. - Issue #16646: ftplib.FTP.makeport() might lose socket error details. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 18:14:02 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 23 Dec 2012 18:14:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_null_merge=2E?= Message-ID: <3YTqtL2FdfzRb3@mail.python.org> http://hg.python.org/cpython/rev/3c830691f598 changeset: 80999:3c830691f598 parent: 80995:bf64c3a38556 parent: 80998:a15109398294 user: Senthil Kumaran date: Sun Dec 23 09:13:33 2012 -0800 summary: null merge. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 19:01:12 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 19:01:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NDQz?= =?utf-8?q?=3A_Add_docstrings_to_regular_expression_match_objects=2E?= Message-ID: <3YTrwm0gyKzRTL@mail.python.org> http://hg.python.org/cpython/rev/e4f1b3565509 changeset: 81000:e4f1b3565509 branch: 3.2 parent: 80968:0935394069cc user: Andrew Svetlov date: Sun Dec 23 19:23:07 2012 +0200 summary: Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. files: Misc/ACKS | 1 + Misc/NEWS | 3 + Modules/_sre.c | 70 +++++++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -543,6 +543,7 @@ Rafe Kaplan Jacob Kaplan-Moss Jan Kaliszewski +Anton Kasyanov Lou Kates Hiroaki Kawai Sebastien Keim diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,9 @@ Library ------- +- Issue #16443: Add docstrings to regular expression match objects. + Patch by Anton Kasyanov. + - Issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2559,35 +2559,35 @@ } PyDoc_STRVAR(pattern_match_doc, -"match(string[, pos[, endpos]]) --> match object or None.\n\ +"match(string[, pos[, endpos]]) -> match object or None.\n\n\ Matches zero or more characters at the beginning of the string"); PyDoc_STRVAR(pattern_search_doc, -"search(string[, pos[, endpos]]) --> match object or None.\n\ +"search(string[, pos[, endpos]]) -> match object or None.\n\n\ Scan through string looking for a match, and return a corresponding\n\ MatchObject instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, -"split(string[, maxsplit = 0]) --> list.\n\ +"split(string[, maxsplit = 0]) -> list.\n\n\ Split string by the occurrences of pattern."); PyDoc_STRVAR(pattern_findall_doc, -"findall(string[, pos[, endpos]]) --> list.\n\ +"findall(string[, pos[, endpos]]) -> list.\n\n\ Return a list of all non-overlapping matches of pattern in string."); PyDoc_STRVAR(pattern_finditer_doc, -"finditer(string[, pos[, endpos]]) --> iterator.\n\ +"finditer(string[, pos[, endpos]]) -> iterator.\n\n\ Return an iterator over all non-overlapping matches for the \n\ RE pattern in string. For each match, the iterator returns a\n\ match object."); PyDoc_STRVAR(pattern_sub_doc, -"sub(repl, string[, count = 0]) --> newstring\n\ +"sub(repl, string[, count = 0]) -> newstring.\n\n\ Return the string obtained by replacing the leftmost non-overlapping\n\ occurrences of pattern in string by the replacement repl."); PyDoc_STRVAR(pattern_subn_doc, -"subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\ +"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\n\ Return the tuple (new_string, number_of_subs_made) found by replacing\n\ the leftmost non-overlapping occurrences of pattern with the\n\ replacement repl."); @@ -3579,14 +3579,54 @@ #endif } +PyDoc_STRVAR(match_doc, +"The result of re.match() and re.search().\n\ +Match objects always have a boolean value of True."); + +PyDoc_STRVAR(match_group_doc, +"group([group1, ...]) -> str or tuple.\n\n\ + Return subgroup(s) of the match by indices or names.\n\ + For 0 returns the entire match."); + +PyDoc_STRVAR(match_start_doc, +"start([group=0]) -> int.\n\n\ + Return index of the start of the substring matched by group."); + +PyDoc_STRVAR(match_end_doc, +"end([group=0]) -> int.\n\n\ + Return index of the end of the substring matched by group."); + +PyDoc_STRVAR(match_span_doc, +"span([group]) -> tuple.\n\n\ + For MatchObject m, return the 2-tuple (m.start(group), m.end(group))."); + +PyDoc_STRVAR(match_groups_doc, +"groups([default=None]) -> tuple.\n\n\ + Return a tuple containing all the subgroups of the match, from 1.\n\ + The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_groupdict_doc, +"groupdict([default=None]) -> dict.\n\n\ + Return a dictionary containing all the named subgroups of the match,\n\ + keyed by the subgroup name. The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_expand_doc, +"expand(template) -> str.\n\n\ + Return the string obtained by doing backslash substitution\n\ + on the string template, as done by the sub() method."); + static PyMethodDef match_methods[] = { - {"group", (PyCFunction) match_group, METH_VARARGS}, - {"start", (PyCFunction) match_start, METH_VARARGS}, - {"end", (PyCFunction) match_end, METH_VARARGS}, - {"span", (PyCFunction) match_span, METH_VARARGS}, - {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS}, - {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS}, - {"expand", (PyCFunction) match_expand, METH_O}, + {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc}, + {"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc}, + {"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc}, + {"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc}, + {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS, + match_groups_doc}, + {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS, + match_groupdict_doc}, + {"expand", (PyCFunction) match_expand, METH_O, match_expand_doc}, {"__copy__", (PyCFunction) match_copy, METH_NOARGS}, {"__deepcopy__", (PyCFunction) match_deepcopy, METH_O}, {NULL, NULL} @@ -3665,7 +3705,7 @@ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ + match_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 19:01:13 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 19:01:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMik6?= =?utf-8?q?_merge_heads?= Message-ID: <3YTrwn4WK5zRfs@mail.python.org> http://hg.python.org/cpython/rev/937f70110f9e changeset: 81001:937f70110f9e branch: 3.2 parent: 80997:919ebf74bfdb parent: 81000:e4f1b3565509 user: Andrew Svetlov date: Sun Dec 23 19:55:21 2012 +0200 summary: merge heads files: Misc/ACKS | 1 + Misc/NEWS | 3 + Modules/_sre.c | 70 +++++++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -543,6 +543,7 @@ Rafe Kaplan Jacob Kaplan-Moss Jan Kaliszewski +Anton Kasyanov Lou Kates Hiroaki Kawai Sebastien Keim diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,9 @@ Library ------- +- Issue #16443: Add docstrings to regular expression match objects. + Patch by Anton Kasyanov. + - Issue #15701: Fix HTTPError info method call to return the headers information. - Issue #16646: ftplib.FTP.makeport() might lose socket error details. diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2559,35 +2559,35 @@ } PyDoc_STRVAR(pattern_match_doc, -"match(string[, pos[, endpos]]) --> match object or None.\n\ +"match(string[, pos[, endpos]]) -> match object or None.\n\n\ Matches zero or more characters at the beginning of the string"); PyDoc_STRVAR(pattern_search_doc, -"search(string[, pos[, endpos]]) --> match object or None.\n\ +"search(string[, pos[, endpos]]) -> match object or None.\n\n\ Scan through string looking for a match, and return a corresponding\n\ MatchObject instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, -"split(string[, maxsplit = 0]) --> list.\n\ +"split(string[, maxsplit = 0]) -> list.\n\n\ Split string by the occurrences of pattern."); PyDoc_STRVAR(pattern_findall_doc, -"findall(string[, pos[, endpos]]) --> list.\n\ +"findall(string[, pos[, endpos]]) -> list.\n\n\ Return a list of all non-overlapping matches of pattern in string."); PyDoc_STRVAR(pattern_finditer_doc, -"finditer(string[, pos[, endpos]]) --> iterator.\n\ +"finditer(string[, pos[, endpos]]) -> iterator.\n\n\ Return an iterator over all non-overlapping matches for the \n\ RE pattern in string. For each match, the iterator returns a\n\ match object."); PyDoc_STRVAR(pattern_sub_doc, -"sub(repl, string[, count = 0]) --> newstring\n\ +"sub(repl, string[, count = 0]) -> newstring.\n\n\ Return the string obtained by replacing the leftmost non-overlapping\n\ occurrences of pattern in string by the replacement repl."); PyDoc_STRVAR(pattern_subn_doc, -"subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\ +"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\n\ Return the tuple (new_string, number_of_subs_made) found by replacing\n\ the leftmost non-overlapping occurrences of pattern with the\n\ replacement repl."); @@ -3579,14 +3579,54 @@ #endif } +PyDoc_STRVAR(match_doc, +"The result of re.match() and re.search().\n\ +Match objects always have a boolean value of True."); + +PyDoc_STRVAR(match_group_doc, +"group([group1, ...]) -> str or tuple.\n\n\ + Return subgroup(s) of the match by indices or names.\n\ + For 0 returns the entire match."); + +PyDoc_STRVAR(match_start_doc, +"start([group=0]) -> int.\n\n\ + Return index of the start of the substring matched by group."); + +PyDoc_STRVAR(match_end_doc, +"end([group=0]) -> int.\n\n\ + Return index of the end of the substring matched by group."); + +PyDoc_STRVAR(match_span_doc, +"span([group]) -> tuple.\n\n\ + For MatchObject m, return the 2-tuple (m.start(group), m.end(group))."); + +PyDoc_STRVAR(match_groups_doc, +"groups([default=None]) -> tuple.\n\n\ + Return a tuple containing all the subgroups of the match, from 1.\n\ + The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_groupdict_doc, +"groupdict([default=None]) -> dict.\n\n\ + Return a dictionary containing all the named subgroups of the match,\n\ + keyed by the subgroup name. The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_expand_doc, +"expand(template) -> str.\n\n\ + Return the string obtained by doing backslash substitution\n\ + on the string template, as done by the sub() method."); + static PyMethodDef match_methods[] = { - {"group", (PyCFunction) match_group, METH_VARARGS}, - {"start", (PyCFunction) match_start, METH_VARARGS}, - {"end", (PyCFunction) match_end, METH_VARARGS}, - {"span", (PyCFunction) match_span, METH_VARARGS}, - {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS}, - {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS}, - {"expand", (PyCFunction) match_expand, METH_O}, + {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc}, + {"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc}, + {"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc}, + {"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc}, + {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS, + match_groups_doc}, + {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS, + match_groupdict_doc}, + {"expand", (PyCFunction) match_expand, METH_O, match_expand_doc}, {"__copy__", (PyCFunction) match_copy, METH_NOARGS}, {"__deepcopy__", (PyCFunction) match_deepcopy, METH_O}, {NULL, NULL} @@ -3665,7 +3705,7 @@ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ + match_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 19:01:15 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 19:01:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316443=3A_Add_docstrings_to_regular_expression_match_o?= =?utf-8?q?bjects=2E?= Message-ID: <3YTrwq108rzRgD@mail.python.org> http://hg.python.org/cpython/rev/64e050c2d010 changeset: 81002:64e050c2d010 branch: 3.3 parent: 80998:a15109398294 parent: 81001:937f70110f9e user: Andrew Svetlov date: Sun Dec 23 19:59:27 2012 +0200 summary: Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. files: Misc/ACKS | 2 + Misc/NEWS | 3 + Modules/_sre.c | 70 +++++++++++++++++++++++++++++-------- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -598,8 +598,10 @@ Peter van Kampen Rafe Kaplan Jacob Kaplan-Moss +Jan Kaliszewski Janne Karila Per ?yvind Karlsen +Anton Kasyanov Lou Kates Hiroaki Kawai Sebastien Keim diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -114,6 +114,9 @@ Library ------- +- Issue #16443: Add docstrings to regular expression match objects. + Patch by Anton Kasyanov. + - Issue #15701: Fix HTTPError info method call to return the headers information. - Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag. diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2527,35 +2527,35 @@ } PyDoc_STRVAR(pattern_match_doc, -"match(string[, pos[, endpos]]) --> match object or None.\n\ +"match(string[, pos[, endpos]]) -> match object or None.\n\ Matches zero or more characters at the beginning of the string"); PyDoc_STRVAR(pattern_search_doc, -"search(string[, pos[, endpos]]) --> match object or None.\n\ +"search(string[, pos[, endpos]]) -> match object or None.\n\ Scan through string looking for a match, and return a corresponding\n\ MatchObject instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, -"split(string[, maxsplit = 0]) --> list.\n\ +"split(string[, maxsplit = 0]) -> list.\n\ Split string by the occurrences of pattern."); PyDoc_STRVAR(pattern_findall_doc, -"findall(string[, pos[, endpos]]) --> list.\n\ +"findall(string[, pos[, endpos]]) -> list.\n\ Return a list of all non-overlapping matches of pattern in string."); PyDoc_STRVAR(pattern_finditer_doc, -"finditer(string[, pos[, endpos]]) --> iterator.\n\ +"finditer(string[, pos[, endpos]]) -> iterator.\n\ Return an iterator over all non-overlapping matches for the \n\ RE pattern in string. For each match, the iterator returns a\n\ match object."); PyDoc_STRVAR(pattern_sub_doc, -"sub(repl, string[, count = 0]) --> newstring\n\ +"sub(repl, string[, count = 0]) -> newstring.\n\ Return the string obtained by replacing the leftmost non-overlapping\n\ occurrences of pattern in string by the replacement repl."); PyDoc_STRVAR(pattern_subn_doc, -"subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\ +"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\ Return the tuple (new_string, number_of_subs_made) found by replacing\n\ the leftmost non-overlapping occurrences of pattern with the\n\ replacement repl."); @@ -3543,14 +3543,54 @@ #endif } +PyDoc_STRVAR(match_doc, +"The result of re.match() and re.search().\n\ +Match objects always have a boolean value of True."); + +PyDoc_STRVAR(match_group_doc, +"group([group1, ...]) -> str or tuple.\n\ + Return subgroup(s) of the match by indices or names.\n\ + For 0 returns the entire match."); + +PyDoc_STRVAR(match_start_doc, +"start([group=0]) -> int.\n\ + Return index of the start of the substring matched by group."); + +PyDoc_STRVAR(match_end_doc, +"end([group=0]) -> int.\n\ + Return index of the end of the substring matched by group."); + +PyDoc_STRVAR(match_span_doc, +"span([group]) -> tuple.\n\ + For MatchObject m, return the 2-tuple (m.start(group), m.end(group))."); + +PyDoc_STRVAR(match_groups_doc, +"groups([default=None]) -> tuple.\n\ + Return a tuple containing all the subgroups of the match, from 1.\n\ + The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_groupdict_doc, +"groupdict([default=None]) -> dict.\n\ + Return a dictionary containing all the named subgroups of the match,\n\ + keyed by the subgroup name. The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_expand_doc, +"expand(template) -> str.\n\ + Return the string obtained by doing backslash substitution\n\ + on the string template, as done by the sub() method."); + static PyMethodDef match_methods[] = { - {"group", (PyCFunction) match_group, METH_VARARGS}, - {"start", (PyCFunction) match_start, METH_VARARGS}, - {"end", (PyCFunction) match_end, METH_VARARGS}, - {"span", (PyCFunction) match_span, METH_VARARGS}, - {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS}, - {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS}, - {"expand", (PyCFunction) match_expand, METH_O}, + {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc}, + {"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc}, + {"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc}, + {"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc}, + {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS, + match_groups_doc}, + {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS, + match_groupdict_doc}, + {"expand", (PyCFunction) match_expand, METH_O, match_expand_doc}, {"__copy__", (PyCFunction) match_copy, METH_NOARGS}, {"__deepcopy__", (PyCFunction) match_deepcopy, METH_O}, {NULL, NULL} @@ -3629,7 +3669,7 @@ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ + match_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 19:01:16 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 19:01:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316443=3A_Add_docstrings_to_regular_expression_m?= =?utf-8?q?atch_objects=2E?= Message-ID: <3YTrwr4rf4zRTL@mail.python.org> http://hg.python.org/cpython/rev/e3d0417d8266 changeset: 81003:e3d0417d8266 parent: 80999:3c830691f598 parent: 81002:64e050c2d010 user: Andrew Svetlov date: Sun Dec 23 20:00:58 2012 +0200 summary: Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. files: Misc/ACKS | 2 + Misc/NEWS | 5 ++ Modules/_sre.c | 70 +++++++++++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -601,8 +601,10 @@ Peter van Kampen Rafe Kaplan Jacob Kaplan-Moss +Jan Kaliszewski Janne Karila Per ?yvind Karlsen +Anton Kasyanov Lou Kates Hiroaki Kawai Sebastien Keim diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -176,6 +176,11 @@ Library ------- +- Issue #16443: Add docstrings to regular expression match objects. + Patch by Anton Kasyanov. + +- Issue #15701: Fix HTTPError info method call to return the headers information. + - Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag. - Issue #16646: ftplib.FTP.makeport() might lose socket error details. diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2527,35 +2527,35 @@ } PyDoc_STRVAR(pattern_match_doc, -"match(string[, pos[, endpos]]) --> match object or None.\n\ +"match(string[, pos[, endpos]]) -> match object or None.\n\ Matches zero or more characters at the beginning of the string"); PyDoc_STRVAR(pattern_search_doc, -"search(string[, pos[, endpos]]) --> match object or None.\n\ +"search(string[, pos[, endpos]]) -> match object or None.\n\ Scan through string looking for a match, and return a corresponding\n\ MatchObject instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, -"split(string[, maxsplit = 0]) --> list.\n\ +"split(string[, maxsplit = 0]) -> list.\n\ Split string by the occurrences of pattern."); PyDoc_STRVAR(pattern_findall_doc, -"findall(string[, pos[, endpos]]) --> list.\n\ +"findall(string[, pos[, endpos]]) -> list.\n\ Return a list of all non-overlapping matches of pattern in string."); PyDoc_STRVAR(pattern_finditer_doc, -"finditer(string[, pos[, endpos]]) --> iterator.\n\ +"finditer(string[, pos[, endpos]]) -> iterator.\n\ Return an iterator over all non-overlapping matches for the \n\ RE pattern in string. For each match, the iterator returns a\n\ match object."); PyDoc_STRVAR(pattern_sub_doc, -"sub(repl, string[, count = 0]) --> newstring\n\ +"sub(repl, string[, count = 0]) -> newstring.\n\ Return the string obtained by replacing the leftmost non-overlapping\n\ occurrences of pattern in string by the replacement repl."); PyDoc_STRVAR(pattern_subn_doc, -"subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\ +"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\ Return the tuple (new_string, number_of_subs_made) found by replacing\n\ the leftmost non-overlapping occurrences of pattern with the\n\ replacement repl."); @@ -3543,14 +3543,54 @@ #endif } +PyDoc_STRVAR(match_doc, +"The result of re.match() and re.search().\n\ +Match objects always have a boolean value of True."); + +PyDoc_STRVAR(match_group_doc, +"group([group1, ...]) -> str or tuple.\n\ + Return subgroup(s) of the match by indices or names.\n\ + For 0 returns the entire match."); + +PyDoc_STRVAR(match_start_doc, +"start([group=0]) -> int.\n\ + Return index of the start of the substring matched by group."); + +PyDoc_STRVAR(match_end_doc, +"end([group=0]) -> int.\n\ + Return index of the end of the substring matched by group."); + +PyDoc_STRVAR(match_span_doc, +"span([group]) -> tuple.\n\ + For MatchObject m, return the 2-tuple (m.start(group), m.end(group))."); + +PyDoc_STRVAR(match_groups_doc, +"groups([default=None]) -> tuple.\n\ + Return a tuple containing all the subgroups of the match, from 1.\n\ + The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_groupdict_doc, +"groupdict([default=None]) -> dict.\n\ + Return a dictionary containing all the named subgroups of the match,\n\ + keyed by the subgroup name. The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_expand_doc, +"expand(template) -> str.\n\ + Return the string obtained by doing backslash substitution\n\ + on the string template, as done by the sub() method."); + static PyMethodDef match_methods[] = { - {"group", (PyCFunction) match_group, METH_VARARGS}, - {"start", (PyCFunction) match_start, METH_VARARGS}, - {"end", (PyCFunction) match_end, METH_VARARGS}, - {"span", (PyCFunction) match_span, METH_VARARGS}, - {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS}, - {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS}, - {"expand", (PyCFunction) match_expand, METH_O}, + {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc}, + {"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc}, + {"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc}, + {"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc}, + {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS, + match_groups_doc}, + {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS, + match_groupdict_doc}, + {"expand", (PyCFunction) match_expand, METH_O, match_expand_doc}, {"__copy__", (PyCFunction) match_copy, METH_NOARGS}, {"__deepcopy__", (PyCFunction) match_deepcopy, METH_O}, {NULL, NULL} @@ -3629,7 +3669,7 @@ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ + match_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 19:09:11 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 23 Dec 2012 19:09:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NDQz?= =?utf-8?q?=3A_Add_docstrings_to_regular_expression_match_objects=2E?= Message-ID: <3YTs5z1G4BzM2d@mail.python.org> http://hg.python.org/cpython/rev/c390dc999fcc changeset: 81004:c390dc999fcc branch: 2.7 parent: 80996:3046bfea59f3 user: Andrew Svetlov date: Sun Dec 23 20:09:01 2012 +0200 summary: Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. files: Misc/ACKS | 1 + Misc/NEWS | 3 + Modules/_sre.c | 58 ++++++++++++++++++++++++++++++++----- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -499,6 +499,7 @@ Peter van Kampen Jacob Kaplan-Moss Piotr Kasprzyk +Anton Kasyanov Lou Kates Hiroaki Kawai Sebastien Keim diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -160,6 +160,9 @@ Library ------- +- Issue #16443: Add docstrings to regular expression match objects. + Patch by Anton Kasyanov. + - Issue #8853: Allow port to be of type long for socket.getaddrinfo(). - Issue #16597: In buffered and text IO, call close() on the underlying stream diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -3545,14 +3545,54 @@ #endif } -static struct PyMethodDef match_methods[] = { - {"group", (PyCFunction) match_group, METH_VARARGS}, - {"start", (PyCFunction) match_start, METH_VARARGS}, - {"end", (PyCFunction) match_end, METH_VARARGS}, - {"span", (PyCFunction) match_span, METH_VARARGS}, - {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS}, - {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS}, - {"expand", (PyCFunction) match_expand, METH_O}, +PyDoc_STRVAR(match_doc, +"The result of re.match() and re.search().\n\ +Match objects always have a boolean value of True."); + +PyDoc_STRVAR(match_group_doc, +"group([group1, ...]) -> str or tuple.\n\ + Return subgroup(s) of the match by indices or names.\n\ + For 0 returns the entire match."); + +PyDoc_STRVAR(match_start_doc, +"start([group=0]) -> int.\n\ + Return index of the start of the substring matched by group."); + +PyDoc_STRVAR(match_end_doc, +"end([group=0]) -> int.\n\ + Return index of the end of the substring matched by group."); + +PyDoc_STRVAR(match_span_doc, +"span([group]) -> tuple.\n\ + For MatchObject m, return the 2-tuple (m.start(group), m.end(group))."); + +PyDoc_STRVAR(match_groups_doc, +"groups([default=None]) -> tuple.\n\ + Return a tuple containing all the subgroups of the match, from 1.\n\ + The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_groupdict_doc, +"groupdict([default=None]) -> dict.\n\ + Return a dictionary containing all the named subgroups of the match,\n\ + keyed by the subgroup name. The default argument is used for groups\n\ + that did not participate in the match"); + +PyDoc_STRVAR(match_expand_doc, +"expand(template) -> str.\n\ + Return the string obtained by doing backslash substitution\n\ + on the string template, as done by the sub() method."); + +static PyMethodDef match_methods[] = { + {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc}, + {"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc}, + {"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc}, + {"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc}, + {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS, + match_groups_doc}, + {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS, + match_groupdict_doc}, + {"expand", (PyCFunction) match_expand, METH_O, match_expand_doc}, {"__copy__", (PyCFunction) match_copy, METH_NOARGS}, {"__deepcopy__", (PyCFunction) match_deepcopy, METH_O}, {NULL, NULL} @@ -3632,7 +3672,7 @@ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, - 0, /* tp_doc */ + match_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 23:55:21 2012 From: python-checkins at python.org (brian.curtin) Date: Sun, 23 Dec 2012 23:55:21 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_=2314470=2E_Remove_w9x?= =?utf-8?q?popen_per_PEP_11=2E?= Message-ID: <3YTzS91KzGzRgT@mail.python.org> http://hg.python.org/cpython/rev/c903e4f1121d changeset: 81005:c903e4f1121d parent: 81003:e3d0417d8266 user: Brian Curtin date: Sun Dec 23 16:53:21 2012 -0600 summary: Fix #14470. Remove w9xpopen per PEP 11. As stated in PEP 11, 3.4 removes code on Windows platforms where COMSPEC points to command.com. The w9xpopen project in Visual Studio was added to support that case, and there was a special case in subprocess to cover that situation. This change removes the w9xpopen project from the Visual Studio solution and removes any references to the w9xpopen executable. files: Lib/subprocess.py | 32 -- PC/w9xpopen.c | 112 ------- PCbuild/pcbuild.sln | 2 - PCbuild/python.vcxproj | 6 +- PCbuild/w9xpopen.vcxproj | 287 ------------------- PCbuild/w9xpopen.vcxproj.filters | 13 - Tools/msi/msi.py | 2 - 7 files changed, 1 insertions(+), 453 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1029,23 +1029,6 @@ return Handle(h) - def _find_w9xpopen(self): - """Find and return absolut path to w9xpopen.exe""" - w9xpopen = os.path.join( - os.path.dirname(_winapi.GetModuleFileName(0)), - "w9xpopen.exe") - if not os.path.exists(w9xpopen): - # Eeek - file-not-found - possibly an embedding - # situation - see if we can locate it in sys.exec_prefix - w9xpopen = os.path.join(os.path.dirname(sys.base_exec_prefix), - "w9xpopen.exe") - if not os.path.exists(w9xpopen): - raise SubprocessError( - "Cannot locate w9xpopen.exe, which is needed for " - "Popen to work with your shell or platform.") - return w9xpopen - - def _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, @@ -1074,21 +1057,6 @@ startupinfo.wShowWindow = _winapi.SW_HIDE comspec = os.environ.get("COMSPEC", "cmd.exe") args = '{} /c "{}"'.format (comspec, args) - if (_winapi.GetVersion() >= 0x80000000 or - os.path.basename(comspec).lower() == "command.com"): - # Win9x, or using command.com on NT. We need to - # use the w9xpopen intermediate program. For more - # information, see KB Q150956 - # (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp) - w9xpopen = self._find_w9xpopen() - args = '"%s" %s' % (w9xpopen, args) - # Not passing CREATE_NEW_CONSOLE has been known to - # cause random failures on win9x. Specifically a - # dialog: "Your program accessed mem currently in - # use at xxx" and a hopeful warning about the - # stability of your system. Cost is Ctrl+C won't - # kill children. - creationflags |= _winapi.CREATE_NEW_CONSOLE # Start the process try: diff --git a/PC/w9xpopen.c b/PC/w9xpopen.c deleted file mode 100644 --- a/PC/w9xpopen.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * w9xpopen.c - * - * Serves as an intermediate stub Win32 console application to - * avoid a hanging pipe when redirecting 16-bit console based - * programs (including MS-DOS console based programs and batch - * files) on Window 95 and Windows 98. - * - * This program is to be launched with redirected standard - * handles. It will launch the command line specified 16-bit - * console based application in the same console, forwarding - * its own redirected standard handles to the 16-bit child. - - * AKA solution to the problem described in KB: Q150956. - */ - -#define WIN32_LEAN_AND_MEAN -#include -#include -#include /* for malloc and its friends */ - -const char *usage = -"This program is used by Python's os.popen function\n" -"to work around a limitation in Windows 95/98. It is\n" -"not designed to be used as a stand-alone program."; - -int main(int argc, char *argv[]) -{ - BOOL bRet; - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD exit_code=0; - size_t cmdlen = 0; - int i; - char *cmdline, *cmdlinefill; - - if (argc < 2) { - if (GetFileType(GetStdHandle(STD_INPUT_HANDLE))==FILE_TYPE_CHAR) - /* Attached to a console, and therefore not executed by Python - Display a message box for the inquisitive user - */ - MessageBox(NULL, usage, argv[0], MB_OK); - else { - /* Eeek - executed by Python, but args are screwed! - Write an error message to stdout so there is at - least some clue for the end user when it appears - in their output. - A message box would be hidden and blocks the app. - */ - fprintf(stdout, "Internal popen error - no args specified\n%s\n", usage); - } - return 1; - } - /* Build up the command-line from the args. - Args with a space are quoted, existing quotes are escaped. - To keep things simple calculating the buffer size, we assume - every character is a quote - ie, we allocate double what we need - in the worst case. As this is only double the command line passed - to us, there is a good chance this is reasonably small, so the total - allocation will almost always be < 512 bytes. - */ - for (i=1;i{cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} false - - {e9e0a1f6-0009-4e8c-b8f8-1b8f5d49a058} - false - - \ No newline at end of file + diff --git a/PCbuild/w9xpopen.vcxproj b/PCbuild/w9xpopen.vcxproj deleted file mode 100644 --- a/PCbuild/w9xpopen.vcxproj +++ /dev/null @@ -1,287 +0,0 @@ -? - - - - Debug - Win32 - - - Debug - x64 - - - PGInstrument - Win32 - - - PGInstrument - x64 - - - PGUpdate - Win32 - - - PGUpdate - x64 - - - Release - Win32 - - - Release - x64 - - - - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058} - w9xpopen - - - - Application - false - MultiByte - - - Application - false - MultiByte - - - Application - false - MultiByte - - - Application - false - NotSet - - - Application - false - MultiByte - - - Application - false - MultiByte - - - Application - false - MultiByte - - - Application - false - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.40219.1 - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - EnableFastChecks - MultiThreadedDebug - - - Console - - - - - X64 - - - Disabled - EnableFastChecks - MultiThreadedDebug - - - Console - - - - - MaxSpeed - OnlyExplicitInline - true - MultiThreaded - true - - - false - Console - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - MultiThreaded - true - - - false - Console - - - - - MaxSpeed - OnlyExplicitInline - true - MultiThreaded - true - - - false - Console - - - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - MultiThreaded - true - - - false - Console - - - MachineX64 - - - - - MaxSpeed - OnlyExplicitInline - true - MultiThreaded - true - - - false - Console - - - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - MultiThreaded - true - - - false - Console - - - MachineX64 - - - - - - - - - \ No newline at end of file diff --git a/PCbuild/w9xpopen.vcxproj.filters b/PCbuild/w9xpopen.vcxproj.filters deleted file mode 100644 --- a/PCbuild/w9xpopen.vcxproj.filters +++ /dev/null @@ -1,13 +0,0 @@ -? - - - - {abc2dffd-3f2a-47bd-b89b-0314c99ef21e} - - - - - Source Files - - - \ No newline at end of file diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -956,8 +956,6 @@ # Add all executables, icons, text files into the TARGETDIR component root = PyDirectory(db, cab, None, srcdir, "TARGETDIR", "SourceDir") default_feature.set_current() - if not msilib.Win64: - root.add_file("%s/w9xpopen.exe" % PCBUILD) root.add_file("README.txt", src="README") root.add_file("NEWS.txt", src="Misc/NEWS") generate_license() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 23 23:55:22 2012 From: python-checkins at python.org (brian.curtin) Date: Sun, 23 Dec 2012 23:55:22 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_NEWS_item_for_fixing_?= =?utf-8?q?=2314470=2E?= Message-ID: <3YTzSB3p8YzRgT@mail.python.org> http://hg.python.org/cpython/rev/ae1845e4006a changeset: 81006:ae1845e4006a user: Brian Curtin date: Sun Dec 23 16:54:41 2012 -0600 summary: Add NEWS item for fixing #14470. files: Misc/NEWS | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #14470: Remove w9xpopen support per PEP 11. + - Issue #9856: Replace deprecation warning with raising TypeError in object.__format__. Patch by Florent Xicluna. -- Repository URL: http://hg.python.org/cpython From root at python.org Sun Dec 23 23:56:28 2012 From: root at python.org (Cron Daemon) Date: Sun, 23 Dec 2012 23:56:28 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: abort: error: Connection reset by peer From python-checkins at python.org Mon Dec 24 00:36:54 2012 From: python-checkins at python.org (chris.jerdonek) Date: Mon, 24 Dec 2012 00:36:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogTGluayB0byAieWll?= =?utf-8?q?ld_from=22_examples_in_yield_documentation=2E?= Message-ID: <3YV0N64xL3zQNH@mail.python.org> http://hg.python.org/cpython/rev/ecbd29ff2dd5 changeset: 81007:ecbd29ff2dd5 branch: 3.3 parent: 81002:64e050c2d010 user: Chris Jerdonek date: Sun Dec 23 15:31:57 2012 -0800 summary: Link to "yield from" examples in yield documentation. This commit also simplifies the more advanced "yield from" example and removes unused function parameters. files: Doc/reference/expressions.rst | 12 +++++++++++- Doc/whatsnew/3.3.rst | 18 +++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -320,7 +320,8 @@ yield_atom: "(" `yield_expression` ")" yield_expression: "yield" [`expression_list` | "from" `expression`] -The :keyword:`yield` expression is only used when defining a generator function, +The :keyword:`yield` expression is only used when defining a :term:`generator` +function, and can only be used in the body of a function definition. Using a :keyword:`yield` expression in a function definition is sufficient to cause that definition to create a generator function instead of a normal function. @@ -438,6 +439,12 @@ other exception, it is propagated to the caller. :meth:`close` does nothing if the generator has already exited due to an exception or normal exit. + +.. index:: single: yield; examples + +Examples +^^^^^^^^ + Here is a simple example that demonstrates the behavior of generators and generator functions:: @@ -465,6 +472,9 @@ >>> generator.close() Don't forget to clean up when 'close()' is called. +For examples using ``yield from``, see :ref:`pep-380` in "What's New in +Python." + .. seealso:: diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -393,14 +393,18 @@ PEP written and implemented by Antoine Pitrou +.. index:: + single: yield; yield from (in What's New) + .. _pep-380: PEP 380: Syntax for Delegating to a Subgenerator ================================================ -PEP 380 adds the ``yield from`` expression, allowing a generator to delegate +PEP 380 adds the ``yield from`` expression, allowing a :term:`generator` to +delegate part of its operations to another generator. This allows a section of code -containing 'yield' to be factored out and placed in another generator. +containing :keyword:`yield` to be factored out and placed in another generator. Additionally, the subgenerator is allowed to return with a value, and the value is made available to the delegating generator. @@ -421,15 +425,15 @@ receive sent and thrown values directly from the calling scope, and return a final value to the outer generator:: - >>> def accumulate(start=0): - ... tally = start + >>> def accumulate(): + ... tally = 0 ... while 1: ... next = yield ... if next is None: ... return tally ... tally += next ... - >>> def gather_tallies(tallies, start=0): + >>> def gather_tallies(tallies): ... while 1: ... tally = yield from accumulate() ... tallies.append(tally) @@ -437,7 +441,7 @@ >>> tallies = [] >>> acc = gather_tallies(tallies) >>> next(acc) # Ensure the accumulator is ready to accept values - >>> for i in range(10): + >>> for i in range(4): ... acc.send(i) ... >>> acc.send(None) # Finish the first tally @@ -446,7 +450,7 @@ ... >>> acc.send(None) # Finish the second tally >>> tallies - [45, 10] + [6, 10] The main principle driving this change is to allow even generators that are designed to be used with the ``send`` and ``throw`` methods to be split into -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 00:36:56 2012 From: python-checkins at python.org (chris.jerdonek) Date: Mon, 24 Dec 2012 00:36:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_from_3=2E3=3A_link_to_=22yield_from=22_examples_in?= =?utf-8?q?_yield_documentation=2E?= Message-ID: <3YV0N80bLJzQkQ@mail.python.org> http://hg.python.org/cpython/rev/76c5f3371db6 changeset: 81008:76c5f3371db6 parent: 81006:ae1845e4006a parent: 81007:ecbd29ff2dd5 user: Chris Jerdonek date: Sun Dec 23 15:35:23 2012 -0800 summary: Merge from 3.3: link to "yield from" examples in yield documentation. files: Doc/reference/expressions.rst | 12 +++++++++++- Doc/whatsnew/3.3.rst | 18 +++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -320,7 +320,8 @@ yield_atom: "(" `yield_expression` ")" yield_expression: "yield" [`expression_list` | "from" `expression`] -The :keyword:`yield` expression is only used when defining a generator function, +The :keyword:`yield` expression is only used when defining a :term:`generator` +function, and can only be used in the body of a function definition. Using a :keyword:`yield` expression in a function definition is sufficient to cause that definition to create a generator function instead of a normal function. @@ -438,6 +439,12 @@ other exception, it is propagated to the caller. :meth:`close` does nothing if the generator has already exited due to an exception or normal exit. + +.. index:: single: yield; examples + +Examples +^^^^^^^^ + Here is a simple example that demonstrates the behavior of generators and generator functions:: @@ -465,6 +472,9 @@ >>> generator.close() Don't forget to clean up when 'close()' is called. +For examples using ``yield from``, see :ref:`pep-380` in "What's New in +Python." + .. seealso:: diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -393,14 +393,18 @@ PEP written and implemented by Antoine Pitrou +.. index:: + single: yield; yield from (in What's New) + .. _pep-380: PEP 380: Syntax for Delegating to a Subgenerator ================================================ -PEP 380 adds the ``yield from`` expression, allowing a generator to delegate +PEP 380 adds the ``yield from`` expression, allowing a :term:`generator` to +delegate part of its operations to another generator. This allows a section of code -containing 'yield' to be factored out and placed in another generator. +containing :keyword:`yield` to be factored out and placed in another generator. Additionally, the subgenerator is allowed to return with a value, and the value is made available to the delegating generator. @@ -421,15 +425,15 @@ receive sent and thrown values directly from the calling scope, and return a final value to the outer generator:: - >>> def accumulate(start=0): - ... tally = start + >>> def accumulate(): + ... tally = 0 ... while 1: ... next = yield ... if next is None: ... return tally ... tally += next ... - >>> def gather_tallies(tallies, start=0): + >>> def gather_tallies(tallies): ... while 1: ... tally = yield from accumulate() ... tallies.append(tally) @@ -437,7 +441,7 @@ >>> tallies = [] >>> acc = gather_tallies(tallies) >>> next(acc) # Ensure the accumulator is ready to accept values - >>> for i in range(10): + >>> for i in range(4): ... acc.send(i) ... >>> acc.send(None) # Finish the first tally @@ -446,7 +450,7 @@ ... >>> acc.send(None) # Finish the second tally >>> tallies - [45, 10] + [6, 10] The main principle driving this change is to allow even generators that are designed to be used with the ``send`` and ``throw`` methods to be split into -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Dec 24 05:53:56 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 24 Dec 2012 05:53:56 +0100 Subject: [Python-checkins] Daily reference leaks (76c5f3371db6): sum=0 Message-ID: results for 76c5f3371db6 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogSFWUCV', '-x'] From andrew.svetlov at gmail.com Mon Dec 24 09:36:52 2012 From: andrew.svetlov at gmail.com (Andrew Svetlov) Date: Mon, 24 Dec 2012 10:36:52 +0200 Subject: [Python-checkins] cpython: Fix #14470. Remove w9xpopen per PEP 11. In-Reply-To: <3YTzS91KzGzRgT@mail.python.org> References: <3YTzS91KzGzRgT@mail.python.org> Message-ID: You missed artifacts in ./PC/VC6 ./PC/VS7.1 ./PC/VS8.0 ./PC/VS9.0 On Mon, Dec 24, 2012 at 12:55 AM, brian.curtin wrote: > http://hg.python.org/cpython/rev/c903e4f1121d > changeset: 81005:c903e4f1121d > parent: 81003:e3d0417d8266 > user: Brian Curtin > date: Sun Dec 23 16:53:21 2012 -0600 > summary: > Fix #14470. Remove w9xpopen per PEP 11. > > As stated in PEP 11, 3.4 removes code on Windows platforms where > COMSPEC points to command.com. The w9xpopen project in Visual Studio > was added to support that case, and there was a special case in subprocess > to cover that situation. This change removes the w9xpopen project from > the Visual Studio solution and removes any references to the w9xpopen > executable. > > files: > Lib/subprocess.py | 32 -- > PC/w9xpopen.c | 112 ------- > PCbuild/pcbuild.sln | 2 - > PCbuild/python.vcxproj | 6 +- > PCbuild/w9xpopen.vcxproj | 287 ------------------- > PCbuild/w9xpopen.vcxproj.filters | 13 - > Tools/msi/msi.py | 2 - > 7 files changed, 1 insertions(+), 453 deletions(-) > > > diff --git a/Lib/subprocess.py b/Lib/subprocess.py > --- a/Lib/subprocess.py > +++ b/Lib/subprocess.py > @@ -1029,23 +1029,6 @@ > return Handle(h) > > > - def _find_w9xpopen(self): > - """Find and return absolut path to w9xpopen.exe""" > - w9xpopen = os.path.join( > - os.path.dirname(_winapi.GetModuleFileName(0)), > - "w9xpopen.exe") > - if not os.path.exists(w9xpopen): > - # Eeek - file-not-found - possibly an embedding > - # situation - see if we can locate it in sys.exec_prefix > - w9xpopen = os.path.join(os.path.dirname(sys.base_exec_prefix), > - "w9xpopen.exe") > - if not os.path.exists(w9xpopen): > - raise SubprocessError( > - "Cannot locate w9xpopen.exe, which is needed for " > - "Popen to work with your shell or platform.") > - return w9xpopen > - > - > def _execute_child(self, args, executable, preexec_fn, close_fds, > pass_fds, cwd, env, > startupinfo, creationflags, shell, > @@ -1074,21 +1057,6 @@ > startupinfo.wShowWindow = _winapi.SW_HIDE > comspec = os.environ.get("COMSPEC", "cmd.exe") > args = '{} /c "{}"'.format (comspec, args) > - if (_winapi.GetVersion() >= 0x80000000 or > - os.path.basename(comspec).lower() == "command.com"): > - # Win9x, or using command.com on NT. We need to > - # use the w9xpopen intermediate program. For more > - # information, see KB Q150956 > - # (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp) > - w9xpopen = self._find_w9xpopen() > - args = '"%s" %s' % (w9xpopen, args) > - # Not passing CREATE_NEW_CONSOLE has been known to > - # cause random failures on win9x. Specifically a > - # dialog: "Your program accessed mem currently in > - # use at xxx" and a hopeful warning about the > - # stability of your system. Cost is Ctrl+C won't > - # kill children. > - creationflags |= _winapi.CREATE_NEW_CONSOLE > > # Start the process > try: > diff --git a/PC/w9xpopen.c b/PC/w9xpopen.c > deleted file mode 100644 > --- a/PC/w9xpopen.c > +++ /dev/null > @@ -1,112 +0,0 @@ > -/* > - * w9xpopen.c > - * > - * Serves as an intermediate stub Win32 console application to > - * avoid a hanging pipe when redirecting 16-bit console based > - * programs (including MS-DOS console based programs and batch > - * files) on Window 95 and Windows 98. > - * > - * This program is to be launched with redirected standard > - * handles. It will launch the command line specified 16-bit > - * console based application in the same console, forwarding > - * its own redirected standard handles to the 16-bit child. > - > - * AKA solution to the problem described in KB: Q150956. > - */ > - > -#define WIN32_LEAN_AND_MEAN > -#include > -#include > -#include /* for malloc and its friends */ > - > -const char *usage = > -"This program is used by Python's os.popen function\n" > -"to work around a limitation in Windows 95/98. It is\n" > -"not designed to be used as a stand-alone program."; > - > -int main(int argc, char *argv[]) > -{ > - BOOL bRet; > - STARTUPINFO si; > - PROCESS_INFORMATION pi; > - DWORD exit_code=0; > - size_t cmdlen = 0; > - int i; > - char *cmdline, *cmdlinefill; > - > - if (argc < 2) { > - if (GetFileType(GetStdHandle(STD_INPUT_HANDLE))==FILE_TYPE_CHAR) > - /* Attached to a console, and therefore not executed by Python > - Display a message box for the inquisitive user > - */ > - MessageBox(NULL, usage, argv[0], MB_OK); > - else { > - /* Eeek - executed by Python, but args are screwed! > - Write an error message to stdout so there is at > - least some clue for the end user when it appears > - in their output. > - A message box would be hidden and blocks the app. > - */ > - fprintf(stdout, "Internal popen error - no args specified\n%s\n", usage); > - } > - return 1; > - } > - /* Build up the command-line from the args. > - Args with a space are quoted, existing quotes are escaped. > - To keep things simple calculating the buffer size, we assume > - every character is a quote - ie, we allocate double what we need > - in the worst case. As this is only double the command line passed > - to us, there is a good chance this is reasonably small, so the total > - allocation will almost always be < 512 bytes. > - */ > - for (i=1;i - cmdlen += strlen(argv[i])*2 + 3; /* one space, maybe 2 quotes */ > - cmdline = cmdlinefill = (char *)malloc(cmdlen+1); > - if (cmdline == NULL) > - return -1; > - for (i=1;i - const char *arglook; > - int bQuote = strchr(argv[i], ' ') != NULL; > - if (bQuote) > - *cmdlinefill++ = '"'; > - /* escape quotes */ > - for (arglook=argv[i];*arglook;arglook++) { > - if (*arglook=='"') > - *cmdlinefill++ = '\\'; > - *cmdlinefill++ = *arglook; > - } > - if (bQuote) > - *cmdlinefill++ = '"'; > - *cmdlinefill++ = ' '; > - } > - *cmdlinefill = '\0'; > - > - /* Make child process use this app's standard files. */ > - ZeroMemory(&si, sizeof si); > - si.cb = sizeof si; > - si.dwFlags = STARTF_USESTDHANDLES; > - si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); > - si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); > - si.hStdError = GetStdHandle(STD_ERROR_HANDLE); > - > - bRet = CreateProcess( > - NULL, cmdline, > - NULL, NULL, > - TRUE, 0, > - NULL, NULL, > - &si, &pi > - ); > - > - free(cmdline); > - > - if (bRet) { > - if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED) { > - GetExitCodeProcess(pi.hProcess, &exit_code); > - } > - CloseHandle(pi.hProcess); > - CloseHandle(pi.hThread); > - return exit_code; > - } > - > - return 1; > -} > diff --git a/PCbuild/pcbuild.sln b/PCbuild/pcbuild.sln > --- a/PCbuild/pcbuild.sln > +++ b/PCbuild/pcbuild.sln > @@ -14,8 +14,6 @@ > EndProject > Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pythonw", "pythonw.vcxproj", "{F4229CC3-873C-49AE-9729-DD308ED4CD4A}" > EndProject > -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcxproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" > -EndProject > Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcxproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" > EndProject > Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcxproj", "{28B5D777-DDF2-4B6B-B34F-31D938813856}" > diff --git a/PCbuild/python.vcxproj b/PCbuild/python.vcxproj > --- a/PCbuild/python.vcxproj > +++ b/PCbuild/python.vcxproj > @@ -357,12 +357,8 @@ > {cf7ac3d1-e2df-41d2-bea6-1e2556cdea26} > false > > - > - {e9e0a1f6-0009-4e8c-b8f8-1b8f5d49a058} > - false > - > > > > > - > \ No newline at end of file > + > diff --git a/PCbuild/w9xpopen.vcxproj b/PCbuild/w9xpopen.vcxproj > deleted file mode 100644 > --- a/PCbuild/w9xpopen.vcxproj > +++ /dev/null > @@ -1,287 +0,0 @@ > -? > - > - > - > - Debug > - Win32 > - > - > - Debug > - x64 > - > - > - PGInstrument > - Win32 > - > - > - PGInstrument > - x64 > - > - > - PGUpdate > - Win32 > - > - > - PGUpdate > - x64 > - > - > - Release > - Win32 > - > - > - Release > - x64 > - > - > - > - {E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058} > - w9xpopen > - > - > - > - Application > - false > - MultiByte > - > - > - Application > - false > - MultiByte > - > - > - Application > - false > - MultiByte > - > - > - Application > - false > - NotSet > - > - > - Application > - false > - MultiByte > - > - > - Application > - false > - MultiByte > - > - > - Application > - false > - MultiByte > - > - > - Application > - false > - MultiByte > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - <_ProjectFileVersion>10.0.40219.1 > - AllRules.ruleset > - > - > - AllRules.ruleset > - > - > - AllRules.ruleset > - > - > - AllRules.ruleset > - > - > - AllRules.ruleset > - > - > - AllRules.ruleset > - > - > - AllRules.ruleset > - > - > - AllRules.ruleset > - > - > - > - > - > - Disabled > - EnableFastChecks > - MultiThreadedDebug > - > - > - Console > - > - > - > - > - X64 > - > - > - Disabled > - EnableFastChecks > - MultiThreadedDebug > - > - > - Console > - > - > - > - > - MaxSpeed > - OnlyExplicitInline > - true > - MultiThreaded > - true > - > - > - false > - Console > - > - > - > - > - X64 > - > - > - MaxSpeed > - OnlyExplicitInline > - true > - MultiThreaded > - true > - > - > - false > - Console > - > - > - > - > - MaxSpeed > - OnlyExplicitInline > - true > - MultiThreaded > - true > - > - > - false > - Console > - > - > - > - > - > - > - X64 > - > - > - MaxSpeed > - OnlyExplicitInline > - true > - MultiThreaded > - true > - > - > - false > - Console > - > - > - MachineX64 > - > - > - > - > - MaxSpeed > - OnlyExplicitInline > - true > - MultiThreaded > - true > - > - > - false > - Console > - > - > - > - > - > - > - X64 > - > - > - MaxSpeed > - OnlyExplicitInline > - true > - MultiThreaded > - true > - > - > - false > - Console > - > - > - MachineX64 > - > - > - > - > - > - > - > - > - > \ No newline at end of file > diff --git a/PCbuild/w9xpopen.vcxproj.filters b/PCbuild/w9xpopen.vcxproj.filters > deleted file mode 100644 > --- a/PCbuild/w9xpopen.vcxproj.filters > +++ /dev/null > @@ -1,13 +0,0 @@ > -? > - > - > - > - {abc2dffd-3f2a-47bd-b89b-0314c99ef21e} > - > - > - > - > - Source Files > - > - > - > \ No newline at end of file > diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py > --- a/Tools/msi/msi.py > +++ b/Tools/msi/msi.py > @@ -956,8 +956,6 @@ > # Add all executables, icons, text files into the TARGETDIR component > root = PyDirectory(db, cab, None, srcdir, "TARGETDIR", "SourceDir") > default_feature.set_current() > - if not msilib.Win64: > - root.add_file("%s/w9xpopen.exe" % PCBUILD) > root.add_file("README.txt", src="README") > root.add_file("NEWS.txt", src="Misc/NEWS") > generate_license() > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > -- Thanks, Andrew Svetlov From python-checkins at python.org Mon Dec 24 12:17:24 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 12:17:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NTEx?= =?utf-8?q?=3A_Use_default_IDLE_width_and_height_if_config_param_is_not_va?= =?utf-8?q?lid=2E?= Message-ID: <3YVHwN4WMQzRlr@mail.python.org> http://hg.python.org/cpython/rev/ffe091ebd5de changeset: 81009:ffe091ebd5de branch: 3.2 parent: 81001:937f70110f9e user: Andrew Svetlov date: Mon Dec 24 13:15:43 2012 +0200 summary: Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. files: Lib/idlelib/EditorWindow.py | 21 ++++++--- Lib/idlelib/FormatParagraph.py | 6 +- Lib/idlelib/configDialog.py | 19 ++++--- Lib/idlelib/configHandler.py | 51 ++++++++++++++------- Misc/NEWS | 3 + 5 files changed, 65 insertions(+), 35 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -170,13 +170,15 @@ 'recent-files.lst') self.text_frame = text_frame = Frame(top) self.vbar = vbar = Scrollbar(text_frame, name='vbar') - self.width = idleConf.GetOption('main','EditorWindow','width') + self.width = idleConf.GetOption('main', 'EditorWindow', + 'width', type='int') text_options = { 'name': 'text', 'padx': 5, 'wrap': 'none', 'width': self.width, - 'height': idleConf.GetOption('main', 'EditorWindow', 'height')} + 'height': idleConf.GetOption('main', 'EditorWindow', + 'height', type='int')} if TkVersion >= 8.5: # Starting with tk 8.5 we have to set the new tabstyle option # to 'wordprocessor' to achieve the same display of tabs as in @@ -253,7 +255,8 @@ if idleConf.GetOption('main', 'EditorWindow', 'font-bold', type='bool'): fontWeight='bold' text.config(font=(idleConf.GetOption('main', 'EditorWindow', 'font'), - idleConf.GetOption('main', 'EditorWindow', 'font-size'), + idleConf.GetOption('main', 'EditorWindow', + 'font-size', type='int'), fontWeight)) text_frame.pack(side=LEFT, fill=BOTH, expand=1) text.pack(side=TOP, fill=BOTH, expand=1) @@ -268,7 +271,8 @@ # Although use-spaces=0 can be configured manually in config-main.def, # configuration of tabs v. spaces is not supported in the configuration # dialog. IDLE promotes the preferred Python indentation: use spaces! - usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool') + usespaces = idleConf.GetOption('main', 'Indent', + 'use-spaces', type='bool') self.usetabs = not usespaces # tabwidth is the display width of a literal tab character. @@ -382,9 +386,11 @@ self.text.tag_remove("sel", "1.0", "end") else: if not self.text.index("sel.first"): - self.text.mark_set("my_anchor", "insert") # there was no previous selection + # there was no previous selection + self.text.mark_set("my_anchor", "insert") else: - if self.text.compare(self.text.index("sel.first"), "<", self.text.index("insert")): + if self.text.compare(self.text.index("sel.first"), "<", + self.text.index("insert")): self.text.mark_set("my_anchor", "sel.first") # extend back else: self.text.mark_set("my_anchor", "sel.last") # extend forward @@ -766,7 +772,8 @@ if idleConf.GetOption('main','EditorWindow','font-bold',type='bool'): fontWeight='bold' self.text.config(font=(idleConf.GetOption('main','EditorWindow','font'), - idleConf.GetOption('main','EditorWindow','font-size'), + idleConf.GetOption('main','EditorWindow','font-size', + type='int'), fontWeight)) def RemoveKeybindings(self): diff --git a/Lib/idlelib/FormatParagraph.py b/Lib/idlelib/FormatParagraph.py --- a/Lib/idlelib/FormatParagraph.py +++ b/Lib/idlelib/FormatParagraph.py @@ -32,7 +32,8 @@ self.editwin = None def format_paragraph_event(self, event): - maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph')) + maxformatwidth = int(idleConf.GetOption('main', 'FormatParagraph', + 'paragraph', type='int')) text = self.editwin.text first, last = self.editwin.get_selection_indices() if first and last: @@ -46,7 +47,8 @@ lines = data.split("\n") lines = map(lambda st, l=len(comment_header): st[l:], lines) data = "\n".join(lines) - # Reformat to maxformatwidth chars or a 20 char width, whichever is greater. + # Reformat to maxformatwidth chars or a 20 char width, + # whichever is greater. format_width = max(maxformatwidth - len(comment_header), 20) newdata = reformat_paragraph(data, format_width) # re-split and re-insert the comment header. diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -925,7 +925,7 @@ for font in fonts: self.listFontName.insert(END,font) configuredFont=idleConf.GetOption('main','EditorWindow','font', - default='courier') + default='courier') lc_configuredFont = configuredFont.lower() self.fontName.set(lc_configuredFont) lc_fonts = [s.lower() for s in fonts] @@ -935,13 +935,13 @@ self.listFontName.select_set(currentFontIndex) self.listFontName.select_anchor(currentFontIndex) ##font size dropdown - fontSize=idleConf.GetOption('main','EditorWindow','font-size', - default='10') + fontSize=idleConf.GetOption('main', 'EditorWindow', 'font-size', + type='int', default='10') self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14', - '16','18','20','22'),fontSize ) + '16','18','20','22'), fontSize ) ##fontWeight self.fontBold.set(idleConf.GetOption('main','EditorWindow', - 'font-bold',default=0,type='bool')) + 'font-bold',default=0,type='bool')) ##font sample self.SetFontSample() @@ -1022,10 +1022,13 @@ self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave', default=0, type='bool')) #initial window size - self.winWidth.set(idleConf.GetOption('main','EditorWindow','width')) - self.winHeight.set(idleConf.GetOption('main','EditorWindow','height')) + self.winWidth.set(idleConf.GetOption('main','EditorWindow','width', + type='int')) + self.winHeight.set(idleConf.GetOption('main','EditorWindow','height', + type='int')) #initial paragraph reformat size - self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph')) + self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph', + type='int')) # default source encoding self.encoding.set(idleConf.GetOption('main', 'EditorWindow', 'encoding', default='none')) diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -237,24 +237,39 @@ printed to stderr. """ - if self.userCfg[configType].has_option(section,option): - return self.userCfg[configType].Get(section, option, - type=type, raw=raw) - elif self.defaultCfg[configType].has_option(section,option): - return self.defaultCfg[configType].Get(section, option, - type=type, raw=raw) - else: #returning default, print warning - if warn_on_default: - warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' - ' problem retrieving configuration option %r\n' - ' from section %r.\n' - ' returning default value: %r\n' % - (option, section, default)) - try: - sys.stderr.write(warning) - except IOError: - pass - return default + try: + if self.userCfg[configType].has_option(section,option): + return self.userCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' invalid %r value for configuration option %r\n' + ' from section %r: %r\n' % + (type, option, section, + self.userCfg[configType].Get(section, option, + raw=raw))) + try: + sys.stderr.write(warning) + except IOError: + pass + try: + if self.defaultCfg[configType].has_option(section,option): + return self.defaultCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + pass + #returning default, print warning + if warn_on_default: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' problem retrieving configuration option %r\n' + ' from section %r.\n' + ' returning default value: %r\n' % + (option, section, default)) + try: + sys.stderr.write(warning) + except IOError: + pass + return default def SetOption(self, configType, section, option, value): """In user's config file, set section's option to value. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,9 @@ Library ------- +- Issue #16511: Use default IDLE width and height if config param is not valid. + Patch Serhiy Storchaka. + - Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 12:17:26 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 12:17:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316511=3A_Use_default_IDLE_width_and_height_if_config_?= =?utf-8?q?param_is_not_valid=2E?= Message-ID: <3YVHwQ12N2zRlr@mail.python.org> http://hg.python.org/cpython/rev/10656b0975b3 changeset: 81010:10656b0975b3 branch: 3.3 parent: 81007:ecbd29ff2dd5 parent: 81009:ffe091ebd5de user: Andrew Svetlov date: Mon Dec 24 13:16:47 2012 +0200 summary: Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. files: Lib/idlelib/EditorWindow.py | 21 ++++++--- Lib/idlelib/FormatParagraph.py | 6 +- Lib/idlelib/configDialog.py | 19 ++++--- Lib/idlelib/configHandler.py | 51 ++++++++++++++------- Misc/NEWS | 3 + 5 files changed, 65 insertions(+), 35 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -170,13 +170,15 @@ 'recent-files.lst') self.text_frame = text_frame = Frame(top) self.vbar = vbar = Scrollbar(text_frame, name='vbar') - self.width = idleConf.GetOption('main','EditorWindow','width') + self.width = idleConf.GetOption('main', 'EditorWindow', + 'width', type='int') text_options = { 'name': 'text', 'padx': 5, 'wrap': 'none', 'width': self.width, - 'height': idleConf.GetOption('main', 'EditorWindow', 'height')} + 'height': idleConf.GetOption('main', 'EditorWindow', + 'height', type='int')} if TkVersion >= 8.5: # Starting with tk 8.5 we have to set the new tabstyle option # to 'wordprocessor' to achieve the same display of tabs as in @@ -253,7 +255,8 @@ if idleConf.GetOption('main', 'EditorWindow', 'font-bold', type='bool'): fontWeight='bold' text.config(font=(idleConf.GetOption('main', 'EditorWindow', 'font'), - idleConf.GetOption('main', 'EditorWindow', 'font-size'), + idleConf.GetOption('main', 'EditorWindow', + 'font-size', type='int'), fontWeight)) text_frame.pack(side=LEFT, fill=BOTH, expand=1) text.pack(side=TOP, fill=BOTH, expand=1) @@ -268,7 +271,8 @@ # Although use-spaces=0 can be configured manually in config-main.def, # configuration of tabs v. spaces is not supported in the configuration # dialog. IDLE promotes the preferred Python indentation: use spaces! - usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool') + usespaces = idleConf.GetOption('main', 'Indent', + 'use-spaces', type='bool') self.usetabs = not usespaces # tabwidth is the display width of a literal tab character. @@ -382,9 +386,11 @@ self.text.tag_remove("sel", "1.0", "end") else: if not self.text.index("sel.first"): - self.text.mark_set("my_anchor", "insert") # there was no previous selection + # there was no previous selection + self.text.mark_set("my_anchor", "insert") else: - if self.text.compare(self.text.index("sel.first"), "<", self.text.index("insert")): + if self.text.compare(self.text.index("sel.first"), "<", + self.text.index("insert")): self.text.mark_set("my_anchor", "sel.first") # extend back else: self.text.mark_set("my_anchor", "sel.last") # extend forward @@ -766,7 +772,8 @@ if idleConf.GetOption('main','EditorWindow','font-bold',type='bool'): fontWeight='bold' self.text.config(font=(idleConf.GetOption('main','EditorWindow','font'), - idleConf.GetOption('main','EditorWindow','font-size'), + idleConf.GetOption('main','EditorWindow','font-size', + type='int'), fontWeight)) def RemoveKeybindings(self): diff --git a/Lib/idlelib/FormatParagraph.py b/Lib/idlelib/FormatParagraph.py --- a/Lib/idlelib/FormatParagraph.py +++ b/Lib/idlelib/FormatParagraph.py @@ -32,7 +32,8 @@ self.editwin = None def format_paragraph_event(self, event): - maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph')) + maxformatwidth = int(idleConf.GetOption('main', 'FormatParagraph', + 'paragraph', type='int')) text = self.editwin.text first, last = self.editwin.get_selection_indices() if first and last: @@ -46,7 +47,8 @@ lines = data.split("\n") lines = map(lambda st, l=len(comment_header): st[l:], lines) data = "\n".join(lines) - # Reformat to maxformatwidth chars or a 20 char width, whichever is greater. + # Reformat to maxformatwidth chars or a 20 char width, + # whichever is greater. format_width = max(maxformatwidth - len(comment_header), 20) newdata = reformat_paragraph(data, format_width) # re-split and re-insert the comment header. diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -925,7 +925,7 @@ for font in fonts: self.listFontName.insert(END,font) configuredFont=idleConf.GetOption('main','EditorWindow','font', - default='courier') + default='courier') lc_configuredFont = configuredFont.lower() self.fontName.set(lc_configuredFont) lc_fonts = [s.lower() for s in fonts] @@ -935,13 +935,13 @@ self.listFontName.select_set(currentFontIndex) self.listFontName.select_anchor(currentFontIndex) ##font size dropdown - fontSize=idleConf.GetOption('main','EditorWindow','font-size', - default='10') + fontSize=idleConf.GetOption('main', 'EditorWindow', 'font-size', + type='int', default='10') self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14', - '16','18','20','22'),fontSize ) + '16','18','20','22'), fontSize ) ##fontWeight self.fontBold.set(idleConf.GetOption('main','EditorWindow', - 'font-bold',default=0,type='bool')) + 'font-bold',default=0,type='bool')) ##font sample self.SetFontSample() @@ -1022,10 +1022,13 @@ self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave', default=0, type='bool')) #initial window size - self.winWidth.set(idleConf.GetOption('main','EditorWindow','width')) - self.winHeight.set(idleConf.GetOption('main','EditorWindow','height')) + self.winWidth.set(idleConf.GetOption('main','EditorWindow','width', + type='int')) + self.winHeight.set(idleConf.GetOption('main','EditorWindow','height', + type='int')) #initial paragraph reformat size - self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph')) + self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph', + type='int')) # default source encoding self.encoding.set(idleConf.GetOption('main', 'EditorWindow', 'encoding', default='none')) diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -238,24 +238,39 @@ printed to stderr. """ - if self.userCfg[configType].has_option(section,option): - return self.userCfg[configType].Get(section, option, - type=type, raw=raw) - elif self.defaultCfg[configType].has_option(section,option): - return self.defaultCfg[configType].Get(section, option, - type=type, raw=raw) - else: #returning default, print warning - if warn_on_default: - warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' - ' problem retrieving configuration option %r\n' - ' from section %r.\n' - ' returning default value: %r\n' % - (option, section, default)) - try: - sys.stderr.write(warning) - except IOError: - pass - return default + try: + if self.userCfg[configType].has_option(section,option): + return self.userCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' invalid %r value for configuration option %r\n' + ' from section %r: %r\n' % + (type, option, section, + self.userCfg[configType].Get(section, option, + raw=raw))) + try: + sys.stderr.write(warning) + except IOError: + pass + try: + if self.defaultCfg[configType].has_option(section,option): + return self.defaultCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + pass + #returning default, print warning + if warn_on_default: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' problem retrieving configuration option %r\n' + ' from section %r.\n' + ' returning default value: %r\n' % + (option, section, default)) + try: + sys.stderr.write(warning) + except IOError: + pass + return default def SetOption(self, configType, section, option, value): """In user's config file, set section's option to value. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -114,6 +114,9 @@ Library ------- +- Issue #16511: Use default IDLE width and height if config param is not valid. + Patch Serhiy Storchaka. + - Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 12:17:27 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 12:17:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316511=3A_Use_default_IDLE_width_and_height_if_c?= =?utf-8?q?onfig_param_is_not_valid=2E?= Message-ID: <3YVHwR50B7zRm1@mail.python.org> http://hg.python.org/cpython/rev/a7c9869a5114 changeset: 81011:a7c9869a5114 parent: 81008:76c5f3371db6 parent: 81010:10656b0975b3 user: Andrew Svetlov date: Mon Dec 24 13:17:11 2012 +0200 summary: Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. files: Lib/idlelib/EditorWindow.py | 21 ++++++--- Lib/idlelib/FormatParagraph.py | 6 +- Lib/idlelib/configDialog.py | 19 ++++--- Lib/idlelib/configHandler.py | 51 ++++++++++++++------- Misc/NEWS | 3 + 5 files changed, 65 insertions(+), 35 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -170,13 +170,15 @@ 'recent-files.lst') self.text_frame = text_frame = Frame(top) self.vbar = vbar = Scrollbar(text_frame, name='vbar') - self.width = idleConf.GetOption('main','EditorWindow','width') + self.width = idleConf.GetOption('main', 'EditorWindow', + 'width', type='int') text_options = { 'name': 'text', 'padx': 5, 'wrap': 'none', 'width': self.width, - 'height': idleConf.GetOption('main', 'EditorWindow', 'height')} + 'height': idleConf.GetOption('main', 'EditorWindow', + 'height', type='int')} if TkVersion >= 8.5: # Starting with tk 8.5 we have to set the new tabstyle option # to 'wordprocessor' to achieve the same display of tabs as in @@ -253,7 +255,8 @@ if idleConf.GetOption('main', 'EditorWindow', 'font-bold', type='bool'): fontWeight='bold' text.config(font=(idleConf.GetOption('main', 'EditorWindow', 'font'), - idleConf.GetOption('main', 'EditorWindow', 'font-size'), + idleConf.GetOption('main', 'EditorWindow', + 'font-size', type='int'), fontWeight)) text_frame.pack(side=LEFT, fill=BOTH, expand=1) text.pack(side=TOP, fill=BOTH, expand=1) @@ -268,7 +271,8 @@ # Although use-spaces=0 can be configured manually in config-main.def, # configuration of tabs v. spaces is not supported in the configuration # dialog. IDLE promotes the preferred Python indentation: use spaces! - usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool') + usespaces = idleConf.GetOption('main', 'Indent', + 'use-spaces', type='bool') self.usetabs = not usespaces # tabwidth is the display width of a literal tab character. @@ -382,9 +386,11 @@ self.text.tag_remove("sel", "1.0", "end") else: if not self.text.index("sel.first"): - self.text.mark_set("my_anchor", "insert") # there was no previous selection + # there was no previous selection + self.text.mark_set("my_anchor", "insert") else: - if self.text.compare(self.text.index("sel.first"), "<", self.text.index("insert")): + if self.text.compare(self.text.index("sel.first"), "<", + self.text.index("insert")): self.text.mark_set("my_anchor", "sel.first") # extend back else: self.text.mark_set("my_anchor", "sel.last") # extend forward @@ -766,7 +772,8 @@ if idleConf.GetOption('main','EditorWindow','font-bold',type='bool'): fontWeight='bold' self.text.config(font=(idleConf.GetOption('main','EditorWindow','font'), - idleConf.GetOption('main','EditorWindow','font-size'), + idleConf.GetOption('main','EditorWindow','font-size', + type='int'), fontWeight)) def RemoveKeybindings(self): diff --git a/Lib/idlelib/FormatParagraph.py b/Lib/idlelib/FormatParagraph.py --- a/Lib/idlelib/FormatParagraph.py +++ b/Lib/idlelib/FormatParagraph.py @@ -32,7 +32,8 @@ self.editwin = None def format_paragraph_event(self, event): - maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph')) + maxformatwidth = int(idleConf.GetOption('main', 'FormatParagraph', + 'paragraph', type='int')) text = self.editwin.text first, last = self.editwin.get_selection_indices() if first and last: @@ -46,7 +47,8 @@ lines = data.split("\n") lines = map(lambda st, l=len(comment_header): st[l:], lines) data = "\n".join(lines) - # Reformat to maxformatwidth chars or a 20 char width, whichever is greater. + # Reformat to maxformatwidth chars or a 20 char width, + # whichever is greater. format_width = max(maxformatwidth - len(comment_header), 20) newdata = reformat_paragraph(data, format_width) # re-split and re-insert the comment header. diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -925,7 +925,7 @@ for font in fonts: self.listFontName.insert(END,font) configuredFont=idleConf.GetOption('main','EditorWindow','font', - default='courier') + default='courier') lc_configuredFont = configuredFont.lower() self.fontName.set(lc_configuredFont) lc_fonts = [s.lower() for s in fonts] @@ -935,13 +935,13 @@ self.listFontName.select_set(currentFontIndex) self.listFontName.select_anchor(currentFontIndex) ##font size dropdown - fontSize=idleConf.GetOption('main','EditorWindow','font-size', - default='10') + fontSize=idleConf.GetOption('main', 'EditorWindow', 'font-size', + type='int', default='10') self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14', - '16','18','20','22'),fontSize ) + '16','18','20','22'), fontSize ) ##fontWeight self.fontBold.set(idleConf.GetOption('main','EditorWindow', - 'font-bold',default=0,type='bool')) + 'font-bold',default=0,type='bool')) ##font sample self.SetFontSample() @@ -1022,10 +1022,13 @@ self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave', default=0, type='bool')) #initial window size - self.winWidth.set(idleConf.GetOption('main','EditorWindow','width')) - self.winHeight.set(idleConf.GetOption('main','EditorWindow','height')) + self.winWidth.set(idleConf.GetOption('main','EditorWindow','width', + type='int')) + self.winHeight.set(idleConf.GetOption('main','EditorWindow','height', + type='int')) #initial paragraph reformat size - self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph')) + self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph', + type='int')) # default source encoding self.encoding.set(idleConf.GetOption('main', 'EditorWindow', 'encoding', default='none')) diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -238,24 +238,39 @@ printed to stderr. """ - if self.userCfg[configType].has_option(section,option): - return self.userCfg[configType].Get(section, option, - type=type, raw=raw) - elif self.defaultCfg[configType].has_option(section,option): - return self.defaultCfg[configType].Get(section, option, - type=type, raw=raw) - else: #returning default, print warning - if warn_on_default: - warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' - ' problem retrieving configuration option %r\n' - ' from section %r.\n' - ' returning default value: %r\n' % - (option, section, default)) - try: - sys.stderr.write(warning) - except IOError: - pass - return default + try: + if self.userCfg[configType].has_option(section,option): + return self.userCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' invalid %r value for configuration option %r\n' + ' from section %r: %r\n' % + (type, option, section, + self.userCfg[configType].Get(section, option, + raw=raw))) + try: + sys.stderr.write(warning) + except IOError: + pass + try: + if self.defaultCfg[configType].has_option(section,option): + return self.defaultCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + pass + #returning default, print warning + if warn_on_default: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' problem retrieving configuration option %r\n' + ' from section %r.\n' + ' returning default value: %r\n' % + (option, section, default)) + try: + sys.stderr.write(warning) + except IOError: + pass + return default def SetOption(self, configType, section, option, value): """In user's config file, set section's option to value. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -178,6 +178,9 @@ Library ------- +- Issue #16511: Use default IDLE width and height if config param is not valid. + Patch Serhiy Storchaka. + - Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 12:18:11 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 12:18:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NTEx?= =?utf-8?q?=3A_Use_default_IDLE_width_and_height_if_config_param_is_not_va?= =?utf-8?q?lid=2E?= Message-ID: <3YVHxH2CxXzRm8@mail.python.org> http://hg.python.org/cpython/rev/133f87a7dbf5 changeset: 81012:133f87a7dbf5 branch: 2.7 parent: 81004:c390dc999fcc user: Andrew Svetlov date: Mon Dec 24 13:17:59 2012 +0200 summary: Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. files: Lib/idlelib/EditorWindow.py | 10 ++- Lib/idlelib/FormatParagraph.py | 3 +- Lib/idlelib/configDialog.py | 11 +++- Lib/idlelib/configHandler.py | 51 ++++++++++++++------- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -172,13 +172,13 @@ 'recent-files.lst') self.text_frame = text_frame = Frame(top) self.vbar = vbar = Scrollbar(text_frame, name='vbar') - self.width = idleConf.GetOption('main','EditorWindow','width') + self.width = idleConf.GetOption('main','EditorWindow','width', type='int') text_options = { 'name': 'text', 'padx': 5, 'wrap': 'none', 'width': self.width, - 'height': idleConf.GetOption('main', 'EditorWindow', 'height')} + 'height': idleConf.GetOption('main', 'EditorWindow', 'height', type='int')} if TkVersion >= 8.5: # Starting with tk 8.5 we have to set the new tabstyle option # to 'wordprocessor' to achieve the same display of tabs as in @@ -255,7 +255,8 @@ if idleConf.GetOption('main', 'EditorWindow', 'font-bold', type='bool'): fontWeight='bold' text.config(font=(idleConf.GetOption('main', 'EditorWindow', 'font'), - idleConf.GetOption('main', 'EditorWindow', 'font-size'), + idleConf.GetOption('main', 'EditorWindow', + 'font-size', type='int'), fontWeight)) text_frame.pack(side=LEFT, fill=BOTH, expand=1) text.pack(side=TOP, fill=BOTH, expand=1) @@ -763,7 +764,8 @@ if idleConf.GetOption('main','EditorWindow','font-bold',type='bool'): fontWeight='bold' self.text.config(font=(idleConf.GetOption('main','EditorWindow','font'), - idleConf.GetOption('main','EditorWindow','font-size'), + idleConf.GetOption('main','EditorWindow','font-size', + type='int'), fontWeight)) def RemoveKeybindings(self): diff --git a/Lib/idlelib/FormatParagraph.py b/Lib/idlelib/FormatParagraph.py --- a/Lib/idlelib/FormatParagraph.py +++ b/Lib/idlelib/FormatParagraph.py @@ -32,7 +32,8 @@ self.editwin = None def format_paragraph_event(self, event): - maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph')) + maxformatwidth = int(idleConf.GetOption('main','FormatParagraph', + 'paragraph', type='int')) text = self.editwin.text first, last = self.editwin.get_selection_indices() if first and last: diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -947,7 +947,7 @@ self.listFontName.select_anchor(currentFontIndex) ##font size dropdown fontSize=idleConf.GetOption('main','EditorWindow','font-size', - default='10') + type='int', default='10') self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14', '16','18','20','22'),fontSize ) ##fontWeight @@ -1033,10 +1033,13 @@ self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave', default=0, type='bool')) #initial window size - self.winWidth.set(idleConf.GetOption('main','EditorWindow','width')) - self.winHeight.set(idleConf.GetOption('main','EditorWindow','height')) + self.winWidth.set(idleConf.GetOption('main','EditorWindow','width', + type='int')) + self.winHeight.set(idleConf.GetOption('main','EditorWindow','height', + type='int')) #initial paragraph reformat size - self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph')) + self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph', + type='int')) # default source encoding self.encoding.set(idleConf.GetOption('main', 'EditorWindow', 'encoding', default='none')) diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -237,24 +237,39 @@ printed to stderr. """ - if self.userCfg[configType].has_option(section,option): - return self.userCfg[configType].Get(section, option, - type=type, raw=raw) - elif self.defaultCfg[configType].has_option(section,option): - return self.defaultCfg[configType].Get(section, option, - type=type, raw=raw) - else: #returning default, print warning - if warn_on_default: - warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' - ' problem retrieving configuration option %r\n' - ' from section %r.\n' - ' returning default value: %r\n' % - (option, section, default)) - try: - sys.stderr.write(warning) - except IOError: - pass - return default + try: + if self.userCfg[configType].has_option(section,option): + return self.userCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' invalid %r value for configuration option %r\n' + ' from section %r: %r\n' % + (type, option, section, + self.userCfg[configType].Get(section, option, + raw=raw))) + try: + sys.stderr.write(warning) + except IOError: + pass + try: + if self.defaultCfg[configType].has_option(section,option): + return self.defaultCfg[configType].Get(section, option, + type=type, raw=raw) + except ValueError: + pass + #returning default, print warning + if warn_on_default: + warning = ('\n Warning: configHandler.py - IdleConf.GetOption -\n' + ' problem retrieving configuration option %r\n' + ' from section %r.\n' + ' returning default value: %r\n' % + (option, section, default)) + try: + sys.stderr.write(warning) + except IOError: + pass + return default def SetOption(self, configType, section, option, value): """In user's config file, set section's option to value. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 16:30:36 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 16:30:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Fix_markup_warning?= Message-ID: <3YVPXX0q6NzRm8@mail.python.org> http://hg.python.org/peps/rev/0e6d9841f759 changeset: 4634:0e6d9841f759 user: Andrew Svetlov date: Mon Dec 24 17:30:27 2012 +0200 summary: Fix markup warning files: pep-3156.txt | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pep-3156.txt b/pep-3156.txt --- a/pep-3156.txt +++ b/pep-3156.txt @@ -159,8 +159,8 @@ This means, in particular: - No more calls scheduled with ``call_later()``, - ``call_repeatedly()``, ``call_soon()``, or - ``call_soon_threadsafe()``, except for cancelled calls. + ``call_repeatedly()``, ``call_soon()``, or + ``call_soon_threadsafe()``, except for cancelled calls. - No more registered file descriptors. It is up to the registering party to unregister a file descriptor when it is closed. -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Mon Dec 24 17:33:49 2012 From: python-checkins at python.org (mark.dickinson) Date: Mon, 24 Dec 2012 17:33:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzEzODYz?= =?utf-8?q?=3A_fix_incorrect_=2Epyc_timestamps_on_Windows_/_NTFS_=28appare?= =?utf-8?q?ntly_due?= Message-ID: <3YVQxT2vPjzRnZ@mail.python.org> http://hg.python.org/cpython/rev/002d5f3b240d changeset: 81013:002d5f3b240d branch: 2.7 user: Mark Dickinson date: Mon Dec 24 16:33:18 2012 +0000 summary: Issue #13863: fix incorrect .pyc timestamps on Windows / NTFS (apparently due to buggy fstat) files: Lib/test/test_import.py | 41 ++++++++++++++++++++++ Misc/NEWS | 4 ++ Python/import.c | 52 +++++++++++++++++++++++++--- 3 files changed, 91 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -5,6 +5,7 @@ import py_compile import random import stat +import struct import sys import unittest import textwrap @@ -350,6 +351,46 @@ del sys.path[0] remove_files(TESTFN) + def test_pyc_mtime(self): + # Test for issue #13863: .pyc timestamp sometimes incorrect on Windows. + sys.path.insert(0, os.curdir) + try: + # Jan 1, 2012; Jul 1, 2012. + mtimes = 1325376000, 1341100800 + + # Different names to avoid running into import caching. + tails = "spam", "eggs" + for mtime, tail in zip(mtimes, tails): + module = TESTFN + tail + source = module + ".py" + compiled = source + ('c' if __debug__ else 'o') + + # Create a new Python file with the given mtime. + with open(source, 'w') as f: + f.write("# Just testing\nx=1, 2, 3\n") + os.utime(source, (mtime, mtime)) + + # Generate the .pyc/o file; if it couldn't be created + # for some reason, skip the test. + m = __import__(module) + if not os.path.exists(compiled): + unlink(source) + self.skipTest("Couldn't create .pyc/.pyo file.") + + # Actual modification time of .py file. + mtime1 = int(os.stat(source).st_mtime) & 0xffffffff + + # mtime that was encoded in the .pyc file. + with open(compiled, 'rb') as f: + mtime2 = struct.unpack('st_mtime; #ifdef MS_WINDOWS /* since Windows uses different permissions */ mode_t mode = srcstat->st_mode & ~S_IEXEC; /* Issue #6074: We ensure user write access, so we can delete it later @@ -993,6 +992,38 @@ return 1; } +#ifdef MS_WINDOWS + +/* Seconds between 1.1.1601 and 1.1.1970 */ +static __int64 secs_between_epochs = 11644473600; + +/* Get mtime from file pointer. */ + +static time_t +win32_mtime(FILE *fp, char *pathname) +{ + __int64 filetime; + HANDLE fh; + BY_HANDLE_FILE_INFORMATION file_information; + + fh = (HANDLE)_get_osfhandle(fileno(fp)); + if (fh == INVALID_HANDLE_VALUE || + !GetFileInformationByHandle(fh, &file_information)) { + PyErr_Format(PyExc_RuntimeError, + "unable to get file status from '%s'", + pathname); + return -1; + } + /* filetime represents the number of 100ns intervals since + 1.1.1601 (UTC). Convert to seconds since 1.1.1970 (UTC). */ + filetime = (__int64)file_information.ftLastWriteTime.dwHighDateTime << 32 | + file_information.ftLastWriteTime.dwLowDateTime; + return filetime / 10000000 - secs_between_epochs; +} + +#endif /* #ifdef MS_WINDOWS */ + + /* Load a source module from a given file and return its module object WITH INCREMENTED REFERENCE COUNT. If there's a matching byte-compiled file, use that instead. */ @@ -1006,6 +1037,7 @@ char *cpathname; PyCodeObject *co = NULL; PyObject *m; + time_t mtime; if (fstat(fileno(fp), &st) != 0) { PyErr_Format(PyExc_RuntimeError, @@ -1013,13 +1045,21 @@ pathname); return NULL; } - if (sizeof st.st_mtime > 4) { + +#ifdef MS_WINDOWS + mtime = win32_mtime(fp, pathname); + if (mtime == (time_t)-1 && PyErr_Occurred()) + return NULL; +#else + mtime = st.st_mtime; +#endif + if (sizeof mtime > 4) { /* Python's .pyc timestamp handling presumes that the timestamp fits in 4 bytes. Since the code only does an equality comparison, ordering is not important and we can safely ignore the higher bits (collisions are extremely unlikely). */ - st.st_mtime &= 0xFFFFFFFF; + mtime &= 0xFFFFFFFF; } buf = PyMem_MALLOC(MAXPATHLEN+1); if (buf == NULL) { @@ -1028,7 +1068,7 @@ cpathname = make_compiled_pathname(pathname, buf, (size_t)MAXPATHLEN + 1); if (cpathname != NULL && - (fpc = check_compiled_module(pathname, st.st_mtime, cpathname))) { + (fpc = check_compiled_module(pathname, mtime, cpathname))) { co = read_compiled_module(cpathname, fpc); fclose(fpc); if (co == NULL) @@ -1053,7 +1093,7 @@ if (b < 0) goto error_exit; if (!b) - write_compiled_module(co, cpathname, &st); + write_compiled_module(co, cpathname, &st, mtime); } } m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 17:44:47 2012 From: python-checkins at python.org (brian.curtin) Date: Mon, 24 Dec 2012 17:44:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_=2314470=2E_Remove_men?= =?utf-8?q?tions_of_w9xpopen_on_old_versions_of_Visual_Studio=2E?= Message-ID: <3YVRB70DF1zRcp@mail.python.org> http://hg.python.org/cpython/rev/deee9f0a4b98 changeset: 81014:deee9f0a4b98 parent: 81011:a7c9869a5114 user: Brian Curtin date: Mon Dec 24 10:44:31 2012 -0600 summary: Fix #14470. Remove mentions of w9xpopen on old versions of Visual Studio. files: PC/VC6/pcbuild.dsw | 15 +- PC/VC6/w9xpopen.dsp | 97 ---- PC/VS7.1/pcbuild.sln | 4 - PC/VS7.1/python.iss | 1 - PC/VS7.1/python20.wse | 5 - PC/VS7.1/w9xpopen.vcproj | 121 ----- PC/VS8.0/pcbuild.sln | 5 - PC/VS8.0/w9xpopen.vcproj | 576 --------------------------- PC/VS9.0/pcbuild.sln | 5 - PC/VS9.0/w9xpopen.vcproj | 576 --------------------------- 10 files changed, 1 insertions(+), 1404 deletions(-) diff --git a/PC/VC6/pcbuild.dsw b/PC/VC6/pcbuild.dsw --- a/PC/VC6/pcbuild.dsw +++ b/PC/VC6/pcbuild.dsw @@ -114,7 +114,6 @@ Project_Dep_Name python End Project Dependency Begin Project Dependency - Project_Dep_Name w9xpopen End Project Dependency }}} @@ -262,19 +261,7 @@ End Project Dependency }}} -############################################################################### - -Project: "w9xpopen"=".\w9xpopen.dsp" - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### +############################################################################## Project: "winsound"=".\winsound.dsp" - Package Owner=<4> diff --git a/PC/VC6/w9xpopen.dsp b/PC/VC6/w9xpopen.dsp deleted file mode 100644 --- a/PC/VC6/w9xpopen.dsp +++ /dev/null @@ -1,97 +0,0 @@ -# Microsoft Developer Studio Project File - Name="w9xpopen" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=w9xpopen - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "w9xpopen.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "w9xpopen.mak" CFG="w9xpopen - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "w9xpopen - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "w9xpopen - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "w9xpopen - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "." -# PROP Intermediate_Dir "x86-temp-release\w9xpopen" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0xc09 /d "NDEBUG" -# ADD RSC /l 0xc09 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 user32.lib /nologo /machine:I386 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "w9xpopen - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "." -# PROP Intermediate_Dir "x86-temp-debug\w9xpopen" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0xc09 /d "_DEBUG" -# ADD RSC /l 0xc09 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 user32.lib /nologo /debug /machine:I386 /out:"./w9xpopen_d.exe" /pdbtype:sept -# SUBTRACT LINK32 /pdb:none - -!ENDIF - -# Begin Target - -# Name "w9xpopen - Win32 Release" -# Name "w9xpopen - Win32 Debug" -# Begin Source File - -SOURCE=..\w9xpopen.c -# End Source File -# End Target -# End Project diff --git a/PC/VS7.1/pcbuild.sln b/PC/VS7.1/pcbuild.sln --- a/PC/VS7.1/pcbuild.sln +++ b/PC/VS7.1/pcbuild.sln @@ -61,10 +61,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcproj", "{51F35FAE-FB92-4B2C-9187-1542C065AD77}" ProjectSection(ProjectDependencies) = postProject {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} diff --git a/PC/VS7.1/python.iss b/PC/VS7.1/python.iss --- a/PC/VS7.1/python.iss +++ b/PC/VS7.1/python.iss @@ -111,7 +111,6 @@ Source: python.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main Source: pythonw.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main -Source: w9xpopen.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main Source: DLLs\tcl83.dll; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: tk diff --git a/PC/VS7.1/python20.wse b/PC/VS7.1/python20.wse --- a/PC/VS7.1/python20.wse +++ b/PC/VS7.1/python20.wse @@ -1702,11 +1702,6 @@ Destination=%MAINDIR%\pythonw.exe Flags=0000000000000010 end -item: Install File - Source=.\w9xpopen.exe - Destination=%MAINDIR%\w9xpopen.exe - Flags=0000000000000010 -end item: Remark end item: Remark diff --git a/PC/VS7.1/w9xpopen.vcproj b/PC/VS7.1/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS7.1/w9xpopen.vcproj +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PC/VS8.0/pcbuild.sln b/PC/VS8.0/pcbuild.sln --- a/PC/VS8.0/pcbuild.sln +++ b/PC/VS8.0/pcbuild.sln @@ -20,11 +20,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}" diff --git a/PC/VS8.0/w9xpopen.vcproj b/PC/VS8.0/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS8.0/w9xpopen.vcproj +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PC/VS9.0/pcbuild.sln b/PC/VS9.0/pcbuild.sln --- a/PC/VS9.0/pcbuild.sln +++ b/PC/VS9.0/pcbuild.sln @@ -20,11 +20,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}" diff --git a/PC/VS9.0/w9xpopen.vcproj b/PC/VS9.0/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS9.0/w9xpopen.vcproj +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- Repository URL: http://hg.python.org/cpython From brian at python.org Mon Dec 24 18:02:27 2012 From: brian at python.org (Brian Curtin) Date: Mon, 24 Dec 2012 11:02:27 -0600 Subject: [Python-checkins] [Python-Dev] cpython: Fix #14470. Remove w9xpopen per PEP 11. In-Reply-To: References: <3YTzS91KzGzRgT@mail.python.org> Message-ID: On Mon, Dec 24, 2012 at 2:36 AM, Andrew Svetlov wrote: > You missed artifacts in ./PC/VC6 ./PC/VS7.1 ./PC/VS8.0 ./PC/VS9.0 Fixed in http://hg.python.org/cpython/rev/deee9f0a4b98 Also reported http://bugs.python.org/issue16769 about removing some those directories because they are pretty much useless. From python-checkins at python.org Mon Dec 24 18:54:28 2012 From: python-checkins at python.org (benjamin.peterson) Date: Mon, 24 Dec 2012 18:54:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_improve_tracing_performanc?= =?utf-8?q?e_when_f=5Ftrace_is_NULL_=28closes_=2316672=29?= Message-ID: <3YVSkX3sQszRmG@mail.python.org> http://hg.python.org/cpython/rev/1fb26db7d719 changeset: 81015:1fb26db7d719 parent: 81011:a7c9869a5114 user: Benjamin Peterson date: Mon Dec 24 11:53:30 2012 -0600 summary: improve tracing performance when f_trace is NULL (closes #16672) Patch by Xavier de Gaye. files: Misc/NEWS | 2 ++ Python/ceval.c | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #16672: Improve performance tracing performance + - Issue #14470: Remove w9xpopen support per PEP 11. - Issue #9856: Replace deprecation warning with raising TypeError diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1277,7 +1277,8 @@ /* line-by-line tracing support */ if (_Py_TracingPossible && - tstate->c_tracefunc != NULL && !tstate->tracing) { + tstate->c_tracefunc != NULL && !tstate->tracing && + f->f_trace != NULL) { int err; /* see maybe_call_line_trace for expository comments */ @@ -3008,7 +3009,7 @@ /* Log traceback info. */ PyTraceBack_Here(f); - if (tstate->c_tracefunc != NULL) + if (tstate->c_tracefunc != NULL && f->f_trace != NULL) call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, f); fast_block_end: @@ -3127,7 +3128,7 @@ } if (tstate->use_tracing) { - if (tstate->c_tracefunc) { + if (tstate->c_tracefunc && f->f_trace != NULL) { if (why == WHY_RETURN || why == WHY_YIELD) { if (call_trace(tstate->c_tracefunc, tstate->c_traceobj, f, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 18:54:30 2012 From: python-checkins at python.org (benjamin.peterson) Date: Mon, 24 Dec 2012 18:54:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3YVSkZ2m2DzRmG@mail.python.org> http://hg.python.org/cpython/rev/c8a55ac9d15b changeset: 81016:c8a55ac9d15b parent: 81015:1fb26db7d719 parent: 81014:deee9f0a4b98 user: Benjamin Peterson date: Mon Dec 24 11:54:13 2012 -0600 summary: merge heads files: PC/VC6/pcbuild.dsw | 15 +- PC/VC6/w9xpopen.dsp | 97 ---- PC/VS7.1/pcbuild.sln | 4 - PC/VS7.1/python.iss | 1 - PC/VS7.1/python20.wse | 5 - PC/VS7.1/w9xpopen.vcproj | 121 ----- PC/VS8.0/pcbuild.sln | 5 - PC/VS8.0/w9xpopen.vcproj | 576 --------------------------- PC/VS9.0/pcbuild.sln | 5 - PC/VS9.0/w9xpopen.vcproj | 576 --------------------------- 10 files changed, 1 insertions(+), 1404 deletions(-) diff --git a/PC/VC6/pcbuild.dsw b/PC/VC6/pcbuild.dsw --- a/PC/VC6/pcbuild.dsw +++ b/PC/VC6/pcbuild.dsw @@ -114,7 +114,6 @@ Project_Dep_Name python End Project Dependency Begin Project Dependency - Project_Dep_Name w9xpopen End Project Dependency }}} @@ -262,19 +261,7 @@ End Project Dependency }}} -############################################################################### - -Project: "w9xpopen"=".\w9xpopen.dsp" - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### +############################################################################## Project: "winsound"=".\winsound.dsp" - Package Owner=<4> diff --git a/PC/VC6/w9xpopen.dsp b/PC/VC6/w9xpopen.dsp deleted file mode 100644 --- a/PC/VC6/w9xpopen.dsp +++ /dev/null @@ -1,97 +0,0 @@ -# Microsoft Developer Studio Project File - Name="w9xpopen" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=w9xpopen - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "w9xpopen.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "w9xpopen.mak" CFG="w9xpopen - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "w9xpopen - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "w9xpopen - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "w9xpopen - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "." -# PROP Intermediate_Dir "x86-temp-release\w9xpopen" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0xc09 /d "NDEBUG" -# ADD RSC /l 0xc09 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 user32.lib /nologo /machine:I386 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "w9xpopen - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "." -# PROP Intermediate_Dir "x86-temp-debug\w9xpopen" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0xc09 /d "_DEBUG" -# ADD RSC /l 0xc09 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 user32.lib /nologo /debug /machine:I386 /out:"./w9xpopen_d.exe" /pdbtype:sept -# SUBTRACT LINK32 /pdb:none - -!ENDIF - -# Begin Target - -# Name "w9xpopen - Win32 Release" -# Name "w9xpopen - Win32 Debug" -# Begin Source File - -SOURCE=..\w9xpopen.c -# End Source File -# End Target -# End Project diff --git a/PC/VS7.1/pcbuild.sln b/PC/VS7.1/pcbuild.sln --- a/PC/VS7.1/pcbuild.sln +++ b/PC/VS7.1/pcbuild.sln @@ -61,10 +61,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcproj", "{51F35FAE-FB92-4B2C-9187-1542C065AD77}" ProjectSection(ProjectDependencies) = postProject {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} diff --git a/PC/VS7.1/python.iss b/PC/VS7.1/python.iss --- a/PC/VS7.1/python.iss +++ b/PC/VS7.1/python.iss @@ -111,7 +111,6 @@ Source: python.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main Source: pythonw.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main -Source: w9xpopen.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main Source: DLLs\tcl83.dll; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: tk diff --git a/PC/VS7.1/python20.wse b/PC/VS7.1/python20.wse --- a/PC/VS7.1/python20.wse +++ b/PC/VS7.1/python20.wse @@ -1702,11 +1702,6 @@ Destination=%MAINDIR%\pythonw.exe Flags=0000000000000010 end -item: Install File - Source=.\w9xpopen.exe - Destination=%MAINDIR%\w9xpopen.exe - Flags=0000000000000010 -end item: Remark end item: Remark diff --git a/PC/VS7.1/w9xpopen.vcproj b/PC/VS7.1/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS7.1/w9xpopen.vcproj +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PC/VS8.0/pcbuild.sln b/PC/VS8.0/pcbuild.sln --- a/PC/VS8.0/pcbuild.sln +++ b/PC/VS8.0/pcbuild.sln @@ -20,11 +20,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}" diff --git a/PC/VS8.0/w9xpopen.vcproj b/PC/VS8.0/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS8.0/w9xpopen.vcproj +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PC/VS9.0/pcbuild.sln b/PC/VS9.0/pcbuild.sln --- a/PC/VS9.0/pcbuild.sln +++ b/PC/VS9.0/pcbuild.sln @@ -20,11 +20,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}" diff --git a/PC/VS9.0/w9xpopen.vcproj b/PC/VS9.0/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS9.0/w9xpopen.vcproj +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 19:00:16 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 19:00:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Use_OESeeror_instead_of_os?= =?utf-8?b?LmVycm9yICgjMTY3MjAp?= Message-ID: <3YVSsD55GszRnt@mail.python.org> http://hg.python.org/cpython/rev/6cfe2982de42 changeset: 81017:6cfe2982de42 parent: 81011:a7c9869a5114 user: Andrew Svetlov date: Mon Dec 24 19:58:48 2012 +0200 summary: Use OESeeror instead of os.error (#16720) Patch by Serhiy Storchaka. files: Lib/cgi.py | 2 +- Lib/os.py | 14 +++++++------- Lib/test/test_bytes.py | 2 +- Lib/test/test_os.py | 12 ++++++------ Lib/test/test_pty.py | 2 +- Tools/freeze/bkfile.py | 4 ++-- Tools/freeze/freeze.py | 2 +- Tools/scripts/byext.py | 2 +- Tools/scripts/byteyears.py | 2 +- Tools/scripts/checkpyc.py | 4 ++-- Tools/scripts/copytime.py | 4 ++-- Tools/scripts/finddiv.py | 2 +- Tools/scripts/findlinksto.py | 2 +- Tools/scripts/fixcid.py | 8 ++++---- Tools/scripts/ftpmirror.py | 20 ++++++++++---------- Tools/scripts/linktree.py | 6 +++--- Tools/scripts/pathfix.py | 10 +++++----- Tools/scripts/pindent.py | 6 +++--- Tools/scripts/treesync.py | 2 +- Tools/scripts/untabify.py | 4 ++-- Tools/scripts/which.py | 2 +- 21 files changed, 56 insertions(+), 56 deletions(-) diff --git a/Lib/cgi.py b/Lib/cgi.py --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -950,7 +950,7 @@ try: pwd = os.getcwd() except OSError as msg: - print("os.error:", html.escape(str(msg))) + print("OSError:", html.escape(str(msg))) else: print(html.escape(pwd)) print() diff --git a/Lib/os.py b/Lib/os.py --- a/Lib/os.py +++ b/Lib/os.py @@ -275,7 +275,7 @@ while head and tail: try: rmdir(head) - except error: + except OSrror: break head, tail = path.split(head) @@ -302,7 +302,7 @@ if head and tail: try: removedirs(head) - except error: + except OSError: pass __all__.extend(["makedirs", "removedirs", "renames"]) @@ -372,10 +372,10 @@ # minor reason when (say) a thousand readable directories are still # left to visit. That logic is copied here. try: - # Note that listdir and error are globals in this module due + # Note that listdir is global in this module due # to earlier import-*. names = listdir(top) - except error as err: + except OSError as err: if onerror is not None: onerror(err) return @@ -477,7 +477,7 @@ try: orig_st = stat(name, dir_fd=topfd, follow_symlinks=follow_symlinks) dirfd = open(name, O_RDONLY, dir_fd=topfd) - except error as err: + except OSError as err: if onerror is not None: onerror(err) return @@ -572,7 +572,7 @@ fullname = path.join(dir, file) try: exec_func(fullname, *argrest) - except error as e: + except OSError as e: last_exc = e tb = sys.exc_info()[2] if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR @@ -830,7 +830,7 @@ elif WIFEXITED(sts): return WEXITSTATUS(sts) else: - raise error("Not stopped, signaled or exited???") + raise OSError("Not stopped, signaled or exited???") def spawnv(mode, file, args): """spawnv(mode, file, args) -> integer 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 @@ -773,7 +773,7 @@ finally: try: os.remove(tfn) - except os.error: + except OSError: pass def test_reverse(self): diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1190,31 +1190,31 @@ if hasattr(os, 'setuid'): def test_setuid(self): if os.getuid() != 0: - self.assertRaises(os.error, os.setuid, 0) + self.assertRaises(OSError, os.setuid, 0) self.assertRaises(OverflowError, os.setuid, 1<<32) if hasattr(os, 'setgid'): def test_setgid(self): if os.getuid() != 0: - self.assertRaises(os.error, os.setgid, 0) + self.assertRaises(OSError, os.setgid, 0) self.assertRaises(OverflowError, os.setgid, 1<<32) if hasattr(os, 'seteuid'): def test_seteuid(self): if os.getuid() != 0: - self.assertRaises(os.error, os.seteuid, 0) + self.assertRaises(OSError, os.seteuid, 0) self.assertRaises(OverflowError, os.seteuid, 1<<32) if hasattr(os, 'setegid'): def test_setegid(self): if os.getuid() != 0: - self.assertRaises(os.error, os.setegid, 0) + self.assertRaises(OSError, os.setegid, 0) self.assertRaises(OverflowError, os.setegid, 1<<32) if hasattr(os, 'setreuid'): def test_setreuid(self): if os.getuid() != 0: - self.assertRaises(os.error, os.setreuid, 0, 0) + self.assertRaises(OSError, os.setreuid, 0, 0) self.assertRaises(OverflowError, os.setreuid, 1<<32, 0) self.assertRaises(OverflowError, os.setreuid, 0, 1<<32) @@ -1228,7 +1228,7 @@ if hasattr(os, 'setregid'): def test_setregid(self): if os.getuid() != 0: - self.assertRaises(os.error, os.setregid, 0, 0) + self.assertRaises(OSError, os.setregid, 0, 0) self.assertRaises(OverflowError, os.setregid, 1<<32, 0) self.assertRaises(OverflowError, os.setregid, 0, 1<<32) diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -187,7 +187,7 @@ ##debug("Reading from master_fd now that the child has exited") ##try: ## s1 = os.read(master_fd, 1024) - ##except os.error: + ##except OSError: ## pass ##else: ## raise TestFailed("Read from master_fd did not raise exception") diff --git a/Tools/freeze/bkfile.py b/Tools/freeze/bkfile.py --- a/Tools/freeze/bkfile.py +++ b/Tools/freeze/bkfile.py @@ -7,11 +7,11 @@ self.__backup = file + '~' try: os.unlink(self.__backup) - except os.error: + except OSError: pass try: os.rename(file, self.__backup) - except os.error: + except OSError: self.__backup = None self.__file = _orig_open(file, mode, bufsize) self.closed = self.__file.closed diff --git a/Tools/freeze/freeze.py b/Tools/freeze/freeze.py --- a/Tools/freeze/freeze.py +++ b/Tools/freeze/freeze.py @@ -311,7 +311,7 @@ try: os.mkdir(odir) print("Created output directory", odir) - except os.error as msg: + except OSError as msg: usage('%s: mkdir failed (%s)' % (odir, str(msg))) base = '' if odir: diff --git a/Tools/scripts/byext.py b/Tools/scripts/byext.py --- a/Tools/scripts/byext.py +++ b/Tools/scripts/byext.py @@ -25,7 +25,7 @@ self.addstats("", "dirs", 1) try: names = os.listdir(dir) - except os.error as err: + except OSError as err: sys.stderr.write("Can't list %s: %s\n" % (dir, err)) self.addstats("", "unlistable", 1) return diff --git a/Tools/scripts/byteyears.py b/Tools/scripts/byteyears.py --- a/Tools/scripts/byteyears.py +++ b/Tools/scripts/byteyears.py @@ -43,7 +43,7 @@ for filename in sys.argv[1:]: try: st = statfunc(filename) - except os.error as msg: + except OSError as msg: sys.stderr.write("can't stat %r: %r\n" % (filename, msg)) status = 1 st = () diff --git a/Tools/scripts/checkpyc.py b/Tools/scripts/checkpyc.py --- a/Tools/scripts/checkpyc.py +++ b/Tools/scripts/checkpyc.py @@ -24,7 +24,7 @@ for dirname in sys.path: try: names = os.listdir(dirname) - except os.error: + except OSError: print('Cannot list directory', repr(dirname)) continue if not silent: @@ -34,7 +34,7 @@ name = os.path.join(dirname, name) try: st = os.stat(name) - except os.error: + except OSError: print('Cannot stat', repr(name)) continue if verbose: diff --git a/Tools/scripts/copytime.py b/Tools/scripts/copytime.py --- a/Tools/scripts/copytime.py +++ b/Tools/scripts/copytime.py @@ -13,12 +13,12 @@ file1, file2 = sys.argv[1], sys.argv[2] try: stat1 = os.stat(file1) - except os.error: + except OSError: sys.stderr.write(file1 + ': cannot stat\n') sys.exit(1) try: os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME])) - except os.error: + except OSError: sys.stderr.write(file2 + ': cannot change time\n') sys.exit(2) diff --git a/Tools/scripts/finddiv.py b/Tools/scripts/finddiv.py --- a/Tools/scripts/finddiv.py +++ b/Tools/scripts/finddiv.py @@ -70,7 +70,7 @@ def processdir(dir, listnames): try: names = os.listdir(dir) - except os.error as msg: + except OSError as msg: sys.stderr.write("Can't list directory: %s\n" % dir) return 1 files = [] diff --git a/Tools/scripts/findlinksto.py b/Tools/scripts/findlinksto.py --- a/Tools/scripts/findlinksto.py +++ b/Tools/scripts/findlinksto.py @@ -36,7 +36,7 @@ linkto = os.readlink(name) if prog.search(linkto) is not None: print(name, '->', linkto) - except os.error: + except OSError: pass if __name__ == '__main__': diff --git a/Tools/scripts/fixcid.py b/Tools/scripts/fixcid.py --- a/Tools/scripts/fixcid.py +++ b/Tools/scripts/fixcid.py @@ -97,7 +97,7 @@ bad = 0 try: names = os.listdir(dirname) - except os.error as msg: + except OSError as msg: err(dirname + ': cannot list directory: ' + str(msg) + '\n') return 1 names.sort() @@ -175,17 +175,17 @@ try: statbuf = os.stat(filename) os.chmod(tempname, statbuf[ST_MODE] & 0o7777) - except os.error as msg: + except OSError as msg: err(tempname + ': warning: chmod failed (' + str(msg) + ')\n') # Then make a backup of the original file as filename~ try: os.rename(filename, filename + '~') - except os.error as msg: + except OSError as msg: err(filename + ': warning: backup failed (' + str(msg) + ')\n') # Now move the temp file to the original file try: os.rename(tempname, filename) - except os.error as msg: + except OSError as msg: err(filename + ': rename failed (' + str(msg) + ')\n') return 1 # Return success diff --git a/Tools/scripts/ftpmirror.py b/Tools/scripts/ftpmirror.py --- a/Tools/scripts/ftpmirror.py +++ b/Tools/scripts/ftpmirror.py @@ -108,7 +108,7 @@ if verbose: print('Creating local directory', repr(localdir)) try: makedir(localdir) - except os.error as msg: + except OSError as msg: print("Failed to establish local directory", repr(localdir)) return infofilename = os.path.join(localdir, '.mirrorinfo') @@ -183,7 +183,7 @@ continue try: os.unlink(tempname) - except os.error: + except OSError: pass if mode[0] == 'l': if verbose: @@ -218,11 +218,11 @@ fp1.close() try: os.unlink(fullname) - except os.error: + except OSError: pass # Ignore the error try: os.rename(tempname, fullname) - except os.error as msg: + except OSError as msg: print("Can't rename %r to %r: %s" % (tempname, fullname, msg)) continue info[filename] = infostuff @@ -255,7 +255,7 @@ try: if not localdir: names = os.listdir(os.curdir) else: names = os.listdir(localdir) - except os.error: + except OSError: names = [] for name in names: if name[0] == '.' or name in info or name in subdirs: @@ -312,7 +312,7 @@ if os.path.isdir(fullname) and not os.path.islink(fullname): try: names = os.listdir(fullname) - except os.error: + except OSError: names = [] ok = 1 for name in names: @@ -322,13 +322,13 @@ return 0 try: os.rmdir(fullname) - except os.error as msg: + except OSError as msg: print("Can't remove local directory %r: %s" % (fullname, msg)) return 0 else: try: os.unlink(fullname) - except os.error as msg: + except OSError as msg: print("Can't remove local file %r: %s" % (fullname, msg)) return 0 return 1 @@ -386,7 +386,7 @@ backup = os.path.join(dir, fname + '~') try: os.unlink(backup) - except os.error: + except OSError: pass fp = open(tempname, 'w') fp.write('{\n') @@ -396,7 +396,7 @@ fp.close() try: os.rename(filename, backup) - except os.error: + except OSError: pass os.rename(tempname, filename) diff --git a/Tools/scripts/linktree.py b/Tools/scripts/linktree.py --- a/Tools/scripts/linktree.py +++ b/Tools/scripts/linktree.py @@ -32,13 +32,13 @@ return 1 try: os.mkdir(newtree, 0o777) - except os.error as msg: + except OSError as msg: print(newtree + ': cannot mkdir:', msg) return 1 linkname = os.path.join(newtree, link) try: os.symlink(os.path.join(os.pardir, oldtree), linkname) - except os.error as msg: + except OSError as msg: if not link_may_fail: print(linkname + ': cannot symlink:', msg) return 1 @@ -51,7 +51,7 @@ if debug: print('linknames', (old, new, link)) try: names = os.listdir(old) - except os.error as msg: + except OSError as msg: print(old + ': warning: cannot listdir:', msg) return for name in names: diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py --- a/Tools/scripts/pathfix.py +++ b/Tools/scripts/pathfix.py @@ -73,7 +73,7 @@ bad = 0 try: names = os.listdir(dirname) - except os.error as msg: + except OSError as msg: err('%s: cannot list directory: %r\n' % (dirname, msg)) return 1 names.sort() @@ -131,24 +131,24 @@ mtime = statbuf.st_mtime atime = statbuf.st_atime os.chmod(tempname, statbuf[ST_MODE] & 0o7777) - except os.error as msg: + except OSError as msg: err('%s: warning: chmod failed (%r)\n' % (tempname, msg)) # Then make a backup of the original file as filename~ try: os.rename(filename, filename + '~') - except os.error as msg: + except OSError as msg: err('%s: warning: backup failed (%r)\n' % (filename, msg)) # Now move the temp file to the original file try: os.rename(tempname, filename) - except os.error as msg: + except OSError as msg: err('%s: rename failed (%r)\n' % (filename, msg)) return 1 if preserve_timestamps: if atime and mtime: try: os.utime(filename, (atime, mtime)) - except os.error as msg: + except OSError as msg: err('%s: reset of timestamp failed (%r)\n' % (filename, msg)) return 1 # Return succes diff --git a/Tools/scripts/pindent.py b/Tools/scripts/pindent.py --- a/Tools/scripts/pindent.py +++ b/Tools/scripts/pindent.py @@ -427,7 +427,7 @@ # end if import os try: os.rename(filename, filename + '~') - except os.error: pass + except OSError: pass # end try f = open(filename, 'w') f.write(result) @@ -442,7 +442,7 @@ # end if import os try: os.rename(filename, filename + '~') - except os.error: pass + except OSError: pass # end try f = open(filename, 'w') f.write(result) @@ -457,7 +457,7 @@ # end if import os try: os.rename(filename, filename + '~') - except os.error: pass + except OSError: pass # end try f = open(filename, 'w') f.write(result) diff --git a/Tools/scripts/treesync.py b/Tools/scripts/treesync.py --- a/Tools/scripts/treesync.py +++ b/Tools/scripts/treesync.py @@ -78,7 +78,7 @@ print("creating slave directory", slave) try: os.mkdir(slave) - except os.error as msg: + except OSError as msg: print("can't make slave directory", slave, ":", msg) return else: diff --git a/Tools/scripts/untabify.py b/Tools/scripts/untabify.py --- a/Tools/scripts/untabify.py +++ b/Tools/scripts/untabify.py @@ -39,11 +39,11 @@ backup = filename + "~" try: os.unlink(backup) - except os.error: + except OSError: pass try: os.rename(filename, backup) - except os.error: + except OSError: pass with open(filename, "w", encoding=encoding) as f: f.write(newtext) diff --git a/Tools/scripts/which.py b/Tools/scripts/which.py --- a/Tools/scripts/which.py +++ b/Tools/scripts/which.py @@ -29,7 +29,7 @@ filename = os.path.join(dir, prog) try: st = os.stat(filename) - except os.error: + except OSError: continue if not S_ISREG(st[ST_MODE]): msg(filename + ': not a disk file') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 19:00:18 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 19:00:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3YVSsG4wZtzRph@mail.python.org> http://hg.python.org/cpython/rev/33494e332e67 changeset: 81018:33494e332e67 parent: 81017:6cfe2982de42 parent: 81016:c8a55ac9d15b user: Andrew Svetlov date: Mon Dec 24 20:00:05 2012 +0200 summary: merge heads files: Misc/NEWS | 2 + PC/VC6/pcbuild.dsw | 15 +- PC/VC6/w9xpopen.dsp | 97 ---- PC/VS7.1/pcbuild.sln | 4 - PC/VS7.1/python.iss | 1 - PC/VS7.1/python20.wse | 5 - PC/VS7.1/w9xpopen.vcproj | 121 ----- PC/VS8.0/pcbuild.sln | 5 - PC/VS8.0/w9xpopen.vcproj | 576 --------------------------- PC/VS9.0/pcbuild.sln | 5 - PC/VS9.0/w9xpopen.vcproj | 576 --------------------------- Python/ceval.c | 7 +- 12 files changed, 7 insertions(+), 1407 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #16672: Improve performance tracing performance + - Issue #14470: Remove w9xpopen support per PEP 11. - Issue #9856: Replace deprecation warning with raising TypeError diff --git a/PC/VC6/pcbuild.dsw b/PC/VC6/pcbuild.dsw --- a/PC/VC6/pcbuild.dsw +++ b/PC/VC6/pcbuild.dsw @@ -114,7 +114,6 @@ Project_Dep_Name python End Project Dependency Begin Project Dependency - Project_Dep_Name w9xpopen End Project Dependency }}} @@ -262,19 +261,7 @@ End Project Dependency }}} -############################################################################### - -Project: "w9xpopen"=".\w9xpopen.dsp" - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### +############################################################################## Project: "winsound"=".\winsound.dsp" - Package Owner=<4> diff --git a/PC/VC6/w9xpopen.dsp b/PC/VC6/w9xpopen.dsp deleted file mode 100644 --- a/PC/VC6/w9xpopen.dsp +++ /dev/null @@ -1,97 +0,0 @@ -# Microsoft Developer Studio Project File - Name="w9xpopen" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=w9xpopen - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "w9xpopen.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "w9xpopen.mak" CFG="w9xpopen - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "w9xpopen - Win32 Release" (based on "Win32 (x86) Application") -!MESSAGE "w9xpopen - Win32 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "w9xpopen - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "." -# PROP Intermediate_Dir "x86-temp-release\w9xpopen" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0xc09 /d "NDEBUG" -# ADD RSC /l 0xc09 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 -# ADD LINK32 user32.lib /nologo /machine:I386 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "w9xpopen - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "." -# PROP Intermediate_Dir "x86-temp-debug\w9xpopen" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "Py_BUILD_CORE_MODULE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0xc09 /d "_DEBUG" -# ADD RSC /l 0xc09 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 user32.lib /nologo /debug /machine:I386 /out:"./w9xpopen_d.exe" /pdbtype:sept -# SUBTRACT LINK32 /pdb:none - -!ENDIF - -# Begin Target - -# Name "w9xpopen - Win32 Release" -# Name "w9xpopen - Win32 Debug" -# Begin Source File - -SOURCE=..\w9xpopen.c -# End Source File -# End Target -# End Project diff --git a/PC/VS7.1/pcbuild.sln b/PC/VS7.1/pcbuild.sln --- a/PC/VS7.1/pcbuild.sln +++ b/PC/VS7.1/pcbuild.sln @@ -61,10 +61,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsound", "winsound.vcproj", "{51F35FAE-FB92-4B2C-9187-1542C065AD77}" ProjectSection(ProjectDependencies) = postProject {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} diff --git a/PC/VS7.1/python.iss b/PC/VS7.1/python.iss --- a/PC/VS7.1/python.iss +++ b/PC/VS7.1/python.iss @@ -111,7 +111,6 @@ Source: python.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main Source: pythonw.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main -Source: w9xpopen.exe; DestDir: {app}; CopyMode: alwaysoverwrite; Components: main Source: DLLs\tcl83.dll; DestDir: {app}\DLLs; CopyMode: alwaysoverwrite; Components: tk diff --git a/PC/VS7.1/python20.wse b/PC/VS7.1/python20.wse --- a/PC/VS7.1/python20.wse +++ b/PC/VS7.1/python20.wse @@ -1702,11 +1702,6 @@ Destination=%MAINDIR%\pythonw.exe Flags=0000000000000010 end -item: Install File - Source=.\w9xpopen.exe - Destination=%MAINDIR%\w9xpopen.exe - Flags=0000000000000010 -end item: Remark end item: Remark diff --git a/PC/VS7.1/w9xpopen.vcproj b/PC/VS7.1/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS7.1/w9xpopen.vcproj +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PC/VS8.0/pcbuild.sln b/PC/VS8.0/pcbuild.sln --- a/PC/VS8.0/pcbuild.sln +++ b/PC/VS8.0/pcbuild.sln @@ -20,11 +20,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}" diff --git a/PC/VS8.0/w9xpopen.vcproj b/PC/VS8.0/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS8.0/w9xpopen.vcproj +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/PC/VS9.0/pcbuild.sln b/PC/VS9.0/pcbuild.sln --- a/PC/VS9.0/pcbuild.sln +++ b/PC/VS9.0/pcbuild.sln @@ -20,11 +20,6 @@ {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} = {CF7AC3D1-E2DF-41D2-BEA6-1E2556CDEA26} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w9xpopen", "w9xpopen.vcproj", "{E9E0A1F6-0009-4E8C-B8F8-1B8F5D49A058}" - ProjectSection(ProjectDependencies) = postProject - {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} = {6DE10744-E396-40A5-B4E2-1B69AA7C8D31} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_buildinfo", "make_buildinfo.vcproj", "{C73F0EC1-358B-4177-940F-0846AC8B04CD}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{553EC33E-9816-4996-A660-5D6186A0B0B3}" diff --git a/PC/VS9.0/w9xpopen.vcproj b/PC/VS9.0/w9xpopen.vcproj deleted file mode 100644 --- a/PC/VS9.0/w9xpopen.vcproj +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1277,7 +1277,8 @@ /* line-by-line tracing support */ if (_Py_TracingPossible && - tstate->c_tracefunc != NULL && !tstate->tracing) { + tstate->c_tracefunc != NULL && !tstate->tracing && + f->f_trace != NULL) { int err; /* see maybe_call_line_trace for expository comments */ @@ -3008,7 +3009,7 @@ /* Log traceback info. */ PyTraceBack_Here(f); - if (tstate->c_tracefunc != NULL) + if (tstate->c_tracefunc != NULL && f->f_trace != NULL) call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, f); fast_block_end: @@ -3127,7 +3128,7 @@ } if (tstate->use_tracing) { - if (tstate->c_tracefunc) { + if (tstate->c_tracefunc && f->f_trace != NULL) { if (why == WHY_RETURN || why == WHY_YIELD) { if (call_trace(tstate->c_tracefunc, tstate->c_traceobj, f, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 19:09:40 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 19:09:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Keep_ref_to_EC?= =?utf-8?q?HILD_in_local_scope_=28=2316650=29?= Message-ID: <3YVT4415V6zRmy@mail.python.org> http://hg.python.org/cpython/rev/0cc4fe5634cf changeset: 81019:0cc4fe5634cf branch: 3.2 parent: 81009:ffe091ebd5de user: Andrew Svetlov date: Mon Dec 24 20:06:35 2012 +0200 summary: Keep ref to ECHILD in local scope (#16650) files: Lib/subprocess.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1411,7 +1411,7 @@ def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid, - _WNOHANG=os.WNOHANG, _os_error=os.error): + _WNOHANG=os.WNOHANG, _os_error=os.error, _ECHILD=errno.ECHILD): """Check if child process has terminated. Returns returncode attribute. @@ -1427,7 +1427,7 @@ except _os_error as e: if _deadstate is not None: self.returncode = _deadstate - elif e.errno == errno.ECHILD: + elif e.errno == _ECHILD: # This happens if SIGCLD is set to be ignored or # waiting for child processes has otherwise been # disabled for our process. This child is dead, we -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 19:09:41 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 19:09:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Keep_ref_to_ECHILD_in_local_scope_=28=2316650=29?= Message-ID: <3YVT453h40zRp1@mail.python.org> http://hg.python.org/cpython/rev/0b1a49f99169 changeset: 81020:0b1a49f99169 branch: 3.3 parent: 81010:10656b0975b3 parent: 81019:0cc4fe5634cf user: Andrew Svetlov date: Mon Dec 24 20:06:52 2012 +0200 summary: Keep ref to ECHILD in local scope (#16650) files: Lib/subprocess.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1452,7 +1452,7 @@ def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid, - _WNOHANG=os.WNOHANG, _os_error=os.error): + _WNOHANG=os.WNOHANG, _os_error=os.error, _ECHILD=errno.ECHILD): """Check if child process has terminated. Returns returncode attribute. @@ -1468,7 +1468,7 @@ except _os_error as e: if _deadstate is not None: self.returncode = _deadstate - elif e.errno == errno.ECHILD: + elif e.errno == _ECHILD: # This happens if SIGCLD is set to be ignored or # waiting for child processes has otherwise been # disabled for our process. This child is dead, we -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 19:09:42 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 19:09:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Keep_ref_to_ECHILD_in_local_scope_=28=2316650=29?= Message-ID: <3YVT465yN1zRpG@mail.python.org> http://hg.python.org/cpython/rev/8f30461395b1 changeset: 81021:8f30461395b1 parent: 81018:33494e332e67 parent: 81020:0b1a49f99169 user: Andrew Svetlov date: Mon Dec 24 20:08:53 2012 +0200 summary: Keep ref to ECHILD in local scope (#16650) files: Lib/subprocess.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1412,7 +1412,7 @@ def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid, - _WNOHANG=os.WNOHANG): + _WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD): """Check if child process has terminated. Returns returncode attribute. @@ -1428,7 +1428,7 @@ except OSError as e: if _deadstate is not None: self.returncode = _deadstate - elif e.errno == errno.ECHILD: + elif e.errno == _ECHILD: # This happens if SIGCLD is set to be ignored or # waiting for child processes has otherwise been # disabled for our process. This child is dead, we -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 19:09:44 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 19:09:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Keep_ref_to_EC?= =?utf-8?q?HILD_in_local_scope_=28=2316650=29?= Message-ID: <3YVT481tdMzRpv@mail.python.org> http://hg.python.org/cpython/rev/a963dd401a63 changeset: 81022:a963dd401a63 branch: 2.7 parent: 81013:002d5f3b240d user: Andrew Svetlov date: Mon Dec 24 20:09:27 2012 +0200 summary: Keep ref to ECHILD in local scope (#16650) files: Lib/subprocess.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1292,7 +1292,7 @@ def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid, - _WNOHANG=os.WNOHANG, _os_error=os.error): + _WNOHANG=os.WNOHANG, _os_error=os.error, _ECHILD=errno.ECHILD): """Check if child process has terminated. Returns returncode attribute. @@ -1308,7 +1308,7 @@ except _os_error as e: if _deadstate is not None: self.returncode = _deadstate - if e.errno == errno.ECHILD: + if e.errno == _ECHILD: # This happens if SIGCLD is set to be ignored or # waiting for child processes has otherwise been # disabled for our process. This child is dead, we -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 20:47:34 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 24 Dec 2012 20:47:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_fix_typo_=28=2316720=29?= Message-ID: <3YVWF208wtzRml@mail.python.org> http://hg.python.org/cpython/rev/e2e5181b10f8 changeset: 81023:e2e5181b10f8 parent: 81021:8f30461395b1 user: Andrew Svetlov date: Mon Dec 24 21:47:24 2012 +0200 summary: fix typo (#16720) files: Lib/os.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/os.py b/Lib/os.py --- a/Lib/os.py +++ b/Lib/os.py @@ -275,7 +275,7 @@ while head and tail: try: rmdir(head) - except OSrror: + except OSError: break head, tail = path.split(head) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 23:04:01 2012 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 24 Dec 2012 23:04:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_issue16713?= =?utf-8?q?_-_tel_url_parsing_with_params?= Message-ID: <3YVZGT56f3zNvZ@mail.python.org> http://hg.python.org/cpython/rev/d002a2e46383 changeset: 81024:d002a2e46383 branch: 3.2 parent: 81019:0cc4fe5634cf user: Senthil Kumaran date: Mon Dec 24 14:00:20 2012 -0800 summary: Fix issue16713 - tel url parsing with params files: Lib/test/test_urlparse.py | 29 +++++++++++++++++++++++++++ Lib/urllib/parse.py | 2 +- Misc/NEWS | 3 ++ 3 files changed, 33 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -818,6 +818,35 @@ p2 = urllib.parse.urlsplit('tel:+31641044153') self.assertEqual(p2.scheme, 'tel') self.assertEqual(p2.path, '+31641044153') + # assert the behavior for urlparse + p1 = urllib.parse.urlparse('tel:+31-641044153') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+31-641044153') + p2 = urllib.parse.urlparse('tel:+31641044153') + self.assertEqual(p2.scheme, 'tel') + self.assertEqual(p2.path, '+31641044153') + + def test_telurl_params(self): + p1 = urllib.parse.urlparse('tel:123-4;phone-context=+1-650-516') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '123-4') + self.assertEqual(p1.params, 'phone-context=+1-650-516') + + p1 = urllib.parse.urlparse('tel:+1-201-555-0123') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+1-201-555-0123') + self.assertEqual(p1.params, '') + + p1 = urllib.parse.urlparse('tel:7042;phone-context=example.com') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '7042') + self.assertEqual(p1.params, 'phone-context=example.com') + + p1 = urllib.parse.urlparse('tel:863-1234;phone-context=+1-914-555') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '863-1234') + self.assertEqual(p1.params, 'phone-context=+1-914-555') + def test_main(): support.run_unittest(UrlParseTestCase) diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -46,7 +46,7 @@ 'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh'] uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap', 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', - 'mms', '', 'sftp'] + 'mms', '', 'sftp', 'tel'] # These are not actually used anymore, but should stay for backwards # compatibility. (They are undocumented, but have a public-looking name.) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -182,6 +182,9 @@ - Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. +- Issue #16713: Parsing of 'tel' urls using urlparse separates params from + path. + - Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 23:04:03 2012 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 24 Dec 2012 23:04:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Fix_issue16713_-_tel_url_parsing_with_params?= Message-ID: <3YVZGW0mhPzRp6@mail.python.org> http://hg.python.org/cpython/rev/727f26d1806f changeset: 81025:727f26d1806f branch: 3.3 parent: 81020:0b1a49f99169 parent: 81024:d002a2e46383 user: Senthil Kumaran date: Mon Dec 24 14:01:13 2012 -0800 summary: Fix issue16713 - tel url parsing with params files: Lib/test/test_urlparse.py | 29 +++++++++++++++++++++++++++ Lib/urllib/parse.py | 2 +- Misc/NEWS | 3 ++ 3 files changed, 33 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -818,6 +818,35 @@ p2 = urllib.parse.urlsplit('tel:+31641044153') self.assertEqual(p2.scheme, 'tel') self.assertEqual(p2.path, '+31641044153') + # assert the behavior for urlparse + p1 = urllib.parse.urlparse('tel:+31-641044153') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+31-641044153') + p2 = urllib.parse.urlparse('tel:+31641044153') + self.assertEqual(p2.scheme, 'tel') + self.assertEqual(p2.path, '+31641044153') + + def test_telurl_params(self): + p1 = urllib.parse.urlparse('tel:123-4;phone-context=+1-650-516') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '123-4') + self.assertEqual(p1.params, 'phone-context=+1-650-516') + + p1 = urllib.parse.urlparse('tel:+1-201-555-0123') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+1-201-555-0123') + self.assertEqual(p1.params, '') + + p1 = urllib.parse.urlparse('tel:7042;phone-context=example.com') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '7042') + self.assertEqual(p1.params, 'phone-context=example.com') + + p1 = urllib.parse.urlparse('tel:863-1234;phone-context=+1-914-555') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '863-1234') + self.assertEqual(p1.params, 'phone-context=+1-914-555') + def test_main(): support.run_unittest(UrlParseTestCase) diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -46,7 +46,7 @@ 'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh'] uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap', 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', - 'mms', '', 'sftp'] + 'mms', '', 'sftp', 'tel'] # These are not actually used anymore, but should stay for backwards # compatibility. (They are undocumented, but have a public-looking name.) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -117,6 +117,9 @@ - Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. +- Issue #16713: Parsing of 'tel' urls using urlparse separates params from + path. + - Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 23:04:04 2012 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 24 Dec 2012 23:04:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_issue16713_-_tel_url_parsing_with_params?= Message-ID: <3YVZGX3QVMzRpN@mail.python.org> http://hg.python.org/cpython/rev/e147d5f3c897 changeset: 81026:e147d5f3c897 parent: 81023:e2e5181b10f8 parent: 81025:727f26d1806f user: Senthil Kumaran date: Mon Dec 24 14:01:48 2012 -0800 summary: Fix issue16713 - tel url parsing with params files: Lib/test/test_urlparse.py | 29 +++++++++++++++++++++++++++ Lib/urllib/parse.py | 2 +- Misc/NEWS | 3 ++ 3 files changed, 33 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -818,6 +818,35 @@ p2 = urllib.parse.urlsplit('tel:+31641044153') self.assertEqual(p2.scheme, 'tel') self.assertEqual(p2.path, '+31641044153') + # assert the behavior for urlparse + p1 = urllib.parse.urlparse('tel:+31-641044153') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+31-641044153') + p2 = urllib.parse.urlparse('tel:+31641044153') + self.assertEqual(p2.scheme, 'tel') + self.assertEqual(p2.path, '+31641044153') + + def test_telurl_params(self): + p1 = urllib.parse.urlparse('tel:123-4;phone-context=+1-650-516') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '123-4') + self.assertEqual(p1.params, 'phone-context=+1-650-516') + + p1 = urllib.parse.urlparse('tel:+1-201-555-0123') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+1-201-555-0123') + self.assertEqual(p1.params, '') + + p1 = urllib.parse.urlparse('tel:7042;phone-context=example.com') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '7042') + self.assertEqual(p1.params, 'phone-context=example.com') + + p1 = urllib.parse.urlparse('tel:863-1234;phone-context=+1-914-555') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '863-1234') + self.assertEqual(p1.params, 'phone-context=+1-914-555') + def test_main(): support.run_unittest(UrlParseTestCase) diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -46,7 +46,7 @@ 'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh'] uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap', 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', - 'mms', '', 'sftp'] + 'mms', '', 'sftp', 'tel'] # These are not actually used anymore, but should stay for backwards # compatibility. (They are undocumented, but have a public-looking name.) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -183,6 +183,9 @@ - Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. +- Issue #16713: Parsing of 'tel' urls using urlparse separates params from + path. + - Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 24 23:04:05 2012 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 24 Dec 2012 23:04:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_issue16713?= =?utf-8?q?_-_tel_url_parsing_with_params?= Message-ID: <3YVZGY5qY6zRpf@mail.python.org> http://hg.python.org/cpython/rev/ff0426b5d75e changeset: 81027:ff0426b5d75e branch: 2.7 parent: 81022:a963dd401a63 user: Senthil Kumaran date: Mon Dec 24 13:56:54 2012 -0800 summary: Fix issue16713 - tel url parsing with params files: Lib/test/test_urlparse.py | 33 +++++++++++++++++++++++++++ Lib/urlparse.py | 2 +- Misc/NEWS | 2 + 3 files changed, 36 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -446,10 +446,43 @@ p1 = urlparse.urlsplit('tel:+31-641044153') self.assertEqual(p1.scheme, 'tel') self.assertEqual(p1.path, '+31-641044153') + p2 = urlparse.urlsplit('tel:+31641044153') self.assertEqual(p2.scheme, 'tel') self.assertEqual(p2.path, '+31641044153') + # Assert for urlparse + p1 = urlparse.urlparse('tel:+31-641044153') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+31-641044153') + + p2 = urlparse.urlparse('tel:+31641044153') + self.assertEqual(p2.scheme, 'tel') + self.assertEqual(p2.path, '+31641044153') + + + def test_telurl_params(self): + p1 = urlparse.urlparse('tel:123-4;phone-context=+1-650-516') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '123-4') + self.assertEqual(p1.params, 'phone-context=+1-650-516') + + p1 = urlparse.urlparse('tel:+1-201-555-0123') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '+1-201-555-0123') + self.assertEqual(p1.params, '') + + p1 = urlparse.urlparse('tel:7042;phone-context=example.com') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '7042') + self.assertEqual(p1.params, 'phone-context=example.com') + + p1 = urlparse.urlparse('tel:863-1234;phone-context=+1-914-555') + self.assertEqual(p1.scheme, 'tel') + self.assertEqual(p1.path, '863-1234') + self.assertEqual(p1.params, 'phone-context=+1-914-555') + + def test_attributes_bad_port(self): """Check handling of non-integer ports.""" p = urlparse.urlsplit("http://www.example.net:foo") diff --git a/Lib/urlparse.py b/Lib/urlparse.py --- a/Lib/urlparse.py +++ b/Lib/urlparse.py @@ -42,7 +42,7 @@ 'svn', 'svn+ssh', 'sftp','nfs','git', 'git+ssh'] uses_params = ['ftp', 'hdl', 'prospero', 'http', 'imap', 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', - 'mms', '', 'sftp'] + 'mms', '', 'sftp', 'tel'] # These are not actually used anymore, but should stay for backwards # compatibility. (They are undocumented, but have a public-looking name.) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -164,6 +164,8 @@ Library ------- +- Issue #16713: Fix the parsing of tel url with params using urlparse module. + - Issue #16443: Add docstrings to regular expression match objects. Patch by Anton Kasyanov. -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Tue Dec 25 05:55:07 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 25 Dec 2012 05:55:07 +0100 Subject: [Python-checkins] Daily reference leaks (e147d5f3c897): sum=0 Message-ID: results for e147d5f3c897 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog4SzznO', '-x'] From python-checkins at python.org Tue Dec 25 11:22:02 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 11:22:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Add_test_cover?= =?utf-8?q?age_for_os=2Eremovedirs_=28=2316775=29?= Message-ID: <3YVtf24BmQzRgx@mail.python.org> http://hg.python.org/cpython/rev/c3acc5ead883 changeset: 81028:c3acc5ead883 branch: 3.2 parent: 81024:d002a2e46383 user: Andrew Svetlov date: Tue Dec 25 12:18:09 2012 +0200 summary: Add test coverage for os.removedirs (#16775) files: Lib/test/test_os.py | 46 +++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -634,6 +634,50 @@ os.removedirs(path) + +class RemoveDirsTests(unittest.TestCase): + def setUp(self): + os.makedirs(support.TESTFN) + + def tearDown(self): + support.rmtree(support.TESTFN) + + def test_remove_all(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + os.removedirs(dirb) + self.assertFalse(os.path.exists(dirb)) + self.assertFalse(os.path.exists(dira)) + self.assertFalse(os.path.exists(support.TESTFN)) + + def test_remove_partial(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + with open(os.path.join(dira, 'file.txt'), 'w') as f: + f.write('text') + os.removedirs(dirb) + self.assertFalse(os.path.exists(dirb)) + self.assertTrue(os.path.exists(dira)) + self.assertTrue(os.path.exists(support.TESTFN)) + + def test_remove_nothing(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + with open(os.path.join(dirb, 'file.txt'), 'w') as f: + f.write('text') + with self.assertRaises(OSError): + os.removedirs(dirb) + self.assertTrue(os.path.exists(dirb)) + self.assertTrue(os.path.exists(dira)) + self.assertTrue(os.path.exists(support.TESTFN)) + + class DevNullTests(unittest.TestCase): def test_devnull(self): with open(os.devnull, 'wb') as f: @@ -642,6 +686,7 @@ with open(os.devnull, 'rb') as f: self.assertEqual(f.read(), b'') + class URandomTests(unittest.TestCase): def test_urandom_length(self): self.assertEqual(len(os.urandom(0)), 0) @@ -1310,6 +1355,7 @@ PidTests, LoginTests, LinkTests, + RemoveDirsTests, ) if __name__ == "__main__": -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 11:22:03 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 11:22:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Add_test_coverage_for_os=2Eremovedirs_=28=2316775=29?= Message-ID: <3YVtf36sKVzRpv@mail.python.org> http://hg.python.org/cpython/rev/dbe9413686b3 changeset: 81029:dbe9413686b3 branch: 3.3 parent: 81025:727f26d1806f parent: 81028:c3acc5ead883 user: Andrew Svetlov date: Tue Dec 25 12:20:39 2012 +0200 summary: Add test coverage for os.removedirs (#16775) files: Lib/test/test_os.py | 46 +++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -905,6 +905,50 @@ os.removedirs(path) + +class RemoveDirsTests(unittest.TestCase): + def setUp(self): + os.makedirs(support.TESTFN) + + def tearDown(self): + support.rmtree(support.TESTFN) + + def test_remove_all(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + os.removedirs(dirb) + self.assertFalse(os.path.exists(dirb)) + self.assertFalse(os.path.exists(dira)) + self.assertFalse(os.path.exists(support.TESTFN)) + + def test_remove_partial(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + with open(os.path.join(dira, 'file.txt'), 'w') as f: + f.write('text') + os.removedirs(dirb) + self.assertFalse(os.path.exists(dirb)) + self.assertTrue(os.path.exists(dira)) + self.assertTrue(os.path.exists(support.TESTFN)) + + def test_remove_nothing(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + with open(os.path.join(dirb, 'file.txt'), 'w') as f: + f.write('text') + with self.assertRaises(OSError): + os.removedirs(dirb) + self.assertTrue(os.path.exists(dirb)) + self.assertTrue(os.path.exists(dira)) + self.assertTrue(os.path.exists(support.TESTFN)) + + class DevNullTests(unittest.TestCase): def test_devnull(self): with open(os.devnull, 'wb') as f: @@ -913,6 +957,7 @@ with open(os.devnull, 'rb') as f: self.assertEqual(f.read(), b'') + class URandomTests(unittest.TestCase): def test_urandom_length(self): self.assertEqual(len(os.urandom(0)), 0) @@ -2078,6 +2123,7 @@ ExtendedAttributeTests, Win32DeprecatedBytesAPI, TermsizeTests, + RemoveDirsTests, ) if __name__ == "__main__": -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 11:22:05 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 11:22:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Add_test_coverage_for_os=2Eremovedirs_=28=2316775=29?= Message-ID: <3YVtf528f7zRr0@mail.python.org> http://hg.python.org/cpython/rev/60240ce64789 changeset: 81030:60240ce64789 parent: 81026:e147d5f3c897 parent: 81029:dbe9413686b3 user: Andrew Svetlov date: Tue Dec 25 12:21:49 2012 +0200 summary: Add test coverage for os.removedirs (#16775) files: Lib/test/test_os.py | 46 +++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -905,6 +905,50 @@ os.removedirs(path) + +class RemoveDirsTests(unittest.TestCase): + def setUp(self): + os.makedirs(support.TESTFN) + + def tearDown(self): + support.rmtree(support.TESTFN) + + def test_remove_all(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + os.removedirs(dirb) + self.assertFalse(os.path.exists(dirb)) + self.assertFalse(os.path.exists(dira)) + self.assertFalse(os.path.exists(support.TESTFN)) + + def test_remove_partial(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + with open(os.path.join(dira, 'file.txt'), 'w') as f: + f.write('text') + os.removedirs(dirb) + self.assertFalse(os.path.exists(dirb)) + self.assertTrue(os.path.exists(dira)) + self.assertTrue(os.path.exists(support.TESTFN)) + + def test_remove_nothing(self): + dira = os.path.join(support.TESTFN, 'dira') + os.mkdir(dira) + dirb = os.path.join(dira, 'dirb') + os.mkdir(dirb) + with open(os.path.join(dirb, 'file.txt'), 'w') as f: + f.write('text') + with self.assertRaises(OSError): + os.removedirs(dirb) + self.assertTrue(os.path.exists(dirb)) + self.assertTrue(os.path.exists(dira)) + self.assertTrue(os.path.exists(support.TESTFN)) + + class DevNullTests(unittest.TestCase): def test_devnull(self): with open(os.devnull, 'wb') as f: @@ -913,6 +957,7 @@ with open(os.devnull, 'rb') as f: self.assertEqual(f.read(), b'') + class URandomTests(unittest.TestCase): def test_urandom_length(self): self.assertEqual(len(os.urandom(0)), 0) @@ -2176,6 +2221,7 @@ Win32DeprecatedBytesAPI, TermsizeTests, OSErrorTests, + RemoveDirsTests, ) if __name__ == "__main__": -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 12:32:46 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 12:32:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315422=3A_get_rid_?= =?utf-8?q?of_PyCFunction=5FNew_macro?= Message-ID: <3YVwCf4vWNzRnR@mail.python.org> http://hg.python.org/cpython/rev/3a86a3f1d89a changeset: 81031:3a86a3f1d89a user: Andrew Svetlov date: Tue Dec 25 13:32:35 2012 +0200 summary: Issue #15422: get rid of PyCFunction_New macro files: Include/methodobject.h | 2 +- Misc/NEWS | 3 +++ Modules/_threadmodule.c | 2 +- Objects/descrobject.c | 8 ++++---- Objects/methodobject.c | 20 ++++++-------------- Objects/typeobject.c | 4 ++-- PC/python3.def | 1 + PC/python34stub.def | 1 + Python/codecs.c | 2 +- 9 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Include/methodobject.h b/Include/methodobject.h --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -46,7 +46,7 @@ }; typedef struct PyMethodDef PyMethodDef; -#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) +PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *); PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, PyObject *); diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15422: Get rid of PyCFunction_New macro. Use PyCFunction_NewEx + function (PyCFunction_New func is still present for backward compatibility). + - Issue #16672: Improve performance tracing performance - Issue #14470: Remove w9xpopen support per PEP 11. diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -741,7 +741,7 @@ wr = PyWeakref_NewRef((PyObject *) self, NULL); if (wr == NULL) goto err; - self->wr_callback = PyCFunction_New(&wr_callback_def, wr); + self->wr_callback = PyCFunction_NewEx(&wr_callback_def, wr, NULL); Py_DECREF(wr); if (self->wr_callback == NULL) goto err; diff --git a/Objects/descrobject.c b/Objects/descrobject.c --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -115,7 +115,7 @@ ((PyTypeObject *)type)->tp_name); return NULL; } - return PyCFunction_New(descr->d_method, type); + return PyCFunction_NewEx(descr->d_method, type, NULL); } static PyObject * @@ -125,7 +125,7 @@ if (descr_check((PyDescrObject *)descr, obj, &res)) return res; - return PyCFunction_New(descr->d_method, obj); + return PyCFunction_NewEx(descr->d_method, obj, NULL); } static PyObject * @@ -239,7 +239,7 @@ return NULL; } - func = PyCFunction_New(descr->d_method, self); + func = PyCFunction_NewEx(descr->d_method, self, NULL); if (func == NULL) return NULL; args = PyTuple_GetSlice(args, 1, argc); @@ -292,7 +292,7 @@ return NULL; } - func = PyCFunction_New(descr->d_method, self); + func = PyCFunction_NewEx(descr->d_method, self, NULL); if (func == NULL) return NULL; args = PyTuple_GetSlice(args, 1, argc); diff --git a/Objects/methodobject.c b/Objects/methodobject.c --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -14,6 +14,12 @@ #endif PyObject * +PyCFunction_New(PyMethodDef *ml, PyObject *self) +{ + return PyCFunction_NewEx(ml, self, NULL); +} + +PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module) { PyCFunctionObject *op; @@ -346,17 +352,3 @@ "free PyCFunction", numfree, sizeof(PyCFunction)); } - -/* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(), - but it's part of the API so we need to keep a function around that - existing C extensions can call. -*/ - -#undef PyCFunction_New -PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *); - -PyObject * -PyCFunction_New(PyMethodDef *ml, PyObject *self) -{ - return PyCFunction_NewEx(ml, self, NULL); -} diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3811,7 +3811,7 @@ descr = PyDescr_NewClassMethod(type, meth); } else if (meth->ml_flags & METH_STATIC) { - PyObject *cfunc = PyCFunction_New(meth, (PyObject*)type); + PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL); if (cfunc == NULL) return -1; descr = PyStaticMethod_New(cfunc); @@ -4879,7 +4879,7 @@ if (_PyDict_GetItemId(type->tp_dict, &PyId___new__) != NULL) return 0; - func = PyCFunction_New(tp_new_methoddef, (PyObject *)type); + func = PyCFunction_NewEx(tp_new_methoddef, (PyObject *)type, NULL); if (func == NULL) return -1; if (_PyDict_SetItemId(type->tp_dict, &PyId___new__, func)) { diff --git a/PC/python3.def b/PC/python3.def --- a/PC/python3.def +++ b/PC/python3.def @@ -38,6 +38,7 @@ PyCFunction_GetFlags=python34.PyCFunction_GetFlags PyCFunction_GetFunction=python34.PyCFunction_GetFunction PyCFunction_GetSelf=python34.PyCFunction_GetSelf + PyCFunction_New=python34.PyCFunction_New PyCFunction_NewEx=python34.PyCFunction_NewEx PyCFunction_Type=python34.PyCFunction_Type DATA PyCallIter_New=python34.PyCallIter_New diff --git a/PC/python34stub.def b/PC/python34stub.def --- a/PC/python34stub.def +++ b/PC/python34stub.def @@ -37,6 +37,7 @@ PyCFunction_GetFlags PyCFunction_GetFunction PyCFunction_GetSelf +PyCFunction_New PyCFunction_NewEx PyCFunction_Type PyCallIter_New diff --git a/Python/codecs.c b/Python/codecs.c --- a/Python/codecs.c +++ b/Python/codecs.c @@ -1026,7 +1026,7 @@ if (interp->codec_error_registry) { for (i = 0; i < Py_ARRAY_LENGTH(methods); ++i) { - PyObject *func = PyCFunction_New(&methods[i].def, NULL); + PyObject *func = PyCFunction_NewEx(&methods[i].def, NULL, NULL); int res; if (!func) Py_FatalError("can't initialize codec error registry"); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 13:27:43 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 13:27:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NzY1OiByZW1v?= =?utf-8?q?ve_unused_import=2E?= Message-ID: <3YVxR337PHzRrW@mail.python.org> http://hg.python.org/cpython/rev/f77648af7ff0 changeset: 81032:f77648af7ff0 branch: 2.7 parent: 81027:ff0426b5d75e user: Ezio Melotti date: Tue Dec 25 14:25:47 2012 +0200 summary: #16765: remove unused import. files: Lib/cgi.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/Lib/cgi.py b/Lib/cgi.py --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -37,7 +37,6 @@ from operator import attrgetter import sys import os -import urllib import UserDict import urlparse -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 13:46:29 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 13:46:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NjY2OiBkb2N1?= =?utf-8?q?ment_default_values_for_socket=2Egetaddrinfo_in_the_text_to_cla?= =?utf-8?q?rify?= Message-ID: <3YVxrj6BrPzRlv@mail.python.org> http://hg.python.org/cpython/rev/1e5e7064e872 changeset: 81033:1e5e7064e872 branch: 2.7 user: Ezio Melotti date: Tue Dec 25 14:45:55 2012 +0200 summary: #16666: document default values for socket.getaddrinfo in the text to clarify that it doesn't accept keyword args. files: Doc/library/socket.rst | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -230,7 +230,7 @@ *source_address* was added. -.. function:: getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0) +.. function:: getaddrinfo(host, port[, family[, socktype[, proto[, flags]]]]) Translate the *host*/*port* argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service. @@ -240,12 +240,12 @@ and *port*, you can pass ``NULL`` to the underlying C API. The *family*, *socktype* and *proto* arguments can be optionally specified - in order to narrow the list of addresses returned. Passing zero as a - value for each of these arguments selects the full range of results. + in order to narrow the list of addresses returned. By default, their value + is ``0``, meaning that the full range of results is selected. The *flags* argument can be one or several of the ``AI_*`` constants, - and will influence how results are computed and returned. - For example, :const:`AI_NUMERICHOST` will disable domain name resolution - and will raise an error if *host* is a domain name. + and will influence how results are computed and returned. Its default value + is ``0``. For example, :const:`AI_NUMERICHOST` will disable domain name + resolution and will raise an error if *host* is a domain name. The function returns a list of 5-tuples with the following structure: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 14:06:56 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Tue, 25 Dec 2012 14:06:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogaXNzdWUgIzg3OTM5?= =?utf-8?q?9?= Message-ID: <3YVyJJ0cjpzRnD@mail.python.org> http://hg.python.org/cpython/rev/5be3fa83d436 changeset: 81034:5be3fa83d436 branch: 2.7 user: Kristj?n Valur J?nsson date: Tue Dec 25 13:04:50 2012 +0000 summary: issue #879399 Fix line buffering of socket._fileobject files: Lib/socket.py | 4 +- Lib/test/test_socket.py | 60 ++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Lib/socket.py b/Lib/socket.py --- a/Lib/socket.py +++ b/Lib/socket.py @@ -319,8 +319,8 @@ self._wbuf.append(data) self._wbuf_len += len(data) if (self._wbufsize == 0 or - self._wbufsize == 1 and '\n' in data or - self._wbuf_len >= self._wbufsize): + (self._wbufsize == 1 and '\n' in data) or + (self._wbufsize > 1 and self._wbuf_len >= self._wbufsize)): self.flush() def writelines(self, list): diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -962,8 +962,8 @@ def tearDown(self): self.serv_file.close() self.assertTrue(self.serv_file.closed) + SocketConnectedTest.tearDown(self) self.serv_file = None - SocketConnectedTest.tearDown(self) def clientSetUp(self): SocketConnectedTest.clientSetUp(self) @@ -1151,6 +1151,64 @@ bufsize = 1 # Default-buffered for reading; line-buffered for writing + class SocketMemo(object): + """A wrapper to keep track of sent data, needed to examine write behaviour""" + def __init__(self, sock): + self._sock = sock + self.sent = [] + + def send(self, data, flags=0): + n = self._sock.send(data, flags) + self.sent.append(data[:n]) + return n + + def sendall(self, data, flags=0): + self._sock.sendall(data, flags) + self.sent.append(data) + + def __getattr__(self, attr): + return getattr(self._sock, attr) + + def getsent(self): + return [e.tobytes() if isinstance(e, memoryview) else e for e in self.sent] + + def setUp(self): + FileObjectClassTestCase.setUp(self) + self.serv_file._sock = self.SocketMemo(self.serv_file._sock) + + def testLinebufferedWrite(self): + # Write two lines, in small chunks + msg = MSG.strip() + print >> self.serv_file, msg, + print >> self.serv_file, msg + + # second line: + print >> self.serv_file, msg, + print >> self.serv_file, msg, + print >> self.serv_file, msg + + # third line + print >> self.serv_file, '' + + self.serv_file.flush() + + msg1 = "%s %s\n"%(msg, msg) + msg2 = "%s %s %s\n"%(msg, msg, msg) + msg3 = "\n" + self.assertEqual(self.serv_file._sock.getsent(), [msg1, msg2, msg3]) + + def _testLinebufferedWrite(self): + msg = MSG.strip() + msg1 = "%s %s\n"%(msg, msg) + msg2 = "%s %s %s\n"%(msg, msg, msg) + msg3 = "\n" + l1 = self.cli_file.readline() + self.assertEqual(l1, msg1) + l2 = self.cli_file.readline() + self.assertEqual(l2, msg2) + l3 = self.cli_file.readline() + self.assertEqual(l3, msg3) + class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 14:47:58 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 14:47:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2Njc3OiByZW5h?= =?utf-8?q?me_section_header_and_fix_markup=2E?= Message-ID: <3YVzCf3VdzzRlj@mail.python.org> http://hg.python.org/cpython/rev/a0f6c68ea12f changeset: 81035:a0f6c68ea12f branch: 2.7 user: Ezio Melotti date: Tue Dec 25 15:45:15 2012 +0200 summary: #16677: rename section header and fix markup. files: Doc/reference/expressions.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1339,8 +1339,8 @@ .. _operator-summary: -Summary -======= +Operator precedence +=================== .. index:: pair: operator; precedence @@ -1363,9 +1363,9 @@ +-----------------------------------------------+-------------------------------------+ | :keyword:`and` | Boolean AND | +-----------------------------------------------+-------------------------------------+ -| :keyword:`not` *x* | Boolean NOT | +| :keyword:`not` ``x`` | Boolean NOT | +-----------------------------------------------+-------------------------------------+ -| :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership | +| :keyword:`in`, :keyword:`not in`, | Comparisons, including membership | | :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, | | ``<=``, ``>``, ``>=``, ``<>``, ``!=``, ``==`` | | +-----------------------------------------------+-------------------------------------+ @@ -1391,7 +1391,7 @@ +-----------------------------------------------+-------------------------------------+ | ``(expressions...)``, | Binding or tuple display, | | ``[expressions...]``, | list display, | -| ``{key:datum...}``, | dictionary display, | +| ``{key: value...}``, | dictionary display, | | ```expressions...``` | string conversion | +-----------------------------------------------+-------------------------------------+ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 14:47:59 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 14:47:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2Njc3OiByZW5h?= =?utf-8?q?me_section_header_and_fix_markup=2E?= Message-ID: <3YVzCg5n0qzRm5@mail.python.org> http://hg.python.org/cpython/rev/2eab4f7b7280 changeset: 81036:2eab4f7b7280 branch: 3.2 parent: 81028:c3acc5ead883 user: Ezio Melotti date: Tue Dec 25 15:45:15 2012 +0200 summary: #16677: rename section header and fix markup. files: Doc/reference/expressions.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1266,8 +1266,8 @@ .. _operator-summary: -Summary -======= +Operator precedence +=================== .. index:: pair: operator; precedence @@ -1291,9 +1291,9 @@ +-----------------------------------------------+-------------------------------------+ | :keyword:`and` | Boolean AND | +-----------------------------------------------+-------------------------------------+ -| :keyword:`not` *x* | Boolean NOT | +| :keyword:`not` ``x`` | Boolean NOT | +-----------------------------------------------+-------------------------------------+ -| :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership | +| :keyword:`in`, :keyword:`not in`, | Comparisons, including membership | | :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, | | ``<=``, ``>``, ``>=``, ``!=``, ``==`` | | +-----------------------------------------------+-------------------------------------+ @@ -1319,7 +1319,7 @@ +-----------------------------------------------+-------------------------------------+ | ``(expressions...)``, | Binding or tuple display, | | ``[expressions...]``, | list display, | -| ``{key:datum...}``, | dictionary display, | +| ``{key: value...}``, | dictionary display, | | ``{expressions...}`` | set display | +-----------------------------------------------+-------------------------------------+ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 14:48:01 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 14:48:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2316677=3A_merge_with_3=2E2=2E?= Message-ID: <3YVzCj0sgtzRpQ@mail.python.org> http://hg.python.org/cpython/rev/356af3fc6471 changeset: 81037:356af3fc6471 branch: 3.3 parent: 81029:dbe9413686b3 parent: 81036:2eab4f7b7280 user: Ezio Melotti date: Tue Dec 25 15:46:58 2012 +0200 summary: #16677: merge with 3.2. files: Doc/reference/expressions.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1303,8 +1303,8 @@ .. _operator-summary: -Summary -======= +Operator precedence +=================== .. index:: pair: operator; precedence @@ -1328,9 +1328,9 @@ +-----------------------------------------------+-------------------------------------+ | :keyword:`and` | Boolean AND | +-----------------------------------------------+-------------------------------------+ -| :keyword:`not` *x* | Boolean NOT | +| :keyword:`not` ``x`` | Boolean NOT | +-----------------------------------------------+-------------------------------------+ -| :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership | +| :keyword:`in`, :keyword:`not in`, | Comparisons, including membership | | :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, | | ``<=``, ``>``, ``>=``, ``!=``, ``==`` | | +-----------------------------------------------+-------------------------------------+ @@ -1356,7 +1356,7 @@ +-----------------------------------------------+-------------------------------------+ | ``(expressions...)``, | Binding or tuple display, | | ``[expressions...]``, | list display, | -| ``{key:datum...}``, | dictionary display, | +| ``{key: value...}``, | dictionary display, | | ``{expressions...}`` | set display | +-----------------------------------------------+-------------------------------------+ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 14:48:02 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 14:48:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogIzE2Njc3OiBtZXJnZSB3aXRoIDMuMy4=?= Message-ID: <3YVzCk3J06zRpF@mail.python.org> http://hg.python.org/cpython/rev/9a65501a71e6 changeset: 81038:9a65501a71e6 parent: 81031:3a86a3f1d89a parent: 81037:356af3fc6471 user: Ezio Melotti date: Tue Dec 25 15:47:41 2012 +0200 summary: #16677: merge with 3.3. files: Doc/reference/expressions.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1303,8 +1303,8 @@ .. _operator-summary: -Summary -======= +Operator precedence +=================== .. index:: pair: operator; precedence @@ -1328,9 +1328,9 @@ +-----------------------------------------------+-------------------------------------+ | :keyword:`and` | Boolean AND | +-----------------------------------------------+-------------------------------------+ -| :keyword:`not` *x* | Boolean NOT | +| :keyword:`not` ``x`` | Boolean NOT | +-----------------------------------------------+-------------------------------------+ -| :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership | +| :keyword:`in`, :keyword:`not in`, | Comparisons, including membership | | :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, | | ``<=``, ``>``, ``>=``, ``!=``, ``==`` | | +-----------------------------------------------+-------------------------------------+ @@ -1356,7 +1356,7 @@ +-----------------------------------------------+-------------------------------------+ | ``(expressions...)``, | Binding or tuple display, | | ``[expressions...]``, | list display, | -| ``{key:datum...}``, | dictionary display, | +| ``{key: value...}``, | dictionary display, | | ``{expressions...}`` | set display | +-----------------------------------------------+-------------------------------------+ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 15:48:00 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 15:48:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Replace_IOError_with_OSErr?= =?utf-8?b?b3IgKCMxNjcxNSk=?= Message-ID: <3YW0Xw2hQhzRpl@mail.python.org> http://hg.python.org/cpython/rev/7d69d04522e3 changeset: 81039:7d69d04522e3 user: Andrew Svetlov date: Tue Dec 25 16:47:37 2012 +0200 summary: Replace IOError with OSError (#16715) files: Lib/_osx_support.py | 2 +- Lib/_pyio.py | 32 +++--- Lib/argparse.py | 4 +- Lib/cgi.py | 2 +- Lib/chunk.py | 6 +- Lib/compileall.py | 4 +- Lib/configparser.py | 2 +- Lib/dbm/__init__.py | 10 +- Lib/dbm/dumb.py | 6 +- Lib/distutils/command/build_scripts.py | 2 +- Lib/distutils/core.py | 2 +- Lib/distutils/cygwinccompiler.py | 2 +- Lib/distutils/dir_util.py | 2 +- Lib/distutils/errors.py | 4 +- Lib/distutils/msvc9compiler.py | 2 +- Lib/distutils/sysconfig.py | 4 +- Lib/distutils/util.py | 4 +- Lib/fileinput.py | 6 +- Lib/ftplib.py | 8 +- Lib/gettext.py | 14 +- Lib/gzip.py | 20 +- Lib/http/cookiejar.py | 13 +- Lib/http/server.py | 2 +- Lib/idlelib/EditorWindow.py | 2 +- Lib/idlelib/GrepDialog.py | 2 +- Lib/idlelib/IOBinding.py | 4 +- Lib/idlelib/OutputWindow.py | 2 +- Lib/idlelib/PyShell.py | 8 +- Lib/idlelib/configHandler.py | 14 +- Lib/idlelib/rpc.py | 2 +- Lib/idlelib/textView.py | 2 +- Lib/imghdr.py | 2 +- Lib/importlib/_bootstrap.py | 4 +- Lib/inspect.py | 20 +- Lib/io.py | 2 +- Lib/lib2to3/pgen2/conv.py | 4 +- Lib/lib2to3/pgen2/driver.py | 2 +- Lib/lib2to3/refactor.py | 2 +- Lib/linecache.py | 4 +- Lib/logging/__init__.py | 4 +- Lib/mailbox.py | 16 +- Lib/mailcap.py | 2 +- Lib/mimetypes.py | 2 +- Lib/multiprocessing/connection.py | 14 +- Lib/multiprocessing/managers.py | 2 +- Lib/multiprocessing/pool.py | 20 +- Lib/netrc.py | 2 +- Lib/nntplib.py | 2 +- Lib/nturl2path.py | 4 +- Lib/pdb.py | 10 +- Lib/pkgutil.py | 2 +- Lib/platform.py | 3 - Lib/pstats.py | 2 +- Lib/pty.py | 6 +- Lib/py_compile.py | 2 +- Lib/pydoc.py | 4 +- Lib/quopri.py | 2 +- Lib/site.py | 4 +- Lib/sndhdr.py | 4 +- Lib/socket.py | 2 +- Lib/subprocess.py | 4 +- Lib/sysconfig.py | 8 +- Lib/tabnanny.py | 2 +- Lib/tarfile.py | 14 +- Lib/test/fork_wait.py | 2 +- Lib/test/multibytecodec_support.py | 2 +- Lib/test/regrtest.py | 2 +- Lib/test/sortperf.py | 4 +- Lib/test/support.py | 12 +- Lib/test/test_array.py | 4 +- Lib/test/test_bz2.py | 6 +- Lib/test/test_csv.py | 12 +- Lib/test/test_dbm.py | 2 +- Lib/test/test_email/torture_test.py | 2 +- Lib/test/test_epoll.py | 10 +- Lib/test/test_exceptions.py | 8 +- Lib/test/test_file.py | 10 +- Lib/test/test_fileinput.py | 4 +- Lib/test/test_fileio.py | 18 +- Lib/test/test_ftplib.py | 6 +- Lib/test/test_imaplib.py | 2 +- Lib/test/test_importlib/source/test_abc_loader.py | 14 +- Lib/test/test_importlib/source/test_file_loader.py | 2 +- Lib/test/test_inspect.py | 8 +- Lib/test/test_io.py | 52 +++++----- Lib/test/test_ioctl.py | 2 +- Lib/test/test_largefile.py | 4 +- Lib/test/test_logging.py | 6 +- Lib/test/test_memoryio.py | 12 +- Lib/test/test_mmap.py | 8 +- Lib/test/test_multiprocessing.py | 18 +- Lib/test/test_normalization.py | 2 +- Lib/test/test_ossaudiodev.py | 4 +- Lib/test/test_posix.py | 2 +- Lib/test/test_resource.py | 2 +- Lib/test/test_shutil.py | 14 +- Lib/test/test_smtplib.py | 2 +- Lib/test/test_socket.py | 2 +- Lib/test/test_ssl.py | 18 +- Lib/test/test_struct.py | 6 +- Lib/test/test_tarfile.py | 12 +- Lib/test/test_timeout.py | 2 +- Lib/test/test_ucn.py | 2 +- Lib/test/test_urllib.py | 10 +- Lib/test/test_urllib2_localnet.py | 2 +- Lib/test/test_urllibnet.py | 2 +- Lib/test/test_zipfile.py | 8 +- Lib/test/test_zipimport.py | 2 +- Lib/token.py | 6 +- Lib/tokenize.py | 2 +- Lib/trace.py | 10 +- Lib/urllib/error.py | 8 +- Lib/urllib/request.py | 16 +- Lib/uuid.py | 4 +- Lib/warnings.py | 2 +- Lib/webbrowser.py | 2 +- Lib/xml/etree/ElementInclude.py | 6 +- Lib/xmlrpc/client.py | 4 +- Lib/zipfile.py | 12 +- Python/Python-ast.c | 1 - Python/importlib.h | 4 +- 121 files changed, 381 insertions(+), 386 deletions(-) diff --git a/Lib/_osx_support.py b/Lib/_osx_support.py --- a/Lib/_osx_support.py +++ b/Lib/_osx_support.py @@ -94,7 +94,7 @@ _SYSTEM_VERSION = '' try: f = open('/System/Library/CoreServices/SystemVersion.plist') - except IOError: + except OSError: # We're on a plain darwin box, fall back to the default # behaviour. pass diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -34,7 +34,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None): - r"""Open file and return a stream. Raise IOError upon failure. + r"""Open file and return a stream. Raise OSError upon failure. file is either a text or byte string giving the name (and the path if the file isn't in the current working directory) of the file to @@ -254,7 +254,7 @@ try: UnsupportedOperation = io.UnsupportedOperation except AttributeError: - class UnsupportedOperation(ValueError, IOError): + class UnsupportedOperation(ValueError, OSError): pass @@ -278,7 +278,7 @@ readinto) needed. Text I/O classes work with str data. Note that calling any method (even inquiries) on a closed stream is - undefined. Implementations may raise IOError in this case. + undefined. Implementations may raise OSError in this case. IOBase (and its subclasses) support the iterator protocol, meaning that an IOBase object can be iterated over yielding the lines in a @@ -294,7 +294,7 @@ ### Internal ### def _unsupported(self, name): - """Internal: raise an IOError exception for unsupported operations.""" + """Internal: raise an OSError exception for unsupported operations.""" raise UnsupportedOperation("%s.%s() not supported" % (self.__class__.__name__, name)) @@ -441,7 +441,7 @@ def fileno(self): """Returns underlying file descriptor (an int) if one exists. - An IOError is raised if the IO object does not use a file descriptor. + An OSError is raised if the IO object does not use a file descriptor. """ self._unsupported("fileno") @@ -699,13 +699,13 @@ def seek(self, pos, whence=0): new_position = self.raw.seek(pos, whence) if new_position < 0: - raise IOError("seek() returned an invalid position") + raise OSError("seek() returned an invalid position") return new_position def tell(self): pos = self.raw.tell() if pos < 0: - raise IOError("tell() returned an invalid position") + raise OSError("tell() returned an invalid position") return pos def truncate(self, pos=None): @@ -927,7 +927,7 @@ """Create a new buffered reader using the given readable raw IO object. """ if not raw.readable(): - raise IOError('"raw" argument must be readable.') + raise OSError('"raw" argument must be readable.') _BufferedIOMixin.__init__(self, raw) if buffer_size <= 0: @@ -1074,7 +1074,7 @@ def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE): if not raw.writable(): - raise IOError('"raw" argument must be writable.') + raise OSError('"raw" argument must be writable.') _BufferedIOMixin.__init__(self, raw) if buffer_size <= 0: @@ -1138,7 +1138,7 @@ errno.EAGAIN, "write could not complete without blocking", 0) if n > len(self._write_buf) or n < 0: - raise IOError("write() returned incorrect number of bytes") + raise OSError("write() returned incorrect number of bytes") del self._write_buf[:n] def tell(self): @@ -1174,10 +1174,10 @@ The arguments are two RawIO instances. """ if not reader.readable(): - raise IOError('"reader" argument must be readable.') + raise OSError('"reader" argument must be readable.') if not writer.writable(): - raise IOError('"writer" argument must be writable.') + raise OSError('"writer" argument must be writable.') self.reader = BufferedReader(reader, buffer_size) self.writer = BufferedWriter(writer, buffer_size) @@ -1248,7 +1248,7 @@ with self._read_lock: self._reset_read_buf() if pos < 0: - raise IOError("seek() returned invalid position") + raise OSError("seek() returned invalid position") return pos def tell(self): @@ -1727,7 +1727,7 @@ if not self._seekable: raise UnsupportedOperation("underlying stream is not seekable") if not self._telling: - raise IOError("telling position disabled by next() call") + raise OSError("telling position disabled by next() call") self.flush() position = self.buffer.tell() decoder = self._decoder @@ -1814,7 +1814,7 @@ chars_decoded += len(decoder.decode(b'', final=True)) need_eof = 1 if chars_decoded < chars_to_skip: - raise IOError("can't reconstruct logical file position") + raise OSError("can't reconstruct logical file position") # The returned cookie corresponds to the last safe start point. return self._pack_cookie( @@ -1891,7 +1891,7 @@ # Skip chars_to_skip of the decoded characters. if len(self._decoded_chars) < chars_to_skip: - raise IOError("can't restore logical file position") + raise OSError("can't restore logical file position") self._decoded_chars_used = chars_to_skip # Finally, reset the encoder (merely useful for proper BOM handling) diff --git a/Lib/argparse.py b/Lib/argparse.py --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1167,7 +1167,7 @@ try: return open(string, self._mode, self._bufsize, self._encoding, self._errors) - except IOError as e: + except OSError as e: message = _("can't open '%s': %s") raise ArgumentTypeError(message % (string, e)) @@ -2020,7 +2020,7 @@ new_arg_strings.extend(arg_strings) finally: args_file.close() - except IOError: + except OSError: err = _sys.exc_info()[1] self.error(str(err)) diff --git a/Lib/cgi.py b/Lib/cgi.py --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -80,7 +80,7 @@ if logfile and not logfp: try: logfp = open(logfile, "a") - except IOError: + except OSError: pass if not logfp: log = nolog diff --git a/Lib/chunk.py b/Lib/chunk.py --- a/Lib/chunk.py +++ b/Lib/chunk.py @@ -70,7 +70,7 @@ self.size_read = 0 try: self.offset = self.file.tell() - except (AttributeError, IOError): + except (AttributeError, OSError): self.seekable = False else: self.seekable = True @@ -102,7 +102,7 @@ if self.closed: raise ValueError("I/O operation on closed file") if not self.seekable: - raise IOError("cannot seek") + raise OSError("cannot seek") if whence == 1: pos = pos + self.size_read elif whence == 2: @@ -158,7 +158,7 @@ self.file.seek(n, 1) self.size_read = self.size_read + n return - except IOError: + except OSError: pass while self.size_read < self.chunksize: n = min(8192, self.chunksize - self.size_read) diff --git a/Lib/compileall.py b/Lib/compileall.py --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -106,7 +106,7 @@ actual = chandle.read(8) if expect == actual: return success - except IOError: + except OSError: pass if not quiet: print('Compiling {!r}...'.format(fullname)) @@ -124,7 +124,7 @@ msg = msg.decode(sys.stdout.encoding) print(msg) success = 0 - except (SyntaxError, UnicodeError, IOError) as e: + except (SyntaxError, UnicodeError, OSError) as e: if quiet: print('*** Error compiling {!r}...'.format(fullname)) else: diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -688,7 +688,7 @@ try: with open(filename, encoding=encoding) as fp: self._read(fp, filename) - except IOError: + except OSError: continue read_ok.append(filename) return read_ok diff --git a/Lib/dbm/__init__.py b/Lib/dbm/__init__.py --- a/Lib/dbm/__init__.py +++ b/Lib/dbm/__init__.py @@ -42,7 +42,7 @@ _defaultmod = None _modules = {} -error = (error, IOError) +error = (error, OSError) def open(file, flag='r', mode=0o666): @@ -109,7 +109,7 @@ f = io.open(filename + ".dir", "rb") f.close() return "dbm.ndbm" - except IOError: + except OSError: # some dbm emulations based on Berkeley DB generate a .db file # some do not, but they should be caught by the bsd checks try: @@ -122,7 +122,7 @@ d = ndbm.open(filename) d.close() return "dbm.ndbm" - except IOError: + except OSError: pass # Check for dumbdbm next -- this has a .dir and a .dat file @@ -139,13 +139,13 @@ return "dbm.dumb" finally: f.close() - except (OSError, IOError): + except OSError: pass # See if the file exists, return None if not try: f = io.open(filename, "rb") - except IOError: + except OSError: return None # Read the start of the file -- the magic number diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py --- a/Lib/dbm/dumb.py +++ b/Lib/dbm/dumb.py @@ -29,7 +29,7 @@ _BLOCKSIZE = 512 -error = IOError +error = OSError class _Database(collections.MutableMapping): @@ -67,7 +67,7 @@ # Mod by Jack: create data file if needed try: f = _io.open(self._datfile, 'r', encoding="Latin-1") - except IOError: + except OSError: f = _io.open(self._datfile, 'w', encoding="Latin-1") self._chmod(self._datfile) f.close() @@ -78,7 +78,7 @@ self._index = {} try: f = _io.open(self._dirfile, 'r', encoding="Latin-1") - except IOError: + except OSError: pass else: for line in f: diff --git a/Lib/distutils/command/build_scripts.py b/Lib/distutils/command/build_scripts.py --- a/Lib/distutils/command/build_scripts.py +++ b/Lib/distutils/command/build_scripts.py @@ -74,7 +74,7 @@ # script. try: f = open(script, "rb") - except IOError: + except OSError: if not self.dry_run: raise f = None diff --git a/Lib/distutils/core.py b/Lib/distutils/core.py --- a/Lib/distutils/core.py +++ b/Lib/distutils/core.py @@ -148,7 +148,7 @@ dist.run_commands() except KeyboardInterrupt: raise SystemExit("interrupted") - except (IOError, OSError) as exc: + except OSError as exc: error = grok_environment_error(exc) if DEBUG: diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py --- a/Lib/distutils/cygwinccompiler.py +++ b/Lib/distutils/cygwinccompiler.py @@ -359,7 +359,7 @@ return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn finally: config_h.close() - except IOError as exc: + except OSError as exc: return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)) diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py --- a/Lib/distutils/dir_util.py +++ b/Lib/distutils/dir_util.py @@ -198,7 +198,7 @@ abspath = os.path.abspath(cmd[1]) if abspath in _path_created: del _path_created[abspath] - except (IOError, OSError) as exc: + except OSError as exc: log.warn(grok_environment_error( exc, "error removing %s: " % directory)) diff --git a/Lib/distutils/errors.py b/Lib/distutils/errors.py --- a/Lib/distutils/errors.py +++ b/Lib/distutils/errors.py @@ -35,8 +35,8 @@ class DistutilsFileError (DistutilsError): """Any problems in the filesystem: expected file not found, etc. - Typically this is for problems that we detect before IOError or - OSError could be raised.""" + Typically this is for problems that we detect before OSError + could be raised.""" pass class DistutilsOptionError (DistutilsError): diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py --- a/Lib/distutils/msvc9compiler.py +++ b/Lib/distutils/msvc9compiler.py @@ -729,7 +729,7 @@ return manifest_file finally: manifest_f.close() - except IOError: + except OSError: pass # -- Miscellaneous methods ----------------------------------------- diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -426,7 +426,7 @@ try: filename = get_makefile_filename() parse_makefile(filename, g) - except IOError as msg: + except OSError as msg: my_msg = "invalid Python installation: unable to open %s" % filename if hasattr(msg, "strerror"): my_msg = my_msg + " (%s)" % msg.strerror @@ -438,7 +438,7 @@ filename = get_config_h_filename() with open(filename) as file: parse_config_h(file, g) - except IOError as msg: + except OSError as msg: my_msg = "invalid Python installation: unable to open %s" % filename if hasattr(msg, "strerror"): my_msg = my_msg + " (%s)" % msg.strerror diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py --- a/Lib/distutils/util.py +++ b/Lib/distutils/util.py @@ -207,8 +207,8 @@ def grok_environment_error (exc, prefix="error: "): - """Generate a useful error message from an EnvironmentError (IOError or - OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and + """Generate a useful error message from an OSError + exception object. Handles Python 1.5.1 and 1.5.2 styles, and does what it can to deal with exception objects that don't have a filename (which happens when the error is due to a two-file operation, such as 'rename()' or 'link()'. Returns the error message as a string diff --git a/Lib/fileinput.py b/Lib/fileinput.py --- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -30,7 +30,7 @@ All files are opened in text mode by default, you can override this by setting the mode parameter to input() or FileInput.__init__(). -If an I/O error occurs during opening or reading a file, the IOError +If an I/O error occurs during opening or reading a file, the OSError exception is raised. If sys.stdin is used more than once, the second and further use will @@ -328,7 +328,7 @@ os.unlink(self._backupfilename) except OSError: pass - # The next few lines may raise IOError + # The next few lines may raise OSError os.rename(self._filename, self._backupfilename) self._file = open(self._backupfilename, self._mode) try: @@ -350,7 +350,7 @@ self._savestdout = sys.stdout sys.stdout = self._output else: - # This may raise IOError + # This may raise OSError if self._openhook: self._file = self._openhook(self._filename, self._mode) else: diff --git a/Lib/ftplib.py b/Lib/ftplib.py --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -61,7 +61,7 @@ # All exceptions (hopefully) that may be raised here and that aren't # (always) programming errors on our side -all_errors = (Error, IOError, EOFError) +all_errors = (Error, OSError, EOFError) # Line terminators (we always output CRLF, but accept any of CRLF, CR, LF) @@ -826,7 +826,7 @@ return resp __all__.append('FTP_TLS') - all_errors = (Error, IOError, EOFError, ssl.SSLError) + all_errors = (Error, OSError, EOFError, ssl.SSLError) _150_re = None @@ -958,7 +958,7 @@ filename = os.path.join(os.environ["HOME"], ".netrc") else: - raise IOError("specify file to load or set $HOME") + raise OSError("specify file to load or set $HOME") self.__hosts = {} self.__macros = {} fp = open(filename, "r") @@ -1074,7 +1074,7 @@ userid = passwd = acct = '' try: netrc = Netrc(rcfile) - except IOError: + except OSError: if rcfile is not None: sys.stderr.write("Could not open account file" " -- using anonymous login.") diff --git a/Lib/gettext.py b/Lib/gettext.py --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -244,7 +244,7 @@ version, msgcount, masteridx, transidx = unpack('>4I', buf[4:20]) ii = '>II' else: - raise IOError(0, 'Bad magic number', filename) + raise OSError(0, 'Bad magic number', filename) # Now put all messages from the .mo file buffer into the catalog # dictionary. for i in range(0, msgcount): @@ -256,7 +256,7 @@ msg = buf[moff:mend] tmsg = buf[toff:tend] else: - raise IOError(0, 'File is corrupt', filename) + raise OSError(0, 'File is corrupt', filename) # See if we're looking at GNU .mo conventions for metadata if mlen == 0: # Catalog description @@ -398,7 +398,7 @@ if not mofiles: if fallback: return NullTranslations() - raise IOError(ENOENT, 'No translation file found for domain', domain) + raise OSError(ENOENT, 'No translation file found for domain', domain) # Avoid opening, reading, and parsing the .mo file after it's been done # once. result = None @@ -460,7 +460,7 @@ try: t = translation(domain, _localedirs.get(domain, None), codeset=_localecodesets.get(domain)) - except IOError: + except OSError: return message return t.gettext(message) @@ -468,7 +468,7 @@ try: t = translation(domain, _localedirs.get(domain, None), codeset=_localecodesets.get(domain)) - except IOError: + except OSError: return message return t.lgettext(message) @@ -476,7 +476,7 @@ try: t = translation(domain, _localedirs.get(domain, None), codeset=_localecodesets.get(domain)) - except IOError: + except OSError: if n == 1: return msgid1 else: @@ -487,7 +487,7 @@ try: t = translation(domain, _localedirs.get(domain, None), codeset=_localecodesets.get(domain)) - except IOError: + except OSError: if n == 1: return msgid1 else: diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -287,10 +287,10 @@ raise EOFError("Reached EOF") if magic != b'\037\213': - raise IOError('Not a gzipped file') + raise OSError('Not a gzipped file') method = ord( self.fileobj.read(1) ) if method != 8: - raise IOError('Unknown compression method') + raise OSError('Unknown compression method') flag = ord( self.fileobj.read(1) ) self.mtime = read32(self.fileobj) # extraflag = self.fileobj.read(1) @@ -326,7 +326,7 @@ self._check_closed() if self.mode != WRITE: import errno - raise IOError(errno.EBADF, "write() on read-only GzipFile object") + raise OSError(errno.EBADF, "write() on read-only GzipFile object") if self.fileobj is None: raise ValueError("write() on closed GzipFile object") @@ -347,7 +347,7 @@ self._check_closed() if self.mode != READ: import errno - raise IOError(errno.EBADF, "read() on write-only GzipFile object") + raise OSError(errno.EBADF, "read() on write-only GzipFile object") if self.extrasize <= 0 and self.fileobj is None: return b'' @@ -380,7 +380,7 @@ self._check_closed() if self.mode != READ: import errno - raise IOError(errno.EBADF, "read1() on write-only GzipFile object") + raise OSError(errno.EBADF, "read1() on write-only GzipFile object") if self.extrasize <= 0 and self.fileobj is None: return b'' @@ -404,7 +404,7 @@ def peek(self, n): if self.mode != READ: import errno - raise IOError(errno.EBADF, "peek() on write-only GzipFile object") + raise OSError(errno.EBADF, "peek() on write-only GzipFile object") # Do not return ridiculously small buffers, for one common idiom # is to call peek(1) and expect more bytes in return. @@ -487,10 +487,10 @@ crc32 = read32(self.fileobj) isize = read32(self.fileobj) # may exceed 2GB if crc32 != self.crc: - raise IOError("CRC check failed %s != %s" % (hex(crc32), + raise OSError("CRC check failed %s != %s" % (hex(crc32), hex(self.crc))) elif isize != (self.size & 0xffffffff): - raise IOError("Incorrect length of data produced") + raise OSError("Incorrect length of data produced") # Gzip files can be padded with zeroes and still have archives. # Consume all zero bytes and set the file position to the first @@ -539,7 +539,7 @@ '''Return the uncompressed stream file position indicator to the beginning of the file''' if self.mode != READ: - raise IOError("Can't rewind in write mode") + raise OSError("Can't rewind in write mode") self.fileobj.seek(0) self._new_member = True self.extrabuf = b"" @@ -564,7 +564,7 @@ raise ValueError('Seek from end not supported') if self.mode == WRITE: if offset < self.offset: - raise IOError('Negative seek in write mode') + raise OSError('Negative seek in write mode') count = offset - self.offset chunk = bytes(1024) for i in range(count // 1024): diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py --- a/Lib/http/cookiejar.py +++ b/Lib/http/cookiejar.py @@ -1730,8 +1730,8 @@ return "<%s[%s]>" % (self.__class__, ", ".join(r)) -# derives from IOError for backwards-compatibility with Python 2.4.0 -class LoadError(IOError): pass +# derives from OSError for backwards-compatibility with Python 2.4.0 +class LoadError(OSError): pass class FileCookieJar(CookieJar): """CookieJar that can be loaded from and saved to a file.""" @@ -1771,7 +1771,7 @@ ignore_discard=False, ignore_expires=False): """Clear all cookies and reload cookies from a saved file. - Raises LoadError (or IOError) if reversion is not successful; the + Raises LoadError (or OSError) if reversion is not successful; the object's state will not be altered if this happens. """ @@ -1786,7 +1786,7 @@ self._cookies = {} try: self.load(filename, ignore_discard, ignore_expires) - except (LoadError, IOError): + except OSError: self._cookies = old_state raise @@ -1937,8 +1937,7 @@ if not ignore_expires and c.is_expired(now): continue self.set_cookie(c) - - except IOError: + except OSError: raise except Exception: _warn_unhandled_exception() @@ -2044,7 +2043,7 @@ continue self.set_cookie(c) - except IOError: + except OSError: raise except Exception: _warn_unhandled_exception() diff --git a/Lib/http/server.py b/Lib/http/server.py --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -711,7 +711,7 @@ ctype = self.guess_type(path) try: f = open(path, 'rb') - except IOError: + except OSError: self.send_error(404, "File not found") return None self.send_response(200) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -886,7 +886,7 @@ with open(self.recent_files_path, 'w', encoding='utf_8', errors='replace') as rf_file: rf_file.writelines(rf_list) - except IOError as err: + except OSError as err: if not getattr(self.root, "recentfilelist_error_displayed", False): self.root.recentfilelist_error_displayed = True tkMessageBox.showerror(title='IDLE Error', diff --git a/Lib/idlelib/GrepDialog.py b/Lib/idlelib/GrepDialog.py --- a/Lib/idlelib/GrepDialog.py +++ b/Lib/idlelib/GrepDialog.py @@ -82,7 +82,7 @@ for fn in list: try: f = open(fn, errors='replace') - except IOError as msg: + except OSError as msg: print(msg) continue lineno = 0 diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py +++ b/Lib/idlelib/IOBinding.py @@ -212,7 +212,7 @@ f.seek(0) bytes = f.read() f.close() - except IOError as msg: + except OSError as msg: tkMessageBox.showerror("I/O Error", str(msg), master=self.text) return False chars, converted = self._decode(two_lines, bytes) @@ -377,7 +377,7 @@ f.flush() f.close() return True - except IOError as msg: + except OSError as msg: tkMessageBox.showerror("I/O Error", str(msg), master=self.text) return False diff --git a/Lib/idlelib/OutputWindow.py b/Lib/idlelib/OutputWindow.py --- a/Lib/idlelib/OutputWindow.py +++ b/Lib/idlelib/OutputWindow.py @@ -106,7 +106,7 @@ f = open(filename, "r") f.close() break - except IOError: + except OSError: continue else: return None diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -58,7 +58,7 @@ try: file.write(warnings.formatwarning(message, category, filename, lineno, line=line)) - except IOError: + except OSError: pass ## file (probably __stderr__) is invalid, warning dropped. warnings.showwarning = idle_showwarning def idle_formatwarning(message, category, filename, lineno, line=None): @@ -211,7 +211,7 @@ try: with open(self.breakpointPath, "r") as fp: lines = fp.readlines() - except IOError: + except OSError: lines = [] try: with open(self.breakpointPath, "w") as new_file: @@ -222,7 +222,7 @@ breaks = self.breakpoints if breaks: new_file.write(filename + '=' + str(breaks) + '\n') - except IOError as err: + except OSError as err: if not getattr(self.root, "breakpoint_error_displayed", False): self.root.breakpoint_error_displayed = True tkMessageBox.showerror(title='IDLE Error', @@ -528,7 +528,7 @@ return try: response = clt.pollresponse(self.active_seq, wait=0.05) - except (EOFError, IOError, KeyboardInterrupt): + except (EOFError, OSError, KeyboardInterrupt): # lost connection or subprocess terminated itself, restart # [the KBI is from rpc.SocketIO.handle_EOF()] if self.tkconsole.closing: diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -142,7 +142,7 @@ fname = self.file try: cfgFile = open(fname, 'w') - except IOError: + except OSError: os.unlink(fname) cfgFile = open(fname, 'w') with cfgFile: @@ -207,7 +207,7 @@ userDir+',\n but the path does not exist.\n') try: sys.stderr.write(warn) - except IOError: + except OSError: pass userDir = '~' if userDir == "~": # still no path to home! @@ -217,7 +217,7 @@ if not os.path.exists(userDir): try: os.mkdir(userDir) - except (OSError, IOError): + except OSError: warn = ('\n Warning: unable to create user config directory\n'+ userDir+'\n Check path and permissions.\n Exiting!\n\n') sys.stderr.write(warn) @@ -251,7 +251,7 @@ raw=raw))) try: sys.stderr.write(warning) - except IOError: + except OSError: pass try: if self.defaultCfg[configType].has_option(section,option): @@ -268,7 +268,7 @@ (option, section, default)) try: sys.stderr.write(warning) - except IOError: + except OSError: pass return default @@ -380,7 +380,7 @@ (element, themeName, theme[element])) try: sys.stderr.write(warning) - except IOError: + except OSError: pass colour=cfgParser.Get(themeName,element,default=theme[element]) theme[element]=colour @@ -637,7 +637,7 @@ (event, keySetName, keyBindings[event])) try: sys.stderr.write(warning) - except IOError: + except OSError: pass return keyBindings diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py --- a/Lib/idlelib/rpc.py +++ b/Lib/idlelib/rpc.py @@ -339,7 +339,7 @@ r, w, x = select.select([], [self.sock], []) n = self.sock.send(s[:BUFSIZE]) except (AttributeError, TypeError): - raise IOError("socket no longer exists") + raise OSError("socket no longer exists") except OSError: raise else: diff --git a/Lib/idlelib/textView.py b/Lib/idlelib/textView.py --- a/Lib/idlelib/textView.py +++ b/Lib/idlelib/textView.py @@ -66,7 +66,7 @@ try: with open(filename, 'r', encoding=encoding) as file: contents = file.read() - except IOError: + except OSError: import tkinter.messagebox as tkMessageBox tkMessageBox.showerror(title='File Load Error', message='Unable to load file %r .' % filename, diff --git a/Lib/imghdr.py b/Lib/imghdr.py --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -149,7 +149,7 @@ sys.stdout.flush() try: print(what(filename)) - except IOError: + except OSError: print('*** not found ***') if __name__ == '__main__': diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -915,7 +915,7 @@ path = self.get_filename(fullname) try: source_bytes = self.get_data(path) - except IOError as exc: + except OSError as exc: raise ImportError("source not available through get_data()", name=fullname) from exc readsource = _io.BytesIO(source_bytes).readline @@ -961,7 +961,7 @@ source_mtime = int(st['mtime']) try: data = self.get_data(bytecode_path) - except IOError: + except OSError: pass else: try: diff --git a/Lib/inspect.py b/Lib/inspect.py --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -545,13 +545,13 @@ The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of all the lines - in the file and the line number indexes a line in that list. An IOError + in the file and the line number indexes a line in that list. An OSError is raised if the source code cannot be retrieved.""" file = getfile(object) sourcefile = getsourcefile(object) if not sourcefile and file[0] + file[-1] != '<>': - raise IOError('source code not available') + raise OSError('source code not available') file = sourcefile if sourcefile else file module = getmodule(object, file) @@ -560,7 +560,7 @@ else: lines = linecache.getlines(file) if not lines: - raise IOError('could not get source code') + raise OSError('could not get source code') if ismodule(object): return lines, 0 @@ -586,7 +586,7 @@ candidates.sort() return lines, candidates[0][1] else: - raise IOError('could not find class definition') + raise OSError('could not find class definition') if ismethod(object): object = object.__func__ @@ -598,14 +598,14 @@ object = object.f_code if iscode(object): if not hasattr(object, 'co_firstlineno'): - raise IOError('could not find function definition') + raise OSError('could not find function definition') lnum = object.co_firstlineno - 1 pat = re.compile(r'^(\s*def\s)|(.*(? 0: if pat.match(lines[lnum]): break lnum = lnum - 1 return lines, lnum - raise IOError('could not find code object') + raise OSError('could not find code object') def getcomments(object): """Get lines of comments immediately preceding an object's source code. @@ -614,7 +614,7 @@ """ try: lines, lnum = findsource(object) - except (IOError, TypeError): + except (OSError, TypeError): return None if ismodule(object): @@ -710,7 +710,7 @@ The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a list of the lines corresponding to the object and the line number indicates where in the - original source file the first line of code was found. An IOError is + original source file the first line of code was found. An OSError is raised if the source code cannot be retrieved.""" lines, lnum = findsource(object) @@ -722,7 +722,7 @@ The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string. An - IOError is raised if the source code cannot be retrieved.""" + OSError is raised if the source code cannot be retrieved.""" lines, lnum = getsourcelines(object) return ''.join(lines) @@ -1122,7 +1122,7 @@ start = lineno - 1 - context//2 try: lines, lnum = findsource(frame) - except IOError: + except OSError: lines = index = None else: start = max(start, 1) diff --git a/Lib/io.py b/Lib/io.py --- a/Lib/io.py +++ b/Lib/io.py @@ -4,7 +4,7 @@ At the top of the I/O hierarchy is the abstract base class IOBase. It defines the basic interface to a stream. Note, however, that there is no separation between reading and writing to streams; implementations are -allowed to raise an IOError if they do not support a given operation. +allowed to raise an OSError if they do not support a given operation. Extending IOBase is RawIOBase which deals simply with the reading and writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide diff --git a/Lib/lib2to3/pgen2/conv.py b/Lib/lib2to3/pgen2/conv.py --- a/Lib/lib2to3/pgen2/conv.py +++ b/Lib/lib2to3/pgen2/conv.py @@ -60,7 +60,7 @@ """ try: f = open(filename) - except IOError as err: + except OSError as err: print("Can't open %s: %s" % (filename, err)) return False self.symbol2number = {} @@ -111,7 +111,7 @@ """ try: f = open(filename) - except IOError as err: + except OSError as err: print("Can't open %s: %s" % (filename, err)) return False # The code below essentially uses f's iterator-ness! diff --git a/Lib/lib2to3/pgen2/driver.py b/Lib/lib2to3/pgen2/driver.py --- a/Lib/lib2to3/pgen2/driver.py +++ b/Lib/lib2to3/pgen2/driver.py @@ -123,7 +123,7 @@ logger.info("Writing grammar tables to %s", gp) try: g.dump(gp) - except IOError as e: + except OSError as e: logger.info("Writing failed:"+str(e)) else: g = grammar.Grammar() diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py --- a/Lib/lib2to3/refactor.py +++ b/Lib/lib2to3/refactor.py @@ -326,7 +326,7 @@ """ try: f = open(filename, "rb") - except IOError as err: + except OSError as err: self.log_error("Can't open %s: %s", filename, err) return None, None try: diff --git a/Lib/linecache.py b/Lib/linecache.py --- a/Lib/linecache.py +++ b/Lib/linecache.py @@ -91,7 +91,7 @@ if name and get_source: try: data = get_source(name) - except (ImportError, IOError): + except (ImportError, OSError): pass else: if data is None: @@ -125,7 +125,7 @@ try: with tokenize.open(fullname) as fp: lines = fp.readlines() - except IOError: + except OSError: return [] if lines and not lines[-1].endswith('\n'): lines[-1] += '\n' diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -896,7 +896,7 @@ # couldn't find the right stack frame, for some reason sys.stderr.write('Logged from file %s, line %s\n' % ( record.filename, record.lineno)) - except IOError: #pragma: no cover + except OSError: #pragma: no cover pass # see issue 5971 finally: del t, v, tb @@ -1838,7 +1838,7 @@ h.acquire() h.flush() h.close() - except (IOError, ValueError): + except (OSError, ValueError): # Ignore errors which might be caused # because handlers have been closed but # references to them are still around at diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -585,7 +585,7 @@ Mailbox.__init__(self, path, factory, create) try: f = open(self._path, 'rb+') - except IOError as e: + except OSError as e: if e.errno == errno.ENOENT: if create: f = open(self._path, 'wb+') @@ -988,7 +988,7 @@ path = os.path.join(self._path, str(key)) try: f = open(path, 'rb+') - except IOError as e: + except OSError as e: if e.errno == errno.ENOENT: raise KeyError('No message with key: %s' % key) else: @@ -1002,7 +1002,7 @@ path = os.path.join(self._path, str(key)) try: f = open(path, 'rb+') - except IOError as e: + except OSError as e: if e.errno == errno.ENOENT: raise KeyError('No message with key: %s' % key) else: @@ -1028,7 +1028,7 @@ f = open(os.path.join(self._path, str(key)), 'rb+') else: f = open(os.path.join(self._path, str(key)), 'rb') - except IOError as e: + except OSError as e: if e.errno == errno.ENOENT: raise KeyError('No message with key: %s' % key) else: @@ -1055,7 +1055,7 @@ f = open(os.path.join(self._path, str(key)), 'rb+') else: f = open(os.path.join(self._path, str(key)), 'rb') - except IOError as e: + except OSError as e: if e.errno == errno.ENOENT: raise KeyError('No message with key: %s' % key) else: @@ -1075,7 +1075,7 @@ """Return a file-like representation or raise a KeyError.""" try: f = open(os.path.join(self._path, str(key)), 'rb') - except IOError as e: + except OSError as e: if e.errno == errno.ENOENT: raise KeyError('No message with key: %s' % key) else: @@ -2068,7 +2068,7 @@ if fcntl: try: fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB) - except IOError as e: + except OSError as e: if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS): raise ExternalClashError('lockf: lock unavailable: %s' % f.name) @@ -2078,7 +2078,7 @@ try: pre_lock = _create_temporary(f.name + '.lock') pre_lock.close() - except IOError as e: + except OSError as e: if e.errno in (errno.EACCES, errno.EROFS): return # Without write access, just skip dotlocking. else: diff --git a/Lib/mailcap.py b/Lib/mailcap.py --- a/Lib/mailcap.py +++ b/Lib/mailcap.py @@ -20,7 +20,7 @@ for mailcap in listmailcapfiles(): try: fp = open(mailcap, 'r') - except IOError: + except OSError: continue morecaps = readmailcapfile(fp) fp.close() diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -359,7 +359,7 @@ def read_mime_types(file): try: f = open(file) - except IOError: + except OSError: return None db = MimeTypes() db.readfp(f, True) diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -132,22 +132,22 @@ def _check_closed(self): if self._handle is None: - raise IOError("handle is closed") + raise OSError("handle is closed") def _check_readable(self): if not self._readable: - raise IOError("connection is write-only") + raise OSError("connection is write-only") def _check_writable(self): if not self._writable: - raise IOError("connection is read-only") + raise OSError("connection is read-only") def _bad_message_length(self): if self._writable: self._readable = False else: self.close() - raise IOError("bad message length") + raise OSError("bad message length") @property def closed(self): @@ -317,7 +317,7 @@ return f elif err == _winapi.ERROR_MORE_DATA: return self._get_more_data(ov, maxsize) - except IOError as e: + except OSError as e: if e.winerror == _winapi.ERROR_BROKEN_PIPE: raise EOFError else: @@ -383,7 +383,7 @@ if remaining == size: raise EOFError else: - raise IOError("got end of file during message") + raise OSError("got end of file during message") buf.write(chunk) remaining -= n return buf @@ -443,7 +443,7 @@ Returns a `Connection` object. ''' if self._listener is None: - raise IOError('listener is closed') + raise OSError('listener is closed') c = self._listener.accept() if self._authkey: deliver_challenge(c, self._authkey) diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -167,7 +167,7 @@ while True: try: c = self.listener.accept() - except (OSError, IOError): + except OSError: continue t = threading.Thread(target=self.handle_request, args=(c,)) t.daemon = True diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py --- a/Lib/multiprocessing/pool.py +++ b/Lib/multiprocessing/pool.py @@ -78,8 +78,8 @@ while maxtasks is None or (maxtasks and completed < maxtasks): try: task = get() - except (EOFError, IOError): - debug('worker got EOFError or IOError -- exiting') + except (EOFError, OSError): + debug('worker got EOFError or OSError -- exiting') break if task is None: @@ -349,7 +349,7 @@ break try: put(task) - except IOError: + except OSError: debug('could not put task on queue') break else: @@ -371,8 +371,8 @@ debug('task handler sending sentinel to workers') for p in pool: put(None) - except IOError: - debug('task handler got IOError when sending sentinels') + except OSError: + debug('task handler got OSError when sending sentinels') debug('task handler exiting') @@ -383,8 +383,8 @@ while 1: try: task = get() - except (IOError, EOFError): - debug('result handler got EOFError/IOError -- exiting') + except (OSError, EOFError): + debug('result handler got EOFError/OSError -- exiting') return if thread._state: @@ -405,8 +405,8 @@ while cache and thread._state != TERMINATE: try: task = get() - except (IOError, EOFError): - debug('result handler got EOFError/IOError -- exiting') + except (OSError, EOFError): + debug('result handler got EOFError/OSError -- exiting') return if task is None: @@ -428,7 +428,7 @@ if not outqueue._reader.poll(): break get() - except (IOError, EOFError): + except (OSError, EOFError): pass debug('result handler exiting: len(cache)=%s, thread._state=%s', diff --git a/Lib/netrc.py b/Lib/netrc.py --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -25,7 +25,7 @@ try: file = os.path.join(os.environ['HOME'], ".netrc") except KeyError: - raise IOError("Could not find .netrc: $HOME is not set") + raise OSError("Could not find .netrc: $HOME is not set") self.hosts = {} self.macros = {} with open(file) as fp: diff --git a/Lib/nntplib.py b/Lib/nntplib.py --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -947,7 +947,7 @@ if auth: user = auth[0] password = auth[2] - except IOError: + except OSError: pass # Perform NNTP authentication if needed. if not user: diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py --- a/Lib/nturl2path.py +++ b/Lib/nturl2path.py @@ -23,7 +23,7 @@ comp = url.split('|') if len(comp) != 2 or comp[0][-1] not in string.ascii_letters: error = 'Bad URL: ' + url - raise IOError(error) + raise OSError(error) drive = comp[0][-1].upper() components = comp[1].split('/') path = drive + ':' @@ -55,7 +55,7 @@ comp = p.split(':') if len(comp) != 2 or len(comp[0]) > 1: error = 'Bad path: ' + p - raise IOError(error) + raise OSError(error) drive = urllib.parse.quote(comp[0].upper()) components = comp[1].split('\\') diff --git a/Lib/pdb.py b/Lib/pdb.py --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -92,7 +92,7 @@ cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname)) try: fp = open(filename) - except IOError: + except OSError: return None # consumer of this info expects the first line to be 1 lineno = 1 @@ -170,12 +170,12 @@ try: with open(os.path.join(envHome, ".pdbrc")) as rcFile: self.rcLines.extend(rcFile) - except IOError: + except OSError: pass try: with open(".pdbrc") as rcFile: self.rcLines.extend(rcFile) - except IOError: + except OSError: pass self.commands = {} # associates a command list to breakpoint numbers @@ -1241,7 +1241,7 @@ breaklist = self.get_file_breaks(filename) try: lines, lineno = getsourcelines(self.curframe) - except IOError as err: + except OSError as err: self.error(err) return self._print_lines(lines, lineno, breaklist, self.curframe) @@ -1257,7 +1257,7 @@ return try: lines, lineno = getsourcelines(obj) - except (IOError, TypeError) as err: + except (OSError, TypeError) as err: self.error(err) return self._print_lines(lines, lineno) diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -587,7 +587,7 @@ if os.path.isfile(pkgfile): try: f = open(pkgfile) - except IOError as msg: + except OSError as msg: sys.stderr.write("Can't open %s: %s\n" % (pkgfile, msg)) else: diff --git a/Lib/platform.py b/Lib/platform.py --- a/Lib/platform.py +++ b/Lib/platform.py @@ -430,9 +430,6 @@ except OSError as why: #print 'Command %s failed: %s' % (cmd,why) continue - except IOError as why: - #print 'Command %s failed: %s' % (cmd,why) - continue else: break else: diff --git a/Lib/pstats.py b/Lib/pstats.py --- a/Lib/pstats.py +++ b/Lib/pstats.py @@ -612,7 +612,7 @@ if line: try: self.stats = Stats(line) - except IOError as err: + except OSError as err: print(err.args[1], file=self.stream) return except Exception as err: diff --git a/Lib/pty.py b/Lib/pty.py --- a/Lib/pty.py +++ b/Lib/pty.py @@ -56,7 +56,7 @@ else: try: tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0) - except IOError as msg: + except OSError as msg: raise OSError(msg) return master_fd, tty_name for x in 'pqrstuvwxyzPQRST': @@ -83,7 +83,7 @@ try: ioctl(result, I_PUSH, "ptem") ioctl(result, I_PUSH, "ldterm") - except IOError: + except OSError: pass return result @@ -173,7 +173,7 @@ restore = 0 try: _copy(master_fd, master_read, stdin_read) - except (IOError, OSError): + except OSError: if restore: tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode) diff --git a/Lib/py_compile.py b/Lib/py_compile.py --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -173,7 +173,7 @@ except PyCompileError as error: rv = 1 sys.stderr.write("%s\n" % error.msg) - except IOError as error: + except OSError as error: rv = 1 sys.stderr.write("%s\n" % error) else: diff --git a/Lib/pydoc.py b/Lib/pydoc.py --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -223,7 +223,7 @@ if lastupdate is None or lastupdate < mtime: try: file = tokenize.open(filename) - except IOError: + except OSError: # module can't be opened, so skip it return None binary_suffixes = importlib.machinery.BYTECODE_SUFFIXES[:] @@ -1419,7 +1419,7 @@ try: pipe.write(text) pipe.close() - except IOError: + except OSError: pass # Ignore broken pipes caused by quitting the pager program. def tempfilepager(text, cmd): diff --git a/Lib/quopri.py b/Lib/quopri.py --- a/Lib/quopri.py +++ b/Lib/quopri.py @@ -223,7 +223,7 @@ else: try: fp = open(file, "rb") - except IOError as msg: + except OSError as msg: sys.stderr.write("%s: can't open (%s)\n" % (file, msg)) sts = 1 continue diff --git a/Lib/site.py b/Lib/site.py --- a/Lib/site.py +++ b/Lib/site.py @@ -153,7 +153,7 @@ fullname = os.path.join(sitedir, name) try: f = open(fullname, "r") - except IOError: + except OSError: return with f: for n, line in enumerate(f): @@ -388,7 +388,7 @@ data = fp.read() fp.close() break - except IOError: + except OSError: pass if data: break diff --git a/Lib/sndhdr.py b/Lib/sndhdr.py --- a/Lib/sndhdr.py +++ b/Lib/sndhdr.py @@ -11,7 +11,7 @@ - number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW If the file doesn't have a recognizable type, it returns None. -If the file can't be opened, IOError is raised. +If the file can't be opened, OSError is raised. To compute the total time, divide the number of frames by the sampling rate (a frame contains a sample for each channel). @@ -230,7 +230,7 @@ sys.stdout.flush() try: print(what(filename)) - except IOError: + except OSError: print('*** not found ***') if __name__ == '__main__': diff --git a/Lib/socket.py b/Lib/socket.py --- a/Lib/socket.py +++ b/Lib/socket.py @@ -291,7 +291,7 @@ self._checkClosed() self._checkReadable() if self._timeout_occurred: - raise IOError("cannot read from timed out object") + raise OSError("cannot read from timed out object") while True: try: return self._sock.recv_into(b) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -897,7 +897,7 @@ if input: try: self.stdin.write(input) - except IOError as e: + except OSError as e: if e.errno != errno.EPIPE and e.errno != errno.EINVAL: raise self.stdin.close() @@ -1152,7 +1152,7 @@ if input is not None: try: self.stdin.write(input) - except IOError as e: + except OSError as e: if e.errno != errno.EPIPE: raise self.stdin.close() diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -349,21 +349,21 @@ makefile = get_makefile_filename() try: _parse_makefile(makefile, vars) - except IOError as e: + except OSError as e: msg = "invalid Python installation: unable to open %s" % makefile if hasattr(e, "strerror"): msg = msg + " (%s)" % e.strerror - raise IOError(msg) + raise OSError(msg) # load the installed pyconfig.h: config_h = get_config_h_filename() try: with open(config_h) as f: parse_config_h(f, vars) - except IOError as e: + except OSError as e: msg = "invalid Python installation: unable to open %s" % config_h if hasattr(e, "strerror"): msg = msg + " (%s)" % e.strerror - raise IOError(msg) + raise OSError(msg) # On AIX, there are wrong paths to the linker scripts in the Makefile # -- these paths are relative to the Python source, but when installed # the scripts are in another directory. diff --git a/Lib/tabnanny.py b/Lib/tabnanny.py --- a/Lib/tabnanny.py +++ b/Lib/tabnanny.py @@ -95,7 +95,7 @@ try: f = tokenize.open(file) - except IOError as msg: + except OSError as msg: errprint("%r: I/O Error: %s" % (file, msg)) return diff --git a/Lib/tarfile.py b/Lib/tarfile.py --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -264,13 +264,13 @@ for b in range(blocks): buf = src.read(BUFSIZE) if len(buf) < BUFSIZE: - raise IOError("end of file reached") + raise OSError("end of file reached") dst.write(buf) if remainder != 0: buf = src.read(remainder) if len(buf) < remainder: - raise IOError("end of file reached") + raise OSError("end of file reached") dst.write(buf) return @@ -399,7 +399,7 @@ if mode == "r": self.dbuf = b"" self.cmp = bz2.BZ2Decompressor() - self.exception = IOError + self.exception = OSError else: self.cmp = bz2.BZ2Compressor() @@ -1631,7 +1631,7 @@ try: fileobj = gzip.GzipFile(name, mode + "b", compresslevel, fileobj) t = cls.taropen(name, mode, fileobj, **kwargs) - except IOError: + except OSError: if not extfileobj and fileobj is not None: fileobj.close() if fileobj is None: @@ -1662,7 +1662,7 @@ try: t = cls.taropen(name, mode, fileobj, **kwargs) - except (IOError, EOFError): + except (OSError, EOFError): fileobj.close() raise ReadError("not a bzip2 file") t._extfileobj = False @@ -2322,9 +2322,9 @@ corresponds to TarFile's mode. """ if self.closed: - raise IOError("%s is closed" % self.__class__.__name__) + raise OSError("%s is closed" % self.__class__.__name__) if mode is not None and self.mode not in mode: - raise IOError("bad operation for mode %r" % self.mode) + raise OSError("bad operation for mode %r" % self.mode) def _find_link_target(self, tarinfo): """Find the target member of a symlink or hardlink member in the diff --git a/Lib/test/fork_wait.py b/Lib/test/fork_wait.py --- a/Lib/test/fork_wait.py +++ b/Lib/test/fork_wait.py @@ -28,7 +28,7 @@ self.alive[id] = os.getpid() try: time.sleep(SHORTSLEEP) - except IOError: + except OSError: pass def wait_impl(self, cpid): diff --git a/Lib/test/multibytecodec_support.py b/Lib/test/multibytecodec_support.py --- a/Lib/test/multibytecodec_support.py +++ b/Lib/test/multibytecodec_support.py @@ -282,7 +282,7 @@ unittest.TestCase.__init__(self, *args, **kw) try: self.open_mapping_file().close() # test it to report the error early - except (IOError, HTTPException): + except (OSError, HTTPException): self.skipTest("Could not retrieve "+self.mapfileurl) def open_mapping_file(self): diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -506,7 +506,7 @@ next_test = fp.read().strip() tests = [next_test] fp.close() - except IOError: + except OSError: pass if fromfile: diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py --- a/Lib/test/sortperf.py +++ b/Lib/test/sortperf.py @@ -22,7 +22,7 @@ fn = os.path.join(td, "rr%06d" % n) try: fp = open(fn, "rb") - except IOError: + except OSError: r = random.random result = [r() for i in range(n)] try: @@ -37,7 +37,7 @@ os.unlink(fn) except OSError: pass - except IOError as msg: + except OSError as msg: print("can't write", fn, ":", msg) else: result = marshal.load(fp) diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -1097,9 +1097,9 @@ # Context managers that raise ResourceDenied when various issues # with the Internet connection manifest themselves as exceptions. # XXX deprecate these and use transient_internet() instead -time_out = TransientResource(IOError, errno=errno.ETIMEDOUT) +time_out = TransientResource(OSError, errno=errno.ETIMEDOUT) socket_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) -ioerror_peer_reset = TransientResource(IOError, errno=errno.ECONNRESET) +ioerror_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET) @contextlib.contextmanager @@ -1145,17 +1145,17 @@ if timeout is not None: socket.setdefaulttimeout(timeout) yield - except IOError as err: + except OSError as err: # urllib can wrap original socket errors multiple times (!), we must # unwrap to get at the original error. while True: a = err.args - if len(a) >= 1 and isinstance(a[0], IOError): + if len(a) >= 1 and isinstance(a[0], OSError): err = a[0] # The error can also be wrapped as args[1]: # except socket.error as msg: - # raise IOError('socket error', msg).with_traceback(sys.exc_info()[2]) - elif len(a) >= 2 and isinstance(a[1], IOError): + # raise OSError('socket error', msg).with_traceback(sys.exc_info()[2]) + elif len(a) >= 2 and isinstance(a[1], OSError): err = a[1] else: break diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -355,12 +355,12 @@ support.unlink(support.TESTFN) def test_fromfile_ioerror(self): - # Issue #5395: Check if fromfile raises a proper IOError + # Issue #5395: Check if fromfile raises a proper OSError # instead of EOFError. a = array.array(self.typecode) f = open(support.TESTFN, 'wb') try: - self.assertRaises(IOError, a.fromfile, f, len(self.example)) + self.assertRaises(OSError, a.fromfile, f, len(self.example)) finally: f.close() support.unlink(support.TESTFN) diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py --- a/Lib/test/test_bz2.py +++ b/Lib/test/test_bz2.py @@ -253,8 +253,8 @@ bz2f.write(b"abc") with BZ2File(self.filename, "r") as bz2f: - self.assertRaises(IOError, bz2f.write, b"a") - self.assertRaises(IOError, bz2f.writelines, [b"a"]) + self.assertRaises(OSError, bz2f.write, b"a") + self.assertRaises(OSError, bz2f.writelines, [b"a"]) def testAppend(self): with BZ2File(self.filename, "w") as bz2f: @@ -429,7 +429,7 @@ del o def testOpenNonexistent(self): - self.assertRaises(IOError, BZ2File, "/non/existent") + self.assertRaises(OSError, BZ2File, "/non/existent") def testReadlinesNoNewline(self): # Issue #1191043: readlines() fails on a file containing no newline. diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -136,12 +136,12 @@ return 10; def __getitem__(self, i): if i > 2: - raise IOError - self.assertRaises(IOError, self._write_test, BadList(), '') + raise OSError + self.assertRaises(OSError, self._write_test, BadList(), '') class BadItem: def __str__(self): - raise IOError - self.assertRaises(IOError, self._write_test, [BadItem()], '') + raise OSError + self.assertRaises(OSError, self._write_test, [BadItem()], '') def test_write_bigfield(self): # This exercises the buffer realloc functionality @@ -186,9 +186,9 @@ def test_writerows(self): class BrokenFile: def write(self, buf): - raise IOError + raise OSError writer = csv.writer(BrokenFile()) - self.assertRaises(IOError, writer.writerows, [['a']]) + self.assertRaises(OSError, writer.writerows, [['a']]) with TemporaryFile("w+", newline='') as fileobj: writer = csv.writer(fileobj) diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -57,7 +57,7 @@ return keys def test_error(self): - self.assertTrue(issubclass(self.module.error, IOError)) + self.assertTrue(issubclass(self.module.error, OSError)) def test_anydbm_not_existing(self): self.assertRaises(dbm.error, dbm.open, _fname) diff --git a/Lib/test/test_email/torture_test.py b/Lib/test/test_email/torture_test.py --- a/Lib/test/test_email/torture_test.py +++ b/Lib/test/test_email/torture_test.py @@ -27,7 +27,7 @@ # Prevent this test from running in the Python distro try: openfile('crispin-torture.txt') -except IOError: +except OSError: raise TestSkipped diff --git a/Lib/test/test_epoll.py b/Lib/test/test_epoll.py --- a/Lib/test/test_epoll.py +++ b/Lib/test/test_epoll.py @@ -33,7 +33,7 @@ try: select.epoll() -except IOError as e: +except OSError as e: if e.errno == errno.ENOSYS: raise unittest.SkipTest("kernel doesn't support epoll()") raise @@ -122,12 +122,12 @@ # ValueError: file descriptor cannot be a negative integer (-1) self.assertRaises(ValueError, ep.register, -1, select.EPOLLIN | select.EPOLLOUT) - # IOError: [Errno 9] Bad file descriptor - self.assertRaises(IOError, ep.register, 10000, + # OSError: [Errno 9] Bad file descriptor + self.assertRaises(OSError, ep.register, 10000, select.EPOLLIN | select.EPOLLOUT) # registering twice also raises an exception ep.register(server, select.EPOLLIN | select.EPOLLOUT) - self.assertRaises(IOError, ep.register, server, + self.assertRaises(OSError, ep.register, server, select.EPOLLIN | select.EPOLLOUT) finally: ep.close() @@ -149,7 +149,7 @@ ep.close() try: ep2.poll(1, 4) - except IOError as e: + except OSError as e: self.assertEqual(e.args[0], errno.EBADF, e) else: self.fail("epoll on closed fd didn't raise EBADF") diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -244,16 +244,16 @@ {'args' : ('foo', 1)}), (SystemExit, ('foo',), {'args' : ('foo',), 'code' : 'foo'}), - (IOError, ('foo',), + (OSError, ('foo',), {'args' : ('foo',), 'filename' : None, 'errno' : None, 'strerror' : None}), - (IOError, ('foo', 'bar'), + (OSError, ('foo', 'bar'), {'args' : ('foo', 'bar'), 'filename' : None, 'errno' : 'foo', 'strerror' : 'bar'}), - (IOError, ('foo', 'bar', 'baz'), + (OSError, ('foo', 'bar', 'baz'), {'args' : ('foo', 'bar'), 'filename' : 'baz', 'errno' : 'foo', 'strerror' : 'bar'}), - (IOError, ('foo', 'bar', 'baz', 'quux'), + (OSError, ('foo', 'bar', 'baz', 'quux'), {'args' : ('foo', 'bar', 'baz', 'quux')}), (OSError, ('errnoStr', 'strErrorStr', 'filenameStr'), {'args' : ('errnoStr', 'strErrorStr'), diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -87,7 +87,7 @@ self.assertTrue(not f.closed) if hasattr(f, "readinto"): - self.assertRaises((IOError, TypeError), f.readinto, "") + self.assertRaises((OSError, TypeError), f.readinto, "") f.close() self.assertTrue(f.closed) @@ -126,7 +126,7 @@ self.assertEqual(self.f.__exit__(*sys.exc_info()), None) def testReadWhenWriting(self): - self.assertRaises(IOError, self.f.read) + self.assertRaises(OSError, self.f.read) class CAutoFileTests(AutoFileTests): open = io.open @@ -151,12 +151,12 @@ def testStdin(self): # This causes the interpreter to exit on OSF1 v5.1. if sys.platform != 'osf1V5': - self.assertRaises((IOError, ValueError), sys.stdin.seek, -1) + self.assertRaises((OSError, ValueError), sys.stdin.seek, -1) else: print(( ' Skipping sys.stdin.seek(-1), it may crash the interpreter.' ' Test manually.'), file=sys.__stdout__) - self.assertRaises((IOError, ValueError), sys.stdin.truncate) + self.assertRaises((OSError, ValueError), sys.stdin.truncate) def testBadModeArgument(self): # verify that we get a sensible error message for bad mode argument @@ -187,7 +187,7 @@ d = int(f.read().decode("ascii")) f.close() f.close() - except IOError as msg: + except OSError as msg: self.fail('error setting buffer size %d: %s' % (s, str(msg))) self.assertEqual(d, s) diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py --- a/Lib/test/test_fileinput.py +++ b/Lib/test/test_fileinput.py @@ -275,8 +275,8 @@ try: t1 = writeTmp(1, [""]) with FileInput(files=t1) as fi: - raise IOError - except IOError: + raise OSError + except OSError: self.assertEqual(fi._files, ()) finally: remove_tempfiles(t1) diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -144,16 +144,16 @@ # Unix calls dircheck() and returns "[Errno 21]: Is a directory" try: _FileIO('.', 'r') - except IOError as e: + except OSError as e: self.assertNotEqual(e.errno, 0) self.assertEqual(e.filename, ".") else: - self.fail("Should have raised IOError") + self.fail("Should have raised OSError") @unittest.skipIf(os.name == 'nt', "test only works on a POSIX-like system") def testOpenDirFD(self): fd = os.open('.', os.O_RDONLY) - with self.assertRaises(IOError) as cm: + with self.assertRaises(OSError) as cm: _FileIO(fd, 'r') os.close(fd) self.assertEqual(cm.exception.errno, errno.EISDIR) @@ -171,7 +171,7 @@ finally: try: self.f.close() - except IOError: + except OSError: pass return wrapper @@ -183,14 +183,14 @@ os.close(f.fileno()) try: func(self, f) - except IOError as e: + except OSError as e: self.assertEqual(e.errno, errno.EBADF) else: - self.fail("Should have raised IOError") + self.fail("Should have raised OSError") finally: try: self.f.close() - except IOError: + except OSError: pass return wrapper @@ -237,7 +237,7 @@ def ReopenForRead(self): try: self.f.close() - except IOError: + except OSError: pass self.f = _FileIO(TESTFN, 'r') os.close(self.f.fileno()) @@ -346,7 +346,7 @@ self.assertRaises(OSError, _FileIO, make_bad_fd()) if sys.platform == 'win32': import msvcrt - self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd()) + self.assertRaises(OSError, msvcrt.get_osfhandle, make_bad_fd()) def testBadModeArgument(self): # verify that we get a sensible error message for bad mode argument diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -482,7 +482,7 @@ def test_all_errors(self): exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm, - ftplib.error_proto, ftplib.Error, IOError, EOFError) + ftplib.error_proto, ftplib.Error, OSError, EOFError) for x in exceptions: try: raise x('exception not included in all_errors set') @@ -721,7 +721,7 @@ source_address=(HOST, port)) self.assertEqual(self.client.sock.getsockname()[1], port) self.client.quit() - except IOError as e: + except OSError as e: if e.errno == errno.EADDRINUSE: self.skipTest("couldn't bind to port %d" % port) raise @@ -732,7 +732,7 @@ try: with self.client.transfercmd('list') as sock: self.assertEqual(sock.getsockname()[1], port) - except IOError as e: + except OSError as e: if e.errno == errno.EADDRINUSE: self.skipTest("couldn't bind to port %d" % port) raise diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -114,7 +114,7 @@ # Naked sockets return empty strings.. return line += part - except IOError: + except OSError: # ..but SSLSockets raise exceptions. return if line.endswith(b'\r\n'): diff --git a/Lib/test/test_importlib/source/test_abc_loader.py b/Lib/test/test_importlib/source/test_abc_loader.py --- a/Lib/test/test_importlib/source/test_abc_loader.py +++ b/Lib/test/test_importlib/source/test_abc_loader.py @@ -59,7 +59,7 @@ elif path == self.bytecode_path: return self.bytecode else: - raise IOError + raise OSError def path_stats(self, path): assert path == self.path @@ -125,12 +125,12 @@ def test_get_source(self): # Verify the source code is returned as a string. - # If an IOError is raised by get_data then raise ImportError. + # If an OSError is raised by get_data then raise ImportError. expected_source = self.loader.source.decode('utf-8') self.assertEqual(self.loader.get_source(self.name), expected_source) - def raise_IOError(path): - raise IOError - self.loader.get_data = raise_IOError + def raise_OSError(path): + raise OSError + self.loader.get_data = raise_OSError with self.assertRaises(ImportError) as cm: self.loader.get_source(self.name) self.assertEqual(cm.exception.name, self.name) @@ -216,7 +216,7 @@ # If no bytecode exists then move on to the source. self.loader.bytecode_path = "" # Sanity check - with self.assertRaises(IOError): + with self.assertRaises(OSError): bytecode_path = imp.cache_from_source(self.path) self.loader.get_data(bytecode_path) code_object = self.loader.get_code(self.name) @@ -265,7 +265,7 @@ self.loader.__class__.set_data = original_set_data def test_set_data_raises_exceptions(self): - # Raising NotImplementedError or IOError is okay for set_data. + # Raising NotImplementedError or OSError is okay for set_data. def raise_exception(exc): def closure(*args, **kwargs): raise exc diff --git a/Lib/test/test_importlib/source/test_file_loader.py b/Lib/test/test_importlib/source/test_file_loader.py --- a/Lib/test/test_importlib/source/test_file_loader.py +++ b/Lib/test/test_importlib/source/test_file_loader.py @@ -407,7 +407,7 @@ os.chmod(bytecode_path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) try: - # Should not raise IOError! + # Should not raise OSError! self.import_(mapping['_temp'], '_temp') finally: # Make writable for eventual clean-up. diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -401,14 +401,14 @@ unicodedata.__file__[-4:] in (".pyc", ".pyo"), "unicodedata is not an external binary module") def test_findsource_binary(self): - self.assertRaises(IOError, inspect.getsource, unicodedata) - self.assertRaises(IOError, inspect.findsource, unicodedata) + self.assertRaises(OSError, inspect.getsource, unicodedata) + self.assertRaises(OSError, inspect.findsource, unicodedata) def test_findsource_code_in_linecache(self): lines = ["x=1"] co = compile(lines[0], "_dynamically_created_file", "exec") - self.assertRaises(IOError, inspect.findsource, co) - self.assertRaises(IOError, inspect.getsource, co) + self.assertRaises(OSError, inspect.findsource, co) + self.assertRaises(OSError, inspect.getsource, co) linecache.cache[co.co_filename] = (1, None, lines, co.co_filename) try: self.assertEqual(inspect.findsource(co), (lines,0)) diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -164,7 +164,7 @@ def close(self): if not self.closed: self.closed = 1 - raise IOError + raise OSError class CCloseFailureIO(CloseFailureIO, io.RawIOBase): pass @@ -600,9 +600,9 @@ def test_flush_error_on_close(self): f = self.open(support.TESTFN, "wb", buffering=0) def bad_flush(): - raise IOError() + raise OSError() f.flush = bad_flush - self.assertRaises(IOError, f.close) # exception not swallowed + self.assertRaises(OSError, f.close) # exception not swallowed self.assertTrue(f.closed) def test_multi_close(self): @@ -761,7 +761,7 @@ if s: # The destructor *may* have printed an unraisable error, check it self.assertEqual(len(s.splitlines()), 1) - self.assertTrue(s.startswith("Exception IOError: "), s) + self.assertTrue(s.startswith("Exception OSError: "), s) self.assertTrue(s.endswith(" ignored"), s) def test_repr(self): @@ -777,22 +777,22 @@ def test_flush_error_on_close(self): raw = self.MockRawIO() def bad_flush(): - raise IOError() + raise OSError() raw.flush = bad_flush b = self.tp(raw) - self.assertRaises(IOError, b.close) # exception not swallowed + self.assertRaises(OSError, b.close) # exception not swallowed self.assertTrue(b.closed) def test_close_error_on_close(self): raw = self.MockRawIO() def bad_flush(): - raise IOError('flush') + raise OSError('flush') def bad_close(): - raise IOError('close') + raise OSError('close') raw.close = bad_close b = self.tp(raw) b.flush = bad_flush - with self.assertRaises(IOError) as err: # exception not swallowed + with self.assertRaises(OSError) as err: # exception not swallowed b.close() self.assertEqual(err.exception.args, ('close',)) self.assertEqual(err.exception.__context__.args, ('flush',)) @@ -1014,8 +1014,8 @@ def test_misbehaved_io(self): rawio = self.MisbehavedRawIO((b"abc", b"d", b"efg")) bufio = self.tp(rawio) - self.assertRaises(IOError, bufio.seek, 0) - self.assertRaises(IOError, bufio.tell) + self.assertRaises(OSError, bufio.seek, 0) + self.assertRaises(OSError, bufio.tell) def test_no_extraneous_read(self): # Issue #9550; when the raw IO object has satisfied the read request, @@ -1066,7 +1066,7 @@ bufio = self.tp(rawio) # _pyio.BufferedReader seems to implement reading different, so that # checking this is not so easy. - self.assertRaises(IOError, bufio.read, 10) + self.assertRaises(OSError, bufio.read, 10) def test_garbage_collection(self): # C BufferedReader objects are collected. @@ -1313,9 +1313,9 @@ def test_misbehaved_io(self): rawio = self.MisbehavedRawIO() bufio = self.tp(rawio, 5) - self.assertRaises(IOError, bufio.seek, 0) - self.assertRaises(IOError, bufio.tell) - self.assertRaises(IOError, bufio.write, b"abcdef") + self.assertRaises(OSError, bufio.seek, 0) + self.assertRaises(OSError, bufio.tell) + self.assertRaises(OSError, bufio.write, b"abcdef") def test_max_buffer_size_removal(self): with self.assertRaises(TypeError): @@ -1324,11 +1324,11 @@ def test_write_error_on_close(self): raw = self.MockRawIO() def bad_write(b): - raise IOError() + raise OSError() raw.write = bad_write b = self.tp(raw) b.write(b'spam') - self.assertRaises(IOError, b.close) # exception not swallowed + self.assertRaises(OSError, b.close) # exception not swallowed self.assertTrue(b.closed) @@ -1393,14 +1393,14 @@ def readable(self): return False - self.assertRaises(IOError, self.tp, NotReadable(), self.MockRawIO()) + self.assertRaises(OSError, self.tp, NotReadable(), self.MockRawIO()) def test_constructor_with_not_writeable(self): class NotWriteable(MockRawIO): def writable(self): return False - self.assertRaises(IOError, self.tp, self.MockRawIO(), NotWriteable()) + self.assertRaises(OSError, self.tp, self.MockRawIO(), NotWriteable()) def test_read(self): pair = self.tp(self.BytesIO(b"abcdef"), self.MockRawIO()) @@ -2146,7 +2146,7 @@ if s: # The destructor *may* have printed an unraisable error, check it self.assertEqual(len(s.splitlines()), 1) - self.assertTrue(s.startswith("Exception IOError: "), s) + self.assertTrue(s.startswith("Exception OSError: "), s) self.assertTrue(s.endswith(" ignored"), s) # Systematic tests of the text I/O API @@ -2218,7 +2218,7 @@ f.seek(0) for line in f: self.assertEqual(line, "\xff\n") - self.assertRaises(IOError, f.tell) + self.assertRaises(OSError, f.tell) self.assertEqual(f.tell(), p2) f.close() @@ -2322,7 +2322,7 @@ def readable(self): return False txt = self.TextIOWrapper(UnReadable()) - self.assertRaises(IOError, txt.read) + self.assertRaises(OSError, txt.read) def test_read_one_by_one(self): txt = self.TextIOWrapper(self.BytesIO(b"AA\r\nBB")) @@ -2497,9 +2497,9 @@ def test_flush_error_on_close(self): txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii") def bad_flush(): - raise IOError() + raise OSError() txt.flush = bad_flush - self.assertRaises(IOError, txt.close) # exception not swallowed + self.assertRaises(OSError, txt.close) # exception not swallowed self.assertTrue(txt.closed) def test_multi_close(self): @@ -3032,7 +3032,7 @@ # buffer, and block again. try: wio.close() - except IOError as e: + except OSError as e: if e.errno != errno.EBADF: raise @@ -3160,7 +3160,7 @@ # buffer, and could block (in case of failure). try: wio.close() - except IOError as e: + except OSError as e: if e.errno != errno.EBADF: raise diff --git a/Lib/test/test_ioctl.py b/Lib/test/test_ioctl.py --- a/Lib/test/test_ioctl.py +++ b/Lib/test/test_ioctl.py @@ -8,7 +8,7 @@ try: tty = open("/dev/tty", "rb") -except IOError: +except OSError: raise unittest.SkipTest("Unable to open /dev/tty") else: # Skip if another process is in foreground diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -14,7 +14,7 @@ import signal # The default handler for SIGXFSZ is to abort the process. # By ignoring it, system calls exceeding the file size resource - # limit will raise IOError instead of crashing the interpreter. + # limit will raise OSError instead of crashing the interpreter. oldhandler = signal.signal(signal.SIGXFSZ, signal.SIG_IGN) except (ImportError, AttributeError): pass @@ -162,7 +162,7 @@ # flush, too! f.write(b'x') f.flush() - except (IOError, OverflowError): + except (OSError, OverflowError): f.close() unlink(TESTFN) raise unittest.SkipTest("filesystem does not have largefile support") diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3183,13 +3183,13 @@ self.assertEqual('0 - release', self.called[-1]) def test_with_ioerror_in_acquire(self): - self._test_with_failure_in_method('acquire', IOError) + self._test_with_failure_in_method('acquire', OSError) def test_with_ioerror_in_flush(self): - self._test_with_failure_in_method('flush', IOError) + self._test_with_failure_in_method('flush', OSError) def test_with_ioerror_in_close(self): - self._test_with_failure_in_method('close', IOError) + self._test_with_failure_in_method('close', OSError) def test_with_valueerror_in_acquire(self): self._test_with_failure_in_method('acquire', ValueError) diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -520,12 +520,12 @@ def test_relative_seek(self): memio = self.ioclass() - self.assertRaises(IOError, memio.seek, -1, 1) - self.assertRaises(IOError, memio.seek, 3, 1) - self.assertRaises(IOError, memio.seek, -3, 1) - self.assertRaises(IOError, memio.seek, -1, 2) - self.assertRaises(IOError, memio.seek, 1, 1) - self.assertRaises(IOError, memio.seek, 1, 2) + self.assertRaises(OSError, memio.seek, -1, 1) + self.assertRaises(OSError, memio.seek, 3, 1) + self.assertRaises(OSError, memio.seek, -3, 1) + self.assertRaises(OSError, memio.seek, -1, 2) + self.assertRaises(OSError, memio.seek, 1, 1) + self.assertRaises(OSError, memio.seek, 1, 2) def test_textio_properties(self): memio = self.ioclass() diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -684,11 +684,11 @@ self.assertTrue(m.closed) def test_context_manager_exception(self): - # Test that the IOError gets passed through + # Test that the OSError gets passed through with self.assertRaises(Exception) as exc: with mmap.mmap(-1, 10) as m: - raise IOError - self.assertIsInstance(exc.exception, IOError, + raise OSError + self.assertIsInstance(exc.exception, OSError, "wrong exception raised in context manager") self.assertTrue(m.closed, "context manager failed") @@ -709,7 +709,7 @@ f.seek(num_zeroes) f.write(tail) f.flush() - except (IOError, OverflowError): + except (OSError, OverflowError): f.close() raise unittest.SkipTest("filesystem does not have largefile support") return f diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -2019,7 +2019,7 @@ address=addr, authkey=authkey, serializer=SERIALIZER) try: manager.start() - except IOError as e: + except OSError as e: if e.errno != errno.EADDRINUSE: raise # Retry after some time, in case the old socket was lingering @@ -2132,9 +2132,9 @@ self.assertEqual(reader.writable, False) self.assertEqual(writer.readable, False) self.assertEqual(writer.writable, True) - self.assertRaises(IOError, reader.send, 2) - self.assertRaises(IOError, writer.recv) - self.assertRaises(IOError, writer.poll) + self.assertRaises(OSError, reader.send, 2) + self.assertRaises(OSError, writer.recv) + self.assertRaises(OSError, writer.poll) def test_spawn_close(self): # We test that a pipe connection can be closed by parent @@ -2296,8 +2296,8 @@ if self.TYPE == 'processes': self.assertTrue(a.closed) self.assertTrue(b.closed) - self.assertRaises(IOError, a.recv) - self.assertRaises(IOError, b.recv) + self.assertRaises(OSError, a.recv) + self.assertRaises(OSError, b.recv) class _TestListener(BaseTestCase): @@ -2318,7 +2318,7 @@ self.assertEqual(d.recv(), 1729) if self.TYPE == 'processes': - self.assertRaises(IOError, l.accept) + self.assertRaises(OSError, l.accept) class _TestListenerClient(BaseTestCase): @@ -2866,12 +2866,12 @@ def test_invalid_handles(self): conn = multiprocessing.connection.Connection(44977608) try: - self.assertRaises((ValueError, IOError), conn.poll) + self.assertRaises((ValueError, OSError), conn.poll) finally: # Hack private attribute _handle to avoid printing an error # in conn.__del__ conn._handle = None - self.assertRaises((ValueError, IOError), + self.assertRaises((ValueError, OSError), multiprocessing.connection.Connection, -1) # diff --git a/Lib/test/test_normalization.py b/Lib/test/test_normalization.py --- a/Lib/test/test_normalization.py +++ b/Lib/test/test_normalization.py @@ -43,7 +43,7 @@ try: testdata = open_urlresource(TESTDATAURL, encoding="utf-8", check=check_version) - except (IOError, HTTPException): + except (OSError, HTTPException): self.skipTest("Could not retrieve " + TESTDATAURL) self.addCleanup(testdata.close) for line in testdata: diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -44,7 +44,7 @@ def play_sound_file(self, data, rate, ssize, nchannels): try: dsp = ossaudiodev.open('w') - except IOError as msg: + except OSError as msg: if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): raise unittest.SkipTest(msg) @@ -190,7 +190,7 @@ def test_main(): try: dsp = ossaudiodev.open('w') - except (ossaudiodev.error, IOError) as msg: + except (ossaudiodev.error, OSError) as msg: if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): raise unittest.SkipTest(msg) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -550,7 +550,7 @@ self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags) try: fd = open(target_file, 'w+') - except IOError as e: + except OSError as e: self.assertEqual(e.errno, errno.EPERM) finally: posix.chflags(target_file, st.st_flags) diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -61,7 +61,7 @@ for i in range(5): time.sleep(.1) f.flush() - except IOError: + except OSError: if not limit_set: raise if limit_set: diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -1515,7 +1515,7 @@ self._exited_with = exc_type, exc_val, exc_tb if self._raise_in_exit: self._raised = True - raise IOError("Cannot close") + raise OSError("Cannot close") return self._suppress_at_exit def tearDown(self): @@ -1529,12 +1529,12 @@ def test_w_source_open_fails(self): def _open(filename, mode='r'): if filename == 'srcfile': - raise IOError('Cannot open "srcfile"') + raise OSError('Cannot open "srcfile"') assert 0 # shouldn't reach here. self._set_shutil_open(_open) - self.assertRaises(IOError, shutil.copyfile, 'srcfile', 'destfile') + self.assertRaises(OSError, shutil.copyfile, 'srcfile', 'destfile') def test_w_dest_open_fails(self): @@ -1544,14 +1544,14 @@ if filename == 'srcfile': return srcfile if filename == 'destfile': - raise IOError('Cannot open "destfile"') + raise OSError('Cannot open "destfile"') assert 0 # shouldn't reach here. self._set_shutil_open(_open) shutil.copyfile('srcfile', 'destfile') self.assertTrue(srcfile._entered) - self.assertTrue(srcfile._exited_with[0] is IOError) + self.assertTrue(srcfile._exited_with[0] is OSError) self.assertEqual(srcfile._exited_with[1].args, ('Cannot open "destfile"',)) @@ -1573,7 +1573,7 @@ self.assertTrue(srcfile._entered) self.assertTrue(destfile._entered) self.assertTrue(destfile._raised) - self.assertTrue(srcfile._exited_with[0] is IOError) + self.assertTrue(srcfile._exited_with[0] is OSError) self.assertEqual(srcfile._exited_with[1].args, ('Cannot close',)) @@ -1591,7 +1591,7 @@ self._set_shutil_open(_open) - self.assertRaises(IOError, + self.assertRaises(OSError, shutil.copyfile, 'srcfile', 'destfile') self.assertTrue(srcfile._entered) self.assertTrue(destfile._entered) diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -222,7 +222,7 @@ self.assertEqual(smtp.source_address, ('127.0.0.1', port)) self.assertEqual(smtp.local_hostname, 'localhost') smtp.quit() - except IOError as e: + except OSError as e: if e.errno == errno.EADDRINUSE: self.skipTest("couldn't bind to port %d" % port) raise diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -3723,7 +3723,7 @@ # First read raises a timeout self.assertRaises(socket.timeout, self.read_file.read, 1) # Second read is disallowed - with self.assertRaises(IOError) as ctx: + with self.assertRaises(OSError) as ctx: self.read_file.read(1) self.assertIn("cannot read from timed out object", str(ctx.exception)) diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -246,15 +246,15 @@ s = ssl.wrap_socket(sock, server_side=True, certfile=CERTFILE) self.assertRaisesRegex(ValueError, "can't connect in server-side mode", s.connect, (HOST, 8080)) - with self.assertRaises(IOError) as cm: + with self.assertRaises(OSError) as cm: with socket.socket() as sock: ssl.wrap_socket(sock, certfile=WRONGCERT) self.assertEqual(cm.exception.errno, errno.ENOENT) - with self.assertRaises(IOError) as cm: + with self.assertRaises(OSError) as cm: with socket.socket() as sock: ssl.wrap_socket(sock, certfile=CERTFILE, keyfile=WRONGCERT) self.assertEqual(cm.exception.errno, errno.ENOENT) - with self.assertRaises(IOError) as cm: + with self.assertRaises(OSError) as cm: with socket.socket() as sock: ssl.wrap_socket(sock, certfile=WRONGCERT, keyfile=WRONGCERT) self.assertEqual(cm.exception.errno, errno.ENOENT) @@ -442,7 +442,7 @@ ctx.load_cert_chain(CERTFILE) ctx.load_cert_chain(CERTFILE, keyfile=CERTFILE) self.assertRaises(TypeError, ctx.load_cert_chain, keyfile=CERTFILE) - with self.assertRaises(IOError) as cm: + with self.assertRaises(OSError) as cm: ctx.load_cert_chain(WRONGCERT) self.assertEqual(cm.exception.errno, errno.ENOENT) with self.assertRaisesRegex(ssl.SSLError, "PEM lib"): @@ -527,7 +527,7 @@ ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None) self.assertRaises(TypeError, ctx.load_verify_locations) self.assertRaises(TypeError, ctx.load_verify_locations, None, None) - with self.assertRaises(IOError) as cm: + with self.assertRaises(OSError) as cm: ctx.load_verify_locations(WRONGCERT) self.assertEqual(cm.exception.errno, errno.ENOENT) with self.assertRaisesRegex(ssl.SSLError, "PEM lib"): @@ -1229,11 +1229,11 @@ except OSError as x: if support.verbose: sys.stdout.write("\nOSError is %s\n" % x.args[1]) - except IOError as x: + except OSError as x: if x.errno != errno.ENOENT: raise if support.verbose: - sys.stdout.write("\IOError is %s\n" % str(x)) + sys.stdout.write("\OSError is %s\n" % str(x)) else: raise AssertionError("Use of invalid cert should have failed!") @@ -1387,7 +1387,7 @@ "badkey.pem")) def test_rude_shutdown(self): - """A brutal shutdown of an SSL server should raise an IOError + """A brutal shutdown of an SSL server should raise an OSError in the client when attempting handshake. """ listener_ready = threading.Event() @@ -1415,7 +1415,7 @@ listener_gone.wait() try: ssl_sock = ssl.wrap_socket(c) - except IOError: + except OSError: pass else: self.fail('connecting to closed SSL socket should have failed') diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -489,7 +489,7 @@ def test_bool(self): class ExplodingBool(object): def __bool__(self): - raise IOError + raise OSError for prefix in tuple("<>!=")+('',): false = (), [], [], '', 0 true = [1], 'test', 5, -1, 0xffffffff+1, 0xffffffff/2 @@ -520,10 +520,10 @@ try: struct.pack(prefix + '?', ExplodingBool()) - except IOError: + except OSError: pass else: - self.fail("Expected IOError: struct.pack(%r, " + self.fail("Expected OSError: struct.pack(%r, " "ExplodingBool())" % (prefix + '?')) for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']: 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 @@ -1662,20 +1662,20 @@ self.assertTrue(tar.closed, "context manager failed") def test_closed(self): - # The __enter__() method is supposed to raise IOError + # The __enter__() method is supposed to raise OSError # if the TarFile object is already closed. tar = tarfile.open(tarname) tar.close() - with self.assertRaises(IOError): + with self.assertRaises(OSError): with tar: pass def test_exception(self): - # Test if the IOError exception is passed through properly. + # Test if the OSError exception is passed through properly. with self.assertRaises(Exception) as exc: with tarfile.open(tarname) as tar: - raise IOError - self.assertIsInstance(exc.exception, IOError, + raise OSError + self.assertIsInstance(exc.exception, OSError, "wrong exception raised in context manager") self.assertTrue(tar.closed, "context manager failed") @@ -1753,7 +1753,7 @@ def test_non_existent_targz_file(self): # Test for issue11513: prevent non-existent gzipped tarfiles raising # multiple exceptions. - with self.assertRaisesRegex(IOError, "xxx") as ex: + with self.assertRaisesRegex(OSError, "xxx") as ex: tarfile.open("xxx", self.mode) self.assertEqual(ex.exception.errno, errno.ENOENT) diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -194,7 +194,7 @@ sock.connect((whitehole)) except socket.timeout: pass - except IOError as err: + except OSError as err: if err.errno == errno.ECONNREFUSED: skip = False finally: diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py --- a/Lib/test/test_ucn.py +++ b/Lib/test/test_ucn.py @@ -172,7 +172,7 @@ try: testdata = support.open_urlresource(url, encoding="utf-8", check=check_version) - except (IOError, HTTPException): + except (OSError, HTTPException): self.skipTest("Could not retrieve " + url) self.addCleanup(testdata.close) for line in testdata: diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -232,7 +232,7 @@ self.check_read(b"1.1") def test_read_bogus(self): - # urlopen() should raise IOError for many error codes. + # urlopen() should raise OSError for many error codes. self.fakehttp(b'''HTTP/1.1 401 Authentication Required Date: Wed, 02 Jan 2008 03:03:54 GMT Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e @@ -240,12 +240,12 @@ Content-Type: text/html; charset=iso-8859-1 ''') try: - self.assertRaises(IOError, urlopen, "http://python.org/") + self.assertRaises(OSError, urlopen, "http://python.org/") finally: self.unfakehttp() def test_invalid_redirect(self): - # urlopen() should raise IOError for many error codes. + # urlopen() should raise OSError for many error codes. self.fakehttp(b'''HTTP/1.1 302 Found Date: Wed, 02 Jan 2008 03:03:54 GMT Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e @@ -260,11 +260,11 @@ self.unfakehttp() def test_empty_socket(self): - # urlopen() raises IOError if the underlying socket does not send any + # urlopen() raises OSError if the underlying socket does not send any # data. (#1680230) self.fakehttp(b'') try: - self.assertRaises(IOError, urlopen, "http://something") + self.assertRaises(OSError, urlopen, "http://something") finally: self.unfakehttp() diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -522,7 +522,7 @@ def test_bad_address(self): # Make sure proper exception is raised when connecting to a bogus # address. - self.assertRaises(IOError, + self.assertRaises(OSError, # Given that both VeriSign and various ISPs have in # the past or are presently hijacking various invalid # domain name requests in an attempt to boost traffic diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py --- a/Lib/test/test_urllibnet.py +++ b/Lib/test/test_urllibnet.py @@ -121,7 +121,7 @@ else: # This happens with some overzealous DNS providers such as OpenDNS self.skipTest("%r should not resolve for test to work" % bogus_domain) - self.assertRaises(IOError, + self.assertRaises(OSError, # SF patch 809915: In Sep 2003, VeriSign started # highjacking invalid .com and .net addresses to # boost traffic to their own site. This test diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -929,7 +929,7 @@ try: with zipfile.ZipFile(TESTFN, 'a') as zf: zf.writestr(filename, content) - except IOError: + except OSError: self.fail('Could not append data to a non-existent zip file.') self.assertTrue(os.path.exists(TESTFN)) @@ -995,7 +995,7 @@ chk = zipfile.is_zipfile(fp) self.assertTrue(chk) - def test_non_existent_file_raises_IOError(self): + def test_non_existent_file_raises_OSError(self): # make sure we don't raise an AttributeError when a partially-constructed # ZipFile instance is finalized; this tests for regression on SF tracker # bug #403871. @@ -1007,7 +1007,7 @@ # it is ignored, but the user should be sufficiently annoyed by # the message on the output that regression will be noticed # quickly. - self.assertRaises(IOError, zipfile.ZipFile, TESTFN) + self.assertRaises(OSError, zipfile.ZipFile, TESTFN) def test_empty_file_raises_BadZipFile(self): f = open(TESTFN, 'w') @@ -1281,7 +1281,7 @@ def test_open_empty_file(self): # Issue 1710703: Check that opening a file with less than 22 bytes # raises a BadZipFile exception (rather than the previously unhelpful - # IOError) + # OSError) f = open(TESTFN, 'w') f.close() self.assertRaises(zipfile.BadZipFile, zipfile.ZipFile, TESTFN, 'r') diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -459,7 +459,7 @@ self.assertRaises(error, z.load_module, 'abc') self.assertRaises(error, z.get_code, 'abc') - self.assertRaises(IOError, z.get_data, 'abc') + self.assertRaises(OSError, z.get_data, 'abc') self.assertRaises(error, z.get_source, 'abc') self.assertRaises(error, z.is_package, 'abc') finally: diff --git a/Lib/token.py b/Lib/token.py --- a/Lib/token.py +++ b/Lib/token.py @@ -93,7 +93,7 @@ outFileName = args[1] try: fp = open(inFileName) - except IOError as err: + except OSError as err: sys.stdout.write("I/O error: %s\n" % str(err)) sys.exit(1) lines = fp.read().split("\n") @@ -112,7 +112,7 @@ # load the output skeleton from the target: try: fp = open(outFileName) - except IOError as err: + except OSError as err: sys.stderr.write("I/O error: %s\n" % str(err)) sys.exit(2) format = fp.read().split("\n") @@ -129,7 +129,7 @@ format[start:end] = lines try: fp = open(outFileName, 'w') - except IOError as err: + except OSError as err: sys.stderr.write("I/O error: %s\n" % str(err)) sys.exit(4) fp.write("\n".join(format)) diff --git a/Lib/tokenize.py b/Lib/tokenize.py --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -670,7 +670,7 @@ error(err.args[0], filename, (line, column)) except SyntaxError as err: error(err, filename) - except IOError as err: + except OSError as err: error(err) except KeyboardInterrupt: print("interrupted\n") diff --git a/Lib/trace.py b/Lib/trace.py --- a/Lib/trace.py +++ b/Lib/trace.py @@ -237,7 +237,7 @@ counts, calledfuncs, callers = \ pickle.load(open(self.infile, 'rb')) self.update(self.__class__(counts, calledfuncs, callers)) - except (IOError, EOFError, ValueError) as err: + except (OSError, EOFError, ValueError) as err: print(("Skipping counts file %r: %s" % (self.infile, err)), file=sys.stderr) @@ -347,7 +347,7 @@ try: pickle.dump((self.counts, self.calledfuncs, self.callers), open(self.outfile, 'wb'), 1) - except IOError as err: + except OSError as err: print("Can't save counts files because %s" % err, file=sys.stderr) def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None): @@ -355,7 +355,7 @@ try: outfile = open(path, "w", encoding=encoding) - except IOError as err: + except OSError as err: print(("trace: Could not open %r for writing: %s" "- skipping" % (path, err)), file=sys.stderr) return 0, 0 @@ -436,7 +436,7 @@ with tokenize.open(filename) as f: prog = f.read() encoding = f.encoding - except IOError as err: + except OSError as err: print(("Not printing coverage data for %r: %s" % (filename, err)), file=sys.stderr) return {} @@ -801,7 +801,7 @@ '__cached__': None, } t.runctx(code, globs, globs) - except IOError as err: + except OSError as err: _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err)) except SystemExit: pass diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -1,6 +1,6 @@ """Exception classes raised by urllib. -The base exception class is URLError, which inherits from IOError. It +The base exception class is URLError, which inherits from OSError. It doesn't define any behavior of its own, but is the base class for all exceptions defined in this package. @@ -17,11 +17,11 @@ # do these error classes make sense? -# make sure all of the IOError stuff is overridden. we just want to be +# make sure all of the OSError stuff is overridden. we just want to be # subtypes. -class URLError(IOError): - # URLError is a sub-type of IOError, but it doesn't share any of +class URLError(OSError): + # URLError is a sub-type of OSError, but it doesn't share any of # the implementation. need to override __init__ and __str__. # It sets self.args for compatibility with other EnvironmentError # subclasses, but args doesn't have the typical format with errno in diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -18,7 +18,7 @@ urllib. pass the url and optionally data to post to an HTTP URL, and get a file-like object back. One difference is that you can also pass a Request instance instead of URL. Raises a URLError (subclass of -IOError); for HTTP errors, raises an HTTPError, which can also be +OSError); for HTTP errors, raises an HTTPError, which can also be treated as a valid response. build_opener -- Function that creates a new OpenerDirector instance. @@ -1722,17 +1722,17 @@ except (HTTPError, URLError): raise except OSError as msg: - raise IOError('socket error', msg).with_traceback(sys.exc_info()[2]) + raise OSError('socket error', msg).with_traceback(sys.exc_info()[2]) def open_unknown(self, fullurl, data=None): """Overridable interface to open unknown URL type.""" type, url = splittype(fullurl) - raise IOError('url error', 'unknown url type', type) + raise OSError('url error', 'unknown url type', type) def open_unknown_proxy(self, proxy, fullurl, data=None): """Overridable interface to open unknown URL type.""" type, url = splittype(fullurl) - raise IOError('url error', 'invalid proxy for %s' % type, proxy) + raise OSError('url error', 'invalid proxy for %s' % type, proxy) # External interface def retrieve(self, url, filename=None, reporthook=None, data=None): @@ -1748,7 +1748,7 @@ hdrs = fp.info() fp.close() return url2pathname(splithost(url1)[1]), hdrs - except IOError as msg: + except OSError as msg: pass fp = self.open(url, data) try: @@ -1841,7 +1841,7 @@ if proxy_bypass(realhost): host = realhost - if not host: raise IOError('http error', 'no host given') + if not host: raise OSError('http error', 'no host given') if proxy_passwd: proxy_passwd = unquote(proxy_passwd) @@ -1914,7 +1914,7 @@ return self.http_error_default(url, fp, errcode, errmsg, headers) def http_error_default(self, url, fp, errcode, errmsg, headers): - """Default error handler: close the connection and raise IOError.""" + """Default error handler: close the connection and raise OSError.""" fp.close() raise HTTPError(url, errcode, errmsg, headers, None) @@ -2041,7 +2041,7 @@ try: [type, data] = url.split(',', 1) except ValueError: - raise IOError('data error', 'bad data URL') + raise OSError('data error', 'bad data URL') if not type: type = 'text/plain;charset=US-ASCII' semi = type.rfind(';') diff --git a/Lib/uuid.py b/Lib/uuid.py --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -329,7 +329,7 @@ if words[i] in hw_identifiers: return int( words[get_index(i)].replace(':', ''), 16) - except IOError: + except OSError: continue return None @@ -371,7 +371,7 @@ for dir in dirs: try: pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') - except IOError: + except OSError: continue else: for line in pipe: diff --git a/Lib/warnings.py b/Lib/warnings.py --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -16,7 +16,7 @@ file = sys.stderr try: file.write(formatwarning(message, category, filename, lineno, line)) - except IOError: + except OSError: pass # the file (probably stderr) is invalid - this warning gets lost. def formatwarning(message, category, filename, lineno, line=None): diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -422,7 +422,7 @@ # no good; attempt to clean it out, but don't fail: try: os.unlink(fn) - except IOError: + except OSError: pass else: return s diff --git a/Lib/xml/etree/ElementInclude.py b/Lib/xml/etree/ElementInclude.py --- a/Lib/xml/etree/ElementInclude.py +++ b/Lib/xml/etree/ElementInclude.py @@ -71,8 +71,8 @@ # @return The expanded resource. If the parse mode is "xml", this # is an ElementTree instance. If the parse mode is "text", this # is a Unicode string. If the loader fails, it can return None -# or raise an IOError exception. -# @throws IOError If the loader fails to load the resource. +# or raise an OSError exception. +# @throws OSError If the loader fails to load the resource. def default_loader(href, parse, encoding=None): if parse == "xml": @@ -95,7 +95,7 @@ # that implements the same interface as default_loader. # @throws FatalIncludeError If the function fails to include a given # resource, or if the tree contains malformed XInclude elements. -# @throws IOError If the function fails to load a given resource. +# @throws OSError If the function fails to load a given resource. def include(elem, loader=None): if loader is None: diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -1045,7 +1045,7 @@ gzf = gzip.GzipFile(mode="rb", fileobj=f) try: decoded = gzf.read() - except IOError: + except OSError: raise ValueError("invalid data") f.close() gzf.close() @@ -1386,7 +1386,7 @@ # get the url type, uri = urllib.parse.splittype(uri) if type not in ("http", "https"): - raise IOError("unsupported XML-RPC protocol") + raise OSError("unsupported XML-RPC protocol") self.__host, self.__handler = urllib.parse.splithost(uri) if not self.__handler: self.__handler = "/RPC2" diff --git a/Lib/zipfile.py b/Lib/zipfile.py --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -164,7 +164,7 @@ try: if _EndRecData(fp): return True # file has correct magic number - except IOError: + except OSError: pass return False @@ -180,7 +180,7 @@ else: with open(filename, "rb") as fp: result = _check_zipfile(fp) - except IOError: + except OSError: pass return result @@ -190,7 +190,7 @@ """ try: fpin.seek(offset - sizeEndCentDir64Locator, 2) - except IOError: + except OSError: # If the seek fails, the file is not large enough to contain a ZIP64 # end-of-archive record, so just return the end record we were given. return endrec @@ -238,7 +238,7 @@ # file if this is the case). try: fpin.seek(-sizeEndCentDir, 2) - except IOError: + except OSError: return None data = fpin.read() if data[0:4] == stringEndArchive and data[-2:] == b"\000\000": @@ -895,7 +895,7 @@ modeDict = {'r' : 'rb', 'w': 'wb', 'a' : 'r+b'} try: self.fp = io.open(file, modeDict[mode]) - except IOError: + except OSError: if mode == 'a': mode = key = 'w' self.fp = io.open(file, modeDict[mode]) @@ -946,7 +946,7 @@ fp = self.fp try: endrec = _EndRecData(fp) - except IOError: + except OSError: raise BadZipFile("File is not a zip file") if not endrec: raise BadZipFile("File is not a zip file") diff --git a/Python/Python-ast.c b/Python/Python-ast.c --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -2066,7 +2066,6 @@ *arena) { expr_ty p; - assert(PyUnicode_CompareWithASCIIString(id, "True") && PyUnicode_CompareWithASCIIString(id, "False") && PyUnicode_CompareWithASCIIString(id, "None")); if (!id) { PyErr_SetString(PyExc_ValueError, "field id is required for Name"); diff --git a/Python/importlib.h b/Python/importlib.h --- a/Python/importlib.h +++ b/Python/importlib.h [stripped] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:16:57 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 17:16:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NzYwOiB1c2Ug?= =?utf-8?q?ref=3A=60match-objects=60_instead_of_=3Aclass=3A=60MatchObject?= =?utf-8?b?YC4=?= Message-ID: <3YW2WY33PszRkk@mail.python.org> http://hg.python.org/cpython/rev/b11f98872c0f changeset: 81040:b11f98872c0f branch: 2.7 parent: 81035:a0f6c68ea12f user: Ezio Melotti date: Tue Dec 25 18:10:49 2012 +0200 summary: #16760: use ref:`match-objects` instead of :class:`MatchObject`. files: Doc/howto/regex.rst | 49 ++++++++++++++++---------------- 1 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -359,9 +359,9 @@ +------------------+-----------------------------------------------+ :meth:`match` and :meth:`search` return ``None`` if no match can be found. If -they're successful, a ``MatchObject`` instance is returned, containing -information about the match: where it starts and ends, the substring it matched, -and more. +they're successful, a :ref:`match object ` instance is returned, +containing information about the match: where it starts and ends, the substring +it matched, and more. You can learn about this by interactively experimenting with the :mod:`re` module. If you have Tkinter available, you may also want to look at @@ -392,16 +392,16 @@ None Now, let's try it on a string that it should match, such as ``tempo``. In this -case, :meth:`match` will return a :class:`MatchObject`, so you should store the -result in a variable for later use. :: +case, :meth:`match` will return a :ref:`match object `, so you +should store the result in a variable for later use. :: >>> m = p.match('tempo') >>> m #doctest: +ELLIPSIS <_sre.SRE_Match object at 0x...> -Now you can query the :class:`MatchObject` for information about the matching -string. :class:`MatchObject` instances also have several methods and -attributes; the most important ones are: +Now you can query the :ref:`match object ` for information +about the matching string. :ref:`match object ` instances +also have several methods and attributes; the most important ones are: +------------------+--------------------------------------------+ | Method/Attribute | Purpose | @@ -442,8 +442,9 @@ >>> m.span() (4, 11) -In actual programs, the most common style is to store the :class:`MatchObject` -in a variable, and then check if it was ``None``. This usually looks like:: +In actual programs, the most common style is to store the +:ref:`match object ` in a variable, and then check if it was +``None``. This usually looks like:: p = re.compile( ... ) m = p.match( 'string goes here' ) @@ -460,8 +461,8 @@ ['12', '11', '10'] :meth:`findall` has to create the entire list before it can be returned as the -result. The :meth:`finditer` method returns a sequence of :class:`MatchObject` -instances as an :term:`iterator`. [#]_ :: +result. The :meth:`finditer` method returns a sequence of +:ref:`match object ` instances as an :term:`iterator`. [#]_ :: >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...') >>> iterator #doctest: +ELLIPSIS @@ -482,7 +483,7 @@ :func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions take the same arguments as the corresponding pattern method, with the RE string added as the first argument, and still return either ``None`` or a -:class:`MatchObject` instance. :: +:ref:`match object ` instance. :: >>> print re.match(r'From\s+', 'Fromage amk') None @@ -791,9 +792,9 @@ index of the text that they match; this can be retrieved by passing an argument to :meth:`group`, :meth:`start`, :meth:`end`, and :meth:`span`. Groups are numbered starting with 0. Group 0 is always present; it's the whole RE, so -:class:`MatchObject` methods all have group 0 as their default argument. Later -we'll see how to express groups that don't capture the span of text that they -match. :: +:ref:`match object ` methods all have group 0 as their default +argument. Later we'll see how to express groups that don't capture the span +of text that they match. :: >>> p = re.compile('(a)b') >>> m = p.match('ab') @@ -913,10 +914,10 @@ The syntax for a named group is one of the Python-specific extensions: ``(?P...)``. *name* is, obviously, the name of the group. Named groups also behave exactly like capturing groups, and additionally associate a name -with a group. The :class:`MatchObject` methods that deal with capturing groups -all accept either integers that refer to the group by number or strings that -contain the desired group's name. Named groups are still given numbers, so you -can retrieve information about a group in two ways:: +with a group. The :ref:`match object ` methods that deal with +capturing groups all accept either integers that refer to the group by number +or strings that contain the desired group's name. Named groups are still +given numbers, so you can retrieve information about a group in two ways:: >>> p = re.compile(r'(?P\b\w+\b)') >>> m = p.search( '(((( Lots of punctuation )))' ) @@ -1180,11 +1181,11 @@ *replacement* can also be a function, which gives you even more control. If *replacement* is a function, the function is called for every non-overlapping -occurrence of *pattern*. On each call, the function is passed a -:class:`MatchObject` argument for the match and can use this information to -compute the desired replacement string and return it. +occurrence of *pattern*. On each call, the function is passed a +:ref:`match object ` argument for the match and can use this +information to compute the desired replacement string and return it. -In the following example, the replacement function translates decimals into +In the following example, the replacement function translates decimals into hexadecimal:: >>> def hexrepl(match): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:16:58 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 17:16:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2NzYwOiB1c2Ug?= =?utf-8?q?ref=3A=60match-objects=60_instead_of_=3Aclass=3A=60MatchObject?= =?utf-8?b?YC4=?= Message-ID: <3YW2WZ6mvyzRpj@mail.python.org> http://hg.python.org/cpython/rev/7c4ef8faeb4a changeset: 81041:7c4ef8faeb4a branch: 3.2 parent: 81036:2eab4f7b7280 user: Ezio Melotti date: Tue Dec 25 18:10:49 2012 +0200 summary: #16760: use ref:`match-objects` instead of :class:`MatchObject`. files: Doc/howto/regex.rst | 49 ++++++++++++++++---------------- 1 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -354,9 +354,9 @@ +------------------+-----------------------------------------------+ :meth:`match` and :meth:`search` return ``None`` if no match can be found. If -they're successful, a ``MatchObject`` instance is returned, containing -information about the match: where it starts and ends, the substring it matched, -and more. +they're successful, a :ref:`match object ` instance is returned, +containing information about the match: where it starts and ends, the substring +it matched, and more. You can learn about this by interactively experimenting with the :mod:`re` module. If you have :mod:`tkinter` available, you may also want to look at @@ -386,16 +386,16 @@ None Now, let's try it on a string that it should match, such as ``tempo``. In this -case, :meth:`match` will return a :class:`MatchObject`, so you should store the -result in a variable for later use. :: +case, :meth:`match` will return a :ref:`match object `, so you +should store the result in a variable for later use. :: >>> m = p.match('tempo') >>> m #doctest: +ELLIPSIS <_sre.SRE_Match object at 0x...> -Now you can query the :class:`MatchObject` for information about the matching -string. :class:`MatchObject` instances also have several methods and -attributes; the most important ones are: +Now you can query the :ref:`match object ` for information +about the matching string. :ref:`match object ` instances +also have several methods and attributes; the most important ones are: +------------------+--------------------------------------------+ | Method/Attribute | Purpose | @@ -436,8 +436,9 @@ >>> m.span() (4, 11) -In actual programs, the most common style is to store the :class:`MatchObject` -in a variable, and then check if it was ``None``. This usually looks like:: +In actual programs, the most common style is to store the +:ref:`match object ` in a variable, and then check if it was +``None``. This usually looks like:: p = re.compile( ... ) m = p.match( 'string goes here' ) @@ -454,8 +455,8 @@ ['12', '11', '10'] :meth:`findall` has to create the entire list before it can be returned as the -result. The :meth:`finditer` method returns a sequence of :class:`MatchObject` -instances as an :term:`iterator`:: +result. The :meth:`finditer` method returns a sequence of +:ref:`match object ` instances as an :term:`iterator`:: >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...') >>> iterator #doctest: +ELLIPSIS @@ -476,7 +477,7 @@ :func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions take the same arguments as the corresponding pattern method, with the RE string added as the first argument, and still return either ``None`` or a -:class:`MatchObject` instance. :: +:ref:`match object ` instance. :: >>> print(re.match(r'From\s+', 'Fromage amk')) None @@ -786,9 +787,9 @@ index of the text that they match; this can be retrieved by passing an argument to :meth:`group`, :meth:`start`, :meth:`end`, and :meth:`span`. Groups are numbered starting with 0. Group 0 is always present; it's the whole RE, so -:class:`MatchObject` methods all have group 0 as their default argument. Later -we'll see how to express groups that don't capture the span of text that they -match. :: +:ref:`match object ` methods all have group 0 as their default +argument. Later we'll see how to express groups that don't capture the span +of text that they match. :: >>> p = re.compile('(a)b') >>> m = p.match('ab') @@ -908,10 +909,10 @@ The syntax for a named group is one of the Python-specific extensions: ``(?P...)``. *name* is, obviously, the name of the group. Named groups also behave exactly like capturing groups, and additionally associate a name -with a group. The :class:`MatchObject` methods that deal with capturing groups -all accept either integers that refer to the group by number or strings that -contain the desired group's name. Named groups are still given numbers, so you -can retrieve information about a group in two ways:: +with a group. The :ref:`match object ` methods that deal with +capturing groups all accept either integers that refer to the group by number +or strings that contain the desired group's name. Named groups are still +given numbers, so you can retrieve information about a group in two ways:: >>> p = re.compile(r'(?P\b\w+\b)') >>> m = p.search( '(((( Lots of punctuation )))' ) @@ -1175,11 +1176,11 @@ *replacement* can also be a function, which gives you even more control. If *replacement* is a function, the function is called for every non-overlapping -occurrence of *pattern*. On each call, the function is passed a -:class:`MatchObject` argument for the match and can use this information to -compute the desired replacement string and return it. +occurrence of *pattern*. On each call, the function is passed a +:ref:`match object ` argument for the match and can use this +information to compute the desired replacement string and return it. -In the following example, the replacement function translates decimals into +In the following example, the replacement function translates decimals into hexadecimal:: >>> def hexrepl(match): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:17:00 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 17:17:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2316760=3A_merge_with_3=2E2=2E?= Message-ID: <3YW2Wc3ftzzRpn@mail.python.org> http://hg.python.org/cpython/rev/4ba1e90e0119 changeset: 81042:4ba1e90e0119 branch: 3.3 parent: 81037:356af3fc6471 parent: 81041:7c4ef8faeb4a user: Ezio Melotti date: Tue Dec 25 18:15:28 2012 +0200 summary: #16760: merge with 3.2. files: Doc/howto/regex.rst | 49 ++++++++++++++++---------------- 1 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -354,9 +354,9 @@ +------------------+-----------------------------------------------+ :meth:`match` and :meth:`search` return ``None`` if no match can be found. If -they're successful, a ``MatchObject`` instance is returned, containing -information about the match: where it starts and ends, the substring it matched, -and more. +they're successful, a :ref:`match object ` instance is returned, +containing information about the match: where it starts and ends, the substring +it matched, and more. You can learn about this by interactively experimenting with the :mod:`re` module. If you have :mod:`tkinter` available, you may also want to look at @@ -386,16 +386,16 @@ None Now, let's try it on a string that it should match, such as ``tempo``. In this -case, :meth:`match` will return a :class:`MatchObject`, so you should store the -result in a variable for later use. :: +case, :meth:`match` will return a :ref:`match object `, so you +should store the result in a variable for later use. :: >>> m = p.match('tempo') >>> m #doctest: +ELLIPSIS <_sre.SRE_Match object at 0x...> -Now you can query the :class:`MatchObject` for information about the matching -string. :class:`MatchObject` instances also have several methods and -attributes; the most important ones are: +Now you can query the :ref:`match object ` for information +about the matching string. :ref:`match object ` instances +also have several methods and attributes; the most important ones are: +------------------+--------------------------------------------+ | Method/Attribute | Purpose | @@ -436,8 +436,9 @@ >>> m.span() (4, 11) -In actual programs, the most common style is to store the :class:`MatchObject` -in a variable, and then check if it was ``None``. This usually looks like:: +In actual programs, the most common style is to store the +:ref:`match object ` in a variable, and then check if it was +``None``. This usually looks like:: p = re.compile( ... ) m = p.match( 'string goes here' ) @@ -454,8 +455,8 @@ ['12', '11', '10'] :meth:`findall` has to create the entire list before it can be returned as the -result. The :meth:`finditer` method returns a sequence of :class:`MatchObject` -instances as an :term:`iterator`:: +result. The :meth:`finditer` method returns a sequence of +:ref:`match object ` instances as an :term:`iterator`:: >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...') >>> iterator #doctest: +ELLIPSIS @@ -476,7 +477,7 @@ :func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions take the same arguments as the corresponding pattern method, with the RE string added as the first argument, and still return either ``None`` or a -:class:`MatchObject` instance. :: +:ref:`match object ` instance. :: >>> print(re.match(r'From\s+', 'Fromage amk')) None @@ -786,9 +787,9 @@ index of the text that they match; this can be retrieved by passing an argument to :meth:`group`, :meth:`start`, :meth:`end`, and :meth:`span`. Groups are numbered starting with 0. Group 0 is always present; it's the whole RE, so -:class:`MatchObject` methods all have group 0 as their default argument. Later -we'll see how to express groups that don't capture the span of text that they -match. :: +:ref:`match object ` methods all have group 0 as their default +argument. Later we'll see how to express groups that don't capture the span +of text that they match. :: >>> p = re.compile('(a)b') >>> m = p.match('ab') @@ -908,10 +909,10 @@ The syntax for a named group is one of the Python-specific extensions: ``(?P...)``. *name* is, obviously, the name of the group. Named groups also behave exactly like capturing groups, and additionally associate a name -with a group. The :class:`MatchObject` methods that deal with capturing groups -all accept either integers that refer to the group by number or strings that -contain the desired group's name. Named groups are still given numbers, so you -can retrieve information about a group in two ways:: +with a group. The :ref:`match object ` methods that deal with +capturing groups all accept either integers that refer to the group by number +or strings that contain the desired group's name. Named groups are still +given numbers, so you can retrieve information about a group in two ways:: >>> p = re.compile(r'(?P\b\w+\b)') >>> m = p.search( '(((( Lots of punctuation )))' ) @@ -1175,11 +1176,11 @@ *replacement* can also be a function, which gives you even more control. If *replacement* is a function, the function is called for every non-overlapping -occurrence of *pattern*. On each call, the function is passed a -:class:`MatchObject` argument for the match and can use this information to -compute the desired replacement string and return it. +occurrence of *pattern*. On each call, the function is passed a +:ref:`match object ` argument for the match and can use this +information to compute the desired replacement string and return it. -In the following example, the replacement function translates decimals into +In the following example, the replacement function translates decimals into hexadecimal:: >>> def hexrepl(match): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:17:01 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 25 Dec 2012 17:17:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogIzE2NzYwOiBtZXJnZSB3aXRoIDMuMy4=?= Message-ID: <3YW2Wf00tCzRp1@mail.python.org> http://hg.python.org/cpython/rev/f2222684dd2d changeset: 81043:f2222684dd2d parent: 81039:7d69d04522e3 parent: 81042:4ba1e90e0119 user: Ezio Melotti date: Tue Dec 25 18:16:31 2012 +0200 summary: #16760: merge with 3.3. files: Doc/howto/regex.rst | 49 ++++++++++++++++---------------- 1 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -354,9 +354,9 @@ +------------------+-----------------------------------------------+ :meth:`match` and :meth:`search` return ``None`` if no match can be found. If -they're successful, a ``MatchObject`` instance is returned, containing -information about the match: where it starts and ends, the substring it matched, -and more. +they're successful, a :ref:`match object ` instance is returned, +containing information about the match: where it starts and ends, the substring +it matched, and more. You can learn about this by interactively experimenting with the :mod:`re` module. If you have :mod:`tkinter` available, you may also want to look at @@ -386,16 +386,16 @@ None Now, let's try it on a string that it should match, such as ``tempo``. In this -case, :meth:`match` will return a :class:`MatchObject`, so you should store the -result in a variable for later use. :: +case, :meth:`match` will return a :ref:`match object `, so you +should store the result in a variable for later use. :: >>> m = p.match('tempo') >>> m #doctest: +ELLIPSIS <_sre.SRE_Match object at 0x...> -Now you can query the :class:`MatchObject` for information about the matching -string. :class:`MatchObject` instances also have several methods and -attributes; the most important ones are: +Now you can query the :ref:`match object ` for information +about the matching string. :ref:`match object ` instances +also have several methods and attributes; the most important ones are: +------------------+--------------------------------------------+ | Method/Attribute | Purpose | @@ -436,8 +436,9 @@ >>> m.span() (4, 11) -In actual programs, the most common style is to store the :class:`MatchObject` -in a variable, and then check if it was ``None``. This usually looks like:: +In actual programs, the most common style is to store the +:ref:`match object ` in a variable, and then check if it was +``None``. This usually looks like:: p = re.compile( ... ) m = p.match( 'string goes here' ) @@ -454,8 +455,8 @@ ['12', '11', '10'] :meth:`findall` has to create the entire list before it can be returned as the -result. The :meth:`finditer` method returns a sequence of :class:`MatchObject` -instances as an :term:`iterator`:: +result. The :meth:`finditer` method returns a sequence of +:ref:`match object ` instances as an :term:`iterator`:: >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...') >>> iterator #doctest: +ELLIPSIS @@ -476,7 +477,7 @@ :func:`search`, :func:`findall`, :func:`sub`, and so forth. These functions take the same arguments as the corresponding pattern method, with the RE string added as the first argument, and still return either ``None`` or a -:class:`MatchObject` instance. :: +:ref:`match object ` instance. :: >>> print(re.match(r'From\s+', 'Fromage amk')) None @@ -786,9 +787,9 @@ index of the text that they match; this can be retrieved by passing an argument to :meth:`group`, :meth:`start`, :meth:`end`, and :meth:`span`. Groups are numbered starting with 0. Group 0 is always present; it's the whole RE, so -:class:`MatchObject` methods all have group 0 as their default argument. Later -we'll see how to express groups that don't capture the span of text that they -match. :: +:ref:`match object ` methods all have group 0 as their default +argument. Later we'll see how to express groups that don't capture the span +of text that they match. :: >>> p = re.compile('(a)b') >>> m = p.match('ab') @@ -908,10 +909,10 @@ The syntax for a named group is one of the Python-specific extensions: ``(?P...)``. *name* is, obviously, the name of the group. Named groups also behave exactly like capturing groups, and additionally associate a name -with a group. The :class:`MatchObject` methods that deal with capturing groups -all accept either integers that refer to the group by number or strings that -contain the desired group's name. Named groups are still given numbers, so you -can retrieve information about a group in two ways:: +with a group. The :ref:`match object ` methods that deal with +capturing groups all accept either integers that refer to the group by number +or strings that contain the desired group's name. Named groups are still +given numbers, so you can retrieve information about a group in two ways:: >>> p = re.compile(r'(?P\b\w+\b)') >>> m = p.search( '(((( Lots of punctuation )))' ) @@ -1175,11 +1176,11 @@ *replacement* can also be a function, which gives you even more control. If *replacement* is a function, the function is called for every non-overlapping -occurrence of *pattern*. On each call, the function is passed a -:class:`MatchObject` argument for the match and can use this information to -compute the desired replacement string and return it. +occurrence of *pattern*. On each call, the function is passed a +:ref:`match object ` argument for the match and can use this +information to compute the desired replacement string and return it. -In the following example, the replacement function translates decimals into +In the following example, the replacement function translates decimals into hexadecimal:: >>> def hexrepl(match): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:49:36 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 17:49:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_rename_MathcOb?= =?utf-8?q?ject_to_match_object_in_doctrings_for_re_module_=28=2316760=29?= Message-ID: <3YW3FD408mzRhg@mail.python.org> http://hg.python.org/cpython/rev/3bee420d400f changeset: 81044:3bee420d400f branch: 3.2 parent: 81041:7c4ef8faeb4a user: Andrew Svetlov date: Tue Dec 25 18:48:54 2012 +0200 summary: rename MathcObject to match object in doctrings for re module (#16760) files: Modules/_sre.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2565,7 +2565,7 @@ PyDoc_STRVAR(pattern_search_doc, "search(string[, pos[, endpos]]) -> match object or None.\n\n\ Scan through string looking for a match, and return a corresponding\n\ - MatchObject instance. Return None if no position in the string matches."); + match object instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, "split(string[, maxsplit = 0]) -> list.\n\n\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:49:37 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 17:49:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_rename_MathcObject_to_match_object_in_doctrings_for_re_module_?= =?utf-8?b?KCMxNjc2MCk=?= Message-ID: <3YW3FF6ZprzRmy@mail.python.org> http://hg.python.org/cpython/rev/73b24ee09e0a changeset: 81045:73b24ee09e0a branch: 3.3 parent: 81042:4ba1e90e0119 parent: 81044:3bee420d400f user: Andrew Svetlov date: Tue Dec 25 18:49:08 2012 +0200 summary: rename MathcObject to match object in doctrings for re module (#16760) files: Modules/_sre.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2533,7 +2533,7 @@ PyDoc_STRVAR(pattern_search_doc, "search(string[, pos[, endpos]]) -> match object or None.\n\ Scan through string looking for a match, and return a corresponding\n\ - MatchObject instance. Return None if no position in the string matches."); + match object instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, "split(string[, maxsplit = 0]) -> list.\n\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:49:39 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 17:49:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_rename_MathcObject_to_match_object_in_doctrings_for_re_m?= =?utf-8?q?odule_=28=2316760=29?= Message-ID: <3YW3FH1jk6zRpS@mail.python.org> http://hg.python.org/cpython/rev/8ebbab768e1b changeset: 81046:8ebbab768e1b parent: 81043:f2222684dd2d parent: 81045:73b24ee09e0a user: Andrew Svetlov date: Tue Dec 25 18:49:24 2012 +0200 summary: rename MathcObject to match object in doctrings for re module (#16760) files: Modules/_sre.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2533,7 +2533,7 @@ PyDoc_STRVAR(pattern_search_doc, "search(string[, pos[, endpos]]) -> match object or None.\n\ Scan through string looking for a match, and return a corresponding\n\ - MatchObject instance. Return None if no position in the string matches."); + match object instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, "split(string[, maxsplit = 0]) -> list.\n\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 17:50:14 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 25 Dec 2012 17:50:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_rename_MathcOb?= =?utf-8?q?ject_to_match_object_in_doctrings_for_re_module_=28=2316760=29?= Message-ID: <3YW3Fy719kzRhg@mail.python.org> http://hg.python.org/cpython/rev/6ca8f965fd65 changeset: 81047:6ca8f965fd65 branch: 2.7 parent: 81040:b11f98872c0f user: Andrew Svetlov date: Tue Dec 25 18:50:03 2012 +0200 summary: rename MathcObject to match object in doctrings for re module (#16760) files: Modules/_sre.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2546,7 +2546,7 @@ PyDoc_STRVAR(pattern_search_doc, "search(string[, pos[, endpos]]) --> match object or None.\n\ Scan through string looking for a match, and return a corresponding\n\ - MatchObject instance. Return None if no position in the string matches."); + match object instance. Return None if no position in the string matches."); PyDoc_STRVAR(pattern_split_doc, "split(string[, maxsplit = 0]) --> list.\n\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 22:05:42 2012 From: python-checkins at python.org (gregory.p.smith) Date: Tue, 25 Dec 2012 22:05:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fixes_issue_=2316772=3A_in?= =?utf-8?q?t=28=29_constructor_second_argument_=28base=29_must_be_an_int?= =?utf-8?q?=2E?= Message-ID: <3YW8wk0fFMzRnr@mail.python.org> http://hg.python.org/cpython/rev/e510e028c486 changeset: 81048:e510e028c486 parent: 81046:8ebbab768e1b user: Gregory P. Smith date: Tue Dec 25 13:05:31 2012 -0800 summary: Fixes issue #16772: int() constructor second argument (base) must be an int. Consistent with the behavior in Python 2. files: Misc/NEWS | 3 +++ Objects/longobject.c | 5 +++++ 2 files changed, 8 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #16772: The int() constructor's second argument (base) no longer + accepts non integer values. Consistent with the behavior in Python 2. + - Issue #15422: Get rid of PyCFunction_New macro. Use PyCFunction_NewEx function (PyCFunction_New func is still present for backward compatibility). diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4260,6 +4260,11 @@ return PyLong_FromLong(0L); if (obase == NULL) return PyNumber_Long(x); + if (!PyLong_Check(obase)) { + PyErr_SetString(PyExc_TypeError, + "int() arg 2 must be an integer."); + return NULL; + } base = PyLong_AsLongAndOverflow(obase, &overflow); if (base == -1 && PyErr_Occurred()) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Dec 25 23:47:04 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Tue, 25 Dec 2012 23:47:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE0NTc0?= =?utf-8?q?=3A_Ignore_socket_errors_raised_when_flushing_a_connection_on_c?= =?utf-8?q?lose=2E?= Message-ID: <3YWC9h61vSzRjg@mail.python.org> http://hg.python.org/cpython/rev/df51cb946d27 changeset: 81049:df51cb946d27 branch: 2.7 parent: 81047:6ca8f965fd65 user: Kristj?n Valur J?nsson date: Tue Dec 25 22:46:32 2012 +0000 summary: Issue #14574: Ignore socket errors raised when flushing a connection on close. files: Doc/library/socketserver.rst | 4 ++-- Lib/SocketServer.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -306,8 +306,8 @@ .. method:: RequestHandler.finish() Called after the :meth:`handle` method to perform any clean-up actions - required. The default implementation does nothing. If :meth:`setup` or - :meth:`handle` raise an exception, this function will not be called. + required. The default implementation does nothing. If :meth:`setup` + raises an exception, this function will not be called. .. method:: RequestHandler.handle() diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py --- a/Lib/SocketServer.py +++ b/Lib/SocketServer.py @@ -701,7 +701,12 @@ def finish(self): if not self.wfile.closed: - self.wfile.flush() + try: + self.wfile.flush() + except socket.error: + # An final socket error may have occurred here, such as + # the local error ECONNABORTED. + pass self.wfile.close() self.rfile.close() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 00:00:53 2012 From: python-checkins at python.org (chris.jerdonek) Date: Wed, 26 Dec 2012 00:00:53 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Add_additional?= =?utf-8?q?_links_and_index_entries_for_=22argument=22_and_=22parameter=22?= =?utf-8?q?=2E?= Message-ID: <3YWCTd5w50zRmv@mail.python.org> http://hg.python.org/cpython/rev/ecf3cd3af502 changeset: 81050:ecf3cd3af502 branch: 2.7 user: Chris Jerdonek date: Tue Dec 25 14:50:21 2012 -0800 summary: Add additional links and index entries for "argument" and "parameter". This adds to the work done for issue #15990 (i.e. f44b8d69e5fc and the commits referenced there). files: Doc/faq/programming.rst | 4 ++++ Doc/glossary.rst | 5 +++-- Doc/reference/compound_stmts.rst | 16 +++++++++++----- Doc/reference/expressions.rst | 18 +++++++++++------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -469,6 +469,10 @@ apply(g, (x,)+args, kwargs) +.. index:: + single: argument; difference from parameter + single: parameter; difference from argument + .. _faq-argument-vs-parameter: What is the difference between arguments and parameters? diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -245,8 +245,9 @@ function A series of statements which returns some value to a caller. It can also - be passed zero or more arguments which may be used in the execution of - the body. See also :term:`argument` and :term:`method`. + be passed zero or more :term:`arguments ` which may be used in + the execution of the body. See also :term:`parameter`, :term:`method`, + and the :ref:`function` section. __future__ A pseudo-module which programmers can use to enable new language features diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -407,6 +407,9 @@ statement. +.. index:: + single: parameter; function definition + .. _function: .. _def: @@ -467,12 +470,15 @@ def func(): pass func = f1(arg)(f2(func)) -.. index:: triple: default; parameter; value +.. index:: + triple: default; parameter; value + single: argument; function definition -When one or more top-level parameters have the form *parameter* ``=`` -*expression*, the function is said to have "default parameter values." For a -parameter with a default value, the corresponding argument may be omitted from a -call, in which case the parameter's default value is substituted. If a +When one or more top-level :term:`parameters ` have the form +*parameter* ``=`` *expression*, the function is said to have "default parameter +values." For a parameter with a default value, the corresponding +:term:`argument` may be omitted from a call, in which +case the parameter's default value is substituted. If a parameter has a default value, all following parameters must also have a default value --- this is a syntactic restriction that is not expressed by the grammar. diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -667,17 +667,18 @@ expressions. +.. index:: + object: callable + single: call + single: argument; call semantics + .. _calls: Calls ----- -.. index:: single: call - -.. index:: object: callable - -A call calls a callable object (e.g., a function) with a possibly empty series -of arguments: +A call calls a callable object (e.g., a :term:`function`) with a possibly empty +series of :term:`arguments `: .. productionlist:: call: `primary` "(" [`argument_list` [","] @@ -696,12 +697,15 @@ A trailing comma may be present after the positional and keyword arguments but does not affect the semantics. +.. index:: + single: parameter; call semantics + The primary must evaluate to a callable object (user-defined functions, built-in functions, methods of built-in objects, class objects, methods of class instances, and certain class instances themselves are callable; extensions may define additional callable object types). All argument expressions are evaluated before the call is attempted. Please refer to section :ref:`function` -for the syntax of formal parameter lists. +for the syntax of formal :term:`parameter` lists. If keyword arguments are present, they are first converted to positional arguments, as follows. First, a list of unfilled slots is created for the -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 00:00:55 2012 From: python-checkins at python.org (chris.jerdonek) Date: Wed, 26 Dec 2012 00:00:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Add_additional?= =?utf-8?q?_links_and_index_entries_for_=22argument=22_and_=22parameter=22?= =?utf-8?q?=2E?= Message-ID: <3YWCTg2QxTzRlM@mail.python.org> http://hg.python.org/cpython/rev/31e1f0b7f42e changeset: 81051:31e1f0b7f42e branch: 3.2 parent: 81044:3bee420d400f user: Chris Jerdonek date: Tue Dec 25 14:54:44 2012 -0800 summary: Add additional links and index entries for "argument" and "parameter". This adds to the work done for issue #15990 (i.e. f44b8d69e5fc and the commits referenced there). files: Doc/faq/programming.rst | 4 ++++ Doc/glossary.rst | 5 +++-- Doc/reference/compound_stmts.rst | 14 ++++++++++---- Doc/reference/expressions.rst | 18 +++++++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -313,6 +313,10 @@ g(x, *args, **kwargs) +.. index:: + single: argument; difference from parameter + single: parameter; difference from argument + .. _faq-argument-vs-parameter: What is the difference between arguments and parameters? diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -240,8 +240,9 @@ function A series of statements which returns some value to a caller. It can also - be passed zero or more arguments which may be used in the execution of - the body. See also :term:`argument` and :term:`method`. + be passed zero or more :term:`arguments ` which may be used in + the execution of the body. See also :term:`parameter`, :term:`method`, + and the :ref:`function` section. __future__ A pseudo-module which programmers can use to enable new language features diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -417,6 +417,9 @@ statement. +.. index:: + single: parameter; function definition + .. _function: .. _def: @@ -478,11 +481,14 @@ def func(): pass func = f1(arg)(f2(func)) -.. index:: triple: default; parameter; value +.. index:: + triple: default; parameter; value + single: argument; function definition -When one or more parameters have the form *parameter* ``=`` *expression*, the -function is said to have "default parameter values." For a parameter with a -default value, the corresponding argument may be omitted from a call, in which +When one or more :term:`parameters ` have the form *parameter* ``=`` +*expression*, the function is said to have "default parameter values." For a +parameter with a default value, the corresponding :term:`argument` may be +omitted from a call, in which case the parameter's default value is substituted. If a parameter has a default value, all following parameters up until the "``*``" must also have a default value --- this is a syntactic restriction that is not expressed by the grammar. diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -600,17 +600,18 @@ expressions. +.. index:: + object: callable + single: call + single: argument; call semantics + .. _calls: Calls ----- -.. index:: single: call - -.. index:: object: callable - -A call calls a callable object (e.g., a function) with a possibly empty series -of arguments: +A call calls a callable object (e.g., a :term:`function`) with a possibly empty +series of :term:`arguments `: .. productionlist:: call: `primary` "(" [`argument_list` [","] | `comprehension`] ")" @@ -628,11 +629,14 @@ A trailing comma may be present after the positional and keyword arguments but does not affect the semantics. +.. index:: + single: parameter; call semantics + The primary must evaluate to a callable object (user-defined functions, built-in functions, methods of built-in objects, class objects, methods of class instances, and all objects having a :meth:`__call__` method are callable). All argument expressions are evaluated before the call is attempted. Please refer -to section :ref:`function` for the syntax of formal parameter lists. +to section :ref:`function` for the syntax of formal :term:`parameter` lists. .. XXX update with kwonly args PEP -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 00:00:56 2012 From: python-checkins at python.org (chris.jerdonek) Date: Wed, 26 Dec 2012 00:00:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_from_3=2E2=3A_add_links_and_index_entries_for_=22argumen?= =?utf-8?q?t=22_and_=22parameter=2E=22?= Message-ID: <3YWCTh5wbGzRn3@mail.python.org> http://hg.python.org/cpython/rev/7a4a1fc6b3ee changeset: 81052:7a4a1fc6b3ee branch: 3.3 parent: 81045:73b24ee09e0a parent: 81051:31e1f0b7f42e user: Chris Jerdonek date: Tue Dec 25 14:57:54 2012 -0800 summary: Merge from 3.2: add links and index entries for "argument" and "parameter." This adds to the work done for issue #15990 (i.e. f44b8d69e5fc and the commits referenced there). files: Doc/faq/programming.rst | 4 ++++ Doc/glossary.rst | 5 +++-- Doc/reference/compound_stmts.rst | 14 ++++++++++---- Doc/reference/expressions.rst | 18 +++++++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -313,6 +313,10 @@ g(x, *args, **kwargs) +.. index:: + single: argument; difference from parameter + single: parameter; difference from argument + .. _faq-argument-vs-parameter: What is the difference between arguments and parameters? diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -240,8 +240,9 @@ function A series of statements which returns some value to a caller. It can also - be passed zero or more arguments which may be used in the execution of - the body. See also :term:`argument` and :term:`method`. + be passed zero or more :term:`arguments ` which may be used in + the execution of the body. See also :term:`parameter`, :term:`method`, + and the :ref:`function` section. __future__ A pseudo-module which programmers can use to enable new language features diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -417,6 +417,9 @@ statement. +.. index:: + single: parameter; function definition + .. _function: .. _def: @@ -478,11 +481,14 @@ def func(): pass func = f1(arg)(f2(func)) -.. index:: triple: default; parameter; value +.. index:: + triple: default; parameter; value + single: argument; function definition -When one or more parameters have the form *parameter* ``=`` *expression*, the -function is said to have "default parameter values." For a parameter with a -default value, the corresponding argument may be omitted from a call, in which +When one or more :term:`parameters ` have the form *parameter* ``=`` +*expression*, the function is said to have "default parameter values." For a +parameter with a default value, the corresponding :term:`argument` may be +omitted from a call, in which case the parameter's default value is substituted. If a parameter has a default value, all following parameters up until the "``*``" must also have a default value --- this is a syntactic restriction that is not expressed by the grammar. diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -637,17 +637,18 @@ expressions. +.. index:: + object: callable + single: call + single: argument; call semantics + .. _calls: Calls ----- -.. index:: single: call - -.. index:: object: callable - -A call calls a callable object (e.g., a function) with a possibly empty series -of arguments: +A call calls a callable object (e.g., a :term:`function`) with a possibly empty +series of :term:`arguments `: .. productionlist:: call: `primary` "(" [`argument_list` [","] | `comprehension`] ")" @@ -665,11 +666,14 @@ A trailing comma may be present after the positional and keyword arguments but does not affect the semantics. +.. index:: + single: parameter; call semantics + The primary must evaluate to a callable object (user-defined functions, built-in functions, methods of built-in objects, class objects, methods of class instances, and all objects having a :meth:`__call__` method are callable). All argument expressions are evaluated before the call is attempted. Please refer -to section :ref:`function` for the syntax of formal parameter lists. +to section :ref:`function` for the syntax of formal :term:`parameter` lists. .. XXX update with kwonly args PEP -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 00:00:58 2012 From: python-checkins at python.org (chris.jerdonek) Date: Wed, 26 Dec 2012 00:00:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_from_3=2E3=3A_add_links_and_index_entries_for_=22a?= =?utf-8?q?rgument=22_and_=22parameter=2E=22?= Message-ID: <3YWCTk2P33zRmv@mail.python.org> http://hg.python.org/cpython/rev/10e4d28d0090 changeset: 81053:10e4d28d0090 parent: 81048:e510e028c486 parent: 81052:7a4a1fc6b3ee user: Chris Jerdonek date: Tue Dec 25 14:59:46 2012 -0800 summary: Merge from 3.3: add links and index entries for "argument" and "parameter." This adds to the work done for issue #15990 (i.e. f44b8d69e5fc and the commits referenced there). files: Doc/faq/programming.rst | 4 ++++ Doc/glossary.rst | 5 +++-- Doc/reference/compound_stmts.rst | 14 ++++++++++---- Doc/reference/expressions.rst | 18 +++++++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst --- a/Doc/faq/programming.rst +++ b/Doc/faq/programming.rst @@ -313,6 +313,10 @@ g(x, *args, **kwargs) +.. index:: + single: argument; difference from parameter + single: parameter; difference from argument + .. _faq-argument-vs-parameter: What is the difference between arguments and parameters? diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -240,8 +240,9 @@ function A series of statements which returns some value to a caller. It can also - be passed zero or more arguments which may be used in the execution of - the body. See also :term:`argument` and :term:`method`. + be passed zero or more :term:`arguments ` which may be used in + the execution of the body. See also :term:`parameter`, :term:`method`, + and the :ref:`function` section. __future__ A pseudo-module which programmers can use to enable new language features diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -417,6 +417,9 @@ statement. +.. index:: + single: parameter; function definition + .. _function: .. _def: @@ -478,11 +481,14 @@ def func(): pass func = f1(arg)(f2(func)) -.. index:: triple: default; parameter; value +.. index:: + triple: default; parameter; value + single: argument; function definition -When one or more parameters have the form *parameter* ``=`` *expression*, the -function is said to have "default parameter values." For a parameter with a -default value, the corresponding argument may be omitted from a call, in which +When one or more :term:`parameters ` have the form *parameter* ``=`` +*expression*, the function is said to have "default parameter values." For a +parameter with a default value, the corresponding :term:`argument` may be +omitted from a call, in which case the parameter's default value is substituted. If a parameter has a default value, all following parameters up until the "``*``" must also have a default value --- this is a syntactic restriction that is not expressed by the grammar. diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -637,17 +637,18 @@ expressions. +.. index:: + object: callable + single: call + single: argument; call semantics + .. _calls: Calls ----- -.. index:: single: call - -.. index:: object: callable - -A call calls a callable object (e.g., a function) with a possibly empty series -of arguments: +A call calls a callable object (e.g., a :term:`function`) with a possibly empty +series of :term:`arguments `: .. productionlist:: call: `primary` "(" [`argument_list` [","] | `comprehension`] ")" @@ -665,11 +666,14 @@ A trailing comma may be present after the positional and keyword arguments but does not affect the semantics. +.. index:: + single: parameter; call semantics + The primary must evaluate to a callable object (user-defined functions, built-in functions, methods of built-in objects, class objects, methods of class instances, and all objects having a :meth:`__call__` method are callable). All argument expressions are evaluated before the call is attempted. Please refer -to section :ref:`function` for the syntax of formal parameter lists. +to section :ref:`function` for the syntax of formal :term:`parameter` lists. .. XXX update with kwonly args PEP -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 00:29:36 2012 From: python-checkins at python.org (chris.jerdonek) Date: Wed, 26 Dec 2012 00:29:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_Sphinx_war?= =?utf-8?q?ning_=28missing_=22setting-envvars=22_reference=29=2E?= Message-ID: <3YWD6m6wdpzRlr@mail.python.org> http://hg.python.org/cpython/rev/e8793c5f0ebc changeset: 81054:e8793c5f0ebc branch: 3.2 parent: 81051:31e1f0b7f42e user: Chris Jerdonek date: Tue Dec 25 15:26:24 2012 -0800 summary: Fix Sphinx warning (missing "setting-envvars" reference). This fixes the following warning when building the docs (probably from the commit for issue #14901): "/Doc/faq/windows.rst:138: WARNING: undefined label: setting-envvars (if the link has no caption the label must precede a section header)" files: Doc/using/windows.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/using/windows.rst b/Doc/using/windows.rst --- a/Doc/using/windows.rst +++ b/Doc/using/windows.rst @@ -82,6 +82,8 @@ settings in Windows. +.. _setting-envvars: + Excursus: Setting environment variables --------------------------------------- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 00:29:38 2012 From: python-checkins at python.org (chris.jerdonek) Date: Wed, 26 Dec 2012 00:29:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Null_merge=2E?= Message-ID: <3YWD6p26qfzRnV@mail.python.org> http://hg.python.org/cpython/rev/517f3432d1b5 changeset: 81055:517f3432d1b5 branch: 3.3 parent: 81052:7a4a1fc6b3ee parent: 81054:e8793c5f0ebc user: Chris Jerdonek date: Tue Dec 25 15:27:56 2012 -0800 summary: Null merge. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 00:29:39 2012 From: python-checkins at python.org (chris.jerdonek) Date: Wed, 26 Dec 2012 00:29:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Null_merge=2E?= Message-ID: <3YWD6q4MqXzRpH@mail.python.org> http://hg.python.org/cpython/rev/3cd57e8144dc changeset: 81056:3cd57e8144dc parent: 81053:10e4d28d0090 parent: 81055:517f3432d1b5 user: Chris Jerdonek date: Tue Dec 25 15:28:45 2012 -0800 summary: Null merge. files: -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Dec 26 05:57:39 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 26 Dec 2012 05:57:39 +0100 Subject: [Python-checkins] Daily reference leaks (3cd57e8144dc): sum=0 Message-ID: results for 3cd57e8144dc on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogGhsxhH', '-x'] From python-checkins at python.org Wed Dec 26 07:38:42 2012 From: python-checkins at python.org (gregory.p.smith) Date: Wed, 26 Dec 2012 07:38:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Test_for_issue16772_and_re?= =?utf-8?q?does_the_previous_fix_to_accept_=5F=5Findex=5F=5F-aware?= Message-ID: <3YWPdt32KtzM2d@mail.python.org> http://hg.python.org/cpython/rev/60f7197f991f changeset: 81057:60f7197f991f user: Gregory P. Smith date: Tue Dec 25 22:38:32 2012 -0800 summary: Test for issue16772 and redoes the previous fix to accept __index__-aware objects as the base by using PyNumber_AsSsize_t similar to round(). files: Lib/test/test_int.py | 24 ++++++++++++++++++++++++ Objects/longobject.c | 7 +++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -240,6 +240,30 @@ self.assertEquals(int(base=1000), 0) self.assertEquals(int(base='foo'), 0) + def test_int_base_limits(self): + """Testing the supported limits of the int() base parameter.""" + self.assertEqual(int('0', 5), 0) + with self.assertRaises(ValueError): + int('0', 1) + with self.assertRaises(ValueError): + int('0', 37) + with self.assertRaises(ValueError): + int('0', -909) # An old magic value base from Python 2. + with self.assertRaises(ValueError): + int('0', base=0-(2**234)) + with self.assertRaises(ValueError): + int('0', base=2**234) + # Bases 2 through 36 are supported. + for base in range(2,37): + self.assertEqual(int('0', base=base), 0) + + def test_int_base_bad_types(self): + """Not integer types are not valid bases; issue16772.""" + with self.assertRaises(TypeError): + int('0', 5.5) + with self.assertRaises(TypeError): + int('0', 5.0) + def test_non_numeric_input_types(self): # Test possible non-numeric types for the argument x, including # subclasses of the explicitly documented accepted types. diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4247,8 +4247,7 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *obase = NULL, *x = NULL; - long base; - int overflow; + Py_ssize_t base; static char *kwlist[] = {"x", "base", 0}; if (type != &PyLong_Type) @@ -4266,10 +4265,10 @@ return NULL; } - base = PyLong_AsLongAndOverflow(obase, &overflow); + base = PyNumber_AsSsize_t(obase, NULL); if (base == -1 && PyErr_Occurred()) return NULL; - if (overflow || (base != 0 && base < 2) || base > 36) { + if ((base != 0 && base < 2) || base > 36) { PyErr_SetString(PyExc_ValueError, "int() arg 2 must be >= 2 and <= 36"); return NULL; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 10:47:28 2012 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 26 Dec 2012 10:47:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NzAy?= =?utf-8?q?=3A_Skip_proxies_for_localhost_in_urllib2=5Flocalnet_tests?= Message-ID: <3YWTqh0JYszNrD@mail.python.org> http://hg.python.org/cpython/rev/6c186caa6285 changeset: 81058:6c186caa6285 branch: 2.7 parent: 81050:ecf3cd3af502 user: Senthil Kumaran date: Wed Dec 26 01:45:22 2012 -0800 summary: Issue #16702: Skip proxies for localhost in urllib2_localnet tests files: Lib/test/test_urllib2_localnet.py | 8 ++++++++ Misc/NEWS | 3 +++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -5,7 +5,9 @@ import BaseHTTPServer import unittest import hashlib + from test import test_support + mimetools = test_support.import_module('mimetools', deprecated=True) threading = test_support.import_module('threading') @@ -346,6 +348,12 @@ for transparent redirection have been written. """ + def setUp(self): + proxy_handler = urllib2.ProxyHandler({}) + opener = urllib2.build_opener(proxy_handler) + urllib2.install_opener(opener) + super(TestUrlopen, self).setUp() + def start_server(self, responses): handler = GetRequestHandler(responses) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -164,6 +164,9 @@ Library ------- +- Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for + localhost tests. + - Issue #16713: Fix the parsing of tel url with params using urlparse module. - Issue #16443: Add docstrings to regular expression match objects. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 10:47:29 2012 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 26 Dec 2012 10:47:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NzAy?= =?utf-8?q?=3A_Skip_proxies_for_localhost_in_urllib2=5Flocalnet_tests?= Message-ID: <3YWTqj2tN4zRcS@mail.python.org> http://hg.python.org/cpython/rev/0eccfb237364 changeset: 81059:0eccfb237364 branch: 3.2 parent: 81054:e8793c5f0ebc user: Senthil Kumaran date: Wed Dec 26 01:45:58 2012 -0800 summary: Issue #16702: Skip proxies for localhost in urllib2_localnet tests files: Lib/test/test_urllib2_localnet.py | 2 ++ Misc/NEWS | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -352,6 +352,8 @@ def setUp(self): super(TestUrlopen, self).setUp() + # Ignore proxies for localhost tests. + os.environ['NO_PROXY'] = '*' self.server = None def tearDown(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,9 @@ Library ------- +- Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for + localhost tests. + - Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 10:47:30 2012 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 26 Dec 2012 10:47:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316702=3A_Skip_proxies_for_localhost_in_urllib2=5Floca?= =?utf-8?q?lnet_tests?= Message-ID: <3YWTqk5PZNzRfJ@mail.python.org> http://hg.python.org/cpython/rev/8a524faeb7ae changeset: 81060:8a524faeb7ae branch: 3.3 parent: 81055:517f3432d1b5 parent: 81059:0eccfb237364 user: Senthil Kumaran date: Wed Dec 26 01:46:39 2012 -0800 summary: Issue #16702: Skip proxies for localhost in urllib2_localnet tests files: Lib/test/test_urllib2_localnet.py | 2 ++ Misc/NEWS | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -352,6 +352,8 @@ def setUp(self): super(TestUrlopen, self).setUp() + # Ignore proxies for localhost tests. + os.environ['NO_PROXY'] = '*' self.server = None def tearDown(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -114,6 +114,9 @@ Library ------- +- Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for + localhost tests. + - Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 10:47:32 2012 From: python-checkins at python.org (senthil.kumaran) Date: Wed, 26 Dec 2012 10:47:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316702=3A_Skip_proxies_for_localhost_in_urllib2?= =?utf-8?q?=5Flocalnet_tests?= Message-ID: <3YWTqm0nsSzRfX@mail.python.org> http://hg.python.org/cpython/rev/43b19d9f9af4 changeset: 81061:43b19d9f9af4 parent: 81057:60f7197f991f parent: 81060:8a524faeb7ae user: Senthil Kumaran date: Wed Dec 26 01:47:09 2012 -0800 summary: Issue #16702: Skip proxies for localhost in urllib2_localnet tests files: Lib/test/test_urllib2_localnet.py | 2 ++ Misc/NEWS | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py --- a/Lib/test/test_urllib2_localnet.py +++ b/Lib/test/test_urllib2_localnet.py @@ -352,6 +352,8 @@ def setUp(self): super(TestUrlopen, self).setUp() + # Ignore proxies for localhost tests. + os.environ['NO_PROXY'] = '*' self.server = None def tearDown(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -186,6 +186,9 @@ Library ------- +- Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for + localhost tests. + - Issue #16511: Use default IDLE width and height if config param is not valid. Patch Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 14:03:38 2012 From: python-checkins at python.org (brian.curtin) Date: Wed, 26 Dec 2012 14:03:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_=2311939=2E_Set_st=5Fd?= =?utf-8?q?ev_attribute_on_Windows_to_simplify_os=2Epath=2Esamefile=2E?= Message-ID: <3YWZB26kGRzRVW@mail.python.org> http://hg.python.org/cpython/rev/189b21f9bc0c changeset: 81062:189b21f9bc0c user: Brian Curtin date: Wed Dec 26 07:03:03 2012 -0600 summary: Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile. By setting the st_dev attribute, we can then remove some Windows-specific code and move os.path.samefile/sameopenfile/samestat to Lib/genericpath.py so all platforms share the same implementation. files: Doc/library/os.path.rst | 12 ++- Lib/genericpath.py | 28 +++++++++- Lib/ntpath.py | 17 ------ Lib/posixpath.py | 28 --------- Lib/test/test_genericpath.py | 68 ++++++++++++++++++++++++ Lib/test/test_posixpath.py | 62 --------------------- Modules/posixmodule.c | 28 +--------- 7 files changed, 104 insertions(+), 139 deletions(-) diff --git a/Doc/library/os.path.rst b/Doc/library/os.path.rst --- a/Doc/library/os.path.rst +++ b/Doc/library/os.path.rst @@ -244,15 +244,14 @@ On Unix, this is determined by the device number and i-node number and raises an exception if a :func:`os.stat` call on either pathname fails. - On Windows, two files are the same if they resolve to the same final path - name using the Windows API call GetFinalPathNameByHandle. This function - raises an exception if handles cannot be obtained to either file. - Availability: Unix, Windows. .. versionchanged:: 3.2 Added Windows support. + .. versionchanged:: 3.4 + Windows now uses the same implementation as all other platforms. + .. function:: sameopenfile(fp1, fp2) @@ -271,7 +270,10 @@ :func:`stat`. This function implements the underlying comparison used by :func:`samefile` and :func:`sameopenfile`. - Availability: Unix. + Availability: Unix, Windows. + + .. versionchanged:: 3.4 + Added Windows support. .. function:: split(path) diff --git a/Lib/genericpath.py b/Lib/genericpath.py --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -7,7 +7,8 @@ import stat __all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime', - 'getsize', 'isdir', 'isfile'] + 'getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile', + 'samestat'] # Does a path exist? @@ -75,6 +76,31 @@ return s1[:i] return s1 +# Are two stat buffers (obtained from stat, fstat or lstat) +# describing the same file? +def samestat(s1, s2): + """Test whether two stat buffers reference the same file""" + return (s1.st_ino == s2.st_ino and + s1.st_dev == s2.st_dev) + + +# Are two filenames really pointing to the same file? +def samefile(f1, f2): + """Test whether two pathnames reference the same actual file""" + s1 = os.stat(f1) + s2 = os.stat(f2) + return samestat(s1, s2) + + +# Are two open files really referencing the same file? +# (Not necessarily the same file descriptor!) +def sameopenfile(fp1, fp2): + """Test whether two open file objects reference the same file""" + s1 = os.fstat(fp1) + s2 = os.fstat(fp2) + return samestat(s1, s2) + + # Split a path in root and extension. # The extension is everything starting at the last dot in the last # pathname component; the root is everything before that. diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -652,23 +652,6 @@ def _getfinalpathname(f): return normcase(abspath(f)) -def samefile(f1, f2): - "Test whether two pathnames reference the same actual file" - return _getfinalpathname(f1) == _getfinalpathname(f2) - - -try: - from nt import _getfileinformation -except ImportError: - # On other operating systems, just return the fd and see that - # it compares equal in sameopenfile. - def _getfileinformation(fd): - return fd - -def sameopenfile(f1, f2): - """Test whether two file objects reference the same file""" - return _getfileinformation(f1) == _getfileinformation(f2) - try: # The genericpath.isdir implementation uses os.stat and checks the mode diff --git a/Lib/posixpath.py b/Lib/posixpath.py --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -177,34 +177,6 @@ return True -# Are two filenames really pointing to the same file? - -def samefile(f1, f2): - """Test whether two pathnames reference the same actual file""" - s1 = os.stat(f1) - s2 = os.stat(f2) - return samestat(s1, s2) - - -# Are two open files really referencing the same file? -# (Not necessarily the same file descriptor!) - -def sameopenfile(fp1, fp2): - """Test whether two open file objects reference the same file""" - s1 = os.fstat(fp1) - s2 = os.fstat(fp2) - return samestat(s1, s2) - - -# Are two stat buffers (obtained from stat, fstat or lstat) -# describing the same file? - -def samestat(s1, s2): - """Test whether two stat buffers reference the same file""" - return s1.st_ino == s2.st_ino and \ - s1.st_dev == s2.st_dev - - # Is a path a mount point? # (Does this work for all UNIXes? Is it even guaranteed to work by Posix?) diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -190,6 +190,74 @@ support.unlink(support.TESTFN) safe_rmdir(support.TESTFN) + @staticmethod + def _create_file(filename): + with open(filename, 'wb') as f: + f.write(b'foo') + + def test_samefile(self): + try: + test_fn = support.TESTFN + "1" + self._create_file(test_fn) + self.assertTrue(self.pathmodule.samefile(test_fn, test_fn)) + self.assertRaises(TypeError, self.pathmodule.samefile) + finally: + os.remove(test_fn) + + @support.skip_unless_symlink + def test_samefile_on_links(self): + try: + test_fn1 = support.TESTFN + "1" + test_fn2 = support.TESTFN + "2" + self._create_file(test_fn1) + + os.symlink(test_fn1, test_fn2) + self.assertTrue(self.pathmodule.samefile(test_fn1, test_fn2)) + os.remove(test_fn2) + + self._create_file(test_fn2) + self.assertFalse(self.pathmodule.samefile(test_fn1, test_fn2)) + finally: + os.remove(test_fn1) + os.remove(test_fn2) + + def test_samestat(self): + try: + test_fn = support.TESTFN + "1" + self._create_file(test_fn) + test_fns = [test_fn]*2 + stats = map(os.stat, test_fns) + self.assertTrue(self.pathmodule.samestat(*stats)) + finally: + os.remove(test_fn) + + @support.skip_unless_symlink + def test_samestat_on_links(self): + try: + test_fn1 = support.TESTFN + "1" + test_fn2 = support.TESTFN + "2" + self._create_file(test_fn1) + test_fns = (test_fn1, test_fn2) + os.symlink(*test_fns) + stats = map(os.stat, test_fns) + self.assertTrue(self.pathmodule.samestat(*stats)) + os.remove(test_fn2) + + self._create_file(test_fn2) + stats = map(os.stat, test_fns) + self.assertFalse(self.pathmodule.samestat(*stats)) + + self.assertRaises(TypeError, self.pathmodule.samestat) + finally: + os.remove(test_fn1) + os.remove(test_fn2) + + def test_sameopenfile(self): + fname = support.TESTFN + "1" + with open(fname, "wb") as a, open(fname, "wb") as b: + self.assertTrue(self.pathmodule.sameopenfile( + a.fileno(), b.fileno())) + # Following TestCase is not supposed to be run from test_genericpath. # It is inherited by other test modules (macpath, ntpath, posixpath). diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -186,63 +186,6 @@ if not f.close(): f.close() - @staticmethod - def _create_file(filename): - with open(filename, 'wb') as f: - f.write(b'foo') - - def test_samefile(self): - test_fn = support.TESTFN + "1" - self._create_file(test_fn) - self.assertTrue(posixpath.samefile(test_fn, test_fn)) - self.assertRaises(TypeError, posixpath.samefile) - - @unittest.skipIf( - sys.platform.startswith('win'), - "posixpath.samefile does not work on links in Windows") - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") - def test_samefile_on_links(self): - test_fn1 = support.TESTFN + "1" - test_fn2 = support.TESTFN + "2" - self._create_file(test_fn1) - - os.symlink(test_fn1, test_fn2) - self.assertTrue(posixpath.samefile(test_fn1, test_fn2)) - os.remove(test_fn2) - - self._create_file(test_fn2) - self.assertFalse(posixpath.samefile(test_fn1, test_fn2)) - - - def test_samestat(self): - test_fn = support.TESTFN + "1" - self._create_file(test_fn) - test_fns = [test_fn]*2 - stats = map(os.stat, test_fns) - self.assertTrue(posixpath.samestat(*stats)) - - @unittest.skipIf( - sys.platform.startswith('win'), - "posixpath.samestat does not work on links in Windows") - @unittest.skipUnless(hasattr(os, "symlink"), - "Missing symlink implementation") - def test_samestat_on_links(self): - test_fn1 = support.TESTFN + "1" - test_fn2 = support.TESTFN + "2" - self._create_file(test_fn1) - test_fns = (test_fn1, test_fn2) - os.symlink(*test_fns) - stats = map(os.stat, test_fns) - self.assertTrue(posixpath.samestat(*stats)) - os.remove(test_fn2) - - self._create_file(test_fn2) - stats = map(os.stat, test_fns) - self.assertFalse(posixpath.samestat(*stats)) - - self.assertRaises(TypeError, posixpath.samestat) - def test_ismount(self): self.assertIs(posixpath.ismount("/"), True) with warnings.catch_warnings(): @@ -518,11 +461,6 @@ finally: os.getcwdb = real_getcwdb - def test_sameopenfile(self): - fname = support.TESTFN + "1" - with open(fname, "wb") as a, open(fname, "wb") as b: - self.assertTrue(posixpath.sameopenfile(a.fileno(), b.fileno())) - class PosixCommonTest(test_genericpath.CommonTest): pathmodule = posixpath diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1249,6 +1249,8 @@ memset(result, 0, sizeof(*result)); result->st_mode = attributes_to_mode(info->dwFileAttributes); result->st_size = (((__int64)info->nFileSizeHigh)<<32) + info->nFileSizeLow; + result->st_dev = info->dwVolumeSerialNumber; + result->st_rdev = result->st_dev; FILE_TIME_to_time_t_nsec(&info->ftCreationTime, &result->st_ctime, &result->st_ctime_nsec); FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result->st_mtime_nsec); FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result->st_atime_nsec); @@ -3503,31 +3505,6 @@ } /* end of posix__getfinalpathname */ -static PyObject * -posix__getfileinformation(PyObject *self, PyObject *args) -{ - HANDLE hFile; - BY_HANDLE_FILE_INFORMATION info; - int fd; - - if (!PyArg_ParseTuple(args, "i:_getfileinformation", &fd)) - return NULL; - - if (!_PyVerify_fd(fd)) - return posix_error(); - - hFile = (HANDLE)_get_osfhandle(fd); - if (hFile == INVALID_HANDLE_VALUE) - return posix_error(); - - if (!GetFileInformationByHandle(hFile, &info)) - return PyErr_SetFromWindowsErr(0); - - return Py_BuildValue("iii", info.dwVolumeSerialNumber, - info.nFileIndexHigh, - info.nFileIndexLow); -} - PyDoc_STRVAR(posix__isdir__doc__, "Return true if the pathname refers to an existing directory."); @@ -10606,7 +10583,6 @@ #ifdef MS_WINDOWS {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, {"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL}, - {"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL}, {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__}, {"_getdiskusage", win32__getdiskusage, METH_VARARGS, win32__getdiskusage__doc__}, #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 14:11:42 2012 From: python-checkins at python.org (brian.curtin) Date: Wed, 26 Dec 2012 14:11:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_NEWS_entry_for_fixing_?= =?utf-8?q?=2311939?= Message-ID: <3YWZML6vVmzRgX@mail.python.org> http://hg.python.org/cpython/rev/82531b78b719 changeset: 81063:82531b78b719 user: Brian Curtin date: Wed Dec 26 07:11:14 2012 -0600 summary: Add NEWS entry for fixing #11939 files: Misc/NEWS | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #11939: Set the st_dev attribute of stat_result to allow Windows to + take advantage of the os.path.samefile/sameopenfile/samestat implementations + used by other platforms. + - Issue #16772: The int() constructor's second argument (base) no longer accepts non integer values. Consistent with the behavior in Python 2. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 14:36:32 2012 From: python-checkins at python.org (brian.curtin) Date: Wed, 26 Dec 2012 14:36:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_tests_for_Issue_=23106?= =?utf-8?b?NDYu?= Message-ID: <3YWZw04yySzQQ7@mail.python.org> http://hg.python.org/cpython/rev/9e980454b85e changeset: 81064:9e980454b85e user: Brian Curtin date: Wed Dec 26 07:36:16 2012 -0600 summary: Add tests for Issue #10646. This issue is now fixed due to changes in Issue #11939, so I've refactored the tests to cover the hard link case. There are no code changes here. files: Lib/test/test_genericpath.py | 20 ++++++++++++++++---- Misc/NEWS | 3 +++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -205,13 +205,19 @@ os.remove(test_fn) @support.skip_unless_symlink - def test_samefile_on_links(self): + def test_samefile_on_symlink(self): + self._test_samefile_on_link_func(os.symlink) + + def test_samefile_on_link(self): + self._test_samefile_on_link_func(os.link) + + def _test_samefile_on_link_func(self, func): try: test_fn1 = support.TESTFN + "1" test_fn2 = support.TESTFN + "2" self._create_file(test_fn1) - os.symlink(test_fn1, test_fn2) + func(test_fn1, test_fn2) self.assertTrue(self.pathmodule.samefile(test_fn1, test_fn2)) os.remove(test_fn2) @@ -232,13 +238,19 @@ os.remove(test_fn) @support.skip_unless_symlink - def test_samestat_on_links(self): + def test_samestat_on_symlink(self): + self._test_samestat_on_link_func(os.symlink) + + def test_samestat_on_link(self): + self._test_samestat_on_link_func(os.link) + + def _test_samestat_on_link_func(self, func): try: test_fn1 = support.TESTFN + "1" test_fn2 = support.TESTFN + "2" self._create_file(test_fn1) test_fns = (test_fn1, test_fn2) - os.symlink(*test_fns) + func(*test_fns) stats = map(os.stat, test_fns) self.assertTrue(self.pathmodule.samestat(*stats)) os.remove(test_fn2) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -516,6 +516,9 @@ Tests ----- +- Issue #10646: Tests rearranged for os.samefile/samestat to check for not + just symlinks but also hard links. + - Issue #16664: Add regression tests for glob's behaviour concerning entries starting with a ".". Patch by Sebastian Kreft. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 15:22:15 2012 From: python-checkins at python.org (brian.curtin) Date: Wed, 26 Dec 2012 15:22:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_=2316788=2E_Add_samest?= =?utf-8?q?at_to_Lib/ntpath=2Epy?= Message-ID: <3YWbwl3zpYzQvS@mail.python.org> http://hg.python.org/cpython/rev/cc3f7ef1072e changeset: 81065:cc3f7ef1072e user: Brian Curtin date: Wed Dec 26 08:22:00 2012 -0600 summary: Fix #16788. Add samestat to Lib/ntpath.py files: Lib/ntpath.py | 2 +- Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -17,7 +17,7 @@ "ismount", "expanduser","expandvars","normpath","abspath", "splitunc","curdir","pardir","sep","pathsep","defpath","altsep", "extsep","devnull","realpath","supports_unicode_filenames","relpath", - "samefile", "sameopenfile",] + "samefile", "sameopenfile", "samestat",] # strings representing various path-related bits and pieces # These are primarily for export; internally, they are hardcoded. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -190,6 +190,8 @@ Library ------- +- Issue #16788: Add samestat to Lib/ntpath.py + - Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for localhost tests. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 16:30:28 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Wed, 26 Dec 2012 16:30:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE0NTc0?= =?utf-8?q?=3A_Ignore_socket_errors_raised_when_flushing_a_connection_on_c?= =?utf-8?q?lose=2E?= Message-ID: <3YWdRS2KHMzNx8@mail.python.org> http://hg.python.org/cpython/rev/7e5d7ef4634d changeset: 81066:7e5d7ef4634d branch: 3.2 parent: 81059:0eccfb237364 user: Kristj?n Valur J?nsson date: Tue Dec 25 22:46:32 2012 +0000 summary: Issue #14574: Ignore socket errors raised when flushing a connection on close. files: Doc/library/socketserver.rst | 4 ++-- Lib/socketserver.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -299,8 +299,8 @@ .. method:: RequestHandler.finish() Called after the :meth:`handle` method to perform any clean-up actions - required. The default implementation does nothing. If :meth:`setup` or - :meth:`handle` raise an exception, this function will not be called. + required. The default implementation does nothing. If :meth:`setup` + raises an exception, this function will not be called. .. method:: RequestHandler.handle() diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -700,7 +700,12 @@ def finish(self): if not self.wfile.closed: - self.wfile.flush() + try: + self.wfile.flush() + except socket.error: + # An final socket error may have occurred here, such as + # the local error ECONNABORTED. + pass self.wfile.close() self.rfile.close() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 16:30:29 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Wed, 26 Dec 2012 16:30:29 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_with_3=2E2_=3A?= Message-ID: <3YWdRT4xp7zRh8@mail.python.org> http://hg.python.org/cpython/rev/7734c3020a47 changeset: 81067:7734c3020a47 branch: 3.3 parent: 81060:8a524faeb7ae parent: 81066:7e5d7ef4634d user: Kristj?n Valur J?nsson date: Wed Dec 26 15:13:29 2012 +0000 summary: Merge with 3.2 : Issue #14574: Ignore socket errors raised when flushing a connection on close. files: Doc/library/socketserver.rst | 4 ++-- Lib/socketserver.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -313,8 +313,8 @@ .. method:: RequestHandler.finish() Called after the :meth:`handle` method to perform any clean-up actions - required. The default implementation does nothing. If :meth:`setup` or - :meth:`handle` raise an exception, this function will not be called. + required. The default implementation does nothing. If :meth:`setup` + raises an exception, this function will not be called. .. method:: RequestHandler.handle() diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -718,7 +718,12 @@ def finish(self): if not self.wfile.closed: - self.wfile.flush() + try: + self.wfile.flush() + except socket.error: + # An final socket error may have occurred here, such as + # the local error ECONNABORTED. + pass self.wfile.close() self.rfile.close() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 16:30:31 2012 From: python-checkins at python.org (kristjan.jonsson) Date: Wed, 26 Dec 2012 16:30:31 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E3?= Message-ID: <3YWdRW074nzRjB@mail.python.org> http://hg.python.org/cpython/rev/2d1cfbaef9a2 changeset: 81068:2d1cfbaef9a2 parent: 81065:cc3f7ef1072e parent: 81067:7734c3020a47 user: Kristj?n Valur J?nsson date: Wed Dec 26 15:15:17 2012 +0000 summary: Merge with 3.3 Issue #14574: Ignore socket errors raised when flushing a connection on close. files: Doc/library/socketserver.rst | 4 ++-- Lib/socketserver.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -313,8 +313,8 @@ .. method:: RequestHandler.finish() Called after the :meth:`handle` method to perform any clean-up actions - required. The default implementation does nothing. If :meth:`setup` or - :meth:`handle` raise an exception, this function will not be called. + required. The default implementation does nothing. If :meth:`setup` + raises an exception, this function will not be called. .. method:: RequestHandler.handle() diff --git a/Lib/socketserver.py b/Lib/socketserver.py --- a/Lib/socketserver.py +++ b/Lib/socketserver.py @@ -718,7 +718,12 @@ def finish(self): if not self.wfile.closed: - self.wfile.flush() + try: + self.wfile.flush() + except socket.error: + # An final socket error may have occurred here, such as + # the local error ECONNABORTED. + pass self.wfile.close() self.rfile.close() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 16:49:24 2012 From: python-checkins at python.org (jesus.cea) Date: Wed, 26 Dec 2012 16:49:24 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICMxNjc4?= =?utf-8?q?9=3A_=3Ameth=3A=60quit=60_links_to_constants_instead_of_own_mod?= =?utf-8?q?ule?= Message-ID: <3YWdsJ39mQzRhC@mail.python.org> http://hg.python.org/cpython/rev/0ffaf1079a7a changeset: 81069:0ffaf1079a7a branch: 2.7 parent: 81058:6c186caa6285 user: Jesus Cea date: Wed Dec 26 16:46:04 2012 +0100 summary: Closes #16789: :meth:`quit` links to constants instead of own module files: Doc/library/ftplib.rst | 8 ++++---- Doc/library/poplib.rst | 2 +- Doc/library/smtplib.rst | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst --- a/Doc/library/ftplib.rst +++ b/Doc/library/ftplib.rst @@ -370,10 +370,10 @@ .. method:: FTP.close() Close the connection unilaterally. This should not be applied to an already - closed connection such as after a successful call to :meth:`quit`. After this - call the :class:`FTP` instance should not be used any more (after a call to - :meth:`close` or :meth:`quit` you cannot reopen the connection by issuing - another :meth:`login` method). + closed connection such as after a successful call to :meth:`~FTP.quit`. + After this call the :class:`FTP` instance should not be used any more (after + a call to :meth:`close` or :meth:`~FTP.quit` you cannot reopen the + connection by issuing another :meth:`login` method). FTP_TLS Objects diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst --- a/Doc/library/poplib.rst +++ b/Doc/library/poplib.rst @@ -102,7 +102,7 @@ .. method:: POP3.pass_(password) Send password, response includes message count and mailbox size. Note: the - mailbox on the server is locked until :meth:`quit` is called. + mailbox on the server is locked until :meth:`~poplib.quit` is called. .. method:: POP3.apop(user, secret) diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -32,7 +32,8 @@ setting will be used). For normal use, you should only require the initialization/connect, - :meth:`sendmail`, and :meth:`quit` methods. An example is included below. + :meth:`sendmail`, and :meth:`~smtplib.quit` methods. + An example is included below. .. versionchanged:: 2.6 *timeout* was added. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 16:49:25 2012 From: python-checkins at python.org (jesus.cea) Date: Wed, 26 Dec 2012 16:49:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogQ2xvc2VzICMxNjc4?= =?utf-8?q?9=3A_=3Ameth=3A=60quit=60_links_to_constants_instead_of_own_mod?= =?utf-8?q?ule?= Message-ID: <3YWdsK5tFXzRjn@mail.python.org> http://hg.python.org/cpython/rev/3801ee5d5d73 changeset: 81070:3801ee5d5d73 branch: 3.2 parent: 81066:7e5d7ef4634d user: Jesus Cea date: Wed Dec 26 16:47:03 2012 +0100 summary: Closes #16789: :meth:`quit` links to constants instead of own module files: Doc/library/ftplib.rst | 8 ++++---- Doc/library/poplib.rst | 2 +- Doc/library/smtplib.rst | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst --- a/Doc/library/ftplib.rst +++ b/Doc/library/ftplib.rst @@ -377,10 +377,10 @@ .. method:: FTP.close() Close the connection unilaterally. This should not be applied to an already - closed connection such as after a successful call to :meth:`quit`. After this - call the :class:`FTP` instance should not be used any more (after a call to - :meth:`close` or :meth:`quit` you cannot reopen the connection by issuing - another :meth:`login` method). + closed connection such as after a successful call to :meth:`~FTP.quit`. + After this call the :class:`FTP` instance should not be used any more (after + a call to :meth:`close` or :meth:`~FTP.quit` you cannot reopen the + connection by issuing another :meth:`login` method). FTP_TLS Objects diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst --- a/Doc/library/poplib.rst +++ b/Doc/library/poplib.rst @@ -105,7 +105,7 @@ .. method:: POP3.pass_(password) Send password, response includes message count and mailbox size. Note: the - mailbox on the server is locked until :meth:`quit` is called. + mailbox on the server is locked until :meth:`~poplib.quit` is called. .. method:: POP3.apop(user, secret) diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -32,7 +32,8 @@ setting will be used). For normal use, you should only require the initialization/connect, - :meth:`sendmail`, and :meth:`quit` methods. An example is included below. + :meth:`sendmail`, and :meth:`~smtplib.quit` methods. + An example is included below. .. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout]) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 16:49:27 2012 From: python-checkins at python.org (jesus.cea) Date: Wed, 26 Dec 2012 16:49:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_MERGE=3A_Closes_=2316789=3A_=3Ameth=3A=60quit=60_links_to_cons?= =?utf-8?q?tants_instead_of_own_module?= Message-ID: <3YWdsM158rzRk8@mail.python.org> http://hg.python.org/cpython/rev/b6a9f8fd9443 changeset: 81071:b6a9f8fd9443 branch: 3.3 parent: 81067:7734c3020a47 parent: 81070:3801ee5d5d73 user: Jesus Cea date: Wed Dec 26 16:47:40 2012 +0100 summary: MERGE: Closes #16789: :meth:`quit` links to constants instead of own module files: Doc/library/ftplib.rst | 8 ++++---- Doc/library/poplib.rst | 2 +- Doc/library/smtplib.rst | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst --- a/Doc/library/ftplib.rst +++ b/Doc/library/ftplib.rst @@ -406,10 +406,10 @@ .. method:: FTP.close() Close the connection unilaterally. This should not be applied to an already - closed connection such as after a successful call to :meth:`quit`. After this - call the :class:`FTP` instance should not be used any more (after a call to - :meth:`close` or :meth:`quit` you cannot reopen the connection by issuing - another :meth:`login` method). + closed connection such as after a successful call to :meth:`~FTP.quit`. + After this call the :class:`FTP` instance should not be used any more (after + a call to :meth:`close` or :meth:`~FTP.quit` you cannot reopen the + connection by issuing another :meth:`login` method). FTP_TLS Objects diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst --- a/Doc/library/poplib.rst +++ b/Doc/library/poplib.rst @@ -105,7 +105,7 @@ .. method:: POP3.pass_(password) Send password, response includes message count and mailbox size. Note: the - mailbox on the server is locked until :meth:`quit` is called. + mailbox on the server is locked until :meth:`~poplib.quit` is called. .. method:: POP3.apop(user, secret) diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -37,7 +37,8 @@ behavior will be used. For normal use, you should only require the initialization/connect, - :meth:`sendmail`, and :meth:`quit` methods. An example is included below. + :meth:`sendmail`, and :meth:`~smtplib.quit` methods. + An example is included below. The :class:`SMTP` class supports the :keyword:`with` statement. When used like this, the SMTP ``QUIT`` command is issued automatically when the -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 16:49:28 2012 From: python-checkins at python.org (jesus.cea) Date: Wed, 26 Dec 2012 16:49:28 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTUVSR0U6IENsb3NlcyAjMTY3ODk6IDptZXRoOmBxdWl0YCBsaW5rcyB0?= =?utf-8?q?o_constants_instead_of_own_module?= Message-ID: <3YWdsN3Vd6zRhj@mail.python.org> http://hg.python.org/cpython/rev/3f7d5c235d82 changeset: 81072:3f7d5c235d82 parent: 81068:2d1cfbaef9a2 parent: 81071:b6a9f8fd9443 user: Jesus Cea date: Wed Dec 26 16:48:26 2012 +0100 summary: MERGE: Closes #16789: :meth:`quit` links to constants instead of own module files: Doc/library/ftplib.rst | 8 ++++---- Doc/library/poplib.rst | 2 +- Doc/library/smtplib.rst | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/library/ftplib.rst b/Doc/library/ftplib.rst --- a/Doc/library/ftplib.rst +++ b/Doc/library/ftplib.rst @@ -406,10 +406,10 @@ .. method:: FTP.close() Close the connection unilaterally. This should not be applied to an already - closed connection such as after a successful call to :meth:`quit`. After this - call the :class:`FTP` instance should not be used any more (after a call to - :meth:`close` or :meth:`quit` you cannot reopen the connection by issuing - another :meth:`login` method). + closed connection such as after a successful call to :meth:`~FTP.quit`. + After this call the :class:`FTP` instance should not be used any more (after + a call to :meth:`close` or :meth:`~FTP.quit` you cannot reopen the + connection by issuing another :meth:`login` method). FTP_TLS Objects diff --git a/Doc/library/poplib.rst b/Doc/library/poplib.rst --- a/Doc/library/poplib.rst +++ b/Doc/library/poplib.rst @@ -116,7 +116,7 @@ .. method:: POP3.pass_(password) Send password, response includes message count and mailbox size. Note: the - mailbox on the server is locked until :meth:`quit` is called. + mailbox on the server is locked until :meth:`~poplib.quit` is called. .. method:: POP3.apop(user, secret) diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -37,7 +37,8 @@ behavior will be used. For normal use, you should only require the initialization/connect, - :meth:`sendmail`, and :meth:`quit` methods. An example is included below. + :meth:`sendmail`, and :meth:`~smtplib.quit` methods. + An example is included below. The :class:`SMTP` class supports the :keyword:`with` statement. When used like this, the SMTP ``QUIT`` command is issued automatically when the -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 18:37:26 2012 From: python-checkins at python.org (georg.brandl) Date: Wed, 26 Dec 2012 18:37:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Add_Serhiy=2E?= Message-ID: <3YWhFy1LT7zRl9@mail.python.org> http://hg.python.org/devguide/rev/189620c7e755 changeset: 579:189620c7e755 user: Georg Brandl date: Wed Dec 26 18:37:23 2012 +0100 summary: Add Serhiy. files: developers.rst | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/developers.rst b/developers.rst --- a/developers.rst +++ b/developers.rst @@ -24,6 +24,9 @@ Permissions History ------------------- +- Serhiy Storchaka was given push privileges on Dec 26 2012 by GFB, for general + contributions, on recommendation by Trent Nelson. + - Chris Jerdonek was given push privileges on Sep 24 2012 by GFB, for general contributions, on recommendation by Ezio Melotti. -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Wed Dec 26 21:52:15 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 26 Dec 2012 21:52:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Revert_back_PyCFunction=5F?= =?utf-8?q?New_macro=2E_Keep_PyCFunction=5FNewEx_usage_in_python_core?= Message-ID: <3YWmZl46KJzM9d@mail.python.org> http://hg.python.org/cpython/rev/6a56eaa5e5fb changeset: 81073:6a56eaa5e5fb user: Andrew Svetlov date: Wed Dec 26 22:52:04 2012 +0200 summary: Revert back PyCFunction_New macro. Keep PyCFunction_NewEx usage in python core modules (#15422) files: Include/methodobject.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Include/methodobject.h b/Include/methodobject.h --- a/Include/methodobject.h +++ b/Include/methodobject.h @@ -46,7 +46,7 @@ }; typedef struct PyMethodDef PyMethodDef; -PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *); +#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, PyObject *); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 22:09:06 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 26 Dec 2012 22:09:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_compilation_error_for_?= =?utf-8?q?=2315422?= Message-ID: <3YWmyB73h7zRjX@mail.python.org> http://hg.python.org/cpython/rev/70ea05f762a1 changeset: 81074:70ea05f762a1 user: Andrew Svetlov date: Wed Dec 26 23:08:54 2012 +0200 summary: Fix compilation error for #15422 files: Objects/methodobject.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Objects/methodobject.c b/Objects/methodobject.c --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -13,6 +13,9 @@ #define PyCFunction_MAXFREELIST 256 #endif +/* undefine macro trampoline to PyCFunction_NewEx */ +#undef PyCFunction_New + PyObject * PyCFunction_New(PyMethodDef *ml, PyObject *self) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 22:36:32 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 26 Dec 2012 22:36:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_fix_test_for_s?= =?utf-8?q?ubprocess_=28=2316644=29?= Message-ID: <3YWnYr0Z89zRfY@mail.python.org> http://hg.python.org/cpython/rev/39be1514c16c changeset: 81075:39be1514c16c branch: 3.2 parent: 81070:3801ee5d5d73 user: Andrew Svetlov date: Wed Dec 26 23:31:45 2012 +0200 summary: fix test for subprocess (#16644) files: Lib/test/test_subprocess.py | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2023,8 +2023,7 @@ stderr=subprocess.PIPE) as proc: pass - if c.exception.errno != errno.ENOENT: # ignore "no such file" - raise c.exception + self.assertEqual(c.exception.errno, errno.ENOENT) def test_main(): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 22:36:33 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 26 Dec 2012 22:36:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_fix_test_for_subprocess_=28=2316644=29?= Message-ID: <3YWnYs31jNzRhC@mail.python.org> http://hg.python.org/cpython/rev/5d172190c37c changeset: 81076:5d172190c37c branch: 3.3 parent: 81071:b6a9f8fd9443 parent: 81075:39be1514c16c user: Andrew Svetlov date: Wed Dec 26 23:34:54 2012 +0200 summary: fix test for subprocess (#16644) files: Lib/test/test_subprocess.py | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2154,15 +2154,12 @@ self.assertEqual(proc.returncode, 1) def test_invalid_args(self): - with self.assertRaises(EnvironmentError) as c: + with self.assertRaises(FileNotFoundError) as c: with subprocess.Popen(['nonexisting_i_hope'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: pass - if c.exception.errno != errno.ENOENT: # ignore "no such file" - raise c.exception - def test_main(): unit_tests = (ProcessTestCase, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 22:36:34 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 26 Dec 2012 22:36:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_fix_test_for_subprocess_=28=2316644=29?= Message-ID: <3YWnYt5ljYzRkc@mail.python.org> http://hg.python.org/cpython/rev/02d589e2d202 changeset: 81077:02d589e2d202 parent: 81074:70ea05f762a1 parent: 81076:5d172190c37c user: Andrew Svetlov date: Wed Dec 26 23:36:17 2012 +0200 summary: fix test for subprocess (#16644) files: Lib/test/test_subprocess.py | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2154,15 +2154,12 @@ self.assertEqual(proc.returncode, 1) def test_invalid_args(self): - with self.assertRaises(OSError) as c: + with self.assertRaises(FileNotFoundError) as c: with subprocess.Popen(['nonexisting_i_hope'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: pass - if c.exception.errno != errno.ENOENT: # ignore "no such file" - raise c.exception - def test_main(): unit_tests = (ProcessTestCase, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Dec 26 23:43:46 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 26 Dec 2012 23:43:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_use_more_specific_type?= Message-ID: <3YWq3Q2R4BzRhx@mail.python.org> http://hg.python.org/cpython/rev/3b5fdb5bc597 changeset: 81078:3b5fdb5bc597 user: Benjamin Peterson date: Wed Dec 26 16:43:33 2012 -0600 summary: use more specific type files: Objects/longobject.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4072,7 +4072,7 @@ static PyObject * long_bitwise(PyLongObject *a, - int op, /* '&', '|', '^' */ + char op, /* '&', '|', '^' */ PyLongObject *b) { int nega, negb, negz; -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Thu Dec 27 05:54:42 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 27 Dec 2012 05:54:42 +0100 Subject: [Python-checkins] Daily reference leaks (3b5fdb5bc597): sum=0 Message-ID: results for 3b5fdb5bc597 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogJmOA5Y', '-x'] From python-checkins at python.org Thu Dec 27 10:25:52 2012 From: python-checkins at python.org (hynek.schlawack) Date: Thu, 27 Dec 2012 10:25:52 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2NjE4OiBNYWtl?= =?utf-8?q?_glob=2Eglob_match_consistently_across_strings_and_bytes?= Message-ID: <3YX5JJ6JYczNrf@mail.python.org> http://hg.python.org/cpython/rev/62f67a52b0c2 changeset: 81079:62f67a52b0c2 branch: 3.2 parent: 81075:39be1514c16c user: Hynek Schlawack date: Thu Dec 27 10:10:11 2012 +0100 summary: #16618: Make glob.glob match consistently across strings and bytes Fixes handling of leading dots. Patch by Serhiy Storchaka. files: Lib/glob.py | 7 ++- Lib/test/test_glob.py | 77 ++++++++++++++++++++---------- Misc/NEWS | 3 + 3 files changed, 58 insertions(+), 29 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -58,8 +58,8 @@ names = os.listdir(dirname) except os.error: return [] - if pattern[0] != '.': - names = [x for x in names if x[0] != '.'] + if not _ishidden(pattern): + names = [x for x in names if not _ishidden(x)] return fnmatch.filter(names, pattern) def glob0(dirname, basename): @@ -83,3 +83,6 @@ else: match = magic_check.search(s) return match is not None + +def _ishidden(path): + return path[0] in ('.', b'.'[0]) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -1,9 +1,10 @@ -import unittest -from test.support import run_unittest, TESTFN, skip_unless_symlink, can_symlink import glob import os import shutil import sys +import unittest + +from test.support import run_unittest, TESTFN, skip_unless_symlink, can_symlink class GlobTests(unittest.TestCase): @@ -31,7 +32,8 @@ self.mktemp('a', 'bcd', 'efg', 'ha') if can_symlink(): os.symlink(self.norm('broken'), self.norm('sym1')) - os.symlink(self.norm('broken'), self.norm('sym2')) + os.symlink('broken', self.norm('sym2')) + os.symlink(os.path.join('a', 'bcd'), self.norm('sym3')) def tearDown(self): shutil.rmtree(self.tempdir) @@ -44,10 +46,16 @@ p = os.path.join(self.tempdir, pattern) res = glob.glob(p) self.assertEqual(list(glob.iglob(p)), res) + bres = [os.fsencode(x) for x in res] + self.assertEqual(glob.glob(os.fsencode(p)), bres) + self.assertEqual(list(glob.iglob(os.fsencode(p))), bres) return res def assertSequencesEqual_noorder(self, l1, l2): + l1 = list(l1) + l2 = list(l2) self.assertEqual(set(l1), set(l2)) + self.assertEqual(sorted(l1), sorted(l2)) def test_glob_literal(self): eq = self.assertSequencesEqual_noorder @@ -56,15 +64,15 @@ eq(self.glob('aab'), [self.norm('aab')]) eq(self.glob('zymurgy'), []) - # test return types are unicode, but only if os.listdir - # returns unicode filenames - uniset = set([str]) - tmp = os.listdir('.') - if set(type(x) for x in tmp) == uniset: - u1 = glob.glob('*') - u2 = glob.glob('./*') - self.assertEqual(set(type(r) for r in u1), uniset) - self.assertEqual(set(type(r) for r in u2), uniset) + res = glob.glob('*') + self.assertEqual({type(r) for r in res}, {str}) + res = glob.glob(os.path.join(os.curdir, '*')) + self.assertEqual({type(r) for r in res}, {str}) + + res = glob.glob(b'*') + self.assertEqual({type(r) for r in res}, {bytes}) + res = glob.glob(os.path.join(os.fsencode(os.curdir), b'*')) + self.assertEqual({type(r) for r in res}, {bytes}) def test_glob_one_directory(self): eq = self.assertSequencesEqual_noorder @@ -93,20 +101,20 @@ eq(self.glob('*', '*a'), []) eq(self.glob('a', '*', '*', '*a'), [self.norm('a', 'bcd', 'efg', 'ha')]) - eq(self.glob('?a?', '*F'), map(self.norm, [os.path.join('aaa', 'zzzF'), - os.path.join('aab', 'F')])) + eq(self.glob('?a?', '*F'), [self.norm('aaa', 'zzzF'), + self.norm('aab', 'F')]) def test_glob_directory_with_trailing_slash(self): # Patterns ending with a slash shouldn't match non-dirs - res = glob.glob(os.path.join(self.tempdir, 'Z*Z') + os.sep) + res = glob.glob(self.norm('Z*Z') + os.sep) self.assertEqual(res, []) - res = glob.glob(os.path.join(self.tempdir, 'ZZZ') + os.sep) + res = glob.glob(self.norm('ZZZ') + os.sep) self.assertEqual(res, []) - # When there is wildcard pattern which ends with os.sep, glob() + # When there is a wildcard pattern which ends with os.sep, glob() # doesn't blow up. - res = glob.glob(os.path.join(self.tempdir, 'aa*') + os.sep) + res = glob.glob(self.norm('aa*') + os.sep) self.assertEqual(len(res), 2) - # either of these results are reasonable + # either of these results is reasonable self.assertIn(set(res), [ {self.norm('aaa'), self.norm('aab')}, {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, @@ -115,22 +123,37 @@ def test_glob_bytes_directory_with_trailing_slash(self): # Same as test_glob_directory_with_trailing_slash, but with a # bytes argument. - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'Z*Z') + os.sep)) + res = glob.glob(os.fsencode(self.norm('Z*Z') + os.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'ZZZ') + os.sep)) + res = glob.glob(os.fsencode(self.norm('ZZZ') + os.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'aa*') + os.sep)) + res = glob.glob(os.fsencode(self.norm('aa*') + os.sep)) self.assertEqual(len(res), 2) - # either of these results are reasonable - self.assertIn({os.fsdecode(x) for x in res}, [ - {self.norm('aaa'), self.norm('aab')}, - {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + # either of these results is reasonable + self.assertIn(set(res), [ + {os.fsencode(self.norm('aaa')), + os.fsencode(self.norm('aab'))}, + {os.fsencode(self.norm('aaa') + os.sep), + os.fsencode(self.norm('aab') + os.sep)}, ]) @skip_unless_symlink + def test_glob_symlinks(self): + eq = self.assertSequencesEqual_noorder + eq(self.glob('sym3'), [self.norm('sym3')]) + eq(self.glob('sym3', '*'), [self.norm('sym3', 'EF'), + self.norm('sym3', 'efg')]) + self.assertIn(self.glob('sym3' + os.sep), + [[self.norm('sym3')], [self.norm('sym3') + os.sep]]) + eq(self.glob('*', '*F'), + [self.norm('aaa', 'zzzF'), + self.norm('aab', 'F'), self.norm('sym3', 'EF')]) + + @skip_unless_symlink def test_glob_broken_symlinks(self): eq = self.assertSequencesEqual_noorder - eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2')]) + eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2'), + self.norm('sym3')]) eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym2'), [self.norm('sym2')]) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -179,6 +179,9 @@ Library ------- +- Issue #16618: Make glob.glob match consistently across strings and bytes + regarding leading dots. Patch by Serhiy Storchaka. + - Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for localhost tests. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 10:25:54 2012 From: python-checkins at python.org (hynek.schlawack) Date: Thu, 27 Dec 2012 10:25:54 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2316618=3A_Make_glob=2Eglob_match_consistently_across_strings?= =?utf-8?q?_and_bytes?= Message-ID: <3YX5JL2m4HzNt9@mail.python.org> http://hg.python.org/cpython/rev/fa8c4f96d990 changeset: 81080:fa8c4f96d990 branch: 3.3 parent: 81076:5d172190c37c parent: 81079:62f67a52b0c2 user: Hynek Schlawack date: Thu Dec 27 10:15:53 2012 +0100 summary: #16618: Make glob.glob match consistently across strings and bytes Fixes handling of leading dots. Patch by Serhiy Storchaka. files: Lib/glob.py | 7 +- Lib/test/test_glob.py | 79 ++++++++++++++++++++---------- Misc/NEWS | 3 + 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -58,8 +58,8 @@ names = os.listdir(dirname) except os.error: return [] - if pattern[0] != '.': - names = [x for x in names if x[0] != '.'] + if not _ishidden(pattern): + names = [x for x in names if not _ishidden(x)] return fnmatch.filter(names, pattern) def glob0(dirname, basename): @@ -83,3 +83,6 @@ else: match = magic_check.search(s) return match is not None + +def _ishidden(path): + return path[0] in ('.', b'.'[0]) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -1,10 +1,11 @@ -import unittest -from test.support import (run_unittest, TESTFN, skip_unless_symlink, - can_symlink, create_empty_file) import glob import os import shutil import sys +import unittest + +from test.support import (run_unittest, TESTFN, skip_unless_symlink, + can_symlink, create_empty_file) class GlobTests(unittest.TestCase): @@ -31,7 +32,8 @@ self.mktemp('a', 'bcd', 'efg', 'ha') if can_symlink(): os.symlink(self.norm('broken'), self.norm('sym1')) - os.symlink(self.norm('broken'), self.norm('sym2')) + os.symlink('broken', self.norm('sym2')) + os.symlink(os.path.join('a', 'bcd'), self.norm('sym3')) def tearDown(self): shutil.rmtree(self.tempdir) @@ -44,10 +46,16 @@ p = os.path.join(self.tempdir, pattern) res = glob.glob(p) self.assertEqual(list(glob.iglob(p)), res) + bres = [os.fsencode(x) for x in res] + self.assertEqual(glob.glob(os.fsencode(p)), bres) + self.assertEqual(list(glob.iglob(os.fsencode(p))), bres) return res def assertSequencesEqual_noorder(self, l1, l2): + l1 = list(l1) + l2 = list(l2) self.assertEqual(set(l1), set(l2)) + self.assertEqual(sorted(l1), sorted(l2)) def test_glob_literal(self): eq = self.assertSequencesEqual_noorder @@ -56,15 +64,15 @@ eq(self.glob('aab'), [self.norm('aab')]) eq(self.glob('zymurgy'), []) - # test return types are unicode, but only if os.listdir - # returns unicode filenames - uniset = set([str]) - tmp = os.listdir('.') - if set(type(x) for x in tmp) == uniset: - u1 = glob.glob('*') - u2 = glob.glob('./*') - self.assertEqual(set(type(r) for r in u1), uniset) - self.assertEqual(set(type(r) for r in u2), uniset) + res = glob.glob('*') + self.assertEqual({type(r) for r in res}, {str}) + res = glob.glob(os.path.join(os.curdir, '*')) + self.assertEqual({type(r) for r in res}, {str}) + + res = glob.glob(b'*') + self.assertEqual({type(r) for r in res}, {bytes}) + res = glob.glob(os.path.join(os.fsencode(os.curdir), b'*')) + self.assertEqual({type(r) for r in res}, {bytes}) def test_glob_one_directory(self): eq = self.assertSequencesEqual_noorder @@ -93,20 +101,20 @@ eq(self.glob('*', '*a'), []) eq(self.glob('a', '*', '*', '*a'), [self.norm('a', 'bcd', 'efg', 'ha')]) - eq(self.glob('?a?', '*F'), map(self.norm, [os.path.join('aaa', 'zzzF'), - os.path.join('aab', 'F')])) + eq(self.glob('?a?', '*F'), [self.norm('aaa', 'zzzF'), + self.norm('aab', 'F')]) def test_glob_directory_with_trailing_slash(self): # Patterns ending with a slash shouldn't match non-dirs - res = glob.glob(os.path.join(self.tempdir, 'Z*Z') + os.sep) + res = glob.glob(self.norm('Z*Z') + os.sep) self.assertEqual(res, []) - res = glob.glob(os.path.join(self.tempdir, 'ZZZ') + os.sep) + res = glob.glob(self.norm('ZZZ') + os.sep) self.assertEqual(res, []) - # When there is wildcard pattern which ends with os.sep, glob() + # When there is a wildcard pattern which ends with os.sep, glob() # doesn't blow up. - res = glob.glob(os.path.join(self.tempdir, 'aa*') + os.sep) + res = glob.glob(self.norm('aa*') + os.sep) self.assertEqual(len(res), 2) - # either of these results are reasonable + # either of these results is reasonable self.assertIn(set(res), [ {self.norm('aaa'), self.norm('aab')}, {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, @@ -115,22 +123,37 @@ def test_glob_bytes_directory_with_trailing_slash(self): # Same as test_glob_directory_with_trailing_slash, but with a # bytes argument. - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'Z*Z') + os.sep)) + res = glob.glob(os.fsencode(self.norm('Z*Z') + os.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'ZZZ') + os.sep)) + res = glob.glob(os.fsencode(self.norm('ZZZ') + os.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'aa*') + os.sep)) + res = glob.glob(os.fsencode(self.norm('aa*') + os.sep)) self.assertEqual(len(res), 2) - # either of these results are reasonable - self.assertIn({os.fsdecode(x) for x in res}, [ - {self.norm('aaa'), self.norm('aab')}, - {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + # either of these results is reasonable + self.assertIn(set(res), [ + {os.fsencode(self.norm('aaa')), + os.fsencode(self.norm('aab'))}, + {os.fsencode(self.norm('aaa') + os.sep), + os.fsencode(self.norm('aab') + os.sep)}, ]) @skip_unless_symlink + def test_glob_symlinks(self): + eq = self.assertSequencesEqual_noorder + eq(self.glob('sym3'), [self.norm('sym3')]) + eq(self.glob('sym3', '*'), [self.norm('sym3', 'EF'), + self.norm('sym3', 'efg')]) + self.assertIn(self.glob('sym3' + os.sep), + [[self.norm('sym3')], [self.norm('sym3') + os.sep]]) + eq(self.glob('*', '*F'), + [self.norm('aaa', 'zzzF'), + self.norm('aab', 'F'), self.norm('sym3', 'EF')]) + + @skip_unless_symlink def test_glob_broken_symlinks(self): eq = self.assertSequencesEqual_noorder - eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2')]) + eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2'), + self.norm('sym3')]) eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym2'), [self.norm('sym2')]) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -114,6 +114,9 @@ Library ------- +- Issue #16618: Make glob.glob match consistently across strings and bytes + regarding leading dots. Patch by Serhiy Storchaka. + - Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for localhost tests. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 10:25:55 2012 From: python-checkins at python.org (hynek.schlawack) Date: Thu, 27 Dec 2012 10:25:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_=2316618=3A_Make_glob=2Eglob_match_consistently_across_s?= =?utf-8?q?trings_and_bytes?= Message-ID: <3YX5JM6tSxzQkQ@mail.python.org> http://hg.python.org/cpython/rev/eae2a42603ee changeset: 81081:eae2a42603ee parent: 81078:3b5fdb5bc597 parent: 81080:fa8c4f96d990 user: Hynek Schlawack date: Thu Dec 27 10:20:38 2012 +0100 summary: #16618: Make glob.glob match consistently across strings and bytes Fixes handling of leading dots. Patch by Serhiy Storchaka. files: Lib/glob.py | 7 +- Lib/test/test_glob.py | 79 ++++++++++++++++++++---------- Misc/NEWS | 3 + 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py --- a/Lib/glob.py +++ b/Lib/glob.py @@ -57,8 +57,8 @@ names = os.listdir(dirname) except OSError: return [] - if pattern[0] != '.': - names = [x for x in names if x[0] != '.'] + if not _ishidden(pattern): + names = [x for x in names if not _ishidden(x)] return fnmatch.filter(names, pattern) def glob0(dirname, basename): @@ -82,3 +82,6 @@ else: match = magic_check.search(s) return match is not None + +def _ishidden(path): + return path[0] in ('.', b'.'[0]) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -1,10 +1,11 @@ -import unittest -from test.support import (run_unittest, TESTFN, skip_unless_symlink, - can_symlink, create_empty_file) import glob import os import shutil import sys +import unittest + +from test.support import (run_unittest, TESTFN, skip_unless_symlink, + can_symlink, create_empty_file) class GlobTests(unittest.TestCase): @@ -31,7 +32,8 @@ self.mktemp('a', 'bcd', 'efg', 'ha') if can_symlink(): os.symlink(self.norm('broken'), self.norm('sym1')) - os.symlink(self.norm('broken'), self.norm('sym2')) + os.symlink('broken', self.norm('sym2')) + os.symlink(os.path.join('a', 'bcd'), self.norm('sym3')) def tearDown(self): shutil.rmtree(self.tempdir) @@ -44,10 +46,16 @@ p = os.path.join(self.tempdir, pattern) res = glob.glob(p) self.assertEqual(list(glob.iglob(p)), res) + bres = [os.fsencode(x) for x in res] + self.assertEqual(glob.glob(os.fsencode(p)), bres) + self.assertEqual(list(glob.iglob(os.fsencode(p))), bres) return res def assertSequencesEqual_noorder(self, l1, l2): + l1 = list(l1) + l2 = list(l2) self.assertEqual(set(l1), set(l2)) + self.assertEqual(sorted(l1), sorted(l2)) def test_glob_literal(self): eq = self.assertSequencesEqual_noorder @@ -56,15 +64,15 @@ eq(self.glob('aab'), [self.norm('aab')]) eq(self.glob('zymurgy'), []) - # test return types are unicode, but only if os.listdir - # returns unicode filenames - uniset = set([str]) - tmp = os.listdir('.') - if set(type(x) for x in tmp) == uniset: - u1 = glob.glob('*') - u2 = glob.glob('./*') - self.assertEqual(set(type(r) for r in u1), uniset) - self.assertEqual(set(type(r) for r in u2), uniset) + res = glob.glob('*') + self.assertEqual({type(r) for r in res}, {str}) + res = glob.glob(os.path.join(os.curdir, '*')) + self.assertEqual({type(r) for r in res}, {str}) + + res = glob.glob(b'*') + self.assertEqual({type(r) for r in res}, {bytes}) + res = glob.glob(os.path.join(os.fsencode(os.curdir), b'*')) + self.assertEqual({type(r) for r in res}, {bytes}) def test_glob_one_directory(self): eq = self.assertSequencesEqual_noorder @@ -93,20 +101,20 @@ eq(self.glob('*', '*a'), []) eq(self.glob('a', '*', '*', '*a'), [self.norm('a', 'bcd', 'efg', 'ha')]) - eq(self.glob('?a?', '*F'), map(self.norm, [os.path.join('aaa', 'zzzF'), - os.path.join('aab', 'F')])) + eq(self.glob('?a?', '*F'), [self.norm('aaa', 'zzzF'), + self.norm('aab', 'F')]) def test_glob_directory_with_trailing_slash(self): # Patterns ending with a slash shouldn't match non-dirs - res = glob.glob(os.path.join(self.tempdir, 'Z*Z') + os.sep) + res = glob.glob(self.norm('Z*Z') + os.sep) self.assertEqual(res, []) - res = glob.glob(os.path.join(self.tempdir, 'ZZZ') + os.sep) + res = glob.glob(self.norm('ZZZ') + os.sep) self.assertEqual(res, []) - # When there is wildcard pattern which ends with os.sep, glob() + # When there is a wildcard pattern which ends with os.sep, glob() # doesn't blow up. - res = glob.glob(os.path.join(self.tempdir, 'aa*') + os.sep) + res = glob.glob(self.norm('aa*') + os.sep) self.assertEqual(len(res), 2) - # either of these results are reasonable + # either of these results is reasonable self.assertIn(set(res), [ {self.norm('aaa'), self.norm('aab')}, {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, @@ -115,22 +123,37 @@ def test_glob_bytes_directory_with_trailing_slash(self): # Same as test_glob_directory_with_trailing_slash, but with a # bytes argument. - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'Z*Z') + os.sep)) + res = glob.glob(os.fsencode(self.norm('Z*Z') + os.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'ZZZ') + os.sep)) + res = glob.glob(os.fsencode(self.norm('ZZZ') + os.sep)) self.assertEqual(res, []) - res = glob.glob(os.fsencode(os.path.join(self.tempdir, 'aa*') + os.sep)) + res = glob.glob(os.fsencode(self.norm('aa*') + os.sep)) self.assertEqual(len(res), 2) - # either of these results are reasonable - self.assertIn({os.fsdecode(x) for x in res}, [ - {self.norm('aaa'), self.norm('aab')}, - {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + # either of these results is reasonable + self.assertIn(set(res), [ + {os.fsencode(self.norm('aaa')), + os.fsencode(self.norm('aab'))}, + {os.fsencode(self.norm('aaa') + os.sep), + os.fsencode(self.norm('aab') + os.sep)}, ]) @skip_unless_symlink + def test_glob_symlinks(self): + eq = self.assertSequencesEqual_noorder + eq(self.glob('sym3'), [self.norm('sym3')]) + eq(self.glob('sym3', '*'), [self.norm('sym3', 'EF'), + self.norm('sym3', 'efg')]) + self.assertIn(self.glob('sym3' + os.sep), + [[self.norm('sym3')], [self.norm('sym3') + os.sep]]) + eq(self.glob('*', '*F'), + [self.norm('aaa', 'zzzF'), + self.norm('aab', 'F'), self.norm('sym3', 'EF')]) + + @skip_unless_symlink def test_glob_broken_symlinks(self): eq = self.assertSequencesEqual_noorder - eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2')]) + eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2'), + self.norm('sym3')]) eq(self.glob('sym1'), [self.norm('sym1')]) eq(self.glob('sym2'), [self.norm('sym2')]) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -190,6 +190,9 @@ Library ------- +- Issue #16618: Make glob.glob match consistently across strings and bytes + regarding leading dots. Patch by Serhiy Storchaka. + - Issue #16788: Add samestat to Lib/ntpath.py - Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 10:25:57 2012 From: python-checkins at python.org (hynek.schlawack) Date: Thu, 27 Dec 2012 10:25:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2NjE4OiBBZGQg?= =?utf-8?q?more_glob_regression_tests?= Message-ID: <3YX5JP42wVzQwl@mail.python.org> http://hg.python.org/cpython/rev/44609ff7e53c changeset: 81082:44609ff7e53c branch: 2.7 parent: 81069:0ffaf1079a7a user: Hynek Schlawack date: Thu Dec 27 10:24:21 2012 +0100 summary: #16618: Add more glob regression tests Mostly about symlinks and str/unicode behavior. Patch by Serhiy Storchaka. files: Lib/test/test_glob.py | 99 +++++++++++++++++++++++------- Misc/NEWS | 3 + 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/Lib/test/test_glob.py b/Lib/test/test_glob.py --- a/Lib/test/test_glob.py +++ b/Lib/test/test_glob.py @@ -1,9 +1,14 @@ -import unittest -from test.test_support import run_unittest, TESTFN import glob import os import shutil import sys +import unittest + +from test.test_support import run_unittest, TESTFN + + +def fsdecode(s): + return unicode(s, sys.getfilesystemencoding()) class GlobTests(unittest.TestCase): @@ -31,7 +36,8 @@ self.mktemp('a', 'bcd', 'efg', 'ha') if hasattr(os, 'symlink'): os.symlink(self.norm('broken'), self.norm('sym1')) - os.symlink(self.norm('broken'), self.norm('sym2')) + os.symlink('broken', self.norm('sym2')) + os.symlink(os.path.join('a', 'bcd'), self.norm('sym3')) def tearDown(self): shutil.rmtree(self.tempdir) @@ -44,10 +50,16 @@ p = os.path.join(self.tempdir, pattern) res = glob.glob(p) self.assertEqual(list(glob.iglob(p)), res) + ures = [fsdecode(x) for x in res] + self.assertEqual(glob.glob(fsdecode(p)), ures) + self.assertEqual(list(glob.iglob(fsdecode(p))), ures) return res def assertSequencesEqual_noorder(self, l1, l2): + l1 = list(l1) + l2 = list(l2) self.assertEqual(set(l1), set(l2)) + self.assertEqual(sorted(l1), sorted(l2)) def test_glob_literal(self): eq = self.assertSequencesEqual_noorder @@ -56,15 +68,19 @@ eq(self.glob('aab'), [self.norm('aab')]) eq(self.glob('zymurgy'), []) + res = glob.glob('*') + self.assertEqual({type(r) for r in res}, {str}) + res = glob.glob(os.path.join(os.curdir, '*')) + self.assertEqual({type(r) for r in res}, {str}) + # test return types are unicode, but only if os.listdir # returns unicode filenames - uniset = set([unicode]) - tmp = os.listdir(u'.') - if set(type(x) for x in tmp) == uniset: - u1 = glob.glob(u'*') - u2 = glob.glob(u'./*') - self.assertEqual(set(type(r) for r in u1), uniset) - self.assertEqual(set(type(r) for r in u2), uniset) + tmp = os.listdir(fsdecode(os.curdir)) + if {type(x) for x in tmp} == {unicode}: + res = glob.glob(u'*') + self.assertEqual({type(r) for r in res}, {unicode}) + res = glob.glob(os.path.join(fsdecode(os.curdir), u'*')) + self.assertEqual({type(r) for r in res}, {unicode}) def test_glob_one_directory(self): eq = self.assertSequencesEqual_noorder @@ -93,23 +109,60 @@ eq(self.glob('*', '*a'), []) eq(self.glob('a', '*', '*', '*a'), [self.norm('a', 'bcd', 'efg', 'ha')]) - eq(self.glob('?a?', '*F'), map(self.norm, [os.path.join('aaa', 'zzzF'), - os.path.join('aab', 'F')])) + eq(self.glob('?a?', '*F'), [self.norm('aaa', 'zzzF'), + self.norm('aab', 'F')]) def test_glob_directory_with_trailing_slash(self): - # We are verifying that when there is wildcard pattern which - # ends with os.sep doesn't blow up. - res = glob.glob(self.tempdir + '*' + os.sep) - self.assertEqual(len(res), 1) - # either of these results are reasonable - self.assertIn(res[0], [self.tempdir, self.tempdir + os.sep]) + # Patterns ending with a slash shouldn't match non-dirs + res = glob.glob(self.norm('Z*Z') + os.sep) + self.assertEqual(res, []) + res = glob.glob(self.norm('ZZZ') + os.sep) + self.assertEqual(res, []) + # When there is a wildcard pattern which ends with os.sep, glob() + # doesn't blow up. + res = glob.glob(self.norm('aa*') + os.sep) + self.assertEqual(len(res), 2) + # either of these results is reasonable + self.assertIn(set(res), [ + {self.norm('aaa'), self.norm('aab')}, + {self.norm('aaa') + os.sep, self.norm('aab') + os.sep}, + ]) + def test_glob_unicode_directory_with_trailing_slash(self): + # Same as test_glob_directory_with_trailing_slash, but with an + # unicode argument. + res = glob.glob(fsdecode(self.norm('Z*Z') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(fsdecode(self.norm('ZZZ') + os.sep)) + self.assertEqual(res, []) + res = glob.glob(fsdecode(self.norm('aa*') + os.sep)) + self.assertEqual(len(res), 2) + # either of these results is reasonable + self.assertIn(set(res), [ + {fsdecode(self.norm('aaa')), fsdecode(self.norm('aab'))}, + {fsdecode(self.norm('aaa') + os.sep), + fsdecode(self.norm('aab') + os.sep)}, + ]) + + @unittest.skipUnless(hasattr(os, 'symlink'), "Requires symlink support") + def test_glob_symlinks(self): + eq = self.assertSequencesEqual_noorder + eq(self.glob('sym3'), [self.norm('sym3')]) + eq(self.glob('sym3', '*'), [self.norm('sym3', 'EF'), + self.norm('sym3', 'efg')]) + self.assertIn(self.glob('sym3' + os.sep), + [[self.norm('sym3')], [self.norm('sym3') + os.sep]]) + eq(self.glob('*', '*F'), + [self.norm('aaa', 'zzzF'), self.norm('aab', 'F'), + self.norm('sym3', 'EF')]) + + @unittest.skipUnless(hasattr(os, 'symlink'), "Requires symlink support") def test_glob_broken_symlinks(self): - if hasattr(os, 'symlink'): - eq = self.assertSequencesEqual_noorder - eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2')]) - eq(self.glob('sym1'), [self.norm('sym1')]) - eq(self.glob('sym2'), [self.norm('sym2')]) + eq = self.assertSequencesEqual_noorder + eq(self.glob('sym*'), [self.norm('sym1'), self.norm('sym2'), + self.norm('sym3')]) + eq(self.glob('sym1'), [self.norm('sym1')]) + eq(self.glob('sym2'), [self.norm('sym2')]) @unittest.skipUnless(sys.platform == "win32", "Win32 specific test") def test_glob_magic_in_drive(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -574,6 +574,9 @@ Tests ----- +- Issue #16618: Add more regression tests for glob. + Patch by Serhiy Storchaka. + - Issue #16664: Add regression tests for glob's behaviour concerning entries starting with a ".". Patch by Sebastian Kreft. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 15:07:43 2012 From: python-checkins at python.org (petri.lehtinen) Date: Thu, 27 Dec 2012 15:07:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Add_myself_as_the_mailbox?= =?utf-8?q?_maintainer?= Message-ID: <3YXCYW6gS1zRfL@mail.python.org> http://hg.python.org/devguide/rev/7f30ff78c729 changeset: 580:7f30ff78c729 user: Petri Lehtinen date: Thu Dec 27 16:07:16 2012 +0200 summary: Add myself as the mailbox maintainer files: experts.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/experts.rst b/experts.rst --- a/experts.rst +++ b/experts.rst @@ -140,7 +140,7 @@ logging vinay.sajip lzma nadeem.vawda macpath -mailbox +mailbox petri.lehtinen mailcap marshal math mark.dickinson, rhettinger, stutzbach -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Thu Dec 27 15:41:26 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 27 Dec 2012 15:41:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_432=3A_Proposal_for_tamin?= =?utf-8?q?g_the_startup_sequence?= Message-ID: <3YXDJQ2ZpmzRWD@mail.python.org> http://hg.python.org/peps/rev/a5261cd124c9 changeset: 4635:a5261cd124c9 user: Nick Coghlan date: Fri Dec 28 00:41:16 2012 +1000 summary: PEP 432: Proposal for taming the startup sequence files: pep-0432.txt | 395 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 395 insertions(+), 0 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt new file mode 100644 --- /dev/null +++ b/pep-0432.txt @@ -0,0 +1,395 @@ +PEP: 432 +Title: Simplifying the CPython startup sequence +Version: $Revision$ +Last-Modified: $Date$ +Author: Nick Coghlan +Status: Draft +Type: Standards Track +Content-Type: text/x-rst +Created: 28-Dec-2012 + + +Abstract +======== + +This PEP proposes a mechanism for simplifying the startup sequence for +CPython, making it easier to modify the initialisation behaviour of the +reference interpreter executable, as well as making it easier to control +CPython's startup behaviour when creating an alternate executable or +embedding it as a Python execution engine inside a larger application. + + +Proposal Summary +================ + +This PEP proposes that CPython move to an explicit 2-phase initialisation +process, where a preliminary interpreter is put in place with limited OS +interaction capabilities early in the startup sequence. This essential core +remains in place while all of the configuration settings are determined, +until a final configuration call takes those settings and finishes +bootstrapping the interpreter immediately before executing the main module. + +As a concrete use case to help guide any design changes, and to solve a known +problem where the appropriate defaults for system utilities differ from those +for running user scripts, this PEP also proposes the creation and +distribution of a separate system Python (``spython``) executable which, by +default, ignores user site directories and environment variables, and does +not implicitly set ``sys.path[0]`` based on the current directory or the +script being executed. + + +Background +========== + +Over time, CPython's initialisation sequence has become progressively more +complicated, offering more options, as well as performing more complex tasks +(such as configuring the Unicode settings for OS interfaces in Python 3 as +well as bootstrapping a pure Python implementation of the import system). + +Much of this complexity is accessible only through the ``Py_Main`` and +``Py_Initialize`` APIs, offering embedding applications little opportunity +for customisation. This creeping complexity also makes life difficult for +maintainers, as much of the configuration needs to take place prior to the +``Py_Initialize`` call, meaning much of the Python C API cannot be used +safely. + +A number of proposals are on the table for even *more* sophisticated +startup behaviour, such as better control over ``sys.path`` initialisation +(easily adding additional directories on the command line in a cross-platform +fashion, as well as controlling the configuration of ``sys.path[0]``), easier +configuration of utilities like coverage tracing when launching Python +subprocesses, and easier control of the encoding used for the standard IO +streams when embedding CPython in a larger application. + +Rather than attempting to bolt such behaviour onto an already complicated +system, this PEP proposes to instead simplify the status quo *first*, with +the aim of making these further feature requests easier to implement. + + +Key Concerns +============ + +There are a couple of key concerns that any change to the startup sequence +needs to take into account. + + +Maintainability +--------------- + +The current CPython startup sequence is difficult to understand, and even +more difficult to modify. It is not clear what state the interpreter is in +while much of the initialisation code executes, leading to behaviour such +as lists, dictionaries and Unicode values being created prior to the call +to ``Py_Initialize`` when the ``-X`` or ``-W`` options are used [1_]. + +By moving to a 2-phase startup sequence, developers should only need to +understand which features are not available in the core bootstrapping state, +as the vast majority of the configuration process will now take place in +that state. + +By basing the new design on a combination of C structures and Python +dictionaries, it should also be easier to modify the system in the +future to add new configuration options. + + +Performance +----------- + +CPython is used heavily to run short scripts where the runtime is dominated +by the interpreter initialisation time. Any changes to the startup sequence +should minimise their impact on the startup overhead. (Given that the +overhead is dominated by IO operations, this is not currently expected to +cause any significant problems). + + +The Status Quo +============== + +Much of the configuration of CPython is currently handled through C level +global variables:: + + Py_IgnoreEnvironmentFlag + Py_HashRandomizationFlag + _Py_HashSecretInitialized + _Py_HashSecret + Py_BytesWarningFlag + Py_DebugFlag + Py_InspectFlag + Py_InteractiveFlag + Py_OptimizeFlag + Py_DontWriteBytecodeFlag + Py_NoUserSiteDirectory + Py_NoSiteFlag + Py_UnbufferedStdioFlag + Py_VerboseFlag + +For the above variables, the conversion of command line options and +environment variables to C global variables is handled by ``Py_Main``, +so each embedding application must set those appropriately in order to +change them from their defaults. + +Some configuration can only be provided as OS level environment variables:: + + PYTHONHASHSEED + PYTHONSTARTUP + PYTHONPATH + PYTHONHOME + PYTHONCASEOK + PYTHONIOENCODING + +Additional configuration is handled via separate API calls:: + + Py_SetProgramName() (call before Py_Initialize()) + Py_SetPath() (optional, call before Py_Initialize()) + Py_SetPythonHome() (optional, call before Py_Initialize()???) + Py_SetArgv[Ex]() (call after Py_Initialize()) + +The ``Py_InitializeEx()`` API also accepts a boolean flag to indicate +whether or not CPython's signal handlers should be installed. + +Finally, some interactive behaviour (such as printing the introductory +banner) is triggered only when standard input is reported as a terminal +connection by the operating system. + +Also see more detailed notes at [1_] + + +Proposal +======== + +(Note: details here are still very much in flux, but preliminary feedback +is appreciated anyway) + +Core Interpreter Initialisation +------------------------------- + +The only configuration that currently absolutely needs to be in place +before even the interpreter core can be initialised is the seed for the +randomised hash algorithm. However, there are a couple of settings needed +there: whether or not hash randomisation is enabled at all, and if it's +enabled, whether or not to use a specific seed value. + +The proposed API for this step in the startup sequence is:: + + void Py_BeginInitialization(Py_CoreConfig *config); + +Like Py_Initialize, this part of the new API treats initialisation failures +as fatal errors. While that's still not particularly embedding friendly, +the operations in this step *really* shouldn't be failing, and changing them +to return error codes instead of aborting would be an even larger task than +the one already being proposed. + +The new Py_CoreConfig struct holds the settings required for preliminary +configuration:: + + typedef struct { + int use_hash_seed; + size_t hash_seed; + } Py_CoreConfig; + +To "disable" hash randomisation, set "use_hash_seed" and pass a hash seed of +zero. (This seems reasonable to me, but there may be security implications +I'm overlooking. If so, adding a separate flag or switching to a 3-valued +"no randomisation", "fixed hash seed" and "randomised hash" option is easy) + +The core configuration settings pointer may be NULL, in which case the +default behaviour of randomised hashes with a random seed will be used. + +A new query API will allow code to determine if the interpreter is in the +bootstrapping state between core initialisation and the completion of the +initialisation process:: + + int Py_IsInitializing(); + +While in the initialising state, the interpreter should be fully functional +except that: + +* compilation is not allowed (as the parser is not yet configured properly) +* The following attributes in the ``sys`` module are all either missing or + ``None``: + * ``sys.path`` + * ``sys.argv`` + * ``sys.executable`` + * ``sys.base_exec_prefix`` + * ``sys.base_prefix`` + * ``sys.exec_prefix`` + * ``sys.prefix`` + * ``sys.warnoptions`` + * ``sys.flags`` + * ``sys.dont_write_bytecode`` + * ``sys.stdin`` + * ``sys.stdout`` +* The filesystem encoding is not yet defined +* The IO encoding is not yet defined +* CPython signal handlers are not yet installed +* only builtin and frozen modules may be imported (due to above limitations) +* ``sys.stderr`` is set to a temporary IO object using unbuffered binary + mode +* The ``warnings`` module is not yet initialised +* The ``__main__`` module does not yet exist + + + +The main things made available by this step will be the core Python +datatypes, in particular dictionaries, lists and strings. This allows them +to be used safely for all of the remaining configuration steps (unlike the +status quo). + +In addition, the current thread will possess a valid Python thread state, +allow any further configuration data to be stored. + +Any call to Py_InitStart() must have a matching call to Py_Finalize(). It +is acceptable to skip calling Py_InitFinish() in between (e.g. if +attempting to read the configuration settings fails) + + +Determining the remaining configuration settings +------------------------------------------------ + +The next step in the initialisation sequence is to determine the full +settings needed to complete the process. No changes are made to the +interpreter state at this point. The core API for this step is:: + + int Py_ReadConfiguration(PyObject *config); + +The config argument should be a pointer to a Python dictionary. For any +supported configuration setting already in the dictionary, CPython will +sanity check the supplied value, but otherwise accept it as correct. + +Unlike Py_Initialize and Py_BeginInitialization, this call will raise an +exception and report an error return rather than exhibiting fatal errors if +a problem is found with the config data. + +Any supported configuration setting which is not already set will be +populated appropriately. The default configuration can be overridden +entirely by setting the value *before* calling Py_ReadConfiguration. The +provided value will then also be used in calculating any settings derived +from that value. + +Alternatively, settings may be overridden *after* the Py_ReadConfiguration +call (this can be useful if an embedding application wants to adjust +a setting rather than replace it completely, such as removing +``sys.path[0]``). + + +Supported configuration settings +-------------------------------- + +At least the following configuration settings will be supported:: + + raw_argv (list of str, default = retrieved from OS APIs) + + argv (list of str, default = derived from raw_argv) + warnoptions (list of str, default = derived from raw_argv and environment) + xoptions (list of str, default = derived from raw_argv and environment) + + program_name (str, default = retrieved from OS APIs) + executable (str, default = derived from program_name) + home (str, default = complicated!) + prefix (str, default = complicated!) + exec_prefix (str, default = complicated!) + base_prefix (str, default = complicated!) + base_exec_prefix (str, default = complicated!) + path (list of str, default = complicated!) + + io_encoding (str, default = derived from environment or OS APIs) + fs_encoding (str, default = derived from OS APIs) + + skip_signal_handlers (boolean, default = derived from environment or False) + ignore_environment (boolean, default = derived from environment or False) + dont_write_bytecode (boolean, default = derived from environment or False) + no_site (boolean, default = derived from environment or False) + no_user_site (boolean, default = derived from environment or False) + + + + +Completing the interpreter initialisation +----------------------------------------- + +The final step in the process is to actually put the configuration settings +into effect and finish bootstrapping the interpreter up to full operation:: + + int Py_EndInitialization(PyObject *config); + +Like Py_ReadConfiguration, this call will raise an exception and report an +error return rather than exhibiting fatal errors if a problem is found with +the config data. + +After a successful call, Py_IsInitializing() will be false, while +Py_IsInitialized() will become true. The caveats described above for the +interpreter during the initialisation phase will no longer hold. + + +Stable ABI +---------- + +All of the APIs proposed in this PEP are excluded from the stable ABI, as +embedding a Python interpreter involves a much higher degree of coupling +than merely writing an extension. + + +Backwards Compatibility +----------------------- + +Backwards compatibility will be preserved primarily by ensuring that +Py_ReadConfiguration() interrogates all the previously defined configuration +settings stored in global variables and environment variables. + +One acknowledged incompatiblity is that some environment variables which +are currently read lazily may instead be read once during interpreter +initialisation. As the PEP matures, these will be discussed in more detail +on a case by case basis. + + +A System Python Executable +========================== + +When executing system utilities with administrative access to a system, many +of the default behaviours of CPython are undesirable, as they may allow +untrusted code to execute with elevated privileges. The most problematic +aspects are the fact that user site directories are enabled, +environment variables are trusted and that the directory containing the +executed file is placed at the beginning of the import path. + +Currently, providing a separate executable with different default behaviour +would be prohibitively hard to maintain. One of the goals of this PEP is to +make it possible to replace much of the hard to maintain bootstrapping code +with more normal CPython code, as well as making it easier for a separate +application to make use of key components of ``Py_Main``. Including this +change in the PEP is designed to help avoid acceptance of a design that +sounds good in theory but proves to be problematic in practice. + +One final aspect not addressed by the general embedding changes above is +the current inaccessibility of the core logic for deciding between the +different execution modes supported by CPython:: + + * script execution + * directory/zipfile execution + * command execution ("-c" switch) + * module or package execution ("-m" switch) + * execution from stdin (non-interactive) + * interactive stdin + + + +Implementation +============== + +None as yet. Once I have a reasonably solid plan of attack, I intend to work +on a reference implementation as a feature branch in my BitBucket sandbox [2_] + + +References +========== + +.. [1] CPython interpreter initialization notes + (http://wiki.python.org/moin/CPythonInterpreterInitialization) + +.. [2] BitBucket Sandbox + (https://bitbucket.org/ncoghlan/cpython_sandbox) + + +Copyright +=========== +This document has been placed in the public domain. -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 27 15:54:32 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 27 Dec 2012 15:54:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Additional_header_info_for_PE?= =?utf-8?q?P_342?= Message-ID: <3YXDbX4qsczNtt@mail.python.org> http://hg.python.org/peps/rev/94c80f268c44 changeset: 4636:94c80f268c44 user: Nick Coghlan date: Fri Dec 28 00:54:23 2012 +1000 summary: Additional header info for PEP 342 files: pep-0432.txt | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -7,6 +7,8 @@ Type: Standards Track Content-Type: text/x-rst Created: 28-Dec-2012 +Python-Version: 3.4 +Post-History: 28-Dec-2012 Abstract -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 27 16:10:16 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 27 Dec 2012 16:10:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Proofread_before_posting_to_p?= =?utf-8?q?ython-ideas?= Message-ID: <3YXDxh2hYwzRh8@mail.python.org> http://hg.python.org/peps/rev/91befe5c72fd changeset: 4637:91befe5c72fd user: Nick Coghlan date: Fri Dec 28 01:10:05 2012 +1000 summary: Proofread before posting to python-ideas files: pep-0432.txt | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -238,11 +238,12 @@ status quo). In addition, the current thread will possess a valid Python thread state, -allow any further configuration data to be stored. +allow any further configuration data to be stored on the interpreter object +rather than in C process globals. -Any call to Py_InitStart() must have a matching call to Py_Finalize(). It -is acceptable to skip calling Py_InitFinish() in between (e.g. if -attempting to read the configuration settings fails) +Any call to Py_BeginInitialization() must have a matching call to +Py_Finalize(). It is acceptable to skip calling Py_EndInitialization() in +between (e.g. if attempting to read the configuration settings fails) Determining the remaining configuration settings @@ -343,6 +344,11 @@ initialisation. As the PEP matures, these will be discussed in more detail on a case by case basis. +The Py_Initialize() style of initialisation will continue to be supported. It +will use the new API internally, but will continue to exhibit the same +behaviour as it does today, ensuring that sys.argv is not set until a +subsequent PySys_SetArgv call. + A System Python Executable ========================== @@ -364,14 +370,14 @@ One final aspect not addressed by the general embedding changes above is the current inaccessibility of the core logic for deciding between the -different execution modes supported by CPython:: +different execution modes supported by CPython: - * script execution - * directory/zipfile execution - * command execution ("-c" switch) - * module or package execution ("-m" switch) - * execution from stdin (non-interactive) - * interactive stdin +* script execution +* directory/zipfile execution +* command execution ("-c" switch) +* module or package execution ("-m" switch) +* execution from stdin (non-interactive) +* interactive stdin -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Dec 27 17:30:57 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 17:30:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4ICMxNDQyMC4g?= =?utf-8?q?Use_PyLong=5FAsUnsignedLong_to_support_the_full_range_of_DWORD?= =?utf-8?q?=2E?= Message-ID: <3YXGkn55q3zQtr@mail.python.org> http://hg.python.org/cpython/rev/b9752b6c40f8 changeset: 81083:b9752b6c40f8 branch: 3.2 parent: 81079:62f67a52b0c2 user: Brian Curtin date: Thu Dec 27 10:12:45 2012 -0600 summary: Fix #14420. Use PyLong_AsUnsignedLong to support the full range of DWORD. This fixes an OverflowError seen in winreg.SetValueEx when passed winreg.REG_DWORD values that should be supported by the underlying API. files: Lib/test/test_winreg.py | 12 ++++++++++++ Misc/NEWS | 3 +++ PC/winreg.c | 2 +- 3 files changed, 16 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -323,6 +323,18 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_setvalueex_value_range(self): + # Test for Issue #14420, accept proper ranges for SetValueEx. + # Py2Reg, which gets called by SetValueEx, was using PyLong_AsLong, + # thus raising OverflowError. The implementation now uses + # PyLong_AsUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + SetValueEx(ck, "test_name", None, REG_DWORD, 0x80000000) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg + when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. + - Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -785,7 +785,7 @@ memcpy(*retDataBuf, &zero, sizeof(DWORD)); } else { - DWORD d = PyLong_AsLong(value); + DWORD d = PyLong_AsUnsignedLong(value); memcpy(*retDataBuf, &d, sizeof(DWORD)); } break; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 17:30:59 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 17:30:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_3=2E2?= Message-ID: <3YXGkq0KsPzQy8@mail.python.org> http://hg.python.org/cpython/rev/94a76b49dc69 changeset: 81084:94a76b49dc69 branch: 3.3 parent: 81080:fa8c4f96d990 parent: 81083:b9752b6c40f8 user: Brian Curtin date: Thu Dec 27 10:14:30 2012 -0600 summary: Merge 3.2 files: Lib/test/test_winreg.py | 12 ++++++++++++ Misc/NEWS | 3 +++ PC/winreg.c | 2 +- 3 files changed, 16 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -323,6 +323,18 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_setvalueex_value_range(self): + # Test for Issue #14420, accept proper ranges for SetValueEx. + # Py2Reg, which gets called by SetValueEx, was using PyLong_AsLong, + # thus raising OverflowError. The implementation now uses + # PyLong_AsUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + SetValueEx(ck, "test_name", None, REG_DWORD, 0x80000000) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg + when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. + - Issue #16597: In buffered and text IO, call close() on the underlying stream if invoking flush() fails. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -785,7 +785,7 @@ memcpy(*retDataBuf, &zero, sizeof(DWORD)); } else { - DWORD d = PyLong_AsLong(value); + DWORD d = PyLong_AsUnsignedLong(value); memcpy(*retDataBuf, &d, sizeof(DWORD)); } break; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 17:31:00 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 17:31:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4z?= Message-ID: <3YXGkr2kbFzQy8@mail.python.org> http://hg.python.org/cpython/rev/8a70fe99151c changeset: 81085:8a70fe99151c parent: 81081:eae2a42603ee parent: 81084:94a76b49dc69 user: Brian Curtin date: Thu Dec 27 10:15:54 2012 -0600 summary: Merge 3.3 files: Lib/test/test_winreg.py | 12 ++++++++++++ Misc/NEWS | 3 +++ PC/winreg.c | 2 +- 3 files changed, 16 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -323,6 +323,18 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_setvalueex_value_range(self): + # Test for Issue #14420, accept proper ranges for SetValueEx. + # Py2Reg, which gets called by SetValueEx, was using PyLong_AsLong, + # thus raising OverflowError. The implementation now uses + # PyLong_AsUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + SetValueEx(ck, "test_name", None, REG_DWORD, 0x80000000) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg + when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. + - Issue #11939: Set the st_dev attribute of stat_result to allow Windows to take advantage of the os.path.samefile/sameopenfile/samestat implementations used by other platforms. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -785,7 +785,7 @@ memcpy(*retDataBuf, &zero, sizeof(DWORD)); } else { - DWORD d = PyLong_AsLong(value); + DWORD d = PyLong_AsUnsignedLong(value); memcpy(*retDataBuf, &d, sizeof(DWORD)); } break; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 19:29:20 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 19:29:20 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogRml4ICMxNDQyMC4g?= =?utf-8?q?Check_for_PyLong_as_well_as_PyInt_when_converting_in_Py2Reg=2E?= Message-ID: <3YXKMN71yNzNvK@mail.python.org> http://hg.python.org/cpython/rev/ccbb16719540 changeset: 81086:ccbb16719540 branch: 2.7 parent: 81082:44609ff7e53c user: Brian Curtin date: Thu Dec 27 12:28:51 2012 -0600 summary: Fix #14420. Check for PyLong as well as PyInt when converting in Py2Reg. This fixes a ValueError seen in winreg.SetValueEx when passed long winreg.REG_DWORD values that should be supported by the underlying API. files: Lib/test/test_winreg.py | 12 ++++++++++++ Misc/NEWS | 4 ++++ PC/_winreg.c | 11 ++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -314,6 +314,18 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_setvalueex_value_range(self): + # Test for Issue #14420, accept proper ranges for SetValueEx. + # Py2Reg, which gets called by SetValueEx, was using PyLong_AsLong, + # thus raising OverflowError. The implementation now uses + # PyLong_AsUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + SetValueEx(ck, "test_name", None, REG_DWORD, 0x80000000) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,10 @@ Core and Builtins ----------------- +- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg + when passed a REG_DWORD value. Fixes ValueError in winreg.SetValueEx when + given a long. + - Issue #13863: Work around buggy 'fstat' implementation on Windows / NTFS that lead to incorrect timestamps (off by one hour) being stored in .pyc files on some systems. diff --git a/PC/_winreg.c b/PC/_winreg.c --- a/PC/_winreg.c +++ b/PC/_winreg.c @@ -753,7 +753,8 @@ Py_ssize_t i,j; switch (typ) { case REG_DWORD: - if (value != Py_None && !PyInt_Check(value)) + if (value != Py_None && + !(PyInt_Check(value) || PyLong_Check(value))) return FALSE; *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1); if (*retDataBuf==NULL){ @@ -765,10 +766,10 @@ DWORD zero = 0; memcpy(*retDataBuf, &zero, sizeof(DWORD)); } - else - memcpy(*retDataBuf, - &PyInt_AS_LONG((PyIntObject *)value), - sizeof(DWORD)); + else { + DWORD d = PyLong_AsUnsignedLong(value); + memcpy(*retDataBuf, &d, sizeof(DWORD)); + } break; case REG_SZ: case REG_EXPAND_SZ: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 19:51:02 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 19:51:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2Njgy?= =?utf-8?q?=3A_Replace_=22Python_string=22_to_=22bytes_object=22_in_audioo?= =?utf-8?q?p?= Message-ID: <3YXKrQ2TGczR2j@mail.python.org> http://hg.python.org/cpython/rev/cd2b4074a2d9 changeset: 81087:cd2b4074a2d9 branch: 3.2 parent: 81083:b9752b6c40f8 user: Serhiy Storchaka date: Thu Dec 27 20:43:36 2012 +0200 summary: Issue #16682: Replace "Python string" to "bytes object" in audioop documentation. files: Doc/library/audioop.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/audioop.rst b/Doc/library/audioop.rst --- a/Doc/library/audioop.rst +++ b/Doc/library/audioop.rst @@ -7,7 +7,7 @@ The :mod:`audioop` module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed integer samples 8, 16 or 32 -bits wide, stored in Python strings. All scalar items are integers, unless +bits wide, stored in bytes objects. All scalar items are integers, unless specified otherwise. .. index:: @@ -126,7 +126,7 @@ .. function:: lin2alaw(fragment, width) Convert samples in the audio fragment to a-LAW encoding and return this as a - Python string. a-LAW is an audio encoding format whereby you get a dynamic + bytes object. a-LAW is an audio encoding format whereby you get a dynamic range of about 13 bits using only 8 bit samples. It is used by the Sun audio hardware, among others. @@ -151,7 +151,7 @@ .. function:: lin2ulaw(fragment, width) Convert samples in the audio fragment to u-LAW encoding and return this as a - Python string. u-LAW is an audio encoding format whereby you get a dynamic + bytes object. u-LAW is an audio encoding format whereby you get a dynamic range of about 14 bits using only 8 bit samples. It is used by the Sun audio hardware, among others. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 19:51:03 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 19:51:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316682=3A_Replace_=22Python_string=22_to_=22bytes_obje?= =?utf-8?q?ct=22_in_audioop?= Message-ID: <3YXKrR4sTNzRYd@mail.python.org> http://hg.python.org/cpython/rev/e8248e597060 changeset: 81088:e8248e597060 branch: 3.3 parent: 81084:94a76b49dc69 parent: 81087:cd2b4074a2d9 user: Serhiy Storchaka date: Thu Dec 27 20:46:19 2012 +0200 summary: Issue #16682: Replace "Python string" to "bytes object" in audioop documentation. files: Doc/library/audioop.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/audioop.rst b/Doc/library/audioop.rst --- a/Doc/library/audioop.rst +++ b/Doc/library/audioop.rst @@ -7,7 +7,7 @@ The :mod:`audioop` module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed integer samples 8, 16 or 32 -bits wide, stored in Python strings. All scalar items are integers, unless +bits wide, stored in bytes objects. All scalar items are integers, unless specified otherwise. .. index:: @@ -126,7 +126,7 @@ .. function:: lin2alaw(fragment, width) Convert samples in the audio fragment to a-LAW encoding and return this as a - Python string. a-LAW is an audio encoding format whereby you get a dynamic + bytes object. a-LAW is an audio encoding format whereby you get a dynamic range of about 13 bits using only 8 bit samples. It is used by the Sun audio hardware, among others. @@ -151,7 +151,7 @@ .. function:: lin2ulaw(fragment, width) Convert samples in the audio fragment to u-LAW encoding and return this as a - Python string. u-LAW is an audio encoding format whereby you get a dynamic + bytes object. u-LAW is an audio encoding format whereby you get a dynamic range of about 14 bits using only 8 bit samples. It is used by the Sun audio hardware, among others. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 19:51:05 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 19:51:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316682=3A_Replace_=22Python_string=22_to_=22byte?= =?utf-8?q?s_object=22_in_audioop?= Message-ID: <3YXKrT08dVzR0N@mail.python.org> http://hg.python.org/cpython/rev/f68aeab64356 changeset: 81089:f68aeab64356 parent: 81085:8a70fe99151c parent: 81088:e8248e597060 user: Serhiy Storchaka date: Thu Dec 27 20:47:30 2012 +0200 summary: Issue #16682: Replace "Python string" to "bytes object" in audioop documentation. files: Doc/library/audioop.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/audioop.rst b/Doc/library/audioop.rst --- a/Doc/library/audioop.rst +++ b/Doc/library/audioop.rst @@ -7,7 +7,7 @@ The :mod:`audioop` module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed integer samples 8, 16 or 32 -bits wide, stored in Python strings. All scalar items are integers, unless +bits wide, stored in bytes objects. All scalar items are integers, unless specified otherwise. .. index:: @@ -126,7 +126,7 @@ .. function:: lin2alaw(fragment, width) Convert samples in the audio fragment to a-LAW encoding and return this as a - Python string. a-LAW is an audio encoding format whereby you get a dynamic + bytes object. a-LAW is an audio encoding format whereby you get a dynamic range of about 13 bits using only 8 bit samples. It is used by the Sun audio hardware, among others. @@ -151,7 +151,7 @@ .. function:: lin2ulaw(fragment, width) Convert samples in the audio fragment to u-LAW encoding and return this as a - Python string. u-LAW is an audio encoding format whereby you get a dynamic + bytes object. u-LAW is an audio encoding format whereby you get a dynamic range of about 14 bits using only 8 bit samples. It is used by the Sun audio hardware, among others. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:05:12 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 21:05:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NTA0?= =?utf-8?q?=3A_Catch_SyntaxErrors_raised_by_tokenizer_in_IDLE=2E?= Message-ID: <3YXMV0483xzQpf@mail.python.org> http://hg.python.org/cpython/rev/d3c81ef728ae changeset: 81090:d3c81ef728ae branch: 2.7 parent: 81082:44609ff7e53c user: Serhiy Storchaka date: Thu Dec 27 21:34:23 2012 +0200 summary: Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. files: Lib/idlelib/EditorWindow.py | 2 +- Misc/NEWS | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1611,7 +1611,7 @@ try: try: _tokenize.tokenize(self.readline, self.tokeneater) - except _tokenize.TokenError: + except (_tokenize.TokenError, SyntaxError): # since we cut off the tokenizer early, we can trigger # spurious errors pass diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -164,6 +164,9 @@ Library ------- +- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by + Roger Serwy. + - Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for localhost tests. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:05:13 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 21:05:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NTA0?= =?utf-8?q?=3A_Catch_SyntaxErrors_raised_by_tokenizer_in_IDLE=2E?= Message-ID: <3YXMV16pjSzR0N@mail.python.org> http://hg.python.org/cpython/rev/e1ef04cfb57c changeset: 81091:e1ef04cfb57c branch: 3.2 parent: 81087:cd2b4074a2d9 user: Serhiy Storchaka date: Thu Dec 27 21:38:04 2012 +0200 summary: Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. Patch by Roger Serwy. files: Lib/idlelib/EditorWindow.py | 2 +- Misc/NEWS | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1618,7 +1618,7 @@ tokens = _tokenize.generate_tokens(self.readline) for token in tokens: self.tokeneater(*token) - except _tokenize.TokenError: + except (_tokenize.TokenError, SyntaxError): # since we cut off the tokenizer early, we can trigger # spurious errors pass diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -182,6 +182,9 @@ Library ------- +- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by + Roger Serwy. + - Issue #16618: Make glob.glob match consistently across strings and bytes regarding leading dots. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:05:15 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 21:05:15 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316504=3A_Catch_SyntaxErrors_raised_by_tokenizer_in_ID?= =?utf-8?b?TEUu?= Message-ID: <3YXMV32H1GzQyh@mail.python.org> http://hg.python.org/cpython/rev/f111e7078d54 changeset: 81092:f111e7078d54 branch: 3.3 parent: 81088:e8248e597060 parent: 81091:e1ef04cfb57c user: Serhiy Storchaka date: Thu Dec 27 21:53:06 2012 +0200 summary: Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. Patch by Roger Serwy. files: Lib/idlelib/EditorWindow.py | 2 +- Misc/NEWS | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1621,7 +1621,7 @@ tokens = _tokenize.generate_tokens(self.readline) for token in tokens: self.tokeneater(*token) - except _tokenize.TokenError: + except (_tokenize.TokenError, SyntaxError): # since we cut off the tokenizer early, we can trigger # spurious errors pass diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -117,6 +117,9 @@ Library ------- +- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by + Roger Serwy. + - Issue #16618: Make glob.glob match consistently across strings and bytes regarding leading dots. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:05:16 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 21:05:16 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316504=3A_Catch_SyntaxErrors_raised_by_tokenizer?= =?utf-8?q?_in_IDLE=2E?= Message-ID: <3YXMV44p8lzNnR@mail.python.org> http://hg.python.org/cpython/rev/69a2f6a7c257 changeset: 81093:69a2f6a7c257 parent: 81089:f68aeab64356 parent: 81092:f111e7078d54 user: Serhiy Storchaka date: Thu Dec 27 21:54:19 2012 +0200 summary: Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. Patch by Roger Serwy. files: Lib/idlelib/EditorWindow.py | 2 +- Misc/NEWS | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1621,7 +1621,7 @@ tokens = _tokenize.generate_tokens(self.readline) for token in tokens: self.tokeneater(*token) - except _tokenize.TokenError: + except (_tokenize.TokenError, SyntaxError): # since we cut off the tokenizer early, we can trigger # spurious errors pass diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -193,6 +193,9 @@ Library ------- +- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by + Roger Serwy. + - Issue #16618: Make glob.glob match consistently across strings and bytes regarding leading dots. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:05:18 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 21:05:18 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMi43IC0+IDIuNyk6?= =?utf-8?q?_Null_merge=2E?= Message-ID: <3YXMV60LQSzRYd@mail.python.org> http://hg.python.org/cpython/rev/26eb2979465c changeset: 81094:26eb2979465c branch: 2.7 parent: 81086:ccbb16719540 parent: 81090:d3c81ef728ae user: Serhiy Storchaka date: Thu Dec 27 22:00:12 2012 +0200 summary: Null merge. files: Lib/idlelib/EditorWindow.py | 2 +- Misc/NEWS | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -1611,7 +1611,7 @@ try: try: _tokenize.tokenize(self.readline, self.tokeneater) - except _tokenize.TokenError: + except (_tokenize.TokenError, SyntaxError): # since we cut off the tokenizer early, we can trigger # spurious errors pass diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -168,6 +168,9 @@ Library ------- +- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by + Roger Serwy. + - Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for localhost tests. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:14:58 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 21:14:58 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4ICMxNjc1OS4g?= =?utf-8?q?Convert_DWORD_registry_values_using_PyLong=5FFromUnsignedLong?= =?utf-8?q?=2E?= Message-ID: <3YXMjG5fXlzQxc@mail.python.org> http://hg.python.org/cpython/rev/4b7e60e05027 changeset: 81095:4b7e60e05027 branch: 3.2 parent: 81083:b9752b6c40f8 user: Brian Curtin date: Thu Dec 27 14:04:42 2012 -0600 summary: Fix #16759. Convert DWORD registry values using PyLong_FromUnsignedLong. When converting REG_DWORD registry values into Python ints, the conversion needs to be made from an *unsigned* long to match the DWORD type. files: Lib/test/test_winreg.py | 17 +++++++++++++++++ Misc/NEWS | 4 ++++ PC/winreg.c | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -335,6 +335,23 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_queryvalueex_return_value(self): + # Test for Issue #16759, return unsigned int from QueryValueEx. + # Reg2Py, which gets called by QueryValueEx, was returning a value + # generated by PyLong_FromLong. The implmentation now uses + # PyLong_FromUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + test_val = 0x80000000 + SetValueEx(ck, "test_name", None, REG_DWORD, test_val) + ret_val, ret_type = QueryValueEx(ck, "test_name") + self.assertEqual(ret_type, REG_DWORD) + self.assertEqual(ret_val, test_val) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py + when retreiving a REG_DWORD value. This corrects functions like + winreg.QueryValueEx that may have been returning truncated values. + - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -900,9 +900,9 @@ switch (typ) { case REG_DWORD: if (retDataSize == 0) - obData = PyLong_FromLong(0); + obData = PyLong_FromUnsignedLong(0); else - obData = PyLong_FromLong(*(int *)retDataBuf); + obData = PyLong_FromUnsignedLong(*(int *)retDataBuf); break; case REG_SZ: case REG_EXPAND_SZ: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:15:00 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 21:15:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_3=2E2?= Message-ID: <3YXMjJ0xmdzNy3@mail.python.org> http://hg.python.org/cpython/rev/a29b48a39e4f changeset: 81096:a29b48a39e4f branch: 3.3 parent: 81084:94a76b49dc69 parent: 81095:4b7e60e05027 user: Brian Curtin date: Thu Dec 27 14:06:06 2012 -0600 summary: Merge 3.2 files: Lib/test/test_winreg.py | 17 +++++++++++++++++ Misc/NEWS | 4 ++++ PC/winreg.c | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -335,6 +335,23 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_queryvalueex_return_value(self): + # Test for Issue #16759, return unsigned int from QueryValueEx. + # Reg2Py, which gets called by QueryValueEx, was returning a value + # generated by PyLong_FromLong. The implmentation now uses + # PyLong_FromUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + test_val = 0x80000000 + SetValueEx(ck, "test_name", None, REG_DWORD, test_val) + ret_val, ret_type = QueryValueEx(ck, "test_name") + self.assertEqual(ret_type, REG_DWORD) + self.assertEqual(ret_val, test_val) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,10 @@ Core and Builtins ----------------- +- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py + when retreiving a REG_DWORD value. This corrects functions like + winreg.QueryValueEx that may have been returning truncated values. + - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -912,9 +912,9 @@ switch (typ) { case REG_DWORD: if (retDataSize == 0) - obData = PyLong_FromLong(0); + obData = PyLong_FromUnsignedLong(0); else - obData = PyLong_FromLong(*(int *)retDataBuf); + obData = PyLong_FromUnsignedLong(*(int *)retDataBuf); break; case REG_SZ: case REG_EXPAND_SZ: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:15:01 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 21:15:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4z?= Message-ID: <3YXMjK3LtWzQxc@mail.python.org> http://hg.python.org/cpython/rev/dd2ca492d263 changeset: 81097:dd2ca492d263 parent: 81085:8a70fe99151c parent: 81096:a29b48a39e4f user: Brian Curtin date: Thu Dec 27 14:06:38 2012 -0600 summary: Merge 3.3 files: Lib/test/test_winreg.py | 17 +++++++++++++++++ Misc/NEWS | 4 ++++ PC/winreg.c | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -335,6 +335,23 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_queryvalueex_return_value(self): + # Test for Issue #16759, return unsigned int from QueryValueEx. + # Reg2Py, which gets called by QueryValueEx, was returning a value + # generated by PyLong_FromLong. The implmentation now uses + # PyLong_FromUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + test_val = 0x80000000 + SetValueEx(ck, "test_name", None, REG_DWORD, test_val) + ret_val, ret_type = QueryValueEx(ck, "test_name") + self.assertEqual(ret_type, REG_DWORD) + self.assertEqual(ret_val, test_val) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py + when retreiving a REG_DWORD value. This corrects functions like + winreg.QueryValueEx that may have been returning truncated values. + - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -912,9 +912,9 @@ switch (typ) { case REG_DWORD: if (retDataSize == 0) - obData = PyLong_FromLong(0); + obData = PyLong_FromUnsignedLong(0); else - obData = PyLong_FromLong(*(int *)retDataBuf); + obData = PyLong_FromUnsignedLong(*(int *)retDataBuf); break; case REG_SZ: case REG_EXPAND_SZ: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:15:02 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 21:15:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge?= Message-ID: <3YXMjL5qpPzNyK@mail.python.org> http://hg.python.org/cpython/rev/0f7ddd93aac7 changeset: 81098:0f7ddd93aac7 parent: 81093:69a2f6a7c257 parent: 81097:dd2ca492d263 user: Brian Curtin date: Thu Dec 27 14:11:38 2012 -0600 summary: merge files: Lib/test/test_winreg.py | 17 +++++++++++++++++ Misc/NEWS | 4 ++++ PC/winreg.c | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -335,6 +335,23 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_queryvalueex_return_value(self): + # Test for Issue #16759, return unsigned int from QueryValueEx. + # Reg2Py, which gets called by QueryValueEx, was returning a value + # generated by PyLong_FromLong. The implmentation now uses + # PyLong_FromUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + test_val = 0x80000000 + SetValueEx(ck, "test_name", None, REG_DWORD, test_val) + ret_val, ret_type = QueryValueEx(ck, "test_name") + self.assertEqual(ret_type, REG_DWORD) + self.assertEqual(ret_val, test_val) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py + when retreiving a REG_DWORD value. This corrects functions like + winreg.QueryValueEx that may have been returning truncated values. + - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -912,9 +912,9 @@ switch (typ) { case REG_DWORD: if (retDataSize == 0) - obData = PyLong_FromLong(0); + obData = PyLong_FromUnsignedLong(0); else - obData = PyLong_FromLong(*(int *)retDataBuf); + obData = PyLong_FromUnsignedLong(*(int *)retDataBuf); break; case REG_SZ: case REG_EXPAND_SZ: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:15:04 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 21:15:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMik6?= =?utf-8?q?_Merge?= Message-ID: <3YXMjN1456zQyh@mail.python.org> http://hg.python.org/cpython/rev/f72cc501cb49 changeset: 81099:f72cc501cb49 branch: 3.2 parent: 81091:e1ef04cfb57c parent: 81095:4b7e60e05027 user: Brian Curtin date: Thu Dec 27 14:12:43 2012 -0600 summary: Merge files: Lib/test/test_winreg.py | 17 +++++++++++++++++ Misc/NEWS | 4 ++++ PC/winreg.c | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -335,6 +335,23 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_queryvalueex_return_value(self): + # Test for Issue #16759, return unsigned int from QueryValueEx. + # Reg2Py, which gets called by QueryValueEx, was returning a value + # generated by PyLong_FromLong. The implmentation now uses + # PyLong_FromUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + test_val = 0x80000000 + SetValueEx(ck, "test_name", None, REG_DWORD, test_val) + ret_val, ret_type = QueryValueEx(ck, "test_name") + self.assertEqual(ret_type, REG_DWORD) + self.assertEqual(ret_val, test_val) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py + when retreiving a REG_DWORD value. This corrects functions like + winreg.QueryValueEx that may have been returning truncated values. + - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -900,9 +900,9 @@ switch (typ) { case REG_DWORD: if (retDataSize == 0) - obData = PyLong_FromLong(0); + obData = PyLong_FromUnsignedLong(0); else - obData = PyLong_FromLong(*(int *)retDataBuf); + obData = PyLong_FromUnsignedLong(*(int *)retDataBuf); break; case REG_SZ: case REG_EXPAND_SZ: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:15:05 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 21:15:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4zIC0+IDMuMyk6?= =?utf-8?q?_another_merge?= Message-ID: <3YXMjP3bc6zR5S@mail.python.org> http://hg.python.org/cpython/rev/5b7f25bd2080 changeset: 81100:5b7f25bd2080 branch: 3.3 parent: 81092:f111e7078d54 parent: 81096:a29b48a39e4f user: Brian Curtin date: Thu Dec 27 14:14:42 2012 -0600 summary: another merge files: Lib/test/test_winreg.py | 17 +++++++++++++++++ Misc/NEWS | 4 ++++ PC/winreg.c | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -335,6 +335,23 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_queryvalueex_return_value(self): + # Test for Issue #16759, return unsigned int from QueryValueEx. + # Reg2Py, which gets called by QueryValueEx, was returning a value + # generated by PyLong_FromLong. The implmentation now uses + # PyLong_FromUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + test_val = 0x80000000 + SetValueEx(ck, "test_name", None, REG_DWORD, test_val) + ret_val, ret_type = QueryValueEx(ck, "test_name") + self.assertEqual(ret_type, REG_DWORD) + self.assertEqual(ret_val, test_val) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,10 @@ Core and Builtins ----------------- +- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py + when retreiving a REG_DWORD value. This corrects functions like + winreg.QueryValueEx that may have been returning truncated values. + - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. diff --git a/PC/winreg.c b/PC/winreg.c --- a/PC/winreg.c +++ b/PC/winreg.c @@ -912,9 +912,9 @@ switch (typ) { case REG_DWORD: if (retDataSize == 0) - obData = PyLong_FromLong(0); + obData = PyLong_FromUnsignedLong(0); else - obData = PyLong_FromLong(*(int *)retDataBuf); + obData = PyLong_FromUnsignedLong(*(int *)retDataBuf); break; case REG_SZ: case REG_EXPAND_SZ: -- Repository URL: http://hg.python.org/cpython From chris.jerdonek at gmail.com Thu Dec 27 21:26:13 2012 From: chris.jerdonek at gmail.com (Chris Jerdonek) Date: Thu, 27 Dec 2012 12:26:13 -0800 Subject: [Python-checkins] cpython (merge 2.7 -> 2.7): Null merge. In-Reply-To: <3YXMV60LQSzRYd@mail.python.org> References: <3YXMV60LQSzRYd@mail.python.org> Message-ID: On Thu, Dec 27, 2012 at 12:05 PM, serhiy.storchaka wrote: > http://hg.python.org/cpython/rev/26eb2979465c > changeset: 81094:26eb2979465c > branch: 2.7 > parent: 81086:ccbb16719540 > parent: 81090:d3c81ef728ae > user: Serhiy Storchaka > date: Thu Dec 27 22:00:12 2012 +0200 > summary: > Null merge. Great to see your first check-ins, Serhiy. Congratulations! I think for this case we usually say "Merge heads," which is different from the case of a null merge (i.e. where the diff is empty, for example when registering that a 3.x commit should not be forward-ported to a later version). --Chris > > files: > Lib/idlelib/EditorWindow.py | 2 +- > Misc/NEWS | 3 +++ > 2 files changed, 4 insertions(+), 1 deletions(-) > > > diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py > --- a/Lib/idlelib/EditorWindow.py > +++ b/Lib/idlelib/EditorWindow.py > @@ -1611,7 +1611,7 @@ > try: > try: > _tokenize.tokenize(self.readline, self.tokeneater) > - except _tokenize.TokenError: > + except (_tokenize.TokenError, SyntaxError): > # since we cut off the tokenizer early, we can trigger > # spurious errors > pass > diff --git a/Misc/NEWS b/Misc/NEWS > --- a/Misc/NEWS > +++ b/Misc/NEWS > @@ -168,6 +168,9 @@ > Library > ------- > > +- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by > + Roger Serwy. > + > - Issue #16702: test_urllib2_localnet tests now correctly ignores proxies for > localhost tests. > > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > From python-checkins at python.org Thu Dec 27 21:37:46 2012 From: python-checkins at python.org (brian.curtin) Date: Thu, 27 Dec 2012 21:37:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogRml4ICMxNjc1OS4g?= =?utf-8?q?Convert_DWORD_registry_values_using_unsigned_long=2E?= Message-ID: <3YXNCZ6C0zzQpV@mail.python.org> http://hg.python.org/cpython/rev/d68563e7ae82 changeset: 81101:d68563e7ae82 branch: 2.7 parent: 81094:26eb2979465c user: Brian Curtin date: Thu Dec 27 14:37:06 2012 -0600 summary: Fix #16759. Convert DWORD registry values using unsigned long. When converting REG_DWORD registry values into Python, the conversion needs to be made from an *unsigned* long (k instead of i) to match the DWORD type. files: Lib/test/test_winreg.py | 17 +++++++++++++++++ Misc/NEWS | 4 ++++ PC/_winreg.c | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -326,6 +326,23 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_queryvalueex_return_value(self): + # Test for Issue #16759, return unsigned int from QueryValueEx. + # Reg2Py, which gets called by QueryValueEx, was returning a value + # generated by PyLong_FromLong. The implmentation now uses + # PyLong_FromUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + test_val = 0x80000000 + SetValueEx(ck, "test_name", None, REG_DWORD, test_val) + ret_val, ret_type = QueryValueEx(ck, "test_name") + self.assertEqual(ret_type, REG_DWORD) + self.assertEqual(ret_val, test_val) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,10 @@ Core and Builtins ----------------- +- Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py + when retreiving a REG_DWORD value. This corrects functions like + winreg.QueryValueEx that may have been returning truncated values. + - Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg when passed a REG_DWORD value. Fixes ValueError in winreg.SetValueEx when given a long. diff --git a/PC/_winreg.c b/PC/_winreg.c --- a/PC/_winreg.c +++ b/PC/_winreg.c @@ -918,9 +918,9 @@ switch (typ) { case REG_DWORD: if (retDataSize == 0) - obData = Py_BuildValue("i", 0); + obData = Py_BuildValue("k", 0); else - obData = Py_BuildValue("i", + obData = Py_BuildValue("k", *(int *)retDataBuf); break; case REG_SZ: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 21:54:40 2012 From: python-checkins at python.org (chris.jerdonek) Date: Thu, 27 Dec 2012 21:54:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2Nzkw?= =?utf-8?q?=3A_add_some_of_the_recent_issue_=2316045_int_tests_to_test=5Fl?= =?utf-8?q?ong=2E?= Message-ID: <3YXNb41Hw0zNwL@mail.python.org> http://hg.python.org/cpython/rev/eb1734e579f7 changeset: 81102:eb1734e579f7 branch: 2.7 user: Chris Jerdonek date: Thu Dec 27 12:53:29 2012 -0800 summary: Issue #16790: add some of the recent issue #16045 int tests to test_long. This patch also provides a simple way to share tests going forward between test_int and test_long. files: Lib/test/test_int.py | 29 +++++++++++++++++++---------- Lib/test/test_long.py | 6 ++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -45,7 +45,25 @@ (unichr(0x200), ValueError), ] -class IntTestCases(unittest.TestCase): +class IntLongCommonTests(object): + + """Mixin of test cases to share between both test_int and test_long.""" + + # Change to int or long in the TestCase subclass. + ntype = None + + def test_no_args(self): + self.assertEqual(self.ntype(), 0) + + def test_keyword_args(self): + # Test invoking constructor using keyword arguments. + self.assertEqual(self.ntype(x=1.2), 1) + self.assertEqual(self.ntype('100', base=2), 4) + self.assertEqual(self.ntype(x='100', base=2), 4) + +class IntTestCases(IntLongCommonTests, unittest.TestCase): + + ntype = int def test_basic(self): self.assertEqual(int(314), 314) @@ -316,15 +334,6 @@ self.assertEqual(int(float(2**54+10)), 2**54+8) self.assertEqual(int(float(2**54+11)), 2**54+12) - def test_no_args(self): - self.assertEquals(int(), 0) - - def test_keyword_args(self): - # Test invoking int() using keyword arguments. - self.assertEquals(int(x=1.2), 1) - self.assertEquals(int('100', base=2), 4) - self.assertEquals(int(x='100', base=2), 4) - def test_valid_non_numeric_input_types_for_x(self): # Test possible valid non-numeric types for x, including subclasses # of the allowed built-in types. diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -1,10 +1,11 @@ import unittest -from test import test_support import sys import random import math +from test import test_int, test_support + # Used for lazy formatting of failure messages class Frm(object): def __init__(self, format, *args): @@ -78,8 +79,9 @@ (unichr(0x200), ValueError), ] +class LongTest(test_int.IntLongCommonTests, unittest.TestCase): -class LongTest(unittest.TestCase): + ntype = long # Get quasi-random long consisting of ndigits digits (in base BASE). # quasi == the most-significant digit will not be 0, and the number -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 22:53:12 2012 From: python-checkins at python.org (ezio.melotti) Date: Thu, 27 Dec 2012 22:53:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Null_merge_with_3=2E2=2E?= Message-ID: <3YXPtc0BkJzM2t@mail.python.org> http://hg.python.org/cpython/rev/f98ab0d3a591 changeset: 81103:f98ab0d3a591 branch: 3.3 parent: 81100:5b7f25bd2080 parent: 81099:f72cc501cb49 user: Ezio Melotti date: Thu Dec 27 23:52:36 2012 +0200 summary: Null merge with 3.2. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 22:53:13 2012 From: python-checkins at python.org (ezio.melotti) Date: Thu, 27 Dec 2012 22:53:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Null_merge_with_3=2E3=2E?= Message-ID: <3YXPtd2X01zQrt@mail.python.org> http://hg.python.org/cpython/rev/30017af40204 changeset: 81104:30017af40204 parent: 81098:0f7ddd93aac7 parent: 81103:f98ab0d3a591 user: Ezio Melotti date: Thu Dec 27 23:52:57 2012 +0200 summary: Null merge with 3.3. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:22:46 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:22:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2Nzky?= =?utf-8?q?=3A_Mark_small_ints_test_as_CPython-only=2E?= Message-ID: <3YXQXk2TcpzNwL@mail.python.org> http://hg.python.org/cpython/rev/8f82e9992ad9 changeset: 81105:8f82e9992ad9 branch: 2.7 parent: 81102:eb1734e579f7 user: Serhiy Storchaka date: Thu Dec 27 23:07:00 2012 +0200 summary: Issue #16792: Mark small ints test as CPython-only. files: Lib/test/test_int.py | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -378,6 +378,14 @@ self.assertEquals(int(base=1), 0) self.assertEquals(int(base=1000), 0) + @test_support.cpython_only + def test_small_ints(self): + self.assertTrue(int('10') is 10) + self.assertTrue(int('-1') is -1) + if have_unicode: + self.assertTrue(int(u'10') is 10) + self.assertTrue(int(u'-1') is -1) + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:22:47 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:22:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2Nzky?= =?utf-8?q?=3A_Mark_small_ints_test_as_CPython-only=2E?= Message-ID: <3YXQXl4mfXzNwL@mail.python.org> http://hg.python.org/cpython/rev/31955234b624 changeset: 81106:31955234b624 branch: 3.2 parent: 81099:f72cc501cb49 user: Serhiy Storchaka date: Thu Dec 27 23:57:00 2012 +0200 summary: Issue #16792: Mark small ints test as CPython-only. files: Lib/test/test_int.py | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -1,6 +1,7 @@ import sys import unittest +from test import support from test.support import run_unittest L = [ @@ -100,10 +101,6 @@ self.assertRaises(ValueError, int, "0b", 2) self.assertRaises(ValueError, int, "0b", 0) - # Bug #3236: Return small longs from PyLong_FromString - self.assertTrue(int("10") is 10) - self.assertTrue(int("-1") is -1) - # SF bug 1334662: int(string, base) wrong answers # Various representations of 2**32 evaluated to 0 # rather than 2**32 in previous versions @@ -221,6 +218,14 @@ self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) + @support.cpython_only + def test_small_ints(self): + # Bug #3236: Return small longs from PyLong_FromString + self.assertIs(int('10'), 10) + self.assertIs(int('-1'), -1) + self.assertIs(int(b'10'), 10) + self.assertIs(int(b'-1'), -1) + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:22:49 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:22:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316792=3A_Mark_small_ints_test_as_CPython-only=2E?= Message-ID: <3YXQXn01vTzQkt@mail.python.org> http://hg.python.org/cpython/rev/dee82e66726d changeset: 81107:dee82e66726d branch: 3.3 parent: 81103:f98ab0d3a591 parent: 81106:31955234b624 user: Serhiy Storchaka date: Fri Dec 28 00:16:53 2012 +0200 summary: Issue #16792: Mark small ints test as CPython-only. files: Lib/test/test_int.py | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -100,10 +100,6 @@ self.assertRaises(ValueError, int, "0b", 2) self.assertRaises(ValueError, int, "0b", 0) - # Bug #3236: Return small longs from PyLong_FromString - self.assertTrue(int("10") is 10) - self.assertTrue(int("-1") is -1) - # SF bug 1334662: int(string, base) wrong answers # Various representations of 2**32 evaluated to 0 # rather than 2**32 in previous versions @@ -221,6 +217,14 @@ self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) + @support.cpython_only + def test_small_ints(self): + # Bug #3236: Return small longs from PyLong_FromString + self.assertIs(int('10'), 10) + self.assertIs(int('-1'), -1) + self.assertIs(int(b'10'), 10) + self.assertIs(int(b'-1'), -1) + def test_no_args(self): self.assertEquals(int(), 0) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:22:50 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:22:50 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316792=3A_Mark_small_ints_test_as_CPython-only?= =?utf-8?q?=2E?= Message-ID: <3YXQXp2KHBzQvn@mail.python.org> http://hg.python.org/cpython/rev/9177d8e6e317 changeset: 81108:9177d8e6e317 parent: 81104:30017af40204 parent: 81107:dee82e66726d user: Serhiy Storchaka date: Fri Dec 28 00:17:38 2012 +0200 summary: Issue #16792: Mark small ints test as CPython-only. files: Lib/test/test_int.py | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -100,10 +100,6 @@ self.assertRaises(ValueError, int, "0b", 2) self.assertRaises(ValueError, int, "0b", 0) - # Bug #3236: Return small longs from PyLong_FromString - self.assertTrue(int("10") is 10) - self.assertTrue(int("-1") is -1) - # SF bug 1334662: int(string, base) wrong answers # Various representations of 2**32 evaluated to 0 # rather than 2**32 in previous versions @@ -221,6 +217,14 @@ self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) + @support.cpython_only + def test_small_ints(self): + # Bug #3236: Return small longs from PyLong_FromString + self.assertIs(int('10'), 10) + self.assertIs(int('-1'), -1) + self.assertIs(int(b'10'), 10) + self.assertIs(int(b'-1'), -1) + def test_no_args(self): self.assertEquals(int(), 0) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:47:03 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:47:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2Nzkz?= =?utf-8?q?=2E_Replace_deprecated_unittest_asserts_with_modern_counterpart?= =?utf-8?q?s=2E?= Message-ID: <3YXR4l3jf8zQjJ@mail.python.org> http://hg.python.org/cpython/rev/a617a50d2766 changeset: 81109:a617a50d2766 branch: 2.7 parent: 81105:8f82e9992ad9 user: Serhiy Storchaka date: Fri Dec 28 00:32:19 2012 +0200 summary: Issue #16793. Replace deprecated unittest asserts with modern counterparts. files: Lib/ctypes/test/test_bitfields.py | 8 ++++---- Lib/test/test_calendar.py | 2 +- Lib/test/test_int.py | 10 +++++----- Lib/test/test_mutex.py | 2 +- Lib/test/test_tarfile.py | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/ctypes/test/test_bitfields.py b/Lib/ctypes/test/test_bitfields.py --- a/Lib/ctypes/test/test_bitfields.py +++ b/Lib/ctypes/test/test_bitfields.py @@ -246,9 +246,9 @@ _fields_ = [("a", c_uint32, 32)] x = X() x.a = 10 - self.assertEquals(x.a, 10) + self.assertEqual(x.a, 10) x.a = 0xFDCBA987 - self.assertEquals(x.a, 0xFDCBA987) + self.assertEqual(x.a, 0xFDCBA987) @unittest.skipUnless(hasattr(ctypes, "c_uint64"), "c_int64 is required") def test_uint64(self): @@ -256,9 +256,9 @@ _fields_ = [("a", c_uint64, 64)] x = X() x.a = 10 - self.assertEquals(x.a, 10) + self.assertEqual(x.a, 10) x.a = 0xFEDCBA9876543211 - self.assertEquals(x.a, 0xFEDCBA9876543211) + self.assertEqual(x.a, 0xFEDCBA9876543211) if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -261,7 +261,7 @@ return calendar.LocaleHTMLCalendar(locale='').formatmonthname(2010, 10) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) - self.assertEquals(old_october, new_october) + self.assertEqual(old_october, new_october) def test_itermonthdates(self): # ensure itermonthdates doesn't overflow after datetime.MAXYEAR diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -347,8 +347,8 @@ for x in values: msg = 'x has value %s and type %s' % (x, type(x).__name__) try: - self.assertEquals(int(x), 100, msg=msg) - self.assertEquals(int(x, 2), 4, msg=msg) + self.assertEqual(int(x), 100, msg=msg) + self.assertEqual(int(x, 2), 4, msg=msg) except TypeError, err: raise AssertionError('For %s got TypeError: %s' % (type(x).__name__, err)) @@ -373,10 +373,10 @@ # expects x to be a string if base is given. @test_support.cpython_only def test_int_base_without_x_returns_0(self): - self.assertEquals(int(base=6), 0) + self.assertEqual(int(base=6), 0) # Even invalid bases don't raise an exception. - self.assertEquals(int(base=1), 0) - self.assertEquals(int(base=1000), 0) + self.assertEqual(int(base=1), 0) + self.assertEqual(int(base=1000), 0) @test_support.cpython_only def test_small_ints(self): diff --git a/Lib/test/test_mutex.py b/Lib/test/test_mutex.py --- a/Lib/test/test_mutex.py +++ b/Lib/test/test_mutex.py @@ -14,7 +14,7 @@ m.lock(called_by_mutex2, "eggs") def called_by_mutex2(some_data): - self.assertEquals(some_data, "eggs") + self.assertEqual(some_data, "eggs") self.assertTrue(m.test(), "mutex not held") self.assertTrue(ready_for_2, "called_by_mutex2 called too soon") 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 @@ -858,7 +858,7 @@ tar = tarfile.open(tmpname, "r") for t in tar: - self.assert_(t.name == "." or t.name.startswith("./")) + self.assertTrue(t.name == "." or t.name.startswith("./")) tar.close() finally: os.chdir(cwd) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:47:04 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:47:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2Nzkz?= =?utf-8?q?=2E_Replace_deprecated_unittest_asserts_with_modern_counterpart?= =?utf-8?q?s=2E?= Message-ID: <3YXR4m62cSzQjJ@mail.python.org> http://hg.python.org/cpython/rev/6601818622ea changeset: 81110:6601818622ea branch: 3.3 parent: 81107:dee82e66726d user: Serhiy Storchaka date: Fri Dec 28 00:34:57 2012 +0200 summary: Issue #16793. Replace deprecated unittest asserts with modern counterparts. files: Lib/test/test_importlib/import_/test_fromlist.py | 2 +- Lib/test/test_int.py | 20 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Lib/test/test_importlib/import_/test_fromlist.py b/Lib/test/test_importlib/import_/test_fromlist.py --- a/Lib/test/test_importlib/import_/test_fromlist.py +++ b/Lib/test/test_importlib/import_/test_fromlist.py @@ -80,7 +80,7 @@ with util.import_state(meta_path=[importer]): with self.assertRaises(ImportError) as exc: import_util.import_('pkg', fromlist=['mod']) - self.assertEquals('i_do_not_exist', exc.exception.name) + self.assertEqual('i_do_not_exist', exc.exception.name) def test_empty_string(self): with util.mock_modules('pkg.__init__', 'pkg.mod') as importer: diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -226,23 +226,23 @@ self.assertIs(int(b'-1'), -1) def test_no_args(self): - self.assertEquals(int(), 0) + self.assertEqual(int(), 0) def test_keyword_args(self): # Test invoking int() using keyword arguments. - self.assertEquals(int(x=1.2), 1) - self.assertEquals(int('100', base=2), 4) - self.assertEquals(int(x='100', base=2), 4) + self.assertEqual(int(x=1.2), 1) + self.assertEqual(int('100', base=2), 4) + self.assertEqual(int(x='100', base=2), 4) # For example, PyPy 1.9.0 raised TypeError for these cases because it # expects x to be a string if base is given. @support.cpython_only def test_base_arg_with_no_x_arg(self): - self.assertEquals(int(base=6), 0) + self.assertEqual(int(base=6), 0) # Even invalid bases don't raise an exception. - self.assertEquals(int(base=1), 0) - self.assertEquals(int(base=1000), 0) - self.assertEquals(int(base='foo'), 0) + self.assertEqual(int(base=1), 0) + self.assertEqual(int(base=1000), 0) + self.assertEqual(int(base='foo'), 0) def test_non_numeric_input_types(self): # Test possible non-numeric types for the argument x, including @@ -259,8 +259,8 @@ for x in values: msg = 'x has type %s' % type(x).__name__ - self.assertEquals(int(x), 100, msg=msg) - self.assertEquals(int(x, 2), 4, msg=msg) + self.assertEqual(int(x), 100, msg=msg) + self.assertEqual(int(x, 2), 4, msg=msg) def test_string_float(self): self.assertRaises(ValueError, int, '1.2') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:47:06 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:47:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316793=2E_Replace_deprecated_unittest_asserts_wi?= =?utf-8?q?th_modern_counterparts=2E?= Message-ID: <3YXR4p1V4zzR3c@mail.python.org> http://hg.python.org/cpython/rev/eb3a4ae095a8 changeset: 81111:eb3a4ae095a8 parent: 81108:9177d8e6e317 parent: 81110:6601818622ea user: Serhiy Storchaka date: Fri Dec 28 00:36:34 2012 +0200 summary: Issue #16793. Replace deprecated unittest asserts with modern counterparts. files: Lib/test/test_int.py | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -226,23 +226,23 @@ self.assertIs(int(b'-1'), -1) def test_no_args(self): - self.assertEquals(int(), 0) + self.assertEqual(int(), 0) def test_keyword_args(self): # Test invoking int() using keyword arguments. - self.assertEquals(int(x=1.2), 1) - self.assertEquals(int('100', base=2), 4) - self.assertEquals(int(x='100', base=2), 4) + self.assertEqual(int(x=1.2), 1) + self.assertEqual(int('100', base=2), 4) + self.assertEqual(int(x='100', base=2), 4) # For example, PyPy 1.9.0 raised TypeError for these cases because it # expects x to be a string if base is given. @support.cpython_only def test_base_arg_with_no_x_arg(self): - self.assertEquals(int(base=6), 0) + self.assertEqual(int(base=6), 0) # Even invalid bases don't raise an exception. - self.assertEquals(int(base=1), 0) - self.assertEquals(int(base=1000), 0) - self.assertEquals(int(base='foo'), 0) + self.assertEqual(int(base=1), 0) + self.assertEqual(int(base=1000), 0) + self.assertEqual(int(base='foo'), 0) def test_int_base_limits(self): """Testing the supported limits of the int() base parameter.""" @@ -283,8 +283,8 @@ for x in values: msg = 'x has type %s' % type(x).__name__ - self.assertEquals(int(x), 100, msg=msg) - self.assertEquals(int(x, 2), 4, msg=msg) + self.assertEqual(int(x), 100, msg=msg) + self.assertEqual(int(x, 2), 4, msg=msg) def test_string_float(self): self.assertRaises(ValueError, int, '1.2') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Dec 27 23:47:07 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Thu, 27 Dec 2012 23:47:07 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2Nzky?= =?utf-8?q?=3A_Use_assertIs=28=29_to_test_identity=2E?= Message-ID: <3YXR4q3hBfzRWp@mail.python.org> http://hg.python.org/cpython/rev/327896bf3152 changeset: 81112:327896bf3152 branch: 2.7 parent: 81109:a617a50d2766 user: Serhiy Storchaka date: Fri Dec 28 00:44:20 2012 +0200 summary: Issue #16792: Use assertIs() to test identity. files: Lib/test/test_int.py | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -380,11 +380,11 @@ @test_support.cpython_only def test_small_ints(self): - self.assertTrue(int('10') is 10) - self.assertTrue(int('-1') is -1) + self.assertIs(int('10'), 10) + self.assertIs(int('-1'), -1) if have_unicode: - self.assertTrue(int(u'10') is 10) - self.assertTrue(int(u'-1') is -1) + self.assertIs(int(u'10'), 10) + self.assertIs(int(u'-1'), -1) def test_intconversion(self): # Test __int__() -- Repository URL: http://hg.python.org/cpython From storchaka at gmail.com Fri Dec 28 00:02:53 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 28 Dec 2012 01:02:53 +0200 Subject: [Python-checkins] cpython (merge 2.7 -> 2.7): Null merge. In-Reply-To: References: <3YXMV60LQSzRYd@mail.python.org> Message-ID: On 27.12.12 22:26, Chris Jerdonek wrote: > Great to see your first check-ins, Serhiy. Congratulations! > > I think for this case we usually say "Merge heads," which is different > from the case of a null merge (i.e. where the diff is empty, for > example when registering that a 3.x commit should not be > forward-ported to a later version). Sorry. Ezio have explained me difference between "Merge heads" and "Null merge". From python-checkins at python.org Fri Dec 28 01:00:55 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 28 Dec 2012 01:00:55 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE2Nzk2OiBmaXgg?= =?utf-8?q?typo=2E__Patch_by_Michael_Schurter=2E?= Message-ID: <3YXSjz1V88zNvj@mail.python.org> http://hg.python.org/cpython/rev/c1623a032adf changeset: 81113:c1623a032adf branch: 2.7 user: Ezio Melotti date: Fri Dec 28 01:59:24 2012 +0200 summary: #16796: fix typo. Patch by Michael Schurter. files: Doc/library/argparse.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1439,7 +1439,7 @@ different functions which require different kinds of command-line arguments. :class:`ArgumentParser` supports the creation of such sub-commands with the :meth:`add_subparsers` method. The :meth:`add_subparsers` method is normally - called with no arguments and returns an special action object. This object + called with no arguments and returns a special action object. This object has a single method, :meth:`~ArgumentParser.add_parser`, which takes a command name and any :class:`ArgumentParser` constructor arguments, and returns an :class:`ArgumentParser` object that can be modified as usual. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 01:00:56 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 28 Dec 2012 01:00:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE2Nzk2OiBmaXgg?= =?utf-8?q?typo=2E__Patch_by_Michael_Schurter=2E?= Message-ID: <3YXSk048tHzP2l@mail.python.org> http://hg.python.org/cpython/rev/f348a3110a85 changeset: 81114:f348a3110a85 branch: 3.2 parent: 81106:31955234b624 user: Ezio Melotti date: Fri Dec 28 01:59:24 2012 +0200 summary: #16796: fix typo. Patch by Michael Schurter. files: Doc/library/argparse.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1440,7 +1440,7 @@ different functions which require different kinds of command-line arguments. :class:`ArgumentParser` supports the creation of such sub-commands with the :meth:`add_subparsers` method. The :meth:`add_subparsers` method is normally - called with no arguments and returns an special action object. This object + called with no arguments and returns a special action object. This object has a single method, :meth:`~ArgumentParser.add_parser`, which takes a command name and any :class:`ArgumentParser` constructor arguments, and returns an :class:`ArgumentParser` object that can be modified as usual. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 01:00:57 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 28 Dec 2012 01:00:57 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_=2316796=3A_merge_with_3=2E2=2E?= Message-ID: <3YXSk16WBmzQwF@mail.python.org> http://hg.python.org/cpython/rev/1e35d1f514b3 changeset: 81115:1e35d1f514b3 branch: 3.3 parent: 81110:6601818622ea parent: 81114:f348a3110a85 user: Ezio Melotti date: Fri Dec 28 02:00:22 2012 +0200 summary: #16796: merge with 3.2. files: Doc/library/argparse.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1459,7 +1459,7 @@ different functions which require different kinds of command-line arguments. :class:`ArgumentParser` supports the creation of such sub-commands with the :meth:`add_subparsers` method. The :meth:`add_subparsers` method is normally - called with no arguments and returns an special action object. This object + called with no arguments and returns a special action object. This object has a single method, :meth:`~ArgumentParser.add_parser`, which takes a command name and any :class:`ArgumentParser` constructor arguments, and returns an :class:`ArgumentParser` object that can be modified as usual. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 01:00:59 2012 From: python-checkins at python.org (ezio.melotti) Date: Fri, 28 Dec 2012 01:00:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogIzE2Nzk2OiBtZXJnZSB3aXRoIDMuMy4=?= Message-ID: <3YXSk31qSbzR44@mail.python.org> http://hg.python.org/cpython/rev/07421f9fcfb0 changeset: 81116:07421f9fcfb0 parent: 81111:eb3a4ae095a8 parent: 81115:1e35d1f514b3 user: Ezio Melotti date: Fri Dec 28 02:00:41 2012 +0200 summary: #16796: merge with 3.3. files: Doc/library/argparse.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1459,7 +1459,7 @@ different functions which require different kinds of command-line arguments. :class:`ArgumentParser` supports the creation of such sub-commands with the :meth:`add_subparsers` method. The :meth:`add_subparsers` method is normally - called with no arguments and returns an special action object. This object + called with no arguments and returns a special action object. This object has a single method, :meth:`~ArgumentParser.add_parser`, which takes a command name and any :class:`ArgumentParser` constructor arguments, and returns an :class:`ArgumentParser` object that can be modified as usual. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 03:34:40 2012 From: python-checkins at python.org (chris.jerdonek) Date: Fri, 28 Dec 2012 03:34:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1MzI0?= =?utf-8?q?=3A_Fix_regrtest_parsing_of_--fromfile_and_--randomize_options?= =?utf-8?q?=2E?= Message-ID: <3YXX7N3RGMzQyh@mail.python.org> http://hg.python.org/cpython/rev/b7a0e03bb987 changeset: 81117:b7a0e03bb987 branch: 2.7 parent: 81113:c1623a032adf user: Chris Jerdonek date: Thu Dec 27 18:14:01 2012 -0800 summary: Issue #15324: Fix regrtest parsing of --fromfile and --randomize options. files: Lib/test/regrtest.py | 4 ++-- Misc/NEWS | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -32,7 +32,7 @@ Selecting tests --r/--random -- randomize test execution order (see below) +-r/--randomize -- randomize test execution order (see below) --randseed -- pass a random seed to reproduce a previous random run -f/--fromfile -- read names of tests to run from a file (see below) -x/--exclude -- arguments are tests to *exclude* @@ -258,7 +258,7 @@ try: opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:j:', ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', - 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', + 'exclude', 'single', 'slow', 'randomize', 'fromfile=', 'findleaks', 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir', 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'multiprocess=', 'slaveargs=', 'forever', 'header']) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -585,6 +585,8 @@ Tests ----- +- Issue #15324: Fix regrtest parsing of --fromfile and --randomize options. + - Issue #16618: Add more regression tests for glob. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 03:34:41 2012 From: python-checkins at python.org (chris.jerdonek) Date: Fri, 28 Dec 2012 03:34:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1MzI0?= =?utf-8?q?=3A_Fix_regrtest_parsing_of_--fromfile=2C_--match=2C_and_--rand?= =?utf-8?q?omize=2E?= Message-ID: <3YXX7P6B7yzR5j@mail.python.org> http://hg.python.org/cpython/rev/b2cd12690a51 changeset: 81118:b2cd12690a51 branch: 3.2 parent: 81114:f348a3110a85 user: Chris Jerdonek date: Thu Dec 27 18:16:32 2012 -0800 summary: Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize. files: Lib/test/regrtest.py | 6 +++--- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -33,7 +33,7 @@ Selecting tests --r/--random -- randomize test execution order (see below) +-r/--randomize -- randomize test execution order (see below) --randseed -- pass a random seed to reproduce a previous random run -f/--fromfile -- read names of tests to run from a file (see below) -x/--exclude -- arguments are tests to *exclude* @@ -274,11 +274,11 @@ try: opts, args = getopt.getopt(sys.argv[1:], 'hvqxsoS:rf:lu:t:TD:NLR:FdwWM:nj:Gm:', ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', - 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', + 'exclude', 'single', 'slow', 'randomize', 'fromfile=', 'findleaks', 'use=', 'threshold=', 'coverdir=', 'nocoverdir', 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', - 'start=', 'nowindows', 'header', 'failfast', 'match']) + 'start=', 'nowindows', 'header', 'failfast', 'match=']) except getopt.error as msg: usage(msg) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -723,6 +723,9 @@ Tests ----- +- Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize + options. + - Issue #16664: Add regression tests for glob's behaviour concerning entries starting with a ".". Patch by Sebastian Kreft. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 03:34:43 2012 From: python-checkins at python.org (chris.jerdonek) Date: Fri, 28 Dec 2012 03:34:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merge_from_3=2E2=3A_Issue_=2315324=3A_Fix_regrtest_--fromfile?= =?utf-8?q?=2C_--match=2C_--randomize=2E?= Message-ID: <3YXX7R1m7xzRb0@mail.python.org> http://hg.python.org/cpython/rev/e100d34070cb changeset: 81119:e100d34070cb branch: 3.3 parent: 81115:1e35d1f514b3 parent: 81118:b2cd12690a51 user: Chris Jerdonek date: Thu Dec 27 18:25:54 2012 -0800 summary: Merge from 3.2: Issue #15324: Fix regrtest --fromfile, --match, --randomize. files: Lib/test/regrtest.py | 6 +++--- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -38,7 +38,7 @@ Selecting tests --r/--random -- randomize test execution order (see below) +-r/--randomize -- randomize test execution order (see below) --randseed -- pass a random seed to reproduce a previous random run -f/--fromfile -- read names of tests to run from a file (see below) -x/--exclude -- arguments are tests to *exclude* @@ -301,12 +301,12 @@ try: opts, args = getopt.getopt(sys.argv[1:], 'hvqxsoS:rf:lu:t:TD:NLR:FdwWM:nj:Gm:', ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', - 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', + 'exclude', 'single', 'slow', 'randomize', 'fromfile=', 'findleaks', 'use=', 'threshold=', 'coverdir=', 'nocoverdir', 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait', - 'failfast', 'match']) + 'failfast', 'match=']) except getopt.error as msg: usage(msg) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -348,6 +348,9 @@ Tests ----- +- Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize + options. + - Issue #16664: Add regression tests for glob's behaviour concerning entries starting with a ".". Patch by Sebastian Kreft. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 03:34:44 2012 From: python-checkins at python.org (chris.jerdonek) Date: Fri, 28 Dec 2012 03:34:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merge_from_3=2E3=3A_Issue_=2315324=3A_Fix_regrtest_--fro?= =?utf-8?q?mfile=2C_--match=2C_--randomize=2E?= Message-ID: <3YXX7S4FX7zRXK@mail.python.org> http://hg.python.org/cpython/rev/2c3399510781 changeset: 81120:2c3399510781 parent: 81116:07421f9fcfb0 parent: 81119:e100d34070cb user: Chris Jerdonek date: Thu Dec 27 18:32:47 2012 -0800 summary: Merge from 3.3: Issue #15324: Fix regrtest --fromfile, --match, --randomize. files: Lib/test/regrtest.py | 6 +++--- Misc/NEWS | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -38,7 +38,7 @@ Selecting tests --r/--random -- randomize test execution order (see below) +-r/--randomize -- randomize test execution order (see below) --randseed -- pass a random seed to reproduce a previous random run -f/--fromfile -- read names of tests to run from a file (see below) -x/--exclude -- arguments are tests to *exclude* @@ -301,12 +301,12 @@ try: opts, args = getopt.getopt(sys.argv[1:], 'hvqxsoS:rf:lu:t:TD:NLR:FdwWM:nj:Gm:', ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', - 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', + 'exclude', 'single', 'slow', 'randomize', 'fromfile=', 'findleaks', 'use=', 'threshold=', 'coverdir=', 'nocoverdir', 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait', - 'failfast', 'match']) + 'failfast', 'match=']) except getopt.error as msg: usage(msg) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -534,6 +534,9 @@ - Issue #10646: Tests rearranged for os.samefile/samestat to check for not just symlinks but also hard links. +- Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize + options. + - Issue #16664: Add regression tests for glob's behaviour concerning entries starting with a ".". Patch by Sebastian Kreft. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 03:55:23 2012 From: python-checkins at python.org (chris.jerdonek) Date: Fri, 28 Dec 2012 03:55:23 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315302=3A_Switch_r?= =?utf-8?q?egrtest_from_using_getopt_to_using_argparse=2E?= Message-ID: <3YXXbH72rYzQvf@mail.python.org> http://hg.python.org/cpython/rev/6e2e5adc0400 changeset: 81121:6e2e5adc0400 user: Chris Jerdonek date: Thu Dec 27 18:53:12 2012 -0800 summary: Issue #15302: Switch regrtest from using getopt to using argparse. This is the first step in refactoring regrtest to use argparse. The regrtest module's main() function still expects a getopt-style return value rather than an argparse.Namespace instance. files: Lib/test/regrtest.py | 224 +++++++++++++++++-------- Lib/test/test_regrtest.py | 96 +++++++++++ Misc/NEWS | 2 + 3 files changed, 245 insertions(+), 77 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -1,11 +1,18 @@ #! /usr/bin/env python3 """ -Usage: +Script to run Python regression tests. +Run this script with -h or --help for documentation. +""" + +USAGE = """\ python -m test [options] [test_name1 [test_name2 ...]] python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]] +""" +DESCRIPTION = """\ +Run Python regression tests. If no arguments or options are provided, finds all files matching the pattern "test_*" in the Lib/test subdirectory and runs @@ -15,63 +22,10 @@ command line: python -E -Wd -m test [options] [test_name1 ...] +""" - -Options: - --h/--help -- print this text and exit ---timeout TIMEOUT - -- dump the traceback and exit if a test takes more - than TIMEOUT seconds; disabled if TIMEOUT is negative - or equals to zero ---wait -- wait for user input, e.g., allow a debugger to be attached - -Verbosity - --v/--verbose -- run tests in verbose mode with output to stdout --w/--verbose2 -- re-run failed tests in verbose mode --W/--verbose3 -- display test output on failure --d/--debug -- print traceback for failed tests --q/--quiet -- no output unless one or more tests fail --o/--slow -- print the slowest 10 tests - --header -- print header with interpreter info - -Selecting tests - --r/--randomize -- randomize test execution order (see below) - --randseed -- pass a random seed to reproduce a previous random run --f/--fromfile -- read names of tests to run from a file (see below) --x/--exclude -- arguments are tests to *exclude* --s/--single -- single step through a set of tests (see below) --m/--match PAT -- match test cases and methods with glob pattern PAT --G/--failfast -- fail as soon as a test fails (only with -v or -W) --u/--use RES1,RES2,... - -- specify which special resource intensive tests to run --M/--memlimit LIMIT - -- run very large memory-consuming tests - --testdir DIR - -- execute test files in the specified directory (instead - of the Python stdlib test suite) - -Special runs - --l/--findleaks -- if GC is available detect tests that leak memory --L/--runleaks -- run the leaks(1) command just before exit --R/--huntrleaks RUNCOUNTS - -- search for reference leaks (needs debug build, v. slow) --j/--multiprocess PROCESSES - -- run PROCESSES processes at once --T/--coverage -- turn on code coverage tracing using the trace module --D/--coverdir DIRECTORY - -- Directory where coverage files are put --N/--nocoverdir -- Put coverage files alongside modules --t/--threshold THRESHOLD - -- call gc.set_threshold(THRESHOLD) --n/--nowindows -- suppress error message boxes on Windows --F/--forever -- run the specified tests in a loop, until an error happens - - -Additional Option Details: +EPILOG = """\ +Additional option details: -r randomizes test execution order. You can use --randseed=int to provide a int seed value for the randomizer; this is useful for reproducing troublesome @@ -168,9 +122,9 @@ # We import importlib *ASAP* in order to test #15386 import importlib +import argparse import builtins import faulthandler -import getopt import io import json import logging @@ -248,10 +202,138 @@ TEMPDIR = os.path.abspath(tempfile.gettempdir()) -def usage(msg): - print(msg, file=sys.stderr) - print("Use --help for usage", file=sys.stderr) - sys.exit(2) +def _create_parser(): + # Set prog to prevent the uninformative "__main__.py" from displaying in + # error messages when using "python -m test ...". + parser = argparse.ArgumentParser(prog='regrtest.py', + usage=USAGE, + description=DESCRIPTION, + epilog=EPILOG, + add_help=False, + formatter_class= + argparse.RawDescriptionHelpFormatter) + + # Arguments with this clause added to its help are described further in + # the epilog's "Additional option details" section. + more_details = ' See the section at bottom for more details.' + + group = parser.add_argument_group('General options') + # We add help explicitly to control what argument group it renders under. + group.add_argument('-h', '--help', action='help', + help='show this help message and exit') + group.add_argument('--timeout', metavar='TIMEOUT', + help='dump the traceback and exit if a test takes ' + 'more than TIMEOUT seconds; disabled if TIMEOUT ' + 'is negative or equals to zero') + group.add_argument('--wait', action='store_true', help='wait for user ' + 'input, e.g., allow a debugger to be attached') + group.add_argument('--slaveargs', metavar='ARGS') + group.add_argument('-S', '--start', metavar='START', help='the name of ' + 'the test at which to start.' + more_details) + + group = parser.add_argument_group('Verbosity') + group.add_argument('-v', '--verbose', action='store_true', + help='run tests in verbose mode with output to stdout') + group.add_argument('-w', '--verbose2', action='store_true', + help='re-run failed tests in verbose mode') + group.add_argument('-W', '--verbose3', action='store_true', + help='display test output on failure') + group.add_argument('-d', '--debug', action='store_true', + help='print traceback for failed tests') + group.add_argument('-q', '--quiet', action='store_true', + help='no output unless one or more tests fail') + group.add_argument('-o', '--slow', action='store_true', + help='print the slowest 10 tests') + group.add_argument('--header', action='store_true', + help='print header with interpreter info') + + group = parser.add_argument_group('Selecting tests') + group.add_argument('-r', '--randomize', action='store_true', + help='randomize test execution order.' + more_details) + group.add_argument('--randseed', metavar='SEED', help='pass a random seed ' + 'to reproduce a previous random run') + group.add_argument('-f', '--fromfile', metavar='FILE', help='read names ' + 'of tests to run from a file.' + more_details) + group.add_argument('-x', '--exclude', action='store_true', + help='arguments are tests to *exclude*') + group.add_argument('-s', '--single', action='store_true', help='single ' + 'step through a set of tests.' + more_details) + group.add_argument('-m', '--match', metavar='PAT', help='match test cases ' + 'and methods with glob pattern PAT') + group.add_argument('-G', '--failfast', action='store_true', help='fail as ' + 'soon as a test fails (only with -v or -W)') + group.add_argument('-u', '--use', metavar='RES1,RES2,...', help='specify ' + 'which special resource intensive tests to run.' + + more_details) + group.add_argument('-M', '--memlimit', metavar='LIMIT', help='run very ' + 'large memory-consuming tests.' + more_details) + group.add_argument('--testdir', metavar='DIR', + help='execute test files in the specified directory ' + '(instead of the Python stdlib test suite)') + + group = parser.add_argument_group('Special runs') + group.add_argument('-l', '--findleaks', action='store_true', help='if GC ' + 'is available detect tests that leak memory') + group.add_argument('-L', '--runleaks', action='store_true', + help='run the leaks(1) command just before exit.' + + more_details) + group.add_argument('-R', '--huntrleaks', metavar='RUNCOUNTS', + help='search for reference leaks (needs debug build, ' + 'very slow).' + more_details) + group.add_argument('-j', '--multiprocess', metavar='PROCESSES', + help='run PROCESSES processes at once') + group.add_argument('-T', '--coverage', action='store_true', help='turn on ' + 'code coverage tracing using the trace module') + group.add_argument('-D', '--coverdir', metavar='DIR', + help='directory where coverage files are put') + group.add_argument('-N', '--nocoverdir', action='store_true', + help='put coverage files alongside modules') + group.add_argument('-t', '--threshold', metavar='THRESHOLD', + help='call gc.set_threshold(THRESHOLD)') + group.add_argument('-n', '--nowindows', action='store_true', + help='suppress error message boxes on Windows') + group.add_argument('-F', '--forever', action='store_true', + help='run the specified tests in a loop, until an ' + 'error happens') + + parser.add_argument('args', nargs=argparse.REMAINDER, + help=argparse.SUPPRESS) + + return parser + +def _convert_namespace_to_getopt(ns): + """Convert an argparse.Namespace object to a getopt-style (opts, args).""" + opts = [] + args_dict = vars(ns) + for key in sorted(args_dict.keys()): + if key == 'args': + continue + val = args_dict[key] + # Don't continue if val equals '' because this means an option + # accepting a value was provided the empty string. Such values should + # show up in the returned opts list. + if val is None or val is False: + continue + if val is True: + # Then an option with action store_true was passed. getopt + # includes these with value '' in the opts list. + val = '' + opts.append(('--' + key, val)) + return opts, ns.args + +# This function has a getopt-style return value because regrtest.main() +# was originally written using getopt. +# TODO: switch this to return an argparse.Namespace instance. +def _parse_args(args=None): + """Parse arguments, and return a getopt-style (opts, args). + + This method mimics the return value of getopt.getopt(). In addition, + the (option, value) pairs in opts are sorted by option and use the long + option string. + """ + parser = _create_parser() + ns = parser.parse_args(args=args) + return _convert_namespace_to_getopt(ns) def main(tests=None, testdir=None, verbose=0, quiet=False, @@ -298,17 +380,8 @@ replace_stdout() support.record_original_stdout(sys.stdout) - try: - opts, args = getopt.getopt(sys.argv[1:], 'hvqxsoS:rf:lu:t:TD:NLR:FdwWM:nj:Gm:', - ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', - 'exclude', 'single', 'slow', 'randomize', 'fromfile=', 'findleaks', - 'use=', 'threshold=', 'coverdir=', 'nocoverdir', - 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', - 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', - 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait', - 'failfast', 'match=']) - except getopt.error as msg: - usage(msg) + + opts, args = _parse_args() # Defaults if random_seed is None: @@ -319,10 +392,7 @@ start = None timeout = None for o, a in opts: - if o in ('-h', '--help'): - print(__doc__) - return - elif o in ('-v', '--verbose'): + if o in ('-v', '--verbose'): verbose += 1 elif o in ('-w', '--verbose2'): verbose2 = True diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py new file mode 100644 --- /dev/null +++ b/Lib/test/test_regrtest.py @@ -0,0 +1,96 @@ +""" +Tests of regrtest.py. +""" + +import argparse +import getopt +import unittest +from test import regrtest, support + +def old_parse_args(args): + """Parse arguments as regrtest did strictly prior to 3.4. + + Raises getopt.GetoptError on bad arguments. + """ + return getopt.getopt(args, 'hvqxsoS:rf:lu:t:TD:NLR:FdwWM:nj:Gm:', + ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', + 'exclude', 'single', 'slow', 'randomize', 'fromfile=', 'findleaks', + 'use=', 'threshold=', 'coverdir=', 'nocoverdir', + 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', + 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', + 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait', + 'failfast', 'match=']) + +class ParseArgsTestCase(unittest.TestCase): + + """Test that regrtest._parse_args() matches the prior getopt behavior.""" + + def _parse_args(self, args): + return regrtest._parse_args(args=args) + + def _check_args(self, args, expected=None): + """ + The expected parameter is for cases when the behavior of the new + parse_args differs from the old (but deliberately so). + """ + if expected is None: + try: + expected = old_parse_args(args) + except getopt.GetoptError: + # Suppress usage string output when an argparse.ArgumentError + # error is raised. + with support.captured_stderr(): + self.assertRaises(SystemExit, self._parse_args, args) + return + # The new parse_args() sorts by long option string. + expected[0].sort() + actual = self._parse_args(args) + self.assertEqual(actual, expected) + + def test_unrecognized_argument(self): + self._check_args(['--xxx']) + + def test_value_not_provided(self): + self._check_args(['--start']) + + def test_short_option(self): + # getopt returns the short option whereas argparse returns the long. + expected = ([('--quiet', '')], []) + self._check_args(['-q'], expected=expected) + + def test_long_option(self): + self._check_args(['--quiet']) + + def test_long_option__partial(self): + self._check_args(['--qui']) + + def test_two_options(self): + self._check_args(['--quiet', '--exclude']) + + def test_option_with_value(self): + self._check_args(['--start', 'foo']) + + def test_option_with_empty_string_value(self): + self._check_args(['--start', '']) + + def test_arg(self): + self._check_args(['foo']) + + def test_option_and_arg(self): + self._check_args(['--quiet', 'foo']) + + def test_fromfile(self): + self._check_args(['--fromfile', 'file']) + + def test_match(self): + self._check_args(['--match', 'pattern']) + + def test_randomize(self): + self._check_args(['--randomize']) + + +def test_main(): + support.run_unittest(__name__) + +if __name__ == '__main__': + test_main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -534,6 +534,8 @@ - Issue #10646: Tests rearranged for os.samefile/samestat to check for not just symlinks but also hard links. +- Issue #15302: Switch regrtest from using getopt to using argparse. + - Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize options. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 04:50:56 2012 From: python-checkins at python.org (chris.jerdonek) Date: Fri, 28 Dec 2012 04:50:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Make_=22build=22_step_of_?= =?utf-8?q?Quick_Start_match_the_formatting_of_the_other_steps=2E?= Message-ID: <3YXYqN12djzR0L@mail.python.org> http://hg.python.org/devguide/rev/04f801a821cf changeset: 581:04f801a821cf user: Chris Jerdonek date: Thu Dec 27 19:50:27 2012 -0800 summary: Make "build" step of Quick Start match the formatting of the other steps. files: index.rst | 7 ++++--- setup.rst | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/index.rst b/index.rst --- a/index.rst +++ b/index.rst @@ -18,10 +18,11 @@ hg clone http://hg.python.org/cpython -2. On UNIX, run ``./configure --with-pydebug && make -j2`` to - :ref:`build Python `. +2. :ref:`Build Python `. On :ref:`UNIX `:: - On :ref:`Windows `, load the project file + ./configure --with-pydebug && make -j2 + + On :ref:`Windows `, open the solution file :file:`PCbuild\\pcbuild.sln` in Visual Studio, select :menuselection:`Debug`, and :menuselection:`Build --> Build Solution`. 3. :doc:`Run the tests `:: diff --git a/setup.rst b/setup.rst --- a/setup.rst +++ b/setup.rst @@ -122,6 +122,8 @@ more Python code than C. +.. _unix-compiling: + UNIX '''' -- Repository URL: http://hg.python.org/devguide From solipsis at pitrou.net Fri Dec 28 05:55:14 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 28 Dec 2012 05:55:14 +0100 Subject: [Python-checkins] Daily reference leaks (07421f9fcfb0): sum=6 Message-ID: results for 07421f9fcfb0 on branch "default" -------------------------------------------- test_dbm leaked [0, 2, 0] references, sum=2 test_dbm leaked [0, 2, 2] memory blocks, sum=4 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogwuD03W', '-x'] From python-checkins at python.org Fri Dec 28 09:03:30 2012 From: python-checkins at python.org (raymond.hettinger) Date: Fri, 28 Dec 2012 09:03:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Make_the_from?= =?utf-8?q?=5Fiterable=28=29_recipe_more_usable=2E?= Message-ID: <3YXgQp0CnFzQtK@mail.python.org> http://hg.python.org/cpython/rev/14f99221d937 changeset: 81122:14f99221d937 branch: 2.7 parent: 81117:b7a0e03bb987 user: Raymond Hettinger date: Fri Dec 28 00:03:30 2012 -0800 summary: Make the from_iterable() recipe more usable. The code isn't exactly equivalent because a classmethod would only make sense inside a chain class, and it would need "cls" as a first argument, and it would need to return an instance of "chain" rather than a generator. The updated example drops the @classmethod decorator so that it can be used standalone: list(from_iterable(['abc', 'def'])) This should be communicate what from_iterable does. files: Doc/library/itertools.rst | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -106,9 +106,8 @@ .. classmethod:: chain.from_iterable(iterable) Alternate constructor for :func:`chain`. Gets chained inputs from a - single iterable argument that is evaluated lazily. Equivalent to:: + single iterable argument that is evaluated lazily. Roughly equivalent to:: - @classmethod def from_iterable(iterables): # chain.from_iterable(['ABC', 'DEF']) --> A B C D E F for it in iterables: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 09:21:00 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 28 Dec 2012 09:21:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NzYx?= =?utf-8?q?=3A_Raise_TypeError_when_int=28=29_or_long=28=29_called_with_ba?= =?utf-8?q?se_argument?= Message-ID: <3YXgq02WYwzR0N@mail.python.org> http://hg.python.org/cpython/rev/c0266ba8e4c6 changeset: 81123:c0266ba8e4c6 branch: 2.7 parent: 81117:b7a0e03bb987 user: Serhiy Storchaka date: Fri Dec 28 09:31:59 2012 +0200 summary: Issue #16761: Raise TypeError when int() or long() called with base argument only. files: Lib/test/test_int.py | 14 ++------------ Misc/NEWS | 3 +++ Objects/intobject.c | 8 +++++++- Objects/longobject.c | 8 +++++++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -60,6 +60,8 @@ self.assertEqual(self.ntype(x=1.2), 1) self.assertEqual(self.ntype('100', base=2), 4) self.assertEqual(self.ntype(x='100', base=2), 4) + self.assertRaises(TypeError, self.ntype, base=10) + self.assertRaises(TypeError, self.ntype, base=0) class IntTestCases(IntLongCommonTests, unittest.TestCase): @@ -365,18 +367,6 @@ def test_error_on_string_base(self): self.assertRaises(TypeError, int, 100, base='foo') - # Include the following because in contrast CPython raises no error - # for bad integer bases when x is not given. - self.assertRaises(TypeError, int, base='foo') - - # For example, PyPy 1.9.0 raised TypeError for these cases because it - # expects x to be a string if base is given. - @test_support.cpython_only - def test_int_base_without_x_returns_0(self): - self.assertEqual(int(base=6), 0) - # Even invalid bases don't raise an exception. - self.assertEqual(int(base=1), 0) - self.assertEqual(int(base=1000), 0) @test_support.cpython_only def test_small_ints(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ Core and Builtins ----------------- +- Issue #16761: Calling ``int()`` and ``long()`` with *base* argument only + now raises TypeError. + - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py when retreiving a REG_DWORD value. This corrects functions like winreg.QueryValueEx that may have been returning truncated values. diff --git a/Objects/intobject.c b/Objects/intobject.c --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -1059,8 +1059,14 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:int", kwlist, &x, &base)) return NULL; - if (x == NULL) + if (x == NULL) { + if (base != -909) { + PyErr_SetString(PyExc_TypeError, + "int() missing string argument"); + return NULL; + } return PyInt_FromLong(0L); + } if (base == -909) return PyNumber_Int(x); if (PyString_Check(x)) { diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3987,8 +3987,14 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:long", kwlist, &x, &base)) return NULL; - if (x == NULL) + if (x == NULL) { + if (base != -909) { + PyErr_SetString(PyExc_TypeError, + "long() missing string argument"); + return NULL; + } return PyLong_FromLong(0L); + } if (base == -909) return PyNumber_Long(x); else if (PyString_Check(x)) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 09:21:01 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 28 Dec 2012 09:21:01 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NzYx?= =?utf-8?q?=3A_Raise_TypeError_when_int=28=29_called_with_base_argument_on?= =?utf-8?b?bHku?= Message-ID: <3YXgq15QGRzR5j@mail.python.org> http://hg.python.org/cpython/rev/e4ea38a92c4d changeset: 81124:e4ea38a92c4d branch: 3.2 parent: 81118:b2cd12690a51 user: Serhiy Storchaka date: Fri Dec 28 09:42:11 2012 +0200 summary: Issue #16761: Raise TypeError when int() called with base argument only. files: Lib/test/test_int.py | 8 ++++++++ Misc/NEWS | 3 +++ Objects/longobject.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -226,6 +226,14 @@ self.assertIs(int(b'10'), 10) self.assertIs(int(b'-1'), -1) + def test_keyword_args(self): + # Test invoking int() using keyword arguments. + self.assertEqual(int(x=1.2), 1) + self.assertEqual(int('100', base=2), 4) + self.assertEqual(int(x='100', base=2), 4) + self.assertRaises(TypeError, int, base=10) + self.assertRaises(TypeError, int, base=0) + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #16761: Calling ``int()`` with *base* argument only now raises + TypeError. + - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py when retreiving a REG_DWORD value. This corrects functions like winreg.QueryValueEx that may have been returning truncated values. diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4130,8 +4130,14 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist, &x, &obase)) return NULL; - if (x == NULL) + if (x == NULL) { + if (obase != NULL) { + PyErr_SetString(PyExc_TypeError, + "int() missing string argument"); + return NULL; + } return PyLong_FromLong(0L); + } if (obase == NULL) return PyNumber_Long(x); @@ -4140,7 +4146,7 @@ return NULL; if (overflow || (base != 0 && base < 2) || base > 36) { PyErr_SetString(PyExc_ValueError, - "int() arg 2 must be >= 2 and <= 36"); + "int() base must be >= 2 and <= 36"); return NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 09:21:03 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 28 Dec 2012 09:21:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316761=3A_Raise_TypeError_when_int=28=29_called_with_b?= =?utf-8?q?ase_argument_only=2E?= Message-ID: <3YXgq30xQwzRfL@mail.python.org> http://hg.python.org/cpython/rev/157ff02bcc16 changeset: 81125:157ff02bcc16 branch: 3.3 parent: 81119:e100d34070cb parent: 81124:e4ea38a92c4d user: Serhiy Storchaka date: Fri Dec 28 10:02:42 2012 +0200 summary: Issue #16761: Raise TypeError when int() called with base argument only. files: Lib/test/test_int.py | 12 ++---------- Misc/NEWS | 3 +++ Objects/longobject.c | 10 ++++++++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -233,16 +233,8 @@ self.assertEqual(int(x=1.2), 1) self.assertEqual(int('100', base=2), 4) self.assertEqual(int(x='100', base=2), 4) - - # For example, PyPy 1.9.0 raised TypeError for these cases because it - # expects x to be a string if base is given. - @support.cpython_only - def test_base_arg_with_no_x_arg(self): - self.assertEqual(int(base=6), 0) - # Even invalid bases don't raise an exception. - self.assertEqual(int(base=1), 0) - self.assertEqual(int(base=1000), 0) - self.assertEqual(int(base='foo'), 0) + self.assertRaises(TypeError, int, base=10) + self.assertRaises(TypeError, int, base=0) def test_non_numeric_input_types(self): # Test possible non-numeric types for the argument x, including diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ Core and Builtins ----------------- +- Issue #16761: Calling ``int()`` with *base* argument only now raises + TypeError. + - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py when retreiving a REG_DWORD value. This corrects functions like winreg.QueryValueEx that may have been returning truncated values. diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4267,8 +4267,14 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist, &x, &obase)) return NULL; - if (x == NULL) + if (x == NULL) { + if (obase != NULL) { + PyErr_SetString(PyExc_TypeError, + "int() missing string argument"); + return NULL; + } return PyLong_FromLong(0L); + } if (obase == NULL) return PyNumber_Long(x); @@ -4277,7 +4283,7 @@ return NULL; if (overflow || (base != 0 && base < 2) || base > 36) { PyErr_SetString(PyExc_ValueError, - "int() arg 2 must be >= 2 and <= 36"); + "int() base must be >= 2 and <= 36"); return NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 09:21:04 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 28 Dec 2012 09:21:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316761=3A_Raise_TypeError_when_int=28=29_called_?= =?utf-8?q?with_base_argument_only=2E?= Message-ID: <3YXgq441ZhzRfY@mail.python.org> http://hg.python.org/cpython/rev/1b2134a78c17 changeset: 81126:1b2134a78c17 parent: 81121:6e2e5adc0400 parent: 81125:157ff02bcc16 user: Serhiy Storchaka date: Fri Dec 28 10:09:54 2012 +0200 summary: Issue #16761: Raise TypeError when int() called with base argument only. files: Lib/test/test_int.py | 12 ++---------- Misc/NEWS | 3 +++ Objects/longobject.c | 12 +++++++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -233,16 +233,8 @@ self.assertEqual(int(x=1.2), 1) self.assertEqual(int('100', base=2), 4) self.assertEqual(int(x='100', base=2), 4) - - # For example, PyPy 1.9.0 raised TypeError for these cases because it - # expects x to be a string if base is given. - @support.cpython_only - def test_base_arg_with_no_x_arg(self): - self.assertEqual(int(base=6), 0) - # Even invalid bases don't raise an exception. - self.assertEqual(int(base=1), 0) - self.assertEqual(int(base=1000), 0) - self.assertEqual(int(base='foo'), 0) + self.assertRaises(TypeError, int, base=10) + self.assertRaises(TypeError, int, base=0) def test_int_base_limits(self): """Testing the supported limits of the int() base parameter.""" diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #16761: Calling ``int()`` with *base* argument only now raises + TypeError. + - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py when retreiving a REG_DWORD value. This corrects functions like winreg.QueryValueEx that may have been returning truncated values. diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4255,13 +4255,19 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist, &x, &obase)) return NULL; - if (x == NULL) + if (x == NULL) { + if (obase != NULL) { + PyErr_SetString(PyExc_TypeError, + "int() missing string argument"); + return NULL; + } return PyLong_FromLong(0L); + } if (obase == NULL) return PyNumber_Long(x); if (!PyLong_Check(obase)) { PyErr_SetString(PyExc_TypeError, - "int() arg 2 must be an integer."); + "int() base must be an integer."); return NULL; } @@ -4270,7 +4276,7 @@ return NULL; if ((base != 0 && base < 2) || base > 36) { PyErr_SetString(PyExc_ValueError, - "int() arg 2 must be >= 2 and <= 36"); + "int() base must be >= 2 and <= 36"); return NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 09:21:05 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Fri, 28 Dec 2012 09:21:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMi43IC0+IDIuNyk6?= =?utf-8?q?_Merge_heads?= Message-ID: <3YXgq56hBmzRb0@mail.python.org> http://hg.python.org/cpython/rev/75eac2794deb changeset: 81127:75eac2794deb branch: 2.7 parent: 81122:14f99221d937 parent: 81123:c0266ba8e4c6 user: Serhiy Storchaka date: Fri Dec 28 10:16:47 2012 +0200 summary: Merge heads files: Lib/test/test_int.py | 14 ++------------ Misc/NEWS | 3 +++ Objects/intobject.c | 8 +++++++- Objects/longobject.c | 8 +++++++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -60,6 +60,8 @@ self.assertEqual(self.ntype(x=1.2), 1) self.assertEqual(self.ntype('100', base=2), 4) self.assertEqual(self.ntype(x='100', base=2), 4) + self.assertRaises(TypeError, self.ntype, base=10) + self.assertRaises(TypeError, self.ntype, base=0) class IntTestCases(IntLongCommonTests, unittest.TestCase): @@ -365,18 +367,6 @@ def test_error_on_string_base(self): self.assertRaises(TypeError, int, 100, base='foo') - # Include the following because in contrast CPython raises no error - # for bad integer bases when x is not given. - self.assertRaises(TypeError, int, base='foo') - - # For example, PyPy 1.9.0 raised TypeError for these cases because it - # expects x to be a string if base is given. - @test_support.cpython_only - def test_int_base_without_x_returns_0(self): - self.assertEqual(int(base=6), 0) - # Even invalid bases don't raise an exception. - self.assertEqual(int(base=1), 0) - self.assertEqual(int(base=1000), 0) @test_support.cpython_only def test_small_ints(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ Core and Builtins ----------------- +- Issue #16761: Calling ``int()`` and ``long()`` with *base* argument only + now raises TypeError. + - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py when retreiving a REG_DWORD value. This corrects functions like winreg.QueryValueEx that may have been returning truncated values. diff --git a/Objects/intobject.c b/Objects/intobject.c --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -1059,8 +1059,14 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:int", kwlist, &x, &base)) return NULL; - if (x == NULL) + if (x == NULL) { + if (base != -909) { + PyErr_SetString(PyExc_TypeError, + "int() missing string argument"); + return NULL; + } return PyInt_FromLong(0L); + } if (base == -909) return PyNumber_Int(x); if (PyString_Check(x)) { diff --git a/Objects/longobject.c b/Objects/longobject.c --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3987,8 +3987,14 @@ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:long", kwlist, &x, &base)) return NULL; - if (x == NULL) + if (x == NULL) { + if (base != -909) { + PyErr_SetString(PyExc_TypeError, + "long() missing string argument"); + return NULL; + } return PyLong_FromLong(0L); + } if (base == -909) return PyNumber_Long(x); else if (PyString_Check(x)) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 18:40:59 2012 From: python-checkins at python.org (nick.coghlan) Date: Fri, 28 Dec 2012 18:40:59 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_432_updates_in_response_t?= =?utf-8?q?o_initial_comments?= Message-ID: <3YXwF72ym4zP4V@mail.python.org> http://hg.python.org/peps/rev/9365512df029 changeset: 4638:9365512df029 user: Nick Coghlan date: Sat Dec 29 03:40:37 2012 +1000 summary: PEP 432 updates in response to initial comments - explicitly narrow scope to exclude major changes to config storage - better articulate the specific settings the API needs to handle - more details on the status quo - fix some issues with the random hashing description files: pep-0432.txt | 394 +++++++++++++++++++++++++++++++++++--- 1 files changed, 357 insertions(+), 37 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -20,6 +20,10 @@ CPython's startup behaviour when creating an alternate executable or embedding it as a Python execution engine inside a larger application. +Note: TBC = To Be Confirmed, TBD = To Be Determined. The appropriate +resolution for most of these should become clearer as the reference +implementation is developed. + Proposal Summary ================ @@ -39,6 +43,18 @@ not implicitly set ``sys.path[0]`` based on the current directory or the script being executed. +To keep the implementation complexity under control, this PEP does *not* +propose wholesale changes to the way the interpreter state is accessed at +runtime, nor does it propose changes to the way subinterpreters are +created after the main interpreter has already been initialised. Changing +the order in which the existing initialisation steps occur to make the +startup sequence easier to maintain is already a substantial change, and +attempting to make those other changes at the same time will make the +change significantly more invasive and much harder to review. However, such +proposals may be suitable topics for follow-on PEPs or patches - one key +benefit of this PEP is decreasing the coupling between the internal storage +model and the configuration interface. + Background ========== @@ -99,21 +115,290 @@ CPython is used heavily to run short scripts where the runtime is dominated by the interpreter initialisation time. Any changes to the startup sequence -should minimise their impact on the startup overhead. (Given that the -overhead is dominated by IO operations, this is not currently expected to -cause any significant problems). +should minimise their impact on the startup overhead. + +Experience with the importlib migration suggests that the startup time is +dominated by IO operations. However, to monitor the impact of any changes, +a simple benchmark can be used to check how long it takes to start and then +tear down the interpreter:: + + python3 -m timeit -s "from subprocess import call" "call(['./python', '-c', 'pass'])" + +If this simple check suggests that any changes may pose a performance +problem, then a more sophisticated microbenchmark will be developed to assist +in investigation. + + +Required Configuration Settings +=============================== + +A comprehensive configuration scheme requires that an embedding application +be able to control the following aspects of the final interpreter state: + +* Whether or not to use randomised hashes (and if used, potentially specify + a specific random seed) +* The "Where is Python located?" elements in the ``sys`` module: + * ``sys.executable`` + * ``sys.base_exec_prefix`` + * ``sys.base_prefix`` + * ``sys.exec_prefix`` + * ``sys.prefix`` +* The path searched for imports from the filesystem (and other path hooks): + * ``sys.path`` +* The command line arguments seen by the interpeter: + * ``sys.argv`` +* The filesystem encoding used by: + * ``sys.getfsencoding`` + * ``os.fsencode`` + * ``os.fsdecode`` +* The IO encoding used by: + * ``sys.stdin`` + * ``sys.stdout`` + * ``sys.stderr`` +* The initial warning system state: + * ``sys.warnoptions`` +* Arbitrary extended options (e.g. to automatically enable ``faulthandler``): + * ``sys._xoptions`` +* Whether or not to implicitly cache bytecode files: + * ``sys.dont_write_bytecode`` +* Whether or not to enforce correct case in filenames on case-insensitive + platforms + * ``os.environ["PYTHONCASEOK"]`` +* The other settings exposed to Python code in ``sys.flags``: + + * ``debug`` (Enable debugging output in the pgen parser) + * ``inspect`` (Enter interactive interpreter after __main__ terminates) + * ``interactive`` (Treat stdin as a tty) + * ``optimize`` (__debug__ status, write .pyc or .pyo, strip doc strings) + * ``no_user_site`` (don't add the user site directory to sys.path) + * ``no_site`` (don't implicitly import site during startup) + * ``ignore_environment`` (whether environment vars are used during config) + * ``verbose`` (enable all sorts of random output) + * ``bytes_warning`` + * ``quiet`` (disable banner output even if verbose is also enabled or + stdin is a tty and the interpreter is launched in interactive mode) + +* Whether or not CPython's signal handlers should be installed +* What code (if any) should be executed as ``__main__``: + + * Nothing (just create an empty module) + * A filesystem path referring to a Python script (source or bytecode) + * A filesystem path referring to a valid ``sys.path`` entry (typically + a directory or zipfile) + * A given string (equivalent to the "-c" option) + * A module or package (equivalent to the "-m" option) + * Standard input as a script (i.e. a non-interactive stream) + * Standard input as an interactive interpreter session + + + +Note that this just covers settings that are currently configurable in some +manner when using the main CPython executable. While this PEP aims to make +adding additional configuration settings easier in the future, it +deliberately avoids any new settings of its own. The Status Quo ============== +The current mechanisms for configuring the interpreter have accumulated in +a fairly ad hoc fashion over the past 20+ years, leading to a rather +inconsistent interface with varying levels of documentation. + +(Note: some of the info below could probably be cleaned up and added to the +C API documentation - it's all CPython specific, so it doesn't belong in +the language reference) + + +Ignoring Environment Variables +------------------------------ + +The ``-E`` command line option allows all environment variables to be +ignored when initialising the Python interpreter. An embedding application +can enable this behaviour by setting ``Py_IgnoreEnvironmentFlag`` before +calling ``Py_Initialize()``. + +In the CPython source code, the ``Py_GETENV`` macro implicitly checks this +flag, and always produces ``NULL`` if it is set. + + + + +Randomised Hashing +------------------ + +The randomised hashing is controlled via the ``-R`` command line option (in +releases prior to 3.3), as well as the ``PYTHONHASHSEED`` environment +variable. + +In Python 3.3, only the environment variable remains relevant. It can be +used to disable randomised hashing (by using a seed value of 0) or else +to force a specific hash value (e.g. for repeatability of testing, or +to share hash values between processes) + +However, embedding applications must use the ``Py_HashRandomizationFlag`` +to explicitly request hash randomisation (CPython sets it in ``Py_Main()`` +rather than in ``Py_Initialize()``). + +The new configuration API should make it straightforward for an +embedding application to reuse the ``PYTHONHASHSEED`` processing with +a text based configuration setting provided by other means. + + +Locating Python and the standard library +---------------------------------------- + +The location of the Python binary and the standard library is influenced +by several elements. The algorithm used to perform the calculation is +not documented anywhere other than in the source code [3_,4_]. Even that +description is incomplete, as it failed to be updated for the virtual +environment support added in Python 3.3 (detailed in PEP 420). + +These calculations are affected by the following function calls (made +prior to calling ``Py_Initialize()``) and environment variables: + +* ``Py_SetProgramName()`` +* ``Py_SetPythonHome()`` +* ``PYTHONHOME`` + +The filesystem is also inspected for ``pyvenv.cfg`` files (see PEP 420) or, +failing that, a ``lib/os.py`` (Windows) or ``lib/python$VERSION/os.py`` +file. + +The build time settings for PREFIX and EXEC_PREFIX are also relevant, +as are some registry settings on Windows. The hardcoded fallbacks are +based on the layout of the CPython source tree and build output when +working in a source checkout. + + +Configuring ``sys.path`` +------------------------ + +An embedding application may call ``Py_SetPath()`` prior to +``Py_Initialize()`` to completely override the calculation of +``sys.path``. It is not straightforward to only allow *some* of the +calculations, as modifying ``sys.path`` after initialisation is +already complete means those modifications will not be in effect +when standard library modules are imported during the startup sequence. + +If ``Py_SetPath()`` is not used prior to the first call to ``Py_GetPath()`` +(implicit in ``Py_Initialize()``), then it builds on the location data +calculations above to calculate suitable path entries, along with +the ``PYTHONPATH`` environment variable. + + + +The ``site`` module, which is implicitly imported at startup (unless +disabled via the ``-S`` option) adds additional paths to this initial +set of paths, as described in its documentation [5_]. + +The ``-s`` command line option can be used to exclude the user site +directory from the list of directories added. Embedding applications +can control this by setting the ``Py_NoUserSiteDirectory`` global variable. + +The following commands can be used to check the default path configurations +for a given Python executable on a given system (after passing the entries +through ``os.path.abspath``): + +* ``./python -m site`` - standard configuration +* ``./python -s -m site`` - user site directory disabled +* ``./python -S -m site`` - all site path modifications disabled + +(Note: on Python versions prior to 3.3, the last command won't have the +desired effect, as the explicit import of the site module will still make +the implicit path modifications that should have been disabled by the ``-S`` +option. The command +``./python -S -c "import sys, pprint; pprint.pprint(sys.path)"`` will +display the desired information. That command can also be used to see +the raw path entries without the ``os.path.abspath`` calls) + +The calculation of ``sys.path[0]`` is comparatively straightforward: + +* For an ordinary script (Python source or compiled bytecode), + ``sys.path[0]`` will be the directory containing the script. +* For a valid ``sys.path`` entry (typically a zipfile or directory), + ``sys.path[0]`` will be that path +* For an interactive session, running from stdin or when using the ``-c`` or + ``-m`` switches, ``sys.path[0]`` will be the empty string, which the import + system interprets as allowing imports from the current directory + + +Configuring ``sys.argv`` +------------------------ + +Unlike most other settings discussed in this PEP, ``sys.argv`` is not +set implicitly by ``Py_Initialize()``. Instead, it must be set via an +explicitly call to ``Py_SetArgv()``. + +CPython calls this in ``Py_Main()`` after calling ``Py_Initialize()``. The +calculation of ``sys.argv[1:]`` is straightforward: they're the command line +arguments passed after the script name or the argument to the ``-c`` or +``-m`` options. + +The calculation of ``sys.argv[0]`` is a little more complicated: + +* For an ordinary script (source or bytecode), it will be the script name +* For a ``sys.path`` entry (typically a zipfile or directory) it will + initially be the zipfile or directory name, but will later be changed by + the ``runpy`` module to the full path to the imported ``__main__`` module. +* For a module specified with the ``-m`` switch, it will initially be the + string ``"-m"``, but will later be changed by the ``runpy`` module to the + full path to the executed module. +* For a package specified with the ``-m`` switch, it will initially be the + string ``"-m"``, but will later be changed by the ``runpy`` module to the + full path to the executed ``__main__`` submodule of the package. +* For a command executed with ``-c``, it will be the string ``"-c"`` +* For explicitly requested input from stdin, it will be the string ``"-"`` +* Otherwise, it will be the empty string + +Embedding applications must call Py_SetArgv themselves. The CPython logic +for doing so is part of ``Py_Main()`` and is not exposed separately. +However, the ``runpy`` module does provide roughly equivalent logic in +``runpy.run_module`` and ``runpy.run_path``. + + + +Other configuration settings +---------------------------- + +TBD: Cover the initialisation of the following in more detail: + +* The initial warning system state: + * ``sys.warnoptions`` +* Arbitrary extended options (e.g. to automatically enable ``faulthandler``): + * ``sys._xoptions`` +* The filesystem encoding used by: + * ``sys.getfsencoding`` + * ``os.fsencode`` + * ``os.fsdecode`` +* The IO encoding used by: + * ``sys.stdin`` + * ``sys.stdout`` + * ``sys.stderr`` +* Whether or not to implicitly cache bytecode files: + * ``sys.dont_write_bytecode`` +* Whether or not to enforce correct case in filenames on case-insensitive + platforms + * ``os.environ["PYTHONCASEOK"]`` +* The other settings exposed to Python code in ``sys.flags``: + + * ``debug`` (Enable debugging output in the pgen parser) + * ``inspect`` (Enter interactive interpreter after __main__ terminates) + * ``interactive`` (Treat stdin as a tty) + * ``optimize`` (__debug__ status, write .pyc or .pyo, strip doc strings) + * ``no_user_site`` (don't add the user site directory to sys.path) + * ``no_site`` (don't implicitly import site during startup) + * ``ignore_environment`` (whether environment vars are used during config) + * ``verbose`` (enable all sorts of random output) + * ``bytes_warning`` (This may be obsolete in Py3k...) + * ``quiet`` (disable banner output even if verbose is also enabled or + stdin is a tty and the interpreter is launched in interactive mode) + +* Whether or not CPython's signal handlers should be installed + Much of the configuration of CPython is currently handled through C level global variables:: - Py_IgnoreEnvironmentFlag - Py_HashRandomizationFlag - _Py_HashSecretInitialized - _Py_HashSecret Py_BytesWarningFlag Py_DebugFlag Py_InspectFlag @@ -132,20 +417,10 @@ Some configuration can only be provided as OS level environment variables:: - PYTHONHASHSEED PYTHONSTARTUP - PYTHONPATH - PYTHONHOME PYTHONCASEOK PYTHONIOENCODING -Additional configuration is handled via separate API calls:: - - Py_SetProgramName() (call before Py_Initialize()) - Py_SetPath() (optional, call before Py_Initialize()) - Py_SetPythonHome() (optional, call before Py_Initialize()???) - Py_SetArgv[Ex]() (call after Py_Initialize()) - The ``Py_InitializeEx()`` API also accepts a boolean flag to indicate whether or not CPython's signal handlers should be installed. @@ -153,7 +428,7 @@ banner) is triggered only when standard input is reported as a terminal connection by the operating system. -Also see more detailed notes at [1_] +Also see detailed sequence of operations notes at [1_] Proposal @@ -162,14 +437,22 @@ (Note: details here are still very much in flux, but preliminary feedback is appreciated anyway) +The main theme of this proposal is to create the interpreter state for +the main interpreter *much* earlier in the startup process. This will allow +most of the CPython API to be used during the remainder of the initialisation +process, potentially simplifying a number of operations that currently need +to rely on basic C functionality rather than being able to use the richer +data structures provided by the CPython C API. + + Core Interpreter Initialisation ------------------------------- The only configuration that currently absolutely needs to be in place -before even the interpreter core can be initialised is the seed for the -randomised hash algorithm. However, there are a couple of settings needed -there: whether or not hash randomisation is enabled at all, and if it's -enabled, whether or not to use a specific seed value. +before even the interpreter core can be initialised is a flag indicating +whether or not to use a specific seed value for the randomised hashes, and +if so, the specific value for the seed (a seed value of zero disables +randomised hashing). The proposed API for this step in the startup sequence is:: @@ -186,27 +469,36 @@ typedef struct { int use_hash_seed; - size_t hash_seed; + unsigned long hash_seed; } Py_CoreConfig; -To "disable" hash randomisation, set "use_hash_seed" and pass a hash seed of -zero. (This seems reasonable to me, but there may be security implications -I'm overlooking. If so, adding a separate flag or switching to a 3-valued -"no randomisation", "fixed hash seed" and "randomised hash" option is easy) +To disable hash randomisation, set "use_hash_seed" and pass a hash seed of +zero. (This is the same approach already used when interpreting the +``PYTHONHASHSEED`` environment variable) The core configuration settings pointer may be NULL, in which case the default behaviour of randomised hashes with a random seed will be used. +The aim is to keep this initial level of configuration as small as possible +in order to keep the bootstrapping environment consistent across +different embedding applications. If we can create a valid interpreter state +without the setting, then the setting should go in the config dict passed +to ``Py_EndInitialization()`` rather than in the core configuration. + A new query API will allow code to determine if the interpreter is in the -bootstrapping state between core initialisation and the completion of the -initialisation process:: +bootstrapping state between the creation of the interpreter state and the +completion of the bulk of the initialisation process:: int Py_IsInitializing(); +Attempting to call ``Py_BeginInitialization()`` again when +``Py_IsInitializing()`` or ``Py_IsInitialized()`` is true is a fatal error. + While in the initialising state, the interpreter should be fully functional except that: -* compilation is not allowed (as the parser is not yet configured properly) +* compilation is not allowed (as the parser and compiler are not yet + configured properly) * The following attributes in the ``sys`` module are all either missing or ``None``: * ``sys.path`` @@ -306,7 +598,6 @@ - Completing the interpreter initialisation ----------------------------------------- @@ -319,6 +610,10 @@ error return rather than exhibiting fatal errors if a problem is found with the config data. +All configuration settings are required - the configuration dictionary +should always be passed through ``Py_ReadConfiguration()`` to ensure it +is fully populated. + After a successful call, Py_IsInitializing() will be false, while Py_IsInitialized() will become true. The caveats described above for the interpreter during the initialisation phase will no longer hold. @@ -337,17 +632,34 @@ Backwards compatibility will be preserved primarily by ensuring that Py_ReadConfiguration() interrogates all the previously defined configuration -settings stored in global variables and environment variables. +settings stored in global variables and environment variables, and that +Py_EndInitialization() writes affected settings back to the relevant +locations. One acknowledged incompatiblity is that some environment variables which are currently read lazily may instead be read once during interpreter initialisation. As the PEP matures, these will be discussed in more detail -on a case by case basis. +on a case by case basis. The environment variables which are currently +known to be looked up dynamically are: -The Py_Initialize() style of initialisation will continue to be supported. It -will use the new API internally, but will continue to exhibit the same -behaviour as it does today, ensuring that sys.argv is not set until a -subsequent PySys_SetArgv call. +* ``PYTHONCASEOK``: writing to ``os.environ['PYTHONCASEOK']`` will no longer + dynamically alter the interpreter's handling of filename case differences + on import (TBC) +* ``PYTHONINSPECT``: ``os.environ['PYTHONINSPECT']`` will still be checked + after execution of the ``__main__`` module terminates + +The ``Py_Initialize()`` style of initialisation will continue to be +supported. It will use (at least some elements of) the new API +internally, but will continue to exhibit the same behaviour as it +does today, ensuring that ``sys.argv`` is not populated until a subsequent +``PySys_SetArgv`` call. All APIs that currently support being called +prior to ``Py_Initialize()`` will +continue to do so, and will also support being called prior to +``Py_BeginInitialization()``. + +To minimise unnecessary code churn, and to ensure the backwards compatibility +is well tested, the main CPython executable may continue to use some elements +of the old style initialisation API. (very much TBC) A System Python Executable @@ -397,6 +709,14 @@ .. [2] BitBucket Sandbox (https://bitbucket.org/ncoghlan/cpython_sandbox) +.. [3] \*nix getpath implementation + (http://hg.python.org/cpython/file/default/Modules/getpath.c) + +.. [4] Windows getpath implementation + (http://hg.python.org/cpython/file/default/PC/getpathp.c) + +.. [5] Site module documentation + (http://docs.python.org/3/library/site.html) Copyright =========== -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Fri Dec 28 19:05:45 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 28 Dec 2012 19:05:45 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Backport_Pytho?= =?utf-8?q?n_3=2E2_fix_for_issue_=2312065=2C_and_add_another_test_for?= Message-ID: <3YXwnj0PqszRwJ@mail.python.org> http://hg.python.org/cpython/rev/3436769a7964 changeset: 81128:3436769a7964 branch: 2.7 user: Antoine Pitrou date: Fri Dec 28 19:03:43 2012 +0100 summary: Backport Python 3.2 fix for issue #12065, and add another test for SSLSocket.connect_ex(). files: Lib/ssl.py | 20 +++++++++++--------- Lib/test/test_ssl.py | 28 ++++++++++++++++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Lib/ssl.py b/Lib/ssl.py --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -313,17 +313,19 @@ self.cert_reqs, self.ssl_version, self.ca_certs, self.ciphers) try: - socket.connect(self, addr) - if self.do_handshake_on_connect: - self.do_handshake() - except socket_error as e: if return_errno: - return e.errno + rc = socket.connect_ex(self, addr) else: - self._sslobj = None - raise e - self._connected = True - return 0 + rc = None + socket.connect(self, addr) + if not rc: + if self.do_handshake_on_connect: + self.do_handshake() + self._connected = True + return rc + except socket_error: + self._sslobj = None + raise def connect(self, addr): """Connects to remote ADDR, and then wraps the connection in diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -280,6 +280,34 @@ finally: s.close() + def test_timeout_connect_ex(self): + # Issue #12065: on a timeout, connect_ex() should return the original + # errno (mimicking the behaviour of non-SSL sockets). + with test_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.settimeout(0.0000001) + rc = s.connect_ex(('svn.python.org', 443)) + if rc == 0: + self.skipTest("svn.python.org responded too quickly") + self.assertIn(rc, (errno.EAGAIN, errno.EWOULDBLOCK)) + finally: + s.close() + + def test_connect_ex_error(self): + with test_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(errno.ECONNREFUSED, + s.connect_ex(("svn.python.org", 444))) + finally: + s.close() + @unittest.skipIf(os.name == "nt", "Can't use a socket as a file under Windows") def test_makefile_close(self): # Issue #5238: creating a file-like object with makefile() shouldn't diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -175,6 +175,9 @@ Library ------- +- Issue #12065: connect_ex() on an SSL socket now returns the original errno + when the socket's timeout expires (it used to return None). + - Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 19:11:43 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 28 Dec 2012 19:11:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMi43IC0+IDMuMik6?= =?utf-8?q?_Forward_port_new_test_for_SSLSocket=2Econnect=5Fex=28=29?= Message-ID: <3YXwwb3VqXzRwm@mail.python.org> http://hg.python.org/cpython/rev/ee8d999b6e05 changeset: 81129:ee8d999b6e05 branch: 3.2 parent: 81124:e4ea38a92c4d parent: 81128:3436769a7964 user: Antoine Pitrou date: Fri Dec 28 19:07:43 2012 +0100 summary: Forward port new test for SSLSocket.connect_ex() files: Lib/test/test_ssl.py | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -558,6 +558,17 @@ finally: s.close() + def test_connect_ex_error(self): + 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(errno.ECONNREFUSED, + s.connect_ex(("svn.python.org", 444))) + 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 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 19:11:44 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 28 Dec 2012 19:11:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Forward_port_new_test_for_SSLSocket=2Econnect=5Fex=28=29?= Message-ID: <3YXwwc5vRkzRwb@mail.python.org> http://hg.python.org/cpython/rev/e0761560d844 changeset: 81130:e0761560d844 branch: 3.3 parent: 81125:157ff02bcc16 parent: 81129:ee8d999b6e05 user: Antoine Pitrou date: Fri Dec 28 19:08:49 2012 +0100 summary: Forward port new test for SSLSocket.connect_ex() files: Lib/test/test_ssl.py | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -714,6 +714,17 @@ finally: s.close() + def test_connect_ex_error(self): + 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(errno.ECONNREFUSED, + s.connect_ex(("svn.python.org", 444))) + 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 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Dec 28 19:11:46 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 28 Dec 2012 19:11:46 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Forward_port_new_test_for_SSLSocket=2Econnect=5Fex=28=29?= Message-ID: <3YXwwf1CLyzRwf@mail.python.org> http://hg.python.org/cpython/rev/5ef49659935f changeset: 81131:5ef49659935f parent: 81126:1b2134a78c17 parent: 81130:e0761560d844 user: Antoine Pitrou date: Fri Dec 28 19:09:41 2012 +0100 summary: Forward port new test for SSLSocket.connect_ex() files: Lib/test/test_ssl.py | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -714,6 +714,17 @@ finally: s.close() + def test_connect_ex_error(self): + 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(errno.ECONNREFUSED, + s.connect_ex(("svn.python.org", 444))) + 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 -- Repository URL: http://hg.python.org/cpython From tjreedy at udel.edu Fri Dec 28 21:07:44 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 28 Dec 2012 15:07:44 -0500 Subject: [Python-checkins] peps: PEP 432 updates in response to initial comments In-Reply-To: <3YXwF72ym4zP4V@mail.python.org> References: <3YXwF72ym4zP4V@mail.python.org> Message-ID: <50DDFC10.6070105@udel.edu> On 12/28/2012 12:40 PM, nick.coghlan wrote: > +The randomised hashing is controlled via the ``-R`` command line option (in > +releases prior to 3.3), as well as the ``PYTHONHASHSEED`` environment > +variable. > +(Note: on Python versions prior to 3.3, the last command won't have the > +desired effect, as the explicit import of the site module will still make Are you planning to backport to such releases, or do you only mention such facts to explain to those who know them why they are not relevant to changing 3.4 (and 3.3?). From tjreedy at udel.edu Fri Dec 28 20:54:55 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 28 Dec 2012 14:54:55 -0500 Subject: [Python-checkins] peps: PEP 432 updates in response to initial comments In-Reply-To: <3YXwF72ym4zP4V@mail.python.org> References: <3YXwF72ym4zP4V@mail.python.org> Message-ID: <50DDF90F.3040008@udel.edu> On 12/28/2012 12:40 PM, nick.coghlan wrote: > + python3 -m timeit -s "from subprocess import call" "call(['./python', '-c', 'pass'])" For anyone tempted to try this interactively, note: 1. timeit will automatically determine the number of repetitions only when the command-line interface is used. 2. the default for interactive calls is number=1000000. 3. With IDLE 3.3 on Win7, I could *not* interrupt a timing with ^C. Fortunately, I was cautious and started with number=3, then 10. ">>> repeat("call(['./python', '-c', 'pass'])", "from subprocess import call", number = 10) [0.7689384926673313, 0.7469100621030975, 0.731362154923886] Result: about .075 seconds on average running from a solid state disk. Each call flashes an interactive window, so don't watch if strobing disturbs you. 4. Running ./python_d from within a PCBuild/python_d interactive window and on a regular disk averages .10 seconds. The slowdown is probably a mixture of disk access and extra debug code, but is not bad. There is no flashing (probably because there already is a window, whereas on Windows IDLE runs code within a windowless pythonw process) and ^C works. This is definitely a better environment for this type of test ;-). Terry From python-checkins at python.org Sat Dec 29 01:48:47 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 29 Dec 2012 01:48:47 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Amend_the_collapsing_the_lead?= =?utf-8?q?ing_slashes_to_account_for_the_POSIX_special_case?= Message-ID: <3YY5kl40RkzRx2@mail.python.org> http://hg.python.org/peps/rev/6813e83ee36c changeset: 4639:6813e83ee36c user: Antoine Pitrou date: Sat Dec 29 01:46:48 2012 +0100 summary: Amend the collapsing the leading slashes to account for the POSIX special case of two leading slashes. Thanks to Daniel Colascione for noticing. files: pep-0428.txt | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pep-0428.txt b/pep-0428.txt --- a/pep-0428.txt +++ b/pep-0428.txt @@ -292,19 +292,29 @@ PurePosixPath('a/../b') Multiple leading slashes are treated differently depending on the path -flavour:: +flavour. They are always retained on Windows paths (because of the UNC +notation):: - >>> PurePosixPath('//some/path') - PurePosixPath('/some/path') >>> PureNTPath('//some/path') PureNTPath('\\\\some\\path\\') +On POSIX, they are collapsed except if there are exactly two leading slashes, +which is a special case in the POSIX specification on `pathname resolution`_ +(this is also necessary for Cygwin compatibility):: + + >>> PurePosixPath('///some/path') + PurePosixPath('/some/path') + >>> PurePosixPath('//some/path') + PurePosixPath('//some/path') + Calling the constructor without any argument creates a path object pointing to the logical "current directory":: >>> PurePosixPath() PurePosixPath('.') +.. _pathname resolution: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 + Representing ------------ -- Repository URL: http://hg.python.org/peps From solipsis at pitrou.net Sat Dec 29 05:56:51 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 29 Dec 2012 05:56:51 +0100 Subject: [Python-checkins] Daily reference leaks (5ef49659935f): sum=0 Message-ID: results for 5ef49659935f on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogxgesic', '-x'] From python-checkins at python.org Sat Dec 29 09:56:27 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 29 Dec 2012 09:56:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_More_PEP_432_updates?= Message-ID: <3YYJYR3NVQzRyK@mail.python.org> http://hg.python.org/peps/rev/6113dc3c8ca2 changeset: 4640:6113dc3c8ca2 user: Nick Coghlan date: Sat Dec 29 18:55:47 2012 +1000 summary: More PEP 432 updates - avoid "-m site" when describing how to explore sys.path - provide example startup times for 2.7, 3.2 and 3.3 on my system - misc notes on things to be documented about the status quo files: pep-0432.txt | 80 ++++++++++++++++++++++++++++------------ 1 files changed, 56 insertions(+), 24 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -124,9 +124,33 @@ python3 -m timeit -s "from subprocess import call" "call(['./python', '-c', 'pass'])" -If this simple check suggests that any changes may pose a performance -problem, then a more sophisticated microbenchmark will be developed to assist -in investigation. +Current numbers on my system for 2.7, 3.2 and 3.3 (using the 3.3 +subprocess and timeit modules to execute the check, all with non-debug +builds):: + + # Python 2.7 + $ py33/python -m timeit -s "from subprocess import call" "call(['py27/python', '-c', 'pass'])" + 100 loops, best of 3: 17.8 msec per loop + # Python 3.2 + $ py33/python -m timeit -s "from subprocess import call" "call(['py32/python', '-c', 'pass'])" + 10 loops, best of 3: 39 msec per loop + # Python 3.3 + $ py33/python -m timeit -s "from subprocess import call" "call(['py33/python', '-c', 'pass'])" + 10 loops, best of 3: 25.3 msec per loop + +Improvements in the import system and the Unicode support already resulted +in a more than 30% improvement in startup time in Python 3.3 relative to +3.2. Python 3.3 is still slightly slower to start than Python 2.7 due to the +additional infrastructure that needs to be put in place to support the Unicode +based text model. + +This PEP is not expected to have any significant effect on the startup time, +as it is aimed primarily at *reordering* the existing initialisation +sequence, without making substantial changes to the individual steps. + +However, if this simple check suggests that the proposed changes to the +initialisation sequence may pose a performance problem, then a more +sophisticated microbenchmark will be developed to assist in investigation. Required Configuration Settings @@ -151,7 +175,7 @@ * ``sys.getfsencoding`` * ``os.fsencode`` * ``os.fsdecode`` -* The IO encoding used by: +* The IO encoding (if any) and the buffering used by: * ``sys.stdin`` * ``sys.stdout`` * ``sys.stderr`` @@ -297,20 +321,21 @@ can control this by setting the ``Py_NoUserSiteDirectory`` global variable. The following commands can be used to check the default path configurations -for a given Python executable on a given system (after passing the entries -through ``os.path.abspath``): +for a given Python executable on a given system: -* ``./python -m site`` - standard configuration -* ``./python -s -m site`` - user site directory disabled -* ``./python -S -m site`` - all site path modifications disabled +* ``./python -c "import sys, pprint; pprint.pprint(sys.path)"`` + - standard configuration +* ``./python -s -c "import sys, pprint; pprint.pprint(sys.path)"`` + - user site directory disabled +* ``./python -S -c "import sys, pprint; pprint.pprint(sys.path)"`` + - all site path modifications disabled -(Note: on Python versions prior to 3.3, the last command won't have the -desired effect, as the explicit import of the site module will still make -the implicit path modifications that should have been disabled by the ``-S`` -option. The command -``./python -S -c "import sys, pprint; pprint.pprint(sys.path)"`` will -display the desired information. That command can also be used to see -the raw path entries without the ``os.path.abspath`` calls) +(Note: you can see similar information using ``-m site`` instead of ``-c``, +but this is slightly misleading as it calls ``os.abspath`` on all of the +path entries (making relative path entries look absolute), and also causes +problems in the last case, as on Python versions prior to 3.3, explicitly +importing site will carry out the path modifications ``-S`` avoids, while on +3.3+ combining ``-m site`` with ``-S`` currently fails) The calculation of ``sys.path[0]`` is comparatively straightforward: @@ -365,18 +390,22 @@ * The initial warning system state: * ``sys.warnoptions`` + * (-W option, PYTHONWARNINGS) * Arbitrary extended options (e.g. to automatically enable ``faulthandler``): * ``sys._xoptions`` + * (-X option) * The filesystem encoding used by: * ``sys.getfsencoding`` * ``os.fsencode`` * ``os.fsdecode`` -* The IO encoding used by: +* The IO encoding and buffering used by: * ``sys.stdin`` * ``sys.stdout`` * ``sys.stderr`` + * (-u option, PYTHONIOENCODING, PYTHONUNBUFFEREDIO) * Whether or not to implicitly cache bytecode files: * ``sys.dont_write_bytecode`` + * (-B option, PYTHONDONTWRITEBYTECODE) * Whether or not to enforce correct case in filenames on case-insensitive platforms * ``os.environ["PYTHONCASEOK"]`` @@ -400,15 +429,15 @@ global variables:: Py_BytesWarningFlag - Py_DebugFlag - Py_InspectFlag + Py_DebugFlag (-d option) + Py_InspectFlag (-i option, PYTHONINSPECT) Py_InteractiveFlag - Py_OptimizeFlag - Py_DontWriteBytecodeFlag - Py_NoUserSiteDirectory - Py_NoSiteFlag + Py_OptimizeFlag (-O option, PYTHONOPTIMIZE) + Py_DontWriteBytecodeFlag (-B option, PYTHONDONTWRITEBYTECODE) + Py_NoUserSiteDirectory (-s option, PYTHONNOUSERSITE) + Py_NoSiteFlag (-S option) Py_UnbufferedStdioFlag - Py_VerboseFlag + Py_VerboseFlag (-v option, PYTHONVERBOSE) For the above variables, the conversion of command line options and environment variables to C global variables is handled by ``Py_Main``, @@ -428,6 +457,9 @@ banner) is triggered only when standard input is reported as a terminal connection by the operating system. +TBD: Document how the "-x" option is handled (skips processing of the +first comment line in the main script) + Also see detailed sequence of operations notes at [1_] -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Dec 29 20:00:48 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 20:00:48 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NjQy?= =?utf-8?q?=3A_Document_kwargs_field_in_sched=2EEvent_named_tuple=2E?= Message-ID: <3YYYym0HZTzRwP@mail.python.org> http://hg.python.org/cpython/rev/5db0833f135b changeset: 81132:5db0833f135b branch: 3.3 parent: 81130:e0761560d844 user: Serhiy Storchaka date: Sat Dec 29 20:57:52 2012 +0200 summary: Issue #16642: Document kwargs field in sched.Event named tuple. files: Doc/library/sched.rst | 3 ++- Lib/sched.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/sched.rst b/Doc/library/sched.rst --- a/Doc/library/sched.rst +++ b/Doc/library/sched.rst @@ -27,6 +27,7 @@ .. versionchanged:: 3.3 *timefunc* and *delayfunc* parameters are optional. + .. versionchanged:: 3.3 :class:`scheduler` class can be safely used in multi-threaded environments. @@ -129,4 +130,4 @@ Read-only attribute returning a list of upcoming events in the order they will be run. Each event is shown as a :term:`named tuple` with the - following fields: time, priority, action, argument. + following fields: time, priority, action, argument, kwargs. diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -13,12 +13,12 @@ function is allowed to modify the queue. Time can be expressed as integers or floating point numbers, as long as it is consistent. -Events are specified by tuples (time, priority, action, argument). +Events are specified by tuples (time, priority, action, argument, kwargs). As in UNIX, lower priority numbers mean higher priority; in this way the queue can be maintained as a priority queue. Execution of the event means calling the action function, passing it the argument sequence in "argument" (remember that in Python, multiple function -arguments are be packed in a sequence). +arguments are be packed in a sequence) and keyword parameters in "kwargs". The action function may be an instance method so it has another way to reference private data (besides global variables). """ @@ -151,7 +151,7 @@ """An ordered list of upcoming events. Events are named tuples with fields for: - time, priority, action, arguments + time, priority, action, arguments, kwargs """ # Use heapq to sort the queue rather than using 'sorted(self._queue)'. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 20:00:49 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 20:00:49 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316642=3A_Document_kwargs_field_in_sched=2EEvent?= =?utf-8?q?_named_tuple=2E?= Message-ID: <3YYYyn2dZwzNvf@mail.python.org> http://hg.python.org/cpython/rev/cf6425df1cb8 changeset: 81133:cf6425df1cb8 parent: 81131:5ef49659935f parent: 81132:5db0833f135b user: Serhiy Storchaka date: Sat Dec 29 20:59:29 2012 +0200 summary: Issue #16642: Document kwargs field in sched.Event named tuple. files: Doc/library/sched.rst | 3 ++- Lib/sched.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/sched.rst b/Doc/library/sched.rst --- a/Doc/library/sched.rst +++ b/Doc/library/sched.rst @@ -27,6 +27,7 @@ .. versionchanged:: 3.3 *timefunc* and *delayfunc* parameters are optional. + .. versionchanged:: 3.3 :class:`scheduler` class can be safely used in multi-threaded environments. @@ -129,4 +130,4 @@ Read-only attribute returning a list of upcoming events in the order they will be run. Each event is shown as a :term:`named tuple` with the - following fields: time, priority, action, argument. + following fields: time, priority, action, argument, kwargs. diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -13,12 +13,12 @@ function is allowed to modify the queue. Time can be expressed as integers or floating point numbers, as long as it is consistent. -Events are specified by tuples (time, priority, action, argument). +Events are specified by tuples (time, priority, action, argument, kwargs). As in UNIX, lower priority numbers mean higher priority; in this way the queue can be maintained as a priority queue. Execution of the event means calling the action function, passing it the argument sequence in "argument" (remember that in Python, multiple function -arguments are be packed in a sequence). +arguments are be packed in a sequence) and keyword parameters in "kwargs". The action function may be an instance method so it has another way to reference private data (besides global variables). """ @@ -151,7 +151,7 @@ """An ordered list of upcoming events. Events are named tuples with fields for: - time, priority, action, arguments + time, priority, action, arguments, kwargs """ # Use heapq to sort the queue rather than using 'sorted(self._queue)'. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 20:17:07 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 20:17:07 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2NjQx?= =?utf-8?q?=3A_Fix_default_values_of_sched=2Escheduler=2Eenter_arguments_w?= =?utf-8?q?ere?= Message-ID: <3YYZKb2NQLzRw2@mail.python.org> http://hg.python.org/cpython/rev/1c9c0f92df65 changeset: 81134:1c9c0f92df65 branch: 3.3 parent: 81132:5db0833f135b user: Serhiy Storchaka date: Sat Dec 29 21:13:45 2012 +0200 summary: Issue #16641: Fix default values of sched.scheduler.enter arguments were modifiable. files: Doc/library/sched.rst | 23 ++++++++++++++--------- Lib/sched.py | 8 ++++++-- Misc/NEWS | 3 +++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Doc/library/sched.rst b/Doc/library/sched.rst --- a/Doc/library/sched.rst +++ b/Doc/library/sched.rst @@ -36,19 +36,22 @@ >>> import sched, time >>> s = sched.scheduler(time.time, time.sleep) - >>> def print_time(): print("From print_time", time.time()) + >>> def print_time(a='default'): + ... print("From print_time", time.time(), a) ... >>> def print_some_times(): ... print(time.time()) - ... s.enter(5, 1, print_time, ()) - ... s.enter(10, 1, print_time, ()) + ... s.enter(10, 1, print_time) + ... s.enter(5, 2, print_time, argument=('positional',)) + ... s.enter(5, 1, print_time, kwargs={'a': 'keyword'}) ... s.run() ... print(time.time()) ... >>> print_some_times() 930343690.257 - From print_time 930343695.274 - From print_time 930343700.273 + From print_time 930343695.274 positional + From print_time 930343695.275 keyword + From print_time 930343700.273 default 930343700.276 .. _scheduler-objects: @@ -59,7 +62,7 @@ :class:`scheduler` instances have the following methods and attributes: -.. method:: scheduler.enterabs(time, priority, action, argument=[], kwargs={}) +.. method:: scheduler.enterabs(time, priority, action, argument=(), kwargs={}) Schedule a new event. The *time* argument should be a numeric type compatible with the return value of the *timefunc* function passed to the constructor. @@ -67,8 +70,10 @@ *priority*. Executing the event means executing ``action(*argument, **kwargs)``. - *argument* must be a sequence holding the parameters for *action*. - *kwargs* must be a dictionary holding the keyword parameters for *action*. + Optional *argument* argument must be a sequence holding the parameters + for *action* if any used. + Optional *kwargs* argument must be a dictionary holding the keyword + parameters for *action* if any used. Return value is an event which may be used for later cancellation of the event (see :meth:`cancel`). @@ -80,7 +85,7 @@ *kwargs* parameter was added. -.. method:: scheduler.enter(delay, priority, action, argument=[], kwargs={}) +.. method:: scheduler.enter(delay, priority, action, argument=(), kwargs={}) Schedule an event for *delay* more time units. Other than the relative time, the other arguments, the effect and the return value are the same as those for diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -50,6 +50,8 @@ def __gt__(s, o): return (s.time, s.priority) > (o.time, o.priority) def __ge__(s, o): return (s.time, s.priority) >= (o.time, o.priority) +_sentinel = object() + class scheduler: def __init__(self, timefunc=_time, delayfunc=time.sleep): @@ -60,19 +62,21 @@ self.timefunc = timefunc self.delayfunc = delayfunc - def enterabs(self, time, priority, action, argument=[], kwargs={}): + def enterabs(self, time, priority, action, argument=(), kwargs=_sentinel): """Enter a new event in the queue at an absolute time. Returns an ID for the event which can be used to remove it, if necessary. """ + if kwargs is _sentinel: + kwargs = {} with self._lock: event = Event(time, priority, action, argument, kwargs) heapq.heappush(self._queue, event) return event # The ID - def enter(self, delay, priority, action, argument=[], kwargs={}): + def enter(self, delay, priority, action, argument=(), kwargs=_sentinel): """A variant that specifies the time as a relative time. This is actually the more commonly used interface. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,9 @@ Library ------- +- Issue #16641: Fix default values of sched.scheduler.enter arguments were + modifiable. + - Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 20:17:08 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 20:17:08 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316641=3A_Fix_default_values_of_sched=2Eschedule?= =?utf-8?q?r=2Eenter_arguments_were?= Message-ID: <3YYZKc6GlLzRwK@mail.python.org> http://hg.python.org/cpython/rev/e22ebc34a8eb changeset: 81135:e22ebc34a8eb parent: 81133:cf6425df1cb8 parent: 81134:1c9c0f92df65 user: Serhiy Storchaka date: Sat Dec 29 21:15:24 2012 +0200 summary: Issue #16641: Fix default values of sched.scheduler.enter arguments were modifiable. files: Doc/library/sched.rst | 23 ++++++++++++++--------- Lib/sched.py | 8 ++++++-- Misc/NEWS | 3 +++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Doc/library/sched.rst b/Doc/library/sched.rst --- a/Doc/library/sched.rst +++ b/Doc/library/sched.rst @@ -36,19 +36,22 @@ >>> import sched, time >>> s = sched.scheduler(time.time, time.sleep) - >>> def print_time(): print("From print_time", time.time()) + >>> def print_time(a='default'): + ... print("From print_time", time.time(), a) ... >>> def print_some_times(): ... print(time.time()) - ... s.enter(5, 1, print_time, ()) - ... s.enter(10, 1, print_time, ()) + ... s.enter(10, 1, print_time) + ... s.enter(5, 2, print_time, argument=('positional',)) + ... s.enter(5, 1, print_time, kwargs={'a': 'keyword'}) ... s.run() ... print(time.time()) ... >>> print_some_times() 930343690.257 - From print_time 930343695.274 - From print_time 930343700.273 + From print_time 930343695.274 positional + From print_time 930343695.275 keyword + From print_time 930343700.273 default 930343700.276 .. _scheduler-objects: @@ -59,7 +62,7 @@ :class:`scheduler` instances have the following methods and attributes: -.. method:: scheduler.enterabs(time, priority, action, argument=[], kwargs={}) +.. method:: scheduler.enterabs(time, priority, action, argument=(), kwargs={}) Schedule a new event. The *time* argument should be a numeric type compatible with the return value of the *timefunc* function passed to the constructor. @@ -67,8 +70,10 @@ *priority*. Executing the event means executing ``action(*argument, **kwargs)``. - *argument* must be a sequence holding the parameters for *action*. - *kwargs* must be a dictionary holding the keyword parameters for *action*. + Optional *argument* argument must be a sequence holding the parameters + for *action* if any used. + Optional *kwargs* argument must be a dictionary holding the keyword + parameters for *action* if any used. Return value is an event which may be used for later cancellation of the event (see :meth:`cancel`). @@ -80,7 +85,7 @@ *kwargs* parameter was added. -.. method:: scheduler.enter(delay, priority, action, argument=[], kwargs={}) +.. method:: scheduler.enter(delay, priority, action, argument=(), kwargs={}) Schedule an event for *delay* more time units. Other than the relative time, the other arguments, the effect and the return value are the same as those for diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -50,6 +50,8 @@ def __gt__(s, o): return (s.time, s.priority) > (o.time, o.priority) def __ge__(s, o): return (s.time, s.priority) >= (o.time, o.priority) +_sentinel = object() + class scheduler: def __init__(self, timefunc=_time, delayfunc=time.sleep): @@ -60,19 +62,21 @@ self.timefunc = timefunc self.delayfunc = delayfunc - def enterabs(self, time, priority, action, argument=[], kwargs={}): + def enterabs(self, time, priority, action, argument=(), kwargs=_sentinel): """Enter a new event in the queue at an absolute time. Returns an ID for the event which can be used to remove it, if necessary. """ + if kwargs is _sentinel: + kwargs = {} with self._lock: event = Event(time, priority, action, argument, kwargs) heapq.heappush(self._queue, event) return event # The ID - def enter(self, delay, priority, action, argument=[], kwargs={}): + def enter(self, delay, priority, action, argument=(), kwargs=_sentinel): """A variant that specifies the time as a relative time. This is actually the more commonly used interface. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,9 @@ Library ------- +- Issue #16641: Fix default values of sched.scheduler.enter arguments were + modifiable. + - Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 20:36:38 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 20:36:38 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2MTY1?= =?utf-8?q?=3A_Fix_sched=2Escheduler=2Erun=28=29_method_was_block_a_schedu?= =?utf-8?q?ler_for?= Message-ID: <3YYZm63bhDzQxq@mail.python.org> http://hg.python.org/cpython/rev/467c46e312eb changeset: 81136:467c46e312eb branch: 3.3 parent: 81134:1c9c0f92df65 user: Serhiy Storchaka date: Sat Dec 29 21:34:11 2012 +0200 summary: Issue #16165: Fix sched.scheduler.run() method was block a scheduler for other threads. files: Lib/sched.py | 40 +++++++++++++++-------------- Lib/test/test_sched.py | 37 +++++++++++++++++++++++++++- Misc/NEWS | 3 ++ 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -128,27 +128,29 @@ """ # localize variable access to minimize overhead # and to improve thread safety - with self._lock: - q = self._queue - delayfunc = self.delayfunc - timefunc = self.timefunc - pop = heapq.heappop - while q: - time, priority, action, argument, kwargs = checked_event = q[0] + lock = self._lock + q = self._queue + delayfunc = self.delayfunc + timefunc = self.timefunc + pop = heapq.heappop + while True: + with lock: + if not q: + break + time, priority, action, argument, kwargs = q[0] now = timefunc() - if now < time: - if not blocking: - return time - now - delayfunc(time - now) + if time > now: + delay = True else: - event = pop(q) - # Verify that the event was not removed or altered - # by another thread after we last looked at q[0]. - if event is checked_event: - action(*argument, **kwargs) - delayfunc(0) # Let other threads run - else: - heapq.heappush(q, event) + delay = False + pop(q) + if delay: + if not blocking: + return time - now + delayfunc(time - now) + else: + action(*argument, **kwargs) + delayfunc(0) # Let other threads run @property def queue(self): diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py --- a/Lib/test/test_sched.py +++ b/Lib/test/test_sched.py @@ -4,7 +4,10 @@ import time import unittest from test import support - +try: + import threading +except ImportError: + threading = None class TestCase(unittest.TestCase): @@ -26,6 +29,20 @@ scheduler.run() self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05]) + @unittest.skipUnless(threading, 'Threading required for this test.') + def test_enter_concurrent(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + scheduler.enter(0.03, 1, fun, (0.03,)) + t = threading.Thread(target=scheduler.run) + t.start() + for x in [0.05, 0.04, 0.02, 0.01]: + z = scheduler.enter(x, 1, fun, (x,)) + scheduler.run() + t.join() + self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05]) + def test_priority(self): l = [] fun = lambda x: l.append(x) @@ -50,6 +67,24 @@ scheduler.run() self.assertEqual(l, [0.02, 0.03, 0.04]) + @unittest.skipUnless(threading, 'Threading required for this test.') + def test_cancel_concurrent(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + now = time.time() + event1 = scheduler.enterabs(now + 0.01, 1, fun, (0.01,)) + event2 = scheduler.enterabs(now + 0.02, 1, fun, (0.02,)) + event3 = scheduler.enterabs(now + 0.03, 1, fun, (0.03,)) + event4 = scheduler.enterabs(now + 0.04, 1, fun, (0.04,)) + event5 = scheduler.enterabs(now + 0.05, 1, fun, (0.05,)) + t = threading.Thread(target=scheduler.run) + t.start() + scheduler.cancel(event1) + scheduler.cancel(event5) + t.join() + self.assertEqual(l, [0.02, 0.03, 0.04]) + def test_empty(self): l = [] fun = lambda x: l.append(x) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,9 @@ Library ------- +- Issue #16165: Fix sched.scheduler.run() method was block a scheduler for + other threads. + - Issue #16641: Fix default values of sched.scheduler.enter arguments were modifiable. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 20:36:40 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 20:36:40 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316165=3A_Fix_sched=2Escheduler=2Erun=28=29_meth?= =?utf-8?q?od_was_block_a_scheduler_for?= Message-ID: <3YYZm80NqnzRw9@mail.python.org> http://hg.python.org/cpython/rev/ac919a281643 changeset: 81137:ac919a281643 parent: 81135:e22ebc34a8eb parent: 81136:467c46e312eb user: Serhiy Storchaka date: Sat Dec 29 21:35:37 2012 +0200 summary: Issue #16165: Fix sched.scheduler.run() method was block a scheduler for other threads. files: Lib/sched.py | 40 +++++++++++++++-------------- Lib/test/test_sched.py | 37 +++++++++++++++++++++++++++- Misc/NEWS | 3 ++ 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -128,27 +128,29 @@ """ # localize variable access to minimize overhead # and to improve thread safety - with self._lock: - q = self._queue - delayfunc = self.delayfunc - timefunc = self.timefunc - pop = heapq.heappop - while q: - time, priority, action, argument, kwargs = checked_event = q[0] + lock = self._lock + q = self._queue + delayfunc = self.delayfunc + timefunc = self.timefunc + pop = heapq.heappop + while True: + with lock: + if not q: + break + time, priority, action, argument, kwargs = q[0] now = timefunc() - if now < time: - if not blocking: - return time - now - delayfunc(time - now) + if time > now: + delay = True else: - event = pop(q) - # Verify that the event was not removed or altered - # by another thread after we last looked at q[0]. - if event is checked_event: - action(*argument, **kwargs) - delayfunc(0) # Let other threads run - else: - heapq.heappush(q, event) + delay = False + pop(q) + if delay: + if not blocking: + return time - now + delayfunc(time - now) + else: + action(*argument, **kwargs) + delayfunc(0) # Let other threads run @property def queue(self): diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py --- a/Lib/test/test_sched.py +++ b/Lib/test/test_sched.py @@ -4,7 +4,10 @@ import time import unittest from test import support - +try: + import threading +except ImportError: + threading = None class TestCase(unittest.TestCase): @@ -26,6 +29,20 @@ scheduler.run() self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05]) + @unittest.skipUnless(threading, 'Threading required for this test.') + def test_enter_concurrent(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + scheduler.enter(0.03, 1, fun, (0.03,)) + t = threading.Thread(target=scheduler.run) + t.start() + for x in [0.05, 0.04, 0.02, 0.01]: + z = scheduler.enter(x, 1, fun, (x,)) + scheduler.run() + t.join() + self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05]) + def test_priority(self): l = [] fun = lambda x: l.append(x) @@ -50,6 +67,24 @@ scheduler.run() self.assertEqual(l, [0.02, 0.03, 0.04]) + @unittest.skipUnless(threading, 'Threading required for this test.') + def test_cancel_concurrent(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + now = time.time() + event1 = scheduler.enterabs(now + 0.01, 1, fun, (0.01,)) + event2 = scheduler.enterabs(now + 0.02, 1, fun, (0.02,)) + event3 = scheduler.enterabs(now + 0.03, 1, fun, (0.03,)) + event4 = scheduler.enterabs(now + 0.04, 1, fun, (0.04,)) + event5 = scheduler.enterabs(now + 0.05, 1, fun, (0.05,)) + t = threading.Thread(target=scheduler.run) + t.start() + scheduler.cancel(event1) + scheduler.cancel(event5) + t.join() + self.assertEqual(l, [0.02, 0.03, 0.04]) + def test_empty(self): l = [] fun = lambda x: l.append(x) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,9 @@ Library ------- +- Issue #16165: Fix sched.scheduler.run() method was block a scheduler for + other threads. + - Issue #16641: Fix default values of sched.scheduler.enter arguments were modifiable. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 20:48:56 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 20:48:56 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316640=3A_Run_less?= =?utf-8?q?_code_under_a_lock_in_sched_module=2E?= Message-ID: <3YYb2J6F5yzRkb@mail.python.org> http://hg.python.org/cpython/rev/1bed43c0a5af changeset: 81138:1bed43c0a5af user: Serhiy Storchaka date: Sat Dec 29 21:46:37 2012 +0200 summary: Issue #16640: Run less code under a lock in sched module. files: Lib/sched.py | 11 +++++------ Misc/NEWS | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -71,10 +71,10 @@ """ if kwargs is _sentinel: kwargs = {} + event = Event(time, priority, action, argument, kwargs) with self._lock: - event = Event(time, priority, action, argument, kwargs) heapq.heappush(self._queue, event) - return event # The ID + return event # The ID def enter(self, delay, priority, action, argument=(), kwargs=_sentinel): """A variant that specifies the time as a relative time. @@ -82,9 +82,8 @@ This is actually the more commonly used interface. """ - with self._lock: - time = self.timefunc() + delay - return self.enterabs(time, priority, action, argument, kwargs) + time = self.timefunc() + delay + return self.enterabs(time, priority, action, argument, kwargs) def cancel(self, event): """Remove an event from the queue. @@ -165,4 +164,4 @@ # the actual order they would be retrieved. with self._lock: events = self._queue[:] - return map(heapq.heappop, [events]*len(events)) + return map(heapq.heappop, [events]*len(events)) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,8 @@ Library ------- +- Issue #16640: Run less code under a lock in sched module. + - Issue #16165: Fix sched.scheduler.run() method was block a scheduler for other threads. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 21:01:39 2012 From: python-checkins at python.org (chris.jerdonek) Date: Sat, 29 Dec 2012 21:01:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Issue_=2316813=3A_Use_the?= =?utf-8?q?_full_relative_path_in_the_documentation-building?= Message-ID: <3YYbJz3wFVzRwx@mail.python.org> http://hg.python.org/devguide/rev/20333d160f4e changeset: 582:20333d160f4e user: Chris Jerdonek date: Sat Dec 29 12:00:42 2012 -0800 summary: Issue #16813: Use the full relative path in the documentation-building instructions. Patch by Tshepang Lekhonkhobe. files: documenting.rst | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/documenting.rst b/documenting.rst --- a/documenting.rst +++ b/documenting.rst @@ -1646,9 +1646,10 @@ cd Doc make html -to check out the necessary toolset in the :file:`tools/` subdirectory and build -the HTML output files. To view the generated HTML, point your favorite browser -at the top-level index :file:`build/html/index.html` after running "make". +to check out the necessary toolset in the :file:`Doc/tools/` subdirectory and +build the HTML output files. To view the generated HTML, point your favorite +browser at the top-level index :file:`Doc/build/html/index.html` after running +:command:`make`. Available make targets are: -- Repository URL: http://hg.python.org/devguide From root at python.org Sat Dec 29 21:05:07 2012 From: root at python.org (Cron Daemon) Date: Sat, 29 Dec 2012 21:05:07 +0100 Subject: [Python-checkins] Cron /home/docs/build-devguide Message-ID: /home/docs/devguide/documenting.rst:768: WARNING: term not in glossary: bytecode From python-checkins at python.org Sat Dec 29 21:46:33 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 21:46:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NDg1?= =?utf-8?q?=3A_Fix_file_descriptor_not_being_closed_if_file_header_patchin?= =?utf-8?q?g?= Message-ID: <3YYcJn2gwHzRwD@mail.python.org> http://hg.python.org/cpython/rev/cf8d692cc847 changeset: 81139:cf8d692cc847 branch: 2.7 parent: 81128:3436769a7964 user: Serhiy Storchaka date: Sat Dec 29 22:25:59 2012 +0200 summary: Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. files: Lib/aifc.py | 38 +++++++++++++++++------------- Lib/test/test_aifc.py | 7 +++++ Misc/NEWS | 3 ++ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Lib/aifc.py b/Lib/aifc.py --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -732,22 +732,28 @@ self._patchheader() def close(self): - self._ensure_header_written(0) - if self._datawritten & 1: - # quick pad to even size - self._file.write(chr(0)) - self._datawritten = self._datawritten + 1 - self._writemarkers() - if self._nframeswritten != self._nframes or \ - self._datalength != self._datawritten or \ - self._marklength: - self._patchheader() - if self._comp: - self._comp.CloseCompressor() - self._comp = None - # Prevent ref cycles - self._convert = None - self._file.close() + if self._file is None: + return + try: + self._ensure_header_written(0) + if self._datawritten & 1: + # quick pad to even size + self._file.write(chr(0)) + self._datawritten = self._datawritten + 1 + self._writemarkers() + if self._nframeswritten != self._nframes or \ + self._datalength != self._datawritten or \ + self._marklength: + self._patchheader() + if self._comp: + self._comp.CloseCompressor() + self._comp = None + finally: + # Prevent ref cycles + self._convert = None + f = self._file + self._file = None + f.close() # # Internal methods. diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -106,6 +106,13 @@ self.assertEqual(testfile.closed, False) f.close() self.assertEqual(testfile.closed, True) + testfile = open(TESTFN, 'wb') + fout = aifc.open(testfile, 'wb') + self.assertFalse(testfile.closed) + with self.assertRaises(aifc.Error): + fout.close() + self.assertTrue(testfile.closed) + fout.close() # do nothing class AIFCLowLevelTest(unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -175,6 +175,9 @@ Library ------- +- Issue #16485: Fix file descriptor not being closed if file header patching + fails on closing of aifc file. + - Issue #12065: connect_ex() on an SSL socket now returns the original errno when the socket's timeout expires (it used to return None). -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 21:46:34 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 21:46:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NDg1?= =?utf-8?q?=3A_Fix_file_descriptor_not_being_closed_if_file_header_patchin?= =?utf-8?q?g?= Message-ID: <3YYcJp58F8zRx4@mail.python.org> http://hg.python.org/cpython/rev/e3c4e9f4ea0f changeset: 81140:e3c4e9f4ea0f branch: 3.2 parent: 81129:ee8d999b6e05 user: Serhiy Storchaka date: Sat Dec 29 22:30:56 2012 +0200 summary: Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. files: Lib/aifc.py | 8 ++++++-- Lib/test/test_aifc.py | 11 ++++++++++- Misc/NEWS | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Lib/aifc.py b/Lib/aifc.py --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -692,7 +692,9 @@ self._patchheader() def close(self): - if self._file: + if self._file is None: + return + try: self._ensure_header_written(0) if self._datawritten & 1: # quick pad to even size @@ -703,10 +705,12 @@ self._datalength != self._datawritten or \ self._marklength: self._patchheader() + finally: # Prevent ref cycles self._convert = None - self._file.close() + f = self._file self._file = None + f.close() # # Internal methods. diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -112,6 +112,13 @@ self.assertEqual(testfile.closed, False) f.close() self.assertEqual(testfile.closed, True) + testfile = open(TESTFN, 'wb') + fout = aifc.open(testfile, 'wb') + self.assertFalse(testfile.closed) + with self.assertRaises(aifc.Error): + fout.close() + self.assertTrue(testfile.closed) + fout.close() # do nothing def test_write_header_comptype_sampwidth(self): for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): @@ -291,11 +298,13 @@ def test_write_header_raises(self): fout = aifc.open(io.BytesIO(), 'wb') self.assertRaises(aifc.Error, fout.close) + fout = aifc.open(io.BytesIO(), 'wb') fout.setnchannels(1) self.assertRaises(aifc.Error, fout.close) + fout = aifc.open(io.BytesIO(), 'wb') + fout.setnchannels(1) fout.setsampwidth(1) self.assertRaises(aifc.Error, fout.close) - fout.initfp(None) def test_write_header_comptype_raises(self): for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -189,6 +189,9 @@ Library ------- +- Issue #16485: Fix file descriptor not being closed if file header patching + fails on closing of aifc file. + - Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 21:46:36 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 21:46:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316485=3A_Fix_file_descriptor_not_being_closed_if_file?= =?utf-8?q?_header_patching?= Message-ID: <3YYcJr0XP2zRx4@mail.python.org> http://hg.python.org/cpython/rev/9a571c4a16d1 changeset: 81141:9a571c4a16d1 branch: 3.3 parent: 81136:467c46e312eb parent: 81140:e3c4e9f4ea0f user: Serhiy Storchaka date: Sat Dec 29 22:36:23 2012 +0200 summary: Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. files: Lib/aifc.py | 8 ++++++-- Lib/test/test_aifc.py | 11 ++++++++++- Misc/NEWS | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Lib/aifc.py b/Lib/aifc.py --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -692,7 +692,9 @@ self._patchheader() def close(self): - if self._file: + if self._file is None: + return + try: self._ensure_header_written(0) if self._datawritten & 1: # quick pad to even size @@ -703,10 +705,12 @@ self._datalength != self._datawritten or \ self._marklength: self._patchheader() + finally: # Prevent ref cycles self._convert = None - self._file.close() + f = self._file self._file = None + f.close() # # Internal methods. diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -112,6 +112,13 @@ self.assertEqual(testfile.closed, False) f.close() self.assertEqual(testfile.closed, True) + testfile = open(TESTFN, 'wb') + fout = aifc.open(testfile, 'wb') + self.assertFalse(testfile.closed) + with self.assertRaises(aifc.Error): + fout.close() + self.assertTrue(testfile.closed) + fout.close() # do nothing def test_write_header_comptype_sampwidth(self): for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): @@ -286,11 +293,13 @@ def test_write_header_raises(self): fout = aifc.open(io.BytesIO(), 'wb') self.assertRaises(aifc.Error, fout.close) + fout = aifc.open(io.BytesIO(), 'wb') fout.setnchannels(1) self.assertRaises(aifc.Error, fout.close) + fout = aifc.open(io.BytesIO(), 'wb') + fout.setnchannels(1) fout.setsampwidth(1) self.assertRaises(aifc.Error, fout.close) - fout.initfp(None) def test_write_header_comptype_raises(self): for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,9 @@ Library ------- +- Issue #16485: Fix file descriptor not being closed if file header patching + fails on closing of aifc file. + - Issue #16165: Fix sched.scheduler.run() method was block a scheduler for other threads. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 21:46:37 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 21:46:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316485=3A_Fix_file_descriptor_not_being_closed_i?= =?utf-8?q?f_file_header_patching?= Message-ID: <3YYcJs2xVqzRxM@mail.python.org> http://hg.python.org/cpython/rev/79a8f6e1dfb0 changeset: 81142:79a8f6e1dfb0 parent: 81138:1bed43c0a5af parent: 81141:9a571c4a16d1 user: Serhiy Storchaka date: Sat Dec 29 22:38:37 2012 +0200 summary: Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. files: Lib/aifc.py | 8 ++++++-- Lib/test/test_aifc.py | 11 ++++++++++- Misc/NEWS | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Lib/aifc.py b/Lib/aifc.py --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -692,7 +692,9 @@ self._patchheader() def close(self): - if self._file: + if self._file is None: + return + try: self._ensure_header_written(0) if self._datawritten & 1: # quick pad to even size @@ -703,10 +705,12 @@ self._datalength != self._datawritten or \ self._marklength: self._patchheader() + finally: # Prevent ref cycles self._convert = None - self._file.close() + f = self._file self._file = None + f.close() # # Internal methods. diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -112,6 +112,13 @@ self.assertEqual(testfile.closed, False) f.close() self.assertEqual(testfile.closed, True) + testfile = open(TESTFN, 'wb') + fout = aifc.open(testfile, 'wb') + self.assertFalse(testfile.closed) + with self.assertRaises(aifc.Error): + fout.close() + self.assertTrue(testfile.closed) + fout.close() # do nothing def test_write_header_comptype_sampwidth(self): for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): @@ -286,11 +293,13 @@ def test_write_header_raises(self): fout = aifc.open(io.BytesIO(), 'wb') self.assertRaises(aifc.Error, fout.close) + fout = aifc.open(io.BytesIO(), 'wb') fout.setnchannels(1) self.assertRaises(aifc.Error, fout.close) + fout = aifc.open(io.BytesIO(), 'wb') + fout.setnchannels(1) fout.setsampwidth(1) self.assertRaises(aifc.Error, fout.close) - fout.initfp(None) def test_write_header_comptype_raises(self): for comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,9 @@ Library ------- +- Issue #16485: Fix file descriptor not being closed if file header patching + fails on closing of aifc file. + - Issue #16640: Run less code under a lock in sched module. - Issue #16165: Fix sched.scheduler.run() method was block a scheduler for -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 21:56:00 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 21:56:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2316486=3A_Make_aif?= =?utf-8?q?c_files_work_with_=27with=27_as_context_managers=2E?= Message-ID: <3YYcWh2W4yzRyF@mail.python.org> http://hg.python.org/cpython/rev/9beb11071dd1 changeset: 81143:9beb11071dd1 user: Serhiy Storchaka date: Sat Dec 29 22:54:49 2012 +0200 summary: Issue #16486: Make aifc files work with 'with' as context managers. files: Doc/library/aifc.rst | 4 ++++ Lib/aifc.py | 12 ++++++++++++ Lib/test/test_aifc.py | 12 ++++++++++++ Misc/NEWS | 2 ++ 4 files changed, 30 insertions(+), 0 deletions(-) diff --git a/Doc/library/aifc.rst b/Doc/library/aifc.rst --- a/Doc/library/aifc.rst +++ b/Doc/library/aifc.rst @@ -51,6 +51,10 @@ used for writing, the file object should be seekable, unless you know ahead of time how many samples you are going to write in total and use :meth:`writeframesraw` and :meth:`setnframes`. + Objects returned by :func:`.open` also supports the :keyword:`with` statement. + +.. versionchanged:: 3.4 + Support for the :keyword:`with` statement was added. Objects returned by :func:`.open` when a file is opened for reading have the following methods: diff --git a/Lib/aifc.py b/Lib/aifc.py --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -334,6 +334,12 @@ # else, assume it is an open file object already self.initfp(f) + def __enter__(self): + return self + + def __exit__(self, *args): + self.close() + # # User visible methods. # @@ -553,6 +559,12 @@ def __del__(self): self.close() + def __enter__(self): + return self + + def __exit__(self, *args): + self.close() + # # User visible methods. # diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -43,6 +43,18 @@ (2, 2, 48000, 14400, b'NONE', b'not compressed'), ) + def test_context_manager(self): + with open(self.sndfilepath, 'rb') as testfile: + with aifc.open(testfile) as f: + pass + self.assertEqual(testfile.closed, True) + with open(TESTFN, 'wb') as testfile: + with self.assertRaises(aifc.Error): + with aifc.open(testfile, 'wb') as fout: + pass + self.assertEqual(testfile.closed, True) + fout.close() # do nothing + def test_read(self): f = self.f = aifc.open(self.sndfilepath) self.assertEqual(f.readframes(0), b'') diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,8 @@ Library ------- +- Issue #16486: Make aifc files work with 'with' as context managers. + - Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 22:11:32 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 29 Dec 2012 22:11:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_docstring_?= =?utf-8?q?in_curses_=28=2316782=29?= Message-ID: <3YYcsc0njJzP0M@mail.python.org> http://hg.python.org/cpython/rev/cbee422ca727 changeset: 81144:cbee422ca727 branch: 3.2 parent: 81140:e3c4e9f4ea0f user: Andrew Svetlov date: Sat Dec 29 23:07:50 2012 +0200 summary: Fix docstring in curses (#16782) files: Lib/curses/__init__.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -5,7 +5,7 @@ import curses from curses import textpad - curses.initwin() + curses.initscr() ... """ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 22:11:33 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 29 Dec 2012 22:11:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Fix_docstring_in_curses_=28=2316782=29?= Message-ID: <3YYcsd3WjSzRnh@mail.python.org> http://hg.python.org/cpython/rev/e9cbe583156f changeset: 81145:e9cbe583156f branch: 3.3 parent: 81141:9a571c4a16d1 parent: 81144:cbee422ca727 user: Andrew Svetlov date: Sat Dec 29 23:08:07 2012 +0200 summary: Fix docstring in curses (#16782) files: Lib/curses/__init__.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -5,7 +5,7 @@ import curses from curses import textpad - curses.initwin() + curses.initscr() ... """ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 22:11:34 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 29 Dec 2012 22:11:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_docstring_in_curses_=28=2316782=29?= Message-ID: <3YYcsf5v0qzRxf@mail.python.org> http://hg.python.org/cpython/rev/2cae7bde45ef changeset: 81146:2cae7bde45ef parent: 81142:79a8f6e1dfb0 parent: 81145:e9cbe583156f user: Andrew Svetlov date: Sat Dec 29 23:09:08 2012 +0200 summary: Fix docstring in curses (#16782) files: Lib/curses/__init__.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -5,7 +5,7 @@ import curses from curses import textpad - curses.initwin() + curses.initscr() ... """ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 22:11:36 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 29 Dec 2012 22:11:36 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_docstring_?= =?utf-8?q?in_curses_=28=2316782=29?= Message-ID: <3YYcsh1685zRyD@mail.python.org> http://hg.python.org/cpython/rev/52900f205e6e changeset: 81147:52900f205e6e branch: 2.7 parent: 81139:cf8d692cc847 user: Andrew Svetlov date: Sat Dec 29 23:09:32 2012 +0200 summary: Fix docstring in curses (#16782) files: Lib/curses/__init__.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -5,7 +5,7 @@ import curses from curses import textpad - curses.initwin() + curses.initscr() ... """ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 22:11:37 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 29 Dec 2012 22:11:37 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3YYcsj3Zp5zRx6@mail.python.org> http://hg.python.org/cpython/rev/a4b0e5241bef changeset: 81148:a4b0e5241bef parent: 81146:2cae7bde45ef parent: 81143:9beb11071dd1 user: Andrew Svetlov date: Sat Dec 29 23:11:20 2012 +0200 summary: merge heads files: Doc/library/aifc.rst | 4 ++++ Lib/aifc.py | 12 ++++++++++++ Lib/test/test_aifc.py | 12 ++++++++++++ Misc/NEWS | 2 ++ 4 files changed, 30 insertions(+), 0 deletions(-) diff --git a/Doc/library/aifc.rst b/Doc/library/aifc.rst --- a/Doc/library/aifc.rst +++ b/Doc/library/aifc.rst @@ -51,6 +51,10 @@ used for writing, the file object should be seekable, unless you know ahead of time how many samples you are going to write in total and use :meth:`writeframesraw` and :meth:`setnframes`. + Objects returned by :func:`.open` also supports the :keyword:`with` statement. + +.. versionchanged:: 3.4 + Support for the :keyword:`with` statement was added. Objects returned by :func:`.open` when a file is opened for reading have the following methods: diff --git a/Lib/aifc.py b/Lib/aifc.py --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -334,6 +334,12 @@ # else, assume it is an open file object already self.initfp(f) + def __enter__(self): + return self + + def __exit__(self, *args): + self.close() + # # User visible methods. # @@ -553,6 +559,12 @@ def __del__(self): self.close() + def __enter__(self): + return self + + def __exit__(self, *args): + self.close() + # # User visible methods. # diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -43,6 +43,18 @@ (2, 2, 48000, 14400, b'NONE', b'not compressed'), ) + def test_context_manager(self): + with open(self.sndfilepath, 'rb') as testfile: + with aifc.open(testfile) as f: + pass + self.assertEqual(testfile.closed, True) + with open(TESTFN, 'wb') as testfile: + with self.assertRaises(aifc.Error): + with aifc.open(testfile, 'wb') as fout: + pass + self.assertEqual(testfile.closed, True) + fout.close() # do nothing + def test_read(self): f = self.f = aifc.open(self.sndfilepath) self.assertEqual(f.readframes(0), b'') diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,8 @@ Library ------- +- Issue #16486: Make aifc files work with 'with' as context managers. + - Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 22:45:32 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 22:45:32 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2Njg4?= =?utf-8?q?=3A_Fix_backreferences_did_make_case-insensitive_regex_fail_on?= Message-ID: <3YYdcr14lszRyG@mail.python.org> http://hg.python.org/cpython/rev/44a4f9289faa changeset: 81149:44a4f9289faa branch: 3.3 parent: 81145:e9cbe583156f user: Serhiy Storchaka date: Sat Dec 29 23:38:48 2012 +0200 summary: Issue #16688: Fix backreferences did make case-insensitive regex fail on non-ASCII strings. Patch by Matthew Barnett. files: Lib/test/test_re.py | 5 +++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/_sre.c | 11 ++++++----- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -968,6 +968,11 @@ self.assertEqual(r, s) self.assertEqual(n, size + 1) + def test_bug_16688(self): + # Issue 16688: Backreferences make case-insensitive regex fail on + # non-ASCII strings. + self.assertEqual(re.findall(r"(?i)(a)\1", "aa \u0100"), ['a']) + self.assertEqual(re.match(r"(?s).{1,3}", "\u0100\u0100").span(), (0, 2)) def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -70,6 +70,7 @@ Nick Barnes Quentin Barnes David Barnett +Matthew Barnett Richard Barran Cesar Eduardo Barros Des Barry diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,9 @@ Library ------- +- Issue #16688: Fix backreferences did make case-insensitive regex fail on + non-ASCII strings. Patch by Matthew Barnett. + - Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -492,7 +492,7 @@ Py_ssize_t i; /* adjust end */ - if (maxcount < end - ptr && maxcount != 65535) + if (maxcount < (end - ptr) / state->charsize && maxcount != 65535) end = ptr + maxcount*state->charsize; switch (pattern[0]) { @@ -583,7 +583,7 @@ Py_ssize_t i; /* check minimal length */ - if (pattern[3] && (end - ptr) < pattern[3]) + if (pattern[3] && (end - ptr)/state->charsize < pattern[3]) return 0; /* check known prefix */ @@ -801,7 +801,7 @@ /* <1=skip> <2=flags> <3=min> ... */ if (ctx->pattern[3] && (end - ctx->ptr)/state->charsize < ctx->pattern[3]) { TRACE(("reject (got %d chars, need %d)\n", - (end - ctx->ptr), ctx->pattern[3])); + (end - ctx->ptr)/state->charsize, ctx->pattern[3])); RETURN_FAILURE; } ctx->pattern += ctx->pattern[1] + 1; @@ -1329,9 +1329,10 @@ RETURN_FAILURE; while (p < e) { if (ctx->ptr >= end || - state->lower(SRE_CHARGET(state, ctx->ptr, 0)) != state->lower(*p)) + state->lower(SRE_CHARGET(state, ctx->ptr, 0)) != + state->lower(SRE_CHARGET(state, p, 0))) RETURN_FAILURE; - p++; + p += state->charsize; ctx->ptr += state->charsize; } } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Dec 29 22:45:33 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sat, 29 Dec 2012 22:45:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316688=3A_Fix_backreferences_did_make_case-insen?= =?utf-8?q?sitive_regex_fail_on?= Message-ID: <3YYdcs3VZGzRx6@mail.python.org> http://hg.python.org/cpython/rev/c59ee1ff6f27 changeset: 81150:c59ee1ff6f27 parent: 81148:a4b0e5241bef parent: 81149:44a4f9289faa user: Serhiy Storchaka date: Sat Dec 29 23:41:08 2012 +0200 summary: Issue #16688: Fix backreferences did make case-insensitive regex fail on non-ASCII strings. Patch by Matthew Barnett. files: Lib/test/test_re.py | 5 +++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/_sre.c | 11 ++++++----- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -968,6 +968,11 @@ self.assertEqual(r, s) self.assertEqual(n, size + 1) + def test_bug_16688(self): + # Issue 16688: Backreferences make case-insensitive regex fail on + # non-ASCII strings. + self.assertEqual(re.findall(r"(?i)(a)\1", "aa \u0100"), ['a']) + self.assertEqual(re.match(r"(?s).{1,3}", "\u0100\u0100").span(), (0, 2)) def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -70,6 +70,7 @@ Nick Barnes Quentin Barnes David Barnett +Matthew Barnett Richard Barran Cesar Eduardo Barros Des Barry diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,9 @@ Library ------- +- Issue #16688: Fix backreferences did make case-insensitive regex fail on + non-ASCII strings. Patch by Matthew Barnett. + - Issue #16486: Make aifc files work with 'with' as context managers. - Issue #16485: Fix file descriptor not being closed if file header patching diff --git a/Modules/_sre.c b/Modules/_sre.c --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -492,7 +492,7 @@ Py_ssize_t i; /* adjust end */ - if (maxcount < end - ptr && maxcount != 65535) + if (maxcount < (end - ptr) / state->charsize && maxcount != 65535) end = ptr + maxcount*state->charsize; switch (pattern[0]) { @@ -583,7 +583,7 @@ Py_ssize_t i; /* check minimal length */ - if (pattern[3] && (end - ptr) < pattern[3]) + if (pattern[3] && (end - ptr)/state->charsize < pattern[3]) return 0; /* check known prefix */ @@ -801,7 +801,7 @@ /* <1=skip> <2=flags> <3=min> ... */ if (ctx->pattern[3] && (end - ctx->ptr)/state->charsize < ctx->pattern[3]) { TRACE(("reject (got %d chars, need %d)\n", - (end - ctx->ptr), ctx->pattern[3])); + (end - ctx->ptr)/state->charsize, ctx->pattern[3])); RETURN_FAILURE; } ctx->pattern += ctx->pattern[1] + 1; @@ -1329,9 +1329,10 @@ RETURN_FAILURE; while (p < e) { if (ctx->ptr >= end || - state->lower(SRE_CHARGET(state, ctx->ptr, 0)) != state->lower(*p)) + state->lower(SRE_CHARGET(state, ctx->ptr, 0)) != + state->lower(SRE_CHARGET(state, p, 0))) RETURN_FAILURE; - p++; + p += state->charsize; ctx->ptr += state->charsize; } } -- Repository URL: http://hg.python.org/cpython From tjreedy at udel.edu Sat Dec 29 23:49:28 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 29 Dec 2012 17:49:28 -0500 Subject: [Python-checkins] cpython (3.3): Issue #16165: Fix sched.scheduler.run() method was block a scheduler for In-Reply-To: <3YYZm63bhDzQxq@mail.python.org> References: <3YYZm63bhDzQxq@mail.python.org> Message-ID: <50DF7378.1010008@udel.edu> On 12/29/2012 2:36 PM, serhiy.storchaka wrote: > summary: > Issue #16165: Fix sched.scheduler.run() method was block a scheduler for > other threads. This is not a coherent English sentence. It is at least missing a period. I am guessing it should be Issue #16165: Fix sched.scheduler.run() method. It previously blocked a scheduler for other threads. From solipsis at pitrou.net Sun Dec 30 05:55:20 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 30 Dec 2012 05:55:20 +0100 Subject: [Python-checkins] Daily reference leaks (c59ee1ff6f27): sum=-1 Message-ID: results for c59ee1ff6f27 on branch "default" -------------------------------------------- test_support leaked [0, 0, -1] references, sum=-1 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogh56coy', '-x'] From python-checkins at python.org Sun Dec 30 14:39:30 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 30 Dec 2012 14:39:30 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Further_PEP_432_updates?= Message-ID: <3YZ2nZ4h29zRy8@mail.python.org> http://hg.python.org/peps/rev/bd623fe7ad27 changeset: 4641:bd623fe7ad27 user: Nick Coghlan date: Sun Dec 30 23:39:20 2012 +1000 summary: Further PEP 432 updates - describe all 4 proposed initialisation phases - more detailed interface for hash seed handling - move ignore environment flag into core config - consistently use American spelling of initialize - preliminary concept for main execution API - misc notes on status quo files: pep-0432.txt | 246 ++++++++++++++++++++++++++++---------- 1 files changed, 181 insertions(+), 65 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -15,7 +15,7 @@ ======== This PEP proposes a mechanism for simplifying the startup sequence for -CPython, making it easier to modify the initialisation behaviour of the +CPython, making it easier to modify the initialization behaviour of the reference interpreter executable, as well as making it easier to control CPython's startup behaviour when creating an alternate executable or embedding it as a Python execution engine inside a larger application. @@ -25,15 +25,24 @@ implementation is developed. -Proposal Summary -================ +Proposal +======== -This PEP proposes that CPython move to an explicit 2-phase initialisation +This PEP proposes that CPython move to an explicit multi-phase initialization process, where a preliminary interpreter is put in place with limited OS interaction capabilities early in the startup sequence. This essential core remains in place while all of the configuration settings are determined, until a final configuration call takes those settings and finishes -bootstrapping the interpreter immediately before executing the main module. +bootstrapping the interpreter immediately before locating and executing +the main module. + +In the new design, the interpreter will move through the following +well-defined phases during the startup sequence: + +* Pre-Initialization - no interpreter available +* Initialization - limited interpreter available +* Pre-Main - full interpreter available, __main__ related metadata incomplete +* Main Execution - normal interpreter operation As a concrete use case to help guide any design changes, and to solve a known problem where the appropriate defaults for system utilities differ from those @@ -46,20 +55,21 @@ To keep the implementation complexity under control, this PEP does *not* propose wholesale changes to the way the interpreter state is accessed at runtime, nor does it propose changes to the way subinterpreters are -created after the main interpreter has already been initialised. Changing -the order in which the existing initialisation steps occur to make the -startup sequence easier to maintain is already a substantial change, and +created after the main interpreter has already been initialized. Changing +the order in which the existing initialization steps occur in order to make +the startup sequence easier to maintain is already a substantial change, and attempting to make those other changes at the same time will make the change significantly more invasive and much harder to review. However, such proposals may be suitable topics for follow-on PEPs or patches - one key benefit of this PEP is decreasing the coupling between the internal storage -model and the configuration interface. +model and the configuration interface, so such changes should be easier +once this PEP has been implemented. Background ========== -Over time, CPython's initialisation sequence has become progressively more +Over time, CPython's initialization sequence has become progressively more complicated, offering more options, as well as performing more complex tasks (such as configuring the Unicode settings for OS interfaces in Python 3 as well as bootstrapping a pure Python implementation of the import system). @@ -72,7 +82,7 @@ safely. A number of proposals are on the table for even *more* sophisticated -startup behaviour, such as better control over ``sys.path`` initialisation +startup behaviour, such as better control over ``sys.path`` initialization (easily adding additional directories on the command line in a cross-platform fashion, as well as controlling the configuration of ``sys.path[0]``), easier configuration of utilities like coverage tracing when launching Python @@ -96,14 +106,14 @@ The current CPython startup sequence is difficult to understand, and even more difficult to modify. It is not clear what state the interpreter is in -while much of the initialisation code executes, leading to behaviour such +while much of the initialization code executes, leading to behaviour such as lists, dictionaries and Unicode values being created prior to the call to ``Py_Initialize`` when the ``-X`` or ``-W`` options are used [1_]. -By moving to a 2-phase startup sequence, developers should only need to -understand which features are not available in the core bootstrapping state, -as the vast majority of the configuration process will now take place in -that state. +By moving to an explicitly multi-phase startup sequence, developers should +only need to understand which features are not available in the core +bootstrapping state, as the vast majority of the configuration process +will now take place in that state. By basing the new design on a combination of C structures and Python dictionaries, it should also be easier to modify the system in the @@ -114,7 +124,7 @@ ----------- CPython is used heavily to run short scripts where the runtime is dominated -by the interpreter initialisation time. Any changes to the startup sequence +by the interpreter initialization time. Any changes to the startup sequence should minimise their impact on the startup overhead. Experience with the importlib migration suggests that the startup time is @@ -141,15 +151,15 @@ Improvements in the import system and the Unicode support already resulted in a more than 30% improvement in startup time in Python 3.3 relative to 3.2. Python 3.3 is still slightly slower to start than Python 2.7 due to the -additional infrastructure that needs to be put in place to support the Unicode -based text model. +additional infrastructure that needs to be put in place to support the +Unicode based text model. This PEP is not expected to have any significant effect on the startup time, -as it is aimed primarily at *reordering* the existing initialisation +as it is aimed primarily at *reordering* the existing initialization sequence, without making substantial changes to the individual steps. However, if this simple check suggests that the proposed changes to the -initialisation sequence may pose a performance problem, then a more +initialization sequence may pose a performance problem, then a more sophisticated microbenchmark will be developed to assist in investigation. @@ -198,7 +208,7 @@ * ``no_site`` (don't implicitly import site during startup) * ``ignore_environment`` (whether environment vars are used during config) * ``verbose`` (enable all sorts of random output) - * ``bytes_warning`` + * ``bytes_warning`` (warnings/errors for implicit str/bytes interaction) * ``quiet`` (disable banner output even if verbose is also enabled or stdin is a tty and the interpreter is launched in interactive mode) @@ -219,7 +229,7 @@ Note that this just covers settings that are currently configurable in some manner when using the main CPython executable. While this PEP aims to make adding additional configuration settings easier in the future, it -deliberately avoids any new settings of its own. +deliberately avoids adding any new settings of its own. The Status Quo @@ -238,13 +248,14 @@ ------------------------------ The ``-E`` command line option allows all environment variables to be -ignored when initialising the Python interpreter. An embedding application +ignored when initializing the Python interpreter. An embedding application can enable this behaviour by setting ``Py_IgnoreEnvironmentFlag`` before calling ``Py_Initialize()``. In the CPython source code, the ``Py_GETENV`` macro implicitly checks this flag, and always produces ``NULL`` if it is set. + @@ -266,7 +277,8 @@ The new configuration API should make it straightforward for an embedding application to reuse the ``PYTHONHASHSEED`` processing with -a text based configuration setting provided by other means. +a text based configuration setting provided by other means (e.g. a +config file or separate environment variable). Locating Python and the standard library @@ -301,7 +313,7 @@ An embedding application may call ``Py_SetPath()`` prior to ``Py_Initialize()`` to completely override the calculation of ``sys.path``. It is not straightforward to only allow *some* of the -calculations, as modifying ``sys.path`` after initialisation is +calculations, as modifying ``sys.path`` after initialization is already complete means those modifications will not be in effect when standard library modules are imported during the startup sequence. @@ -332,10 +344,10 @@ (Note: you can see similar information using ``-m site`` instead of ``-c``, but this is slightly misleading as it calls ``os.abspath`` on all of the -path entries (making relative path entries look absolute), and also causes -problems in the last case, as on Python versions prior to 3.3, explicitly -importing site will carry out the path modifications ``-S`` avoids, while on -3.3+ combining ``-m site`` with ``-S`` currently fails) +path entries, making relative path entries look absolute. Using the ``site`` +module also causes problems in the last case, as on Python versions prior to +3.3, explicitly importing site will carry out the path modifications ``-S`` +avoids, while on 3.3+ combining ``-m site`` with ``-S`` currently fails) The calculation of ``sys.path[0]`` is comparatively straightforward: @@ -386,7 +398,7 @@ Other configuration settings ---------------------------- -TBD: Cover the initialisation of the following in more detail: +TBD: Cover the initialization of the following in more detail: * The initial warning system state: * ``sys.warnoptions`` @@ -419,7 +431,7 @@ * ``no_site`` (don't implicitly import site during startup) * ``ignore_environment`` (whether environment vars are used during config) * ``verbose`` (enable all sorts of random output) - * ``bytes_warning`` (This may be obsolete in Py3k...) + * ``bytes_warning`` (warnings/errors for implicit str/bytes interaction) * ``quiet`` (disable banner output even if verbose is also enabled or stdin is a tty and the interpreter is launched in interactive mode) @@ -428,15 +440,15 @@ Much of the configuration of CPython is currently handled through C level global variables:: - Py_BytesWarningFlag + Py_BytesWarningFlag (-b) Py_DebugFlag (-d option) Py_InspectFlag (-i option, PYTHONINSPECT) - Py_InteractiveFlag + Py_InteractiveFlag (property of stdin, cannot be overridden) Py_OptimizeFlag (-O option, PYTHONOPTIMIZE) Py_DontWriteBytecodeFlag (-B option, PYTHONDONTWRITEBYTECODE) Py_NoUserSiteDirectory (-s option, PYTHONNOUSERSITE) Py_NoSiteFlag (-S option) - Py_UnbufferedStdioFlag + Py_UnbufferedStdioFlag (-u, PYTHONUNBUFFEREDIO) Py_VerboseFlag (-v option, PYTHONVERBOSE) For the above variables, the conversion of command line options and @@ -463,34 +475,63 @@ Also see detailed sequence of operations notes at [1_] -Proposal -======== +Design Details +============== (Note: details here are still very much in flux, but preliminary feedback is appreciated anyway) The main theme of this proposal is to create the interpreter state for the main interpreter *much* earlier in the startup process. This will allow -most of the CPython API to be used during the remainder of the initialisation +most of the CPython API to be used during the remainder of the initialization process, potentially simplifying a number of operations that currently need to rely on basic C functionality rather than being able to use the richer data structures provided by the CPython C API. +In the following, the term "embedding application" also covers the standard +CPython command line application. -Core Interpreter Initialisation -------------------------------- -The only configuration that currently absolutely needs to be in place -before even the interpreter core can be initialised is a flag indicating -whether or not to use a specific seed value for the randomised hashes, and -if so, the specific value for the seed (a seed value of zero disables -randomised hashing). +Startup Phases +-------------- + +Four distinct phases are proposed: + +* Pre-Initialization: no interpreter is available. Embedding application + determines the settings required to create the core interpreter and + moves to the next phase by calling ``Py_BeginInitialization``. +* Initialization - a limited interpreter is available. Embedding application + determines and applies the settings required to complete the initialization + process by calling ``Py_ReadConfiguration`` and ``Py_EndInitialization``. +* Pre-Main - the full interpreter is available, but ``__main__`` related + metadata is incomplete. +* Main Execution - normal interpreter operation + +All 4 phases will be used by the standard CPython interpreter and the +proposed System Python interpreter. Other embedding applications may +choose to skip the step of executing code in the ``__main__`` module. + +Pre-Initialization Phase +------------------------ + +The pre-initialization phase is where an embedding application determines +the settings which are absolutely required before the interpreter can be +initialized at all. Currently, the only configuration settings in this +category are those related to the randomised hash algorithm - the hash +algorithms must be consistent for the lifetime of the process, and so they +must be in place before the core interpreter is created. + +The specific settings needed are a flag indicating whether or not to use a +specific seed value for the randomised hashes, and if so, the specific value +for the seed (a seed value of zero disables randomised hashing). In addition, +the question of whether or not to consider environment variables must be +addressed early. The proposed API for this step in the startup sequence is:: void Py_BeginInitialization(Py_CoreConfig *config); -Like Py_Initialize, this part of the new API treats initialisation failures +Like Py_Initialize, this part of the new API treats initialization failures as fatal errors. While that's still not particularly embedding friendly, the operations in this step *really* shouldn't be failing, and changing them to return error codes instead of aborting would be an even larger task than @@ -500,16 +541,50 @@ configuration:: typedef struct { + int ignore_environment; int use_hash_seed; unsigned long hash_seed; } Py_CoreConfig; -To disable hash randomisation, set "use_hash_seed" and pass a hash seed of -zero. (This is the same approach already used when interpreting the -``PYTHONHASHSEED`` environment variable) +The core configuration settings pointer may be ``NULL``, in which case the +default values are ``ignore_environment = 0`` and ``use_hash_seed = -1``. -The core configuration settings pointer may be NULL, in which case the -default behaviour of randomised hashes with a random seed will be used. +``ignore_environment`` controls the processing of all Python related +environment variables. If the flag is zero, then environment variables are +processed normally. Otherwise, all Python-specific environment variables +are considered undefined (exceptions may be made for some OS specific +environment variables, such as those used on Mac OS X to communicate +between the App bundle and the main Python binary). + +``use_hash_seed`` controls the configuration of the randomised hash +algorithm. If it is zero, then randomised hashes with a random seed will +be used. It it is positive, then the value in ``hash_seed`` will be used +to seed the random number generator. If the ``hash_seed`` is zero in this +case, then the randomised hashing is disabled completely. + +If ``use_hash_seed`` is negative (and ``ignore_environment`` is zero), +then CPython will inspect the ``PYTHONHASHSEED`` environment variable. If it +is not set, is set to the empty string, or to the value ``"random"``, then +randomised hashes with a random seed will be used. If it is set to the string +``"0"`` the randomised hashing will be disabled. Otherwise, the hash seed is +expected to be a string representation of an integer in the range +``[0; 4294967295]``. + +To make it easier for embedding applications to use the ``PYTHONHASHSEED`` +processing with a different data source, the following helper function +will be added to the C API:: + + int Py_ReadHashSeed(char *seed_text, + int *use_hash_seed, + unsigned long *hash_seed); + +This function accepts a seed string in ``seed_text`` and converts it to +the appropriate flag and seed values. If ``seed_text`` is ``NULL``, +the empty string or the value ``"random"``, both ``use_hash_seed`` and +``hash_seed`` will be set to zero. Otherwise, ``use_hash_seed`` will be set to +``1`` and the seed text will be interpreted as an integer and reported as +``hash_seed``. On success the function will return zero. A non-zero return +value indicates an error (most likely in the conversion to an integer). The aim is to keep this initial level of configuration as small as possible in order to keep the bootstrapping environment consistent across @@ -519,14 +594,14 @@ A new query API will allow code to determine if the interpreter is in the bootstrapping state between the creation of the interpreter state and the -completion of the bulk of the initialisation process:: +completion of the bulk of the initialization process:: int Py_IsInitializing(); Attempting to call ``Py_BeginInitialization()`` again when ``Py_IsInitializing()`` or ``Py_IsInitialized()`` is true is a fatal error. -While in the initialising state, the interpreter should be fully functional +While in the initializing state, the interpreter should be fully functional except that: * compilation is not allowed (as the parser and compiler are not yet @@ -551,7 +626,7 @@ * only builtin and frozen modules may be imported (due to above limitations) * ``sys.stderr`` is set to a temporary IO object using unbuffered binary mode -* The ``warnings`` module is not yet initialised +* The ``warnings`` module is not yet initialized * The ``__main__`` module does not yet exist @@ -573,7 +648,7 @@ Determining the remaining configuration settings ------------------------------------------------ -The next step in the initialisation sequence is to determine the full +The next step in the initialization sequence is to determine the full settings needed to complete the process. No changes are made to the interpreter state at this point. The core API for this step is:: @@ -630,11 +705,12 @@ -Completing the interpreter initialisation +Completing the interpreter initialization ----------------------------------------- -The final step in the process is to actually put the configuration settings -into effect and finish bootstrapping the interpreter up to full operation:: +The final step in the initialization process is to actually put the +configuration settings into effect and finish bootstrapping the interpreter +up to full operation:: int Py_EndInitialization(PyObject *config); @@ -648,7 +724,48 @@ After a successful call, Py_IsInitializing() will be false, while Py_IsInitialized() will become true. The caveats described above for the -interpreter during the initialisation phase will no longer hold. +interpreter during the initialization phase will no longer hold. + +However, some metadata related to the ``__main__`` module may still be +incomplete: + +* ``sys.argv[0]`` may not yet have its final value + * it will be ``-m`` when executing a module or package with CPython + * it will be the same as ``sys.path[0]`` rather than the location of + the ``__main__`` module when executing a valid ``sys.path`` entry + (typically a zipfile or directory) +* the metadata in the ``__main__`` module will still indicate it is a + builtin module + + +Executing the main module +------------------------- + + + +Initial thought is that hiding the various options behind a single API +would make that API too complicated, so 3 separate APIs is more likely:: + + Py_RunPathAsMain + Py_RunModuleAsMain + Py_RunStreamAsMain + + +Internal Storage of Configuration Data +-------------------------------------- + +The interpreter state will be updated to include details of the configuration +settings supplied during initialization by extending the interpreter state +object with an embedded copy of the ``Py_CoreConfig`` struct and an +additional ``PyObject`` pointer to hold a reference to a copy of the +supplied configuration dictionary. + +For debugging purposes, the copied configuration dictionary will be +exposed as ``sys._configuration``. It will include additional keys for +the fields in the ``Py_CoreConfig`` struct. + +These are *snapshots* of the initial configuration settings. They are not +consulted by the interpreter during runtime. Stable ABI @@ -670,7 +787,7 @@ One acknowledged incompatiblity is that some environment variables which are currently read lazily may instead be read once during interpreter -initialisation. As the PEP matures, these will be discussed in more detail +initialization. As the PEP matures, these will be discussed in more detail on a case by case basis. The environment variables which are currently known to be looked up dynamically are: @@ -680,7 +797,7 @@ * ``PYTHONINSPECT``: ``os.environ['PYTHONINSPECT']`` will still be checked after execution of the ``__main__`` module terminates -The ``Py_Initialize()`` style of initialisation will continue to be +The ``Py_Initialize()`` style of initialization will continue to be supported. It will use (at least some elements of) the new API internally, but will continue to exhibit the same behaviour as it does today, ensuring that ``sys.argv`` is not populated until a subsequent @@ -691,7 +808,7 @@ To minimise unnecessary code churn, and to ensure the backwards compatibility is well tested, the main CPython executable may continue to use some elements -of the old style initialisation API. (very much TBC) +of the old style initialization API. (very much TBC) A System Python Executable @@ -712,8 +829,8 @@ change in the PEP is designed to help avoid acceptance of a design that sounds good in theory but proves to be problematic in practice. -One final aspect not addressed by the general embedding changes above is -the current inaccessibility of the core logic for deciding between the +Better supporting this kind of "alternate CLI" is the main reason for the +proposed changes to better expose the core logic for deciding between the different execution modes supported by CPython: * script execution @@ -723,7 +840,6 @@ * execution from stdin (non-interactive) * interactive stdin - Implementation ============== -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sun Dec 30 15:18:33 2012 From: python-checkins at python.org (eli.bendersky) Date: Sun, 30 Dec 2012 15:18:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogRm9yIElzc3VlICMx?= =?utf-8?q?6076=3A_make_sure_that_pickling_of_Element_objects_is_tested=2C?= =?utf-8?q?_and_do?= Message-ID: <3YZ3fd6krfzRyM@mail.python.org> http://hg.python.org/cpython/rev/71508fc738bb changeset: 81151:71508fc738bb branch: 3.3 parent: 81149:44a4f9289faa user: Eli Bendersky date: Sun Dec 30 06:17:49 2012 -0800 summary: For Issue #16076: make sure that pickling of Element objects is tested, and do it properly to avoid problems with test-run-order dependencies. files: Lib/test/test_xml_etree.py | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -16,6 +16,7 @@ import html import io +import pickle import sys import unittest import weakref @@ -1768,6 +1769,20 @@ self.assertEqual(flag, True) self.assertEqual(wref(), None) + def test_pickle(self): + # For now this test only works for the Python version of ET, + # so set sys.modules accordingly because pickle uses __import__ + # to load the __module__ of the class. + if pyET: + sys.modules['xml.etree.ElementTree'] = pyET + else: + raise unittest.SkipTest('only for the Python version') + e1 = ET.Element('foo', bar=42) + s = pickle.dumps(e1) + e2 = pickle.loads(s) + self.assertEqual(e2.tag, 'foo') + self.assertEqual(e2.attrib['bar'], 42) + class ElementTreeTest(unittest.TestCase): def test_istype(self): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 15:18:35 2012 From: python-checkins at python.org (eli.bendersky) Date: Sun, 30 Dec 2012 15:18:35 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_For_issue_=2316076=3A_merge_3=2E3?= Message-ID: <3YZ3fg1zdtzS0b@mail.python.org> http://hg.python.org/cpython/rev/5a38f4d7833c changeset: 81152:5a38f4d7833c parent: 81150:c59ee1ff6f27 parent: 81151:71508fc738bb user: Eli Bendersky date: Sun Dec 30 06:18:19 2012 -0800 summary: For issue #16076: merge 3.3 files: Lib/test/test_xml_etree.py | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -16,6 +16,7 @@ import html import io +import pickle import sys import unittest import weakref @@ -1768,6 +1769,20 @@ self.assertEqual(flag, True) self.assertEqual(wref(), None) + def test_pickle(self): + # For now this test only works for the Python version of ET, + # so set sys.modules accordingly because pickle uses __import__ + # to load the __module__ of the class. + if pyET: + sys.modules['xml.etree.ElementTree'] = pyET + else: + raise unittest.SkipTest('only for the Python version') + e1 = ET.Element('foo', bar=42) + s = pickle.dumps(e1) + e2 = pickle.loads(s) + self.assertEqual(e2.tag, 'foo') + self.assertEqual(e2.attrib['bar'], 42) + class ElementTreeTest(unittest.TestCase): def test_istype(self): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 15:30:02 2012 From: python-checkins at python.org (eli.bendersky) Date: Sun, 30 Dec 2012 15:30:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Skip_a_test_co?= =?utf-8?q?rrectly_for_the_C-version=2E_The_decorator_doesn=27t_really_wor?= =?utf-8?q?k?= Message-ID: <3YZ3vt3smhzRxt@mail.python.org> http://hg.python.org/cpython/rev/e2cce1100bd3 changeset: 81153:e2cce1100bd3 branch: 3.3 parent: 81151:71508fc738bb user: Eli Bendersky date: Sun Dec 30 06:27:56 2012 -0800 summary: Skip a test correctly for the C-version. The decorator doesn't really work because it evaluates its condition before pyET is even set by test_main. Therefore, the check it moved to "runtime". files: Lib/test/test_xml_etree.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -2420,8 +2420,11 @@ # -------------------------------------------------------------------- - at unittest.skipUnless(pyET, 'only for the Python version') class NoAcceleratorTest(unittest.TestCase): + def setUp(self): + if not pyET: + raise SkipTest('only for the Python version') + # Test that the C accelerator was not imported for pyET def test_correct_import_pyET(self): self.assertEqual(pyET.Element.__module__, 'xml.etree.ElementTree') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 15:30:03 2012 From: python-checkins at python.org (eli.bendersky) Date: Sun, 30 Dec 2012 15:30:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Skip_a_test_correctly_for_the_C-version=2E_The_decorator?= =?utf-8?q?_doesn=27t_really_work?= Message-ID: <3YZ3vv6PLQzRxt@mail.python.org> http://hg.python.org/cpython/rev/08c215115842 changeset: 81154:08c215115842 parent: 81152:5a38f4d7833c parent: 81153:e2cce1100bd3 user: Eli Bendersky date: Sun Dec 30 06:29:49 2012 -0800 summary: Skip a test correctly for the C-version. The decorator doesn't really work because it evaluates its condition before pyET is even set by test_main. Therefore, the check it moved to "runtime". files: Lib/test/test_xml_etree.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -2420,8 +2420,11 @@ # -------------------------------------------------------------------- - at unittest.skipUnless(pyET, 'only for the Python version') class NoAcceleratorTest(unittest.TestCase): + def setUp(self): + if not pyET: + raise SkipTest('only for the Python version') + # Test that the C accelerator was not imported for pyET def test_correct_import_pyET(self): self.assertEqual(pyET.Element.__module__, 'xml.etree.ElementTree') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 16:12:12 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 30 Dec 2012 16:12:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_PEP_432_syntax_fix?= Message-ID: <3YZ4rX2BbNzS09@mail.python.org> http://hg.python.org/peps/rev/001751ad90c2 changeset: 4642:001751ad90c2 user: Nick Coghlan date: Mon Dec 31 01:12:03 2012 +1000 summary: PEP 432 syntax fix files: pep-0432.txt | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -730,10 +730,12 @@ incomplete: * ``sys.argv[0]`` may not yet have its final value + * it will be ``-m`` when executing a module or package with CPython * it will be the same as ``sys.path[0]`` rather than the location of the ``__main__`` module when executing a valid ``sys.path`` entry (typically a zipfile or directory) + * the metadata in the ``__main__`` module will still indicate it is a builtin module -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sun Dec 30 16:33:00 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 30 Dec 2012 16:33:00 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Allow_future-proof_initialisa?= =?utf-8?q?tion_of_Py=5FCoreConfig?= Message-ID: <3YZ5JX3Kd2zQvQ@mail.python.org> http://hg.python.org/peps/rev/6da7f3ff59b7 changeset: 4643:6da7f3ff59b7 user: Nick Coghlan date: Mon Dec 31 01:32:51 2012 +1000 summary: Allow future-proof initialisation of Py_CoreConfig files: pep-0432.txt | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -546,9 +546,16 @@ unsigned long hash_seed; } Py_CoreConfig; + #define Py_CoreConfig_INIT {0, -1, 0} + The core configuration settings pointer may be ``NULL``, in which case the default values are ``ignore_environment = 0`` and ``use_hash_seed = -1``. +The ``Py_CoreConfig_INIT`` macro is designed to allow easy initialization +of a struct instance with sensible defaults:: + + Py_CoreConfig core_config = Py_CoreConfig_INIT; + ``ignore_environment`` controls the processing of all Python related environment variables. If the flag is zero, then environment variables are processed normally. Otherwise, all Python-specific environment variables -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sun Dec 30 16:49:11 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 30 Dec 2012 16:49:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_short_example_of_using_th?= =?utf-8?q?e_new_API?= Message-ID: <3YZ5gC5GjzzRyT@mail.python.org> http://hg.python.org/peps/rev/6926ad909071 changeset: 4644:6926ad909071 user: Nick Coghlan date: Mon Dec 31 01:49:02 2012 +1000 summary: Add short example of using the new API files: pep-0432.txt | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) diff --git a/pep-0432.txt b/pep-0432.txt --- a/pep-0432.txt +++ b/pep-0432.txt @@ -511,6 +511,35 @@ proposed System Python interpreter. Other embedding applications may choose to skip the step of executing code in the ``__main__`` module. +An embedding application may still continue to leave the second phase +entirely under CPython's control by using the existing ``Py_Initialize`` +API. Alternatively, if an embedding application wants greater control +over CPython's initial state, it will be able to use the new, finer +grained API, which allows the embedding application greater control +over the initialization process:: + + /* Phase 1: Pre-Initialization */ + Py_CoreConfig core_config = Py_CoreConfig_INIT; + PyObject *full_config = NULL; + /* Easily control the core configuration */ + core_config.ignore_environment = 1; /* Ignore environment variables */ + core_config.use_hash_seed = 0; /* Full hash randomisation */ + Py_BeginInitialization(&core_config); + /* Phase 2: Initialization */ + full_config = PyDict_New(); + /* Can preconfigure settings here - they will then be + * used to derive other settings */ + Py_ReadConfiguration(full_config); + /* Can completely override derived settings here */ + Py_EndInitialization(full_config); + /* Phase 3: Pre-Main */ + Py_DECREF(full_config); + /* If an embedding application has no real concept of a main module + * it can leave the interpreter in this state indefinitely. + * Otherwise, it can launch __main__ via the Py_Run*AsMain functions. + */ + + Pre-Initialization Phase ------------------------ -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sun Dec 30 19:22:23 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 30 Dec 2012 19:22:23 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE2NjQ1?= =?utf-8?q?=3A_Fix_hardlink_extracting_test_for_tarfile=2E?= Message-ID: <3YZ93z5bHCzRwW@mail.python.org> http://hg.python.org/cpython/rev/503b889668fc changeset: 81155:503b889668fc branch: 2.7 parent: 81147:52900f205e6e user: Serhiy Storchaka date: Sun Dec 30 20:15:10 2012 +0200 summary: Issue #16645: Fix hardlink extracting test for tarfile. files: Lib/test/test_tarfile.py | 27 +++++++++++---------------- 1 files changed, 11 insertions(+), 16 deletions(-) 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 @@ -297,26 +297,21 @@ def test_extract_hardlink(self): # Test hardlink extraction (e.g. bug #857297). - tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") + with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar: + tar.extract("ustar/regtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/regtype")) - tar.extract("ustar/regtype", TEMPDIR) - try: tar.extract("ustar/lnktype", TEMPDIR) - except EnvironmentError, e: - if e.errno == errno.ENOENT: - self.fail("hardlink not extracted properly") + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/lnktype")) + with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: + data = f.read() + self.assertEqual(md5sum(data), md5_regtype) - data = open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb").read() - self.assertEqual(md5sum(data), md5_regtype) - - try: tar.extract("ustar/symtype", TEMPDIR) - except EnvironmentError, e: - if e.errno == errno.ENOENT: - self.fail("symlink not extracted properly") - - data = open(os.path.join(TEMPDIR, "ustar/symtype"), "rb").read() - self.assertEqual(md5sum(data), md5_regtype) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/symtype")) + with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: + data = f.read() + self.assertEqual(md5sum(data), md5_regtype) def test_extractall(self): # Test if extractall() correctly restores directory permissions -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 19:22:25 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 30 Dec 2012 19:22:25 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE2NjQ1?= =?utf-8?q?=3A_Fix_hardlink_extracting_test_for_tarfile=2E?= Message-ID: <3YZ9410sL0zS00@mail.python.org> http://hg.python.org/cpython/rev/d42bf4faf3d1 changeset: 81156:d42bf4faf3d1 branch: 3.2 parent: 81144:cbee422ca727 user: Serhiy Storchaka date: Sun Dec 30 20:16:30 2012 +0200 summary: Issue #16645: Fix hardlink extracting test for tarfile. files: Lib/test/test_tarfile.py | 24 +++++++----------------- 1 files changed, 7 insertions(+), 17 deletions(-) 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 @@ -328,31 +328,21 @@ @support.skip_unless_symlink def test_extract_hardlink(self): # Test hardlink extraction (e.g. bug #857297). - tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") + with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar: + tar.extract("ustar/regtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/regtype")) - try: - tar.extract("ustar/regtype", TEMPDIR) - try: - tar.extract("ustar/lnktype", TEMPDIR) - except EnvironmentError as e: - if e.errno == errno.ENOENT: - self.fail("hardlink not extracted properly") - + tar.extract("ustar/lnktype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/lnktype")) with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - try: - tar.extract("ustar/symtype", TEMPDIR) - except EnvironmentError as e: - if e.errno == errno.ENOENT: - self.fail("symlink not extracted properly") - + tar.extract("ustar/symtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/symtype")) with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - finally: - tar.close() def test_extractall(self): # Test if extractall() correctly restores directory permissions -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 19:22:26 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 30 Dec 2012 19:22:26 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Issue_=2316645=3A_Fix_hardlink_extracting_test_for_tarfile=2E?= Message-ID: <3YZ9423G1qzS3Z@mail.python.org> http://hg.python.org/cpython/rev/e1a0901e4ef7 changeset: 81157:e1a0901e4ef7 branch: 3.3 parent: 81153:e2cce1100bd3 parent: 81156:d42bf4faf3d1 user: Serhiy Storchaka date: Sun Dec 30 20:17:28 2012 +0200 summary: Issue #16645: Fix hardlink extracting test for tarfile. files: Lib/test/test_tarfile.py | 24 +++++++----------------- 1 files changed, 7 insertions(+), 17 deletions(-) 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 @@ -336,31 +336,21 @@ @support.skip_unless_symlink def test_extract_hardlink(self): # Test hardlink extraction (e.g. bug #857297). - tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") + with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar: + tar.extract("ustar/regtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/regtype")) - try: - tar.extract("ustar/regtype", TEMPDIR) - try: - tar.extract("ustar/lnktype", TEMPDIR) - except EnvironmentError as e: - if e.errno == errno.ENOENT: - self.fail("hardlink not extracted properly") - + tar.extract("ustar/lnktype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/lnktype")) with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - try: - tar.extract("ustar/symtype", TEMPDIR) - except EnvironmentError as e: - if e.errno == errno.ENOENT: - self.fail("symlink not extracted properly") - + tar.extract("ustar/symtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/symtype")) with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - finally: - tar.close() def test_extractall(self): # Test if extractall() correctly restores directory permissions -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 19:22:27 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Sun, 30 Dec 2012 19:22:27 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316645=3A_Fix_hardlink_extracting_test_for_tarfi?= =?utf-8?b?bGUu?= Message-ID: <3YZ9435hHVzS3f@mail.python.org> http://hg.python.org/cpython/rev/f173c2e92b64 changeset: 81158:f173c2e92b64 parent: 81154:08c215115842 parent: 81157:e1a0901e4ef7 user: Serhiy Storchaka date: Sun Dec 30 20:18:58 2012 +0200 summary: Issue #16645: Fix hardlink extracting test for tarfile. files: Lib/test/test_tarfile.py | 24 +++++++----------------- 1 files changed, 7 insertions(+), 17 deletions(-) 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 @@ -336,31 +336,21 @@ @support.skip_unless_symlink def test_extract_hardlink(self): # Test hardlink extraction (e.g. bug #857297). - tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") + with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar: + tar.extract("ustar/regtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/regtype")) - try: - tar.extract("ustar/regtype", TEMPDIR) - try: - tar.extract("ustar/lnktype", TEMPDIR) - except OSError as e: - if e.errno == errno.ENOENT: - self.fail("hardlink not extracted properly") - + tar.extract("ustar/lnktype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/lnktype")) with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - try: - tar.extract("ustar/symtype", TEMPDIR) - except OSError as e: - if e.errno == errno.ENOENT: - self.fail("symlink not extracted properly") - + tar.extract("ustar/symtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/symtype")) with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - finally: - tar.close() def test_extractall(self): # Test if extractall() correctly restores directory permissions -- Repository URL: http://hg.python.org/cpython From tjreedy at udel.edu Sun Dec 30 21:06:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 30 Dec 2012 15:06:33 -0500 Subject: [Python-checkins] peps: Further PEP 432 updates In-Reply-To: <3YZ2nZ4h29zRy8@mail.python.org> References: <3YZ2nZ4h29zRy8@mail.python.org> Message-ID: <50E09EC9.5020000@udel.edu> On 12/30/2012 8:39 AM, nick.coghlan wrote: > +In the new design, the interpreter will move through the following > +well-defined phases during the startup sequence: > + > +* Pre-Initialization - no interpreter available > +* Initialization - limited interpreter available > +* Pre-Main - full interpreter available, __main__ related metadata incomplete > +* Main Execution - normal interpreter operation It seems that you are saying to do the following four tasks: * Setup limited interpreter, using 'raw' C, that has a limited C-API. * Complete the full interpreter, using C and the limited API. * Setup __main__ module, using full API. * Execute Python code in __main__. Since I think of a 'phase' as activity rather than a 'thing', I prefer the verb form of phase description as describing what the interpreter is doing during the phase. I am assuming that the full interpreter is the limited interpreter 'fleshed out', rather than a new object built built from scratch. (The way that the PEP is written, it might be interpreted to mean the latter.) From python-checkins at python.org Sun Dec 30 22:49:03 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 30 Dec 2012 22:49:03 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E3=29=3A_Fix_the_advert?= =?utf-8?q?ised_size_of_PyCFunctionObjects_in_sys=2E=5Fdebugmallocstats=28?= =?utf-8?b?KS4=?= Message-ID: <3YZFfR33MqzS3C@mail.python.org> http://hg.python.org/cpython/rev/9e6ead98762e changeset: 81159:9e6ead98762e branch: 3.3 parent: 81157:e1a0901e4ef7 user: Antoine Pitrou date: Sun Dec 30 22:46:04 2012 +0100 summary: Fix the advertised size of PyCFunctionObjects in sys._debugmallocstats(). files: Objects/methodobject.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/methodobject.c b/Objects/methodobject.c --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -343,8 +343,8 @@ _PyCFunction_DebugMallocStats(FILE *out) { _PyDebugAllocatorStats(out, - "free PyCFunction", - numfree, sizeof(PyCFunction)); + "free PyCFunctionObjects", + numfree, sizeof(PyCFunctionObject)); } /* PyCFunction_New() is now just a macro that calls PyCFunction_NewEx(), -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Dec 30 22:49:04 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 30 Dec 2012 22:49:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_the_advertised_size_of_PyCFunctionObjects_in_sys=2E?= =?utf-8?q?=5Fdebugmallocstats=28=29=2E?= Message-ID: <3YZFfS5Q2szS3C@mail.python.org> http://hg.python.org/cpython/rev/e61381137b4a changeset: 81160:e61381137b4a parent: 81158:f173c2e92b64 parent: 81159:9e6ead98762e user: Antoine Pitrou date: Sun Dec 30 22:46:56 2012 +0100 summary: Fix the advertised size of PyCFunctionObjects in sys._debugmallocstats(). files: Objects/methodobject.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/methodobject.c b/Objects/methodobject.c --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -352,6 +352,6 @@ _PyCFunction_DebugMallocStats(FILE *out) { _PyDebugAllocatorStats(out, - "free PyCFunction", - numfree, sizeof(PyCFunction)); + "free PyCFunctionObjects", + numfree, sizeof(PyCFunctionObject)); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 02:29:42 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 02:29:42 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fixes_issue_?= =?utf-8?q?=2315803=3A_incorrect_=60ConfigParser=2Eitems=28=29=60_docstrin?= =?utf-8?q?g?= Message-ID: <3YZLY21W1nzS5m@mail.python.org> http://hg.python.org/cpython/rev/850503a117a9 changeset: 81161:850503a117a9 branch: 3.2 parent: 81156:d42bf4faf3d1 user: ?ukasz Langa date: Mon Dec 31 02:18:20 2012 +0100 summary: Fixes issue #15803: incorrect `ConfigParser.items()` docstring files: Lib/configparser.py | 7 +++---- Misc/ACKS | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -99,10 +99,9 @@ yes, on for True). Returns False or True. items(section=_UNSET, raw=False, vars=None) - If section is given, return a list of tuples with (section_name, - section_proxy) for each section, including DEFAULTSECT. Otherwise, - return a list of tuples with (name, value) for each option - in the section. + If section is given, return a list of tuples with (name, value) for + each option in the section. Otherwise, return a list of tuples with + (section_name, section_proxy) for each section, including DEFAULTSECT. remove_section(section) Remove the given file section and all its options. diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1078,6 +1078,7 @@ Matias Torchinsky Sandro Tosi Richard Townsend +Nathan Trapuzzano Laurence Tratt John Tromp Jason Trowbridge -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 02:29:43 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 02:29:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merged_fix_for_=2315803_from_3=2E2?= Message-ID: <3YZLY33wSHzS5m@mail.python.org> http://hg.python.org/cpython/rev/cc277b25eae7 changeset: 81162:cc277b25eae7 branch: 3.3 parent: 81159:9e6ead98762e parent: 81161:850503a117a9 user: ?ukasz Langa date: Mon Dec 31 02:25:28 2012 +0100 summary: Merged fix for #15803 from 3.2 files: Lib/configparser.py | 7 +++---- Misc/ACKS | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -99,10 +99,9 @@ yes, on for True). Returns False or True. items(section=_UNSET, raw=False, vars=None) - If section is given, return a list of tuples with (section_name, - section_proxy) for each section, including DEFAULTSECT. Otherwise, - return a list of tuples with (name, value) for each option - in the section. + If section is given, return a list of tuples with (name, value) for + each option in the section. Otherwise, return a list of tuples with + (section_name, section_proxy) for each section, including DEFAULTSECT. remove_section(section) Remove the given file section and all its options. diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1191,6 +1191,7 @@ Sandro Tosi Richard Townsend David Townshend +Nathan Trapuzzano Laurence Tratt Alberto Trevino Matthias Troffaes -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 02:29:44 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 02:29:44 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Merged_fix_for_=2315803_from_3=2E2_through_3=2E3?= Message-ID: <3YZLY46ZV7zS6j@mail.python.org> http://hg.python.org/cpython/rev/b4975cb4be95 changeset: 81163:b4975cb4be95 parent: 81160:e61381137b4a parent: 81162:cc277b25eae7 user: ?ukasz Langa date: Mon Dec 31 02:26:11 2012 +0100 summary: Merged fix for #15803 from 3.2 through 3.3 files: Lib/configparser.py | 7 +++---- Misc/ACKS | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -99,10 +99,9 @@ yes, on for True). Returns False or True. items(section=_UNSET, raw=False, vars=None) - If section is given, return a list of tuples with (section_name, - section_proxy) for each section, including DEFAULTSECT. Otherwise, - return a list of tuples with (name, value) for each option - in the section. + If section is given, return a list of tuples with (name, value) for + each option in the section. Otherwise, return a list of tuples with + (section_name, section_proxy) for each section, including DEFAULTSECT. remove_section(section) Remove the given file section and all its options. diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1202,6 +1202,7 @@ Sandro Tosi Richard Townsend David Townshend +Nathan Trapuzzano Laurence Tratt Alberto Trevino Matthias Troffaes -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 03:44:10 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 03:44:10 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4ZXMgYHBhcnNl?= =?utf-8?q?r=2Eclean=28=29=60_reported_in_issue_=2316820=2E?= Message-ID: <3YZNBy5zKnzS7G@mail.python.org> http://hg.python.org/cpython/rev/dc5adc08f1a8 changeset: 81164:dc5adc08f1a8 branch: 3.2 parent: 81161:850503a117a9 user: ?ukasz Langa date: Mon Dec 31 03:38:39 2012 +0100 summary: Fixes `parser.clean()` reported in issue #16820. files: Doc/library/configparser.rst | 8 ++++++- Lib/configparser.py | 13 +++++++++++ Lib/test/test_cfgparser.py | 27 ++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -389,7 +389,13 @@ the default value to be visible again. Trying to delete a default value causes a ``KeyError``. -* Trying to delete the ``DEFAULTSECT`` raises ``ValueError``. +* ``DEFAULTSECT`` cannot be removed from the parser: + + * trying to delete it raises ``ValueError``, + + * ``parser.clear()`` leaves it intact, + + * ``parser.popitem()`` never returns it. * ``parser.get(section, option, **kwargs)`` - the second argument is **not** a fallback value. Note however that the section-level ``get()`` methods are diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -851,6 +851,19 @@ value_getter = lambda option: d[option] return [(option, value_getter(option)) for option in d.keys()] + def popitem(self): + """Remove a section from the parser and return it as + a (section_name, section_proxy) tuple. If no section is present, raise + KeyError. + + The section DEFAULT is never returned because it cannot be removed. + """ + for key in self.sections(): + value = self[key] + del self[key] + return key, value + raise KeyError + def optionxform(self, optionstr): return optionstr.lower() diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py --- a/Lib/test/test_cfgparser.py +++ b/Lib/test/test_cfgparser.py @@ -770,6 +770,33 @@ with self.assertRaises(configparser.NoSectionError): cf.items("no such section") + def test_popitem(self): + cf = self.fromstring(""" + [section1] + name1 {0[0]} value1 + [section2] + name2 {0[0]} value2 + [section3] + name3 {0[0]} value3 + """.format(self.delimiters), defaults={"default": ""}) + self.assertEqual(cf.popitem()[0], 'section1') + self.assertEqual(cf.popitem()[0], 'section2') + self.assertEqual(cf.popitem()[0], 'section3') + with self.assertRaises(KeyError): + cf.popitem() + + def test_clear(self): + cf = self.newconfig({"foo": "Bar"}) + self.assertEqual( + cf.get(self.default_section, "Foo"), "Bar", + "could not locate option, expecting case-insensitive option names") + cf['zing'] = {'option1': 'value1', 'option2': 'value2'} + self.assertEqual(cf.sections(), ['zing']) + self.assertEqual(set(cf['zing'].keys()), {'option1', 'option2', 'foo'}) + cf.clear() + self.assertEqual(set(cf.sections()), set()) + self.assertEqual(set(cf[self.default_section].keys()), {'foo'}) + class StrictTestCase(BasicTestCase): config_class = configparser.RawConfigParser -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 03:44:12 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 03:44:12 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_added_Wolfgang?= =?utf-8?q?_Scherer_to_acknowledgements?= Message-ID: <3YZNC01GrFzS7F@mail.python.org> http://hg.python.org/cpython/rev/0786dfc3b2b4 changeset: 81165:0786dfc3b2b4 branch: 3.2 user: ?ukasz Langa date: Mon Dec 31 03:40:36 2012 +0100 summary: added Wolfgang Scherer to acknowledgements files: Misc/ACKS | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -947,6 +947,7 @@ Andreas Schawo Neil Schemenauer David Scherer +Wolfgang Scherer Hynek Schlawack Bob Schmertz Gregor Schmid -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 03:44:13 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 03:44:13 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Merged_=60parser=2Eclean=28=29=60_fix_=28issue_=2316820=29_fro?= =?utf-8?b?bSAzLjIu?= Message-ID: <3YZNC13f8ZzS6p@mail.python.org> http://hg.python.org/cpython/rev/4fc2fea807e6 changeset: 81166:4fc2fea807e6 branch: 3.3 parent: 81162:cc277b25eae7 parent: 81165:0786dfc3b2b4 user: ?ukasz Langa date: Mon Dec 31 03:41:54 2012 +0100 summary: Merged `parser.clean()` fix (issue #16820) from 3.2. files: Doc/library/configparser.rst | 8 +++++- Lib/configparser.py | 13 +++++++++++ Lib/test/test_configparser.py | 27 +++++++++++++++++++++++ Misc/ACKS | 1 + 4 files changed, 48 insertions(+), 1 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -389,7 +389,13 @@ the default value to be visible again. Trying to delete a default value causes a ``KeyError``. -* Trying to delete the ``DEFAULTSECT`` raises ``ValueError``. +* ``DEFAULTSECT`` cannot be removed from the parser: + + * trying to delete it raises ``ValueError``, + + * ``parser.clear()`` leaves it intact, + + * ``parser.popitem()`` never returns it. * ``parser.get(section, option, **kwargs)`` - the second argument is **not** a fallback value. Note however that the section-level ``get()`` methods are diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -852,6 +852,19 @@ value_getter = lambda option: d[option] return [(option, value_getter(option)) for option in d.keys()] + def popitem(self): + """Remove a section from the parser and return it as + a (section_name, section_proxy) tuple. If no section is present, raise + KeyError. + + The section DEFAULT is never returned because it cannot be removed. + """ + for key in self.sections(): + value = self[key] + del self[key] + return key, value + raise KeyError + def optionxform(self, optionstr): return optionstr.lower() diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -770,6 +770,33 @@ with self.assertRaises(configparser.NoSectionError): cf.items("no such section") + def test_popitem(self): + cf = self.fromstring(""" + [section1] + name1 {0[0]} value1 + [section2] + name2 {0[0]} value2 + [section3] + name3 {0[0]} value3 + """.format(self.delimiters), defaults={"default": ""}) + self.assertEqual(cf.popitem()[0], 'section1') + self.assertEqual(cf.popitem()[0], 'section2') + self.assertEqual(cf.popitem()[0], 'section3') + with self.assertRaises(KeyError): + cf.popitem() + + def test_clear(self): + cf = self.newconfig({"foo": "Bar"}) + self.assertEqual( + cf.get(self.default_section, "Foo"), "Bar", + "could not locate option, expecting case-insensitive option names") + cf['zing'] = {'option1': 'value1', 'option2': 'value2'} + self.assertEqual(cf.sections(), ['zing']) + self.assertEqual(set(cf['zing'].keys()), {'option1', 'option2', 'foo'}) + cf.clear() + self.assertEqual(set(cf.sections()), set()) + self.assertEqual(set(cf[self.default_section].keys()), {'foo'}) + class StrictTestCase(BasicTestCase): config_class = configparser.RawConfigParser diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1049,6 +1049,7 @@ Andreas Schawo Neil Schemenauer David Scherer +Wolfgang Scherer Hynek Schlawack Bob Schmertz Gregor Schmid -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 03:44:14 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 03:44:14 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2VkIGBwYXJzZXIuY2xlYW4oKWAgZml4IChpc3N1ZSAjMTY4MjAp?= =?utf-8?q?_from_3=2E2_through_3=2E3=2E?= Message-ID: <3YZNC264m4zS7F@mail.python.org> http://hg.python.org/cpython/rev/c6f9bc5a0cf1 changeset: 81167:c6f9bc5a0cf1 parent: 81163:b4975cb4be95 parent: 81166:4fc2fea807e6 user: ?ukasz Langa date: Mon Dec 31 03:43:37 2012 +0100 summary: Merged `parser.clean()` fix (issue #16820) from 3.2 through 3.3. files: Doc/library/configparser.rst | 8 +++++- Lib/configparser.py | 13 +++++++++++ Lib/test/test_configparser.py | 27 +++++++++++++++++++++++ Misc/ACKS | 1 + 4 files changed, 48 insertions(+), 1 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -389,7 +389,13 @@ the default value to be visible again. Trying to delete a default value causes a ``KeyError``. -* Trying to delete the ``DEFAULTSECT`` raises ``ValueError``. +* ``DEFAULTSECT`` cannot be removed from the parser: + + * trying to delete it raises ``ValueError``, + + * ``parser.clear()`` leaves it intact, + + * ``parser.popitem()`` never returns it. * ``parser.get(section, option, **kwargs)`` - the second argument is **not** a fallback value. Note however that the section-level ``get()`` methods are diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -852,6 +852,19 @@ value_getter = lambda option: d[option] return [(option, value_getter(option)) for option in d.keys()] + def popitem(self): + """Remove a section from the parser and return it as + a (section_name, section_proxy) tuple. If no section is present, raise + KeyError. + + The section DEFAULT is never returned because it cannot be removed. + """ + for key in self.sections(): + value = self[key] + del self[key] + return key, value + raise KeyError + def optionxform(self, optionstr): return optionstr.lower() diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -770,6 +770,33 @@ with self.assertRaises(configparser.NoSectionError): cf.items("no such section") + def test_popitem(self): + cf = self.fromstring(""" + [section1] + name1 {0[0]} value1 + [section2] + name2 {0[0]} value2 + [section3] + name3 {0[0]} value3 + """.format(self.delimiters), defaults={"default": ""}) + self.assertEqual(cf.popitem()[0], 'section1') + self.assertEqual(cf.popitem()[0], 'section2') + self.assertEqual(cf.popitem()[0], 'section3') + with self.assertRaises(KeyError): + cf.popitem() + + def test_clear(self): + cf = self.newconfig({"foo": "Bar"}) + self.assertEqual( + cf.get(self.default_section, "Foo"), "Bar", + "could not locate option, expecting case-insensitive option names") + cf['zing'] = {'option1': 'value1', 'option2': 'value2'} + self.assertEqual(cf.sections(), ['zing']) + self.assertEqual(set(cf['zing'].keys()), {'option1', 'option2', 'foo'}) + cf.clear() + self.assertEqual(set(cf.sections()), set()) + self.assertEqual(set(cf[self.default_section].keys()), {'foo'}) + class StrictTestCase(BasicTestCase): config_class = configparser.RawConfigParser diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1057,6 +1057,7 @@ Andreas Schawo Neil Schemenauer David Scherer +Wolfgang Scherer Hynek Schlawack Bob Schmertz Gregor Schmid -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Dec 31 05:55:03 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 31 Dec 2012 05:55:03 +0100 Subject: [Python-checkins] Daily reference leaks (b4975cb4be95): sum=0 Message-ID: results for b4975cb4be95 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/refloggE7iL3', '-x'] From python-checkins at python.org Mon Dec 31 10:38:33 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 31 Dec 2012 10:38:33 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogSXNzdWUgIzE2ODI0?= =?utf-8?q?=3A_Fix_a_failure_guard_in_the_never_reached_in_the_normal_test?= Message-ID: <3YZYP508Q5zS7x@mail.python.org> http://hg.python.org/cpython/rev/9472928af085 changeset: 81168:9472928af085 branch: 3.3 parent: 81166:4fc2fea807e6 user: Serhiy Storchaka date: Mon Dec 31 11:31:41 2012 +0200 summary: Issue #16824: Fix a failure guard in the never reached in the normal test execution code in test_pep380. files: Lib/test/test_pep380.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_pep380.py b/Lib/test/test_pep380.py --- a/Lib/test/test_pep380.py +++ b/Lib/test/test_pep380.py @@ -519,7 +519,7 @@ next(gi) for x in range(3): y = gi.send(42) - trace.append("Should not have yielded:", y) + trace.append("Should not have yielded: %s" % (y,)) except AttributeError as e: self.assertIn("send", e.args[0]) else: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 10:38:34 2012 From: python-checkins at python.org (serhiy.storchaka) Date: Mon, 31 Dec 2012 10:38:34 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2316824=3A_Fix_a_failure_guard_in_the_never_reach?= =?utf-8?q?ed_in_the_normal_test?= Message-ID: <3YZYP62mhLzS8d@mail.python.org> http://hg.python.org/cpython/rev/66665ef7d9d6 changeset: 81169:66665ef7d9d6 parent: 81167:c6f9bc5a0cf1 parent: 81168:9472928af085 user: Serhiy Storchaka date: Mon Dec 31 11:37:34 2012 +0200 summary: Issue #16824: Fix a failure guard in the never reached in the normal test execution code in test_pep380. Original patch by Stefan Behnel. files: Lib/test/test_pep380.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_pep380.py b/Lib/test/test_pep380.py --- a/Lib/test/test_pep380.py +++ b/Lib/test/test_pep380.py @@ -519,7 +519,7 @@ next(gi) for x in range(3): y = gi.send(42) - trace.append("Should not have yielded:", y) + trace.append("Should not have yielded: %s" % (y,)) except AttributeError as e: self.assertIn("send", e.args[0]) else: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 13:57:41 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 13:57:41 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4zKTogRml4ZXMgYF9fc2V0?= =?utf-8?q?item=5F=5F=60_on_parser=5B=27DEFAULT=27=5D_reported_in_issue_?= =?utf-8?q?=2316820=2E?= Message-ID: <3YZdps6QqlzMwg@mail.python.org> http://hg.python.org/cpython/rev/459a23083b66 changeset: 81170:459a23083b66 branch: 3.3 parent: 81168:9472928af085 user: ?ukasz Langa date: Mon Dec 31 13:55:11 2012 +0100 summary: Fixes `__setitem__` on parser['DEFAULT'] reported in issue #16820. files: Lib/configparser.py | 5 +++- Lib/test/test_configparser.py | 28 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletions(-) diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -960,7 +960,10 @@ # XXX this is not atomic if read_dict fails at any point. Then again, # no update method in configparser is atomic in this implementation. - self.remove_section(key) + if key == self.default_section: + self._defaults.clear() + else: + self.remove_section(key) self.read_dict({key: value}) def __delitem__(self, key): diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -797,6 +797,34 @@ self.assertEqual(set(cf.sections()), set()) self.assertEqual(set(cf[self.default_section].keys()), {'foo'}) + def test_setitem(self): + cf = self.fromstring(""" + [section1] + name1 {0[0]} value1 + [section2] + name2 {0[0]} value2 + [section3] + name3 {0[0]} value3 + """.format(self.delimiters), defaults={"nameD": "valueD"}) + self.assertEqual(set(cf['section1'].keys()), {'name1', 'named'}) + self.assertEqual(set(cf['section2'].keys()), {'name2', 'named'}) + self.assertEqual(set(cf['section3'].keys()), {'name3', 'named'}) + self.assertEqual(cf['section1']['name1'], 'value1') + self.assertEqual(cf['section2']['name2'], 'value2') + self.assertEqual(cf['section3']['name3'], 'value3') + cf['section2'] = {'name22': 'value22'} + self.assertEqual(set(cf['section2'].keys()), {'name22', 'named'}) + self.assertEqual(cf['section2']['name22'], 'value22') + self.assertNotIn('name2', cf['section2']) + cf['section3'] = {} + self.assertEqual(set(cf['section3'].keys()), {'named'}) + self.assertNotIn('name3', cf['section3']) + cf[self.default_section] = {} + self.assertEqual(set(cf[self.default_section].keys()), set()) + self.assertEqual(set(cf['section1'].keys()), {'name1'}) + self.assertEqual(set(cf['section2'].keys()), {'name22'}) + self.assertEqual(set(cf['section3'].keys()), set()) + class StrictTestCase(BasicTestCase): config_class = configparser.RawConfigParser -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 13:57:43 2012 From: python-checkins at python.org (lukasz.langa) Date: Mon, 31 Dec 2012 13:57:43 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?b?KTogTWVyZ2VkIGBwYXJzZXJbJ0RFRkFVTFQnXS5fX3NldGl0ZW1fX2AgZml4?= =?utf-8?q?_=28issue_=2316820=29_from_3=2E3=2E?= Message-ID: <3YZdpv20JKzSBB@mail.python.org> http://hg.python.org/cpython/rev/f6fb5a5748f0 changeset: 81171:f6fb5a5748f0 parent: 81169:66665ef7d9d6 parent: 81170:459a23083b66 user: ?ukasz Langa date: Mon Dec 31 13:57:21 2012 +0100 summary: Merged `parser['DEFAULT'].__setitem__` fix (issue #16820) from 3.3. files: Lib/configparser.py | 5 +++- Lib/test/test_configparser.py | 28 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletions(-) diff --git a/Lib/configparser.py b/Lib/configparser.py --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -960,7 +960,10 @@ # XXX this is not atomic if read_dict fails at any point. Then again, # no update method in configparser is atomic in this implementation. - self.remove_section(key) + if key == self.default_section: + self._defaults.clear() + else: + self.remove_section(key) self.read_dict({key: value}) def __delitem__(self, key): diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py --- a/Lib/test/test_configparser.py +++ b/Lib/test/test_configparser.py @@ -797,6 +797,34 @@ self.assertEqual(set(cf.sections()), set()) self.assertEqual(set(cf[self.default_section].keys()), {'foo'}) + def test_setitem(self): + cf = self.fromstring(""" + [section1] + name1 {0[0]} value1 + [section2] + name2 {0[0]} value2 + [section3] + name3 {0[0]} value3 + """.format(self.delimiters), defaults={"nameD": "valueD"}) + self.assertEqual(set(cf['section1'].keys()), {'name1', 'named'}) + self.assertEqual(set(cf['section2'].keys()), {'name2', 'named'}) + self.assertEqual(set(cf['section3'].keys()), {'name3', 'named'}) + self.assertEqual(cf['section1']['name1'], 'value1') + self.assertEqual(cf['section2']['name2'], 'value2') + self.assertEqual(cf['section3']['name3'], 'value3') + cf['section2'] = {'name22': 'value22'} + self.assertEqual(set(cf['section2'].keys()), {'name22', 'named'}) + self.assertEqual(cf['section2']['name22'], 'value22') + self.assertNotIn('name2', cf['section2']) + cf['section3'] = {} + self.assertEqual(set(cf['section3'].keys()), {'named'}) + self.assertNotIn('name3', cf['section3']) + cf[self.default_section] = {} + self.assertEqual(set(cf[self.default_section].keys()), set()) + self.assertEqual(set(cf['section1'].keys()), {'name1'}) + self.assertEqual(set(cf['section2'].keys()), {'name22'}) + self.assertEqual(set(cf['section3'].keys()), set()) + class StrictTestCase(BasicTestCase): config_class = configparser.RawConfigParser -- Repository URL: http://hg.python.org/cpython From brett at python.org Mon Dec 31 15:35:17 2012 From: brett at python.org (Brett Cannon) Date: Mon, 31 Dec 2012 09:35:17 -0500 Subject: [Python-checkins] peps: Further PEP 432 updates In-Reply-To: <3YZ2nZ4h29zRy8@mail.python.org> References: <3YZ2nZ4h29zRy8@mail.python.org> Message-ID: On Sun, Dec 30, 2012 at 8:39 AM, nick.coghlan wrote: > [SNIP] > The ``-E`` command line option allows all environment variables to be > -ignored when initialising the Python interpreter. An embedding application > +ignored when initializing the Python interpreter. An embedding application > can enable this behaviour by setting ``Py_IgnoreEnvironmentFlag`` before > calling ``Py_Initialize()``. > > In the CPython source code, the ``Py_GETENV`` macro implicitly checks this > flag, and always produces ``NULL`` if it is set. > > + > > > That is true and that is a bug. =) http://bugs.python.org/issue16826 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Mon Dec 31 16:45:11 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 31 Dec 2012 16:45:11 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?peps=3A_Claim_the_packaging_PEPs_=28a?= =?utf-8?q?nd_strip_trailing_whitespace=29?= Message-ID: <3YZjX76lGHzS4N@mail.python.org> http://hg.python.org/peps/rev/7f88cb558d79 changeset: 4645:7f88cb558d79 user: Nick Coghlan date: Tue Jan 01 01:45:03 2013 +1000 summary: Claim the packaging PEPs (and strip trailing whitespace) files: pep-0425.txt | 7 ++++--- pep-0426.txt | 23 ++++++++++++----------- pep-0427.txt | 5 +++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pep-0425.txt b/pep-0425.txt --- a/pep-0425.txt +++ b/pep-0425.txt @@ -1,8 +1,9 @@ PEP: 425 -Title: Compatibility Tags for Built Distributions +Title: Compatibility Tags for Built Distributions Version: $Revision$ Last-Modified: 07-Aug-2012 Author: Daniel Holth +BDFL-Delegate: Nick Coghlan Status: Draft Type: Standards Track Content-Type: text/x-rst @@ -216,7 +217,7 @@ Who will maintain the registry of abbreviated implementations? New two-letter abbreviations can be requested on the python-dev mailing list. As a rule of thumb, abbreviations are reserved for - the current 4 most prominent implementations. + the current 4 most prominent implementations. Does the compatibility tag go into METADATA or PKG-INFO? No. The compatibility tag is part of the built distribution's @@ -253,7 +254,7 @@ This document has been placed in the public domain. - + .. Local Variables: mode: indented-text diff --git a/pep-0426.txt b/pep-0426.txt --- a/pep-0426.txt +++ b/pep-0426.txt @@ -3,6 +3,7 @@ Version: $Revision$ Last-Modified: $Date$ Author: Daniel Holth +BDFL-Delegate: Nick Coghlan Discussions-To: Distutils SIG Status: Draft Type: Standards Track @@ -618,7 +619,7 @@ - Extension - Provides-Extra - Setup-Requires-Dist - + References ========== @@ -643,15 +644,15 @@ # Metadata 1.3 demo from email.generator import Generator - from email import header - from email.parser import Parser - from email.policy import Compat32 + from email import header + from email.parser import Parser + from email.policy import Compat32 from email.utils import _has_surrogates class MetadataPolicy(Compat32): max_line_length = 0 continuation_whitespace = '\t' - + def _sanitize_header(self, name, value): if not isinstance(value, str): return value @@ -676,8 +677,8 @@ Summary: A package. Description: Description =========== - - + + A description of the package. """ @@ -687,9 +688,9 @@ m['License'] = 'GPL' description = m['Description'] description_lines = description.splitlines() - m.set_payload(description_lines[0] - + '\n' - + textwrap.dedent('\n'.join(description_lines[1:])) + m.set_payload(description_lines[0] + + '\n' + + textwrap.dedent('\n'.join(description_lines[1:])) + '\n') del m['Description'] @@ -701,7 +702,7 @@ This document has been placed in the public domain. - + .. Local Variables: mode: indented-text diff --git a/pep-0427.txt b/pep-0427.txt --- a/pep-0427.txt +++ b/pep-0427.txt @@ -3,6 +3,7 @@ Version: $Revision$ Last-Modified: $Date$ Author: Daniel Holth +BDFL-Delegate: Nick Coghlan Discussions-To: Status: Draft Type: Standards Track @@ -319,7 +320,7 @@ ======== Example urlsafe-base64-nopad implementation:: - + # urlsafe-base64-nopad for Python 3 import base64 @@ -337,7 +338,7 @@ This document has been placed into the public domain. - + .. Local Variables: mode: indented-text -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Mon Dec 31 17:40:02 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 31 Dec 2012 17:40:02 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_issue_1052?= =?utf-8?q?7=3A_make_multiprocessing_use_poll=28=29_instead_of_select=28?= =?utf-8?q?=29_if?= Message-ID: <3YZklQ5lXJzP21@mail.python.org> http://hg.python.org/cpython/rev/5530251d9cac changeset: 81172:5530251d9cac branch: 3.2 parent: 81165:0786dfc3b2b4 user: Giampaolo Rodola' date: Mon Dec 31 17:23:09 2012 +0100 summary: Fix issue 10527: make multiprocessing use poll() instead of select() if available. files: Lib/multiprocessing/connection.py | 21 +++++++++++++++++++ Lib/test/test_multiprocessing.py | 1 + Misc/NEWS | 2 + 3 files changed, 24 insertions(+), 0 deletions(-) diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -213,6 +213,27 @@ return c1, c2 else: + if hasattr(select, 'poll'): + def _poll(fds, timeout): + if timeout is not None: + timeout = int(timeout) * 1000 # timeout is in milliseconds + fd_map = {} + pollster = select.poll() + for fd in fds: + pollster.register(fd, select.POLLIN) + if hasattr(fd, 'fileno'): + fd_map[fd.fileno()] = fd + else: + fd_map[fd] = fd + ls = [] + for fd, event in pollster.poll(timeout): + if event & select.POLLNVAL: + raise ValueError('invalid file descriptor %i' % fd) + ls.append(fd_map[fd]) + return ls + else: + def _poll(fds, timeout): + return select.select(fds, [], [], timeout)[0] from _multiprocessing import win32 diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1574,6 +1574,7 @@ self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1) conn.send(None) + time.sleep(.1) self.assertEqual(poll(TIMEOUT1), True) self.assertTimingAlmostEqual(poll.elapsed, 0) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -189,6 +189,8 @@ Library ------- +- Issue 10527: make multiprocessing use poll() instead of select() if available. + - Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 17:40:04 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 31 Dec 2012 17:40:04 +0100 (CET) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMyk6?= =?utf-8?q?_Fix_issue_10527=3A_make_multiprocessing_use_poll=28=29_instead?= =?utf-8?q?_of_select=28=29_if?= Message-ID: <3YZklS1VMPzSC9@mail.python.org> http://hg.python.org/cpython/rev/d89891f3f769 changeset: 81173:d89891f3f769 branch: 3.3 parent: 81170:459a23083b66 parent: 81172:5530251d9cac user: Giampaolo Rodola' date: Mon Dec 31 17:38:17 2012 +0100 summary: Fix issue 10527: make multiprocessing use poll() instead of select() if available. files: Lib/multiprocessing/connection.py | 21 +++++++++++++++++++ Lib/test/test_multiprocessing.py | 6 +++- Misc/NEWS | 2 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -509,6 +509,27 @@ return c1, c2 else: + if hasattr(select, 'poll'): + def _poll(fds, timeout): + if timeout is not None: + timeout = int(timeout) * 1000 # timeout is in milliseconds + fd_map = {} + pollster = select.poll() + for fd in fds: + pollster.register(fd, select.POLLIN) + if hasattr(fd, 'fileno'): + fd_map[fd.fileno()] = fd + else: + fd_map[fd] = fd + ls = [] + for fd, event in pollster.poll(timeout): + if event & select.POLLNVAL: + raise ValueError('invalid file descriptor %i' % fd) + ls.append(fd_map[fd]) + return ls + else: + def _poll(fds, timeout): + return select.select(fds, [], [], timeout)[0] def Pipe(duplex=True): ''' diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -2127,6 +2127,7 @@ self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1) conn.send(None) + time.sleep(.1) self.assertEqual(poll(TIMEOUT1), True) self.assertTimingAlmostEqual(poll.elapsed, 0) @@ -3232,6 +3233,7 @@ from multiprocessing.connection import wait expected = 3 + sorted_ = lambda l: sorted(l, key=lambda x: isinstance(x, int)) sem = multiprocessing.Semaphore(0) a, b = multiprocessing.Pipe() p = multiprocessing.Process(target=self.signal_and_sleep, @@ -3255,7 +3257,7 @@ res = wait([a, p.sentinel, b], 20) delta = time.time() - start - self.assertEqual(res, [p.sentinel, b]) + self.assertEqual(sorted_(res), sorted_([p.sentinel, b])) self.assertLess(delta, 0.4) b.send(None) @@ -3264,7 +3266,7 @@ res = wait([a, p.sentinel, b], 20) delta = time.time() - start - self.assertEqual(res, [a, p.sentinel, b]) + self.assertEqual(sorted_(res), sorted_([a, p.sentinel, b])) self.assertLess(delta, 0.4) p.terminate() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -124,6 +124,8 @@ Library ------- +- Issue 10527: make multiprocessing use poll() instead of select() if available. + - Issue #16688: Fix backreferences did make case-insensitive regex fail on non-ASCII strings. Patch by Matthew Barnett. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 17:40:05 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 31 Dec 2012 17:40:05 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E3_-=3E_default?= =?utf-8?q?=29=3A_Fix_issue_10527=3A_make_multiprocessing_use_poll=28=29_i?= =?utf-8?q?nstead_of_select=28=29_if?= Message-ID: <3YZklT3wyczSC9@mail.python.org> http://hg.python.org/cpython/rev/e971a70984b8 changeset: 81174:e971a70984b8 parent: 81171:f6fb5a5748f0 parent: 81173:d89891f3f769 user: Giampaolo Rodola' date: Mon Dec 31 17:38:46 2012 +0100 summary: Fix issue 10527: make multiprocessing use poll() instead of select() if available. files: Lib/multiprocessing/connection.py | 21 +++++++++++++++++++ Lib/test/test_multiprocessing.py | 6 +++- Misc/NEWS | 2 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -509,6 +509,27 @@ return c1, c2 else: + if hasattr(select, 'poll'): + def _poll(fds, timeout): + if timeout is not None: + timeout = int(timeout) * 1000 # timeout is in milliseconds + fd_map = {} + pollster = select.poll() + for fd in fds: + pollster.register(fd, select.POLLIN) + if hasattr(fd, 'fileno'): + fd_map[fd.fileno()] = fd + else: + fd_map[fd] = fd + ls = [] + for fd, event in pollster.poll(timeout): + if event & select.POLLNVAL: + raise ValueError('invalid file descriptor %i' % fd) + ls.append(fd_map[fd]) + return ls + else: + def _poll(fds, timeout): + return select.select(fds, [], [], timeout)[0] def Pipe(duplex=True): ''' diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -2102,6 +2102,7 @@ self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1) conn.send(None) + time.sleep(.1) self.assertEqual(poll(TIMEOUT1), True) self.assertTimingAlmostEqual(poll.elapsed, 0) @@ -3251,6 +3252,7 @@ from multiprocessing.connection import wait expected = 3 + sorted_ = lambda l: sorted(l, key=lambda x: isinstance(x, int)) sem = multiprocessing.Semaphore(0) a, b = multiprocessing.Pipe() p = multiprocessing.Process(target=self.signal_and_sleep, @@ -3274,7 +3276,7 @@ res = wait([a, p.sentinel, b], 20) delta = time.time() - start - self.assertEqual(res, [p.sentinel, b]) + self.assertEqual(sorted_(res), sorted_([p.sentinel, b])) self.assertLess(delta, 0.4) b.send(None) @@ -3283,7 +3285,7 @@ res = wait([a, p.sentinel, b], 20) delta = time.time() - start - self.assertEqual(res, [a, p.sentinel, b]) + self.assertEqual(sorted_(res), sorted_([a, p.sentinel, b])) self.assertLess(delta, 0.4) p.terminate() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -200,6 +200,8 @@ Library ------- +- Issue 10527: make multiprocessing use poll() instead of select() if available. + - Issue #16688: Fix backreferences did make case-insensitive regex fail on non-ASCII strings. Patch by Matthew Barnett. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 17:44:39 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Mon, 31 Dec 2012 17:44:39 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_issue_1052?= =?utf-8?q?7=3A_make_multiprocessing_use_poll=28=29_instead_of_select=28?= =?utf-8?q?=29_if?= Message-ID: <3YZkrl6tYbzS78@mail.python.org> http://hg.python.org/cpython/rev/c5c27b84d7af changeset: 81175:c5c27b84d7af branch: 2.7 parent: 81155:503b889668fc user: Giampaolo Rodola' date: Mon Dec 31 17:23:09 2012 +0100 summary: Fix issue 10527: make multiprocessing use poll() instead of select() if available. files: Lib/multiprocessing/connection.py | 21 +++++++++++++++++++ Lib/test/test_multiprocessing.py | 1 + Misc/NEWS | 2 + 3 files changed, 24 insertions(+), 0 deletions(-) diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -200,6 +200,27 @@ return c1, c2 else: + if hasattr(select, 'poll'): + def _poll(fds, timeout): + if timeout is not None: + timeout = int(timeout) * 1000 # timeout is in milliseconds + fd_map = {} + pollster = select.poll() + for fd in fds: + pollster.register(fd, select.POLLIN) + if hasattr(fd, 'fileno'): + fd_map[fd.fileno()] = fd + else: + fd_map[fd] = fd + ls = [] + for fd, event in pollster.poll(timeout): + if event & select.POLLNVAL: + raise ValueError('invalid file descriptor %i' % fd) + ls.append(fd_map[fd]) + return ls + else: + def _poll(fds, timeout): + return select.select(fds, [], [], timeout)[0] from _multiprocessing import win32 diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -1513,6 +1513,7 @@ self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1) conn.send(None) + time.sleep(.1) self.assertEqual(poll(TIMEOUT1), True) self.assertTimingAlmostEqual(poll.elapsed, 0) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -175,6 +175,8 @@ Library ------- +- Issue 10527: make multiprocessing use poll() instead of select() if available. + - Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Dec 31 19:00:06 2012 From: python-checkins at python.org (brian.curtin) Date: Mon, 31 Dec 2012 19:00:06 +0100 (CET) Subject: [Python-checkins] =?utf-8?q?cpython=3A_st=5Fdev/st=5Frdev_should_?= =?utf-8?q?be_unsigned_long_as_dwVolumeSerialNumber=2C_which_it_is_set?= Message-ID: <3YZmWp0BRnzSCh@mail.python.org> http://hg.python.org/cpython/rev/3738d270c54a changeset: 81176:3738d270c54a parent: 81174:e971a70984b8 user: Brian Curtin date: Mon Dec 31 11:59:48 2012 -0600 summary: st_dev/st_rdev should be unsigned long as dwVolumeSerialNumber, which it is set to, is a DWORD. This was fixed in #11939 and the overflow was mentioned in #10657 and seen by me on some machines. files: Modules/posixmodule.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1184,13 +1184,13 @@ #define HAVE_STAT_NSEC 1 struct win32_stat{ - int st_dev; + unsigned long st_dev; __int64 st_ino; unsigned short st_mode; int st_nlink; int st_uid; int st_gid; - int st_rdev; + unsigned long st_rdev; __int64 st_size; time_t st_atime; int st_atime_nsec; -- Repository URL: http://hg.python.org/cpython