From python-checkins at python.org Wed Aug 1 03:58:09 2012 From: python-checkins at python.org (jesus.cea) Date: Wed, 1 Aug 2012 03:58:09 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Closes_=2315499=3A_Sleep_i?= =?utf-8?q?s_hardcoded_in_webbrowser=2EUnixBrowser?= Message-ID: <3WmyN10MgmzPc5@mail.python.org> http://hg.python.org/cpython/rev/a16403affccd changeset: 78362:a16403affccd user: Jesus Cea date: Wed Aug 01 03:57:52 2012 +0200 summary: Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser files: Lib/webbrowser.py | 17 +++++++---------- Misc/NEWS | 3 +++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -232,17 +232,14 @@ stdout=(self.redirect_stdout and inout or None), stderr=inout, start_new_session=True) if remote: - # wait five seconds. If the subprocess is not finished, the + # wait at most five seconds. If the subprocess is not finished, the # remote invocation has (hopefully) started a new instance. - time.sleep(1) - rc = p.poll() - if rc is None: - time.sleep(4) - rc = p.poll() - if rc is None: - return True - # if remote call failed, open() will try direct invocation - return not rc + try: + rc = p.wait(5) + # if remote call failed, open() will try direct invocation + return not rc + except subprocess.TimeoutExpired: + return True elif self.background: if p.poll() is None: return True diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -72,6 +72,9 @@ Library ------- +- Issue #15499: Launching a webbrowser in Unix used to sleep for a few + seconds. Original patch by Anton Barkovsky. + - Issue #15463: the faulthandler module truncates strings to 500 characters, instead of 100, to be able to display long file paths -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Aug 1 06:00:43 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 01 Aug 2012 06:00:43 +0200 Subject: [Python-checkins] Daily reference leaks (b213894e0859): sum=0 Message-ID: results for b213894e0859 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogE2tNjp', '-x'] From python-checkins at python.org Wed Aug 1 06:50:18 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 1 Aug 2012 06:50:18 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_construct_fields_in_the_ri?= =?utf-8?q?ght_order_=28closes_=2315517=29?= Message-ID: <3Wn2Bf1rMPzMVq@mail.python.org> http://hg.python.org/cpython/rev/cbfb915424fd changeset: 78363:cbfb915424fd parent: 78361:b213894e0859 user: Benjamin Peterson date: Tue Jul 31 21:41:56 2012 -0700 summary: construct fields in the right order (closes #15517) Patch from Taihyun Hwang. files: Misc/ACKS | 2 +- Parser/asdl.py | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -476,6 +476,7 @@ Jim Hugunin Greg Humphreys Eric Huss +Taihyun Hwang Jeremy Hylton Gerhard H?ring Fredrik H??rd @@ -1174,4 +1175,3 @@ Kai Zhu Tarek Ziad? Peter ?strand - diff --git a/Parser/asdl.py b/Parser/asdl.py --- a/Parser/asdl.py +++ b/Parser/asdl.py @@ -156,15 +156,11 @@ if id.value != "attributes": raise ASDLSyntaxError(id.lineno, msg="expected attributes, found %s" % id) - if attributes: - attributes.reverse() return Sum(sum, attributes) def p_product(self, info): " product ::= ( fields ) " _0, fields, _1 = info - # XXX can't I just construct things in the right order? - fields.reverse() return Product(fields) def p_sum_0(self, constructor): @@ -188,8 +184,6 @@ def p_constructor_1(self, info): " constructor ::= Id ( fields ) " id, _0, fields, _1 = info - # XXX can't I just construct things in the right order? - fields.reverse() return Constructor(id, fields) def p_fields_0(self, field): @@ -197,8 +191,8 @@ return [field[0]] def p_fields_1(self, info): - " fields ::= field , fields " - field, _, fields = info + " fields ::= fields , field " + fields, _, field = info return fields + [field] def p_field_0(self, type_): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 06:50:19 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 1 Aug 2012 06:50:19 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3Wn2Bg6jtRzMVq@mail.python.org> http://hg.python.org/cpython/rev/c58f65e22fe9 changeset: 78364:c58f65e22fe9 parent: 78363:cbfb915424fd parent: 78362:a16403affccd user: Benjamin Peterson date: Tue Jul 31 21:50:11 2012 -0700 summary: merge heads files: Lib/webbrowser.py | 17 +++++++---------- Misc/NEWS | 3 +++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -232,17 +232,14 @@ stdout=(self.redirect_stdout and inout or None), stderr=inout, start_new_session=True) if remote: - # wait five seconds. If the subprocess is not finished, the + # wait at most five seconds. If the subprocess is not finished, the # remote invocation has (hopefully) started a new instance. - time.sleep(1) - rc = p.poll() - if rc is None: - time.sleep(4) - rc = p.poll() - if rc is None: - return True - # if remote call failed, open() will try direct invocation - return not rc + try: + rc = p.wait(5) + # if remote call failed, open() will try direct invocation + return not rc + except subprocess.TimeoutExpired: + return True elif self.background: if p.poll() is None: return True diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -72,6 +72,9 @@ Library ------- +- Issue #15499: Launching a webbrowser in Unix used to sleep for a few + seconds. Original patch by Anton Barkovsky. + - Issue #15463: the faulthandler module truncates strings to 500 characters, instead of 100, to be able to display long file paths -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 10:06:38 2012 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Aug 2012 10:06:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzg4NDc6?= =?utf-8?q?_Disable_COMDAT_folding_in_Windows_PGO_builds=2E?= Message-ID: <3Wn6YB3S9FzNbw@mail.python.org> http://hg.python.org/cpython/rev/5a8c5631463f changeset: 78365:5a8c5631463f branch: 2.7 parent: 78350:8f1a8e80f330 user: Martin v. L?wis date: Wed Aug 01 10:05:27 2012 +0200 summary: Issue #8847: Disable COMDAT folding in Windows PGO builds. files: Misc/NEWS | 2 ++ PCbuild/pginstrument.vsprops | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -315,6 +315,8 @@ Build ----- +- Issue #8847: Disable COMDAT folding in Windows PGO builds. + - Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. - Issue #8767: Restore building with --disable-unicode. diff --git a/PCbuild/pginstrument.vsprops b/PCbuild/pginstrument.vsprops --- a/PCbuild/pginstrument.vsprops +++ b/PCbuild/pginstrument.vsprops @@ -22,7 +22,7 @@ http://hg.python.org/cpython/rev/2638ce032151 changeset: 78366:2638ce032151 branch: 3.2 parent: 78348:47536beb7453 user: Martin v. L?wis date: Wed Aug 01 10:32:11 2012 +0200 summary: Issue #8847: Disable COMDAT folding in Windows PGO builds. Analysis by Victor Stinner. Patch by Stefan Krah. files: Lib/test/test_list.py | 8 ++++++++ Lib/test/test_tuple.py | 8 ++++++++ Misc/NEWS | 2 ++ PCbuild/pginstrument.vsprops | 2 +- 4 files changed, 19 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -70,6 +70,14 @@ check(1000000) + def test_no_comdat_folding(self): + # Issue 8847: In the PGO build, the MSVC linker's COMDAT folding + # optimization causes failures in code that relies on distinct + # function addresses. + class L(list): pass + with self.assertRaises(TypeError): + (3,) + L([1,2]) + def test_main(verbose=None): support.run_unittest(ListTest) diff --git a/Lib/test/test_tuple.py b/Lib/test/test_tuple.py --- a/Lib/test/test_tuple.py +++ b/Lib/test/test_tuple.py @@ -164,6 +164,14 @@ check(10) # check our checking code check(1000000) + def test_no_comdat_folding(self): + # Issue 8847: In the PGO build, the MSVC linker's COMDAT folding + # optimization causes failures in code that relies on distinct + # function addresses. + class T(tuple): pass + with self.assertRaises(TypeError): + [3,] + T((1,2)) + def test_main(): support.run_unittest(TupleTest) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -425,6 +425,8 @@ Build ----- +- Issue #8847: Disable COMDAT folding in Windows PGO builds. + - Issue #14197: For OS X framework builds, ensure links to the shared library are created with the proper ABI suffix. diff --git a/PCbuild/pginstrument.vsprops b/PCbuild/pginstrument.vsprops --- a/PCbuild/pginstrument.vsprops +++ b/PCbuild/pginstrument.vsprops @@ -22,7 +22,7 @@ http://hg.python.org/cpython/rev/029cde4e58c5 changeset: 78367:029cde4e58c5 parent: 78364:c58f65e22fe9 user: Martin v. L?wis date: Wed Aug 01 11:06:53 2012 +0200 summary: Issue #8847: Disable COMDAT folding in Windows PGO builds. Patch by Stefan Krah. files: PCbuild/pginstrument.props | 4 ++-- PCbuild/pylauncher.vcxproj | 14 +++++++------- PCbuild/pywlauncher.vcxproj | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/PCbuild/pginstrument.props b/PCbuild/pginstrument.props --- a/PCbuild/pginstrument.props +++ b/PCbuild/pginstrument.props @@ -24,7 +24,7 @@ true - true + false PGInstrument $(SolutionDir)$(Platform)-pgi\$(TargetName).pgd $(OutDirPGI)\$(TargetName).lib @@ -35,4 +35,4 @@ $(OutDirPGI) - \ No newline at end of file + diff --git a/PCbuild/pylauncher.vcxproj b/PCbuild/pylauncher.vcxproj --- a/PCbuild/pylauncher.vcxproj +++ b/PCbuild/pylauncher.vcxproj @@ -199,7 +199,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -216,7 +216,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -233,7 +233,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -250,7 +250,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -267,7 +267,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -284,7 +284,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -308,4 +308,4 @@ - \ No newline at end of file + diff --git a/PCbuild/pywlauncher.vcxproj b/PCbuild/pywlauncher.vcxproj --- a/PCbuild/pywlauncher.vcxproj +++ b/PCbuild/pywlauncher.vcxproj @@ -143,7 +143,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -160,7 +160,7 @@ true - true + false true false version.lib;%(AdditionalDependencies) @@ -199,4 +199,4 @@ - \ No newline at end of file + -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 11:11:13 2012 From: python-checkins at python.org (martin.v.loewis) Date: Wed, 1 Aug 2012 11:11:13 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=238847=3A_Merge_with_3=2E2?= Message-ID: <3Wn7zj2wy0zPff@mail.python.org> http://hg.python.org/cpython/rev/d3afe5d8a4da changeset: 78368:d3afe5d8a4da parent: 78367:029cde4e58c5 parent: 78366:2638ce032151 user: Martin v. L?wis date: Wed Aug 01 11:09:55 2012 +0200 summary: Issue #8847: Merge with 3.2 files: Lib/test/test_list.py | 8 ++++++++ Lib/test/test_tuple.py | 8 ++++++++ Misc/NEWS | 2 ++ PC/VS9.0/pginstrument.vsprops | 2 +- 4 files changed, 19 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -98,6 +98,14 @@ d = pickle.dumps(it) self.assertEqual(self.type2test(it), self.type2test(reversed(data))[1:]) + def test_no_comdat_folding(self): + # Issue 8847: In the PGO build, the MSVC linker's COMDAT folding + # optimization causes failures in code that relies on distinct + # function addresses. + class L(list): pass + with self.assertRaises(TypeError): + (3,) + L([1,2]) + def test_main(verbose=None): support.run_unittest(ListTest) diff --git a/Lib/test/test_tuple.py b/Lib/test/test_tuple.py --- a/Lib/test/test_tuple.py +++ b/Lib/test/test_tuple.py @@ -193,6 +193,14 @@ d = pickle.dumps(it) self.assertEqual(self.type2test(it), self.type2test(reversed(data))[1:]) + def test_no_comdat_folding(self): + # Issue 8847: In the PGO build, the MSVC linker's COMDAT folding + # optimization causes failures in code that relies on distinct + # function addresses. + class T(tuple): pass + with self.assertRaises(TypeError): + [3,] + T((1,2)) + def test_main(): support.run_unittest(TupleTest) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -276,6 +276,8 @@ Build ----- +- Issue #8847: Disable COMDAT folding in Windows PGO builds. + - Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. - Issue #15431: Add _freeze_importlib project to regenerate importlib.h diff --git a/PC/VS9.0/pginstrument.vsprops b/PC/VS9.0/pginstrument.vsprops --- a/PC/VS9.0/pginstrument.vsprops +++ b/PC/VS9.0/pginstrument.vsprops @@ -22,7 +22,7 @@ http://hg.python.org/cpython/rev/7e438f088129 changeset: 78369:7e438f088129 user: Antoine Pitrou date: Wed Aug 01 14:53:16 2012 +0200 summary: Clarify that hash randomization is on by default files: Doc/using/cmdline.rst | 31 +++++++++++++++---------------- 1 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -229,23 +229,22 @@ .. cmdoption:: -R - Turn on hash randomization, so that the :meth:`__hash__` values of str, bytes - and datetime objects are "salted" with an unpredictable random value. - Although they remain constant within an individual Python process, they are - not predictable between repeated invocations of Python. + Kept for compatibility. On Python 3.3 and greater, hash randomization is + turned on by default. - This is intended to provide protection against a denial-of-service caused by - carefully-chosen inputs that exploit the worst case performance of a dict - construction, O(n^2) complexity. See + On previous versions of Python, this option turns on hash randomization, + so that the :meth:`__hash__` values of str, bytes and datetime + are "salted" with an unpredictable random value. Although they remain + constant within an individual Python process, they are not predictable + between repeated invocations of Python. + + Hash randomization is intended to provide protection against a + denial-of-service caused by carefully-chosen inputs that exploit the worst + case performance of a dict construction, O(n^2) complexity. See http://www.ocert.org/advisories/ocert-2011-003.html for details. - Changing hash values affects the order in which keys are retrieved from a - dict. Although Python has never made guarantees about this ordering (and it - typically varies between 32-bit and 64-bit builds), enough real-world code - implicitly relies on this non-guaranteed behavior that the randomization is - disabled by default. - - See also :envvar:`PYTHONHASHSEED`. + :envvar:`PYTHONHASHSEED` allows you to set a fixed value for the hash + seed secret. .. versionadded:: 3.2.3 @@ -486,8 +485,8 @@ .. envvar:: PYTHONHASHSEED - If this variable is set to ``random``, a random value is used to seed the - hashes of str, bytes and datetime objects. + If this variable is not set or set to ``random``, a random value is used + to seed the hashes of str, bytes and datetime objects. If :envvar:`PYTHONHASHSEED` is set to an integer value, it is used as a fixed seed for generating the hash() of the types covered by the hash -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 14:55:54 2012 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 1 Aug 2012 14:55:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Improve_wording_for_=5F=5F?= =?utf-8?b?aGFzaF9f?= Message-ID: <3WnDyy6vwXzPfN@mail.python.org> http://hg.python.org/cpython/rev/2dd1b056d663 changeset: 78370:2dd1b056d663 user: Antoine Pitrou date: Wed Aug 01 14:53:22 2012 +0200 summary: Improve wording for __hash__ files: Doc/reference/datamodel.rst | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1291,7 +1291,7 @@ .. note:: - Note by default the :meth:`__hash__` values of str, bytes and datetime + By default, the :meth:`__hash__` values of str, bytes and datetime objects are "salted" with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python. @@ -1301,9 +1301,9 @@ dict insertion, O(n^2) complexity. See http://www.ocert.org/advisories/ocert-2011-003.html for details. - Changing hash values affects the order in which keys are retrieved from a - dict. Note Python has never made guarantees about this ordering (and it - typically varies between 32-bit and 64-bit builds). + Changing hash values affects the iteration order of dicts, sets and + other mappings. Python has never made guarantees about this ordering + (and it typically varies between 32-bit and 64-bit builds). See also :envvar:`PYTHONHASHSEED`. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 18:45:00 2012 From: python-checkins at python.org (richard.oudkerk) Date: Wed, 1 Aug 2012 18:45:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315525=3A_Increase?= =?utf-8?q?_timeout_when_TerminateProcess=28=29_fails?= Message-ID: <3WnL3J1MPCzPjP@mail.python.org> http://hg.python.org/cpython/rev/b99a82bc2cde changeset: 78371:b99a82bc2cde user: Richard Oudkerk date: Wed Aug 01 17:44:18 2012 +0100 summary: Issue #15525: Increase timeout when TerminateProcess() fails files: Lib/multiprocessing/forking.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py +++ b/Lib/multiprocessing/forking.py @@ -273,8 +273,8 @@ if self.returncode is None: try: _winapi.TerminateProcess(int(self._handle), TERMINATE) - except WindowsError: - if self.wait(timeout=0.1) is None: + except OSError: + if self.wait(timeout=1.0) is None: raise # -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 19:45:34 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 1 Aug 2012 19:45:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_the_user_signal_handle?= =?utf-8?q?r_of_faulthandler?= Message-ID: <3WnMPB6xNszPgL@mail.python.org> http://hg.python.org/cpython/rev/2dd1aaf41319 changeset: 78372:2dd1aaf41319 user: Victor Stinner date: Wed Aug 01 19:36:36 2012 +0200 summary: Fix the user signal handler of faulthandler Don't exit the tstate is NULL to restore the errno and chain the signal handler if needed. files: Modules/faulthandler.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -653,9 +653,8 @@ if (user->all_threads) _Py_DumpTracebackThreads(user->fd, user->interp, tstate); else { - if (tstate == NULL) - return; - _Py_DumpTraceback(user->fd, tstate); + if (tstate != NULL) + _Py_DumpTraceback(user->fd, tstate); } #ifdef HAVE_SIGACTION if (user->chain) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 19:49:38 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 1 Aug 2012 19:49:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315463=3A_Write_a_?= =?utf-8?q?test_for_faulthandler_truncating_the_name_of_functions?= Message-ID: <3WnMTt0JT0zPgV@mail.python.org> http://hg.python.org/cpython/rev/6e03f9b72c61 changeset: 78373:6e03f9b72c61 user: Victor Stinner date: Wed Aug 01 19:45:34 2012 +0200 summary: Issue #15463: Write a test for faulthandler truncating the name of functions to 500 characters. files: Lib/test/test_faulthandler.py | 24 +++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -316,6 +316,30 @@ with temporary_filename() as filename: self.check_dump_traceback(filename) + def test_truncate(self): + maxlen = 500 + func_name = 'x' * (maxlen + 50) + truncated = 'x' * maxlen + '...' + code = """ +import faulthandler + +def {func_name}(): + faulthandler.dump_traceback(all_threads=False) + +{func_name}() +""".strip() + code = code.format( + func_name=func_name, + ) + expected = [ + 'Traceback (most recent call first):', + ' File "", line 4 in %s' % truncated, + ' File "", line 6 in ' + ] + trace, exitcode = self.get_output(code) + self.assertEqual(trace, expected) + self.assertEqual(exitcode, 0) + @unittest.skipIf(not HAVE_THREADS, 'need threads') def check_dump_traceback_threads(self, filename): """ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 20:07:53 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 1 Aug 2012 20:07:53 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315441=3A_Skip_tes?= =?utf-8?q?t=5Fnonascii=5Fabspath=28=29_of_test=5Fgenericpath_on_Windows?= Message-ID: <3WnMtx2RY1zPgX@mail.python.org> http://hg.python.org/cpython/rev/3edc71ed19e7 changeset: 78374:3edc71ed19e7 user: Victor Stinner date: Wed Aug 01 20:03:49 2012 +0200 summary: Issue #15441: Skip test_nonascii_abspath() of test_genericpath on Windows if the bytes filenames cannot be encoded from the file system (ANSI) code page files: Lib/test/test_genericpath.py | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 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 @@ -299,8 +299,7 @@ unicwd = '\xe7w\xf0' try: - fsencoding = support.TESTFN_ENCODING or "ascii" - unicwd.encode(fsencoding) + os.fsencode(unicwd) except (AttributeError, UnicodeEncodeError): # FS encoding is probably ASCII pass @@ -312,10 +311,19 @@ @unittest.skipIf(sys.platform == 'darwin', "Mac OS X denies the creation of a directory with an invalid utf8 name") def test_nonascii_abspath(self): + name = b'\xe7w\xf0' + if sys.platform == 'win32': + try: + os.fsdecode(name) + except UnicodeDecodeError: + self.skipTest("the filename %a is not decodable " + "from the ANSI code page %s" + % (name, sys.getfilesystemencoding())) + # Test non-ASCII, non-UTF8 bytes in the path. with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) - with support.temp_cwd(b'\xe7w\xf0'): + with support.temp_cwd(name): self.test_abspath() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 1 20:16:49 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 1 Aug 2012 20:16:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_findnocoding=2Ep_and_p?= =?utf-8?q?ysource=2Epy_scripts?= Message-ID: <3WnN5F1BX5zPgm@mail.python.org> http://hg.python.org/cpython/rev/67d36e8ddcfc changeset: 78375:67d36e8ddcfc user: Victor Stinner date: Wed Aug 01 20:12:51 2012 +0200 summary: Fix findnocoding.p and pysource.py scripts I suppose that these scripts didn't work since Python 3.0. files: Tools/scripts/findnocoding.py | 22 +++++++++++----------- Tools/scripts/pysource.py | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Tools/scripts/findnocoding.py b/Tools/scripts/findnocoding.py --- a/Tools/scripts/findnocoding.py +++ b/Tools/scripts/findnocoding.py @@ -32,7 +32,7 @@ "no sophisticated Python source file search will be done.", file=sys.stderr) -decl_re = re.compile(r"coding[=:]\s*([-\w.]+)") +decl_re = re.compile(rb"coding[=:]\s*([-\w.]+)") def get_declaration(line): match = decl_re.search(line) @@ -50,21 +50,21 @@ def needs_declaration(fullpath): try: - infile = open(fullpath) + infile = open(fullpath, 'rb') except IOError: # Oops, the file was removed - ignore it return None - line1 = infile.readline() - line2 = infile.readline() + with infile: + line1 = infile.readline() + line2 = infile.readline() - if get_declaration(line1) or get_declaration(line2): - # the file does have an encoding declaration, so trust it - infile.close() - return False + if get_declaration(line1) or get_declaration(line2): + # the file does have an encoding declaration, so trust it + infile.close() + return False - # check the whole file for non utf-8 characters - rest = infile.read() - infile.close() + # check the whole file for non utf-8 characters + rest = infile.read() if has_correct_encoding(line1+line2+rest, "utf-8"): return False diff --git a/Tools/scripts/pysource.py b/Tools/scripts/pysource.py --- a/Tools/scripts/pysource.py +++ b/Tools/scripts/pysource.py @@ -22,7 +22,7 @@ import os, re -binary_re = re.compile('[\x00-\x08\x0E-\x1F\x7F]') +binary_re = re.compile(br'[\x00-\x08\x0E-\x1F\x7F]') debug = False @@ -42,7 +42,7 @@ return None try: - return open(fullpath) + return open(fullpath, "rb") except IOError as err: # Access denied, or a special file - ignore it print_debug("%s: access denied: %s" % (fullpath, err)) return None @@ -65,7 +65,7 @@ if fullpath.endswith(".py") or fullpath.endswith(".pyw"): return True - elif "python" in line: + elif b"python" in line: # disguised Python script (e.g. CGI) return True -- Repository URL: http://hg.python.org/cpython From storchaka at gmail.com Wed Aug 1 22:52:02 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 01 Aug 2012 23:52:02 +0300 Subject: [Python-checkins] cpython: Fix findnocoding.p and pysource.py scripts In-Reply-To: <3WnN5F1BX5zPgm@mail.python.org> References: <3WnN5F1BX5zPgm@mail.python.org> Message-ID: <501996F2.7000208@gmail.com> On 01.08.12 21:16, victor.stinner wrote: > http://hg.python.org/cpython/rev/67d36e8ddcfc > changeset: 78375:67d36e8ddcfc > user: Victor Stinner > date: Wed Aug 01 20:12:51 2012 +0200 > summary: > Fix findnocoding.p and pysource.py scripts > > I suppose that these scripts didn't work since Python 3.0. > - line1 = infile.readline() > - line2 = infile.readline() > + with infile: > + line1 = infile.readline() > + line2 = infile.readline() > > - if get_declaration(line1) or get_declaration(line2): > - # the file does have an encoding declaration, so trust it > - infile.close() > - return False > + if get_declaration(line1) or get_declaration(line2): > + # the file does have an encoding declaration, so trust it > + infile.close() > + return False infile.close() is unnecessary here. From python-checkins at python.org Thu Aug 2 00:10:05 2012 From: python-checkins at python.org (victor.stinner) Date: Thu, 2 Aug 2012 00:10:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Cleanup_findnocoding=2Epy_?= =?utf-8?q?and_pysource=2Epy_scripts_=28with_infile/infile=2Eclose=29?= Message-ID: <3WnTGP0jW0zPcR@mail.python.org> http://hg.python.org/cpython/rev/8ace059cdffd changeset: 78376:8ace059cdffd user: Victor Stinner date: Thu Aug 02 00:05:41 2012 +0200 summary: Cleanup findnocoding.py and pysource.py scripts (with infile/infile.close) files: Tools/scripts/findnocoding.py | 1 - Tools/scripts/pysource.py | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Tools/scripts/findnocoding.py b/Tools/scripts/findnocoding.py --- a/Tools/scripts/findnocoding.py +++ b/Tools/scripts/findnocoding.py @@ -60,7 +60,6 @@ if get_declaration(line1) or get_declaration(line2): # the file does have an encoding declaration, so trust it - infile.close() return False # check the whole file for non utf-8 characters diff --git a/Tools/scripts/pysource.py b/Tools/scripts/pysource.py --- a/Tools/scripts/pysource.py +++ b/Tools/scripts/pysource.py @@ -55,8 +55,8 @@ if infile is None: return False - line = infile.readline() - infile.close() + with infile: + line = infile.readline() if binary_re.search(line): # file appears to be binary @@ -76,8 +76,8 @@ if infile is None: return False - code = infile.read() - infile.close() + with infile: + code = infile.read() try: compile(code, fullpath, "exec") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 01:57:39 2012 From: python-checkins at python.org (eli.bendersky) Date: Thu, 2 Aug 2012 01:57:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1MzIx?= =?utf-8?q?=3A_update_PyPI_upload_doc_to_say_--no-raw_passed_to_rst2html?= =?utf-8?b?LnB5?= Message-ID: <3WnWfW50ydzPfY@mail.python.org> http://hg.python.org/cpython/rev/014b36383a54 changeset: 78377:014b36383a54 branch: 3.2 parent: 78366:2638ce032151 user: Eli Bendersky date: Thu Aug 02 02:56:39 2012 +0300 summary: Issue #15321: update PyPI upload doc to say --no-raw passed to rst2html.py files: Doc/distutils/uploading.rst | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Doc/distutils/uploading.rst b/Doc/distutils/uploading.rst --- a/Doc/distutils/uploading.rst +++ b/Doc/distutils/uploading.rst @@ -73,4 +73,8 @@ $ python setup.py --long-description | rst2html.py > output.html :mod:`docutils` will display a warning if there's something wrong with your -syntax. +syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw`` +to ``rst2html.py`` in the command above), being able to run the command above +without warnings does not guarantee that PyPI will convert the content +successfully. + -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 02:00:58 2012 From: python-checkins at python.org (eli.bendersky) Date: Thu, 2 Aug 2012 02:00:58 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1MjMx?= =?utf-8?q?=3A_update_PyPI_upload_doc_to_say_--no-raw_passed_to_rst2html?= =?utf-8?b?LnB5?= Message-ID: <3WnWkL1wYWzPfY@mail.python.org> http://hg.python.org/cpython/rev/29bdbcadf299 changeset: 78378:29bdbcadf299 branch: 2.7 parent: 78365:5a8c5631463f user: Eli Bendersky date: Thu Aug 02 03:00:33 2012 +0300 summary: Issue #15231: update PyPI upload doc to say --no-raw passed to rst2html.py files: Doc/distutils/uploading.rst | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Doc/distutils/uploading.rst b/Doc/distutils/uploading.rst --- a/Doc/distutils/uploading.rst +++ b/Doc/distutils/uploading.rst @@ -74,4 +74,9 @@ $ python setup.py --long-description | rst2html.py > output.html -:mod:`docutils` will display a warning if there's something wrong with your syntax. +:mod:`docutils` will display a warning if there's something wrong with your +syntax. Because PyPI applies additional checks (e.g. by passing ``--no-raw`` +to ``rst2html.py`` in the command above), being able to run the command above +without warnings does not guarantee that PyPI will convert the content +successfully. + -- Repository URL: http://hg.python.org/cpython From victor.stinner at gmail.com Thu Aug 2 00:12:17 2012 From: victor.stinner at gmail.com (Victor Stinner) Date: Thu, 2 Aug 2012 00:12:17 +0200 Subject: [Python-checkins] [Python-Dev] cpython: Fix findnocoding.p and pysource.py scripts In-Reply-To: <501996F2.7000208@gmail.com> References: <3WnN5F1BX5zPgm@mail.python.org> <501996F2.7000208@gmail.com> Message-ID: 2012/8/1 Serhiy Storchaka : >> changeset: 78375:67d36e8ddcfc >> Fix findnocoding.p and pysource.py scripts >> > >> - line1 = infile.readline() >> - line2 = infile.readline() >> + with infile: >> + line1 = infile.readline() >> + line2 = infile.readline() >> >> - if get_declaration(line1) or get_declaration(line2): >> - # the file does have an encoding declaration, so trust it >> - infile.close() >> - return False >> + if get_declaration(line1) or get_declaration(line2): >> + # the file does have an encoding declaration, so trust it >> + infile.close() >> + return False > > infile.close() is unnecessary here. Ah yes correct, I forgot this one. The new changeset 8ace059cdffd removes it. It is not perfect, there is still a race condition in looks_like_python() (pysource.py) if KeyboardInterrupt occurs between the file is opened and the beginning of the "with infile" block, but it don't think that it is really important ;-) Victor From solipsis at pitrou.net Thu Aug 2 06:01:51 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 02 Aug 2012 06:01:51 +0200 Subject: [Python-checkins] Daily reference leaks (8ace059cdffd): sum=2 Message-ID: results for 8ace059cdffd on branch "default" -------------------------------------------- test_dbm leaked [0, 0, 2] references, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog8UAvLP', '-x'] From python-checkins at python.org Thu Aug 2 09:21:40 2012 From: python-checkins at python.org (ezio.melotti) Date: Thu, 2 Aug 2012 09:21:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devguide=3A_=2315521=3A_mention_that_?= =?utf-8?q?test=2Eregrtest_is_necessary_to_run_tests_on_2=2E7=2E__Patch_by?= Message-ID: <3WnjVr3bYqzPfP@mail.python.org> http://hg.python.org/devguide/rev/851adff2d434 changeset: 536:851adff2d434 user: Ezio Melotti date: Thu Aug 02 09:21:21 2012 +0200 summary: #15521: mention that test.regrtest is necessary to run tests on 2.7. Patch by Chris Jerdonek. files: runtests.rst | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/runtests.rst b/runtests.rst --- a/runtests.rst +++ b/runtests.rst @@ -18,6 +18,11 @@ ./python -m test +If you are using Python 2.7, then use the following instead as the basis +for the commands in this section:: + + ./python -m test.regrtest + If you don't have easy access to a command line, you can run the test suite from a Python or IDLE shell:: -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Thu Aug 2 13:26:14 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 2 Aug 2012 13:26:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315502=3A_Bring_th?= =?utf-8?q?e_importlib_ABCs_into_line_with_the_current_state_of_the?= Message-ID: <3Wnpx25v1RzPhl@mail.python.org> http://hg.python.org/cpython/rev/184700df5b6a changeset: 78379:184700df5b6a parent: 78376:8ace059cdffd user: Nick Coghlan date: Thu Aug 02 21:26:03 2012 +1000 summary: Issue #15502: Bring the importlib ABCs into line with the current state of the import protocols given PEP 420. Original patch by Eric Snow. files: Doc/library/importlib.rst | 77 +++++--- Lib/importlib/abc.py | 82 ++++++--- Lib/test/test_importlib/source/test_abc_loader.py | 23 +- Lib/test/test_importlib/test_abc.py | 7 +- Misc/NEWS | 3 + 5 files changed, 127 insertions(+), 65 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -125,32 +125,49 @@ .. class:: Finder - An abstract base class representing a :term:`finder`. - See :pep:`302` for the exact definition for a finder. - - .. method:: find_loader(self, fullname): - - An abstract method for finding a :term:`loader` for the specified - module. Returns a 2-tuple of ``(loader, portion)`` where portion is a - sequence of file system locations contributing to part of a namespace - package. The sequence may be empty. When present, `find_loader()` is - preferred over `find_module()`. - - .. versionadded: 3.3 - - .. method:: find_module(fullname, path=None) - - An abstract method for finding a :term:`loader` for the specified - module. If the :term:`finder` is found on :data:`sys.meta_path` and the - module to be searched for is a subpackage or module then *path* will - be the value of :attr:`__path__` from the parent package. If a loader - cannot be found, ``None`` is returned. + An abstract base class representing a :term:`finder`. Finder + implementations should derive from (or register with) the more specific + :class:`MetaPathFinder` or :class:`PathEntryFinder` ABCs. .. method:: invalidate_caches() - An optional method which, when called, should invalidate any internal - cache used by the finder. Used by :func:`invalidate_caches()` when - invalidating the caches of all cached finders. + An optional method which, when called, should invalidate any internal + cache used by the finder. Used by :func:`invalidate_caches()` when + invalidating the caches of all cached finders. + + .. versionchanged:: 3.3 + The API signatures for meta path finders and path entry finders + were separated by PEP 420. Accordingly, the Finder ABC no + longer requires implementation of a ``find_module()`` method. + + +.. class:: MetaPathFinder(Finder) + + An abstract base class representing a :term:`meta path finder`. + + .. versionadded:: 3.3 + + .. method:: find_module(fullname, path) + + An abstract method for finding a :term:`loader` for the specified + module. If this is a top-level import, *path* will be ``None``. + Otheriwse, this is a search for a subpackage or module and *path* + will be the value of :attr:`__path__` from the parent + package. If a loader cannot be found, ``None`` is returned. + + +.. class:: PathEntryFinder(Finder) + + An abstract base class representing a :term:`path entry finder`. + + .. versionadded:: 3.3 + + .. method:: find_loader(self, fullname): + + An abstract method for finding a :term:`loader` for the specified + module. Returns a 2-tuple of ``(loader, portion)`` where portion is a + sequence of file system locations contributing to part of a namespace + package. The sequence may be empty. .. class:: Loader @@ -569,8 +586,8 @@ An :term:`importer` for built-in modules. All known built-in modules are listed in :data:`sys.builtin_module_names`. This class implements the - :class:`importlib.abc.Finder` and :class:`importlib.abc.InspectLoader` - ABCs. + :class:`importlib.abc.MetaPathFinder` and + :class:`importlib.abc.InspectLoader` ABCs. Only class methods are defined by this class to alleviate the need for instantiation. @@ -579,8 +596,8 @@ .. class:: FrozenImporter An :term:`importer` for frozen modules. This class implements the - :class:`importlib.abc.Finder` and :class:`importlib.abc.InspectLoader` - ABCs. + :class:`importlib.abc.MetaPathFinder` and + :class:`importlib.abc.InspectLoader` ABCs. Only class methods are defined by this class to alleviate the need for instantiation. @@ -589,7 +606,7 @@ .. class:: PathFinder :term:`Finder` for :data:`sys.path`. This class implements the - :class:`importlib.abc.Finder` ABC. + :class:`importlib.abc.MetaPathFinder` ABC. This class does not perfectly mirror the semantics of :keyword:`import` in terms of :data:`sys.path`. No implicit path hooks are assumed for @@ -616,8 +633,8 @@ .. class:: FileFinder(path, \*loader_details) - A concrete implementation of :class:`importlib.abc.Finder` which caches - results from the file system. + A concrete implementation of :class:`importlib.abc.PathEntryFinder` which + caches results from the file system. The *path* argument is the directory for which the finder is in charge of searching. diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -23,6 +23,61 @@ abstract_cls.register(frozen_cls) +class Finder(metaclass=abc.ABCMeta): + + """Common abstract base class for import finders. + + Finder implementations should derive from the more specific + MetaPathFinder or PathEntryFinder ABCs rather than directly from Finder. + """ + + def find_module(self, fullname, path=None): + """An optional legacy method that should find a module. + The fullname is a str and the optional path is a str or None. + Returns a Loader object. + + The path finder will use this method only if find_loader() does + not exist. It may optionally be implemented for compatibility + with legacy third party reimplementations of the import system. + """ + raise NotImplementedError + + # invalidate_caches() is a completely optional method, so no default + # implementation is provided. See the docs for details. + + +class MetaPathFinder(Finder): + + """Abstract base class for import finders on sys.meta_path.""" + + @abc.abstractmethod + def find_module(self, fullname, path): + """Abstract method which when implemented should find a module. + The fullname is a str and the path is a str or None. + Returns a Loader object. + """ + raise NotImplementedError + +_register(MetaPathFinder, machinery.BuiltinImporter, machinery.FrozenImporter, + machinery.PathFinder) + + +class PathEntryFinder(Finder): + + """Abstract base class for path entry finders used by PathFinder.""" + + @abc.abstractmethod + def find_loader(self, fullname): + """Abstract method which when implemented returns a module loader. + The fullname is a str. Returns a 2-tuple of (Loader, portion) where + portion is a sequence of file system locations contributing to part of + a namespace package. The sequence may be empty. + """ + raise NotImplementedError + +_register(PathEntryFinder, machinery.FileFinder) + + class Loader(metaclass=abc.ABCMeta): """Abstract base class for import loaders.""" @@ -40,33 +95,6 @@ raise NotImplementedError -class Finder(metaclass=abc.ABCMeta): - - """Abstract base class for import finders.""" - - @abc.abstractmethod - def find_loader(self, fullname): - """Abstract method which when implemented returns a module loader. - The fullname is a str. Returns a 2-tuple of (Loader, portion) where - portion is a sequence of file system locations contributing to part of - a namespace package. The sequence may be empty. When present, - `find_loader()` is preferred over `find_module()`. - """ - raise NotImplementedError - - @abc.abstractmethod - def find_module(self, fullname, path=None): - """Abstract method which when implemented should find a module. - The fullname is a str and the optional path is a str or None. - Returns a Loader object. This method is only called if - `find_loader()` is not present. - """ - raise NotImplementedError - -_register(Finder, machinery.BuiltinImporter, machinery.FrozenImporter, - machinery.PathFinder, machinery.FileFinder) - - class ResourceLoader(Loader): """Abstract base class for loaders which can return data from their 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 @@ -778,23 +778,32 @@ expect = io.IncrementalNewlineDecoder(None, True).decode(source) self.assertEqual(mock.get_source(name), expect) + class AbstractMethodImplTests(unittest.TestCase): """Test the concrete abstractmethod implementations.""" + class MetaPathFinder(abc.MetaPathFinder): + def find_module(self, fullname, path): + super().find_module(fullname, path) + + class PathEntryFinder(abc.PathEntryFinder): + def find_module(self, _): + super().find_module(_) + + def find_loader(self, _): + super().find_loader(_) + + class Finder(abc.Finder): + def find_module(self, fullname, path): + super().find_module(fullname, path) + class Loader(abc.Loader): def load_module(self, fullname): super().load_module(fullname) def module_repr(self, module): super().module_repr(module) - class Finder(abc.Finder): - def find_module(self, _): - super().find_module(_) - - def find_loader(self, _): - super().find_loader(_) - class ResourceLoader(Loader, abc.ResourceLoader): def get_data(self, _): super().get_data(_) diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py --- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -30,11 +30,16 @@ "{0} is not a superclass of {1}".format(superclass, self.__test)) -class Finder(InheritanceTests, unittest.TestCase): +class MetaPathFinder(InheritanceTests, unittest.TestCase): + superclasses = [abc.Finder] subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter, machinery.PathFinder] +class PathEntryFinder(InheritanceTests, unittest.TestCase): + + superclasses = [abc.Finder] + subclasses = [machinery.FileFinder] class Loader(InheritanceTests, unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -72,6 +72,9 @@ Library ------- +- Issue #15502: Bring the importlib ABCs into line with the current state + of the import protocols given PEP 420. Original patch by Eric Snow. + - Issue #15499: Launching a webbrowser in Unix used to sleep for a few seconds. Original patch by Anton Barkovsky. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 13:45:37 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 2 Aug 2012 13:45:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2315519=3A_Properly?= =?utf-8?q?_expose_WindowsRegistryFinder_in_importlib_and_bring_the?= Message-ID: <3WnqMP0dPxzPWR@mail.python.org> http://hg.python.org/cpython/rev/a1ac1e13c5a0 changeset: 78380:a1ac1e13c5a0 user: Nick Coghlan date: Thu Aug 02 21:45:24 2012 +1000 summary: Close #15519: Properly expose WindowsRegistryFinder in importlib and bring the name into line with normal import terminology. Original patch by Eric Snow files: Doc/library/importlib.rst | 11 + Lib/importlib/_bootstrap.py | 8 +- Lib/importlib/abc.py | 2 +- Lib/importlib/machinery.py | 1 + Lib/test/test_importlib/test_abc.py | 2 +- Misc/NEWS | 3 + Python/importlib.h | 5018 +++++++------- 7 files changed, 2529 insertions(+), 2516 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -603,6 +603,17 @@ instantiation. +.. class:: WindowsRegistryFinder + + :term:`Finder` for modules declared in the Windows registry. This class + implements the :class:`importlib.abc.MetaPathFinder` ABC. + + Only class methods are defined by this class to alleviate the need for + instantiation. + + .. versionadded:: 3.3 + + .. class:: PathFinder :term:`Finder` for :data:`sys.path`. This class implements the diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -720,9 +720,9 @@ return _imp.is_frozen_package(fullname) -class WindowsRegistryImporter: +class WindowsRegistryFinder: - """Meta path import for modules declared in the Windows registry. + """Meta path finder for modules declared in the Windows registry. """ REGISTRY_KEY = ( @@ -1683,7 +1683,7 @@ if builtin_os == 'nt': SOURCE_SUFFIXES.append('.pyw') if '_d.pyd' in _imp.extension_suffixes(): - WindowsRegistryImporter.DEBUG_BUILD = True + WindowsRegistryFinder.DEBUG_BUILD = True def _install(sys_module, _imp_module): @@ -1694,5 +1694,5 @@ sys.meta_path.append(BuiltinImporter) sys.meta_path.append(FrozenImporter) if _os.__name__ == 'nt': - sys.meta_path.append(WindowsRegistryImporter) + sys.meta_path.append(WindowsRegistryFinder) sys.meta_path.append(PathFinder) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -59,7 +59,7 @@ raise NotImplementedError _register(MetaPathFinder, machinery.BuiltinImporter, machinery.FrozenImporter, - machinery.PathFinder) + machinery.PathFinder, machinery.WindowsRegistryFinder) class PathEntryFinder(Finder): diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -6,6 +6,7 @@ OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES) from ._bootstrap import BuiltinImporter from ._bootstrap import FrozenImporter +from ._bootstrap import WindowsRegistryFinder from ._bootstrap import PathFinder from ._bootstrap import FileFinder from ._bootstrap import SourceFileLoader diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py --- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -34,7 +34,7 @@ superclasses = [abc.Finder] subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter, - machinery.PathFinder] + machinery.PathFinder, machinery.WindowsRegistryFinder] class PathEntryFinder(InheritanceTests, unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -72,6 +72,9 @@ Library ------- +- Issue #15519: Properly expose WindowsRegistryFinder in importlib (and use + the correct term for it). Original patch by Eric Snow. + - Issue #15502: Bring the importlib ABCs into line with the current state of the import protocols given PEP 420. Original patch by Eric Snow. 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 Thu Aug 2 14:02:44 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 2 Aug 2012 14:02:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Clarify_the_import_stateme?= =?utf-8?q?nt_semantics=2C_especially_for_implicit_imports_in_the?= Message-ID: <3Wnql84czzzPcp@mail.python.org> http://hg.python.org/cpython/rev/2231722667d9 changeset: 78381:2231722667d9 user: Nick Coghlan date: Thu Aug 02 22:02:35 2012 +1000 summary: Clarify the import statement semantics, especially for implicit imports in the 'from X import Y' variant files: Doc/reference/simple_stmts.rst | 97 ++++++++++++++++----- 1 files changed, 71 insertions(+), 26 deletions(-) diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -660,41 +660,86 @@ relative_module: "."* `module` | "."+ name: `identifier` -Import statements are executed in two steps: (1) find a module, loading and -initializing it if necessary; (2) define a name or names in the local -namespace (of the scope where the :keyword:`import` statement occurs). -Step (1) may be performed recursively if the named module is a submodule or -subpackage of a parent package. +The basic import statement (no :keyword:`from` clause) is executed in two +steps: -The :keyword:`import` statement comes in two forms differing on whether it -uses the :keyword:`from` keyword. The first form (without :keyword:`from`) -repeats these steps for each identifier in the list. The form with -:keyword:`from` performs step (1), and then performs step (2) repeatedly. +#. find a module, loading and initializing it if necessary +#. define a name or names in the local namespace for the scope where + the :keyword:`import` statement occurs. -The details of step (1), finding and loading modules is described in greater -detail in the section on the :ref:`import system `, which -also describes the various types of packages and modules that can be imported, -as well as all the hooks that can be used to customize Python's import. +When the statement contains multiple clauses (separated by +commas) the two steps are carried out separately for each clause, just +as though the clauses had been separated out into individiual import +statements. -When step (1) finishes without raising an exception, step (2) can begin. +The details of the first step, finding and loading modules is described in +greater detail in the section on the :ref:`import system `, +which also describes the various types of packages and modules that can +be imported, as well as all the hooks that can be used to customize +the import system. Note that failures in this step may indicate either +that the module could not be located, *or* that an error occurred while +initializing the module, which includes execution of the module's code. -The first form of :keyword:`import` statement binds the module name in the -local namespace to the module object, and then goes on to import the next -identifier, if any. If the module name is followed by :keyword:`as`, the name -following :keyword:`as` is used as the local name for the module. +If the requested module is retrieved successfully, it will be made +available in the local namespace in one of three ways: + +* If the module name is followed by :keyword:`as`, then the name + following :keyword:`as` is bound directly to the imported module. +* If no other name is specified, and the module being imported is a top + level module, the module's name is bound in the local namespace as a + reference to the imported module +* If the module being imported is *not* a top level module, then the name + of the top level package that contains the module is bound in the local + namespace as a reference to the top level package. The imported module + must be accessed using its full qualified name rather than directly + .. index:: pair: name; binding + keyword: from exception: ImportError -The :keyword:`from` form does not bind the module name: it goes through the -list of identifiers, looks each one of them up in the module found in step -(1), and binds the name in the local namespace to the object thus found. As -with the first form of :keyword:`import`, an alternate local name can be -supplied by specifying ":keyword:`as` localname". If a name is not found, -:exc:`ImportError` is raised. If the list of identifiers is replaced by a -star (``'*'``), all public names defined in the module are bound in the local -namespace of the :keyword:`import` statement. +The :keyword:`from` form uses a slightly more complex process: + +#. find the module specified in the :keyword:`from` clause loading and + initializing it if necessary; +#. for each of the identifiers specified in the :keyword:`import` clauses: + + #. check if the imported module has an attribute by that name + #. if not, attempt to import a submodule with that name and then + check the imported module again for that attribute + #. if the attribute is not found, :exc:`ImportError` is raised. + #. otherwise, a reference to that value is bound in the local namespace, + using the name in the :keyword:`as` clause if it is present, + otherwise using the attribute name + +Examples:: + + import foo # foo imported and bound locally + import foo.bar.baz # foo.bar.baz imported, foo bound locally + import foo.bar.baz as fbb # foo.bar.baz imported and bound as fbb + from foo.bar import baz # foo.bar.baz imported and bound as baz + from foo import attr # foo imported and foo.attr bound as attr + +If the list of identifiers is replaced by a star (``'*'``), all public +names defined in the module are bound in the local namespace for the scope +where the :keyword:`import` statement occurs. + +.. index:: single: __all__ (optional module attribute) + +The *public names* defined by a module are determined by checking the module's +namespace for a variable named ``__all__``; if defined, it must be a sequence +of strings which are names defined or imported by that module. The names +given in ``__all__`` are all considered public and are required to exist. If +``__all__`` is not defined, the set of public names includes all names found +in the module's namespace which do not begin with an underscore character +(``'_'``). ``__all__`` should contain the entire public API. It is intended +to avoid accidentally exporting items that are not part of the API (such as +library modules which were imported and used within the module). + +The :keyword:`from` form with ``*`` may only occur in a module scope. +Attempting to use it in class or function definitions will raise a +:exc:`SyntaxError`. .. index:: single: __all__ (optional module attribute) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 15:04:11 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 2 Aug 2012 15:04:11 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315502=3A_Bring_th?= =?utf-8?q?e_importlib=2EPathFinder_docs_and_docstring_more_in_line?= Message-ID: <3Wns631KFWzPhs@mail.python.org> http://hg.python.org/cpython/rev/1f8351cf00f3 changeset: 78382:1f8351cf00f3 user: Nick Coghlan date: Thu Aug 02 23:03:58 2012 +1000 summary: Issue #15502: Bring the importlib.PathFinder docs and docstring more in line with the new import system documentation, and fix various parts of the new docs that weren't quite right given PEP 420 or were otherwise a bit misleading. Also note the key terminology problem still being discussed in the issue files: Doc/library/importlib.rst | 15 +- Doc/reference/import.rst | 221 +- Lib/importlib/_bootstrap.py | 8 +- Python/importlib.h | 2583 +++++++++++----------- 4 files changed, 1449 insertions(+), 1378 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -606,7 +606,7 @@ .. class:: WindowsRegistryFinder :term:`Finder` for modules declared in the Windows registry. This class - implements the :class:`importlib.abc.MetaPathFinder` ABC. + implements the :class:`importlib.abc.Finder` ABC. Only class methods are defined by this class to alleviate the need for instantiation. @@ -616,14 +616,8 @@ .. class:: PathFinder - :term:`Finder` for :data:`sys.path`. This class implements the - :class:`importlib.abc.MetaPathFinder` ABC. - - This class does not perfectly mirror the semantics of :keyword:`import` in - terms of :data:`sys.path`. No implicit path hooks are assumed for - simplification of the class and its semantics. This implies that when - ``None`` is found in :data:`sys.path_importer_cache` that it is simply - ignored instead of implying a default finder. + :term:`Finder` for :data:`sys.path` and package ``__path__`` attributes. + This class implements the :class:`importlib.abc.MetaPathFinder` ABC. Only class methods are defined by this class to alleviate the need for instantiation. @@ -639,7 +633,8 @@ :data:`sys.path_importer_cache`, then :data:`sys.path_hooks` is searched for a finder for the path entry and, if found, is stored in :data:`sys.path_importer_cache` along with being queried about the - module. If no finder is ever found then ``None`` is returned. + module. If no finder is ever found then ``None`` is both stored in + the cache and returned. .. class:: FileFinder(path, \*loader_details) diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -16,8 +16,8 @@ The :keyword:`import` statement combines two operations; it searches for the named module, then it binds the results of that search to a name in the local scope. The search operation of the :keyword:`import` statement is defined as -a call to the built-in :func:`__import__` function, with the appropriate -arguments. The return value of :func:`__import__` is used to perform the name +a call to the :func:`__import__` function, with the appropriate arguments. +The return value of :func:`__import__` is used to perform the name binding operation of the :keyword:`import` statement. See the :keyword:`import` statement for the exact details of that name binding operation. @@ -28,13 +28,19 @@ (including :data:`sys.modules`), only the :keyword:`import` statement performs a name binding operation. +When calling :func:`__import__` as part of an import statement, the +import system first checks the module global namespace for a function by +that name. If it is not found, then the standard builtin :func:`__import__` +is called. Other mechanisms for invoking the import system (such as +:func:`importlib.import_module`) do not perform this check and will always +use the standard import system. + When a module is first imported, Python searches for the module and if found, it creates a module object [#fnmo]_, initializing it. If the named module cannot be found, an :exc:`ImportError` is raised. Python implements various strategies to search for the named module when the import machinery is invoked. These strategies can be modified and extended by using various hooks -described in the sections below. More coarse-grained overriding of the import -system can be accomplished by replacing built-in :func:`__import__`. +described in the sections below. :mod:`importlib` @@ -69,7 +75,7 @@ It's important to keep in mind that all packages are modules, but not all modules are packages. Or put another way, packages are just a special kind of -module. Specifically, any module that contains an ``__path__`` attribute is +module. Specifically, any module that contains a ``__path__`` attribute is considered a package. All modules have a name. Subpackage names are separated from their parent @@ -90,7 +96,7 @@ packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory containing an ``__init__.py`` file. When a regular package is imported, this -``__init__.py`` file is implicitly imported, and the objects it defines are +``__init__.py`` file is implicitly executed, and the objects it defines are bound to names in the package's namespace. The ``__init__.py`` file can contain the same Python code that any other module can contain, and Python will add some additional attributes to the module when it is imported. @@ -107,9 +113,9 @@ three/ __init__.py -Importing ``parent.one`` will implicitly import ``parent/__init__.py`` and +Importing ``parent.one`` will implicitly execute ``parent/__init__.py`` and ``parent/one/__init__.py``. Subsequent imports of ``parent.two`` or -``parent.three`` will import ``parent/two/__init__.py`` and +``parent.three`` will execute ``parent/two/__init__.py`` and ``parent/three/__init__.py`` respectively. @@ -128,6 +134,12 @@ objects on the file system; they may be virtual modules that have no concrete representation. +Namespace packages do not use an ordinary list for their ``__path__`` +attribute. They instead use a custom iterable type which will automatically +perform a new search for package portions on the next import attempt within +that package if the path of their parent package (or :data:`sys.path` for a +top level package) changes. + With namespace packages, there is no ``parent/__init__.py`` file. In fact, there may be multiple ``parent`` directories found during import search, where each one is provided by a different portion. Thus ``parent/one`` may not be @@ -172,14 +184,18 @@ :exc:`ImportError` is raised. If the module name is missing, Python will continue searching for the module. -:data:`sys.modules` is writable. Deleting a key will not destroy the -associated module, but it will invalidate the cache entry for the named -module, causing Python to search anew for the named module upon its next -import. Beware though, because if you keep a reference to the module object, +:data:`sys.modules` is writable. Deleting a key may not destroy the +associated module (as other modules may hold references to it), +but it will invalidate the cache entry for the named module, causing +Python to search anew for the named module upon its next +import. The key can also be assigned to ``None``, forcing the next import +of the module to result in an :exc:`ImportError`. + +Beware though, as if you keep a reference to the module object, invalidate its cache entry in :data:`sys.modules`, and then re-import the -named module, the two module objects will *not* be the same. The key can also -be assigned to ``None``, forcing the next import of the module to result in an -:exc:`ImportError`. +named module, the two module objects will *not* be the same. By contrast, +:func:`imp.reload` will reuse the *same* module object, and simply +reinitialise the module contents by rerunning the module's code. Finders and loaders @@ -193,14 +209,16 @@ protocol is invoked to find and load the module. This protocol consists of two conceptual objects, :term:`finders ` and :term:`loaders `. A finder's job is to determine whether it can find the named module using -whatever strategy it knows about. +whatever strategy it knows about. Objects that implement both of these +interfaces are referred to as :term:`importers ` - they return +themselves when they find that they can load the requested module. -By default, Python comes with several default finders. One knows how to -locate frozen modules, and another knows how to locate built-in modules. A -third default finder searches an :term:`import path` for modules. The -:term:`import path` is a list of locations that may name file system paths or -zip files. It can also be extended to search for any locatable resource, such -as those identified by URLs. +By default, Python comes with several default finders and importers. One +knows how to locate frozen modules, and another knows how to locate +built-in modules. A third default finder searches an :term:`import path` +for modules. The :term:`import path` is a list of locations that may +name file system paths or zip files. It can also be extended to search +for any locatable resource, such as those identified by URLs. The import machinery is extensible, so new finders can be added to extend the range and scope of module searching. @@ -265,11 +283,26 @@ The :meth:`find_module()` method of meta path finders is called with two arguments. The first is the fully qualified name of the module being -imported, for example ``foo.bar.baz``. The second argument is the relative -import path for the module search. For top-level modules, this second -argument will always be ``None``, but for submodules or subpackages, the -second argument is the value of the parent package's ``__path__`` attribute, -which must exist on the parent module or an :exc:`ImportError` is raised. +imported, for example ``foo.bar.baz``. The second argument is the path +entries to use for the module search. For top-level modules, the second +argument is ``None``, but for submodules or subpackages, the second +argument is the value of the parent package's ``__path__`` attribute. If +the appropriate ``__path__`` attribute cannot be accessed, an +:exc:`ImportError` is raised. + +The meta path may be traversed multiple times for a single import request. +For example, assuming none of the modules involved has already been cached, +importing ``foo.bar.baz`` will first perform a top level import, calling +``mpf.find_module("foo", None)`` on each meta path finder (``mpf``). After +``foo`` has been imported, ``foo.bar`` will be imported by traversing the +meta path a second time, calling +``mpf.find_module("foo.bar", foo.__path__)``. Once ``foo.bar`` has been +imported, the final traversal will call +``mpf.find_module("foo.bar.baz", foo.bar.__path__)``. + +Some meta path finders only support top level imports. These importers will +always return ``None`` when anything other than ``None`` is passed as the +second argument. Python's default :data:`sys.meta_path` has three meta path finders, one that knows how to import built-in modules, one that knows how to import frozen @@ -295,7 +328,7 @@ * If there is an existing module object with the given name in :data:`sys.modules`, the loader must use that existing module. (Otherwise, - the :func:`imp.reload` will not work correctly.) If the named module does + :func:`imp.reload` will not work correctly.) If the named module does not exist in :data:`sys.modules`, the loader must create a new module object and add it to :data:`sys.modules`. @@ -320,10 +353,12 @@ required, setting this attribute is highly recommended so that the :meth:`repr()` of the module is more informative. - * If module is a package (either regular or namespace), the loader must set - the module object's ``__path__`` attribute. The value must be a list, but - may be empty if ``__path__`` has no further significance to the importer. - More details on the semantics of ``__path__`` are given below. + * If the module is a package (either regular or namespace), the loader must + set the module object's ``__path__`` attribute. The value must be + iterable, but may be empty if ``__path__`` has no further significance + to the importer. If ``__path__`` is not empty, it must produce strings + when iterated over. More details on the semantics of ``__path__`` are + given :ref`below `. * The ``__loader__`` attribute must be set to the loader object that loaded the module. This is mostly for introspection and reloading, but can be @@ -369,7 +404,7 @@ Here are the exact rules used: - * If the module has an ``__loader__`` and that loader has a + * If the module has a ``__loader__`` and that loader has a :meth:`module_repr()` method, call it with a single argument, which is the module object. The value returned is used as the module's repr. @@ -377,10 +412,10 @@ and discarded, and the calculation of the module's repr continues as if :meth:`module_repr()` did not exist. - * If the module has an ``__file__`` attribute, this is used as part of the + * If the module has a ``__file__`` attribute, this is used as part of the module's repr. - * If the module has no ``__file__`` but does have an ``__loader__``, then the + * If the module has no ``__file__`` but does have a ``__loader__``, then the loader's repr is used as part of the module's repr. * Otherwise, just use the module's ``__name__`` in the repr. @@ -394,6 +429,8 @@ return "".format(module.__name__) +.. _package-path-rules: + module.__path__ --------------- @@ -406,10 +443,10 @@ However, ``__path__`` is typically much more constrained than :data:`sys.path`. -``__path__`` must be a list, but it may be empty. The same rules used for -:data:`sys.path` also apply to a package's ``__path__``, and -:data:`sys.path_hooks` (described below) is consulted when traversing a -package's ``__path__``. +``__path__`` must be an iterable of strings, but it may be empty. +The same rules used for :data:`sys.path` also apply to a package's +``__path__``, and :data:`sys.path_hooks` (described below) are +consulted when traversing a package's ``__path__``. A package's ``__init__.py`` file may set or alter the package's ``__path__`` attribute, and this was typically the way namespace packages were implemented @@ -430,15 +467,20 @@ path`, which contains a list of :term:`path entries `. Each path entry names a location to search for modules. -Path entries may name file system locations, and by default the :term:`path -importer` knows how to provide traditional file system imports. It implements -all the semantics for finding modules on the file system, handling special -file types such as Python source code (``.py`` files), Python byte code -(``.pyc`` and ``.pyo`` files) and shared libraries (e.g. ``.so`` files). +The path importer itself doesn't know how to import anything. Instead, it +traverses the individual path entries, associating each of them with a +path entry finder that knows how to handle that particular kind of path. + +The default set of path entry finders implement all the semantics for finding +modules on the file system, handling special file types such as Python source +code (``.py`` files), Python byte code (``.pyc`` and ``.pyo`` files) and +shared libraries (e.g. ``.so`` files). When supported by the :mod:`zipimport` +module in the standard library, the default path entry finders also handle +loading all of these file types (other than shared libraries) from zipfiles. Path entries need not be limited to file system locations. They can refer to -the contents of zip files, URLs, database queries, or any other location that -can be specified as a string. +the URLs, database queries, or any other location that can be specified as a +string. The :term:`path importer` provides additional hooks and protocols so that you can extend and customize the types of searchable path entries. For example, @@ -483,8 +525,8 @@ Three variables are used by the :term:`path importer`, :data:`sys.path`, :data:`sys.path_hooks` and :data:`sys.path_importer_cache`. The ``__path__`` -attribute on package objects is also used. These provide additional ways that -the import machinery can be customized. +attributes on package objects are also used. These provide additional ways +that the import machinery can be customized. :data:`sys.path` contains a list of strings providing search locations for modules and packages. It is initialized from the :data:`PYTHONPATH` @@ -495,11 +537,12 @@ URLs, or database queries. The :term:`path importer` is a :term:`meta path finder`, so the import -machinery begins :term:`import path` search by calling the path importer's -:meth:`find_module()` method as described previously. When the ``path`` -argument to :meth:`find_module()` is given, it will be a list of string paths -to traverse. If the ``path`` argument is not given or is ``None``, -:data:`sys.path` is used. +machinery begins the :term:`import path` search by calling the path +importer's :meth:`find_module()` method as described previously. When +the ``path`` argument to :meth:`find_module()` is given, it will be a +list of string paths to traverse - typically a package's ``__path__`` +attribute for an import within that package. If the ``path`` argument +is ``None``, this indicates a top level import and :data:`sys.path` is used. The :term:`path importer` iterates over every entry in the search path, and for each of these, looks for an appropriate :term:`path entry finder` for the @@ -523,8 +566,9 @@ If :data:`sys.path_hooks` iteration ends with no :term:`path entry finder` being returned, then the path importer's :meth:`find_module()` method will -return ``None``, indicating that this :term:`meta path finder` could not find -the module. +store ``None`` in :data:`sys.path_importer_cache` (to indicate that there +is no finder for this path entry) and return ``None``, indicating that +this :term:`meta path finder` could not find the module. If a :term:`path entry finder` *is* returned by one of the :term:`path entry hook` callables on :data:`sys.path_hooks`, then the following protocol is used @@ -534,29 +578,59 @@ Path entry finder protocol -------------------------- -Path entry finders support the same :meth:`find_module()` method that meta -path finders support, however path entry finder's :meth:`find_module()` -methods are never called with a ``path`` argument. - -The :meth:`find_module()` method on path entry finders is deprecated though, -and instead path entry finders should implement the :meth:`find_loader()` -method. If it exists on the path entry finder, :meth:`find_loader()` will -always be called instead of :meth:`find_module()`. +In order to support imports of modules and initialized packages and also to +contribute portions to namespace packages, path entry finders must implement +the :meth:`find_loader()` method. :meth:`find_loader()` takes one argument, the fully qualified name of the module being imported. :meth:`find_loader()` returns a 2-tuple where the first item is the loader and the second item is a namespace :term:`portion`. When the first item (i.e. the loader) is ``None``, this means that while the -path entry finder does not have a loader for the named module, it knows that -the :term:`path entry` contributes to a namespace portion for the named -module. This will almost always be the case where Python is asked to import a -:term:`namespace package` that has no physical presence on the file system. -When a path entry finder returns ``None`` for the loader, the second item of -the 2-tuple return value must be a sequence, although it can be empty. +path entry finder does not have a loader for the named module, it knows that the +path entry contributes to a namespace portion for the named module. This will +almost always be the case where Python is asked to import a namespace package +that has no physical presence on the file system. When a path entry finder +returns ``None`` for the loader, the second item of the 2-tuple return value +must be a sequence, although it can be empty. If :meth:`find_loader()` returns a non-``None`` loader value, the portion is -ignored and the loader is returned from the :term:`path importer`, terminating -the :term:`import path` search. +ignored and the loader is returned from the path importer, terminating the +search through the path entries. + +For backwards compatibility with other implementations of the import +protocol, many path entry finders also support the same, +traditional :meth:`find_module()` method that meta path finders support. +However path entry finder :meth:`find_module()` methods are never called +with a ``path`` argument (they are expected to record the appropriate +path information from the initial call to the path hook). + +The :meth:`find_module()` method on path entry finders is deprecated, +as it does not allow the path entry finder to contribute portions to +namespace packages. Instead path entry finders should implement the +:meth:`find_loader()` method as described above. If it exists on the path +entry finder, the import system will always call :meth:`find_loader()` +in preference to :meth:`find_module()`. + + +Replacing the standard import system +==================================== + +The most reliable mechanism for replacing the entire import system is to +delete the default contents of :data:`sys.meta_path`, replacing them +entirely with a custom meta path hook. + +If it is acceptable to only alter the behaviour of import statements +without affecting other APIs that access the import system, then replacing +the builtin :func:`__import__` function may be sufficient. This technique +may also be employed at the module level to only alter the behaviour of +import statements within that module. + +To selectively prevent import of some modules from a hook early on the +meta path (rather than disabling the standard import system entirely), +it is sufficient to raise :exc:`ImportError` directly from +:meth:`find_module` instead of returning ``None``. The latter indicates +that the meta path search should continue. while raising an exception +terminates it immediately. Open issues @@ -568,11 +642,12 @@ attributes of modules and packages, perhaps expanding upon or supplanting the related entries in the data model reference page? -XXX Module reprs: how does module.__qualname__ fit in? - XXX runpy, pkgutil, et al in the library manual should all get "See Also" links at the top pointing to the new import system section. +XXX The :term:`path importer` is not, in fact, an :term:`importer`. That's +why the corresponding implementation class is :class:`importlib.PathFinder`. + References ========== diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1183,7 +1183,7 @@ class PathFinder: - """Meta path finder for sys.(path|path_hooks|path_importer_cache).""" + """Meta path finder for sys.path and package __path__ attributes.""" @classmethod def _path_hooks(cls, path): @@ -1204,10 +1204,10 @@ @classmethod def _path_importer_cache(cls, path): - """Get the finder for the path from sys.path_importer_cache. + """Get the finder for the path entry from sys.path_importer_cache. - If the path is not in the cache, find the appropriate finder and cache - it. If no finder is available, store None. + If the path entry is not in the cache, find the appropriate finder + and cache it. If no finder is available, store None. """ if path == '': 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 barry at python.org Thu Aug 2 16:32:19 2012 From: barry at python.org (Barry Warsaw) Date: Thu, 2 Aug 2012 10:32:19 -0400 Subject: [Python-checkins] cpython: Issue #15502: Bring the importlib.PathFinder docs and docstring more in line In-Reply-To: <3Wns631KFWzPhs@mail.python.org> References: <3Wns631KFWzPhs@mail.python.org> Message-ID: <20120802103219.19acba49@resist.wooz.org> On Aug 02, 2012, at 03:04 PM, nick.coghlan wrote: >http://hg.python.org/cpython/rev/1f8351cf00f3 >changeset: 78382:1f8351cf00f3 >user: Nick Coghlan >date: Thu Aug 02 23:03:58 2012 +1000 >summary: > Issue #15502: Bring the importlib.PathFinder docs and docstring more in line with the new import system documentation, and fix various parts of the new docs that weren't quite right given PEP 420 or were otherwise a bit misleading. Also note the key terminology problem still being discussed in the issue > >files: > Doc/library/importlib.rst | 15 +- > Doc/reference/import.rst | 221 +- > Lib/importlib/_bootstrap.py | 8 +- > Python/importlib.h | 2583 +++++++++++----------- > 4 files changed, 1449 insertions(+), 1378 deletions(-) > > >diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst >--- a/Doc/reference/import.rst >+++ b/Doc/reference/import.rst >@@ -69,7 +75,7 @@ > > It's important to keep in mind that all packages are modules, but not all > modules are packages. Or put another way, packages are just a special kind of >-module. Specifically, any module that contains an ``__path__`` attribute is >+module. Specifically, any module that contains a ``__path__`` attribute is I find this change hilarious! Is it "an under-under path" or "a dunder path"? Personally, I think word "dunder" should never be used unless it's followed by the word "mifflin", but that might be a bit too regional. Or maybe too old skool (yeah, I know all the kids love the dunder). I suppose I don't care that much, but it would be useful to have some consistency, like whether we use American or British spellings. >@@ -90,7 +96,7 @@ > packages are traditional packages as they existed in Python 3.2 and earlier. > A regular package is typically implemented as a directory containing an > ``__init__.py`` file. When a regular package is imported, this >-``__init__.py`` file is implicitly imported, and the objects it defines are >+``__init__.py`` file is implicitly executed, and the objects it defines are Perhaps "loaded" instead of either "imported" or "executed"? >@@ -107,9 +113,9 @@ > three/ > __init__.py > >-Importing ``parent.one`` will implicitly import ``parent/__init__.py`` and >+Importing ``parent.one`` will implicitly execute ``parent/__init__.py`` and Same. > ``parent/one/__init__.py``. Subsequent imports of ``parent.two`` or >-``parent.three`` will import ``parent/two/__init__.py`` and >+``parent.three`` will execute ``parent/two/__init__.py`` and And here. > ``parent/three/__init__.py`` respectively. > > >@@ -128,6 +134,12 @@ > objects on the file system; they may be virtual modules that have no concrete > representation. > >+Namespace packages do not use an ordinary list for their ``__path__`` >+attribute. They instead use a custom iterable type which will automatically >+perform a new search for package portions on the next import attempt within >+that package if the path of their parent package (or :data:`sys.path` for a >+top level package) changes. Nice addition. I can't help but suggest a slight rephrasing: Namespace packages use a custom iterable type for their ``__path__`` attribute, so that changes in their parent package's path (or :data:`sys.path` for a top level package) are handled automatically. >@@ -172,14 +184,18 @@ > :exc:`ImportError` is raised. If the module name is missing, Python will > continue searching for the module. > >-:data:`sys.modules` is writable. Deleting a key will not destroy the >-associated module, but it will invalidate the cache entry for the named >-module, causing Python to search anew for the named module upon its next >-import. Beware though, because if you keep a reference to the module object, >+:data:`sys.modules` is writable. Deleting a key may not destroy the >+associated module (as other modules may hold references to it), s/as other modules may hold references to it/due to circular references/ >@@ -369,7 +404,7 @@ > > Here are the exact rules used: > >- * If the module has an ``__loader__`` and that loader has a >+ * If the module has a ``__loader__`` and that loader has a > :meth:`module_repr()` method, call it with a single argument, which is the > module object. The value returned is used as the module's repr. > >@@ -377,10 +412,10 @@ > and discarded, and the calculation of the module's repr continues as if > :meth:`module_repr()` did not exist. > >- * If the module has an ``__file__`` attribute, this is used as part of the >+ * If the module has a ``__file__`` attribute, this is used as part of the > module's repr. > >- * If the module has no ``__file__`` but does have an ``__loader__``, then the >+ * If the module has no ``__file__`` but does have a ``__loader__``, then the > loader's repr is used as part of the module's repr. > > * Otherwise, just use the module's ``__name__`` in the repr. C'mon Michael Scott, make it stop! Do you remember the episode where Dwight and Jim team up to... Oh, I was in stitches! >@@ -430,15 +467,20 @@ > path`, which contains a list of :term:`path entries `. Each path > entry names a location to search for modules. > >-Path entries may name file system locations, and by default the :term:`path >-importer` knows how to provide traditional file system imports. It implements >-all the semantics for finding modules on the file system, handling special >-file types such as Python source code (``.py`` files), Python byte code >-(``.pyc`` and ``.pyo`` files) and shared libraries (e.g. ``.so`` files). >+The path importer itself doesn't know how to import anything. Instead, it >+traverses the individual path entries, associating each of them with a >+path entry finder that knows how to handle that particular kind of path. >+ >+The default set of path entry finders implement all the semantics for finding >+modules on the file system, handling special file types such as Python source >+code (``.py`` files), Python byte code (``.pyc`` and ``.pyo`` files) and >+shared libraries (e.g. ``.so`` files). When supported by the :mod:`zipimport` >+module in the standard library, the default path entry finders also handle >+loading all of these file types (other than shared libraries) from zipfiles. s/zipfiles/zip files/ > > Path entries need not be limited to file system locations. They can refer to >-the contents of zip files, URLs, database queries, or any other location that >-can be specified as a string. >+the URLs, database queries, or any other location that can be specified as a >+string. s/the URLs/URLs/ > > The :term:`path importer` provides additional hooks and protocols so that you > can extend and customize the types of searchable path entries. For example, >@@ -534,29 +578,59 @@ > Path entry finder protocol > -------------------------- > >-Path entry finders support the same :meth:`find_module()` method that meta >-path finders support, however path entry finder's :meth:`find_module()` >-methods are never called with a ``path`` argument. >- >-The :meth:`find_module()` method on path entry finders is deprecated though, >-and instead path entry finders should implement the :meth:`find_loader()` >-method. If it exists on the path entry finder, :meth:`find_loader()` will >-always be called instead of :meth:`find_module()`. >+In order to support imports of modules and initialized packages and also to >+contribute portions to namespace packages, path entry finders must implement >+the :meth:`find_loader()` method. This is an improvement, because it de-emphasizes the deprecated API. Perhaps add a footnote that describes the legacy API? > :meth:`find_loader()` takes one argument, the fully qualified name of the > module being imported. :meth:`find_loader()` returns a 2-tuple where the > first item is the loader and the second item is a namespace :term:`portion`. > When the first item (i.e. the loader) is ``None``, this means that while the >-path entry finder does not have a loader for the named module, it knows that >-the :term:`path entry` contributes to a namespace portion for the named >-module. This will almost always be the case where Python is asked to import a >-:term:`namespace package` that has no physical presence on the file system. >-When a path entry finder returns ``None`` for the loader, the second item of >-the 2-tuple return value must be a sequence, although it can be empty. >+path entry finder does not have a loader for the named module, it knows that the >+path entry contributes to a namespace portion for the named module. This will >+almost always be the case where Python is asked to import a namespace package >+that has no physical presence on the file system. When a path entry finder >+returns ``None`` for the loader, the second item of the 2-tuple return value >+must be a sequence, although it can be empty. > > If :meth:`find_loader()` returns a non-``None`` loader value, the portion is >-ignored and the loader is returned from the :term:`path importer`, terminating >-the :term:`import path` search. >+ignored and the loader is returned from the path importer, terminating the >+search through the path entries. >+ >+For backwards compatibility with other implementations of the import >+protocol, many path entry finders also support the same, >+traditional :meth:`find_module()` method that meta path finders support. >+However path entry finder :meth:`find_module()` methods are never called >+with a ``path`` argument (they are expected to record the appropriate >+path information from the initial call to the path hook). >+ >+The :meth:`find_module()` method on path entry finders is deprecated, >+as it does not allow the path entry finder to contribute portions to >+namespace packages. Instead path entry finders should implement the >+:meth:`find_loader()` method as described above. If it exists on the path >+entry finder, the import system will always call :meth:`find_loader()` >+in preference to :meth:`find_module()`. The above is what could be moved to the footnote. Cheers, -Barry From chris.jerdonek at gmail.com Thu Aug 2 16:41:05 2012 From: chris.jerdonek at gmail.com (Chris Jerdonek) Date: Thu, 2 Aug 2012 07:41:05 -0700 Subject: [Python-checkins] cpython: Issue #15502: Bring the importlib.PathFinder docs and docstring more in line In-Reply-To: <20120802103219.19acba49@resist.wooz.org> References: <3Wns631KFWzPhs@mail.python.org> <20120802103219.19acba49@resist.wooz.org> Message-ID: On Thu, Aug 2, 2012 at 7:32 AM, Barry Warsaw wrote: > On Aug 02, 2012, at 03:04 PM, nick.coghlan wrote: > >>-module. Specifically, any module that contains an ``__path__`` attribute is >>+module. Specifically, any module that contains a ``__path__`` attribute is > > I find this change hilarious! Is it "an under-under path" or "a dunder path"? Personally, I just say "path" (same with __init__, __main__, etc) and rely on context. --Chris From brett at python.org Thu Aug 2 17:35:55 2012 From: brett at python.org (Brett Cannon) Date: Thu, 2 Aug 2012 11:35:55 -0400 Subject: [Python-checkins] cpython: Issue #15502: Bring the importlib ABCs into line with the current state of the In-Reply-To: <3Wnpx25v1RzPhl@mail.python.org> References: <3Wnpx25v1RzPhl@mail.python.org> Message-ID: Mostly as a note to myself (although if someone else wants to change this, then great), PathEntryFinder.find_loader() specifies self while the other docs don't bother to list it. And I just realized that the other classes defined in the importlib docs don't list their superclasses like MetaPathFinder and PathEntryFinder now do. On Thu, Aug 2, 2012 at 7:26 AM, nick.coghlan wrote: > http://hg.python.org/cpython/rev/184700df5b6a > changeset: 78379:184700df5b6a > parent: 78376:8ace059cdffd > user: Nick Coghlan > date: Thu Aug 02 21:26:03 2012 +1000 > summary: > Issue #15502: Bring the importlib ABCs into line with the current state > of the import protocols given PEP 420. Original patch by Eric Snow. > > files: > Doc/library/importlib.rst | 77 +++++--- > Lib/importlib/abc.py | 82 ++++++--- > Lib/test/test_importlib/source/test_abc_loader.py | 23 +- > Lib/test/test_importlib/test_abc.py | 7 +- > Misc/NEWS | 3 + > 5 files changed, 127 insertions(+), 65 deletions(-) > > > diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst > --- a/Doc/library/importlib.rst > +++ b/Doc/library/importlib.rst > @@ -125,32 +125,49 @@ > > .. class:: Finder > > - An abstract base class representing a :term:`finder`. > - See :pep:`302` for the exact definition for a finder. > - > - .. method:: find_loader(self, fullname): > - > - An abstract method for finding a :term:`loader` for the specified > - module. Returns a 2-tuple of ``(loader, portion)`` where portion > is a > - sequence of file system locations contributing to part of a > namespace > - package. The sequence may be empty. When present, > `find_loader()` is > - preferred over `find_module()`. > - > - .. versionadded: 3.3 > - > - .. method:: find_module(fullname, path=None) > - > - An abstract method for finding a :term:`loader` for the specified > - module. If the :term:`finder` is found on :data:`sys.meta_path` > and the > - module to be searched for is a subpackage or module then *path* > will > - be the value of :attr:`__path__` from the parent package. If a > loader > - cannot be found, ``None`` is returned. > + An abstract base class representing a :term:`finder`. Finder > + implementations should derive from (or register with) the more specific > + :class:`MetaPathFinder` or :class:`PathEntryFinder` ABCs. > > .. method:: invalidate_caches() > > - An optional method which, when called, should invalidate any > internal > - cache used by the finder. Used by :func:`invalidate_caches()` when > - invalidating the caches of all cached finders. > + An optional method which, when called, should invalidate any > internal > + cache used by the finder. Used by :func:`invalidate_caches()` when > + invalidating the caches of all cached finders. > + > + .. versionchanged:: 3.3 > + The API signatures for meta path finders and path entry finders > + were separated by PEP 420. Accordingly, the Finder ABC no > + longer requires implementation of a ``find_module()`` method. > + > + > +.. class:: MetaPathFinder(Finder) > + > + An abstract base class representing a :term:`meta path finder`. > + > + .. versionadded:: 3.3 > + > + .. method:: find_module(fullname, path) > + > + An abstract method for finding a :term:`loader` for the specified > + module. If this is a top-level import, *path* will be ``None``. > + Otheriwse, this is a search for a subpackage or module and *path* > + will be the value of :attr:`__path__` from the parent > + package. If a loader cannot be found, ``None`` is returned. > + > + > +.. class:: PathEntryFinder(Finder) > + > + An abstract base class representing a :term:`path entry finder`. > + > + .. versionadded:: 3.3 > + > + .. method:: find_loader(self, fullname): > + > + An abstract method for finding a :term:`loader` for the specified > + module. Returns a 2-tuple of ``(loader, portion)`` where portion > is a > + sequence of file system locations contributing to part of a > namespace > + package. The sequence may be empty. > > > .. class:: Loader > @@ -569,8 +586,8 @@ > > An :term:`importer` for built-in modules. All known built-in modules > are > listed in :data:`sys.builtin_module_names`. This class implements the > - :class:`importlib.abc.Finder` and :class:`importlib.abc.InspectLoader` > - ABCs. > + :class:`importlib.abc.MetaPathFinder` and > + :class:`importlib.abc.InspectLoader` ABCs. > > Only class methods are defined by this class to alleviate the need for > instantiation. > @@ -579,8 +596,8 @@ > .. class:: FrozenImporter > > An :term:`importer` for frozen modules. This class implements the > - :class:`importlib.abc.Finder` and :class:`importlib.abc.InspectLoader` > - ABCs. > + :class:`importlib.abc.MetaPathFinder` and > + :class:`importlib.abc.InspectLoader` ABCs. > > Only class methods are defined by this class to alleviate the need for > instantiation. > @@ -589,7 +606,7 @@ > .. class:: PathFinder > > :term:`Finder` for :data:`sys.path`. This class implements the > - :class:`importlib.abc.Finder` ABC. > + :class:`importlib.abc.MetaPathFinder` ABC. > > This class does not perfectly mirror the semantics of > :keyword:`import` in > terms of :data:`sys.path`. No implicit path hooks are assumed for > @@ -616,8 +633,8 @@ > > .. class:: FileFinder(path, \*loader_details) > > - A concrete implementation of :class:`importlib.abc.Finder` which caches > - results from the file system. > + A concrete implementation of :class:`importlib.abc.PathEntryFinder` > which > + caches results from the file system. > > The *path* argument is the directory for which the finder is in charge > of > searching. > diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py > --- a/Lib/importlib/abc.py > +++ b/Lib/importlib/abc.py > @@ -23,6 +23,61 @@ > abstract_cls.register(frozen_cls) > > > +class Finder(metaclass=abc.ABCMeta): > + > + """Common abstract base class for import finders. > + > + Finder implementations should derive from the more specific > + MetaPathFinder or PathEntryFinder ABCs rather than directly from > Finder. > + """ > + > + def find_module(self, fullname, path=None): > + """An optional legacy method that should find a module. > + The fullname is a str and the optional path is a str or None. > + Returns a Loader object. > + > + The path finder will use this method only if find_loader() does > + not exist. It may optionally be implemented for compatibility > + with legacy third party reimplementations of the import system. > + """ > + raise NotImplementedError > + > + # invalidate_caches() is a completely optional method, so no default > + # implementation is provided. See the docs for details. > + > + > +class MetaPathFinder(Finder): > + > + """Abstract base class for import finders on sys.meta_path.""" > + > + @abc.abstractmethod > + def find_module(self, fullname, path): > + """Abstract method which when implemented should find a module. > + The fullname is a str and the path is a str or None. > + Returns a Loader object. > + """ > + raise NotImplementedError > + > +_register(MetaPathFinder, machinery.BuiltinImporter, > machinery.FrozenImporter, > + machinery.PathFinder) > + > + > +class PathEntryFinder(Finder): > + > + """Abstract base class for path entry finders used by PathFinder.""" > + > + @abc.abstractmethod > + def find_loader(self, fullname): > + """Abstract method which when implemented returns a module loader. > + The fullname is a str. Returns a 2-tuple of (Loader, portion) > where > + portion is a sequence of file system locations contributing to > part of > + a namespace package. The sequence may be empty. > + """ > + raise NotImplementedError > + > +_register(PathEntryFinder, machinery.FileFinder) > + > + > class Loader(metaclass=abc.ABCMeta): > > """Abstract base class for import loaders.""" > @@ -40,33 +95,6 @@ > raise NotImplementedError > > > -class Finder(metaclass=abc.ABCMeta): > - > - """Abstract base class for import finders.""" > - > - @abc.abstractmethod > - def find_loader(self, fullname): > - """Abstract method which when implemented returns a module loader. > - The fullname is a str. Returns a 2-tuple of (Loader, portion) > where > - portion is a sequence of file system locations contributing to > part of > - a namespace package. The sequence may be empty. When present, > - `find_loader()` is preferred over `find_module()`. > - """ > - raise NotImplementedError > - > - @abc.abstractmethod > - def find_module(self, fullname, path=None): > - """Abstract method which when implemented should find a module. > - The fullname is a str and the optional path is a str or None. > - Returns a Loader object. This method is only called if > - `find_loader()` is not present. > - """ > - raise NotImplementedError > - > -_register(Finder, machinery.BuiltinImporter, machinery.FrozenImporter, > - machinery.PathFinder, machinery.FileFinder) > - > - > class ResourceLoader(Loader): > > """Abstract base class for loaders which can return data from their > 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 > @@ -778,23 +778,32 @@ > expect = io.IncrementalNewlineDecoder(None, True).decode(source) > self.assertEqual(mock.get_source(name), expect) > > + > class AbstractMethodImplTests(unittest.TestCase): > > """Test the concrete abstractmethod implementations.""" > > + class MetaPathFinder(abc.MetaPathFinder): > + def find_module(self, fullname, path): > + super().find_module(fullname, path) > + > + class PathEntryFinder(abc.PathEntryFinder): > + def find_module(self, _): > + super().find_module(_) > + > + def find_loader(self, _): > + super().find_loader(_) > + > + class Finder(abc.Finder): > + def find_module(self, fullname, path): > + super().find_module(fullname, path) > + > class Loader(abc.Loader): > def load_module(self, fullname): > super().load_module(fullname) > def module_repr(self, module): > super().module_repr(module) > > - class Finder(abc.Finder): > - def find_module(self, _): > - super().find_module(_) > - > - def find_loader(self, _): > - super().find_loader(_) > - > class ResourceLoader(Loader, abc.ResourceLoader): > def get_data(self, _): > super().get_data(_) > diff --git a/Lib/test/test_importlib/test_abc.py > b/Lib/test/test_importlib/test_abc.py > --- a/Lib/test/test_importlib/test_abc.py > +++ b/Lib/test/test_importlib/test_abc.py > @@ -30,11 +30,16 @@ > "{0} is not a superclass of {1}".format(superclass, > self.__test)) > > > -class Finder(InheritanceTests, unittest.TestCase): > +class MetaPathFinder(InheritanceTests, unittest.TestCase): > > + superclasses = [abc.Finder] > subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter, > machinery.PathFinder] > > +class PathEntryFinder(InheritanceTests, unittest.TestCase): > + > + superclasses = [abc.Finder] > + subclasses = [machinery.FileFinder] > > class Loader(InheritanceTests, unittest.TestCase): > > diff --git a/Misc/NEWS b/Misc/NEWS > --- a/Misc/NEWS > +++ b/Misc/NEWS > @@ -72,6 +72,9 @@ > Library > ------- > > +- Issue #15502: Bring the importlib ABCs into line with the current state > + of the import protocols given PEP 420. Original patch by Eric Snow. > + > - Issue #15499: Launching a webbrowser in Unix used to sleep for a few > seconds. Original patch by Anton Barkovsky. > > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stephen at xemacs.org Thu Aug 2 17:49:28 2012 From: stephen at xemacs.org (Stephen J. Turnbull) Date: Fri, 03 Aug 2012 00:49:28 +0900 Subject: [Python-checkins] [Python-Dev] cpython: Issue #15502: Bring the importlib.PathFinder docs and docstring more in line In-Reply-To: References: <3Wns631KFWzPhs@mail.python.org> <20120802103219.19acba49@resist.wooz.org> Message-ID: <876291l2ev.fsf@uwakimon.sk.tsukuba.ac.jp> Chris Jerdonek writes: > On Thu, Aug 2, 2012 at 7:32 AM, Barry Warsaw wrote: > > I find this change hilarious! Is it "an under-under path" or "a > > dunder path"? > > Personally, I just say "path" (same with __init__, __main__, etc) and > rely on context. I think that's what the Chicago Manual of Style recommends. Now-needing-surgery-for-my-cheek-hernia-ly y'rs, From python-checkins at python.org Thu Aug 2 20:42:17 2012 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 2 Aug 2012 20:42:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NTM4?= =?utf-8?q?=3A_Fix_compilation_of_the_getnameinfo=28=29_/_getaddrinfo=28?= =?utf-8?q?=29_emulation?= Message-ID: <3Wp0c90sBdzPct@mail.python.org> http://hg.python.org/cpython/rev/86558ff7ce33 changeset: 78383:86558ff7ce33 branch: 2.7 parent: 78378:29bdbcadf299 user: Antoine Pitrou date: Thu Aug 02 20:37:12 2012 +0200 summary: Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() emulation code. Patch by Philipp Hagemeister. files: Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/getaddrinfo.c | 2 +- Modules/getnameinfo.c | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -323,6 +323,7 @@ Lars Gust?bel Thomas G?ttler Barry Haddow +Philipp Hagemeister Paul ten Hagen Rasmus Hahn Peter Haight diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -92,6 +92,9 @@ Library ------- +- Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() + emulation code. Patch by Philipp Hagemeister. + - Issue #9803: Don't close IDLE on saving if breakpoint is open. Patch by Roger Serwy. diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c --- a/Modules/getaddrinfo.c +++ b/Modules/getaddrinfo.c @@ -430,7 +430,7 @@ break; #ifdef ENABLE_IPV6 case AF_INET6: - pfx = ((struct in6_addr *)pton)->s6_addr8[0]; + pfx = ((struct in6_addr *)pton)->s6_addr[0]; if (pfx == 0 || pfx == 0xfe || pfx == 0xff) pai->ai_flags &= ~AI_CANONNAME; break; diff --git a/Modules/getnameinfo.c b/Modules/getnameinfo.c --- a/Modules/getnameinfo.c +++ b/Modules/getnameinfo.c @@ -161,7 +161,7 @@ break; #ifdef ENABLE_IPV6 case AF_INET6: - pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr8[0]; + pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[0]; if (pfx == 0 || pfx == 0xfe || pfx == 0xff) flags |= NI_NUMERICHOST; break; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 20:42:20 2012 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 2 Aug 2012 20:42:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NTM4?= =?utf-8?q?=3A_Fix_compilation_of_the_getnameinfo=28=29_/_getaddrinfo=28?= =?utf-8?q?=29_emulation?= Message-ID: <3Wp0cD0LVszPjM@mail.python.org> http://hg.python.org/cpython/rev/547f3a55a216 changeset: 78384:547f3a55a216 branch: 3.2 parent: 78377:014b36383a54 user: Antoine Pitrou date: Thu Aug 02 20:37:12 2012 +0200 summary: Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() emulation code. Patch by Philipp Hagemeister. files: Misc/NEWS | 3 +++ Modules/getaddrinfo.c | 2 +- Modules/getnameinfo.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -98,6 +98,9 @@ Library ------- +- Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() + emulation code. Patch by Philipp Hagemeister. + - Issue #9803: Don't close IDLE on saving if breakpoint is open. Patch by Roger Serwy. diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c --- a/Modules/getaddrinfo.c +++ b/Modules/getaddrinfo.c @@ -430,7 +430,7 @@ break; #ifdef ENABLE_IPV6 case AF_INET6: - pfx = ((struct in6_addr *)pton)->s6_addr8[0]; + pfx = ((struct in6_addr *)pton)->s6_addr[0]; if (pfx == 0 || pfx == 0xfe || pfx == 0xff) pai->ai_flags &= ~AI_CANONNAME; break; diff --git a/Modules/getnameinfo.c b/Modules/getnameinfo.c --- a/Modules/getnameinfo.c +++ b/Modules/getnameinfo.c @@ -161,7 +161,7 @@ break; #ifdef ENABLE_IPV6 case AF_INET6: - pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr8[0]; + pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[0]; if (pfx == 0 || pfx == 0xfe || pfx == 0xff) flags |= NI_NUMERICHOST; break; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 20:42:21 2012 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 2 Aug 2012 20:42:21 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315538=3A_Fix_compilation_of_the_getnameinfo=28?= =?utf-8?q?=29_/_getaddrinfo=28=29_emulation?= Message-ID: <3Wp0cF4sJLzPjQ@mail.python.org> http://hg.python.org/cpython/rev/61a56e982e98 changeset: 78385:61a56e982e98 parent: 78382:1f8351cf00f3 parent: 78384:547f3a55a216 user: Antoine Pitrou date: Thu Aug 02 20:39:10 2012 +0200 summary: Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() emulation code. Patch by Philipp Hagemeister. files: Misc/NEWS | 3 +++ Modules/getaddrinfo.c | 2 +- Modules/getnameinfo.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -72,6 +72,9 @@ Library ------- +- Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() + emulation code. Patch by Philipp Hagemeister. + - Issue #15519: Properly expose WindowsRegistryFinder in importlib (and use the correct term for it). Original patch by Eric Snow. diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c --- a/Modules/getaddrinfo.c +++ b/Modules/getaddrinfo.c @@ -430,7 +430,7 @@ break; #ifdef ENABLE_IPV6 case AF_INET6: - pfx = ((struct in6_addr *)pton)->s6_addr8[0]; + pfx = ((struct in6_addr *)pton)->s6_addr[0]; if (pfx == 0 || pfx == 0xfe || pfx == 0xff) pai->ai_flags &= ~AI_CANONNAME; break; diff --git a/Modules/getnameinfo.c b/Modules/getnameinfo.c --- a/Modules/getnameinfo.c +++ b/Modules/getnameinfo.c @@ -161,7 +161,7 @@ break; #ifdef ENABLE_IPV6 case AF_INET6: - pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr8[0]; + pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[0]; if (pfx == 0 || pfx == 0xfe || pfx == 0xff) flags |= NI_NUMERICHOST; break; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 23:09:18 2012 From: python-checkins at python.org (victor.stinner) Date: Thu, 2 Aug 2012 23:09:18 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2315534=3A_Fix_a_ty?= =?utf-8?q?po_in_the_fast_search_function_of_the_string_library_=28=5Fs?= Message-ID: <3Wp3sp3fMlzPfh@mail.python.org> http://hg.python.org/cpython/rev/0e95b61af859 changeset: 78386:0e95b61af859 user: Victor Stinner date: Thu Aug 02 23:05:01 2012 +0200 summary: Close #15534: Fix a typo in the fast search function of the string library (_s => s) Replace _s with ptr to avoid future confusion. Add also non regression tests. files: Lib/test/string_tests.py | 8 ++++++++ Misc/NEWS | 4 +++- Objects/stringlib/fastsearch.h | 10 +++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -262,6 +262,9 @@ # issue 7458 self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0) + # issue #15534 + self.checkequal(0, '<......\u043c...', "rfind", "<") + def test_index(self): self.checkequal(0, 'abcdefghiabc', 'index', '') self.checkequal(3, 'abcdefghiabc', 'index', 'def') @@ -597,6 +600,8 @@ EQ("ReyKKjavik", "Reykjavik", "replace", "k", "KK", 1) EQ("Reykjavik", "Reykjavik", "replace", "k", "KK", 0) EQ("A----B----C----", "A.B.C.", "replace", ".", "----") + # issue #15534 + EQ('...\u043c......<', '...\u043c......<', "replace", "<", "<") EQ("Reykjavik", "Reykjavik", "replace", "q", "KK") @@ -1316,6 +1321,9 @@ self.assertRaisesRegex(TypeError, r'^endswith\(', s.endswith, x, None, None, None) + # issue #15534 + self.checkequal(10, "...\u043c......<", "find", "<") + class MixinStrUnicodeTest: # Additional tests that only work with str and unicode. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #15534: Fix the fast-search function for non-ASCII Unicode strings. + - Issue #15508: Fix the docstring for __import__ to have the proper default value of 0 for 'level' and to not mention negative levels since they are not supported. @@ -83,7 +85,7 @@ - Issue #15499: Launching a webbrowser in Unix used to sleep for a few seconds. Original patch by Anton Barkovsky. - + - Issue #15463: the faulthandler module truncates strings to 500 characters, instead of 100, to be able to display long file paths diff --git a/Objects/stringlib/fastsearch.h b/Objects/stringlib/fastsearch.h --- a/Objects/stringlib/fastsearch.h +++ b/Objects/stringlib/fastsearch.h @@ -48,16 +48,16 @@ } while (0) if (mode == FAST_SEARCH) { - const STRINGLIB_CHAR *_s = s; + const STRINGLIB_CHAR *ptr = s; const STRINGLIB_CHAR *e = s + n; - while (_s < e) { - DO_MEMCHR(memchr, _s, needle, e - _s); + while (ptr < e) { + DO_MEMCHR(memchr, ptr, needle, e - ptr); if (found == NULL) return -1; if (sizeof(STRINGLIB_CHAR) == 1 || *found == ch) - return (found - _s); + return (found - s); /* False positive */ - _s = found + 1; + ptr = found + 1; } return -1; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 23:50:13 2012 From: python-checkins at python.org (brett.cannon) Date: Thu, 2 Aug 2012 23:50:13 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Ditch_the_=27self=27_argum?= =?utf-8?q?ent_in_importlib_docs_since_it=27s_implied=2E?= Message-ID: <3Wp4n120B1zPVM@mail.python.org> http://hg.python.org/cpython/rev/0a4c7a1e53f2 changeset: 78387:0a4c7a1e53f2 user: Brett Cannon date: Thu Aug 02 17:35:34 2012 -0400 summary: Ditch the 'self' argument in importlib docs since it's implied. files: Doc/library/importlib.rst | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -162,7 +162,7 @@ .. versionadded:: 3.3 - .. method:: find_loader(self, fullname): + .. method:: find_loader(fullname): An abstract method for finding a :term:`loader` for the specified module. Returns a 2-tuple of ``(loader, portion)`` where portion is a @@ -336,7 +336,7 @@ optimization to speed up loading by removing the parsing step of Python's compiler, and so no bytecode-specific API is exposed. - .. method:: path_stats(self, path) + .. method:: path_stats(path) Optional abstract method which returns a :class:`dict` containing metadata about the specifed path. Supported dictionary keys are: @@ -350,7 +350,7 @@ .. versionadded:: 3.3 - .. method:: path_mtime(self, path) + .. method:: path_mtime(path) Optional abstract method which returns the modification time for the specified path. @@ -360,7 +360,7 @@ have to implement it, but it is still available for compatibility purposes. - .. method:: set_data(self, path, data) + .. method:: set_data(path, data) Optional abstract method which writes the specified bytes to a file path. Any intermediate directories which do not exist are to be created @@ -369,19 +369,19 @@ When writing to the path fails because the path is read-only (:attr:`errno.EACCES`), do not propagate the exception. - .. method:: get_code(self, fullname) + .. method:: get_code(fullname) Concrete implementation of :meth:`InspectLoader.get_code`. - .. method:: load_module(self, fullname) + .. method:: load_module(fullname) Concrete implementation of :meth:`Loader.load_module`. - .. method:: get_source(self, fullname) + .. method:: get_source(fullname) Concrete implementation of :meth:`InspectLoader.get_source`. - .. method:: is_package(self, fullname) + .. method:: is_package(fullname) Concrete implementation of :meth:`InspectLoader.is_package`. A module is determined to be a package if its file path (as provided by -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 2 23:50:15 2012 From: python-checkins at python.org (brett.cannon) Date: Thu, 2 Aug 2012 23:50:15 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Update_the_What=27s_New_de?= =?utf-8?q?tails_for_importlib_based_on_doc/ABC_changes=2E?= Message-ID: <3Wp4n324DJzPhs@mail.python.org> http://hg.python.org/cpython/rev/083534cd7874 changeset: 78388:083534cd7874 user: Brett Cannon date: Thu Aug 02 17:50:06 2012 -0400 summary: Update the What's New details for importlib based on doc/ABC changes. files: Doc/library/importlib.rst | 10 ++++++---- Doc/whatsnew/3.3.rst | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -141,9 +141,10 @@ longer requires implementation of a ``find_module()`` method. -.. class:: MetaPathFinder(Finder) +.. class:: MetaPathFinder - An abstract base class representing a :term:`meta path finder`. + An abstract base class representing a :term:`meta path finder` and + inheriting from :class:`Finder`. .. versionadded:: 3.3 @@ -156,9 +157,10 @@ package. If a loader cannot be found, ``None`` is returned. -.. class:: PathEntryFinder(Finder) +.. class:: PathEntryFinder - An abstract base class representing a :term:`path entry finder`. + An abstract base class representing a :term:`path entry finder` and + inheriting from :class:`Finder`. .. versionadded:: 3.3 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 @@ -519,7 +519,15 @@ making the import statement work. That means the various importers that were once implicit are now fully exposed as part of the :mod:`importlib` package. -In terms of finders, * :class:`importlib.machinery.FileFinder` exposes the +The abstract base classes defined in :mod:`importlib.abc` have been expanded +to properly delineate between :term:`meta path finders ` +and :term:`path entry finders ` by introducing +:class:`importlib.abc.MetaPathFinder` and +:class:`importlib.abc.PathEntryFinder`, respectively. The old ABC of +:class:`importlib.abc.Finder` is now only provided for backwards-compatibility +and does not enforce any method requirements. + +In terms of finders, :class:`importlib.machinery.FileFinder` exposes the mechanism used to search for source and bytecode files of a module. Previously this class was an implicit member of :attr:`sys.path_hooks`. @@ -547,10 +555,10 @@ Beyond the expanse of what :mod:`importlib` now exposes, there are other visible changes to import. The biggest is that :attr:`sys.meta_path` and -:attr:`sys.path_hooks` now store all of the finders used by import explicitly. -Previously the finders were implicit and hidden within the C code of import -instead of being directly exposed. This means that one can now easily remove or -change the order of the various finders to fit one's needs. +:attr:`sys.path_hooks` now store all of the meta path finders and path entry +hooks used by import. Previously the finders were implicit and hidden within +the C code of import instead of being directly exposed. This means that one can +now easily remove or change the order of the various finders to fit one's needs. Another change is that all modules have a ``__loader__`` attribute, storing the loader used to create the module. :pep:`302` has been updated to make this @@ -1733,6 +1741,12 @@ both the modification time and size of the source file the bytecode file was compiled from. +* :class:`importlib.abc.Finder` no longer specifies a `find_module()` abstract + method that must be implemented. If you were relying on subclasses to + implement that method, make sure to check for the method's existence first. + You will probably want to check for `find_loader()` first, though, in the + case of working with :term:`path entry finders `. + * :mod:`pkgutil` has been converted to use :mod:`importlib` internally. This eliminates many edge cases where the old behaviour of the PEP 302 import emulation failed to match the behaviour of the real import system. The -- Repository URL: http://hg.python.org/cpython From brett at python.org Thu Aug 2 23:53:46 2012 From: brett at python.org (Brett Cannon) Date: Thu, 2 Aug 2012 17:53:46 -0400 Subject: [Python-checkins] cpython: Update the What's New details for importlib based on doc/ABC changes. In-Reply-To: <3Wp4n324DJzPhs@mail.python.org> References: <3Wp4n324DJzPhs@mail.python.org> Message-ID: Sorry about accidentally committing another minor cleanup to importlib in this commit; thought I had already committed it separately. On Thu, Aug 2, 2012 at 5:50 PM, brett.cannon wrote: > http://hg.python.org/cpython/rev/083534cd7874 > changeset: 78388:083534cd7874 > user: Brett Cannon > date: Thu Aug 02 17:50:06 2012 -0400 > summary: > Update the What's New details for importlib based on doc/ABC changes. > > files: > Doc/library/importlib.rst | 10 ++++++---- > Doc/whatsnew/3.3.rst | 24 +++++++++++++++++++----- > 2 files changed, 25 insertions(+), 9 deletions(-) > > > diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst > --- a/Doc/library/importlib.rst > +++ b/Doc/library/importlib.rst > @@ -141,9 +141,10 @@ > longer requires implementation of a ``find_module()`` method. > > > -.. class:: MetaPathFinder(Finder) > +.. class:: MetaPathFinder > > - An abstract base class representing a :term:`meta path finder`. > + An abstract base class representing a :term:`meta path finder` and > + inheriting from :class:`Finder`. > > .. versionadded:: 3.3 > > @@ -156,9 +157,10 @@ > package. If a loader cannot be found, ``None`` is returned. > > > -.. class:: PathEntryFinder(Finder) > +.. class:: PathEntryFinder > > - An abstract base class representing a :term:`path entry finder`. > + An abstract base class representing a :term:`path entry finder` and > + inheriting from :class:`Finder`. > > .. versionadded:: 3.3 > > 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 > @@ -519,7 +519,15 @@ > making the import statement work. That means the various importers that > were > once implicit are now fully exposed as part of the :mod:`importlib` > package. > > -In terms of finders, * :class:`importlib.machinery.FileFinder` exposes the > +The abstract base classes defined in :mod:`importlib.abc` have been > expanded > +to properly delineate between :term:`meta path finders ` > +and :term:`path entry finders ` by introducing > +:class:`importlib.abc.MetaPathFinder` and > +:class:`importlib.abc.PathEntryFinder`, respectively. The old ABC of > +:class:`importlib.abc.Finder` is now only provided for > backwards-compatibility > +and does not enforce any method requirements. > + > +In terms of finders, :class:`importlib.machinery.FileFinder` exposes the > mechanism used to search for source and bytecode files of a module. > Previously > this class was an implicit member of :attr:`sys.path_hooks`. > > @@ -547,10 +555,10 @@ > > Beyond the expanse of what :mod:`importlib` now exposes, there are other > visible changes to import. The biggest is that :attr:`sys.meta_path` and > -:attr:`sys.path_hooks` now store all of the finders used by import > explicitly. > -Previously the finders were implicit and hidden within the C code of > import > -instead of being directly exposed. This means that one can now easily > remove or > -change the order of the various finders to fit one's needs. > +:attr:`sys.path_hooks` now store all of the meta path finders and path > entry > +hooks used by import. Previously the finders were implicit and hidden > within > +the C code of import instead of being directly exposed. This means that > one can > +now easily remove or change the order of the various finders to fit one's > needs. > > Another change is that all modules have a ``__loader__`` attribute, > storing the > loader used to create the module. :pep:`302` has been updated to make this > @@ -1733,6 +1741,12 @@ > both the modification time and size of the source file the bytecode > file was > compiled from. > > +* :class:`importlib.abc.Finder` no longer specifies a `find_module()` > abstract > + method that must be implemented. If you were relying on subclasses to > + implement that method, make sure to check for the method's existence > first. > + You will probably want to check for `find_loader()` first, though, in > the > + case of working with :term:`path entry finders `. > + > * :mod:`pkgutil` has been converted to use :mod:`importlib` internally. > This > eliminates many edge cases where the old behaviour of the PEP 302 import > emulation failed to match the behaviour of the real import system. The > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Fri Aug 3 06:00:56 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 03 Aug 2012 06:00:56 +0200 Subject: [Python-checkins] Daily reference leaks (083534cd7874): sum=0 Message-ID: results for 083534cd7874 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogMzfybi', '-x'] From python-checkins at python.org Fri Aug 3 06:06:19 2012 From: python-checkins at python.org (ned.deily) Date: Fri, 3 Aug 2012 06:06:19 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Closes_=2315311_-_update_?= =?utf-8?q?devguide_publication_info=2E?= Message-ID: <3WpF6z0zNyzPhf@mail.python.org> http://hg.python.org/devguide/rev/864cd63db2bb changeset: 537:864cd63db2bb user: Ned Deily date: Thu Aug 02 21:05:33 2012 -0700 summary: Closes #15311 - update devguide publication info. (Patch by Chris Jerdoneck) files: docquality.rst | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/docquality.rst b/docquality.rst --- a/docquality.rst +++ b/docquality.rst @@ -76,7 +76,8 @@ make html -Changes to the documentation are published immediately using an update hook. +Changes to the documentation are normally published within a day on a +schedule that may be different from the main documentation. .. _separate repository: http://hg.python.org/devguide .. _Sphinx: http://sphinx.pocoo.org/ -- Repository URL: http://hg.python.org/devguide From ncoghlan at gmail.com Fri Aug 3 07:13:50 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Fri, 3 Aug 2012 15:13:50 +1000 Subject: [Python-checkins] cpython: Issue #15502: Bring the importlib.PathFinder docs and docstring more in line In-Reply-To: References: <3Wns631KFWzPhs@mail.python.org> <20120802103219.19acba49@resist.wooz.org> Message-ID: On Fri, Aug 3, 2012 at 12:41 AM, Chris Jerdonek wrote: > On Thu, Aug 2, 2012 at 7:32 AM, Barry Warsaw wrote: >> On Aug 02, 2012, at 03:04 PM, nick.coghlan wrote: >> >>>-module. Specifically, any module that contains an ``__path__`` attribute is >>>+module. Specifically, any module that contains a ``__path__`` attribute is >> >> I find this change hilarious! Is it "an under-under path" or "a dunder path"? > > Personally, I just say "path" (same with __init__, __main__, etc) and > rely on context. Yup. That's why I would write "a __path__ attribute", but "an __init__ method". If I have to be explicit when speaking, I'll typically say either "dunder " or "double underscore ". I find that's only needed if there is a name class between the double underscore name and a non-prefixed variable though, which doesn't happen very often. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From python-checkins at python.org Fri Aug 3 14:18:24 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 14:18:24 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Closes_=2315514=3A_Correct?= =?utf-8?q?_=5F=5Fsizeof=5F=5F_support_for_cpu=5Fset?= Message-ID: <3WpS2m00fWzPk8@mail.python.org> http://hg.python.org/cpython/rev/463d3ad22cdb changeset: 78389:463d3ad22cdb user: Jesus Cea date: Fri Aug 03 14:18:11 2012 +0200 summary: Closes #15514: Correct __sizeof__ support for cpu_set files: Lib/test/test_posix.py | 6 ++++++ Misc/NEWS | 3 +++ Modules/posixmodule.c | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 0 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 @@ -1008,6 +1008,12 @@ self.assertIs(b, l) self.assertEqual(l.count(), 3) + @requires_sched_affinity + @support.cpython_only + def test_cpu_set_sizeof(self): + self.assertGreater(sys.getsizeof(posix.cpu_set(1000)), + sys.getsizeof(posix.cpu_set(1))) + def test_rtld_constants(self): # check presence of major RTLD_* constants posix.RTLD_LAZY diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -373,6 +373,9 @@ - Issue #15487: Add a __sizeof__ implementation for buffered I/O objects. Patch by Serhiy Storchaka. +- Issue #15514: Correct __sizeof__ support for cpu_set. + Patch by Serhiy Storchaka. + - Issue #15187: Bugfix: remove temporary directories test_shutil was leaving behind. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5772,6 +5772,20 @@ return (PyObject *)make_new_cpu_set(type, size); } +PyDoc_STRVAR(cpu_set_sizeof_doc, +"cpu_set.__sizeof__() -> int\n\n\ +Returns size in memory, in bytes."); + +static PyObject * +cpu_set_sizeof(Py_cpu_set *set, PyObject *noargs) +{ + Py_ssize_t res = 0; + + res = sizeof(Py_cpu_set); + res += set->size; + return PyLong_FromSsize_t(res); +} + static PyObject * cpu_set_repr(Py_cpu_set *set) { @@ -5959,6 +5973,7 @@ {"isset", (PyCFunction)cpu_set_isset, METH_VARARGS, cpu_set_isset_doc}, {"set", (PyCFunction)cpu_set_set, METH_VARARGS, cpu_set_set_doc}, {"zero", (PyCFunction)cpu_set_zero, METH_NOARGS, cpu_set_zero_doc}, + {"__sizeof__", (PyCFunction)cpu_set_sizeof, METH_NOARGS, cpu_set_sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 14:29:49 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 14:29:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICMxNTUx?= =?utf-8?q?2=3A_Correct_=5F=5Fsizeof=5F=5F_support_for_parser?= Message-ID: <3WpSHx1LdSzPWr@mail.python.org> http://hg.python.org/cpython/rev/aceb975c4832 changeset: 78390:aceb975c4832 branch: 2.7 parent: 78383:86558ff7ce33 user: Jesus Cea date: Fri Aug 03 14:25:53 2012 +0200 summary: Closes #15512: Correct __sizeof__ support for parser files: Include/node.h | 3 + Lib/test/test_parser.py | 52 +++++++++++++++++++++++++++- Misc/NEWS | 3 + Modules/parsermodule.c | 23 +++++++++++- Parser/node.c | 26 ++++++++++++++ 5 files changed, 103 insertions(+), 4 deletions(-) diff --git a/Include/node.h b/Include/node.h --- a/Include/node.h +++ b/Include/node.h @@ -20,6 +20,9 @@ PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, char *str, int lineno, int col_offset); PyAPI_FUNC(void) PyNode_Free(node *n); +#ifndef Py_LIMITED_API +Py_ssize_t _PyNode_SizeOf(node *n); +#endif /* Node access functions */ #define NCH(n) ((n)->n_nchildren) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -1,7 +1,8 @@ import parser import unittest import sys -from test import test_support +import struct +from test import test_support as support # # First, we test that we can generate trees from valid source fragments, @@ -583,12 +584,59 @@ print >>sys.stderr, "Expecting 's_push: parser stack overflow' in next line" self.assertRaises(MemoryError, parser.expr, e) +class STObjectTestCase(unittest.TestCase): + """Test operations on ST objects themselves""" + + check_sizeof = support.check_sizeof + + @support.cpython_only + def test_sizeof(self): + def XXXROUNDUP(n): + if n <= 1: + return n + if n <= 128: + return (n + 3) & ~3 + return 1 << (n - 1).bit_length() + + basesize = support.calcobjsize('Pii') + nodesize = struct.calcsize('hP3iP0h') + def sizeofchildren(node): + if node is None: + return 0 + res = 0 + hasstr = len(node) > 1 and isinstance(node[-1], str) + if hasstr: + res += len(node[-1]) + 1 + children = node[1:-1] if hasstr else node[1:] + if children: + res += XXXROUNDUP(len(children)) * nodesize + res1 = res + if children: + for child in children: + res += sizeofchildren(child) + return res + + def check_st_sizeof(st): + self.check_sizeof(st, basesize + nodesize + + sizeofchildren(st.totuple())) + + check_st_sizeof(parser.expr('2 + 3')) + check_st_sizeof(parser.expr('2 + 3 + 4')) + check_st_sizeof(parser.suite('x = 2 + 3')) + check_st_sizeof(parser.suite('')) + check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-')) + check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']')) + + + # XXX tests for pickling and unpickling of ST objects should go here + def test_main(): - test_support.run_unittest( + support.run_unittest( RoundtripLegalSyntaxTestCase, IllegalSyntaxTestCase, CompileTestCase, ParserStackLimitTestCase, + STObjectTestCase, ) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ - Issue #15487: Add a __sizeof__ implementation for buffered I/O objects. Patch by Serhiy Storchaka. +- Issue #15512: Add a __sizeof__ implementation for parser. + Patch by Serhiy Storchaka. + - Issue #15402: An issue in the struct module that caused sys.getsizeof to return incorrect results for struct.Struct instances has been fixed. Initial patch by Serhiy Storchaka. diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -169,8 +169,10 @@ static void parser_free(PyST_Object *st); +static PyObject* parser_sizeof(PyST_Object *, void *); static int parser_compare(PyST_Object *left, PyST_Object *right); static PyObject *parser_getattr(PyObject *self, char *name); +static PyMethodDef parser_methods[]; static @@ -200,7 +202,14 @@ Py_TPFLAGS_DEFAULT, /* tp_flags */ /* __doc__ */ - "Intermediate representation of a Python parse tree." + "Intermediate representation of a Python parse tree.", + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + parser_methods, /* tp_methods */ }; /* PyST_Type */ @@ -508,7 +517,8 @@ PyDoc_STR("Creates a list-tree representation of this ST.")}, {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, PyDoc_STR("Creates a tuple-tree representation of this ST.")}, - + {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS, + PyDoc_STR("Returns size in memory, in bytes.")}, {NULL, NULL, 0, NULL} }; @@ -695,6 +705,15 @@ return parser_tuple2st(self, args, kw); } +static PyObject * +parser_sizeof(PyST_Object *st, void *unused) +{ + Py_ssize_t res; + + res = sizeof(PyST_Object) + _PyNode_SizeOf(st->st_node); + return PyLong_FromSsize_t(res); +} + /* node* build_node_children() * diff --git a/Parser/node.c b/Parser/node.c --- a/Parser/node.c +++ b/Parser/node.c @@ -114,6 +114,7 @@ /* Forward */ static void freechildren(node *); +static Py_ssize_t sizeofchildren(node *n); void @@ -125,6 +126,16 @@ } } +Py_ssize_t +_PyNode_SizeOf(node *n) +{ + Py_ssize_t res = 0; + + if (n != NULL) + res = sizeof(node) + sizeofchildren(n); + return res; +} + static void freechildren(node *n) { @@ -136,3 +147,18 @@ if (STR(n) != NULL) PyObject_FREE(STR(n)); } + +static Py_ssize_t +sizeofchildren(node *n) +{ + Py_ssize_t res = 0; + int i; + for (i = NCH(n); --i >= 0; ) + res += sizeofchildren(CHILD(n, i)); + if (n->n_child != NULL) + /* allocated size of n->n_child array */ + res += XXXROUNDUP(NCH(n)) * sizeof(node); + if (STR(n) != NULL) + res += strlen(STR(n)) + 1; + return res; +} -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 14:29:50 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 14:29:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogQ2xvc2VzICMxNTUx?= =?utf-8?q?2=3A_Correct_=5F=5Fsizeof=5F=5F_support_for_parser?= Message-ID: <3WpSHy67Z9zPfh@mail.python.org> http://hg.python.org/cpython/rev/91884d04de06 changeset: 78391:91884d04de06 branch: 3.2 parent: 78384:547f3a55a216 user: Jesus Cea date: Fri Aug 03 14:28:37 2012 +0200 summary: Closes #15512: Correct __sizeof__ support for parser files: Include/node.h | 3 ++ Lib/test/test_parser.py | 41 +++++++++++++++++++++++++++++ Misc/NEWS | 3 ++ Modules/parsermodule.c | 13 ++++++++- Parser/node.c | 26 ++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletions(-) diff --git a/Include/node.h b/Include/node.h --- a/Include/node.h +++ b/Include/node.h @@ -20,6 +20,9 @@ PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, char *str, int lineno, int col_offset); PyAPI_FUNC(void) PyNode_Free(node *n); +#ifndef Py_LIMITED_API +Py_ssize_t _PyNode_SizeOf(node *n); +#endif /* Node access functions */ #define NCH(n) ((n)->n_nchildren) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -2,6 +2,7 @@ import unittest import sys import operator +import struct from test import support # @@ -675,6 +676,46 @@ self.assertRaises(TypeError, operator.lt, st1, 1815) self.assertRaises(TypeError, operator.gt, b'waterloo', st2) + check_sizeof = support.check_sizeof + + @support.cpython_only + def test_sizeof(self): + def XXXROUNDUP(n): + if n <= 1: + return n + if n <= 128: + return (n + 3) & ~3 + return 1 << (n - 1).bit_length() + + basesize = support.calcobjsize('Pii') + nodesize = struct.calcsize('hP3iP0h') + def sizeofchildren(node): + if node is None: + return 0 + res = 0 + hasstr = len(node) > 1 and isinstance(node[-1], str) + if hasstr: + res += len(node[-1]) + 1 + children = node[1:-1] if hasstr else node[1:] + if children: + res += XXXROUNDUP(len(children)) * nodesize + res1 = res + if children: + for child in children: + res += sizeofchildren(child) + return res + + def check_st_sizeof(st): + self.check_sizeof(st, basesize + nodesize + + sizeofchildren(st.totuple())) + + check_st_sizeof(parser.expr('2 + 3')) + check_st_sizeof(parser.expr('2 + 3 + 4')) + check_st_sizeof(parser.suite('x = 2 + 3')) + check_st_sizeof(parser.suite('')) + check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-')) + check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']')) + # XXX tests for pickling and unpickling of ST objects should go here diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ - Issue #12288: Consider '0' and '0.0' as valid initialvalue for tkinter SimpleDialog. +- Issue #15512: Add a __sizeof__ implementation for parser. + Patch by Serhiy Storchaka. + - Issue #15489: Add a __sizeof__ implementation for BytesIO objects. Patch by Serhiy Storchaka. diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -167,6 +167,7 @@ static void parser_free(PyST_Object *st); +static PyObject* parser_sizeof(PyST_Object *, void *); static PyObject* parser_richcompare(PyObject *left, PyObject *right, int op); static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); @@ -187,7 +188,8 @@ PyDoc_STR("Creates a list-tree representation of this ST.")}, {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, PyDoc_STR("Creates a tuple-tree representation of this ST.")}, - + {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS, + PyDoc_STR("Returns size in memory, in bytes.")}, {NULL, NULL, 0, NULL} }; @@ -361,6 +363,15 @@ PyObject_Del(st); } +static PyObject * +parser_sizeof(PyST_Object *st, void *unused) +{ + Py_ssize_t res; + + res = sizeof(PyST_Object) + _PyNode_SizeOf(st->st_node); + return PyLong_FromSsize_t(res); +} + /* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw) * diff --git a/Parser/node.c b/Parser/node.c --- a/Parser/node.c +++ b/Parser/node.c @@ -114,6 +114,7 @@ /* Forward */ static void freechildren(node *); +static Py_ssize_t sizeofchildren(node *n); void @@ -125,6 +126,16 @@ } } +Py_ssize_t +_PyNode_SizeOf(node *n) +{ + Py_ssize_t res = 0; + + if (n != NULL) + res = sizeof(node) + sizeofchildren(n); + return res; +} + static void freechildren(node *n) { @@ -136,3 +147,18 @@ if (STR(n) != NULL) PyObject_FREE(STR(n)); } + +static Py_ssize_t +sizeofchildren(node *n) +{ + Py_ssize_t res = 0; + int i; + for (i = NCH(n); --i >= 0; ) + res += sizeofchildren(CHILD(n, i)); + if (n->n_child != NULL) + /* allocated size of n->n_child array */ + res += XXXROUNDUP(NCH(n)) * sizeof(node); + if (STR(n) != NULL) + res += strlen(STR(n)) + 1; + return res; +} -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 14:29:52 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 14:29:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTUVSR0U6IENsb3NlcyAjMTU1MTI6IENvcnJlY3QgX19zaXplb2ZfXyBz?= =?utf-8?q?upport_for_parser?= Message-ID: <3WpSJ04KH2zPkf@mail.python.org> http://hg.python.org/cpython/rev/f7248550059c changeset: 78392:f7248550059c parent: 78389:463d3ad22cdb parent: 78391:91884d04de06 user: Jesus Cea date: Fri Aug 03 14:29:26 2012 +0200 summary: MERGE: Closes #15512: Correct __sizeof__ support for parser files: Include/node.h | 3 ++ Lib/test/test_parser.py | 41 +++++++++++++++++++++++++++++ Misc/NEWS | 3 ++ Modules/parsermodule.c | 13 ++++++++- Parser/node.c | 26 ++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletions(-) diff --git a/Include/node.h b/Include/node.h --- a/Include/node.h +++ b/Include/node.h @@ -20,6 +20,9 @@ PyAPI_FUNC(int) PyNode_AddChild(node *n, int type, char *str, int lineno, int col_offset); PyAPI_FUNC(void) PyNode_Free(node *n); +#ifndef Py_LIMITED_API +Py_ssize_t _PyNode_SizeOf(node *n); +#endif /* Node access functions */ #define NCH(n) ((n)->n_nchildren) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -2,6 +2,7 @@ import unittest import sys import operator +import struct from test import support # @@ -679,6 +680,46 @@ self.assertRaises(TypeError, operator.lt, st1, 1815) self.assertRaises(TypeError, operator.gt, b'waterloo', st2) + check_sizeof = support.check_sizeof + + @support.cpython_only + def test_sizeof(self): + def XXXROUNDUP(n): + if n <= 1: + return n + if n <= 128: + return (n + 3) & ~3 + return 1 << (n - 1).bit_length() + + basesize = support.calcobjsize('Pii') + nodesize = struct.calcsize('hP3iP0h') + def sizeofchildren(node): + if node is None: + return 0 + res = 0 + hasstr = len(node) > 1 and isinstance(node[-1], str) + if hasstr: + res += len(node[-1]) + 1 + children = node[1:-1] if hasstr else node[1:] + if children: + res += XXXROUNDUP(len(children)) * nodesize + res1 = res + if children: + for child in children: + res += sizeofchildren(child) + return res + + def check_st_sizeof(st): + self.check_sizeof(st, basesize + nodesize + + sizeofchildren(st.totuple())) + + check_st_sizeof(parser.expr('2 + 3')) + check_st_sizeof(parser.expr('2 + 3 + 4')) + check_st_sizeof(parser.suite('x = 2 + 3')) + check_st_sizeof(parser.suite('')) + check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-')) + check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']')) + # XXX tests for pickling and unpickling of ST objects should go here diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -367,6 +367,9 @@ - Issue #12288: Consider '0' and '0.0' as valid initialvalue for tkinter SimpleDialog. +- Issue #15512: Add a __sizeof__ implementation for parser. + Patch by Serhiy Storchaka. + - Issue #15489: Add a __sizeof__ implementation for BytesIO objects. Patch by Serhiy Storchaka. diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -167,6 +167,7 @@ static void parser_free(PyST_Object *st); +static PyObject* parser_sizeof(PyST_Object *, void *); static PyObject* parser_richcompare(PyObject *left, PyObject *right, int op); static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); @@ -187,7 +188,8 @@ PyDoc_STR("Creates a list-tree representation of this ST.")}, {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, PyDoc_STR("Creates a tuple-tree representation of this ST.")}, - + {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS, + PyDoc_STR("Returns size in memory, in bytes.")}, {NULL, NULL, 0, NULL} }; @@ -361,6 +363,15 @@ PyObject_Del(st); } +static PyObject * +parser_sizeof(PyST_Object *st, void *unused) +{ + Py_ssize_t res; + + res = sizeof(PyST_Object) + _PyNode_SizeOf(st->st_node); + return PyLong_FromSsize_t(res); +} + /* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw) * diff --git a/Parser/node.c b/Parser/node.c --- a/Parser/node.c +++ b/Parser/node.c @@ -114,6 +114,7 @@ /* Forward */ static void freechildren(node *); +static Py_ssize_t sizeofchildren(node *n); void @@ -125,6 +126,16 @@ } } +Py_ssize_t +_PyNode_SizeOf(node *n) +{ + Py_ssize_t res = 0; + + if (n != NULL) + res = sizeof(node) + sizeofchildren(n); + return res; +} + static void freechildren(node *n) { @@ -136,3 +147,18 @@ if (STR(n) != NULL) PyObject_FREE(STR(n)); } + +static Py_ssize_t +sizeofchildren(node *n) +{ + Py_ssize_t res = 0; + int i; + for (i = NCH(n); --i >= 0; ) + res += sizeofchildren(CHILD(n, i)); + if (n->n_child != NULL) + /* allocated size of n->n_child array */ + res += XXXROUNDUP(NCH(n)) * sizeof(node); + if (STR(n) != NULL) + res += strlen(STR(n)) + 1; + return res; +} -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 14:52:40 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 14:52:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICMxNTQ2?= =?utf-8?q?9=3A_Correct_=5F=5Fsizeof=5F=5F_support_for_deque?= Message-ID: <3WpSpJ3yflzPch@mail.python.org> http://hg.python.org/cpython/rev/a3d49f1de893 changeset: 78393:a3d49f1de893 branch: 2.7 parent: 78390:aceb975c4832 user: Jesus Cea date: Fri Aug 03 14:48:23 2012 +0200 summary: Closes #15469: Correct __sizeof__ support for deque files: Lib/test/test_deque.py | 16 ++++++++++++++++ Misc/NEWS | 3 +++ Modules/_collectionsmodule.c | 21 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -6,6 +6,7 @@ import copy import cPickle as pickle import random +import struct BIG = 100000 @@ -517,6 +518,21 @@ gc.collect() self.assertTrue(ref() is None, "Cycle was not collected") + check_sizeof = test_support.check_sizeof + + @test_support.cpython_only + def test_sizeof(self): + BLOCKLEN = 62 + basesize = test_support.calcobjsize('2P4PlP') + blocksize = struct.calcsize('2P%dP' % BLOCKLEN) + self.assertEqual(object.__sizeof__(deque()), basesize) + check = self.check_sizeof + check(deque(), basesize + blocksize) + check(deque('a'), basesize + blocksize) + check(deque('a' * (BLOCKLEN // 2)), basesize + blocksize) + check(deque('a' * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize) + check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize) + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,9 @@ - Issue #15489: Add a __sizeof__ implementation for BytesIO objects. Patch by Serhiy Storchaka. +- Issue #15469: Add a __sizeof__ implementation for deque objects. + Patch by Serhiy Storchaka. + - Issue #15487: Add a __sizeof__ implementation for buffered I/O objects. Patch by Serhiy Storchaka. diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -991,6 +991,23 @@ } static PyObject * +deque_sizeof(dequeobject *deque, void *unused) +{ + Py_ssize_t res; + Py_ssize_t blocks; + + res = sizeof(dequeobject); + blocks = (deque->leftindex + deque->len + BLOCKLEN - 1) / BLOCKLEN; + assert(deque->leftindex + deque->len - 1 == + (blocks - 1) * BLOCKLEN + deque->rightindex); + res += blocks * sizeof(block); + return PyLong_FromSsize_t(res); +} + +PyDoc_STRVAR(sizeof_doc, +"D.__sizeof__() -- size of D in memory, in bytes"); + +static PyObject * deque_get_maxlen(dequeobject *deque) { if (deque->maxlen == -1) @@ -1053,7 +1070,9 @@ {"reverse", (PyCFunction)deque_reverse, METH_NOARGS, reverse_doc}, {"rotate", (PyCFunction)deque_rotate, - METH_VARARGS, rotate_doc}, + METH_VARARGS, rotate_doc}, + {"__sizeof__", (PyCFunction)deque_sizeof, + METH_NOARGS, sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 14:52:42 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 14:52:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogQ2xvc2VzICMxNTQ2?= =?utf-8?q?9=3A_Correct_=5F=5Fsizeof=5F=5F_support_for_deque?= Message-ID: <3WpSpL0rfNzPj1@mail.python.org> http://hg.python.org/cpython/rev/b0725c1b3068 changeset: 78394:b0725c1b3068 branch: 3.2 parent: 78391:91884d04de06 user: Jesus Cea date: Fri Aug 03 14:49:42 2012 +0200 summary: Closes #15469: Correct __sizeof__ support for deque files: Lib/test/test_deque.py | 16 ++++++++++++++++ Misc/NEWS | 3 +++ Modules/_collectionsmodule.c | 21 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -7,6 +7,7 @@ import pickle from io import StringIO import random +import struct BIG = 100000 @@ -518,6 +519,21 @@ gc.collect() self.assertTrue(ref() is None, "Cycle was not collected") + check_sizeof = support.check_sizeof + + @support.cpython_only + def test_sizeof(self): + BLOCKLEN = 62 + basesize = support.calcobjsize('2P4PlP') + blocksize = struct.calcsize('2P%dP' % BLOCKLEN) + self.assertEqual(object.__sizeof__(deque()), basesize) + check = self.check_sizeof + check(deque(), basesize + blocksize) + check(deque('a'), basesize + blocksize) + check(deque('a' * (BLOCKLEN // 2)), basesize + blocksize) + check(deque('a' * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize) + check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize) + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -110,6 +110,9 @@ - Issue #15512: Add a __sizeof__ implementation for parser. Patch by Serhiy Storchaka. +- Issue #15469: Add a __sizeof__ implementation for deque objects. + Patch by Serhiy Storchaka. + - Issue #15489: Add a __sizeof__ implementation for BytesIO objects. Patch by Serhiy Storchaka. diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -933,6 +933,23 @@ } static PyObject * +deque_sizeof(dequeobject *deque, void *unused) +{ + Py_ssize_t res; + Py_ssize_t blocks; + + res = sizeof(dequeobject); + blocks = (deque->leftindex + deque->len + BLOCKLEN - 1) / BLOCKLEN; + assert(deque->leftindex + deque->len - 1 == + (blocks - 1) * BLOCKLEN + deque->rightindex); + res += blocks * sizeof(block); + return PyLong_FromSsize_t(res); +} + +PyDoc_STRVAR(sizeof_doc, +"D.__sizeof__() -- size of D in memory, in bytes"); + +static PyObject * deque_get_maxlen(dequeobject *deque) { if (deque->maxlen == -1) @@ -995,7 +1012,9 @@ {"reverse", (PyCFunction)deque_reverse, METH_NOARGS, reverse_doc}, {"rotate", (PyCFunction)deque_rotate, - METH_VARARGS, rotate_doc}, + METH_VARARGS, rotate_doc}, + {"__sizeof__", (PyCFunction)deque_sizeof, + METH_NOARGS, sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 14:52:43 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 14:52:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTUVSR0U6IENsb3NlcyAjMTU0Njk6IENvcnJlY3QgX19zaXplb2ZfXyBz?= =?utf-8?q?upport_for_deque?= Message-ID: <3WpSpM3yTSzPjl@mail.python.org> http://hg.python.org/cpython/rev/b80a780514dd changeset: 78395:b80a780514dd parent: 78392:f7248550059c parent: 78394:b0725c1b3068 user: Jesus Cea date: Fri Aug 03 14:52:12 2012 +0200 summary: MERGE: Closes #15469: Correct __sizeof__ support for deque files: Lib/test/test_deque.py | 16 ++++++++++++++++ Misc/NEWS | 3 +++ Modules/_collectionsmodule.c | 21 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -7,6 +7,7 @@ import pickle from io import StringIO import random +import struct BIG = 100000 @@ -531,6 +532,21 @@ gc.collect() self.assertTrue(ref() is None, "Cycle was not collected") + check_sizeof = support.check_sizeof + + @support.cpython_only + def test_sizeof(self): + BLOCKLEN = 62 + basesize = support.calcobjsize('2P4nlP') + blocksize = struct.calcsize('2P%dP' % BLOCKLEN) + self.assertEqual(object.__sizeof__(deque()), basesize) + check = self.check_sizeof + check(deque(), basesize + blocksize) + check(deque('a'), basesize + blocksize) + check(deque('a' * (BLOCKLEN // 2)), basesize + blocksize) + check(deque('a' * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize) + check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize) + class TestVariousIteratorArgs(unittest.TestCase): def test_constructor(self): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -370,6 +370,9 @@ - Issue #15512: Add a __sizeof__ implementation for parser. Patch by Serhiy Storchaka. +- Issue #15469: Add a __sizeof__ implementation for deque objects. + Patch by Serhiy Storchaka. + - Issue #15489: Add a __sizeof__ implementation for BytesIO objects. Patch by Serhiy Storchaka. diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -933,6 +933,23 @@ } static PyObject * +deque_sizeof(dequeobject *deque, void *unused) +{ + Py_ssize_t res; + Py_ssize_t blocks; + + res = sizeof(dequeobject); + blocks = (deque->leftindex + deque->len + BLOCKLEN - 1) / BLOCKLEN; + assert(deque->leftindex + deque->len - 1 == + (blocks - 1) * BLOCKLEN + deque->rightindex); + res += blocks * sizeof(block); + return PyLong_FromSsize_t(res); +} + +PyDoc_STRVAR(sizeof_doc, +"D.__sizeof__() -- size of D in memory, in bytes"); + +static PyObject * deque_get_maxlen(dequeobject *deque) { if (deque->maxlen == -1) @@ -995,7 +1012,9 @@ {"reverse", (PyCFunction)deque_reverse, METH_NOARGS, reverse_doc}, {"rotate", (PyCFunction)deque_rotate, - METH_VARARGS, rotate_doc}, + METH_VARARGS, rotate_doc}, + {"__sizeof__", (PyCFunction)deque_sizeof, + METH_NOARGS, sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 15:51:35 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 15:51:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1NTEyOiBSZW1v?= =?utf-8?q?ve_remnants_of_debugging_code?= Message-ID: <3WpV6H1ZnJzPk7@mail.python.org> http://hg.python.org/cpython/rev/0827fef8652d changeset: 78396:0827fef8652d branch: 2.7 parent: 78393:a3d49f1de893 user: Jesus Cea date: Fri Aug 03 15:48:56 2012 +0200 summary: #15512: Remove remnants of debugging code files: Lib/test/test_parser.py | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -610,8 +610,6 @@ children = node[1:-1] if hasstr else node[1:] if children: res += XXXROUNDUP(len(children)) * nodesize - res1 = res - if children: for child in children: res += sizeofchildren(child) return res -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 15:51:36 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 15:51:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1NTEyOiBSZW1v?= =?utf-8?q?ve_remnants_of_debugging_code?= Message-ID: <3WpV6J6SKDzPkY@mail.python.org> http://hg.python.org/cpython/rev/0bda3f00b60a changeset: 78397:0bda3f00b60a branch: 3.2 parent: 78394:b0725c1b3068 user: Jesus Cea date: Fri Aug 03 15:49:14 2012 +0200 summary: #15512: Remove remnants of debugging code files: Lib/test/test_parser.py | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -699,8 +699,6 @@ children = node[1:-1] if hasstr else node[1:] if children: res += XXXROUNDUP(len(children)) * nodesize - res1 = res - if children: for child in children: res += sizeofchildren(child) return res -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 15:51:38 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 15:51:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_MERGE=3A_=2315512=3A_Remove_remnants_of_debugging_code?= Message-ID: <3WpV6L4dFJzPkf@mail.python.org> http://hg.python.org/cpython/rev/593eba5e867c changeset: 78398:593eba5e867c parent: 78395:b80a780514dd parent: 78397:0bda3f00b60a user: Jesus Cea date: Fri Aug 03 15:49:40 2012 +0200 summary: MERGE: #15512: Remove remnants of debugging code files: Lib/test/test_parser.py | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -703,8 +703,6 @@ children = node[1:-1] if hasstr else node[1:] if children: res += XXXROUNDUP(len(children)) * nodesize - res1 = res - if children: for child in children: res += sizeofchildren(child) return res -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 3 15:51:40 2012 From: python-checkins at python.org (jesus.cea) Date: Fri, 3 Aug 2012 15:51:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1NTEyOiBEZWNs?= =?utf-8?q?arations_reorganization?= Message-ID: <3WpV6N0wllzPlL@mail.python.org> http://hg.python.org/cpython/rev/c5bf5a82a3f2 changeset: 78399:c5bf5a82a3f2 branch: 2.7 parent: 78396:0827fef8652d user: Jesus Cea date: Fri Aug 03 15:51:11 2012 +0200 summary: #15512: Declarations reorganization files: Modules/parsermodule.c | 46 +++++++++++++++-------------- 1 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -172,8 +172,30 @@ static PyObject* parser_sizeof(PyST_Object *, void *); static int parser_compare(PyST_Object *left, PyST_Object *right); static PyObject *parser_getattr(PyObject *self, char *name); -static PyMethodDef parser_methods[]; - +static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_issuite(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_st2list(PyST_Object *, PyObject *, PyObject *); +static PyObject* parser_st2tuple(PyST_Object *, PyObject *, PyObject *); + +#define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) + +static PyMethodDef +parser_methods[] = { + {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, + PyDoc_STR("Compile this ST object into a code object.")}, + {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, + PyDoc_STR("Determines if this ST object was created from an expression.")}, + {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, + PyDoc_STR("Determines if this ST object was created from a suite.")}, + {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, + PyDoc_STR("Creates a list-tree representation of this ST.")}, + {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, + PyDoc_STR("Creates a tuple-tree representation of this ST.")}, + {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS, + PyDoc_STR("Returns size in memory, in bytes.")}, + {NULL, NULL, 0, NULL} +}; static PyTypeObject PyST_Type = { @@ -503,26 +525,6 @@ } -#define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) - -static PyMethodDef -parser_methods[] = { - {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, - PyDoc_STR("Compile this ST object into a code object.")}, - {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if this ST object was created from an expression.")}, - {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, - PyDoc_STR("Determines if this ST object was created from a suite.")}, - {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a list-tree representation of this ST.")}, - {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, - PyDoc_STR("Creates a tuple-tree representation of this ST.")}, - {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS, - PyDoc_STR("Returns size in memory, in bytes.")}, - {NULL, NULL, 0, NULL} -}; - - static PyObject* parser_getattr(PyObject *self, char *name) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 00:59:52 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 4 Aug 2012 00:59:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Make_TextIOWra?= =?utf-8?q?pper=27s_documentation_clearer_by_copying_the_newline_argument?= =?utf-8?q?=27s?= Message-ID: <3WpkGw4Y1NzPK4@mail.python.org> http://hg.python.org/cpython/rev/f19bea7bbee7 changeset: 78400:f19bea7bbee7 branch: 3.2 parent: 78397:0bda3f00b60a user: Antoine Pitrou date: Sat Aug 04 00:55:38 2012 +0200 summary: Make TextIOWrapper's documentation clearer by copying the newline argument's description from open(). files: Doc/library/io.rst | 24 ++++++++++++++++-------- Modules/_io/textio.c | 25 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -757,14 +757,22 @@ sequences) can be used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. - *newline* can be ``None``, ``''``, ``'\n'``, ``'\r'``, or ``'\r\n'``. It - controls the handling of line endings. If it is ``None``, universal newlines - is enabled. With this enabled, on input, the lines endings ``'\n'``, - ``'\r'``, or ``'\r\n'`` are translated to ``'\n'`` before being returned to - the caller. Conversely, on output, ``'\n'`` is translated to the system - default line separator, :data:`os.linesep`. If *newline* is any other of its - legal values, that newline becomes the newline when the file is read and it - is returned untranslated. On output, ``'\n'`` is converted to the *newline*. + *newline* controls how line endings are handled. It can be ``None``, + ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: + + * On input, if *newline* is ``None``, universal newlines mode is enabled. + Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these + are translated into ``'\n'`` before being returned to the caller. If it is + ``''``, universal newline mode is enabled, but line endings are returned to + the caller untranslated. If it has any of the other legal values, input + lines are only terminated by the given string, and the line ending is + returned to the caller untranslated. + + * On output, if *newline* is ``None``, any ``'\n'`` characters written are + translated to the system default line separator, :data:`os.linesep`. If + *newline* is ``''``, no translation takes place. If *newline* is any of + the other legal values, any ``'\n'`` characters written are translated to + the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -622,15 +622,22 @@ "errors determines the strictness of encoding and decoding (see the\n" "codecs.register) and defaults to \"strict\".\n" "\n" - "newline can be None, '', '\\n', '\\r', or '\\r\\n'. It controls the\n" - "handling of line endings. If it is None, universal newlines is\n" - "enabled. With this enabled, on input, the lines endings '\\n', '\\r',\n" - "or '\\r\\n' are translated to '\\n' before being returned to the\n" - "caller. Conversely, on output, '\\n' is translated to the system\n" - "default line separator, os.linesep. If newline is any other of its\n" - "legal values, that newline becomes the newline when the file is read\n" - "and it is returned untranslated. On output, '\\n' is converted to the\n" - "newline.\n" + "newline controls how line endings are handled. It can be None, '',\n" + "'\\n', '\\r', and '\\r\\n'. It works as follows:\n" + "\n" + "* On input, if newline is None, universal newlines mode is\n" + " enabled. Lines in the input can end in '\\n', '\\r', or '\\r\\n', and\n" + " these are translated into '\\n' before being returned to the\n" + " caller. If it is '', universal newline mode is enabled, but line\n" + " endings are returned to the caller untranslated. If it has any of\n" + " the other legal values, input lines are only terminated by the given\n" + " string, and the line ending is returned to the caller untranslated.\n" + "\n" + "* On output, if newline is None, any '\\n' characters written are\n" + " translated to the system default line separator, os.linesep. If\n" + " newline is '', no translation takes place. If newline is any of the\n" + " other legal values, any '\\n' characters written are translated to\n" + " the given string.\n" "\n" "If line_buffering is True, a call to flush is implied when a call to\n" "write contains a newline character." -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 00:59:54 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 4 Aug 2012 00:59:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Make_TextIOWrapper=27s_documentation_clearer_by_copying_?= =?utf-8?q?the_newline_argument=27s?= Message-ID: <3WpkGy3N7VzPgX@mail.python.org> http://hg.python.org/cpython/rev/f17a1410ebe5 changeset: 78401:f17a1410ebe5 parent: 78398:593eba5e867c parent: 78400:f19bea7bbee7 user: Antoine Pitrou date: Sat Aug 04 00:56:19 2012 +0200 summary: Make TextIOWrapper's documentation clearer by copying the newline argument's description from open(). files: Doc/library/io.rst | 24 ++++++++++++++++-------- Modules/_io/textio.c | 25 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -767,14 +767,22 @@ sequences) can be used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. - *newline* can be ``None``, ``''``, ``'\n'``, ``'\r'``, or ``'\r\n'``. It - controls the handling of line endings. If it is ``None``, universal newlines - is enabled. With this enabled, on input, the lines endings ``'\n'``, - ``'\r'``, or ``'\r\n'`` are translated to ``'\n'`` before being returned to - the caller. Conversely, on output, ``'\n'`` is translated to the system - default line separator, :data:`os.linesep`. If *newline* is any other of its - legal values, that newline becomes the newline when the file is read and it - is returned untranslated. On output, ``'\n'`` is converted to the *newline*. + *newline* controls how line endings are handled. It can be ``None``, + ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: + + * On input, if *newline* is ``None``, universal newlines mode is enabled. + Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these + are translated into ``'\n'`` before being returned to the caller. If it is + ``''``, universal newline mode is enabled, but line endings are returned to + the caller untranslated. If it has any of the other legal values, input + lines are only terminated by the given string, and the line ending is + returned to the caller untranslated. + + * On output, if *newline* is ``None``, any ``'\n'`` characters written are + translated to the system default line separator, :data:`os.linesep`. If + *newline* is ``''``, no translation takes place. If *newline* is any of + the other legal values, any ``'\n'`` characters written are translated to + the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -635,15 +635,22 @@ "errors determines the strictness of encoding and decoding (see the\n" "codecs.register) and defaults to \"strict\".\n" "\n" - "newline can be None, '', '\\n', '\\r', or '\\r\\n'. It controls the\n" - "handling of line endings. If it is None, universal newlines is\n" - "enabled. With this enabled, on input, the lines endings '\\n', '\\r',\n" - "or '\\r\\n' are translated to '\\n' before being returned to the\n" - "caller. Conversely, on output, '\\n' is translated to the system\n" - "default line separator, os.linesep. If newline is any other of its\n" - "legal values, that newline becomes the newline when the file is read\n" - "and it is returned untranslated. On output, '\\n' is converted to the\n" - "newline.\n" + "newline controls how line endings are handled. It can be None, '',\n" + "'\\n', '\\r', and '\\r\\n'. It works as follows:\n" + "\n" + "* On input, if newline is None, universal newlines mode is\n" + " enabled. Lines in the input can end in '\\n', '\\r', or '\\r\\n', and\n" + " these are translated into '\\n' before being returned to the\n" + " caller. If it is '', universal newline mode is enabled, but line\n" + " endings are returned to the caller untranslated. If it has any of\n" + " the other legal values, input lines are only terminated by the given\n" + " string, and the line ending is returned to the caller untranslated.\n" + "\n" + "* On output, if newline is None, any '\\n' characters written are\n" + " translated to the system default line separator, os.linesep. If\n" + " newline is '', no translation takes place. If newline is any of the\n" + " other legal values, any '\\n' characters written are translated to\n" + " the given string.\n" "\n" "If line_buffering is True, a call to flush is implied when a call to\n" "write contains a newline character." -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 01:03:12 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 4 Aug 2012 01:03:12 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Make_TextIOWra?= =?utf-8?q?pper=27s_documentation_clearer_by_copying_the_newline_argument?= =?utf-8?q?=27s?= Message-ID: <3WpkLm0SS7zPmY@mail.python.org> http://hg.python.org/cpython/rev/c52e709577b3 changeset: 78402:c52e709577b3 branch: 2.7 parent: 78399:c5bf5a82a3f2 user: Antoine Pitrou date: Sat Aug 04 00:55:38 2012 +0200 summary: Make TextIOWrapper's documentation clearer by copying the newline argument's description from open(). files: Doc/library/io.rst | 24 ++++++++++++++++-------- Modules/_io/textio.c | 25 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -754,14 +754,22 @@ sequences) can be used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. - *newline* can be ``None``, ``''``, ``'\n'``, ``'\r'``, or ``'\r\n'``. It - controls the handling of line endings. If it is ``None``, universal newlines - is enabled. With this enabled, on input, the lines endings ``'\n'``, - ``'\r'``, or ``'\r\n'`` are translated to ``'\n'`` before being returned to - the caller. Conversely, on output, ``'\n'`` is translated to the system - default line separator, :data:`os.linesep`. If *newline* is any other of its - legal values, that newline becomes the newline when the file is read and it - is returned untranslated. On output, ``'\n'`` is converted to the *newline*. + *newline* controls how line endings are handled. It can be ``None``, + ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: + + * On input, if *newline* is ``None``, universal newlines mode is enabled. + Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these + are translated into ``'\n'`` before being returned to the caller. If it is + ``''``, universal newline mode is enabled, but line endings are returned to + the caller untranslated. If it has any of the other legal values, input + lines are only terminated by the given string, and the line ending is + returned to the caller untranslated. + + * On output, if *newline* is ``None``, any ``'\n'`` characters written are + translated to the system default line separator, :data:`os.linesep`. If + *newline* is ``''``, no translation takes place. If *newline* is any of + the other legal values, any ``'\n'`` characters written are translated to + the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -622,15 +622,22 @@ "errors determines the strictness of encoding and decoding (see the\n" "codecs.register) and defaults to \"strict\".\n" "\n" - "newline can be None, '', '\\n', '\\r', or '\\r\\n'. It controls the\n" - "handling of line endings. If it is None, universal newlines is\n" - "enabled. With this enabled, on input, the lines endings '\\n', '\\r',\n" - "or '\\r\\n' are translated to '\\n' before being returned to the\n" - "caller. Conversely, on output, '\\n' is translated to the system\n" - "default line separator, os.linesep. If newline is any other of its\n" - "legal values, that newline becomes the newline when the file is read\n" - "and it is returned untranslated. On output, '\\n' is converted to the\n" - "newline.\n" + "newline controls how line endings are handled. It can be None, '',\n" + "'\\n', '\\r', and '\\r\\n'. It works as follows:\n" + "\n" + "* On input, if newline is None, universal newlines mode is\n" + " enabled. Lines in the input can end in '\\n', '\\r', or '\\r\\n', and\n" + " these are translated into '\\n' before being returned to the\n" + " caller. If it is '', universal newline mode is enabled, but line\n" + " endings are returned to the caller untranslated. If it has any of\n" + " the other legal values, input lines are only terminated by the given\n" + " string, and the line ending is returned to the caller untranslated.\n" + "\n" + "* On output, if newline is None, any '\\n' characters written are\n" + " translated to the system default line separator, os.linesep. If\n" + " newline is '', no translation takes place. If newline is any of the\n" + " other legal values, any '\\n' characters written are translated to\n" + " the given string.\n" "\n" "If line_buffering is True, a call to flush is implied when a call to\n" "write contains a newline character." -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 01:27:28 2012 From: python-checkins at python.org (victor.stinner) Date: Sat, 4 Aug 2012 01:27:28 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogb3BlbigpIC8gVGV4?= =?utf-8?q?tIOWrapper_doc=3A_make_it_explicit_than_newline=3D=27=5Cn=27_do?= =?utf-8?q?esn=27t?= Message-ID: <3Wpktm36GKzPnB@mail.python.org> http://hg.python.org/cpython/rev/243ad1a6f638 changeset: 78403:243ad1a6f638 branch: 3.2 parent: 78400:f19bea7bbee7 user: Victor Stinner date: Sat Aug 04 01:18:56 2012 +0200 summary: open() / TextIOWrapper doc: make it explicit than newline='\n' doesn't translate newlines on output. files: Doc/library/functions.rst | 6 +++--- Doc/library/io.rst | 6 +++--- Modules/_io/_iomodule.c | 6 +++--- Modules/_io/textio.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -888,9 +888,9 @@ * On output, if *newline* is ``None``, any ``'\n'`` characters written are translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''``, no translation takes place. If *newline* is any of - the other legal values, any ``'\n'`` characters written are translated to - the given string. + *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* + is any of the other legal values, any ``'\n'`` characters written are + translated to the given string. If *closefd* is ``False`` and a file descriptor rather than a filename was given, the underlying file descriptor will be kept open when the file is diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -770,9 +770,9 @@ * On output, if *newline* is ``None``, any ``'\n'`` characters written are translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''``, no translation takes place. If *newline* is any of - the other legal values, any ``'\n'`` characters written are translated to - the given string. + *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* + is any of the other legal values, any ``'\n'`` characters written are + translated to the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -264,9 +264,9 @@ "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" -" newline is '', no translation takes place. If newline is any of the\n" -" other legal values, any '\\n' characters written are translated to\n" -" the given string.\n" +" newline is '' or '\n', no translation takes place. If newline is any\n" +" of the other legal values, any '\\n' characters written are translated\n" +" to the given string.\n" "\n" "If closefd is False, the underlying file descriptor will be kept open\n" "when the file is closed. This does not work when a file name is given\n" diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -635,9 +635,9 @@ "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" - " newline is '', no translation takes place. If newline is any of the\n" - " other legal values, any '\\n' characters written are translated to\n" - " the given string.\n" + " newline is '' or '\n', no translation takes place. If newline is any\n" + " of the other legal values, any '\\n' characters written are translated\n" + " to the given string.\n" "\n" "If line_buffering is True, a call to flush is implied when a call to\n" "write contains a newline character." -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 01:27:30 2012 From: python-checkins at python.org (victor.stinner) Date: Sat, 4 Aug 2012 01:27:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_=28Merge_3=2E2=29_open=28=29_/_TextIOWrapper_doc=3A_make?= =?utf-8?q?_it_explicit_than_newline=3D=27=5Cn=27?= Message-ID: <3Wpktp5VkCzPnZ@mail.python.org> http://hg.python.org/cpython/rev/083776adcacc changeset: 78404:083776adcacc parent: 78401:f17a1410ebe5 parent: 78403:243ad1a6f638 user: Victor Stinner date: Sat Aug 04 01:22:07 2012 +0200 summary: (Merge 3.2) open() / TextIOWrapper doc: make it explicit than newline='\n' doesn't translate newlines on output. files: Doc/library/functions.rst | 6 +++--- Doc/library/io.rst | 6 +++--- Modules/_io/_iomodule.c | 6 +++--- Modules/_io/textio.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -887,9 +887,9 @@ * On output, if *newline* is ``None``, any ``'\n'`` characters written are translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''``, no translation takes place. If *newline* is any of - the other legal values, any ``'\n'`` characters written are translated to - the given string. + *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* + is any of the other legal values, any ``'\n'`` characters written are + translated to the given string. If *closefd* is ``False`` and a file descriptor rather than a filename was given, the underlying file descriptor will be kept open when the file is diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -780,9 +780,9 @@ * On output, if *newline* is ``None``, any ``'\n'`` characters written are translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''``, no translation takes place. If *newline* is any of - the other legal values, any ``'\n'`` characters written are translated to - the given string. + *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* + is any of the other legal values, any ``'\n'`` characters written are + translated to the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -185,9 +185,9 @@ "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" -" newline is '', no translation takes place. If newline is any of the\n" -" other legal values, any '\\n' characters written are translated to\n" -" the given string.\n" +" newline is '' or '\n', no translation takes place. If newline is any\n" +" of the other legal values, any '\\n' characters written are translated\n" +" to the given string.\n" "\n" "If closefd is False, the underlying file descriptor will be kept open\n" "when the file is closed. This does not work when a file name is given\n" diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -648,9 +648,9 @@ "\n" "* On output, if newline is None, any '\\n' characters written are\n" " translated to the system default line separator, os.linesep. If\n" - " newline is '', no translation takes place. If newline is any of the\n" - " other legal values, any '\\n' characters written are translated to\n" - " the given string.\n" + " newline is '' or '\n', no translation takes place. If newline is any\n" + " of the other legal values, any '\\n' characters written are translated\n" + " to the given string.\n" "\n" "If line_buffering is True, a call to flush is implied when a call to\n" "write contains a newline character." -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 01:31:58 2012 From: python-checkins at python.org (victor.stinner) Date: Sat, 4 Aug 2012 01:31:58 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2313119=3A_use_=22?= =?utf-8?q?=5Cr=5Cn=22_newline_for_sys=2Estdout/err_on_Windows?= Message-ID: <3Wpkzy1h6PzPm8@mail.python.org> http://hg.python.org/cpython/rev/c55dbb84f3b4 changeset: 78405:c55dbb84f3b4 user: Victor Stinner date: Sat Aug 04 01:28:00 2012 +0200 summary: Close #13119: use "\r\n" newline for sys.stdout/err on Windows sys.stdout and sys.stderr are now using "\r\n" newline on Windows, as Python 2. files: Lib/test/test_cmd_line.py | 17 +++++++++++++++++ Misc/NEWS | 3 +++ Python/pythonrun.c | 13 ++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -259,6 +259,23 @@ "print(repr(input()))", b"'abc'") + def test_output_newline(self): + # Issue 13119 Newline for print() should be \r\n on Windows. + code = """if 1: + import sys + print(1) + print(2) + print(3, file=sys.stderr) + print(4, file=sys.stderr)""" + rc, out, err = assert_python_ok('-c', code) + + if sys.platform == 'win32': + self.assertEqual(b'1\r\n2\r\n', out) + self.assertEqual(b'3\r\n4', err) + else: + self.assertEqual(b'1\n2\n', out) + self.assertEqual(b'3\n4', err) + def test_unmached_quote(self): # Issue #10206: python program starting with unmatched quote # spewed spaces to stdout diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on + Windows, as Python 2. + - Issue #15534: Fix the fast-search function for non-ASCII Unicode strings. - Issue #15508: Fix the docstring for __import__ to have the proper default diff --git a/Python/pythonrun.c b/Python/pythonrun.c --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -971,12 +971,15 @@ Py_CLEAR(raw); Py_CLEAR(text); +#ifdef MS_WINDOWS + /* sys.stdin: enable universal newline mode, translate "\r\n" and "\r" + newlines to "\n". + sys.stdout and sys.stderr: translate "\n" to "\r\n". */ + newline = NULL; +#else + /* sys.stdin: split lines at "\n". + sys.stdout and sys.stderr: don't translate newlines (use "\n"). */ newline = "\n"; -#ifdef MS_WINDOWS - if (!write_mode) { - /* translate \r\n to \n for sys.stdin on Windows */ - newline = NULL; - } #endif stream = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "OsssO", -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 01:42:20 2012 From: python-checkins at python.org (victor.stinner) Date: Sat, 4 Aug 2012 01:42:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogQ2xvc2UgIzEzMTE5?= =?utf-8?q?=3A_use_=22=5Cr=5Cn=22_newline_for_sys=2Estdout/err_on_Windows?= Message-ID: <3WplCw3q8DzPp0@mail.python.org> http://hg.python.org/cpython/rev/09408b990ca5 changeset: 78406:09408b990ca5 branch: 3.2 parent: 78403:243ad1a6f638 user: Victor Stinner date: Sat Aug 04 01:37:32 2012 +0200 summary: Close #13119: use "\r\n" newline for sys.stdout/err on Windows sys.stdout and sys.stderr are now using "\r\n" newline on Windows, as Python 2. files: Lib/test/test_cmd_line.py | 17 +++++++++++++++++ Misc/NEWS | 3 +++ Python/pythonrun.c | 13 ++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -265,6 +265,23 @@ "print(repr(input()))", b"'abc'") + def test_output_newline(self): + # Issue 13119 Newline for print() should be \r\n on Windows. + code = """if 1: + import sys + print(1) + print(2) + print(3, file=sys.stderr) + print(4, file=sys.stderr)""" + rc, out, err = assert_python_ok('-c', code) + + if sys.platform == 'win32': + self.assertEqual(b'1\r\n2\r\n', out) + self.assertEqual(b'3\r\n4', err) + else: + self.assertEqual(b'1\n2\n', out) + self.assertEqual(b'3\n4', err) + def test_unmached_quote(self): # Issue #10206: python program starting with unmatched quote # spewed spaces to stdout diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on + Windows, as Python 2. + - Issue #14579: Fix CVE-2012-2135: vulnerability in the utf-16 decoder after error handling. Patch by Serhiy Storchaka. diff --git a/Python/pythonrun.c b/Python/pythonrun.c --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -870,12 +870,15 @@ Py_CLEAR(raw); Py_CLEAR(text); +#ifdef MS_WINDOWS + /* sys.stdin: enable universal newline mode, translate "\r\n" and "\r" + newlines to "\n". + sys.stdout and sys.stderr: translate "\n" to "\r\n". */ + newline = NULL; +#else + /* sys.stdin: split lines at "\n". + sys.stdout and sys.stderr: don't translate newlines (use "\n"). */ newline = "\n"; -#ifdef MS_WINDOWS - if (!write_mode) { - /* translate \r\n to \n for sys.stdin on Windows */ - newline = NULL; - } #endif stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO", -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 01:42:22 2012 From: python-checkins at python.org (victor.stinner) Date: Sat, 4 Aug 2012 01:42:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Null_merge_=28fix_already_applied_to_the_default_branch?= =?utf-8?q?=29?= Message-ID: <3WplCy2RxyzPp9@mail.python.org> http://hg.python.org/cpython/rev/92c6bbf7bb85 changeset: 78407:92c6bbf7bb85 parent: 78405:c55dbb84f3b4 parent: 78406:09408b990ca5 user: Victor Stinner date: Sat Aug 04 01:38:16 2012 +0200 summary: Null merge (fix already applied to the default branch) files: -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sat Aug 4 06:03:41 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 04 Aug 2012 06:03:41 +0200 Subject: [Python-checkins] Daily reference leaks (92c6bbf7bb85): sum=0 Message-ID: results for 92c6bbf7bb85 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogjWCwfT', '-x'] From python-checkins at python.org Sat Aug 4 14:38:26 2012 From: python-checkins at python.org (giampaolo.rodola) Date: Sat, 4 Aug 2012 14:38:26 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_asynchat_speedup_improveme?= =?utf-8?q?nt=3A_avoid_to_use_a_function_mimicking_old_buffer=28=29?= Message-ID: <3Wq4RQ3C0JzPfm@mail.python.org> http://hg.python.org/cpython/rev/ab959a5b04a0 changeset: 78408:ab959a5b04a0 user: Giampaolo Rodola' date: Sat Aug 04 14:38:16 2012 +0200 summary: asynchat speedup improvement: avoid to use a function mimicking old buffer() builtin behavior; instead use plain slicing files: Lib/asynchat.py | 14 +------------- 1 files changed, 1 insertions(+), 13 deletions(-) diff --git a/Lib/asynchat.py b/Lib/asynchat.py --- a/Lib/asynchat.py +++ b/Lib/asynchat.py @@ -49,18 +49,6 @@ import asyncore from collections import deque -def buffer(obj, start=None, stop=None): - # if memoryview objects gain slicing semantics, - # this function will change for the better - # memoryview used for the TypeError - memoryview(obj) - if start == None: - start = 0 - if stop == None: - stop = len(obj) - x = obj[start:stop] - ## print("buffer type is: %s"%(type(x),)) - return x class async_chat (asyncore.dispatcher): """This is an abstract class. You must derive from this class, and add @@ -240,7 +228,7 @@ # handle classic producer behavior obs = self.ac_out_buffer_size try: - data = buffer(first, 0, obs) + data = first[:obs] except TypeError: data = first.more() if data: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 15:39:11 2012 From: python-checkins at python.org (nadeem.vawda) Date: Sat, 4 Aug 2012 15:39:11 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=2315546=3A_Fix_BZ2File=2E?= =?utf-8?q?read1=28=29=27s_handling_of_pathological_input_data=2E?= Message-ID: <3Wq5nW4P8czPX8@mail.python.org> http://hg.python.org/cpython/rev/cdf27a213bd2 changeset: 78409:cdf27a213bd2 user: Nadeem Vawda date: Sat Aug 04 15:29:28 2012 +0200 summary: #15546: Fix BZ2File.read1()'s handling of pathological input data. files: Lib/bz2.py | 47 +++++++++++++++++++++++------------------ 1 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Lib/bz2.py b/Lib/bz2.py --- a/Lib/bz2.py +++ b/Lib/bz2.py @@ -174,29 +174,31 @@ # Fill the readahead buffer if it is empty. Returns False on EOF. def _fill_buffer(self): - if self._buffer: - return True + # Depending on the input data, our call to the decompressor may not + # return any data. In this case, try again after reading another block. + while True: + if self._buffer: + return True - if self._decompressor.unused_data: - rawblock = self._decompressor.unused_data - else: - rawblock = self._fp.read(_BUFFER_SIZE) + if self._decompressor.unused_data: + rawblock = self._decompressor.unused_data + else: + rawblock = self._fp.read(_BUFFER_SIZE) - if not rawblock: + if not rawblock: + if self._decompressor.eof: + self._mode = _MODE_READ_EOF + self._size = self._pos + return False + else: + raise EOFError("Compressed file ended before the " + "end-of-stream marker was reached") + + # Continue to next stream. if self._decompressor.eof: - self._mode = _MODE_READ_EOF - self._size = self._pos - return False - else: - raise EOFError("Compressed file ended before the " - "end-of-stream marker was reached") + self._decompressor = BZ2Decompressor() - # Continue to next stream. - if self._decompressor.eof: - self._decompressor = BZ2Decompressor() - - self._buffer = self._decompressor.decompress(rawblock) - return True + self._buffer = self._decompressor.decompress(rawblock) # Read data until EOF. # If return_data is false, consume the data without returning it. @@ -256,11 +258,14 @@ return self._read_block(size) def read1(self, size=-1): - """Read up to size uncompressed bytes with at most one read - from the underlying stream. + """Read up to size uncompressed bytes, while trying to avoid + making multiple reads from the underlying stream. Returns b'' if the file is at EOF. """ + # Usually, read1() calls _fp.read() at most once. However, sometimes + # this does not give enough data for the decompressor to make progress. + # In this case we make multiple reads, to avoid returning b"". with self._lock: self._check_can_read() if (size == 0 or self._mode == _MODE_READ_EOF or -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 16:19:50 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 4 Aug 2012 16:19:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2312655=3A_Instead_?= =?utf-8?q?of_requiring_a_custom_type=2C_os=2Esched=5Fgetaffinity_and?= Message-ID: <3Wq6hQ6v2NzPcc@mail.python.org> http://hg.python.org/cpython/rev/d6745ddbccbd changeset: 78410:d6745ddbccbd parent: 78407:92c6bbf7bb85 user: Antoine Pitrou date: Sat Aug 04 16:16:35 2012 +0200 summary: Issue #12655: Instead of requiring a custom type, os.sched_getaffinity and os.sched_setaffinity now use regular sets of integers to represent the CPUs a process is restricted to. files: Doc/library/os.rst | 48 +-- Lib/test/test_posix.py | 97 +---- Misc/NEWS | 4 + Modules/posixmodule.c | 463 ++++++++-------------------- 4 files changed, 170 insertions(+), 442 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3141,47 +3141,17 @@ Voluntarily relinquish the CPU. -.. class:: cpu_set(ncpus) - - :class:`cpu_set` represents a set of CPUs on which a process is eligible to - run. *ncpus* is the number of CPUs the set should describe. Methods on - :class:`cpu_set` allow CPUs to be add or removed. - - :class:`cpu_set` supports the AND, OR, and XOR bitwise operations. For - example, given two cpu_sets, ``one`` and ``two``, ``one | two`` returns a - :class:`cpu_set` containing the cpus enabled both in ``one`` and ``two``. - - .. method:: set(i) - - Enable CPU *i*. - - .. method:: clear(i) - - Remove CPU *i*. - - .. method:: isset(i) - - Return ``True`` if CPU *i* is enabled in the set. - - .. method:: count() - - Return the number of enabled CPUs in the set. - - .. method:: zero() - - Clear the set completely. - - .. function:: sched_setaffinity(pid, mask) - Restrict the process with PID *pid* to a set of CPUs. *mask* is a - :class:`cpu_set` instance. - - -.. function:: sched_getaffinity(pid, size) - - Return the :class:`cpu_set` the process with PID *pid* is restricted to. The - result will contain *size* CPUs. + Restrict the process with PID *pid* (or the current process if zero) to a + set of CPUs. *mask* is an iterable of integers representing the set of + CPUs to which the process should be restricted. + + +.. function:: sched_getaffinity(pid) + + Return the set of CPUs the process with PID *pid* (or the current process + if zero) is restricted to. .. _os-path: 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 @@ -855,7 +855,7 @@ requires_sched_h = unittest.skipUnless(hasattr(posix, 'sched_yield'), "don't have scheduling support") - requires_sched_affinity = unittest.skipUnless(hasattr(posix, 'cpu_set'), + requires_sched_affinity = unittest.skipUnless(hasattr(posix, 'sched_setaffinity'), "don't have sched affinity support") @requires_sched_h @@ -936,83 +936,28 @@ self.assertLess(interval, 1.) @requires_sched_affinity - def test_sched_affinity(self): - mask = posix.sched_getaffinity(0, 1024) - self.assertGreaterEqual(mask.count(), 1) - self.assertIsInstance(mask, posix.cpu_set) - self.assertRaises(OSError, posix.sched_getaffinity, -1, 1024) - empty = posix.cpu_set(10) - posix.sched_setaffinity(0, mask) - self.assertRaises(OSError, posix.sched_setaffinity, 0, empty) - self.assertRaises(OSError, posix.sched_setaffinity, -1, mask) + def test_sched_getaffinity(self): + mask = posix.sched_getaffinity(0) + self.assertIsInstance(mask, set) + self.assertGreaterEqual(len(mask), 1) + self.assertRaises(OSError, posix.sched_getaffinity, -1) + for cpu in mask: + self.assertIsInstance(cpu, int) + self.assertGreaterEqual(cpu, 0) + self.assertLess(cpu, 1 << 32) @requires_sched_affinity - def test_cpu_set_basic(self): - s = posix.cpu_set(10) - self.assertEqual(len(s), 10) - self.assertEqual(s.count(), 0) - s.set(0) - s.set(9) - self.assertTrue(s.isset(0)) - self.assertTrue(s.isset(9)) - self.assertFalse(s.isset(5)) - self.assertEqual(s.count(), 2) - s.clear(0) - self.assertFalse(s.isset(0)) - self.assertEqual(s.count(), 1) - s.zero() - self.assertFalse(s.isset(0)) - self.assertFalse(s.isset(9)) - self.assertEqual(s.count(), 0) - self.assertRaises(ValueError, s.set, -1) - self.assertRaises(ValueError, s.set, 10) - self.assertRaises(ValueError, s.clear, -1) - self.assertRaises(ValueError, s.clear, 10) - self.assertRaises(ValueError, s.isset, -1) - self.assertRaises(ValueError, s.isset, 10) - - @requires_sched_affinity - def test_cpu_set_cmp(self): - self.assertNotEqual(posix.cpu_set(11), posix.cpu_set(12)) - l = posix.cpu_set(10) - r = posix.cpu_set(10) - self.assertEqual(l, r) - l.set(1) - self.assertNotEqual(l, r) - r.set(1) - self.assertEqual(l, r) - - @requires_sched_affinity - def test_cpu_set_bitwise(self): - l = posix.cpu_set(5) - l.set(0) - l.set(1) - r = posix.cpu_set(5) - r.set(1) - r.set(2) - b = l & r - self.assertEqual(b.count(), 1) - self.assertTrue(b.isset(1)) - b = l | r - self.assertEqual(b.count(), 3) - self.assertTrue(b.isset(0)) - self.assertTrue(b.isset(1)) - self.assertTrue(b.isset(2)) - b = l ^ r - self.assertEqual(b.count(), 2) - self.assertTrue(b.isset(0)) - self.assertFalse(b.isset(1)) - self.assertTrue(b.isset(2)) - b = l - b |= r - self.assertIs(b, l) - self.assertEqual(l.count(), 3) - - @requires_sched_affinity - @support.cpython_only - def test_cpu_set_sizeof(self): - self.assertGreater(sys.getsizeof(posix.cpu_set(1000)), - sys.getsizeof(posix.cpu_set(1))) + def test_sched_setaffinity(self): + mask = posix.sched_getaffinity(0) + if len(mask) > 1: + # Empty masks are forbidden + mask.pop() + posix.sched_setaffinity(0, mask) + self.assertEqual(posix.sched_getaffinity(0), mask) + self.assertRaises(OSError, posix.sched_setaffinity, 0, []) + self.assertRaises(ValueError, posix.sched_setaffinity, 0, [-10]) + self.assertRaises(OverflowError, posix.sched_setaffinity, 0, [1<<128]) + self.assertRaises(OSError, posix.sched_setaffinity, -1, mask) def test_rtld_constants(self): # check presence of major RTLD_* constants diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,10 @@ Library ------- +- Issue #12655: Instead of requiring a custom type, os.sched_getaffinity and + os.sched_setaffinity now use regular sets of integers to represent the CPUs + a process is restricted to. + - Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() emulation code. Patch by Philipp Hagemeister. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5720,305 +5720,8 @@ #ifdef HAVE_SCHED_SETAFFINITY -typedef struct { - PyObject_HEAD; - Py_ssize_t size; - int ncpus; - cpu_set_t *set; -} Py_cpu_set; - -static PyTypeObject cpu_set_type; - -static void -cpu_set_dealloc(Py_cpu_set *set) -{ - assert(set->set); - CPU_FREE(set->set); - Py_TYPE(set)->tp_free(set); -} - -static Py_cpu_set * -make_new_cpu_set(PyTypeObject *type, Py_ssize_t size) -{ - Py_cpu_set *set; - - if (size < 0) { - PyErr_SetString(PyExc_ValueError, "negative size"); - return NULL; - } - set = (Py_cpu_set *)type->tp_alloc(type, 0); - if (!set) - return NULL; - set->ncpus = size; - set->size = CPU_ALLOC_SIZE(size); - set->set = CPU_ALLOC(size); - if (!set->set) { - type->tp_free(set); - PyErr_NoMemory(); - return NULL; - } - CPU_ZERO_S(set->size, set->set); - return set; -} - -static PyObject * -cpu_set_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) -{ - int size; - - if (!_PyArg_NoKeywords("cpu_set()", kwargs) || - !PyArg_ParseTuple(args, "i:cpu_set", &size)) - return NULL; - return (PyObject *)make_new_cpu_set(type, size); -} - -PyDoc_STRVAR(cpu_set_sizeof_doc, -"cpu_set.__sizeof__() -> int\n\n\ -Returns size in memory, in bytes."); - -static PyObject * -cpu_set_sizeof(Py_cpu_set *set, PyObject *noargs) -{ - Py_ssize_t res = 0; - - res = sizeof(Py_cpu_set); - res += set->size; - return PyLong_FromSsize_t(res); -} - -static PyObject * -cpu_set_repr(Py_cpu_set *set) -{ - return PyUnicode_FromFormat("", set->ncpus); -} - -static Py_ssize_t -cpu_set_len(Py_cpu_set *set) -{ - return set->ncpus; -} - -static int -_get_cpu(Py_cpu_set *set, const char *requester, PyObject *args) -{ - int cpu; - if (!PyArg_ParseTuple(args, requester, &cpu)) - return -1; - if (cpu < 0) { - PyErr_SetString(PyExc_ValueError, "cpu < 0 not valid"); - return -1; - } - if (cpu >= set->ncpus) { - PyErr_SetString(PyExc_ValueError, "cpu too large for set"); - return -1; - } - return cpu; -} - -PyDoc_STRVAR(cpu_set_set_doc, -"cpu_set.set(i)\n\n\ -Add CPU *i* to the set."); - -static PyObject * -cpu_set_set(Py_cpu_set *set, PyObject *args) -{ - int cpu = _get_cpu(set, "i|set", args); - if (cpu == -1) - return NULL; - CPU_SET_S(cpu, set->size, set->set); - Py_RETURN_NONE; -} - -PyDoc_STRVAR(cpu_set_count_doc, -"cpu_set.count() -> int\n\n\ -Return the number of CPUs active in the set."); - -static PyObject * -cpu_set_count(Py_cpu_set *set, PyObject *noargs) -{ - return PyLong_FromLong(CPU_COUNT_S(set->size, set->set)); -} - -PyDoc_STRVAR(cpu_set_clear_doc, -"cpu_set.clear(i)\n\n\ -Remove CPU *i* from the set."); - -static PyObject * -cpu_set_clear(Py_cpu_set *set, PyObject *args) -{ - int cpu = _get_cpu(set, "i|clear", args); - if (cpu == -1) - return NULL; - CPU_CLR_S(cpu, set->size, set->set); - Py_RETURN_NONE; -} - -PyDoc_STRVAR(cpu_set_isset_doc, -"cpu_set.isset(i) -> bool\n\n\ -Test if CPU *i* is in the set."); - -static PyObject * -cpu_set_isset(Py_cpu_set *set, PyObject *args) -{ - int cpu = _get_cpu(set, "i|isset", args); - if (cpu == -1) - return NULL; - if (CPU_ISSET_S(cpu, set->size, set->set)) - Py_RETURN_TRUE; - Py_RETURN_FALSE; -} - -PyDoc_STRVAR(cpu_set_zero_doc, -"cpu_set.zero()\n\n\ -Clear the cpu_set."); - -static PyObject * -cpu_set_zero(Py_cpu_set *set, PyObject *noargs) -{ - CPU_ZERO_S(set->size, set->set); - Py_RETURN_NONE; -} - -static PyObject * -cpu_set_richcompare(Py_cpu_set *set, Py_cpu_set *other, int op) -{ - int eq; - - if ((op != Py_EQ && op != Py_NE) || Py_TYPE(other) != &cpu_set_type) - Py_RETURN_NOTIMPLEMENTED; - - eq = set->ncpus == other->ncpus && CPU_EQUAL_S(set->size, set->set, other->set); - if ((op == Py_EQ) ? eq : !eq) - Py_RETURN_TRUE; - else - Py_RETURN_FALSE; -} - -#define CPU_SET_BINOP(name, op) \ - static PyObject * \ - do_cpu_set_##name(Py_cpu_set *left, Py_cpu_set *right, Py_cpu_set *res) { \ - if (res) { \ - Py_INCREF(res); \ - } \ - else { \ - res = make_new_cpu_set(&cpu_set_type, left->ncpus); \ - if (!res) \ - return NULL; \ - } \ - if (Py_TYPE(right) != &cpu_set_type || left->ncpus != right->ncpus) { \ - Py_DECREF(res); \ - Py_RETURN_NOTIMPLEMENTED; \ - } \ - assert(left->size == right->size && right->size == res->size); \ - op(res->size, res->set, left->set, right->set); \ - return (PyObject *)res; \ - } \ - static PyObject * \ - cpu_set_##name(Py_cpu_set *left, Py_cpu_set *right) { \ - return do_cpu_set_##name(left, right, NULL); \ - } \ - static PyObject * \ - cpu_set_i##name(Py_cpu_set *left, Py_cpu_set *right) { \ - return do_cpu_set_##name(left, right, left); \ - } \ - -CPU_SET_BINOP(and, CPU_AND_S) -CPU_SET_BINOP(or, CPU_OR_S) -CPU_SET_BINOP(xor, CPU_XOR_S) -#undef CPU_SET_BINOP - -PyDoc_STRVAR(cpu_set_doc, -"cpu_set(size)\n\n\ -Create an empty mask of CPUs."); - -static PyNumberMethods cpu_set_as_number = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_bool*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - (binaryfunc)cpu_set_and, /*nb_and*/ - (binaryfunc)cpu_set_xor, /*nb_xor*/ - (binaryfunc)cpu_set_or, /*nb_or*/ - 0, /*nb_int*/ - 0, /*nb_reserved*/ - 0, /*nb_float*/ - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - (binaryfunc)cpu_set_iand, /*nb_inplace_and*/ - (binaryfunc)cpu_set_ixor, /*nb_inplace_xor*/ - (binaryfunc)cpu_set_ior, /*nb_inplace_or*/ -}; - -static PySequenceMethods cpu_set_as_sequence = { - (lenfunc)cpu_set_len, /* sq_length */ -}; - -static PyMethodDef cpu_set_methods[] = { - {"clear", (PyCFunction)cpu_set_clear, METH_VARARGS, cpu_set_clear_doc}, - {"count", (PyCFunction)cpu_set_count, METH_NOARGS, cpu_set_count_doc}, - {"isset", (PyCFunction)cpu_set_isset, METH_VARARGS, cpu_set_isset_doc}, - {"set", (PyCFunction)cpu_set_set, METH_VARARGS, cpu_set_set_doc}, - {"zero", (PyCFunction)cpu_set_zero, METH_NOARGS, cpu_set_zero_doc}, - {"__sizeof__", (PyCFunction)cpu_set_sizeof, METH_NOARGS, cpu_set_sizeof_doc}, - {NULL, NULL} /* sentinel */ -}; - -static PyTypeObject cpu_set_type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "posix.cpu_set", /* tp_name */ - sizeof(Py_cpu_set), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - (destructor)cpu_set_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - (reprfunc)cpu_set_repr, /* tp_repr */ - &cpu_set_as_number, /* tp_as_number */ - &cpu_set_as_sequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - PyObject_HashNotImplemented, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - cpu_set_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)cpu_set_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - cpu_set_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - PyType_GenericAlloc, /* tp_alloc */ - cpu_set_new, /* tp_new */ - PyObject_Del, /* tp_free */ -}; +/* The minimum number of CPUs allocated in a cpu_set_t */ +static const int NCPUS_START = sizeof(unsigned long) * CHAR_BIT; PyDoc_STRVAR(posix_sched_setaffinity__doc__, "sched_setaffinity(pid, cpu_set)\n\n\ @@ -6028,14 +5731,89 @@ posix_sched_setaffinity(PyObject *self, PyObject *args) { pid_t pid; - Py_cpu_set *cpu_set; - - if (!PyArg_ParseTuple(args, _Py_PARSE_PID "O!:sched_setaffinity", - &pid, &cpu_set_type, &cpu_set)) - return NULL; - if (sched_setaffinity(pid, cpu_set->size, cpu_set->set)) - return posix_error(); + int ncpus; + size_t setsize; + cpu_set_t *mask = NULL; + PyObject *iterable, *iterator = NULL, *item; + + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "O:sched_setaffinity", + &pid, &iterable)) + return NULL; + + iterator = PyObject_GetIter(iterable); + if (iterator == NULL) + return NULL; + + ncpus = NCPUS_START; + setsize = CPU_ALLOC_SIZE(ncpus); + mask = CPU_ALLOC(ncpus); + if (mask == NULL) { + PyErr_NoMemory(); + goto error; + } + CPU_ZERO_S(setsize, mask); + + while ((item = PyIter_Next(iterator))) { + long cpu; + if (!PyLong_Check(item)) { + PyErr_Format(PyExc_TypeError, + "expected an iterator of ints, " + "but iterator yielded %R", + Py_TYPE(item)); + Py_DECREF(item); + goto error; + } + cpu = PyLong_AsLong(item); + Py_DECREF(item); + if (cpu < 0) { + if (!PyErr_Occurred()) + PyErr_SetString(PyExc_ValueError, "negative CPU number"); + goto error; + } + if (cpu > INT_MAX - 1) { + PyErr_SetString(PyExc_OverflowError, "CPU number too large"); + goto error; + } + if (cpu >= ncpus) { + /* Grow CPU mask to fit the CPU number */ + int newncpus = ncpus; + cpu_set_t *newmask; + size_t newsetsize; + while (newncpus <= cpu) { + if (newncpus > INT_MAX / 2) + newncpus = cpu + 1; + else + newncpus = newncpus * 2; + } + newmask = CPU_ALLOC(newncpus); + if (newmask == NULL) { + PyErr_NoMemory(); + goto error; + } + newsetsize = CPU_ALLOC_SIZE(newncpus); + CPU_ZERO_S(newsetsize, newmask); + memcpy(newmask, mask, setsize); + CPU_FREE(mask); + setsize = newsetsize; + mask = newmask; + ncpus = newncpus; + } + CPU_SET_S(cpu, setsize, mask); + } + Py_CLEAR(iterator); + + if (sched_setaffinity(pid, setsize, mask)) { + posix_error(); + goto error; + } + CPU_FREE(mask); Py_RETURN_NONE; + +error: + if (mask) + CPU_FREE(mask); + Py_XDECREF(iterator); + return NULL; } PyDoc_STRVAR(posix_sched_getaffinity__doc__, @@ -6047,20 +5825,58 @@ posix_sched_getaffinity(PyObject *self, PyObject *args) { pid_t pid; - int ncpus; - Py_cpu_set *res; - - if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:sched_getaffinity", - &pid, &ncpus)) - return NULL; - res = make_new_cpu_set(&cpu_set_type, ncpus); - if (!res) - return NULL; - if (sched_getaffinity(pid, res->size, res->set)) { - Py_DECREF(res); - return posix_error(); - } - return (PyObject *)res; + int cpu, ncpus, count; + size_t setsize; + cpu_set_t *mask = NULL; + PyObject *res = NULL; + + if (!PyArg_ParseTuple(args, _Py_PARSE_PID ":sched_getaffinity", + &pid)) + return NULL; + + ncpus = NCPUS_START; + while (1) { + setsize = CPU_ALLOC_SIZE(ncpus); + mask = CPU_ALLOC(ncpus); + if (mask == NULL) + return PyErr_NoMemory(); + if (sched_getaffinity(pid, setsize, mask) == 0) + break; + CPU_FREE(mask); + if (errno != EINVAL) + return posix_error(); + if (ncpus > INT_MAX / 2) { + PyErr_SetString(PyExc_OverflowError, "could not allocate " + "a large enough CPU set"); + return NULL; + } + ncpus = ncpus * 2; + } + + res = PySet_New(NULL); + if (res == NULL) + goto error; + for (cpu = 0, count = CPU_COUNT_S(setsize, mask); count; cpu++) { + if (CPU_ISSET_S(cpu, setsize, mask)) { + PyObject *cpu_num = PyLong_FromLong(cpu); + --count; + if (cpu_num == NULL) + goto error; + if (PySet_Add(res, cpu_num)) { + Py_DECREF(cpu_num); + goto error; + } + Py_DECREF(cpu_num); + } + } + CPU_FREE(mask); + return res; + +error: + if (mask) + CPU_FREE(mask); + Py_XDECREF(res); + return NULL; } #endif /* HAVE_SCHED_SETAFFINITY */ @@ -11997,13 +11813,6 @@ Py_INCREF(PyExc_OSError); PyModule_AddObject(m, "error", PyExc_OSError); -#ifdef HAVE_SCHED_SETAFFINITY - if (PyType_Ready(&cpu_set_type) < 0) - return NULL; - Py_INCREF(&cpu_set_type); - PyModule_AddObject(m, "cpu_set", (PyObject *)&cpu_set_type); -#endif - #ifdef HAVE_PUTENV if (posix_putenv_garbage == NULL) posix_putenv_garbage = PyDict_New(); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 16:19:52 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 4 Aug 2012 16:19:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge?= Message-ID: <3Wq6hS4MLkzPgw@mail.python.org> http://hg.python.org/cpython/rev/27ae40361ca5 changeset: 78411:27ae40361ca5 parent: 78410:d6745ddbccbd parent: 78409:cdf27a213bd2 user: Antoine Pitrou date: Sat Aug 04 16:17:10 2012 +0200 summary: Merge files: Lib/asynchat.py | 14 +---------- Lib/bz2.py | 47 ++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/Lib/asynchat.py b/Lib/asynchat.py --- a/Lib/asynchat.py +++ b/Lib/asynchat.py @@ -49,18 +49,6 @@ import asyncore from collections import deque -def buffer(obj, start=None, stop=None): - # if memoryview objects gain slicing semantics, - # this function will change for the better - # memoryview used for the TypeError - memoryview(obj) - if start == None: - start = 0 - if stop == None: - stop = len(obj) - x = obj[start:stop] - ## print("buffer type is: %s"%(type(x),)) - return x class async_chat (asyncore.dispatcher): """This is an abstract class. You must derive from this class, and add @@ -240,7 +228,7 @@ # handle classic producer behavior obs = self.ac_out_buffer_size try: - data = buffer(first, 0, obs) + data = first[:obs] except TypeError: data = first.more() if data: diff --git a/Lib/bz2.py b/Lib/bz2.py --- a/Lib/bz2.py +++ b/Lib/bz2.py @@ -174,29 +174,31 @@ # Fill the readahead buffer if it is empty. Returns False on EOF. def _fill_buffer(self): - if self._buffer: - return True + # Depending on the input data, our call to the decompressor may not + # return any data. In this case, try again after reading another block. + while True: + if self._buffer: + return True - if self._decompressor.unused_data: - rawblock = self._decompressor.unused_data - else: - rawblock = self._fp.read(_BUFFER_SIZE) + if self._decompressor.unused_data: + rawblock = self._decompressor.unused_data + else: + rawblock = self._fp.read(_BUFFER_SIZE) - if not rawblock: + if not rawblock: + if self._decompressor.eof: + self._mode = _MODE_READ_EOF + self._size = self._pos + return False + else: + raise EOFError("Compressed file ended before the " + "end-of-stream marker was reached") + + # Continue to next stream. if self._decompressor.eof: - self._mode = _MODE_READ_EOF - self._size = self._pos - return False - else: - raise EOFError("Compressed file ended before the " - "end-of-stream marker was reached") + self._decompressor = BZ2Decompressor() - # Continue to next stream. - if self._decompressor.eof: - self._decompressor = BZ2Decompressor() - - self._buffer = self._decompressor.decompress(rawblock) - return True + self._buffer = self._decompressor.decompress(rawblock) # Read data until EOF. # If return_data is false, consume the data without returning it. @@ -256,11 +258,14 @@ return self._read_block(size) def read1(self, size=-1): - """Read up to size uncompressed bytes with at most one read - from the underlying stream. + """Read up to size uncompressed bytes, while trying to avoid + making multiple reads from the underlying stream. Returns b'' if the file is at EOF. """ + # Usually, read1() calls _fp.read() at most once. However, sometimes + # this does not give enough data for the decompressor to make progress. + # In this case we make multiple reads, to avoid returning b"". with self._lock: self._check_can_read() if (size == 0 or self._mode == _MODE_READ_EOF or -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 19:43:20 2012 From: python-checkins at python.org (sandro.tosi) Date: Sat, 4 Aug 2012 19:43:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_add_missing_pe?= =?utf-8?q?riod=3B_thanks_to_Gaston_Fiore_from_docs=40?= Message-ID: <3WqCCD50TpzPgt@mail.python.org> http://hg.python.org/cpython/rev/1bc398a63444 changeset: 78412:1bc398a63444 branch: 2.7 parent: 78402:c52e709577b3 user: Sandro Tosi date: Sat Aug 04 19:42:06 2012 +0200 summary: add missing period; thanks to Gaston Fiore from docs@ files: Doc/tutorial/modules.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -242,7 +242,7 @@ are not part of the core of the language but are nevertheless built in, either for efficiency or to provide access to operating system primitives such as system calls. The set of such modules is a configuration option which also -depends on the underlying platform For example, the :mod:`winreg` module is only +depends on the underlying platform. For example, the :mod:`winreg` module is only provided on Windows systems. One particular module deserves some attention: :mod:`sys`, which is built into every Python interpreter. The variables ``sys.ps1`` and ``sys.ps2`` define the strings used as primary and secondary -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 19:43:22 2012 From: python-checkins at python.org (sandro.tosi) Date: Sat, 4 Aug 2012 19:43:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_add_missing_pe?= =?utf-8?q?riod=3B_thanks_to_Gaston_Fiore_from_docs=40?= Message-ID: <3WqCCG32S5zPkL@mail.python.org> http://hg.python.org/cpython/rev/66b53f555704 changeset: 78413:66b53f555704 branch: 3.2 parent: 78406:09408b990ca5 user: Sandro Tosi date: Sat Aug 04 19:42:24 2012 +0200 summary: add missing period; thanks to Gaston Fiore from docs@ files: Doc/tutorial/modules.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -248,7 +248,7 @@ are not part of the core of the language but are nevertheless built in, either for efficiency or to provide access to operating system primitives such as system calls. The set of such modules is a configuration option which also -depends on the underlying platform For example, the :mod:`winreg` module is only +depends on the underlying platform. For example, the :mod:`winreg` module is only provided on Windows systems. One particular module deserves some attention: :mod:`sys`, which is built into every Python interpreter. The variables ``sys.ps1`` and ``sys.ps2`` define the strings used as primary and secondary -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 19:43:23 2012 From: python-checkins at python.org (sandro.tosi) Date: Sat, 4 Aug 2012 19:43:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3WqCCH5mNBzPk6@mail.python.org> http://hg.python.org/cpython/rev/fa8f6c680c6b changeset: 78414:fa8f6c680c6b parent: 78411:27ae40361ca5 parent: 78413:66b53f555704 user: Sandro Tosi date: Sat Aug 04 19:42:46 2012 +0200 summary: merge with 3.2 files: Doc/tutorial/modules.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -248,7 +248,7 @@ are not part of the core of the language but are nevertheless built in, either for efficiency or to provide access to operating system primitives such as system calls. The set of such modules is a configuration option which also -depends on the underlying platform For example, the :mod:`winreg` module is only +depends on the underlying platform. For example, the :mod:`winreg` module is only provided on Windows systems. One particular module deserves some attention: :mod:`sys`, which is built into every Python interpreter. The variables ``sys.ps1`` and ``sys.ps2`` define the strings used as primary and secondary -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 20:45:48 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 4 Aug 2012 20:45:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzEzMDUy?= =?utf-8?q?=3A_Fix_IDLE_crashing_when_replace_string_in_Search/Replace_dia?= =?utf-8?q?log?= Message-ID: <3WqDbJ3FxszPl1@mail.python.org> http://hg.python.org/cpython/rev/0f38948cc6df changeset: 78415:0f38948cc6df branch: 3.2 parent: 78413:66b53f555704 user: Andrew Svetlov date: Sat Aug 04 21:38:22 2012 +0300 summary: Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. files: Lib/idlelib/ReplaceDialog.py | 31 ++++++++++++++++++++--- Misc/NEWS | 3 ++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Lib/idlelib/ReplaceDialog.py b/Lib/idlelib/ReplaceDialog.py --- a/Lib/idlelib/ReplaceDialog.py +++ b/Lib/idlelib/ReplaceDialog.py @@ -2,6 +2,8 @@ from idlelib import SearchEngine from idlelib.SearchDialogBase import SearchDialogBase +import re + def replace(text): root = text._root() @@ -11,6 +13,7 @@ dialog = engine._replacedialog dialog.open(text) + class ReplaceDialog(SearchDialogBase): title = "Replace Dialog" @@ -55,8 +58,23 @@ def default_command(self, event=None): if self.do_find(self.ok): - self.do_replace() - self.do_find(0) + if self.do_replace(): # Only find next match if replace succeeded. + # A bad re can cause a it to fail. + self.do_find(0) + + def _replace_expand(self, m, repl): + """ Helper function for expanding a regular expression + in the replace field, if needed. """ + if self.engine.isre(): + try: + new = m.expand(repl) + except re.error: + self.engine.report_error(repl, 'Invalid Replace Expression') + new = None + else: + new = repl + + return new def replace_all(self, event=None): prog = self.engine.getprog() @@ -86,7 +104,9 @@ line, m = res chars = text.get("%d.0" % line, "%d.0" % (line+1)) orig = m.group() - new = m.expand(repl) + new = self._replace_expand(m, repl) + if new is None: + break i, j = m.span() first = "%d.%d" % (line, i) last = "%d.%d" % (line, j) @@ -103,7 +123,6 @@ text.undo_block_stop() if first and last: self.show_hit(first, last) - self.close() def do_find(self, ok=0): if not self.engine.getprog(): @@ -138,7 +157,9 @@ m = prog.match(chars, col) if not prog: return False - new = m.expand(self.replvar.get()) + new = self._replace_expand(m, self.replvar.get()) + if new is None: + return False text.mark_set("insert", first) text.undo_block_start() if m.group(): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,9 @@ Library ------- +- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog + ended with '\'. Patch by Roger Serwy. + - Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() emulation code. Patch by Philipp Hagemeister. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 20:45:50 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 4 Aug 2012 20:45:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2313052=3A_Fix_IDLE_crashing_when_replace_string_?= =?utf-8?q?in_Search/Replace_dialog?= Message-ID: <3WqDbL1DTSzPfN@mail.python.org> http://hg.python.org/cpython/rev/9dcfba4d0357 changeset: 78416:9dcfba4d0357 parent: 78414:fa8f6c680c6b parent: 78415:0f38948cc6df user: Andrew Svetlov date: Sat Aug 04 21:42:48 2012 +0300 summary: Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. files: Lib/idlelib/ReplaceDialog.py | 31 ++++++++++++++++++++--- Misc/NEWS | 3 ++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Lib/idlelib/ReplaceDialog.py b/Lib/idlelib/ReplaceDialog.py --- a/Lib/idlelib/ReplaceDialog.py +++ b/Lib/idlelib/ReplaceDialog.py @@ -2,6 +2,8 @@ from idlelib import SearchEngine from idlelib.SearchDialogBase import SearchDialogBase +import re + def replace(text): root = text._root() @@ -11,6 +13,7 @@ dialog = engine._replacedialog dialog.open(text) + class ReplaceDialog(SearchDialogBase): title = "Replace Dialog" @@ -55,8 +58,23 @@ def default_command(self, event=None): if self.do_find(self.ok): - self.do_replace() - self.do_find(0) + if self.do_replace(): # Only find next match if replace succeeded. + # A bad re can cause a it to fail. + self.do_find(0) + + def _replace_expand(self, m, repl): + """ Helper function for expanding a regular expression + in the replace field, if needed. """ + if self.engine.isre(): + try: + new = m.expand(repl) + except re.error: + self.engine.report_error(repl, 'Invalid Replace Expression') + new = None + else: + new = repl + + return new def replace_all(self, event=None): prog = self.engine.getprog() @@ -86,7 +104,9 @@ line, m = res chars = text.get("%d.0" % line, "%d.0" % (line+1)) orig = m.group() - new = m.expand(repl) + new = self._replace_expand(m, repl) + if new is None: + break i, j = m.span() first = "%d.%d" % (line, i) last = "%d.%d" % (line, j) @@ -103,7 +123,6 @@ text.undo_block_stop() if first and last: self.show_hit(first, last) - self.close() def do_find(self, ok=0): if not self.engine.getprog(): @@ -138,7 +157,9 @@ m = prog.match(chars, col) if not prog: return False - new = m.expand(self.replvar.get()) + new = self._replace_expand(m, self.replvar.get()) + if new is None: + return False text.mark_set("insert", first) text.undo_block_start() if m.group(): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,9 @@ Library ------- +- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog + ended with '\'. Patch by Roger Serwy. + - Issue #12655: Instead of requiring a custom type, os.sched_getaffinity and os.sched_setaffinity now use regular sets of integers to represent the CPUs a process is restricted to. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 20:45:51 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 4 Aug 2012 20:45:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzEzMDUy?= =?utf-8?q?=3A_Fix_IDLE_crashing_when_replace_string_in_Search/Replace_dia?= =?utf-8?q?log?= Message-ID: <3WqDbM4nWBzPgt@mail.python.org> http://hg.python.org/cpython/rev/44c00de723b3 changeset: 78417:44c00de723b3 branch: 2.7 parent: 78412:1bc398a63444 user: Andrew Svetlov date: Sat Aug 04 21:45:23 2012 +0300 summary: Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. files: Lib/idlelib/ReplaceDialog.py | 30 ++++++++++++++++++++---- Misc/NEWS | 3 ++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Lib/idlelib/ReplaceDialog.py b/Lib/idlelib/ReplaceDialog.py --- a/Lib/idlelib/ReplaceDialog.py +++ b/Lib/idlelib/ReplaceDialog.py @@ -2,6 +2,8 @@ from idlelib import SearchEngine from idlelib.SearchDialogBase import SearchDialogBase +import re + def replace(text): root = text._root() @@ -11,6 +13,7 @@ dialog = engine._replacedialog dialog.open(text) + class ReplaceDialog(SearchDialogBase): title = "Replace Dialog" @@ -55,8 +58,22 @@ def default_command(self, event=None): if self.do_find(self.ok): - self.do_replace() - self.do_find(0) + if self.do_replace(): # Only find next match if replace succeeded. + # A bad re can cause a it to fail. + self.do_find(0) + + def _replace_expand(self, m, repl): + """ Helper function for expanding a regular expression + in the replace field, if needed. """ + if self.engine.isre(): + try: + new = m.expand(repl) + except re.error: + self.engine.report_error(repl, 'Invalid Replace Expression') + new = None + else: + new = repl + return new def replace_all(self, event=None): prog = self.engine.getprog() @@ -86,7 +103,9 @@ line, m = res chars = text.get("%d.0" % line, "%d.0" % (line+1)) orig = m.group() - new = m.expand(repl) + new = self._replace_expand(m, repl) + if new is None: + break i, j = m.span() first = "%d.%d" % (line, i) last = "%d.%d" % (line, j) @@ -103,7 +122,6 @@ text.undo_block_stop() if first and last: self.show_hit(first, last) - self.close() def do_find(self, ok=0): if not self.engine.getprog(): @@ -138,7 +156,9 @@ m = prog.match(chars, col) if not prog: return False - new = m.expand(self.replvar.get()) + new = self._replace_expand(m, self.replvar.get()) + if new is None: + return False text.mark_set("insert", first) text.undo_block_start() if m.group(): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -92,6 +92,9 @@ Library ------- +- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog + ended with '\'. Patch by Roger Serwy. + - Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() emulation code. Patch by Philipp Hagemeister. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 21:01:46 2012 From: python-checkins at python.org (victor.stinner) Date: Sat, 4 Aug 2012 21:01:46 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2312655=3A_Mention_?= =?utf-8?q?multiprocessing=2Ecpu=5Fcount=28=29_in_os=2Esched=5Fgetaffinity?= =?utf-8?b?KCkgZG9j?= Message-ID: <3WqDxk3FWnzPl2@mail.python.org> http://hg.python.org/cpython/rev/fb975cb8fb45 changeset: 78418:fb975cb8fb45 parent: 78416:9dcfba4d0357 user: Victor Stinner date: Sat Aug 04 20:57:48 2012 +0200 summary: Issue #12655: Mention multiprocessing.cpu_count() in os.sched_getaffinity() doc files: Doc/library/os.rst | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3153,6 +3153,10 @@ Return the set of CPUs the process with PID *pid* (or the current process if zero) is restricted to. + .. seealso:: + :func:`multiprocessing.cpu_count` returns the number of CPUs in the + system. + .. _os-path: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 4 23:29:25 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 4 Aug 2012 23:29:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_unused_variable_=60?= =?utf-8?b?dHJpbV9nZXRfY29kZWAu?= Message-ID: <3WqJD51BlHzPk5@mail.python.org> http://hg.python.org/cpython/rev/9ba8d0b3ff18 changeset: 78419:9ba8d0b3ff18 user: Antoine Pitrou date: Sat Aug 04 23:26:25 2012 +0200 summary: Remove unused variable `trim_get_code`. files: Python/import.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-) diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -1155,7 +1155,6 @@ const char *importlib_filename = ""; const char *remove_frames = "_call_with_frames_removed"; int always_trim = 0; - int trim_get_code = 0; int in_importlib = 0; PyObject *exception, *value, *base_tb, *tb; PyObject **prev_link, **outer_link = NULL; @@ -1170,9 +1169,6 @@ if (PyType_IsSubtype((PyTypeObject *) exception, (PyTypeObject *) PyExc_ImportError)) always_trim = 1; - if (PyType_IsSubtype((PyTypeObject *) exception, - (PyTypeObject *) PyExc_SyntaxError)) - trim_get_code = 1; prev_link = &base_tb; tb = base_tb; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 00:29:44 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 5 Aug 2012 00:29:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4IHRlc3Rfc3lz?= =?utf-8?q?_under_Windows_=28issue_=2313119=29?= Message-ID: <3WqKYh0Sd0zPkm@mail.python.org> http://hg.python.org/cpython/rev/4efad7fba42a changeset: 78420:4efad7fba42a branch: 3.2 parent: 78415:0f38948cc6df user: Antoine Pitrou date: Sun Aug 05 00:15:06 2012 +0200 summary: Fix test_sys under Windows (issue #13119) files: Lib/test/test_sys.py | 3 ++- 1 files changed, 2 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 @@ -523,7 +523,8 @@ p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'], stdout = subprocess.PIPE, env=env) out = p.communicate()[0].strip() - self.assertEqual(out, "\xa2\n".encode("cp424")) + expected = ("\xa2" + os.linesep).encode("cp424") + self.assertEqual(out, expected) env["PYTHONIOENCODING"] = "ascii:replace" p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'], -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 00:29:45 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 5 Aug 2012 00:29:45 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_universal_?= =?utf-8?q?newlines_test_to_avoid_the_newline_translation_done_by_sys=2Est?= =?utf-8?q?dout=2E?= Message-ID: <3WqKYj5JcQzPlN@mail.python.org> http://hg.python.org/cpython/rev/481f5d9ef577 changeset: 78421:481f5d9ef577 branch: 3.2 user: Antoine Pitrou date: Sun Aug 05 00:23:40 2012 +0200 summary: Fix universal newlines test to avoid the newline translation done by sys.stdout. files: Lib/test/test_subprocess.py | 54 ++++++++++++------------ 1 files changed, 28 insertions(+), 26 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 @@ -476,21 +476,22 @@ def test_universal_newlines(self): p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + - 'sys.stdout.write(sys.stdin.readline());' - 'sys.stdout.flush();' - 'sys.stdout.write("line2\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write(sys.stdin.read());' - 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], + 'buf = sys.stdout.buffer;' + 'buf.write(sys.stdin.readline().encode());' + 'buf.flush();' + 'buf.write(b"line2\\n");' + 'buf.flush();' + 'buf.write(sys.stdin.read().encode());' + 'buf.flush();' + 'buf.write(b"line4\\n");' + 'buf.flush();' + 'buf.write(b"line5\\r\\n");' + 'buf.flush();' + 'buf.write(b"line6\\r");' + 'buf.flush();' + 'buf.write(b"\\nline7");' + 'buf.flush();' + 'buf.write(b"\\nline8");'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=1) @@ -510,17 +511,18 @@ # universal newlines through communicate() p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + - 'sys.stdout.write("line2\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], + 'buf = sys.stdout.buffer;' + 'buf.write(b"line2\\n");' + 'buf.flush();' + 'buf.write(b"line4\\n");' + 'buf.flush();' + 'buf.write(b"line5\\r\\n");' + 'buf.flush();' + 'buf.write(b"line6\\r");' + 'buf.flush();' + 'buf.write(b"\\nline7");' + 'buf.flush();' + 'buf.write(b"\\nline8");'], stderr=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=1) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 00:29:47 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 5 Aug 2012 00:29:47 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_universal_newlines-related_fixes_=28issue_=2313119?= =?utf-8?q?=29?= Message-ID: <3WqKYl2LT5zPl1@mail.python.org> http://hg.python.org/cpython/rev/e4a87f0253e9 changeset: 78422:e4a87f0253e9 parent: 78419:9ba8d0b3ff18 parent: 78421:481f5d9ef577 user: Antoine Pitrou date: Sun Aug 05 00:25:31 2012 +0200 summary: Merge universal newlines-related fixes (issue #13119) files: Lib/test/test_subprocess.py | 54 ++++++++++++------------ Lib/test/test_sys.py | 3 +- 2 files changed, 30 insertions(+), 27 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 @@ -563,21 +563,22 @@ def test_universal_newlines(self): p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + - 'sys.stdout.write(sys.stdin.readline());' - 'sys.stdout.flush();' - 'sys.stdout.write("line2\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write(sys.stdin.read());' - 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], + 'buf = sys.stdout.buffer;' + 'buf.write(sys.stdin.readline().encode());' + 'buf.flush();' + 'buf.write(b"line2\\n");' + 'buf.flush();' + 'buf.write(sys.stdin.read().encode());' + 'buf.flush();' + 'buf.write(b"line4\\n");' + 'buf.flush();' + 'buf.write(b"line5\\r\\n");' + 'buf.flush();' + 'buf.write(b"line6\\r");' + 'buf.flush();' + 'buf.write(b"\\nline7");' + 'buf.flush();' + 'buf.write(b"\\nline8");'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=1) @@ -597,17 +598,18 @@ # universal newlines through communicate() p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + - 'sys.stdout.write("line2\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' - 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], + 'buf = sys.stdout.buffer;' + 'buf.write(b"line2\\n");' + 'buf.flush();' + 'buf.write(b"line4\\n");' + 'buf.flush();' + 'buf.write(b"line5\\r\\n");' + 'buf.flush();' + 'buf.write(b"line6\\r");' + 'buf.flush();' + 'buf.write(b"\\nline7");' + 'buf.flush();' + 'buf.write(b"\\nline8");'], stderr=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=1) 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 @@ -535,7 +535,8 @@ p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'], stdout = subprocess.PIPE, env=env) out = p.communicate()[0].strip() - self.assertEqual(out, "\xa2\n".encode("cp424")) + expected = ("\xa2" + os.linesep).encode("cp424") + self.assertEqual(out, expected) env["PYTHONIOENCODING"] = "ascii:replace" p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'], -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 00:35:53 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 5 Aug 2012 00:35:53 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_test=5Fvenv_to_work_wi?= =?utf-8?q?th_universal_newlines_=28issue_=2313119=29?= Message-ID: <3WqKhn4DWrzPkm@mail.python.org> http://hg.python.org/cpython/rev/f8e435d6a801 changeset: 78423:f8e435d6a801 user: Antoine Pitrou date: Sun Aug 05 00:33:10 2012 +0200 summary: Fix test_venv to work with universal newlines (issue #13119) files: Lib/test/test_venv.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -111,7 +111,7 @@ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - self.assertEqual(out[:-1], expected.encode()) + self.assertEqual(out.strip(), expected.encode()) def test_overwrite_existing(self): """ @@ -179,7 +179,7 @@ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - self.assertEqual(out[:-1], envpy.encode()) + self.assertEqual(out.strip(), envpy.encode()) @unittest.skipUnless(can_symlink(), 'Needs symlinks') def test_executable_symlinks(self): @@ -194,7 +194,7 @@ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - self.assertEqual(out[:-1], envpy.encode()) + self.assertEqual(out.strip(), envpy.encode()) def test_main(): run_unittest(BasicTest) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 00:43:32 2012 From: python-checkins at python.org (vinay.sajip) Date: Sun, 5 Aug 2012 00:43:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NTQx?= =?utf-8?q?=3A_Correct_anomaly_in_logging=2Eexception=2E_Thanks_to_Ned_Bat?= =?utf-8?q?chelder?= Message-ID: <3WqKsc72dtzPkm@mail.python.org> http://hg.python.org/cpython/rev/322da186cced changeset: 78424:322da186cced branch: 2.7 parent: 78417:44c00de723b3 user: Vinay Sajip date: Sat Aug 04 23:40:21 2012 +0100 summary: Issue #15541: Correct anomaly in logging.exception. Thanks to Ned Batchelder for the report. files: Lib/logging/__init__.py | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1173,11 +1173,12 @@ if self.isEnabledFor(ERROR): self._log(ERROR, msg, args, **kwargs) - def exception(self, msg, *args): + def exception(self, msg, *args, **kwargs): """ Convenience method for logging an ERROR with exception information. """ - self.error(msg, exc_info=1, *args) + kwargs['exc_info'] = 1 + self.error(msg, *args, **kwargs) def critical(self, msg, *args, **kwargs): """ @@ -1582,12 +1583,13 @@ basicConfig() root.error(msg, *args, **kwargs) -def exception(msg, *args): +def exception(msg, *args, **kwargs): """ Log a message with severity 'ERROR' on the root logger, with exception information. """ - error(msg, exc_info=1, *args) + kwargs['exc_info'] = 1 + error(msg, *args, **kwargs) def warning(msg, *args, **kwargs): """ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 02:19:35 2012 From: python-checkins at python.org (nadeem.vawda) Date: Sun, 5 Aug 2012 02:19:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=2315546=3A_Fix_=7BGzipFil?= =?utf-8?q?e=2CLZMAFile=7D=2Eread1=28=29=27s_handling_of_pathological_inpu?= =?utf-8?q?t_data=2E?= Message-ID: <3WqN0R3XmpzPl2@mail.python.org> http://hg.python.org/cpython/rev/5284e65e865b changeset: 78425:5284e65e865b parent: 78423:f8e435d6a801 user: Nadeem Vawda date: Sun Aug 05 02:19:09 2012 +0200 summary: #15546: Fix {GzipFile,LZMAFile}.read1()'s handling of pathological input data. files: Lib/gzip.py | 5 +++- Lib/lzma.py | 47 ++++++++++++++++++++++------------------ Misc/NEWS | 3 ++ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -385,7 +385,10 @@ return b'' try: - self._read() + # For certain input data, a single call to _read() may not return + # any data. In this case, retry until we get some data or reach EOF. + while self.extrasize <= 0: + self._read() except EOFError: pass if size < 0 or size > self.extrasize: diff --git a/Lib/lzma.py b/Lib/lzma.py --- a/Lib/lzma.py +++ b/Lib/lzma.py @@ -204,29 +204,31 @@ # Fill the readahead buffer if it is empty. Returns False on EOF. def _fill_buffer(self): - if self._buffer: - return True + # Depending on the input data, our call to the decompressor may not + # return any data. In this case, try again after reading another block. + while True: + if self._buffer: + return True - if self._decompressor.unused_data: - rawblock = self._decompressor.unused_data - else: - rawblock = self._fp.read(_BUFFER_SIZE) + if self._decompressor.unused_data: + rawblock = self._decompressor.unused_data + else: + rawblock = self._fp.read(_BUFFER_SIZE) - if not rawblock: + if not rawblock: + if self._decompressor.eof: + self._mode = _MODE_READ_EOF + self._size = self._pos + return False + else: + raise EOFError("Compressed file ended before the " + "end-of-stream marker was reached") + + # Continue to next stream. if self._decompressor.eof: - self._mode = _MODE_READ_EOF - self._size = self._pos - return False - else: - raise EOFError("Compressed file ended before the " - "end-of-stream marker was reached") + self._decompressor = LZMADecompressor(**self._init_args) - # Continue to next stream. - if self._decompressor.eof: - self._decompressor = LZMADecompressor(**self._init_args) - - self._buffer = self._decompressor.decompress(rawblock) - return True + self._buffer = self._decompressor.decompress(rawblock) # Read data until EOF. # If return_data is false, consume the data without returning it. @@ -284,11 +286,14 @@ return self._read_block(size) def read1(self, size=-1): - """Read up to size uncompressed bytes with at most one read - from the underlying stream. + """Read up to size uncompressed bytes, while trying to avoid + making multiple reads from the underlying stream. Returns b"" if the file is at EOF. """ + # Usually, read1() calls _fp.read() at most once. However, sometimes + # this does not give enough data for the decompressor to make progress. + # In this case we make multiple reads, to avoid returning b"". self._check_can_read() if (size == 0 or self._mode == _MODE_READ_EOF or not self._fill_buffer()): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,9 @@ Library ------- +- Issue #15546: Fix handling of pathological input data in the read1() method of + the BZ2File, GzipFile and LZMAFile classes. + - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 05:34:43 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 05:34:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Note_some_easy_ways_to_ge?= =?utf-8?q?t_the_optional_build_dependencies_on_Ubuntu_and_Fedora?= Message-ID: <3WqSKb4qqvzPlR@mail.python.org> http://hg.python.org/devguide/rev/80358cdac0a6 changeset: 538:80358cdac0a6 user: Nick Coghlan date: Sun Aug 05 13:34:34 2012 +1000 summary: Note some easy ways to get the optional build dependencies on Ubuntu and Fedora files: setup.rst | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/setup.rst b/setup.rst --- a/setup.rst +++ b/setup.rst @@ -87,6 +87,33 @@ additional requirements so that the compiled interpreter supports the desired features. +For Windows systems, all the necessary components should be included in the +CPython checkout. + +For UNIX based systems, we try to use system libraries whenever available. +This means optional components will only build if the relevant system headers +are available. The best way to obtain the appropriate headers will vary by +distribution, but the appropriate commands for some popular distributions +are below. + +Fedora, Red Hat Enterprise Linux and other ``yum`` based systems:: + + $ sudo yum install yum-utils + $ sudo yum-builddep python3 + +Debian, Ubuntu and other ``apt`` based systems:: + + $ sudo apt-get build-dep python3 + +There will sometimes be optional modules added for a new release which +won't yet be identified in the OS level build dependencies. In those cases, +just ask for assistance on the core-mentorship list. If working on bug +fixes for Python 2.7, use ``python`` in place of ``python3`` in the above +commands. + +Explaining how to build optional dependencies on a UNIX based system without +root access is beyond the scope of this guide. + .. _clang: http://clang.llvm.org/ .. note:: While you need a C compiler to build CPython, you don't need any -- Repository URL: http://hg.python.org/devguide From solipsis at pitrou.net Sun Aug 5 05:56:43 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 05 Aug 2012 05:56:43 +0200 Subject: [Python-checkins] Daily reference leaks (5284e65e865b): sum=0 Message-ID: results for 5284e65e865b on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogkGH4IO', '-x'] From python-checkins at python.org Sun Aug 5 10:20:36 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 10:20:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2315559=3A_Implemen?= =?utf-8?q?ting_=5F=5Findex=5F=5F_creates_a_nasty_interaction_with_the_byt?= =?utf-8?q?es?= Message-ID: <3WqZgS2zn9zPkY@mail.python.org> http://hg.python.org/cpython/rev/5abea8a43f19 changeset: 78426:5abea8a43f19 user: Nick Coghlan date: Sun Aug 05 18:20:17 2012 +1000 summary: Close #15559: Implementing __index__ creates a nasty interaction with the bytes constructor. At least for 3.3, ipaddress objects must now be explicitly converted with int() and thus can't be passed directly to the hex() builtin. files: Lib/ipaddress.py | 6 ------ Lib/test/test_ipaddress.py | 17 +++++++++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -511,9 +511,6 @@ and '/' in str(address)): raise AddressValueError("Unexpected '/' in %r" % address) - def __index__(self): - return self._ip - def __int__(self): return self._ip @@ -571,9 +568,6 @@ def __init__(self, address): self._cache = {} - def __index__(self): - return int(self.network_address) ^ self.prefixlen - def __int__(self): return int(self.network_address) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -7,6 +7,7 @@ import unittest import re import contextlib +import operator import ipaddress class BaseTestCase(unittest.TestCase): @@ -72,6 +73,14 @@ with self.assertAddressError(re.escape(repr("1.0"))): self.factory(1.0) + def test_not_an_index_issue15559(self): + # Implementing __index__ makes for a very nasty interaction with the + # bytes constructor. Thus, we disallow implicit use as an integer + self.assertRaises(TypeError, operator.index, self.factory(1)) + self.assertRaises(TypeError, hex, self.factory(1)) + self.assertRaises(TypeError, bytes, self.factory(1)) + + class CommonTestMixin_v4(CommonTestMixin): def test_leading_zeros(self): @@ -599,7 +608,6 @@ self.assertEqual(first, last) self.assertEqual(128, ipaddress._count_righthand_zero_bits(0, 128)) self.assertEqual("IPv4Network('1.2.3.0/24')", repr(self.ipv4_network)) - self.assertEqual('0x1020318', hex(self.ipv4_network)) def testMissingAddressVersion(self): class Broken(ipaddress._BaseAddress): @@ -1545,13 +1553,6 @@ self.assertEqual(42540616829182469433547762482097946625, int(self.ipv6_address)) - def testHexRepresentation(self): - self.assertEqual(hex(0x1020304), - hex(self.ipv4_address)) - - self.assertEqual(hex(0x20010658022ACAFE0200000000000001), - hex(self.ipv6_address)) - def testForceVersion(self): self.assertEqual(ipaddress.ip_network(1).version, 4) self.assertEqual(ipaddress.IPv6Network(1).version, 6) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 10:48:44 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 10:48:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devguide=3A_It_has_been_pointed_out_t?= =?utf-8?q?his_paragraph_was_incorrect=2E_One_of_the_Windows_devs?= Message-ID: <3WqbHw6rP5zPl0@mail.python.org> http://hg.python.org/devguide/rev/f518f23d06d5 changeset: 539:f518f23d06d5 user: Nick Coghlan date: Sun Aug 05 18:48:35 2012 +1000 summary: It has been pointed out this paragraph was incorrect. One of the Windows devs will need to fill in more accurate info files: setup.rst | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/setup.rst b/setup.rst --- a/setup.rst +++ b/setup.rst @@ -87,9 +87,6 @@ additional requirements so that the compiled interpreter supports the desired features. -For Windows systems, all the necessary components should be included in the -CPython checkout. - For UNIX based systems, we try to use system libraries whenever available. This means optional components will only build if the relevant system headers are available. The best way to obtain the appropriate headers will vary by -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Sun Aug 5 12:43:29 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 12:43:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_NEWS_entry_for_previous_ip?= =?utf-8?q?address_fix?= Message-ID: <3WqdrK1pcDzPkX@mail.python.org> http://hg.python.org/cpython/rev/7c81caf2dd5a changeset: 78427:7c81caf2dd5a user: Nick Coghlan date: Sun Aug 05 20:43:19 2012 +1000 summary: NEWS entry for previous ipaddress fix 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 @@ -77,6 +77,10 @@ Library ------- +- Issue #15559: To avoid a problematic failure mode when passed to the bytes + constructor, objects in the ipaddress module no longer implement __index__ + (they still implement __int__ as appropriate) + - Issue #15546: Fix handling of pathological input data in the read1() method of the BZ2File, GzipFile and LZMAFile classes. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:02:29 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 14:02:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_14814=3A_Docs_work_s?= =?utf-8?q?howed_some_more_cases_of_networks_pretending_to_be?= Message-ID: <3WqgbT3hkCzPbb@mail.python.org> http://hg.python.org/cpython/rev/b513ad06d1fa changeset: 78428:b513ad06d1fa user: Nick Coghlan date: Sun Aug 05 22:02:18 2012 +1000 summary: Issue 14814: Docs work showed some more cases of networks pretending to be addresses and highlighted the weird approach to implementing the 'is_whatever' properties. Impl now illustrates far more clearly that networks have a property if both their network and broadcast addresses have that property files: Doc/library/ipaddress.rst | 464 +++++++++++++++++--- Lib/ipaddress.py | 554 +++++++++++++----------- Lib/test/test_ipaddress.py | 4 +- 3 files changed, 688 insertions(+), 334 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -9,17 +9,26 @@ -------------- -The :mod:`ipaddress` module provides the capabilities to create, manipulate and +.. note:: + + The ``ipaddress`` module has been included in the standard library on a + :term:`provisional basis `. Backwards incompatible + changes (up to and including removal of the package) may occur if deemed + necessary by the core developers. + +:mod:`ipaddress` provides the capabilities to create, manipulate and operate on IPv4 and IPv6 addresses and networks. +The functions and classes in this module make it straightforward to handle +various tasks related to IP addresses, including checking whether or not two +hosts are on the same subnet, iterating over all hosts in a particular +subnet, checking whether or not a string represents a valid IP address or +network definition, and so on. + This is the full module API reference - for an overview and introduction, see :ref:`ipaddress-howto`. -The functions and classes in this module make it straightforward to handle -various tasks related to IP addresses, including checking whether or not two -hosts are on the same subnet, iterating over all hosts in a particular -subnet, as well as checking whether or not a string represents a valid -IP address or network definition. +.. versionadded:: 3.3 Convenience factory functions @@ -65,15 +74,24 @@ :exc:`ValueError` is raised if *address* does not represent a valid IPv4 or IPv6 address. +One downside of these convenience functions is that the need to handle both +IPv4 and IPv6 formats means that error messages provide minimal +information on the precise error, as the functions don't know whether the +IPv4 or IPv6 format was intended. More detailed error reporting can be +obtained by calling the appropriate version specific class constructors +directly. + + +IP Addresses +------------ Address objects ---------------- +^^^^^^^^^^^^^^^ The :class:`IPv4Address` and :class:`IPv6Address` objects share a lot of common attributes. Some attributes that are only meaningful for IPv6 addresses are also implemented by :class:`IPv4Address` objects, in order to make it easier to -write code that handles both IP versions correctly. To avoid duplication, all -common attributes will only be documented for :class:`IPv4Address`. +write code that handles both IP versions correctly. .. class:: IPv4Address(address) @@ -84,66 +102,79 @@ 1. A string in decimal-dot notation, consisting of four decimal integers in the inclusive range 0-255, separated by dots (e.g. ``192.168.0.1``). Each - integer represents an octet (byte) in the address, big-endian. + integer represents an octet (byte) in the address. Leading zeroes are + tolerated only for values less then 8 (as there is no ambiguity + between the decimal and octal interpretations of such strings). 2. An integer that fits into 32 bits. - 3. An integer packed into a :class:`bytes` object of length 4, big-endian. + 3. An integer packed into a :class:`bytes` object of length 4 (most + significant octet first). >>> ipaddress.IPv4Address('192.168.0.1') IPv4Address('192.168.0.1') - >>> ipaddress.IPv4Address('192.0.2.1') == ipaddress.IPv4Address(3221225985) - True + >>> ipaddress.IPv4Address(3221225985) + IPv4Address('192.168.0.1') + >>> ipaddress.IPv4Address(b'\xC0\xA8\x00\x01') + IPv4Address('192.168.0.1') + .. attribute:: version + + The appropriate version number: ``4`` for IPv4, ``6`` for IPv6. + + .. attribute:: max_prefixlen + + The total number of bits in the address representation for this + version: ``32`` for IPv4, ``128`` for IPv6. + + The prefix defines the number of leading bits in an address that + are compared to determine whether or not an address is part of a + network. + + .. attribute:: compressed .. attribute:: exploded - The longhand version of the address as a string. Note: the - exploded/compressed distinction is meaningful only for IPv6 addresses. - For IPv4 addresses it is the same. + The string representation in dotted decimal notation. Leading zeroes + are never included in the representation. - .. attribute:: compressed - - The shorthand version of the address as a string. + As IPv4 does not define a shorthand notation for addresses with octets + set to zero, these two attributes are always the same as ``str(addr)`` + for IPv4 addresses. Exposing these attributes makes it easier to + write display code that can handle both IPv4 and IPv6 addresses. .. attribute:: packed - The binary representation of this address - a :class:`bytes` object. - - .. attribute:: version - - A numeric version number. - - .. attribute:: max_prefixlen - - Maximal length of the prefix (in bits). The prefix defines the number of - leading bits in an address that are compared to determine whether or not an - address is part of a network. + The binary representation of this address - a :class:`bytes` object of + the appropriate length (most significant octet first). This is 4 bytes + for IPv4 and 16 bytes for IPv6. .. attribute:: is_multicast - ``True`` if the address is reserved for multicast use. See :RFC:`3171` (for - IPv4) or :RFC:`2373` (for IPv6). + ``True`` if the address is reserved for multicast use. See + :RFC:`3171` (for IPv4) or :RFC:`2373` (for IPv6). .. attribute:: is_private - ``True`` if the address is allocated for private networks. See :RFC:`1918` - (for IPv4) or :RFC:`4193` (for IPv6). + ``True`` if the address is allocated for private networks. See + :RFC:`1918` (for IPv4) or :RFC:`4193` (for IPv6). .. attribute:: is_unspecified - ``True`` if the address is unspecified. See :RFC:`5375` (for IPv4) or - :RFC:`2373` (for IPv6). + ``True`` if the address is unspecified. See :RFC:`5375` (for IPv4) + or :RFC:`2373` (for IPv6). .. attribute:: is_reserved - ``True`` if the address is otherwise IETF reserved. + ``True`` if the address is otherwise IETF reserved. .. attribute:: is_loopback - ``True`` if this is a loopback address. See :RFC:`3330` (for IPv4) or - :RFC:`2373` (for IPv6). + ``True`` if this is a loopback address. See :RFC:`3330` (for IPv4) + or :RFC:`2373` (for IPv6). .. attribute:: is_link_local - ``True`` if the address is reserved for link-local. See :RFC:`3927`. + ``True`` if the address is reserved for link-local usage. See + :RFC:`3927`. + .. class:: IPv6Address(address) @@ -165,31 +196,79 @@ >>> ipaddress.IPv6Address('2001:db8::1000') IPv6Address('2001:db8::1000') - All the attributes exposed by :class:`IPv4Address` are supported. In - addition, the following attributs are exposed only by :class:`IPv6Address`. + All the attributes implemented by :class:`IPv4Address` are supported. In + addition, the following attributs are implemented only by + :class:`IPv6Address`. + + .. attribute:: compressed + + The short form of the address representation, with leading zeroes in + groups omitted and the longest sequence of groups consisting entirely of + zeroes collapsed to a single empty group. + + This is also the value returned by ``str(addr)`` for IPv6 addresses. + + .. attribute:: exploded + + The long form of the address representation, with all leading zeroes and + groups consisting entirely of zeroes included. + + .. attribute:: packed + .. attribute:: version + .. attribute:: max_prefixlen + .. attribute:: is_multicast + .. attribute:: is_private + .. attribute:: is_unspecified + .. attribute:: is_reserved + .. attribute:: is_loopback + .. attribute:: is_link_local + + Refer to the corresponding attribute documentation in + :class:`IPv4Address` .. attribute:: is_site_local - ``True`` if the address is reserved for site-local. Note that the site-local - address space has been deprecated by :RFC:`3879`. Use - :attr:`~IPv4Address.is_private` to test if this address is in the space of - unique local addresses as defined by :RFC:`4193`. + ``True`` if the address is reserved for site-local usage. Note that + the site-local address space has been deprecated by :RFC:`3879`. Use + :attr:`~IPv4Address.is_private` to test if this address is in the + space of unique local addresses as defined by :RFC:`4193`. .. attribute:: ipv4_mapped - If this address represents a IPv4 mapped address, return the IPv4 mapped - address. Otherwise return ``None``. + For addresses that appear to be IPv4 mapped addresses (starting with + ``::FFFF/96``), this property will report the embedded IPv4 address. + For any other address, this property will be ``None``. + + .. attribute:: sixtofour + + For addresses that appear to be 6to4 addresses (starting with + ``2002::/16``) as defined by :RFC:`3056`, this property will report + the embedded IPv4 address. For any other address, this property will + be ``None``. .. attribute:: teredo - If this address appears to be a teredo address (starts with ``2001::/32``), - return a tuple of embedded teredo IPs ``(server, client)`` pairs. Otherwise - return ``None``. + For addresses that appear to be Teredo addresses (starting with + ``2001::/32``) as defined by :RFC:`4380`, this property will report + the embedded ``(server, client)`` IP address pair. For any other + address, this property will be ``None``. - .. attribute:: sixtofour - If this address appears to contain a 6to4 embedded address, return the - embedded IPv4 address. Otherwise return ``None``. +Conversion to Strings and Integers +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +To interoperate with networking interfaces such as the socket module, +addresses must be converted to strings or integers. This is handled using +the :func:`str` and :func:`int` builtin functions:: + + >>> str(ipaddress.IPv4Address('192.168.0.1')) + '192.168.0.1' + >>> int(ipaddress.IPv4Address('192.168.0.1')) + 3232235521 + >>> str(ipaddress.IPv6Address('::1')) + '::1' + >>> int(ipaddress.IPv6Address('::1')) + 1 Operators @@ -199,6 +278,7 @@ only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with IPv6). + Logical operators """"""""""""""""" @@ -212,6 +292,7 @@ >>> IPv4Address('127.0.0.2') != IPv4Address('127.0.0.1') True + Arithmetic operators """""""""""""""""""" @@ -227,45 +308,274 @@ ipaddress.AddressValueError: 4294967296 (>= 2**32) is not permitted as an IPv4 address +IP Network definitions +---------------------- + +The :class:`IPv4Network` and :class:`IPv6Network` objects provide a mechanism +for defining and inspecting IP network definitions. A network definition +consists of a *mask* and a *network address*, and as such defines a range of +IP addresses that equal the network address when masked (binary AND) with the +mask. For example, a network definition with the mask ``255.255.255.0`` and +the network address ``192.168.1.0`` consists of IP addresses in the inclusive +range ``192.168.1.0`` to ``192.168.1.255``. + + +Prefix, net mask and host mask +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +There are several equivalent ways to specify IP network masks. A *prefix* +``/`` is a notation that denotes how many high-order bits are set in +the network mask. A *net mask* is an IP address with some number of +high-order bits set. Thus the prefix ``/24`` is equivalent to the net mask +``255.255.255.0`` in IPv4, or ``ffff:ff00::`` in IPv6. In addition, a +*host mask* is the logical inverse of a *net mask*, and is sometimes used +(for example in Cisco access control lists) to denote a network mask. The +host mask equivalent to ``/24`` in IPv4 is ``0.0.0.255``. + + Network objects ---------------- +^^^^^^^^^^^^^^^ + +All attributes implemented by address objects are implemented by network +objects as well. In addition, network objects implement additional attributes. +All of these are common between :class:`IPv4Network` and :class:`IPv6Network`, +so to avoid duplication they are only documented for :class:`IPv4Network`. .. class:: IPv4Network(address, strict=True) - Construct an IPv4 network. *address* is a string or integer representing the - IP address (and optionally the network). An :exc:`AddressValueError` is - raised if *address* is not a valid IPv4 address. A :exc:`NetmaskValueError` - is raised if the netmask is not valid for an IPv4 address. + Construct an IPv4 network definition. *address* can be one of the following: + + 1. A string consisting of an IP address and an optional mask, separated by + a slash (``/``). The IP address is the network address, and the mask + can be either a single number, which means it's a *prefix*, or a string + representation of an IPv4 address. If it's the latter, the mask is + interpreted as a *net mask* if it starts with a non-zero field, or as + a *host mask* if it starts with a zero field. If no mask is provided, + it's considered to be ``/32``. + + For example, the following *address* specifications are equivalent: + ``192.168.1.0/24``, ``192.168.1.0/255.255.255.0`` and + ``192.168.1.0/0.0.0.255``. + + 2. An integer that fits into 32 bits. This is equivalent to a + single-address network, with the network address being *address* and + the mask being ``/32``. + + 3. An integer packed into a :class:`bytes` object of length 4, big-endian. + The interpretation is similar to an integer *address*. + + An :exc:`AddressValueError` is raised if *address* is not a valid IPv4 + address. A :exc:`NetmaskValueError` is raised if the mask is not valid for + an IPv4 address. If *strict* is ``True`` and host bits are set in the supplied address, - then :exc:`ValueError` is raised. Otherwise, the host bits are masked out + then :exc:`ValueError` is raised. Otherwise, the host bits are masked out to determine the appropriate network address. - >>> ipaddress.IPv4Network('192.0.2.0/27') - IPv4Network('192.0.2.0/27') - >>> ipaddress.IPv4Network('192.0.2.0/27').netmask - IPv4Address('255.255.255.224') - >>> ipaddress.IPv4Network('192.0.2.5/27', strict=False) - IPv4Network('192.0.2.0/27') + This class implements all the attributes of :class:`IPv4Address`, and also + the following attributes and methods. Unless stated otherwise, all methods + accepting other network / address objects will raise :exc:`TypeError` if + the argument's IP version is incompatible to ``self``: + + .. attribute:: broadcast_address + + The broadcast address for the network. + + .. attribute:: host mask + + The host mask, as a string. + + .. attribute:: with_prefixlen + + A string representation of the network, with the mask in prefix notation. + + .. attribute:: with_netmask + + A string representation of the network, with the mask in net mask notation. + + .. attribute:: with_hostmask + + A string representation of the network, with the mask in host mask notation. + + .. attribute:: num_addresses + + The total number of addresses in the network. + + .. attribute:: prefixlen + + Length of the prefix, in bits. + + .. method:: hosts() + + Generates an iterator over the usable hosts in the network. The usable hosts + are all the IP addresses that belong to the network, except the network + address itself and the network broadcast address. + + >>> list(ip_network('192.0.2.0/29').hosts()) + [IPv4Address('192.0.2.1'), IPv4Address('192.0.2.2'), + IPv4Address('192.0.2.3'), IPv4Address('192.0.2.4'), + IPv4Address('192.0.2.5'), IPv4Address('192.0.2.6')] + + .. method:: overlaps(other) + + ``True`` if this network is partly contained in *other*. + + .. method:: address_exclude(network) + + Computes the network defintions resulting from removing the given *network* + from this one. Returns a generator. Raises :exc:`ValueError` if *network* + is not completely contained in this network. + + >>> n1 = ip_network('192.0.2.0/28') + >>> n2 = ip_network('192.0.2.1/32') + >>> list(n1.address_exclude(n2)) + [IPv4Network('192.0.2.8/29'), IPv4Network('192.0.2.4/30'), + IPv4Network('192.0.2.2/31'), IPv4Network('192.0.2.0/32')] + + .. method:: subnets(prefixlen_diff=1, new_prefix=None) + + The subnets that join to make the current network definition, depending on + the argument values. *prefixlen_diff* is the amount our prefix length + should be increased by. *new_prefix* is the desired new prefix of the + subnets; it must be larger than our prefix. One and only one of + *prefixlen_diff* and *new_prefix* must be set. Returns an iterator of + network objects. + + >>> list(ip_network('192.0.2.0/24').subnets()) + [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] + >>> list(ip_network('192.0.2.0/24').subnets(prefixlen_diff=2)) + [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), + IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=26)) + [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), + IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=23)) + Traceback (most recent call last): + File "", line 1, in + raise ValueError('new prefix must be longer') + ValueError: new prefix must be longer + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=25)) + [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] + >>> + + .. method:: supernet(prefixlen_diff=1, new_prefix=None) + + The supernet containing this network definition, depending on the argument + values. *prefixlen_diff* is the amount our prefix length should be + decreased by. *new_prefix* is the desired new prefix of the supernet; it + must be smaller than our prefix. One and only one of *prefixlen_diff* and + *new_prefix* must be set. Returns a single network object. + + >>> ip_network('192.0.2.0/24').supernet() + IPv4Network('192.0.2.0/23') + >>> ip_network('192.0.2.0/24').supernet(prefixlen_diff=2) + IPv4Network('192.0.0.0/22') + >>> ip_network('192.0.2.0/24').supernet(new_prefix=20) + IPv4Network('192.0.0.0/20') + + .. method:: compare_networks(other) + + Compare this network to *other*. In this comparison only the network + addresses are considered; host bits aren't. Returns either ``-1``, ``0`` + or ``1``. + + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.2/32')) + -1 + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.0/32')) + 1 + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.1/32')) + 0 .. class:: IPv6Network(address, strict=True) - Construct an IPv6 network. *address* is a string or integer representing the - IP address (and optionally the network). An :exc:`AddressValueError` is - raised if *address* is not a valid IPv6 address. A :exc:`NetmaskValueError` - is raised if the netmask is not valid for an IPv6 address. + Construct an IPv6 network definition. *address* can be one of the following: + + 1. A string consisting of an IP address and an optional mask, separated by + a slash (``/``). The IP addrses is the network address, and the mask + can be either a single number, which means it's a *prefix*, or a string + representation of an IPv6 address. If it's the latter, the mask is + interpreted as a *net mask*. If no mask is provided, it's considered to + be ``/128``. + + For example, the following *address* specifications are equivalent: + ``2001:db00::0/24`` and ``2001:db00::0/ffff:ff00::``. + + 2. An integer that fits into 128 bits. This is equivalent to a + single-address network, with the network address being *address* and + the mask being ``/128``. + + 3. An integer packed into a :class:`bytes` object of length 16, bit-endian. + The interpretation is similar to an integer *address*. + + An :exc:`AddressValueError` is raised if *address* is not a valid IPv6 + address. A :exc:`NetmaskValueError` is raised if the mask is not valid for + an IPv6 address. If *strict* is ``True`` and host bits are set in the supplied address, - then :exc:`ValueError` is raised. Otherwise, the host bits are masked out + then :exc:`ValueError` is raised. Otherwise, the host bits are masked out to determine the appropriate network address. - >>> ipaddress.IPv6Network('2001:db8::/96') - IPv6Network('2001:db8::/96') - >>> ipaddress.IPv6Network('2001:db8::/96').netmask - IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') - >>> ipaddress.IPv6Network('2001:db8::1000/96', strict=False) - IPv6Network('2001:db8::/96') + .. describe:: Attributes and methods + + All attributes and methods implemented by :class:`IPv4Network` and by + :class:`IPv6Address` are also implemented by :class:`IPv6Network`. + + +Operators +^^^^^^^^^ + +Network objects support some operators. Unless stated otherwise, operators can +only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with +IPv6). + +Logical operators +""""""""""""""""" + +Network objects can be compared with the usual set of logical operators, +similarly to address objects. + +Iteration +""""""""" + +Network objects can be iterated to list all the addresses belonging to the +network. For iteration, *all* hosts are returned, including unusable hosts +(for usable hosts, use the :meth:`~IPv4Network.hosts` method). An +example:: + + >>> for addr in IPv4Network('192.0.2.0/28'): + ... addr + ... + IPv4Address('192.0.2.0') + IPv4Address('192.0.2.1') + IPv4Address('192.0.2.2') + IPv4Address('192.0.2.3') + IPv4Address('192.0.2.4') + IPv4Address('192.0.2.5') + IPv4Address('192.0.2.6') + IPv4Address('192.0.2.7') + IPv4Address('192.0.2.8') + IPv4Address('192.0.2.9') + IPv4Address('192.0.2.10') + IPv4Address('192.0.2.11') + IPv4Address('192.0.2.12') + IPv4Address('192.0.2.13') + IPv4Address('192.0.2.14') + IPv4Address('192.0.2.15') + +Networks as containers of addresses +""""""""""""""""""""""""""""""""""" + +Network objects can act as containers of addresses. Some examples:: + + >>> IPv4Network('192.0.2.0/28')[0] + IPv4Address('192.0.2.0') + >>> IPv4Network('192.0.2.0/28')[15] + IPv4Address('192.0.2.15') + >>> IPv4Address('192.0.2.6') in IPv4Network('192.0.2.0/28') + True + >>> IPv4Address('192.0.3.6') in IPv4Network('192.0.2.0/28') + False Interface objects diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -497,6 +497,7 @@ prefixlen = self._prefixlen return self._string_from_ip_int(self._ip_int_from_prefix(prefixlen)) + class _BaseAddress(_IPAddressBase): """A generic IP object. @@ -568,9 +569,6 @@ def __init__(self, address): self._cache = {} - def __int__(self): - return int(self.network_address) - def __repr__(self): return '%s(%r)' % (self.__class__.__name__, str(self)) @@ -937,6 +935,76 @@ strict=False) return t.__class__('%s/%d' % (t.network_address, t.prefixlen)) + @property + def is_multicast(self): + """Test if the address is reserved for multicast use. + + Returns: + A boolean, True if the address is a multicast address. + See RFC 2373 2.7 for details. + + """ + return (self.network_address.is_multicast and + self.broadcast_address.is_multicast) + + @property + def is_reserved(self): + """Test if the address is otherwise IETF reserved. + + Returns: + A boolean, True if the address is within one of the + reserved IPv6 Network ranges. + + """ + return (self.network_address.is_reserved and + self.broadcast_address.is_reserved) + + @property + def is_link_local(self): + """Test if the address is reserved for link-local. + + Returns: + A boolean, True if the address is reserved per RFC 4291. + + """ + return (self.network_address.is_link_local and + self.broadcast_address.is_link_local) + + @property + def is_private(self): + """Test if this address is allocated for private networks. + + Returns: + A boolean, True if the address is reserved per RFC 4193. + + """ + return (self.network_address.is_private and + self.broadcast_address.is_private) + + @property + def is_unspecified(self): + """Test if the address is unspecified. + + Returns: + A boolean, True if this is the unspecified address as defined in + RFC 2373 2.5.2. + + """ + return (self.network_address.is_unspecified and + self.broadcast_address.is_unspecified) + + @property + def is_loopback(self): + """Test if the address is a loopback address. + + Returns: + A boolean, True if the address is a loopback address as defined in + RFC 2373 2.5.3. + + """ + return (self.network_address.is_loopback and + self.broadcast_address.is_loopback) + class _BaseV4: @@ -1094,102 +1162,6 @@ def version(self): return self._version - @property - def is_reserved(self): - """Test if the address is otherwise IETF reserved. - - Returns: - A boolean, True if the address is within the - reserved IPv4 Network range. - - """ - reserved_network = IPv4Network('240.0.0.0/4') - if isinstance(self, _BaseAddress): - return self in reserved_network - return (self.network_address in reserved_network and - self.broadcast_address in reserved_network) - - @property - def is_private(self): - """Test if this address is allocated for private networks. - - Returns: - A boolean, True if the address is reserved per RFC 1918. - - """ - private_10 = IPv4Network('10.0.0.0/8') - private_172 = IPv4Network('172.16.0.0/12') - private_192 = IPv4Network('192.168.0.0/16') - if isinstance(self, _BaseAddress): - return (self in private_10 or self in private_172 or - self in private_192) - else: - return ((self.network_address in private_10 and - self.broadcast_address in private_10) or - (self.network_address in private_172 and - self.broadcast_address in private_172) or - (self.network_address in private_192 and - self.broadcast_address in private_192)) - - @property - def is_multicast(self): - """Test if the address is reserved for multicast use. - - Returns: - A boolean, True if the address is multicast. - See RFC 3171 for details. - - """ - multicast_network = IPv4Network('224.0.0.0/4') - if isinstance(self, _BaseAddress): - return self in IPv4Network('224.0.0.0/4') - return (self.network_address in multicast_network and - self.broadcast_address in multicast_network) - - @property - def is_unspecified(self): - """Test if the address is unspecified. - - Returns: - A boolean, True if this is the unspecified address as defined in - RFC 5735 3. - - """ - unspecified_address = IPv4Address('0.0.0.0') - if isinstance(self, _BaseAddress): - return self == unspecified_address - return (self.network_address == self.broadcast_address == - unspecified_address) - - @property - def is_loopback(self): - """Test if the address is a loopback address. - - Returns: - A boolean, True if the address is a loopback per RFC 3330. - - """ - loopback_address = IPv4Network('127.0.0.0/8') - if isinstance(self, _BaseAddress): - return self in loopback_address - - return (self.network_address in loopback_address and - self.broadcast_address in loopback_address) - - @property - def is_link_local(self): - """Test if the address is reserved for link-local. - - Returns: - A boolean, True if the address is link-local per RFC 3927. - - """ - linklocal_network = IPv4Network('169.254.0.0/16') - if isinstance(self, _BaseAddress): - return self in linklocal_network - return (self.network_address in linklocal_network and - self.broadcast_address in linklocal_network) - class IPv4Address(_BaseV4, _BaseAddress): @@ -1236,6 +1208,79 @@ """The binary representation of this address.""" return v4_int_to_packed(self._ip) + @property + def is_reserved(self): + """Test if the address is otherwise IETF reserved. + + Returns: + A boolean, True if the address is within the + reserved IPv4 Network range. + + """ + reserved_network = IPv4Network('240.0.0.0/4') + return self in reserved_network + + @property + def is_private(self): + """Test if this address is allocated for private networks. + + Returns: + A boolean, True if the address is reserved per RFC 1918. + + """ + private_10 = IPv4Network('10.0.0.0/8') + private_172 = IPv4Network('172.16.0.0/12') + private_192 = IPv4Network('192.168.0.0/16') + return (self in private_10 or + self in private_172 or + self in private_192) + + @property + def is_multicast(self): + """Test if the address is reserved for multicast use. + + Returns: + A boolean, True if the address is multicast. + See RFC 3171 for details. + + """ + multicast_network = IPv4Network('224.0.0.0/4') + return self in multicast_network + + @property + def is_unspecified(self): + """Test if the address is unspecified. + + Returns: + A boolean, True if this is the unspecified address as defined in + RFC 5735 3. + + """ + unspecified_address = IPv4Address('0.0.0.0') + return self == unspecified_address + + @property + def is_loopback(self): + """Test if the address is a loopback address. + + Returns: + A boolean, True if the address is a loopback per RFC 3330. + + """ + loopback_network = IPv4Network('127.0.0.0/8') + return self in loopback_network + + @property + def is_link_local(self): + """Test if the address is reserved for link-local. + + Returns: + A boolean, True if the address is link-local per RFC 3927. + + """ + linklocal_network = IPv4Network('169.254.0.0/16') + return self in linklocal_network + class IPv4Interface(IPv4Address): @@ -1674,162 +1719,6 @@ def version(self): return self._version - @property - def is_multicast(self): - """Test if the address is reserved for multicast use. - - Returns: - A boolean, True if the address is a multicast address. - See RFC 2373 2.7 for details. - - """ - multicast_network = IPv6Network('ff00::/8') - if isinstance(self, _BaseAddress): - return self in multicast_network - return (self.network_address in multicast_network and - self.broadcast_address in multicast_network) - - @property - def is_reserved(self): - """Test if the address is otherwise IETF reserved. - - Returns: - A boolean, True if the address is within one of the - reserved IPv6 Network ranges. - - """ - reserved_networks = [IPv6Network('::/8'), IPv6Network('100::/8'), - IPv6Network('200::/7'), IPv6Network('400::/6'), - IPv6Network('800::/5'), IPv6Network('1000::/4'), - IPv6Network('4000::/3'), IPv6Network('6000::/3'), - IPv6Network('8000::/3'), IPv6Network('A000::/3'), - IPv6Network('C000::/3'), IPv6Network('E000::/4'), - IPv6Network('F000::/5'), IPv6Network('F800::/6'), - IPv6Network('FE00::/9')] - - if isinstance(self, _BaseAddress): - return any(self in x for x in reserved_networks) - return any(self.network_address in x and self.broadcast_address in x - for x in reserved_networks) - - @property - def is_link_local(self): - """Test if the address is reserved for link-local. - - Returns: - A boolean, True if the address is reserved per RFC 4291. - - """ - linklocal_network = IPv6Network('fe80::/10') - if isinstance(self, _BaseAddress): - return self in linklocal_network - return (self.network_address in linklocal_network and - self.broadcast_address in linklocal_network) - - @property - def is_site_local(self): - """Test if the address is reserved for site-local. - - Note that the site-local address space has been deprecated by RFC 3879. - Use is_private to test if this address is in the space of unique local - addresses as defined by RFC 4193. - - Returns: - A boolean, True if the address is reserved per RFC 3513 2.5.6. - - """ - sitelocal_network = IPv6Network('fec0::/10') - if isinstance(self, _BaseAddress): - return self in sitelocal_network - return (self.network_address in sitelocal_network and - self.broadcast_address in sitelocal_network) - - @property - def is_private(self): - """Test if this address is allocated for private networks. - - Returns: - A boolean, True if the address is reserved per RFC 4193. - - """ - private_network = IPv6Network('fc00::/7') - if isinstance(self, _BaseAddress): - return self in private_network - return (self.network_address in private_network and - self.broadcast_address in private_network) - - @property - def ipv4_mapped(self): - """Return the IPv4 mapped address. - - Returns: - If the IPv6 address is a v4 mapped address, return the - IPv4 mapped address. Return None otherwise. - - """ - if (self._ip >> 32) != 0xFFFF: - return None - return IPv4Address(self._ip & 0xFFFFFFFF) - - @property - def teredo(self): - """Tuple of embedded teredo IPs. - - Returns: - Tuple of the (server, client) IPs or None if the address - doesn't appear to be a teredo address (doesn't start with - 2001::/32) - - """ - if (self._ip >> 96) != 0x20010000: - return None - return (IPv4Address((self._ip >> 64) & 0xFFFFFFFF), - IPv4Address(~self._ip & 0xFFFFFFFF)) - - @property - def sixtofour(self): - """Return the IPv4 6to4 embedded address. - - Returns: - The IPv4 6to4-embedded address if present or None if the - address doesn't appear to contain a 6to4 embedded address. - - """ - if (self._ip >> 112) != 0x2002: - return None - return IPv4Address((self._ip >> 80) & 0xFFFFFFFF) - - @property - def is_unspecified(self): - """Test if the address is unspecified. - - Returns: - A boolean, True if this is the unspecified address as defined in - RFC 2373 2.5.2. - - """ - if isinstance(self, (IPv6Network, IPv6Interface)): - return int(self.network_address) == 0 and getattr( - self, '_prefixlen', 128) == 128 - return self._ip == 0 - - @property - def is_loopback(self): - """Test if the address is a loopback address. - - Returns: - A boolean, True if the address is a loopback address as defined in - RFC 2373 2.5.3. - - """ - if isinstance(self, IPv6Network): - return int(self) == 1 and getattr( - self, '_prefixlen', 128) == 128 - elif isinstance(self, IPv6Interface): - return int(self.network.network_address) == 1 and getattr( - self, '_prefixlen', 128) == 128 - return self._ip == 1 - class IPv6Address(_BaseV6, _BaseAddress): @@ -1878,6 +1767,138 @@ """The binary representation of this address.""" return v6_int_to_packed(self._ip) + @property + def is_multicast(self): + """Test if the address is reserved for multicast use. + + Returns: + A boolean, True if the address is a multicast address. + See RFC 2373 2.7 for details. + + """ + multicast_network = IPv6Network('ff00::/8') + return self in multicast_network + + @property + def is_reserved(self): + """Test if the address is otherwise IETF reserved. + + Returns: + A boolean, True if the address is within one of the + reserved IPv6 Network ranges. + + """ + reserved_networks = [IPv6Network('::/8'), IPv6Network('100::/8'), + IPv6Network('200::/7'), IPv6Network('400::/6'), + IPv6Network('800::/5'), IPv6Network('1000::/4'), + IPv6Network('4000::/3'), IPv6Network('6000::/3'), + IPv6Network('8000::/3'), IPv6Network('A000::/3'), + IPv6Network('C000::/3'), IPv6Network('E000::/4'), + IPv6Network('F000::/5'), IPv6Network('F800::/6'), + IPv6Network('FE00::/9')] + + return any(self in x for x in reserved_networks) + + @property + def is_link_local(self): + """Test if the address is reserved for link-local. + + Returns: + A boolean, True if the address is reserved per RFC 4291. + + """ + linklocal_network = IPv6Network('fe80::/10') + return self in linklocal_network + + @property + def is_site_local(self): + """Test if the address is reserved for site-local. + + Note that the site-local address space has been deprecated by RFC 3879. + Use is_private to test if this address is in the space of unique local + addresses as defined by RFC 4193. + + Returns: + A boolean, True if the address is reserved per RFC 3513 2.5.6. + + """ + sitelocal_network = IPv6Network('fec0::/10') + return self in sitelocal_network + + @property + def is_private(self): + """Test if this address is allocated for private networks. + + Returns: + A boolean, True if the address is reserved per RFC 4193. + + """ + private_network = IPv6Network('fc00::/7') + return self in private_network + + @property + def is_unspecified(self): + """Test if the address is unspecified. + + Returns: + A boolean, True if this is the unspecified address as defined in + RFC 2373 2.5.2. + + """ + return self._ip == 0 + + @property + def is_loopback(self): + """Test if the address is a loopback address. + + Returns: + A boolean, True if the address is a loopback address as defined in + RFC 2373 2.5.3. + + """ + return self._ip == 1 + + @property + def ipv4_mapped(self): + """Return the IPv4 mapped address. + + Returns: + If the IPv6 address is a v4 mapped address, return the + IPv4 mapped address. Return None otherwise. + + """ + if (self._ip >> 32) != 0xFFFF: + return None + return IPv4Address(self._ip & 0xFFFFFFFF) + + @property + def teredo(self): + """Tuple of embedded teredo IPs. + + Returns: + Tuple of the (server, client) IPs or None if the address + doesn't appear to be a teredo address (doesn't start with + 2001::/32) + + """ + if (self._ip >> 96) != 0x20010000: + return None + return (IPv4Address((self._ip >> 64) & 0xFFFFFFFF), + IPv4Address(~self._ip & 0xFFFFFFFF)) + + @property + def sixtofour(self): + """Return the IPv4 6to4 embedded address. + + Returns: + The IPv4 6to4-embedded address if present or None if the + address doesn't appear to contain a 6to4 embedded address. + + """ + if (self._ip >> 112) != 0x2002: + return None + return IPv4Address((self._ip >> 80) & 0xFFFFFFFF) + class IPv6Interface(IPv6Address): @@ -1946,6 +1967,14 @@ return '%s/%s' % (self._string_from_ip_int(self._ip), self.hostmask) + @property + def is_unspecified(self): + return self._ip == 0 and self.network.is_unspecified + + @property + def is_loopback(self): + return self._ip == 1 and self.network.is_loopback + class IPv6Network(_BaseV6, _BaseNetwork): @@ -2054,3 +2083,18 @@ except ValueError: return False return 0 <= prefixlen <= self._max_prefixlen + + @property + def is_site_local(self): + """Test if the address is reserved for site-local. + + Note that the site-local address space has been deprecated by RFC 3879. + Use is_private to test if this address is in the space of unique local + addresses as defined by RFC 4193. + + Returns: + A boolean, True if the address is reserved per RFC 3513 2.5.6. + + """ + return (self.network_address.is_site_local and + self.broadcast_address.is_site_local) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -647,8 +647,8 @@ ipv4 = ipaddress.ip_network('1.2.3.4') ipv6 = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1') - self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4))) - self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6))) + self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4.network_address))) + self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6.network_address))) v6_int = 42540616829182469433547762482097946625 self.assertEqual(self.ipv6_interface._ip, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:32:48 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 14:32:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2314814=3A_Finish_r?= =?utf-8?q?eview_of_ipaddress_network_object_docs_=28initial_patch_was?= Message-ID: <3WqhGS5QgpzPlp@mail.python.org> http://hg.python.org/cpython/rev/cf8d42596a44 changeset: 78429:cf8d42596a44 user: Nick Coghlan date: Sun Aug 05 22:32:37 2012 +1000 summary: Issue #14814: Finish review of ipaddress network object docs (initial patch was by Eli Bendersky) files: Doc/library/ipaddress.rst | 211 ++++++++++++++++--------- 1 files changed, 134 insertions(+), 77 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -196,10 +196,6 @@ >>> ipaddress.IPv6Address('2001:db8::1000') IPv6Address('2001:db8::1000') - All the attributes implemented by :class:`IPv4Address` are supported. In - addition, the following attributs are implemented only by - :class:`IPv6Address`. - .. attribute:: compressed The short form of the address representation, with leading zeroes in @@ -372,119 +368,149 @@ then :exc:`ValueError` is raised. Otherwise, the host bits are masked out to determine the appropriate network address. - This class implements all the attributes of :class:`IPv4Address`, and also - the following attributes and methods. Unless stated otherwise, all methods - accepting other network / address objects will raise :exc:`TypeError` if - the argument's IP version is incompatible to ``self``: + Unless stated otherwise, all network methods accepting other network/address + objects will raise :exc:`TypeError` if the argument's IP version is + incompatible to ``self`` + + .. attribute:: version + .. attribute:: max_prefixlen + + Refer to the corresponding attribute documentation in + :class:`IPv4Address` + + .. attribute:: is_multicast + .. attribute:: is_private + .. attribute:: is_unspecified + .. attribute:: is_reserved + .. attribute:: is_loopback + .. attribute:: is_link_local + + These attributes are true for the network as a whole if they are true + true for both the network address and the broadcast address + + .. attribute:: network_address + + The broadcast address for the network. .. attribute:: broadcast_address - The broadcast address for the network. + The broadcast address for the network. .. attribute:: host mask - The host mask, as a string. + The host mask, as a string. .. attribute:: with_prefixlen + .. attribute:: compressed + .. attribute:: exploded - A string representation of the network, with the mask in prefix notation. + A string representation of the network, with the mask in prefix + notation. + + ``with_prefixlen`` and ``compressed`` are always the same as + ``str(network)``. + ``exploded`` uses the exploded form the network address. .. attribute:: with_netmask - A string representation of the network, with the mask in net mask notation. + A string representation of the network, with the mask in net mask + notation. .. attribute:: with_hostmask - A string representation of the network, with the mask in host mask notation. + A string representation of the network, with the mask in host mask + notation. .. attribute:: num_addresses - The total number of addresses in the network. + The total number of addresses in the network. .. attribute:: prefixlen - Length of the prefix, in bits. + Length of the network prefix, in bits. .. method:: hosts() - Generates an iterator over the usable hosts in the network. The usable hosts - are all the IP addresses that belong to the network, except the network - address itself and the network broadcast address. + Returns an iterator over the usable hosts in the network. The usable + hosts are all the IP addresses that belong to the network, except the + network address itself and the network broadcast address. - >>> list(ip_network('192.0.2.0/29').hosts()) - [IPv4Address('192.0.2.1'), IPv4Address('192.0.2.2'), - IPv4Address('192.0.2.3'), IPv4Address('192.0.2.4'), - IPv4Address('192.0.2.5'), IPv4Address('192.0.2.6')] + >>> list(ip_network('192.0.2.0/29').hosts()) + [IPv4Address('192.0.2.1'), IPv4Address('192.0.2.2'), + IPv4Address('192.0.2.3'), IPv4Address('192.0.2.4'), + IPv4Address('192.0.2.5'), IPv4Address('192.0.2.6')] .. method:: overlaps(other) - ``True`` if this network is partly contained in *other*. + ``True`` if this network is partly or wholly contained in *other* or + or *other* is wholly contained in this network. .. method:: address_exclude(network) - Computes the network defintions resulting from removing the given *network* - from this one. Returns a generator. Raises :exc:`ValueError` if *network* - is not completely contained in this network. + Computes the network definitions resulting from removing the given + *network* from this one. Returns an iterator of network objects. + Raises :exc:`ValueError` if *network* is not completely contained in + this network. - >>> n1 = ip_network('192.0.2.0/28') - >>> n2 = ip_network('192.0.2.1/32') - >>> list(n1.address_exclude(n2)) - [IPv4Network('192.0.2.8/29'), IPv4Network('192.0.2.4/30'), - IPv4Network('192.0.2.2/31'), IPv4Network('192.0.2.0/32')] + >>> n1 = ip_network('192.0.2.0/28') + >>> n2 = ip_network('192.0.2.1/32') + >>> list(n1.address_exclude(n2)) + [IPv4Network('192.0.2.8/29'), IPv4Network('192.0.2.4/30'), + IPv4Network('192.0.2.2/31'), IPv4Network('192.0.2.0/32')] .. method:: subnets(prefixlen_diff=1, new_prefix=None) - The subnets that join to make the current network definition, depending on - the argument values. *prefixlen_diff* is the amount our prefix length - should be increased by. *new_prefix* is the desired new prefix of the - subnets; it must be larger than our prefix. One and only one of - *prefixlen_diff* and *new_prefix* must be set. Returns an iterator of - network objects. + The subnets that join to make the current network definition, depending + on the argument values. *prefixlen_diff* is the amount our prefix + length should be increased by. *new_prefix* is the desired new + prefix of the subnets; it must be larger than our prefix. One and + only one of *prefixlen_diff* and *new_prefix* must be set. Returns an + iterator of network objects. - >>> list(ip_network('192.0.2.0/24').subnets()) - [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] - >>> list(ip_network('192.0.2.0/24').subnets(prefixlen_diff=2)) - [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), - IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] - >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=26)) - [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), - IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] - >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=23)) - Traceback (most recent call last): - File "", line 1, in - raise ValueError('new prefix must be longer') - ValueError: new prefix must be longer - >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=25)) - [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] - >>> + >>> list(ip_network('192.0.2.0/24').subnets()) + [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] + >>> list(ip_network('192.0.2.0/24').subnets(prefixlen_diff=2)) + [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), + IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=26)) + [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), + IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=23)) + Traceback (most recent call last): + File "", line 1, in + raise ValueError('new prefix must be longer') + ValueError: new prefix must be longer + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=25)) + [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] .. method:: supernet(prefixlen_diff=1, new_prefix=None) - The supernet containing this network definition, depending on the argument - values. *prefixlen_diff* is the amount our prefix length should be - decreased by. *new_prefix* is the desired new prefix of the supernet; it - must be smaller than our prefix. One and only one of *prefixlen_diff* and - *new_prefix* must be set. Returns a single network object. + The supernet containing this network definition, depending on the + argument values. *prefixlen_diff* is the amount our prefix length + should be decreased by. *new_prefix* is the desired new prefix of + the supernet; it must be smaller than our prefix. One and only one + of *prefixlen_diff* and *new_prefix* must be set. Returns a single + network object. - >>> ip_network('192.0.2.0/24').supernet() - IPv4Network('192.0.2.0/23') - >>> ip_network('192.0.2.0/24').supernet(prefixlen_diff=2) - IPv4Network('192.0.0.0/22') - >>> ip_network('192.0.2.0/24').supernet(new_prefix=20) - IPv4Network('192.0.0.0/20') + >>> ip_network('192.0.2.0/24').supernet() + IPv4Network('192.0.2.0/23') + >>> ip_network('192.0.2.0/24').supernet(prefixlen_diff=2) + IPv4Network('192.0.0.0/22') + >>> ip_network('192.0.2.0/24').supernet(new_prefix=20) + IPv4Network('192.0.0.0/20') .. method:: compare_networks(other) - Compare this network to *other*. In this comparison only the network - addresses are considered; host bits aren't. Returns either ``-1``, ``0`` - or ``1``. + Compare this network to *other*. In this comparison only the network + addresses are considered; host bits aren't. Returns either ``-1``, + ``0`` or ``1``. - >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.2/32')) - -1 - >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.0/32')) - 1 - >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.1/32')) - 0 + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.2/32')) + -1 + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.0/32')) + 1 + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.1/32')) + 0 .. class:: IPv6Network(address, strict=True) @@ -492,7 +518,7 @@ Construct an IPv6 network definition. *address* can be one of the following: 1. A string consisting of an IP address and an optional mask, separated by - a slash (``/``). The IP addrses is the network address, and the mask + a slash (``/``). The IP address is the network address, and the mask can be either a single number, which means it's a *prefix*, or a string representation of an IPv6 address. If it's the latter, the mask is interpreted as a *net mask*. If no mask is provided, it's considered to @@ -516,10 +542,38 @@ then :exc:`ValueError` is raised. Otherwise, the host bits are masked out to determine the appropriate network address. - .. describe:: Attributes and methods + .. attribute:: version + .. attribute:: max_prefixlen + .. attribute:: is_multicast + .. attribute:: is_private + .. attribute:: is_unspecified + .. attribute:: is_reserved + .. attribute:: is_loopback + .. attribute:: is_link_local + .. attribute:: network_address + .. attribute:: broadcast_address + .. attribute:: host mask + .. attribute:: with_prefixlen + .. attribute:: compressed + .. attribute:: exploded + .. attribute:: with_netmask + .. attribute:: with_hostmask + .. attribute:: num_addresses + .. attribute:: prefixlen + .. method:: hosts() + .. method:: overlaps(other) + .. method:: address_exclude(network) + .. method:: subnets(prefixlen_diff=1, new_prefix=None) + .. method:: supernet(prefixlen_diff=1, new_prefix=None) + .. method:: compare_networks(other) - All attributes and methods implemented by :class:`IPv4Network` and by - :class:`IPv6Address` are also implemented by :class:`IPv6Network`. + Refer to the corresponding attribute documentation in + :class:`IPv4Network` + + .. attribute:: is_site_local + + These attribute is true for the network as a whole if it is true + true for both the network address and the broadcast address Operators @@ -529,12 +583,14 @@ only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with IPv6). + Logical operators """"""""""""""""" Network objects can be compared with the usual set of logical operators, similarly to address objects. + Iteration """"""""" @@ -563,6 +619,7 @@ IPv4Address('192.0.2.14') IPv4Address('192.0.2.15') + Networks as containers of addresses """"""""""""""""""""""""""""""""""" -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:45:33 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 14:45:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2314814=3A_Remove_r?= =?utf-8?q?edundant_property_from_interface_objects_-_prefixlen_can?= Message-ID: <3WqhY9373MzPkS@mail.python.org> http://hg.python.org/cpython/rev/cf9526db1a7e changeset: 78430:cf9526db1a7e user: Nick Coghlan date: Sun Aug 05 22:45:22 2012 +1000 summary: Issue #14814: Remove redundant property from interface objects - prefixlen can be accessed via the associated network object files: Lib/ipaddress.py | 10 +--------- Lib/test/test_ipaddress.py | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1331,10 +1331,6 @@ return self._ip ^ self._prefixlen ^ int(self.network.network_address) @property - def prefixlen(self): - return self._prefixlen - - @property def ip(self): return IPv4Address(self._ip) @@ -1708,7 +1704,7 @@ hex_str = '%032x' % ip_int parts = [hex_str[x:x+4] for x in range(0, 32, 4)] if isinstance(self, (_BaseNetwork, IPv6Interface)): - return '%s/%d' % (':'.join(parts), self.prefixlen) + return '%s/%d' % (':'.join(parts), self._prefixlen) return ':'.join(parts) @property @@ -1947,10 +1943,6 @@ return self._ip ^ self._prefixlen ^ int(self.network.network_address) @property - def prefixlen(self): - return self._prefixlen - - @property def ip(self): return IPv6Address(self._ip) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -731,8 +731,8 @@ '2001:658:22a:cafe:ffff:ffff:ffff:ffff') def testGetPrefixlen(self): - self.assertEqual(self.ipv4_interface.prefixlen, 24) - self.assertEqual(self.ipv6_interface.prefixlen, 64) + self.assertEqual(self.ipv4_interface.network.prefixlen, 24) + self.assertEqual(self.ipv6_interface.network.prefixlen, 64) def testGetSupernet(self): self.assertEqual(self.ipv4_network.supernet().prefixlen, 23) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:48:09 2012 From: python-checkins at python.org (nadeem.vawda) Date: Sun, 5 Aug 2012 14:48:09 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=2315546=3A_Also_fix_GzipF?= =?utf-8?b?aWxlLnBlZWsoKS4=?= Message-ID: <3Wqhc95JmlzPkS@mail.python.org> http://hg.python.org/cpython/rev/8c07ff7f882f changeset: 78431:8c07ff7f882f user: Nadeem Vawda date: Sun Aug 05 14:45:41 2012 +0200 summary: #15546: Also fix GzipFile.peek(). files: Lib/gzip.py | 6 ++++-- Misc/NEWS | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -413,8 +413,10 @@ if self.fileobj is None: return b'' try: - # 1024 is the same buffering heuristic used in read() - self._read(max(n, 1024)) + # Ensure that we don't return b"" if we haven't reached EOF. + while self.extrasize == 0: + # 1024 is the same buffering heuristic used in read() + self._read(max(n, 1024)) except EOFError: pass offset = self.offset - self.extrastart diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -81,8 +81,8 @@ constructor, objects in the ipaddress module no longer implement __index__ (they still implement __int__ as appropriate) -- Issue #15546: Fix handling of pathological input data in the read1() method of - the BZ2File, GzipFile and LZMAFile classes. +- Issue #15546: Fix handling of pathological input data in the peek() and + read1() methods of the BZ2File, GzipFile and LZMAFile classes. - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:52:49 2012 From: python-checkins at python.org (nick.coghlan) Date: Sun, 5 Aug 2012 14:52:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2314814=3A_Attempt_?= =?utf-8?q?to_clarify_network_address_and_broadcast_address_for_less?= Message-ID: <3WqhjY0jdRzPkm@mail.python.org> http://hg.python.org/cpython/rev/abbae7314b52 changeset: 78432:abbae7314b52 user: Nick Coghlan date: Sun Aug 05 22:52:38 2012 +1000 summary: Issue #14814: Attempt to clarify network address and broadcast address for less experienced users files: Doc/library/ipaddress.rst | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -390,11 +390,13 @@ .. attribute:: network_address - The broadcast address for the network. + The network address for the network. The network address and the + prefix length together uniquely define a network. .. attribute:: broadcast_address - The broadcast address for the network. + The broadcast address for the network. Packets sent to the broadcast + address should be received by every host on the network. .. attribute:: host mask -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:56:33 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 5 Aug 2012 14:56:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_CGI_tests_?= =?utf-8?q?to_take_into_account_the_platform=27s_line_ending_=28issue_=231?= =?utf-8?q?3119=29?= Message-ID: <3Wqhns4B4czPl8@mail.python.org> http://hg.python.org/cpython/rev/bc4fdb758b8c changeset: 78433:bc4fdb758b8c branch: 3.2 parent: 78421:481f5d9ef577 user: Antoine Pitrou date: Sun Aug 05 14:52:45 2012 +0200 summary: Fix CGI tests to take into account the platform's line ending (issue #13119) files: Lib/test/test_httpservers.py | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -313,6 +313,8 @@ class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler): pass + linesep = os.linesep.encode('ascii') + def setUp(self): BaseTestCase.setUp(self) self.cwd = os.getcwd() @@ -410,7 +412,7 @@ def test_headers_and_content(self): res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_post(self): @@ -419,7 +421,7 @@ headers = {'Content-type' : 'application/x-www-form-urlencoded'} res = self.request('/cgi-bin/file2.py', 'POST', params, headers) - self.assertEqual(res.read(), b'1, python, 123456\n') + self.assertEqual(res.read(), b'1, python, 123456' + self.linesep) def test_invaliduri(self): res = self.request('/cgi-bin/invalid') @@ -430,20 +432,20 @@ headers = {b'Authorization' : b'Basic ' + base64.b64encode(b'username:pass')} res = self.request('/cgi-bin/file1.py', 'GET', headers=headers) - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_no_leading_slash(self): # http://bugs.python.org/issue2254 res = self.request('cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_os_environ_is_not_altered(self): signature = "Test CGI Server" os.environ['SERVER_SOFTWARE'] = signature res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) self.assertEqual(os.environ['SERVER_SOFTWARE'], signature) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:56:35 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 5 Aug 2012 14:56:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Fix_CGI_tests_to_take_into_account_the_platform=27s_line?= =?utf-8?q?_ending_=28issue_=2313119=29?= Message-ID: <3Wqhnv1y4YzPlB@mail.python.org> http://hg.python.org/cpython/rev/ee185c6b2880 changeset: 78434:ee185c6b2880 parent: 78429:cf8d42596a44 parent: 78433:bc4fdb758b8c user: Antoine Pitrou date: Sun Aug 05 14:53:33 2012 +0200 summary: Fix CGI tests to take into account the platform's line ending (issue #13119) files: Lib/test/test_httpservers.py | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -313,6 +313,8 @@ class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler): pass + linesep = os.linesep.encode('ascii') + def setUp(self): BaseTestCase.setUp(self) self.cwd = os.getcwd() @@ -410,7 +412,7 @@ def test_headers_and_content(self): res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_post(self): @@ -419,7 +421,7 @@ headers = {'Content-type' : 'application/x-www-form-urlencoded'} res = self.request('/cgi-bin/file2.py', 'POST', params, headers) - self.assertEqual(res.read(), b'1, python, 123456\n') + self.assertEqual(res.read(), b'1, python, 123456' + self.linesep) def test_invaliduri(self): res = self.request('/cgi-bin/invalid') @@ -430,20 +432,20 @@ headers = {b'Authorization' : b'Basic ' + base64.b64encode(b'username:pass')} res = self.request('/cgi-bin/file1.py', 'GET', headers=headers) - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_no_leading_slash(self): # http://bugs.python.org/issue2254 res = self.request('cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_os_environ_is_not_altered(self): signature = "Test CGI Server" os.environ['SERVER_SOFTWARE'] = signature res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) self.assertEqual(os.environ['SERVER_SOFTWARE'], signature) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 14:56:36 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sun, 5 Aug 2012 14:56:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge?= Message-ID: <3Wqhnw6DQdzPlv@mail.python.org> http://hg.python.org/cpython/rev/df5c9f4ba3b5 changeset: 78435:df5c9f4ba3b5 parent: 78434:ee185c6b2880 parent: 78432:abbae7314b52 user: Antoine Pitrou date: Sun Aug 05 14:53:49 2012 +0200 summary: Merge files: Doc/library/ipaddress.rst | 6 ++++-- Lib/gzip.py | 6 ++++-- Lib/ipaddress.py | 10 +--------- Lib/test/test_ipaddress.py | 4 ++-- Misc/NEWS | 4 ++-- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -390,11 +390,13 @@ .. attribute:: network_address - The broadcast address for the network. + The network address for the network. The network address and the + prefix length together uniquely define a network. .. attribute:: broadcast_address - The broadcast address for the network. + The broadcast address for the network. Packets sent to the broadcast + address should be received by every host on the network. .. attribute:: host mask diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -413,8 +413,10 @@ if self.fileobj is None: return b'' try: - # 1024 is the same buffering heuristic used in read() - self._read(max(n, 1024)) + # Ensure that we don't return b"" if we haven't reached EOF. + while self.extrasize == 0: + # 1024 is the same buffering heuristic used in read() + self._read(max(n, 1024)) except EOFError: pass offset = self.offset - self.extrastart diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1331,10 +1331,6 @@ return self._ip ^ self._prefixlen ^ int(self.network.network_address) @property - def prefixlen(self): - return self._prefixlen - - @property def ip(self): return IPv4Address(self._ip) @@ -1708,7 +1704,7 @@ hex_str = '%032x' % ip_int parts = [hex_str[x:x+4] for x in range(0, 32, 4)] if isinstance(self, (_BaseNetwork, IPv6Interface)): - return '%s/%d' % (':'.join(parts), self.prefixlen) + return '%s/%d' % (':'.join(parts), self._prefixlen) return ':'.join(parts) @property @@ -1947,10 +1943,6 @@ return self._ip ^ self._prefixlen ^ int(self.network.network_address) @property - def prefixlen(self): - return self._prefixlen - - @property def ip(self): return IPv6Address(self._ip) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -731,8 +731,8 @@ '2001:658:22a:cafe:ffff:ffff:ffff:ffff') def testGetPrefixlen(self): - self.assertEqual(self.ipv4_interface.prefixlen, 24) - self.assertEqual(self.ipv6_interface.prefixlen, 64) + self.assertEqual(self.ipv4_interface.network.prefixlen, 24) + self.assertEqual(self.ipv6_interface.network.prefixlen, 64) def testGetSupernet(self): self.assertEqual(self.ipv4_network.supernet().prefixlen, 23) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -81,8 +81,8 @@ constructor, objects in the ipaddress module no longer implement __index__ (they still implement __int__ as appropriate) -- Issue #15546: Fix handling of pathological input data in the read1() method of - the BZ2File, GzipFile and LZMAFile classes. +- Issue #15546: Fix handling of pathological input data in the peek() and + read1() methods of the BZ2File, GzipFile and LZMAFile classes. - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 15:22:07 2012 From: python-checkins at python.org (victor.stinner) Date: Sun, 5 Aug 2012 15:22:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_os=2Eunlinkat=28=29_has_be?= =?utf-8?q?en_removed=2C_update_os=2Efwalk=28=29_doc?= Message-ID: <3WqjMM68qSzPlB@mail.python.org> http://hg.python.org/cpython/rev/066005ff562c changeset: 78436:066005ff562c user: Victor Stinner date: Sun Aug 05 15:18:02 2012 +0200 summary: os.unlinkat() has been removed, update os.fwalk() doc files: Doc/library/os.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -2248,7 +2248,7 @@ dirs.remove('CVS') # don't visit CVS directories In the next example, walking the tree bottom-up is essential: - :func:`unlinkat` doesn't allow deleting a directory before the directory is + :func:`rmdir` doesn't allow deleting a directory before the directory is empty:: # Delete everything reachable from the directory named in "top", @@ -2258,9 +2258,9 @@ import os for root, dirs, files, rootfd in os.fwalk(top, topdown=False): for name in files: - os.unlinkat(rootfd, name) + os.unlink(name, dir_fd=rootfd) for name in dirs: - os.unlinkat(rootfd, name, os.AT_REMOVEDIR) + os.rmdir(name, dir_fd=rootfd) Availability: Unix. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 16:00:47 2012 From: python-checkins at python.org (victor.stinner) Date: Sun, 5 Aug 2012 16:00:47 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315548=3A_Update_a?= =?utf-8?q?nd_complete_What=27s_New_in_Python_3=2E3=2C_especially_the_=22o?= =?utf-8?q?s=22?= Message-ID: <3WqkCz1jnVzPl8@mail.python.org> http://hg.python.org/cpython/rev/b7b8e4ada3e5 changeset: 78437:b7b8e4ada3e5 user: Victor Stinner date: Sun Aug 05 15:56:51 2012 +0200 summary: Issue #15548: Update and complete What's New in Python 3.3, especially the "os" section files: Doc/whatsnew/3.3.rst | 143 ++++++++++++++++-------------- 1 files changed, 76 insertions(+), 67 deletions(-) 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 @@ -786,6 +786,20 @@ (contributed by Antoine Pitrou in :issue:`9260`.) +Builtin functions +================= + + * :func:`open` gets a new *opener* parameter: the underlying file descriptor + for the file object is then obtained by calling *opener* with (*file*, + *flags*). It can be used to use custom flags like :data:`os.O_CLOEXEC` for + example. The ``'x'`` mode was added: open for exclusive creation, failing if + the file already exists. + * :func:`print`: added the *flush* keyword argument. If the *flush* keyword + argument is true, the stream is forcibly flushed. + * :func:`hash`: hash randomization is enabled by default, see + :meth:`object.__hash__` and :envvar:`PYTHONHASHSEED`. + + New and Improved Modules ======================== @@ -1163,6 +1177,29 @@ (Patch submitted by Ross Lagerwall and Giampaolo Rodol? in :issue:`10882`.) +* To avoid race conditions like symlink attacks and issues with temporary + files and directories, it is more reliable (and also faster) to manipulate + file descriptors instead of file names. Python 3.3 enhances existing functions + and introduces new functions to work on file descriptors. + + - The :mod:`os` module has a new :func:`~os.fwalk` function similar to + :func:`~os.walk` except that it also yields file descriptors referring to the + directories visited. This is especially useful to avoid symlink races. + + - The following functions get new optional *dir_fd* (:ref:`paths relative to + directory descriptors `) and/or *follow_symlinks* (:ref:`not + following symlinks `): + :func:`~os.access`, :func:`~os.chflags`, :func:`~os.chmod`, :func:`~os.chown`, + :func:`~os.link`, :func:`~os.lstat`, :func:`~os.mkdir`, :func:`~os.mkfifo`, + :func:`~os.mknod`, :func:`~os.open`, :func:`~os.readlink`, :func:`~os.remove`, + :func:`~os.rename`, :func:`~os.replace`, :func:`~os.rmdir`, :func:`~os.stat`, + :func:`~os.symlink`, :func:`~os.unlink`, :func:`~os.utime`. + + - The following functions now support a file descriptor for their path argument: + :func:`~os.chdir`, :func:`~os.chmod`, :func:`~os.chown`, + :func:`~os.execve`, :func:`~os.listdir`, :func:`~os.pathconf`, + :func:`~os.stat`, :func:`~os.statvfs`, :func:`~os.utime`. + * The :mod:`os` module has two new functions: :func:`~os.getpriority` and :func:`~os.setpriority`. They can be used to get or set process niceness/priority in a fashion similar to :func:`os.nice` but extended to all @@ -1170,10 +1207,6 @@ (Patch submitted by Giampaolo Rodol? in :issue:`10784`.) -* The :mod:`os` module has a new :func:`~os.fwalk` function similar to - :func:`~os.walk` except that it also yields file descriptors referring to the - directories visited. This is especially useful to avoid symlink races. - * The new :func:`os.replace` function allows cross-platform renaming of a file with overwriting the destination. With :func:`os.rename`, an existing destination file is overwritten under POSIX, but raises an error under @@ -1181,78 +1214,51 @@ (Contributed by Antoine Pitrou in :issue:`8828`.) * The new :func:`os.get_terminal_size` function queries the size of the - terminal attached to a file descriptor. + terminal attached to a file descriptor. See also + :func:`shutil.get_terminal_size`. (Contributed by Zbigniew J?drzejewski-Szmek in :issue:`13609`.) .. XXX sort out this mess after beta1 - * "at" functions (:issue:`4761`): +* New functions to support Linux extended attributes: + :func:`~os.getxattr`, :func:`~os.listxattr`, :func:`~os.removexattr`, + :func:`~os.setxattr`. - * :func:`~os.faccessat` - * :func:`~os.fchmodat` - * :func:`~os.fchownat` - * :func:`~os.fstatat` - * :func:`~os.futimesat` - * :func:`~os.linkat` - * :func:`~os.mkdirat` - * :func:`~os.mkfifoat` - * :func:`~os.mknodat` - * :func:`~os.openat` - * :func:`~os.readlinkat` - * :func:`~os.renameat` - * :func:`~os.symlinkat` - * :func:`~os.unlinkat` - * :func:`~os.utimensat` +* New interface to the scheduler. These functions + control how a process is allocated CPU time by the operating system. New + functions: + :func:`~os.sched_get_priority_max`, :func:`~os.sched_get_priority_min`, + :func:`~os.sched_getaffinity`, :func:`~os.sched_getparam`, + :func:`~os.sched_getscheduler`, :func:`~os.sched_rr_get_interval`, + :func:`~os.sched_setaffinity`, :func:`~os.sched_setparam`, + :func:`~os.sched_setscheduler`, :func:`~os.sched_yield`, - * extended attributes (:issue:`12720`): +* New functions to control the file system: - * :func:`~os.fgetxattr` - * :func:`~os.flistxattr` - * :func:`~os.fremovexattr` - * :func:`~os.fsetxattr` - * :func:`~os.getxattr` - * :func:`~os.lgetxattr` - * :func:`~os.listxattr` - * :func:`~os.llistxattr` - * :func:`~os.lremovexattr` - * :func:`~os.lsetxattr` - * :func:`~os.removexattr` - * :func:`~os.setxattr` + * :func:`~os.posix_fadvise`: Announces an intention to access data in a + specific pattern thus allowing the kernel to make optimizations. + * :func:`~os.posix_fallocate`: Ensures that enough disk space is allocated + for a file. + * :func:`~os.sync`: Force write of everything to disk. - * Scheduler functions (:issue:`12655`): +* Add some extra posix functions to the os module: - * :func:`~os.sched_get_priority_max` - * :func:`~os.sched_get_priority_min` - * :func:`~os.sched_getaffinity` - * :func:`~os.sched_getparam` - * :func:`~os.sched_getscheduler` - * :func:`~os.sched_rr_get_interval` - * :func:`~os.sched_setaffinity` - * :func:`~os.sched_setparam` - * :func:`~os.sched_setscheduler` - * :func:`~os.sched_yield` + * :func:`~os.lockf`: Apply, test or remove a POSIX lock on an open file descriptor. + * :func:`~os.pread`: Read from a file descriptor at an offset, the file + offset remains unchanged. + * :func:`~os.pwrite`: Write to a file descriptor from an offset, leaving + the file offset unchanged. + * :func:`~os.readv`: Read from a file descriptor into a number of writable buffers. + * :func:`~os.truncate`: Truncate the file corresponding to *path*, so that + it is at most *length* bytes in size. + * :func:`~os.waitid`: Wait for the completion of one or more child processes. + * :func:`~os.writev`: Write the contents of *buffers* to a file descriptor, + where *buffers* is an arbitrary sequence of buffers. + * :func:`~os.getgrouplist` (:issue:`9344`): Return list of group ids that + specified user belongs to. - * Add some extra posix functions to the os module (:issue:`10812`): - - * :func:`~os.fexecve` - * :func:`~os.futimens` - * :func:`~os.futimes` - * :func:`~os.lockf` - * :func:`~os.lutimes` - * :func:`~os.posix_fadvise` - * :func:`~os.posix_fallocate` - * :func:`~os.pread` - * :func:`~os.pwrite` - * :func:`~os.readv` - * :func:`~os.sync` - * :func:`~os.truncate` - * :func:`~os.waitid` - * :func:`~os.writev` - - * Other new functions: - - * :func:`~os.flistdir` (:issue:`10755`) - * :func:`~os.getgrouplist` (:issue:`9344`) +* :func:`~os.times` and :func:`~os.uname`: Return type changed from a tuple to + a tuple-like object with named attributes. pdb @@ -1614,6 +1620,7 @@ * The behaviour of :func:`time.clock` depends on the platform: use the new :func:`time.perf_counter` or :func:`time.process_time` function instead, depending on your requirements, to have a well defined behaviour. +* The :func:`os.stat_float_times` function is deprecated. Deprecated functions and types of the C API @@ -1690,7 +1697,9 @@ Porting Python code ------------------- -.. XXX add a point about hash randomization and that it's always on in 3.3 +* Hash randomization is enabled by default. Set the :envvar:`PYTHONHASHSEED` + environment variable to ``0`` to disable hash randomization. See also the + :meth:`object.__hash__` method. * :issue:`12326`: On Linux, sys.platform doesn't contain the major version anymore. It is now always 'linux', instead of 'linux2' or 'linux3' depending -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 16:41:02 2012 From: python-checkins at python.org (victor.stinner) Date: Sun, 5 Aug 2012 16:41:02 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Complete_What=27s_New_in_P?= =?utf-8?q?ython_3=2E3=2E?= Message-ID: <3Wql6Q2DYKzPk7@mail.python.org> http://hg.python.org/cpython/rev/7ca6b3a16e15 changeset: 78438:7ca6b3a16e15 user: Victor Stinner date: Sun Aug 05 16:31:32 2012 +0200 summary: Complete What's New in Python 3.3. files: Doc/whatsnew/3.3.rst | 99 ++++++++++++++++++++++++++----- 1 files changed, 81 insertions(+), 18 deletions(-) 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 @@ -786,18 +786,21 @@ (contributed by Antoine Pitrou in :issue:`9260`.) -Builtin functions -================= +Builtin functions and types +=========================== - * :func:`open` gets a new *opener* parameter: the underlying file descriptor - for the file object is then obtained by calling *opener* with (*file*, - *flags*). It can be used to use custom flags like :data:`os.O_CLOEXEC` for - example. The ``'x'`` mode was added: open for exclusive creation, failing if - the file already exists. - * :func:`print`: added the *flush* keyword argument. If the *flush* keyword - argument is true, the stream is forcibly flushed. - * :func:`hash`: hash randomization is enabled by default, see - :meth:`object.__hash__` and :envvar:`PYTHONHASHSEED`. +* :func:`open` gets a new *opener* parameter: the underlying file descriptor + for the file object is then obtained by calling *opener* with (*file*, + *flags*). It can be used to use custom flags like :data:`os.O_CLOEXEC` for + example. The ``'x'`` mode was added: open for exclusive creation, failing if + the file already exists. +* :func:`print`: added the *flush* keyword argument. If the *flush* keyword + argument is true, the stream is forcibly flushed. +* :func:`hash`: hash randomization is enabled by default, see + :meth:`object.__hash__` and :envvar:`PYTHONHASHSEED`. +* The :class:`str` type gets a new :meth:`~str.casefold` method: return a + casefolded copy of the string, casefolded strings may be used for caseless + matching. For example, ``'?'.casefold()`` returns ``'ss'``. New and Improved Modules @@ -829,12 +832,22 @@ (Contributed by Oren Tirosh and Hirokazu Yamamoto in :issue:`1172711`) +base64, binascii +---------------- + +ASCII-only Unicode strings are now accepted by the decoding functions of the +modern interface. For example, ``base64.b64decode('YWJj')`` returns ``b'abc'``. + + bz2 --- The :mod:`bz2` module has been rewritten from scratch. In the process, several new features have been added: +* New :func:`bz2.open` function: open a bzip2-compressed file in binary or + text mode. + * :class:`bz2.BZ2File` can now read from and write to arbitrary file-like objects, by means of its constructor's *fileobj* argument. @@ -924,7 +937,7 @@ crypt ----- -Addition of salt and modular crypt format and the :func:`~crypt.mksalt` +Addition of salt and modular crypt format (hashing method) and the :func:`~crypt.mksalt` function to the :mod:`crypt` module. (:issue:`10924`) @@ -945,6 +958,17 @@ (Contributed by I?igo Serna in :issue:`6755`) +datetime +-------- + + * Equality comparisons between naive and aware :class:`~datetime.datetime` + instances don't raise :exc:`TypeError`. + * New :meth:`datetime.datetime.timestamp` method: Return POSIX timestamp + corresponding to the :class:`~datetime.datetime` instance. + * The :meth:`datetime.datetime.strftime` method supports formatting years + older than 1000. + + decimal ------- @@ -1041,10 +1065,26 @@ faulthandler ------------ -New module: :mod:`faulthandler`. +This new debug module contains functions to dump Python tracebacks explicitly, +on a fault (a crash like a segmentation fault), after a timeout, or on a user +signal. Call :func:`faulthandler.enable` to install fault handlers for the +:const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS`, and +:const:`SIGILL` signals. You can also enable them at startup by setting the +:envvar:`PYTHONFAULTHANDLER` environment variable or by using :option:`-X` +``faulthandler`` command line option. - * :envvar:`PYTHONFAULTHANDLER` - * :option:`-X` ``faulthandler`` +Example of a segmentation fault on Linux: :: + + $ python -q -X faulthandler + >>> import ctypes + >>> ctypes.string_at(0) + Fatal Python error: Segmentation fault + + Current thread 0x00007fb899f39700: + File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at + File "", line 1 in + Segmentation fault + ftplib ------ @@ -1057,6 +1097,13 @@ (Contributed by Giampaolo Rodol? in :issue:`12139`) +gc +-- + +It is now possible to register callbacks invoked by the garbage collector +before and after collection using the new :`data:`~gc.callbacks` list. + + hmac ---- @@ -1101,6 +1148,12 @@ (Contributed by David Townshend in :issue:`12760`) +The constructor of the :class:`~io.TextIOWrapper` class has a new +*write_through* optional argument. If *write_through* is ``True``, calls to +:meth:`~io.TextIOWrapper.write` are guaranteed not to be buffered: any data +written on the :class:`~io.TextIOWrapper` object is immediately handled to its +underlying binary buffer. + ipaddress --------- @@ -1180,7 +1233,8 @@ * To avoid race conditions like symlink attacks and issues with temporary files and directories, it is more reliable (and also faster) to manipulate file descriptors instead of file names. Python 3.3 enhances existing functions - and introduces new functions to work on file descriptors. + and introduces new functions to work on file descriptors (:issue:`4761`, + :issue:`10755`). - The :mod:`os` module has a new :func:`~os.fwalk` function similar to :func:`~os.walk` except that it also yields file descriptors referring to the @@ -1197,7 +1251,7 @@ - The following functions now support a file descriptor for their path argument: :func:`~os.chdir`, :func:`~os.chmod`, :func:`~os.chown`, - :func:`~os.execve`, :func:`~os.listdir`, :func:`~os.pathconf`, + :func:`~os.execve`, :func:`~os.listdir`, :func:`~os.pathconf`, :func:`~os.path.exists`, :func:`~os.stat`, :func:`~os.statvfs`, :func:`~os.utime`. * The :mod:`os` module has two new functions: :func:`~os.getpriority` and @@ -1220,7 +1274,7 @@ .. XXX sort out this mess after beta1 -* New functions to support Linux extended attributes: +* New functions to support Linux extended attributes (:issue:`12720`): :func:`~os.getxattr`, :func:`~os.listxattr`, :func:`~os.removexattr`, :func:`~os.setxattr`. @@ -1621,6 +1675,15 @@ :func:`time.perf_counter` or :func:`time.process_time` function instead, depending on your requirements, to have a well defined behaviour. * The :func:`os.stat_float_times` function is deprecated. +* :mod:`abc` module: + + * :class:`abc.abstractproperty` has been deprecated, use :class:`property` + with :func:`abc.abstractmethod` instead. + * :class:`abc.abstractclassmethod` has been deprecated, use + :class:`classmethod` with :func:`abc.abstractmethod` instead. + * :class:`abc.abstractstaticmethod` has been deprecated, use + :class:`staticmethod` with :func:`abc.abstractmethod` instead. + Deprecated functions and types of the C API -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 5 16:41:05 2012 From: python-checkins at python.org (victor.stinner) Date: Sun, 5 Aug 2012 16:41:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_What=27s_New_in_Python_3?= =?utf-8?q?=2E3=3A_Split_improved_and_new_modules=2C_start_to_write_a?= Message-ID: <3Wql6T1bwDzPlc@mail.python.org> http://hg.python.org/cpython/rev/80a1ae3a1b39 changeset: 78439:80a1ae3a1b39 user: Victor Stinner date: Sun Aug 05 16:37:12 2012 +0200 summary: What's New in Python 3.3: Split improved and new modules, start to write a summary files: Doc/whatsnew/3.3.rst | 105 +++++++++++++++++------------- 1 files changed, 60 insertions(+), 45 deletions(-) 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 @@ -53,6 +53,18 @@ release, so it's worth checking back even after reading earlier versions. +Summary +======= + +Major changes since Python 3.2: + + * 4 new modules: :mod:`faulthandler`, :mod:`ipaddress`, :mod:`lzma` and :mod:`venv`. + * Syntax changes: + + - ``u'unicode'`` syntax is accepted again + - Add ``yield from`` syntax + + PEP 405: Virtual Environments ============================= @@ -803,8 +815,54 @@ matching. For example, ``'?'.casefold()`` returns ``'ss'``. -New and Improved Modules -======================== +New Modules +=========== + +faulthandler +------------ + +This new debug module contains functions to dump Python tracebacks explicitly, +on a fault (a crash like a segmentation fault), after a timeout, or on a user +signal. Call :func:`faulthandler.enable` to install fault handlers for the +:const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS`, and +:const:`SIGILL` signals. You can also enable them at startup by setting the +:envvar:`PYTHONFAULTHANDLER` environment variable or by using :option:`-X` +``faulthandler`` command line option. + +Example of a segmentation fault on Linux: :: + + $ python -q -X faulthandler + >>> import ctypes + >>> ctypes.string_at(0) + Fatal Python error: Segmentation fault + + Current thread 0x00007fb899f39700: + File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at + File "", line 1 in + Segmentation fault + + +ipaddress +--------- + +The new :mod:`ipaddress` module provides tools for creating and manipulating +objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e. +an IP address associated with a specific IP subnet). + +(Contributed by Google and Peter Moody in :pep:`3144`) + +lzma +---- + +The newly-added :mod:`lzma` module provides data compression and decompression +using the LZMA algorithm, including support for the ``.xz`` and ``.lzma`` +file formats. + +(Contributed by Nadeem Vawda and Per ?yvind Karlsen in :issue:`6715`) + + +Improved Modules +================ abc --- @@ -1062,30 +1120,6 @@ changed to match the order displayed by :func:`repr`. -faulthandler ------------- - -This new debug module contains functions to dump Python tracebacks explicitly, -on a fault (a crash like a segmentation fault), after a timeout, or on a user -signal. Call :func:`faulthandler.enable` to install fault handlers for the -:const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS`, and -:const:`SIGILL` signals. You can also enable them at startup by setting the -:envvar:`PYTHONFAULTHANDLER` environment variable or by using :option:`-X` -``faulthandler`` command line option. - -Example of a segmentation fault on Linux: :: - - $ python -q -X faulthandler - >>> import ctypes - >>> ctypes.string_at(0) - Fatal Python error: Segmentation fault - - Current thread 0x00007fb899f39700: - File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at - File "", line 1 in - Segmentation fault - - ftplib ------ @@ -1155,25 +1189,6 @@ underlying binary buffer. -ipaddress ---------- - -The new :mod:`ipaddress` module provides tools for creating and manipulating -objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e. -an IP address associated with a specific IP subnet). - -(Contributed by Google and Peter Moody in :pep:`3144`) - -lzma ----- - -The newly-added :mod:`lzma` module provides data compression and decompression -using the LZMA algorithm, including support for the ``.xz`` and ``.lzma`` -file formats. - -(Contributed by Nadeem Vawda and Per ?yvind Karlsen in :issue:`6715`) - - math ---- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:05:57 2012 From: python-checkins at python.org (benjamin.peterson) Date: Mon, 6 Aug 2012 00:05:57 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_add_another_testcase?= Message-ID: <3Wqwzn61ftzPhR@mail.python.org> http://hg.python.org/cpython/rev/cde674716de4 changeset: 78440:cde674716de4 parent: 78425:5284e65e865b user: Benjamin Peterson date: Sun Aug 05 15:05:34 2012 -0700 summary: add another testcase files: Lib/test/test_unicode.py | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) 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 @@ -572,6 +572,7 @@ self.assertEqual('?'.casefold(), 'fi') self.assertEqual('\u03a3'.casefold(), '\u03c3') self.assertEqual('A\u0345\u03a3'.casefold(), 'a\u03b9\u03c3') + self.assertEqual('\u00b5'.casefold(), '\u03bc') def test_upper(self): string_tests.CommonTest.test_upper(self) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:06:00 2012 From: python-checkins at python.org (benjamin.peterson) Date: Mon, 6 Aug 2012 00:06:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3Wqwzr11KTzPjW@mail.python.org> http://hg.python.org/cpython/rev/a8b05f3c14fc changeset: 78441:a8b05f3c14fc parent: 78440:cde674716de4 parent: 78439:80a1ae3a1b39 user: Benjamin Peterson date: Sun Aug 05 15:05:53 2012 -0700 summary: merge heads files: Doc/library/ipaddress.rst | 523 +++++++++++++++++--- Doc/library/os.rst | 6 +- Doc/whatsnew/3.3.rst | 279 +++++++--- Lib/gzip.py | 6 +- Lib/ipaddress.py | 570 ++++++++++++---------- Lib/test/test_httpservers.py | 12 +- Lib/test/test_ipaddress.py | 25 +- Misc/NEWS | 8 +- 8 files changed, 962 insertions(+), 467 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -9,17 +9,26 @@ -------------- -The :mod:`ipaddress` module provides the capabilities to create, manipulate and +.. note:: + + The ``ipaddress`` module has been included in the standard library on a + :term:`provisional basis `. Backwards incompatible + changes (up to and including removal of the package) may occur if deemed + necessary by the core developers. + +:mod:`ipaddress` provides the capabilities to create, manipulate and operate on IPv4 and IPv6 addresses and networks. +The functions and classes in this module make it straightforward to handle +various tasks related to IP addresses, including checking whether or not two +hosts are on the same subnet, iterating over all hosts in a particular +subnet, checking whether or not a string represents a valid IP address or +network definition, and so on. + This is the full module API reference - for an overview and introduction, see :ref:`ipaddress-howto`. -The functions and classes in this module make it straightforward to handle -various tasks related to IP addresses, including checking whether or not two -hosts are on the same subnet, iterating over all hosts in a particular -subnet, as well as checking whether or not a string represents a valid -IP address or network definition. +.. versionadded:: 3.3 Convenience factory functions @@ -65,15 +74,24 @@ :exc:`ValueError` is raised if *address* does not represent a valid IPv4 or IPv6 address. +One downside of these convenience functions is that the need to handle both +IPv4 and IPv6 formats means that error messages provide minimal +information on the precise error, as the functions don't know whether the +IPv4 or IPv6 format was intended. More detailed error reporting can be +obtained by calling the appropriate version specific class constructors +directly. + + +IP Addresses +------------ Address objects ---------------- +^^^^^^^^^^^^^^^ The :class:`IPv4Address` and :class:`IPv6Address` objects share a lot of common attributes. Some attributes that are only meaningful for IPv6 addresses are also implemented by :class:`IPv4Address` objects, in order to make it easier to -write code that handles both IP versions correctly. To avoid duplication, all -common attributes will only be documented for :class:`IPv4Address`. +write code that handles both IP versions correctly. .. class:: IPv4Address(address) @@ -84,66 +102,79 @@ 1. A string in decimal-dot notation, consisting of four decimal integers in the inclusive range 0-255, separated by dots (e.g. ``192.168.0.1``). Each - integer represents an octet (byte) in the address, big-endian. + integer represents an octet (byte) in the address. Leading zeroes are + tolerated only for values less then 8 (as there is no ambiguity + between the decimal and octal interpretations of such strings). 2. An integer that fits into 32 bits. - 3. An integer packed into a :class:`bytes` object of length 4, big-endian. + 3. An integer packed into a :class:`bytes` object of length 4 (most + significant octet first). >>> ipaddress.IPv4Address('192.168.0.1') IPv4Address('192.168.0.1') - >>> ipaddress.IPv4Address('192.0.2.1') == ipaddress.IPv4Address(3221225985) - True + >>> ipaddress.IPv4Address(3221225985) + IPv4Address('192.168.0.1') + >>> ipaddress.IPv4Address(b'\xC0\xA8\x00\x01') + IPv4Address('192.168.0.1') + .. attribute:: version + + The appropriate version number: ``4`` for IPv4, ``6`` for IPv6. + + .. attribute:: max_prefixlen + + The total number of bits in the address representation for this + version: ``32`` for IPv4, ``128`` for IPv6. + + The prefix defines the number of leading bits in an address that + are compared to determine whether or not an address is part of a + network. + + .. attribute:: compressed .. attribute:: exploded - The longhand version of the address as a string. Note: the - exploded/compressed distinction is meaningful only for IPv6 addresses. - For IPv4 addresses it is the same. + The string representation in dotted decimal notation. Leading zeroes + are never included in the representation. - .. attribute:: compressed - - The shorthand version of the address as a string. + As IPv4 does not define a shorthand notation for addresses with octets + set to zero, these two attributes are always the same as ``str(addr)`` + for IPv4 addresses. Exposing these attributes makes it easier to + write display code that can handle both IPv4 and IPv6 addresses. .. attribute:: packed - The binary representation of this address - a :class:`bytes` object. - - .. attribute:: version - - A numeric version number. - - .. attribute:: max_prefixlen - - Maximal length of the prefix (in bits). The prefix defines the number of - leading bits in an address that are compared to determine whether or not an - address is part of a network. + The binary representation of this address - a :class:`bytes` object of + the appropriate length (most significant octet first). This is 4 bytes + for IPv4 and 16 bytes for IPv6. .. attribute:: is_multicast - ``True`` if the address is reserved for multicast use. See :RFC:`3171` (for - IPv4) or :RFC:`2373` (for IPv6). + ``True`` if the address is reserved for multicast use. See + :RFC:`3171` (for IPv4) or :RFC:`2373` (for IPv6). .. attribute:: is_private - ``True`` if the address is allocated for private networks. See :RFC:`1918` - (for IPv4) or :RFC:`4193` (for IPv6). + ``True`` if the address is allocated for private networks. See + :RFC:`1918` (for IPv4) or :RFC:`4193` (for IPv6). .. attribute:: is_unspecified - ``True`` if the address is unspecified. See :RFC:`5375` (for IPv4) or - :RFC:`2373` (for IPv6). + ``True`` if the address is unspecified. See :RFC:`5375` (for IPv4) + or :RFC:`2373` (for IPv6). .. attribute:: is_reserved - ``True`` if the address is otherwise IETF reserved. + ``True`` if the address is otherwise IETF reserved. .. attribute:: is_loopback - ``True`` if this is a loopback address. See :RFC:`3330` (for IPv4) or - :RFC:`2373` (for IPv6). + ``True`` if this is a loopback address. See :RFC:`3330` (for IPv4) + or :RFC:`2373` (for IPv6). .. attribute:: is_link_local - ``True`` if the address is reserved for link-local. See :RFC:`3927`. + ``True`` if the address is reserved for link-local usage. See + :RFC:`3927`. + .. class:: IPv6Address(address) @@ -165,31 +196,75 @@ >>> ipaddress.IPv6Address('2001:db8::1000') IPv6Address('2001:db8::1000') - All the attributes exposed by :class:`IPv4Address` are supported. In - addition, the following attributs are exposed only by :class:`IPv6Address`. + .. attribute:: compressed + + The short form of the address representation, with leading zeroes in + groups omitted and the longest sequence of groups consisting entirely of + zeroes collapsed to a single empty group. + + This is also the value returned by ``str(addr)`` for IPv6 addresses. + + .. attribute:: exploded + + The long form of the address representation, with all leading zeroes and + groups consisting entirely of zeroes included. + + .. attribute:: packed + .. attribute:: version + .. attribute:: max_prefixlen + .. attribute:: is_multicast + .. attribute:: is_private + .. attribute:: is_unspecified + .. attribute:: is_reserved + .. attribute:: is_loopback + .. attribute:: is_link_local + + Refer to the corresponding attribute documentation in + :class:`IPv4Address` .. attribute:: is_site_local - ``True`` if the address is reserved for site-local. Note that the site-local - address space has been deprecated by :RFC:`3879`. Use - :attr:`~IPv4Address.is_private` to test if this address is in the space of - unique local addresses as defined by :RFC:`4193`. + ``True`` if the address is reserved for site-local usage. Note that + the site-local address space has been deprecated by :RFC:`3879`. Use + :attr:`~IPv4Address.is_private` to test if this address is in the + space of unique local addresses as defined by :RFC:`4193`. .. attribute:: ipv4_mapped - If this address represents a IPv4 mapped address, return the IPv4 mapped - address. Otherwise return ``None``. + For addresses that appear to be IPv4 mapped addresses (starting with + ``::FFFF/96``), this property will report the embedded IPv4 address. + For any other address, this property will be ``None``. + + .. attribute:: sixtofour + + For addresses that appear to be 6to4 addresses (starting with + ``2002::/16``) as defined by :RFC:`3056`, this property will report + the embedded IPv4 address. For any other address, this property will + be ``None``. .. attribute:: teredo - If this address appears to be a teredo address (starts with ``2001::/32``), - return a tuple of embedded teredo IPs ``(server, client)`` pairs. Otherwise - return ``None``. + For addresses that appear to be Teredo addresses (starting with + ``2001::/32``) as defined by :RFC:`4380`, this property will report + the embedded ``(server, client)`` IP address pair. For any other + address, this property will be ``None``. - .. attribute:: sixtofour - If this address appears to contain a 6to4 embedded address, return the - embedded IPv4 address. Otherwise return ``None``. +Conversion to Strings and Integers +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +To interoperate with networking interfaces such as the socket module, +addresses must be converted to strings or integers. This is handled using +the :func:`str` and :func:`int` builtin functions:: + + >>> str(ipaddress.IPv4Address('192.168.0.1')) + '192.168.0.1' + >>> int(ipaddress.IPv4Address('192.168.0.1')) + 3232235521 + >>> str(ipaddress.IPv6Address('::1')) + '::1' + >>> int(ipaddress.IPv6Address('::1')) + 1 Operators @@ -199,6 +274,7 @@ only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with IPv6). + Logical operators """"""""""""""""" @@ -212,6 +288,7 @@ >>> IPv4Address('127.0.0.2') != IPv4Address('127.0.0.1') True + Arithmetic operators """""""""""""""""""" @@ -227,45 +304,337 @@ ipaddress.AddressValueError: 4294967296 (>= 2**32) is not permitted as an IPv4 address +IP Network definitions +---------------------- + +The :class:`IPv4Network` and :class:`IPv6Network` objects provide a mechanism +for defining and inspecting IP network definitions. A network definition +consists of a *mask* and a *network address*, and as such defines a range of +IP addresses that equal the network address when masked (binary AND) with the +mask. For example, a network definition with the mask ``255.255.255.0`` and +the network address ``192.168.1.0`` consists of IP addresses in the inclusive +range ``192.168.1.0`` to ``192.168.1.255``. + + +Prefix, net mask and host mask +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +There are several equivalent ways to specify IP network masks. A *prefix* +``/`` is a notation that denotes how many high-order bits are set in +the network mask. A *net mask* is an IP address with some number of +high-order bits set. Thus the prefix ``/24`` is equivalent to the net mask +``255.255.255.0`` in IPv4, or ``ffff:ff00::`` in IPv6. In addition, a +*host mask* is the logical inverse of a *net mask*, and is sometimes used +(for example in Cisco access control lists) to denote a network mask. The +host mask equivalent to ``/24`` in IPv4 is ``0.0.0.255``. + + Network objects ---------------- +^^^^^^^^^^^^^^^ + +All attributes implemented by address objects are implemented by network +objects as well. In addition, network objects implement additional attributes. +All of these are common between :class:`IPv4Network` and :class:`IPv6Network`, +so to avoid duplication they are only documented for :class:`IPv4Network`. .. class:: IPv4Network(address, strict=True) - Construct an IPv4 network. *address* is a string or integer representing the - IP address (and optionally the network). An :exc:`AddressValueError` is - raised if *address* is not a valid IPv4 address. A :exc:`NetmaskValueError` - is raised if the netmask is not valid for an IPv4 address. + Construct an IPv4 network definition. *address* can be one of the following: + + 1. A string consisting of an IP address and an optional mask, separated by + a slash (``/``). The IP address is the network address, and the mask + can be either a single number, which means it's a *prefix*, or a string + representation of an IPv4 address. If it's the latter, the mask is + interpreted as a *net mask* if it starts with a non-zero field, or as + a *host mask* if it starts with a zero field. If no mask is provided, + it's considered to be ``/32``. + + For example, the following *address* specifications are equivalent: + ``192.168.1.0/24``, ``192.168.1.0/255.255.255.0`` and + ``192.168.1.0/0.0.0.255``. + + 2. An integer that fits into 32 bits. This is equivalent to a + single-address network, with the network address being *address* and + the mask being ``/32``. + + 3. An integer packed into a :class:`bytes` object of length 4, big-endian. + The interpretation is similar to an integer *address*. + + An :exc:`AddressValueError` is raised if *address* is not a valid IPv4 + address. A :exc:`NetmaskValueError` is raised if the mask is not valid for + an IPv4 address. If *strict* is ``True`` and host bits are set in the supplied address, - then :exc:`ValueError` is raised. Otherwise, the host bits are masked out + then :exc:`ValueError` is raised. Otherwise, the host bits are masked out to determine the appropriate network address. - >>> ipaddress.IPv4Network('192.0.2.0/27') - IPv4Network('192.0.2.0/27') - >>> ipaddress.IPv4Network('192.0.2.0/27').netmask - IPv4Address('255.255.255.224') - >>> ipaddress.IPv4Network('192.0.2.5/27', strict=False) - IPv4Network('192.0.2.0/27') + Unless stated otherwise, all network methods accepting other network/address + objects will raise :exc:`TypeError` if the argument's IP version is + incompatible to ``self`` + + .. attribute:: version + .. attribute:: max_prefixlen + + Refer to the corresponding attribute documentation in + :class:`IPv4Address` + + .. attribute:: is_multicast + .. attribute:: is_private + .. attribute:: is_unspecified + .. attribute:: is_reserved + .. attribute:: is_loopback + .. attribute:: is_link_local + + These attributes are true for the network as a whole if they are true + true for both the network address and the broadcast address + + .. attribute:: network_address + + The network address for the network. The network address and the + prefix length together uniquely define a network. + + .. attribute:: broadcast_address + + The broadcast address for the network. Packets sent to the broadcast + address should be received by every host on the network. + + .. attribute:: host mask + + The host mask, as a string. + + .. attribute:: with_prefixlen + .. attribute:: compressed + .. attribute:: exploded + + A string representation of the network, with the mask in prefix + notation. + + ``with_prefixlen`` and ``compressed`` are always the same as + ``str(network)``. + ``exploded`` uses the exploded form the network address. + + .. attribute:: with_netmask + + A string representation of the network, with the mask in net mask + notation. + + .. attribute:: with_hostmask + + A string representation of the network, with the mask in host mask + notation. + + .. attribute:: num_addresses + + The total number of addresses in the network. + + .. attribute:: prefixlen + + Length of the network prefix, in bits. + + .. method:: hosts() + + Returns an iterator over the usable hosts in the network. The usable + hosts are all the IP addresses that belong to the network, except the + network address itself and the network broadcast address. + + >>> list(ip_network('192.0.2.0/29').hosts()) + [IPv4Address('192.0.2.1'), IPv4Address('192.0.2.2'), + IPv4Address('192.0.2.3'), IPv4Address('192.0.2.4'), + IPv4Address('192.0.2.5'), IPv4Address('192.0.2.6')] + + .. method:: overlaps(other) + + ``True`` if this network is partly or wholly contained in *other* or + or *other* is wholly contained in this network. + + .. method:: address_exclude(network) + + Computes the network definitions resulting from removing the given + *network* from this one. Returns an iterator of network objects. + Raises :exc:`ValueError` if *network* is not completely contained in + this network. + + >>> n1 = ip_network('192.0.2.0/28') + >>> n2 = ip_network('192.0.2.1/32') + >>> list(n1.address_exclude(n2)) + [IPv4Network('192.0.2.8/29'), IPv4Network('192.0.2.4/30'), + IPv4Network('192.0.2.2/31'), IPv4Network('192.0.2.0/32')] + + .. method:: subnets(prefixlen_diff=1, new_prefix=None) + + The subnets that join to make the current network definition, depending + on the argument values. *prefixlen_diff* is the amount our prefix + length should be increased by. *new_prefix* is the desired new + prefix of the subnets; it must be larger than our prefix. One and + only one of *prefixlen_diff* and *new_prefix* must be set. Returns an + iterator of network objects. + + >>> list(ip_network('192.0.2.0/24').subnets()) + [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] + >>> list(ip_network('192.0.2.0/24').subnets(prefixlen_diff=2)) + [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), + IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=26)) + [IPv4Network('192.0.2.0/26'), IPv4Network('192.0.2.64/26'), + IPv4Network('192.0.2.128/26'), IPv4Network('192.0.2.192/26')] + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=23)) + Traceback (most recent call last): + File "", line 1, in + raise ValueError('new prefix must be longer') + ValueError: new prefix must be longer + >>> list(ip_network('192.0.2.0/24').subnets(new_prefix=25)) + [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')] + + .. method:: supernet(prefixlen_diff=1, new_prefix=None) + + The supernet containing this network definition, depending on the + argument values. *prefixlen_diff* is the amount our prefix length + should be decreased by. *new_prefix* is the desired new prefix of + the supernet; it must be smaller than our prefix. One and only one + of *prefixlen_diff* and *new_prefix* must be set. Returns a single + network object. + + >>> ip_network('192.0.2.0/24').supernet() + IPv4Network('192.0.2.0/23') + >>> ip_network('192.0.2.0/24').supernet(prefixlen_diff=2) + IPv4Network('192.0.0.0/22') + >>> ip_network('192.0.2.0/24').supernet(new_prefix=20) + IPv4Network('192.0.0.0/20') + + .. method:: compare_networks(other) + + Compare this network to *other*. In this comparison only the network + addresses are considered; host bits aren't. Returns either ``-1``, + ``0`` or ``1``. + + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.2/32')) + -1 + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.0/32')) + 1 + >>> ip_network('192.0.2.1/32').compare_networks(ip_network('192.0.2.1/32')) + 0 .. class:: IPv6Network(address, strict=True) - Construct an IPv6 network. *address* is a string or integer representing the - IP address (and optionally the network). An :exc:`AddressValueError` is - raised if *address* is not a valid IPv6 address. A :exc:`NetmaskValueError` - is raised if the netmask is not valid for an IPv6 address. + Construct an IPv6 network definition. *address* can be one of the following: + + 1. A string consisting of an IP address and an optional mask, separated by + a slash (``/``). The IP address is the network address, and the mask + can be either a single number, which means it's a *prefix*, or a string + representation of an IPv6 address. If it's the latter, the mask is + interpreted as a *net mask*. If no mask is provided, it's considered to + be ``/128``. + + For example, the following *address* specifications are equivalent: + ``2001:db00::0/24`` and ``2001:db00::0/ffff:ff00::``. + + 2. An integer that fits into 128 bits. This is equivalent to a + single-address network, with the network address being *address* and + the mask being ``/128``. + + 3. An integer packed into a :class:`bytes` object of length 16, bit-endian. + The interpretation is similar to an integer *address*. + + An :exc:`AddressValueError` is raised if *address* is not a valid IPv6 + address. A :exc:`NetmaskValueError` is raised if the mask is not valid for + an IPv6 address. If *strict* is ``True`` and host bits are set in the supplied address, - then :exc:`ValueError` is raised. Otherwise, the host bits are masked out + then :exc:`ValueError` is raised. Otherwise, the host bits are masked out to determine the appropriate network address. - >>> ipaddress.IPv6Network('2001:db8::/96') - IPv6Network('2001:db8::/96') - >>> ipaddress.IPv6Network('2001:db8::/96').netmask - IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') - >>> ipaddress.IPv6Network('2001:db8::1000/96', strict=False) - IPv6Network('2001:db8::/96') + .. attribute:: version + .. attribute:: max_prefixlen + .. attribute:: is_multicast + .. attribute:: is_private + .. attribute:: is_unspecified + .. attribute:: is_reserved + .. attribute:: is_loopback + .. attribute:: is_link_local + .. attribute:: network_address + .. attribute:: broadcast_address + .. attribute:: host mask + .. attribute:: with_prefixlen + .. attribute:: compressed + .. attribute:: exploded + .. attribute:: with_netmask + .. attribute:: with_hostmask + .. attribute:: num_addresses + .. attribute:: prefixlen + .. method:: hosts() + .. method:: overlaps(other) + .. method:: address_exclude(network) + .. method:: subnets(prefixlen_diff=1, new_prefix=None) + .. method:: supernet(prefixlen_diff=1, new_prefix=None) + .. method:: compare_networks(other) + + Refer to the corresponding attribute documentation in + :class:`IPv4Network` + + .. attribute:: is_site_local + + These attribute is true for the network as a whole if it is true + true for both the network address and the broadcast address + + +Operators +^^^^^^^^^ + +Network objects support some operators. Unless stated otherwise, operators can +only be applied between compatible objects (i.e. IPv4 with IPv4, IPv6 with +IPv6). + + +Logical operators +""""""""""""""""" + +Network objects can be compared with the usual set of logical operators, +similarly to address objects. + + +Iteration +""""""""" + +Network objects can be iterated to list all the addresses belonging to the +network. For iteration, *all* hosts are returned, including unusable hosts +(for usable hosts, use the :meth:`~IPv4Network.hosts` method). An +example:: + + >>> for addr in IPv4Network('192.0.2.0/28'): + ... addr + ... + IPv4Address('192.0.2.0') + IPv4Address('192.0.2.1') + IPv4Address('192.0.2.2') + IPv4Address('192.0.2.3') + IPv4Address('192.0.2.4') + IPv4Address('192.0.2.5') + IPv4Address('192.0.2.6') + IPv4Address('192.0.2.7') + IPv4Address('192.0.2.8') + IPv4Address('192.0.2.9') + IPv4Address('192.0.2.10') + IPv4Address('192.0.2.11') + IPv4Address('192.0.2.12') + IPv4Address('192.0.2.13') + IPv4Address('192.0.2.14') + IPv4Address('192.0.2.15') + + +Networks as containers of addresses +""""""""""""""""""""""""""""""""""" + +Network objects can act as containers of addresses. Some examples:: + + >>> IPv4Network('192.0.2.0/28')[0] + IPv4Address('192.0.2.0') + >>> IPv4Network('192.0.2.0/28')[15] + IPv4Address('192.0.2.15') + >>> IPv4Address('192.0.2.6') in IPv4Network('192.0.2.0/28') + True + >>> IPv4Address('192.0.3.6') in IPv4Network('192.0.2.0/28') + False Interface objects diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -2248,7 +2248,7 @@ dirs.remove('CVS') # don't visit CVS directories In the next example, walking the tree bottom-up is essential: - :func:`unlinkat` doesn't allow deleting a directory before the directory is + :func:`rmdir` doesn't allow deleting a directory before the directory is empty:: # Delete everything reachable from the directory named in "top", @@ -2258,9 +2258,9 @@ import os for root, dirs, files, rootfd in os.fwalk(top, topdown=False): for name in files: - os.unlinkat(rootfd, name) + os.unlink(name, dir_fd=rootfd) for name in dirs: - os.unlinkat(rootfd, name, os.AT_REMOVEDIR) + os.rmdir(name, dir_fd=rootfd) Availability: Unix. 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 @@ -53,6 +53,18 @@ release, so it's worth checking back even after reading earlier versions. +Summary +======= + +Major changes since Python 3.2: + + * 4 new modules: :mod:`faulthandler`, :mod:`ipaddress`, :mod:`lzma` and :mod:`venv`. + * Syntax changes: + + - ``u'unicode'`` syntax is accepted again + - Add ``yield from`` syntax + + PEP 405: Virtual Environments ============================= @@ -786,8 +798,71 @@ (contributed by Antoine Pitrou in :issue:`9260`.) -New and Improved Modules -======================== +Builtin functions and types +=========================== + +* :func:`open` gets a new *opener* parameter: the underlying file descriptor + for the file object is then obtained by calling *opener* with (*file*, + *flags*). It can be used to use custom flags like :data:`os.O_CLOEXEC` for + example. The ``'x'`` mode was added: open for exclusive creation, failing if + the file already exists. +* :func:`print`: added the *flush* keyword argument. If the *flush* keyword + argument is true, the stream is forcibly flushed. +* :func:`hash`: hash randomization is enabled by default, see + :meth:`object.__hash__` and :envvar:`PYTHONHASHSEED`. +* The :class:`str` type gets a new :meth:`~str.casefold` method: return a + casefolded copy of the string, casefolded strings may be used for caseless + matching. For example, ``'?'.casefold()`` returns ``'ss'``. + + +New Modules +=========== + +faulthandler +------------ + +This new debug module contains functions to dump Python tracebacks explicitly, +on a fault (a crash like a segmentation fault), after a timeout, or on a user +signal. Call :func:`faulthandler.enable` to install fault handlers for the +:const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS`, and +:const:`SIGILL` signals. You can also enable them at startup by setting the +:envvar:`PYTHONFAULTHANDLER` environment variable or by using :option:`-X` +``faulthandler`` command line option. + +Example of a segmentation fault on Linux: :: + + $ python -q -X faulthandler + >>> import ctypes + >>> ctypes.string_at(0) + Fatal Python error: Segmentation fault + + Current thread 0x00007fb899f39700: + File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at + File "", line 1 in + Segmentation fault + + +ipaddress +--------- + +The new :mod:`ipaddress` module provides tools for creating and manipulating +objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e. +an IP address associated with a specific IP subnet). + +(Contributed by Google and Peter Moody in :pep:`3144`) + +lzma +---- + +The newly-added :mod:`lzma` module provides data compression and decompression +using the LZMA algorithm, including support for the ``.xz`` and ``.lzma`` +file formats. + +(Contributed by Nadeem Vawda and Per ?yvind Karlsen in :issue:`6715`) + + +Improved Modules +================ abc --- @@ -815,12 +890,22 @@ (Contributed by Oren Tirosh and Hirokazu Yamamoto in :issue:`1172711`) +base64, binascii +---------------- + +ASCII-only Unicode strings are now accepted by the decoding functions of the +modern interface. For example, ``base64.b64decode('YWJj')`` returns ``b'abc'``. + + bz2 --- The :mod:`bz2` module has been rewritten from scratch. In the process, several new features have been added: +* New :func:`bz2.open` function: open a bzip2-compressed file in binary or + text mode. + * :class:`bz2.BZ2File` can now read from and write to arbitrary file-like objects, by means of its constructor's *fileobj* argument. @@ -910,7 +995,7 @@ crypt ----- -Addition of salt and modular crypt format and the :func:`~crypt.mksalt` +Addition of salt and modular crypt format (hashing method) and the :func:`~crypt.mksalt` function to the :mod:`crypt` module. (:issue:`10924`) @@ -931,6 +1016,17 @@ (Contributed by I?igo Serna in :issue:`6755`) +datetime +-------- + + * Equality comparisons between naive and aware :class:`~datetime.datetime` + instances don't raise :exc:`TypeError`. + * New :meth:`datetime.datetime.timestamp` method: Return POSIX timestamp + corresponding to the :class:`~datetime.datetime` instance. + * The :meth:`datetime.datetime.strftime` method supports formatting years + older than 1000. + + decimal ------- @@ -1024,14 +1120,6 @@ changed to match the order displayed by :func:`repr`. -faulthandler ------------- - -New module: :mod:`faulthandler`. - - * :envvar:`PYTHONFAULTHANDLER` - * :option:`-X` ``faulthandler`` - ftplib ------ @@ -1043,6 +1131,13 @@ (Contributed by Giampaolo Rodol? in :issue:`12139`) +gc +-- + +It is now possible to register callbacks invoked by the garbage collector +before and after collection using the new :`data:`~gc.callbacks` list. + + hmac ---- @@ -1087,24 +1182,11 @@ (Contributed by David Townshend in :issue:`12760`) - -ipaddress ---------- - -The new :mod:`ipaddress` module provides tools for creating and manipulating -objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e. -an IP address associated with a specific IP subnet). - -(Contributed by Google and Peter Moody in :pep:`3144`) - -lzma ----- - -The newly-added :mod:`lzma` module provides data compression and decompression -using the LZMA algorithm, including support for the ``.xz`` and ``.lzma`` -file formats. - -(Contributed by Nadeem Vawda and Per ?yvind Karlsen in :issue:`6715`) +The constructor of the :class:`~io.TextIOWrapper` class has a new +*write_through* optional argument. If *write_through* is ``True``, calls to +:meth:`~io.TextIOWrapper.write` are guaranteed not to be buffered: any data +written on the :class:`~io.TextIOWrapper` object is immediately handled to its +underlying binary buffer. math @@ -1163,6 +1245,30 @@ (Patch submitted by Ross Lagerwall and Giampaolo Rodol? in :issue:`10882`.) +* To avoid race conditions like symlink attacks and issues with temporary + files and directories, it is more reliable (and also faster) to manipulate + file descriptors instead of file names. Python 3.3 enhances existing functions + and introduces new functions to work on file descriptors (:issue:`4761`, + :issue:`10755`). + + - The :mod:`os` module has a new :func:`~os.fwalk` function similar to + :func:`~os.walk` except that it also yields file descriptors referring to the + directories visited. This is especially useful to avoid symlink races. + + - The following functions get new optional *dir_fd* (:ref:`paths relative to + directory descriptors `) and/or *follow_symlinks* (:ref:`not + following symlinks `): + :func:`~os.access`, :func:`~os.chflags`, :func:`~os.chmod`, :func:`~os.chown`, + :func:`~os.link`, :func:`~os.lstat`, :func:`~os.mkdir`, :func:`~os.mkfifo`, + :func:`~os.mknod`, :func:`~os.open`, :func:`~os.readlink`, :func:`~os.remove`, + :func:`~os.rename`, :func:`~os.replace`, :func:`~os.rmdir`, :func:`~os.stat`, + :func:`~os.symlink`, :func:`~os.unlink`, :func:`~os.utime`. + + - The following functions now support a file descriptor for their path argument: + :func:`~os.chdir`, :func:`~os.chmod`, :func:`~os.chown`, + :func:`~os.execve`, :func:`~os.listdir`, :func:`~os.pathconf`, :func:`~os.path.exists`, + :func:`~os.stat`, :func:`~os.statvfs`, :func:`~os.utime`. + * The :mod:`os` module has two new functions: :func:`~os.getpriority` and :func:`~os.setpriority`. They can be used to get or set process niceness/priority in a fashion similar to :func:`os.nice` but extended to all @@ -1170,10 +1276,6 @@ (Patch submitted by Giampaolo Rodol? in :issue:`10784`.) -* The :mod:`os` module has a new :func:`~os.fwalk` function similar to - :func:`~os.walk` except that it also yields file descriptors referring to the - directories visited. This is especially useful to avoid symlink races. - * The new :func:`os.replace` function allows cross-platform renaming of a file with overwriting the destination. With :func:`os.rename`, an existing destination file is overwritten under POSIX, but raises an error under @@ -1181,78 +1283,51 @@ (Contributed by Antoine Pitrou in :issue:`8828`.) * The new :func:`os.get_terminal_size` function queries the size of the - terminal attached to a file descriptor. + terminal attached to a file descriptor. See also + :func:`shutil.get_terminal_size`. (Contributed by Zbigniew J?drzejewski-Szmek in :issue:`13609`.) .. XXX sort out this mess after beta1 - * "at" functions (:issue:`4761`): +* New functions to support Linux extended attributes (:issue:`12720`): + :func:`~os.getxattr`, :func:`~os.listxattr`, :func:`~os.removexattr`, + :func:`~os.setxattr`. - * :func:`~os.faccessat` - * :func:`~os.fchmodat` - * :func:`~os.fchownat` - * :func:`~os.fstatat` - * :func:`~os.futimesat` - * :func:`~os.linkat` - * :func:`~os.mkdirat` - * :func:`~os.mkfifoat` - * :func:`~os.mknodat` - * :func:`~os.openat` - * :func:`~os.readlinkat` - * :func:`~os.renameat` - * :func:`~os.symlinkat` - * :func:`~os.unlinkat` - * :func:`~os.utimensat` +* New interface to the scheduler. These functions + control how a process is allocated CPU time by the operating system. New + functions: + :func:`~os.sched_get_priority_max`, :func:`~os.sched_get_priority_min`, + :func:`~os.sched_getaffinity`, :func:`~os.sched_getparam`, + :func:`~os.sched_getscheduler`, :func:`~os.sched_rr_get_interval`, + :func:`~os.sched_setaffinity`, :func:`~os.sched_setparam`, + :func:`~os.sched_setscheduler`, :func:`~os.sched_yield`, - * extended attributes (:issue:`12720`): +* New functions to control the file system: - * :func:`~os.fgetxattr` - * :func:`~os.flistxattr` - * :func:`~os.fremovexattr` - * :func:`~os.fsetxattr` - * :func:`~os.getxattr` - * :func:`~os.lgetxattr` - * :func:`~os.listxattr` - * :func:`~os.llistxattr` - * :func:`~os.lremovexattr` - * :func:`~os.lsetxattr` - * :func:`~os.removexattr` - * :func:`~os.setxattr` + * :func:`~os.posix_fadvise`: Announces an intention to access data in a + specific pattern thus allowing the kernel to make optimizations. + * :func:`~os.posix_fallocate`: Ensures that enough disk space is allocated + for a file. + * :func:`~os.sync`: Force write of everything to disk. - * Scheduler functions (:issue:`12655`): +* Add some extra posix functions to the os module: - * :func:`~os.sched_get_priority_max` - * :func:`~os.sched_get_priority_min` - * :func:`~os.sched_getaffinity` - * :func:`~os.sched_getparam` - * :func:`~os.sched_getscheduler` - * :func:`~os.sched_rr_get_interval` - * :func:`~os.sched_setaffinity` - * :func:`~os.sched_setparam` - * :func:`~os.sched_setscheduler` - * :func:`~os.sched_yield` + * :func:`~os.lockf`: Apply, test or remove a POSIX lock on an open file descriptor. + * :func:`~os.pread`: Read from a file descriptor at an offset, the file + offset remains unchanged. + * :func:`~os.pwrite`: Write to a file descriptor from an offset, leaving + the file offset unchanged. + * :func:`~os.readv`: Read from a file descriptor into a number of writable buffers. + * :func:`~os.truncate`: Truncate the file corresponding to *path*, so that + it is at most *length* bytes in size. + * :func:`~os.waitid`: Wait for the completion of one or more child processes. + * :func:`~os.writev`: Write the contents of *buffers* to a file descriptor, + where *buffers* is an arbitrary sequence of buffers. + * :func:`~os.getgrouplist` (:issue:`9344`): Return list of group ids that + specified user belongs to. - * Add some extra posix functions to the os module (:issue:`10812`): - - * :func:`~os.fexecve` - * :func:`~os.futimens` - * :func:`~os.futimes` - * :func:`~os.lockf` - * :func:`~os.lutimes` - * :func:`~os.posix_fadvise` - * :func:`~os.posix_fallocate` - * :func:`~os.pread` - * :func:`~os.pwrite` - * :func:`~os.readv` - * :func:`~os.sync` - * :func:`~os.truncate` - * :func:`~os.waitid` - * :func:`~os.writev` - - * Other new functions: - - * :func:`~os.flistdir` (:issue:`10755`) - * :func:`~os.getgrouplist` (:issue:`9344`) +* :func:`~os.times` and :func:`~os.uname`: Return type changed from a tuple to + a tuple-like object with named attributes. pdb @@ -1614,6 +1689,16 @@ * The behaviour of :func:`time.clock` depends on the platform: use the new :func:`time.perf_counter` or :func:`time.process_time` function instead, depending on your requirements, to have a well defined behaviour. +* The :func:`os.stat_float_times` function is deprecated. +* :mod:`abc` module: + + * :class:`abc.abstractproperty` has been deprecated, use :class:`property` + with :func:`abc.abstractmethod` instead. + * :class:`abc.abstractclassmethod` has been deprecated, use + :class:`classmethod` with :func:`abc.abstractmethod` instead. + * :class:`abc.abstractstaticmethod` has been deprecated, use + :class:`staticmethod` with :func:`abc.abstractmethod` instead. + Deprecated functions and types of the C API @@ -1690,7 +1775,9 @@ Porting Python code ------------------- -.. XXX add a point about hash randomization and that it's always on in 3.3 +* Hash randomization is enabled by default. Set the :envvar:`PYTHONHASHSEED` + environment variable to ``0`` to disable hash randomization. See also the + :meth:`object.__hash__` method. * :issue:`12326`: On Linux, sys.platform doesn't contain the major version anymore. It is now always 'linux', instead of 'linux2' or 'linux3' depending diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -413,8 +413,10 @@ if self.fileobj is None: return b'' try: - # 1024 is the same buffering heuristic used in read() - self._read(max(n, 1024)) + # Ensure that we don't return b"" if we haven't reached EOF. + while self.extrasize == 0: + # 1024 is the same buffering heuristic used in read() + self._read(max(n, 1024)) except EOFError: pass offset = self.offset - self.extrastart diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -497,6 +497,7 @@ prefixlen = self._prefixlen return self._string_from_ip_int(self._ip_int_from_prefix(prefixlen)) + class _BaseAddress(_IPAddressBase): """A generic IP object. @@ -511,9 +512,6 @@ and '/' in str(address)): raise AddressValueError("Unexpected '/' in %r" % address) - def __index__(self): - return self._ip - def __int__(self): return self._ip @@ -571,12 +569,6 @@ def __init__(self, address): self._cache = {} - def __index__(self): - return int(self.network_address) ^ self.prefixlen - - def __int__(self): - return int(self.network_address) - def __repr__(self): return '%s(%r)' % (self.__class__.__name__, str(self)) @@ -943,6 +935,76 @@ strict=False) return t.__class__('%s/%d' % (t.network_address, t.prefixlen)) + @property + def is_multicast(self): + """Test if the address is reserved for multicast use. + + Returns: + A boolean, True if the address is a multicast address. + See RFC 2373 2.7 for details. + + """ + return (self.network_address.is_multicast and + self.broadcast_address.is_multicast) + + @property + def is_reserved(self): + """Test if the address is otherwise IETF reserved. + + Returns: + A boolean, True if the address is within one of the + reserved IPv6 Network ranges. + + """ + return (self.network_address.is_reserved and + self.broadcast_address.is_reserved) + + @property + def is_link_local(self): + """Test if the address is reserved for link-local. + + Returns: + A boolean, True if the address is reserved per RFC 4291. + + """ + return (self.network_address.is_link_local and + self.broadcast_address.is_link_local) + + @property + def is_private(self): + """Test if this address is allocated for private networks. + + Returns: + A boolean, True if the address is reserved per RFC 4193. + + """ + return (self.network_address.is_private and + self.broadcast_address.is_private) + + @property + def is_unspecified(self): + """Test if the address is unspecified. + + Returns: + A boolean, True if this is the unspecified address as defined in + RFC 2373 2.5.2. + + """ + return (self.network_address.is_unspecified and + self.broadcast_address.is_unspecified) + + @property + def is_loopback(self): + """Test if the address is a loopback address. + + Returns: + A boolean, True if the address is a loopback address as defined in + RFC 2373 2.5.3. + + """ + return (self.network_address.is_loopback and + self.broadcast_address.is_loopback) + class _BaseV4: @@ -1100,102 +1162,6 @@ def version(self): return self._version - @property - def is_reserved(self): - """Test if the address is otherwise IETF reserved. - - Returns: - A boolean, True if the address is within the - reserved IPv4 Network range. - - """ - reserved_network = IPv4Network('240.0.0.0/4') - if isinstance(self, _BaseAddress): - return self in reserved_network - return (self.network_address in reserved_network and - self.broadcast_address in reserved_network) - - @property - def is_private(self): - """Test if this address is allocated for private networks. - - Returns: - A boolean, True if the address is reserved per RFC 1918. - - """ - private_10 = IPv4Network('10.0.0.0/8') - private_172 = IPv4Network('172.16.0.0/12') - private_192 = IPv4Network('192.168.0.0/16') - if isinstance(self, _BaseAddress): - return (self in private_10 or self in private_172 or - self in private_192) - else: - return ((self.network_address in private_10 and - self.broadcast_address in private_10) or - (self.network_address in private_172 and - self.broadcast_address in private_172) or - (self.network_address in private_192 and - self.broadcast_address in private_192)) - - @property - def is_multicast(self): - """Test if the address is reserved for multicast use. - - Returns: - A boolean, True if the address is multicast. - See RFC 3171 for details. - - """ - multicast_network = IPv4Network('224.0.0.0/4') - if isinstance(self, _BaseAddress): - return self in IPv4Network('224.0.0.0/4') - return (self.network_address in multicast_network and - self.broadcast_address in multicast_network) - - @property - def is_unspecified(self): - """Test if the address is unspecified. - - Returns: - A boolean, True if this is the unspecified address as defined in - RFC 5735 3. - - """ - unspecified_address = IPv4Address('0.0.0.0') - if isinstance(self, _BaseAddress): - return self == unspecified_address - return (self.network_address == self.broadcast_address == - unspecified_address) - - @property - def is_loopback(self): - """Test if the address is a loopback address. - - Returns: - A boolean, True if the address is a loopback per RFC 3330. - - """ - loopback_address = IPv4Network('127.0.0.0/8') - if isinstance(self, _BaseAddress): - return self in loopback_address - - return (self.network_address in loopback_address and - self.broadcast_address in loopback_address) - - @property - def is_link_local(self): - """Test if the address is reserved for link-local. - - Returns: - A boolean, True if the address is link-local per RFC 3927. - - """ - linklocal_network = IPv4Network('169.254.0.0/16') - if isinstance(self, _BaseAddress): - return self in linklocal_network - return (self.network_address in linklocal_network and - self.broadcast_address in linklocal_network) - class IPv4Address(_BaseV4, _BaseAddress): @@ -1242,6 +1208,79 @@ """The binary representation of this address.""" return v4_int_to_packed(self._ip) + @property + def is_reserved(self): + """Test if the address is otherwise IETF reserved. + + Returns: + A boolean, True if the address is within the + reserved IPv4 Network range. + + """ + reserved_network = IPv4Network('240.0.0.0/4') + return self in reserved_network + + @property + def is_private(self): + """Test if this address is allocated for private networks. + + Returns: + A boolean, True if the address is reserved per RFC 1918. + + """ + private_10 = IPv4Network('10.0.0.0/8') + private_172 = IPv4Network('172.16.0.0/12') + private_192 = IPv4Network('192.168.0.0/16') + return (self in private_10 or + self in private_172 or + self in private_192) + + @property + def is_multicast(self): + """Test if the address is reserved for multicast use. + + Returns: + A boolean, True if the address is multicast. + See RFC 3171 for details. + + """ + multicast_network = IPv4Network('224.0.0.0/4') + return self in multicast_network + + @property + def is_unspecified(self): + """Test if the address is unspecified. + + Returns: + A boolean, True if this is the unspecified address as defined in + RFC 5735 3. + + """ + unspecified_address = IPv4Address('0.0.0.0') + return self == unspecified_address + + @property + def is_loopback(self): + """Test if the address is a loopback address. + + Returns: + A boolean, True if the address is a loopback per RFC 3330. + + """ + loopback_network = IPv4Network('127.0.0.0/8') + return self in loopback_network + + @property + def is_link_local(self): + """Test if the address is reserved for link-local. + + Returns: + A boolean, True if the address is link-local per RFC 3927. + + """ + linklocal_network = IPv4Network('169.254.0.0/16') + return self in linklocal_network + class IPv4Interface(IPv4Address): @@ -1292,10 +1331,6 @@ return self._ip ^ self._prefixlen ^ int(self.network.network_address) @property - def prefixlen(self): - return self._prefixlen - - @property def ip(self): return IPv4Address(self._ip) @@ -1669,7 +1704,7 @@ hex_str = '%032x' % ip_int parts = [hex_str[x:x+4] for x in range(0, 32, 4)] if isinstance(self, (_BaseNetwork, IPv6Interface)): - return '%s/%d' % (':'.join(parts), self.prefixlen) + return '%s/%d' % (':'.join(parts), self._prefixlen) return ':'.join(parts) @property @@ -1680,162 +1715,6 @@ def version(self): return self._version - @property - def is_multicast(self): - """Test if the address is reserved for multicast use. - - Returns: - A boolean, True if the address is a multicast address. - See RFC 2373 2.7 for details. - - """ - multicast_network = IPv6Network('ff00::/8') - if isinstance(self, _BaseAddress): - return self in multicast_network - return (self.network_address in multicast_network and - self.broadcast_address in multicast_network) - - @property - def is_reserved(self): - """Test if the address is otherwise IETF reserved. - - Returns: - A boolean, True if the address is within one of the - reserved IPv6 Network ranges. - - """ - reserved_networks = [IPv6Network('::/8'), IPv6Network('100::/8'), - IPv6Network('200::/7'), IPv6Network('400::/6'), - IPv6Network('800::/5'), IPv6Network('1000::/4'), - IPv6Network('4000::/3'), IPv6Network('6000::/3'), - IPv6Network('8000::/3'), IPv6Network('A000::/3'), - IPv6Network('C000::/3'), IPv6Network('E000::/4'), - IPv6Network('F000::/5'), IPv6Network('F800::/6'), - IPv6Network('FE00::/9')] - - if isinstance(self, _BaseAddress): - return any(self in x for x in reserved_networks) - return any(self.network_address in x and self.broadcast_address in x - for x in reserved_networks) - - @property - def is_link_local(self): - """Test if the address is reserved for link-local. - - Returns: - A boolean, True if the address is reserved per RFC 4291. - - """ - linklocal_network = IPv6Network('fe80::/10') - if isinstance(self, _BaseAddress): - return self in linklocal_network - return (self.network_address in linklocal_network and - self.broadcast_address in linklocal_network) - - @property - def is_site_local(self): - """Test if the address is reserved for site-local. - - Note that the site-local address space has been deprecated by RFC 3879. - Use is_private to test if this address is in the space of unique local - addresses as defined by RFC 4193. - - Returns: - A boolean, True if the address is reserved per RFC 3513 2.5.6. - - """ - sitelocal_network = IPv6Network('fec0::/10') - if isinstance(self, _BaseAddress): - return self in sitelocal_network - return (self.network_address in sitelocal_network and - self.broadcast_address in sitelocal_network) - - @property - def is_private(self): - """Test if this address is allocated for private networks. - - Returns: - A boolean, True if the address is reserved per RFC 4193. - - """ - private_network = IPv6Network('fc00::/7') - if isinstance(self, _BaseAddress): - return self in private_network - return (self.network_address in private_network and - self.broadcast_address in private_network) - - @property - def ipv4_mapped(self): - """Return the IPv4 mapped address. - - Returns: - If the IPv6 address is a v4 mapped address, return the - IPv4 mapped address. Return None otherwise. - - """ - if (self._ip >> 32) != 0xFFFF: - return None - return IPv4Address(self._ip & 0xFFFFFFFF) - - @property - def teredo(self): - """Tuple of embedded teredo IPs. - - Returns: - Tuple of the (server, client) IPs or None if the address - doesn't appear to be a teredo address (doesn't start with - 2001::/32) - - """ - if (self._ip >> 96) != 0x20010000: - return None - return (IPv4Address((self._ip >> 64) & 0xFFFFFFFF), - IPv4Address(~self._ip & 0xFFFFFFFF)) - - @property - def sixtofour(self): - """Return the IPv4 6to4 embedded address. - - Returns: - The IPv4 6to4-embedded address if present or None if the - address doesn't appear to contain a 6to4 embedded address. - - """ - if (self._ip >> 112) != 0x2002: - return None - return IPv4Address((self._ip >> 80) & 0xFFFFFFFF) - - @property - def is_unspecified(self): - """Test if the address is unspecified. - - Returns: - A boolean, True if this is the unspecified address as defined in - RFC 2373 2.5.2. - - """ - if isinstance(self, (IPv6Network, IPv6Interface)): - return int(self.network_address) == 0 and getattr( - self, '_prefixlen', 128) == 128 - return self._ip == 0 - - @property - def is_loopback(self): - """Test if the address is a loopback address. - - Returns: - A boolean, True if the address is a loopback address as defined in - RFC 2373 2.5.3. - - """ - if isinstance(self, IPv6Network): - return int(self) == 1 and getattr( - self, '_prefixlen', 128) == 128 - elif isinstance(self, IPv6Interface): - return int(self.network.network_address) == 1 and getattr( - self, '_prefixlen', 128) == 128 - return self._ip == 1 - class IPv6Address(_BaseV6, _BaseAddress): @@ -1884,6 +1763,138 @@ """The binary representation of this address.""" return v6_int_to_packed(self._ip) + @property + def is_multicast(self): + """Test if the address is reserved for multicast use. + + Returns: + A boolean, True if the address is a multicast address. + See RFC 2373 2.7 for details. + + """ + multicast_network = IPv6Network('ff00::/8') + return self in multicast_network + + @property + def is_reserved(self): + """Test if the address is otherwise IETF reserved. + + Returns: + A boolean, True if the address is within one of the + reserved IPv6 Network ranges. + + """ + reserved_networks = [IPv6Network('::/8'), IPv6Network('100::/8'), + IPv6Network('200::/7'), IPv6Network('400::/6'), + IPv6Network('800::/5'), IPv6Network('1000::/4'), + IPv6Network('4000::/3'), IPv6Network('6000::/3'), + IPv6Network('8000::/3'), IPv6Network('A000::/3'), + IPv6Network('C000::/3'), IPv6Network('E000::/4'), + IPv6Network('F000::/5'), IPv6Network('F800::/6'), + IPv6Network('FE00::/9')] + + return any(self in x for x in reserved_networks) + + @property + def is_link_local(self): + """Test if the address is reserved for link-local. + + Returns: + A boolean, True if the address is reserved per RFC 4291. + + """ + linklocal_network = IPv6Network('fe80::/10') + return self in linklocal_network + + @property + def is_site_local(self): + """Test if the address is reserved for site-local. + + Note that the site-local address space has been deprecated by RFC 3879. + Use is_private to test if this address is in the space of unique local + addresses as defined by RFC 4193. + + Returns: + A boolean, True if the address is reserved per RFC 3513 2.5.6. + + """ + sitelocal_network = IPv6Network('fec0::/10') + return self in sitelocal_network + + @property + def is_private(self): + """Test if this address is allocated for private networks. + + Returns: + A boolean, True if the address is reserved per RFC 4193. + + """ + private_network = IPv6Network('fc00::/7') + return self in private_network + + @property + def is_unspecified(self): + """Test if the address is unspecified. + + Returns: + A boolean, True if this is the unspecified address as defined in + RFC 2373 2.5.2. + + """ + return self._ip == 0 + + @property + def is_loopback(self): + """Test if the address is a loopback address. + + Returns: + A boolean, True if the address is a loopback address as defined in + RFC 2373 2.5.3. + + """ + return self._ip == 1 + + @property + def ipv4_mapped(self): + """Return the IPv4 mapped address. + + Returns: + If the IPv6 address is a v4 mapped address, return the + IPv4 mapped address. Return None otherwise. + + """ + if (self._ip >> 32) != 0xFFFF: + return None + return IPv4Address(self._ip & 0xFFFFFFFF) + + @property + def teredo(self): + """Tuple of embedded teredo IPs. + + Returns: + Tuple of the (server, client) IPs or None if the address + doesn't appear to be a teredo address (doesn't start with + 2001::/32) + + """ + if (self._ip >> 96) != 0x20010000: + return None + return (IPv4Address((self._ip >> 64) & 0xFFFFFFFF), + IPv4Address(~self._ip & 0xFFFFFFFF)) + + @property + def sixtofour(self): + """Return the IPv4 6to4 embedded address. + + Returns: + The IPv4 6to4-embedded address if present or None if the + address doesn't appear to contain a 6to4 embedded address. + + """ + if (self._ip >> 112) != 0x2002: + return None + return IPv4Address((self._ip >> 80) & 0xFFFFFFFF) + class IPv6Interface(IPv6Address): @@ -1932,10 +1943,6 @@ return self._ip ^ self._prefixlen ^ int(self.network.network_address) @property - def prefixlen(self): - return self._prefixlen - - @property def ip(self): return IPv6Address(self._ip) @@ -1952,6 +1959,14 @@ return '%s/%s' % (self._string_from_ip_int(self._ip), self.hostmask) + @property + def is_unspecified(self): + return self._ip == 0 and self.network.is_unspecified + + @property + def is_loopback(self): + return self._ip == 1 and self.network.is_loopback + class IPv6Network(_BaseV6, _BaseNetwork): @@ -2060,3 +2075,18 @@ except ValueError: return False return 0 <= prefixlen <= self._max_prefixlen + + @property + def is_site_local(self): + """Test if the address is reserved for site-local. + + Note that the site-local address space has been deprecated by RFC 3879. + Use is_private to test if this address is in the space of unique local + addresses as defined by RFC 4193. + + Returns: + A boolean, True if the address is reserved per RFC 3513 2.5.6. + + """ + return (self.network_address.is_site_local and + self.broadcast_address.is_site_local) diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -313,6 +313,8 @@ class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler): pass + linesep = os.linesep.encode('ascii') + def setUp(self): BaseTestCase.setUp(self) self.cwd = os.getcwd() @@ -410,7 +412,7 @@ def test_headers_and_content(self): res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_post(self): @@ -419,7 +421,7 @@ headers = {'Content-type' : 'application/x-www-form-urlencoded'} res = self.request('/cgi-bin/file2.py', 'POST', params, headers) - self.assertEqual(res.read(), b'1, python, 123456\n') + self.assertEqual(res.read(), b'1, python, 123456' + self.linesep) def test_invaliduri(self): res = self.request('/cgi-bin/invalid') @@ -430,20 +432,20 @@ headers = {b'Authorization' : b'Basic ' + base64.b64encode(b'username:pass')} res = self.request('/cgi-bin/file1.py', 'GET', headers=headers) - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_no_leading_slash(self): # http://bugs.python.org/issue2254 res = self.request('cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) def test_os_environ_is_not_altered(self): signature = "Test CGI Server" os.environ['SERVER_SOFTWARE'] = signature res = self.request('/cgi-bin/file1.py') - self.assertEqual((b'Hello World\n', 'text/html', 200), + self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), (res.read(), res.getheader('Content-type'), res.status)) self.assertEqual(os.environ['SERVER_SOFTWARE'], signature) diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -7,6 +7,7 @@ import unittest import re import contextlib +import operator import ipaddress class BaseTestCase(unittest.TestCase): @@ -72,6 +73,14 @@ with self.assertAddressError(re.escape(repr("1.0"))): self.factory(1.0) + def test_not_an_index_issue15559(self): + # Implementing __index__ makes for a very nasty interaction with the + # bytes constructor. Thus, we disallow implicit use as an integer + self.assertRaises(TypeError, operator.index, self.factory(1)) + self.assertRaises(TypeError, hex, self.factory(1)) + self.assertRaises(TypeError, bytes, self.factory(1)) + + class CommonTestMixin_v4(CommonTestMixin): def test_leading_zeros(self): @@ -599,7 +608,6 @@ self.assertEqual(first, last) self.assertEqual(128, ipaddress._count_righthand_zero_bits(0, 128)) self.assertEqual("IPv4Network('1.2.3.0/24')", repr(self.ipv4_network)) - self.assertEqual('0x1020318', hex(self.ipv4_network)) def testMissingAddressVersion(self): class Broken(ipaddress._BaseAddress): @@ -639,8 +647,8 @@ ipv4 = ipaddress.ip_network('1.2.3.4') ipv6 = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1') - self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4))) - self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6))) + self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4.network_address))) + self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6.network_address))) v6_int = 42540616829182469433547762482097946625 self.assertEqual(self.ipv6_interface._ip, @@ -723,8 +731,8 @@ '2001:658:22a:cafe:ffff:ffff:ffff:ffff') def testGetPrefixlen(self): - self.assertEqual(self.ipv4_interface.prefixlen, 24) - self.assertEqual(self.ipv6_interface.prefixlen, 64) + self.assertEqual(self.ipv4_interface.network.prefixlen, 24) + self.assertEqual(self.ipv6_interface.network.prefixlen, 64) def testGetSupernet(self): self.assertEqual(self.ipv4_network.supernet().prefixlen, 23) @@ -1545,13 +1553,6 @@ self.assertEqual(42540616829182469433547762482097946625, int(self.ipv6_address)) - def testHexRepresentation(self): - self.assertEqual(hex(0x1020304), - hex(self.ipv4_address)) - - self.assertEqual(hex(0x20010658022ACAFE0200000000000001), - hex(self.ipv6_address)) - def testForceVersion(self): self.assertEqual(ipaddress.ip_network(1).version, 4) self.assertEqual(ipaddress.IPv6Network(1).version, 6) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,8 +77,12 @@ Library ------- -- Issue #15546: Fix handling of pathological input data in the read1() method of - the BZ2File, GzipFile and LZMAFile classes. +- Issue #15559: To avoid a problematic failure mode when passed to the bytes + constructor, objects in the ipaddress module no longer implement __index__ + (they still implement __int__ as appropriate) + +- Issue #15546: Fix handling of pathological input data in the peek() and + read1() methods of the BZ2File, GzipFile and LZMAFile classes. - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:17:38 2012 From: python-checkins at python.org (ned.deily) Date: Mon, 6 Aug 2012 00:17:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NTYw?= =?utf-8?q?=3A_Fix_building_=5Fsqlite3_extension_on_OS_X_with_an_SDK=2E?= Message-ID: <3WqxFG5zpPzPgD@mail.python.org> http://hg.python.org/cpython/rev/ef6c6d8adcf5 changeset: 78442:ef6c6d8adcf5 branch: 2.7 parent: 78424:322da186cced user: Ned Deily date: Sun Aug 05 14:42:45 2012 -0700 summary: Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. files: Misc/NEWS | 2 ++ setup.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -327,6 +327,8 @@ Build ----- +- Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. + - Issue #8847: Disable COMDAT folding in Windows PGO builds. - Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1028,12 +1028,12 @@ if sys.platform == 'darwin': sysroot = macosx_sdk_root() - for d in inc_dirs + sqlite_inc_paths: + for d_ in inc_dirs + sqlite_inc_paths: + d = d_ + if sys.platform == 'darwin' and is_macosx_sdk_path(d): + d = os.path.join(sysroot, d[1:]) + f = os.path.join(d, "sqlite3.h") - - if sys.platform == 'darwin' and is_macosx_sdk_path(d): - f = os.path.join(sysroot, d[1:], "sqlite3.h") - if os.path.exists(f): if sqlite_setup_debug: print "sqlite: found %s"%f incf = open(f).read() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:17:40 2012 From: python-checkins at python.org (ned.deily) Date: Mon, 6 Aug 2012 00:17:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NTYw?= =?utf-8?q?=3A_Fix_building_=5Fsqlite3_extension_on_OS_X_with_an_SDK=2E?= Message-ID: <3WqxFJ322zzPmY@mail.python.org> http://hg.python.org/cpython/rev/ee0ac9a0461f changeset: 78443:ee0ac9a0461f branch: 3.2 parent: 78433:bc4fdb758b8c user: Ned Deily date: Sun Aug 05 14:56:21 2012 -0700 summary: Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. files: Misc/NEWS | 2 ++ setup.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -440,6 +440,8 @@ Build ----- +- Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. + - Issue #8847: Disable COMDAT folding in Windows PGO builds. - Issue #14197: For OS X framework builds, ensure links to the shared diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -981,12 +981,12 @@ if sys.platform == 'darwin': sysroot = macosx_sdk_root() - for d in inc_dirs + sqlite_inc_paths: + for d_ in inc_dirs + sqlite_inc_paths: + d = d_ + if sys.platform == 'darwin' and is_macosx_sdk_path(d): + d = os.path.join(sysroot, d[1:]) + f = os.path.join(d, "sqlite3.h") - - if sys.platform == 'darwin' and is_macosx_sdk_path(d): - f = os.path.join(sysroot, d[1:], "sqlite3.h") - if os.path.exists(f): if sqlite_setup_debug: print("sqlite: found %s"%f) with open(f) as file: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:17:41 2012 From: python-checkins at python.org (ned.deily) Date: Mon, 6 Aug 2012 00:17:41 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315560=3A_null_merge?= Message-ID: <3WqxFK6YcczPmN@mail.python.org> http://hg.python.org/cpython/rev/d706a6f4724c changeset: 78444:d706a6f4724c parent: 78439:80a1ae3a1b39 parent: 78443:ee0ac9a0461f user: Ned Deily date: Sun Aug 05 15:12:20 2012 -0700 summary: Issue #15560: null merge files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:17:43 2012 From: python-checkins at python.org (ned.deily) Date: Mon, 6 Aug 2012 00:17:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315560=3A_Fix_buil?= =?utf-8?q?ding_=5Fsqlite3_extension_on_OS_X_with_an_SDK=2E?= Message-ID: <3WqxFM2tySzPfM@mail.python.org> http://hg.python.org/cpython/rev/6af33673e955 changeset: 78445:6af33673e955 user: Ned Deily date: Sun Aug 05 15:13:33 2012 -0700 summary: Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. files: Misc/NEWS | 2 ++ setup.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -304,6 +304,8 @@ Build ----- +- Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. + - Issue #8847: Disable COMDAT folding in Windows PGO builds. - Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1041,12 +1041,12 @@ if host_platform == 'darwin': sysroot = macosx_sdk_root() - for d in inc_dirs + sqlite_inc_paths: + for d_ in inc_dirs + sqlite_inc_paths: + d = d_ + if host_platform == 'darwin' and is_macosx_sdk_path(d): + d = os.path.join(sysroot, d[1:]) + f = os.path.join(d, "sqlite3.h") - - if host_platform == 'darwin' and is_macosx_sdk_path(d): - f = os.path.join(sysroot, d[1:], "sqlite3.h") - if os.path.exists(f): if sqlite_setup_debug: print("sqlite: found %s"%f) with open(f) as file: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:17:44 2012 From: python-checkins at python.org (ned.deily) Date: Mon, 6 Aug 2012 00:17:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3WqxFN69RLzPfN@mail.python.org> http://hg.python.org/cpython/rev/099639507383 changeset: 78446:099639507383 parent: 78445:6af33673e955 parent: 78441:a8b05f3c14fc user: Ned Deily date: Sun Aug 05 15:16:04 2012 -0700 summary: merge heads files: Lib/test/test_unicode.py | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) 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 @@ -572,6 +572,7 @@ self.assertEqual('?'.casefold(), 'fi') self.assertEqual('\u03a3'.casefold(), '\u03c3') self.assertEqual('A\u0345\u03a3'.casefold(), 'a\u03b9\u03c3') + self.assertEqual('\u00b5'.casefold(), '\u03bc') def test_upper(self): string_tests.CommonTest.test_upper(self) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 00:54:30 2012 From: python-checkins at python.org (victor.stinner) Date: Mon, 6 Aug 2012 00:54:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2313072=3A_Restore_?= =?utf-8?q?code_before_the_PEP_393_for_the_array_module?= Message-ID: <3Wqy3p6GbPzPck@mail.python.org> http://hg.python.org/cpython/rev/95da47ddebe0 changeset: 78447:95da47ddebe0 user: Victor Stinner date: Mon Aug 06 00:46:05 2012 +0200 summary: Close #13072: Restore code before the PEP 393 for the array module 'u' format of the array module uses again Py_UNICODE type for backward compatibility with Python 3.2. The only change from Python 3.2 is that PyUnicode_AsUnicode() result is now checked for NULL value. files: Doc/library/array.rst | 11 ++- Modules/arraymodule.c | 86 +++++++++++++++++------------- 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/Doc/library/array.rst b/Doc/library/array.rst --- a/Doc/library/array.rst +++ b/Doc/library/array.rst @@ -21,7 +21,7 @@ +-----------+--------------------+-------------------+-----------------------+-------+ | ``'B'`` | unsigned char | int | 1 | | +-----------+--------------------+-------------------+-----------------------+-------+ -| ``'u'`` | Py_UCS4 | Unicode character | 4 | | +| ``'u'`` | Py_UNICODE | Unicode character | 2 | \(1) | +-----------+--------------------+-------------------+-----------------------+-------+ | ``'h'`` | signed short | int | 2 | | +-----------+--------------------+-------------------+-----------------------+-------+ @@ -35,9 +35,9 @@ +-----------+--------------------+-------------------+-----------------------+-------+ | ``'L'`` | unsigned long | int | 4 | | +-----------+--------------------+-------------------+-----------------------+-------+ -| ``'q'`` | signed long long | int | 8 | \(1) | +| ``'q'`` | signed long long | int | 8 | \(2) | +-----------+--------------------+-------------------+-----------------------+-------+ -| ``'Q'`` | unsigned long long | int | 8 | \(1) | +| ``'Q'`` | unsigned long long | int | 8 | \(2) | +-----------+--------------------+-------------------+-----------------------+-------+ | ``'f'`` | float | float | 4 | | +-----------+--------------------+-------------------+-----------------------+-------+ @@ -47,6 +47,11 @@ Notes: (1) + The ``'u'`` type code corresponds to Python's unicode character + (:c:type:`Py_UNICODE` which is :c:type:`wchar_t`). Depending on the + platform, it can be 16 bits or 32 bits. + +(2) The ``'q'`` and ``'Q'`` type codes are available only if the platform C compiler used to build Python supports C :c:type:`long long`, or, on Windows, :c:type:`__int64`. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -174,25 +174,24 @@ static PyObject * u_getitem(arrayobject *ap, Py_ssize_t i) { - return PyUnicode_FromOrdinal(((Py_UCS4 *) ap->ob_item)[i]); + return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1); } static int u_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) { - PyObject *p; + Py_UNICODE *p; + Py_ssize_t len; - if (!PyArg_Parse(v, "U;array item must be unicode character", &p)) + if (!PyArg_Parse(v, "u#;array item must be unicode character", &p, &len)) return -1; - if (PyUnicode_READY(p)) - return -1; - if (PyUnicode_GET_LENGTH(p) != 1) { + if (len != 1) { PyErr_SetString(PyExc_TypeError, "array item must be unicode character"); return -1; } if (i >= 0) - ((Py_UCS4 *)ap->ob_item)[i] = PyUnicode_READ_CHAR(p, 0); + ((Py_UNICODE *)ap->ob_item)[i] = p[0]; return 0; } @@ -444,13 +443,6 @@ return 0; } -#if SIZEOF_INT == 4 -# define STRUCT_LONG_FORMAT "I" -#elif SIZEOF_LONG == 4 -# define STRUCT_LONG_FORMAT "L" -#else -# error "Unable to get struct format for Py_UCS4" -#endif /* Description of types. * @@ -460,7 +452,7 @@ static struct arraydescr descriptors[] = { {'b', 1, b_getitem, b_setitem, "b", 1, 1}, {'B', 1, BB_getitem, BB_setitem, "B", 1, 0}, - {'u', sizeof(Py_UCS4), u_getitem, u_setitem, STRUCT_LONG_FORMAT, 0, 0}, + {'u', sizeof(Py_UNICODE), u_getitem, u_setitem, "u", 0, 0}, {'h', sizeof(short), h_getitem, h_setitem, "h", 1, 1}, {'H', sizeof(short), HH_getitem, HH_setitem, "H", 1, 0}, {'i', sizeof(int), i_getitem, i_setitem, "i", 1, 1}, @@ -1519,26 +1511,25 @@ static PyObject * array_fromunicode(arrayobject *self, PyObject *args) { - PyObject *ustr; + Py_UNICODE *ustr; Py_ssize_t n; + char typecode; - if (!PyArg_ParseTuple(args, "U:fromunicode", &ustr)) + if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n)) return NULL; - if (self->ob_descr->typecode != 'u') { + typecode = self->ob_descr->typecode; + if ((typecode != 'u')) { PyErr_SetString(PyExc_ValueError, "fromunicode() may only be called on " "unicode type arrays"); return NULL; } - if (PyUnicode_READY(ustr)) - return NULL; - n = PyUnicode_GET_LENGTH(ustr); if (n > 0) { Py_ssize_t old_size = Py_SIZE(self); if (array_resize(self, old_size + n) == -1) return NULL; - if (!PyUnicode_AsUCS4(ustr, (Py_UCS4 *)self->ob_item + old_size, n, 0)) - return NULL; + memcpy(self->ob_item + old_size * sizeof(Py_UNICODE), + ustr, n * sizeof(Py_UNICODE)); } Py_INCREF(Py_None); @@ -1557,14 +1548,14 @@ static PyObject * array_tounicode(arrayobject *self, PyObject *unused) { - if (self->ob_descr->typecode != 'u') { + char typecode; + typecode = self->ob_descr->typecode; + if ((typecode != 'u')) { PyErr_SetString(PyExc_ValueError, "tounicode() may only be called on unicode type arrays"); return NULL; } - return PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, - (Py_UCS4 *) self->ob_item, - Py_SIZE(self)); + return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, Py_SIZE(self)); } PyDoc_STRVAR(tounicode_doc, @@ -1671,7 +1662,13 @@ return UNSIGNED_INT8; case 'u': - return UTF32_LE + is_big_endian; + if (sizeof(Py_UNICODE) == 2) { + return UTF16_LE + is_big_endian; + } + if (sizeof(Py_UNICODE) == 4) { + return UTF32_LE + is_big_endian; + } + return UNKNOWN_FORMAT; case 'f': if (sizeof(float) == 4) { @@ -2419,8 +2416,14 @@ view->strides = &(view->itemsize); view->format = NULL; view->internal = NULL; - if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) + if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) { view->format = self->ob_descr->formats; +#ifdef Py_UNICODE_WIDE + if (self->ob_descr->typecode == 'u') { + view->format = "w"; + } +#endif + } finish: self->ob_exports++; @@ -2534,25 +2537,29 @@ Py_DECREF(v); } else if (initial != NULL && PyUnicode_Check(initial)) { + Py_UNICODE *ustr; Py_ssize_t n; - if (PyUnicode_READY(initial)) { + + ustr = PyUnicode_AsUnicode(initial); + if (ustr == NULL) { + PyErr_NoMemory(); Py_DECREF(a); return NULL; } - n = PyUnicode_GET_LENGTH(initial); + + n = PyUnicode_GET_DATA_SIZE(initial); if (n > 0) { arrayobject *self = (arrayobject *)a; - Py_UCS4 *item = (Py_UCS4 *)self->ob_item; - item = (Py_UCS4 *)PyMem_Realloc(item, n * sizeof(Py_UCS4)); + char *item = self->ob_item; + item = (char *)PyMem_Realloc(item, n); if (item == NULL) { PyErr_NoMemory(); Py_DECREF(a); return NULL; } - self->ob_item = (char*)item; - Py_SIZE(self) = n; - if (!PyUnicode_AsUCS4(initial, item, n, 0)) - return NULL; + self->ob_item = item; + Py_SIZE(self) = n / sizeof(Py_UNICODE); + memcpy(item, ustr, n); self->allocated = Py_SIZE(self); } } @@ -2593,7 +2600,7 @@ Type code C Type Minimum size in bytes \n\ 'b' signed integer 1 \n\ 'B' unsigned integer 1 \n\ - 'u' Unicode character 4 \n\ + 'u' Unicode character 2 (see note) \n\ 'h' signed integer 2 \n\ 'H' unsigned integer 2 \n\ 'i' signed integer 2 \n\ @@ -2605,6 +2612,9 @@ 'f' floating point 4 \n\ 'd' floating point 8 \n\ \n\ +NOTE: The 'u' typecode corresponds to Python's unicode character. On \n\ +narrow builds this is 2-bytes on wide builds this is 4-bytes.\n\ +\n\ NOTE: The 'q' and 'Q' type codes are only available if the platform \n\ C compiler used to build Python supports 'long long', or, on Windows, \n\ '__int64'.\n\ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 01:53:10 2012 From: python-checkins at python.org (brett.cannon) Date: Mon, 6 Aug 2012 01:53:10 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_a_spelling_mistake_in_?= =?utf-8?q?a_comment=2E?= Message-ID: <3WqzMV20qFzPmF@mail.python.org> http://hg.python.org/cpython/rev/9066dca1a9b3 changeset: 78448:9066dca1a9b3 user: Brett Cannon date: Sun Aug 05 19:24:57 2012 -0400 summary: Fix a spelling mistake in a comment. files: Python/import.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -1243,7 +1243,7 @@ } else { /* Only have to care what given_globals is if it will be used - fortsomething. */ + for something. */ if (level > 0 && !PyDict_Check(given_globals)) { PyErr_SetString(PyExc_TypeError, "globals must be a dict"); goto error; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 02:50:10 2012 From: python-checkins at python.org (brett.cannon) Date: Mon, 6 Aug 2012 02:50:10 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NDgy?= =?utf-8?q?=3A_Properly_document_the_default_=27level=27_parameter_for?= Message-ID: <3Wr0dG6dmszPlk@mail.python.org> http://hg.python.org/cpython/rev/3fe01f7520e2 changeset: 78449:3fe01f7520e2 branch: 3.2 parent: 78443:ee0ac9a0461f user: Brett Cannon date: Sun Aug 05 20:46:25 2012 -0400 summary: Issue #15482: Properly document the default 'level' parameter for __import__(). To help explain why the -1 default value is typically not seen, a note about how import statements only use values of >= 0 is also noted. files: Doc/library/functions.rst | 13 ++++++++----- Misc/NEWS | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1410,7 +1410,7 @@ True -.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=0) +.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=-1) .. index:: statement: import @@ -1435,10 +1435,13 @@ not use its *locals* argument at all, and uses its *globals* only to determine the package context of the :keyword:`import` statement. - *level* specifies whether to use absolute or relative imports. ``0`` (the - default) means only perform absolute imports. Positive values for - *level* indicate the number of parent directories to search relative to the - directory of the module calling :func:`__import__`. + *level* specifies whether to use absolute or relative imports. ``0`` + means only perform absolute imports. Positive values for *level* indicate the + number of parent directories to search relative to the directory of the + module calling :func:`__import__`. Negative values attempt both an implicit + relative import and an absolute import (usage of negative values for *level* + are strongly discouraged as future versions of Python do not support such + values). Import statements only use values of 0 or greater. When the *name* variable is of the form ``package.module``, normally, the top-level package (the name up till the first dot) is returned, *not* the diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -465,6 +465,9 @@ Documentation ------------- +- Issue 15482: Properly document the default 'level' value for __import__() + while warning about using negative values. + - Issue #15230: Clearly document some of the limitations of the runpy module and nudge readers towards importlib when appropriate. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 02:50:12 2012 From: python-checkins at python.org (brett.cannon) Date: Mon, 6 Aug 2012 02:50:12 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315482=3A_Merge_78449=3A3fe01f7520e2_with_a_mino?= =?utf-8?q?r_clarification=2E?= Message-ID: <3Wr0dJ4rdmzPm8@mail.python.org> http://hg.python.org/cpython/rev/05bec2e78a5c changeset: 78450:05bec2e78a5c parent: 78448:9066dca1a9b3 parent: 78449:3fe01f7520e2 user: Brett Cannon date: Sun Aug 05 20:49:53 2012 -0400 summary: Issue #15482: Merge 78449:3fe01f7520e2 with a minor clarification. files: Doc/library/functions.rst | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1507,7 +1507,8 @@ use :func:`importlib.import_module`. .. versionchanged:: 3.3 - Negative values for *level* are no longer supported. + Negative values for *level* are no longer supported (which also changes + the default value to 0). .. rubric:: Footnotes -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Aug 6 06:03:15 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 06 Aug 2012 06:03:15 +0200 Subject: [Python-checkins] Daily reference leaks (05bec2e78a5c): sum=0 Message-ID: results for 05bec2e78a5c on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogNOoeU7', '-x'] From python-checkins at python.org Mon Aug 6 15:42:43 2012 From: python-checkins at python.org (ned.deily) Date: Mon, 6 Aug 2012 15:42:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_OS_X_installer_cleanups=3A?= Message-ID: <3WrKmg4w85zPnf@mail.python.org> http://hg.python.org/cpython/rev/6280c13d907c changeset: 78451:6280c13d907c user: Ned Deily date: Mon Aug 06 06:34:00 2012 -0700 summary: OS X installer cleanups: - Remove OS X installer and Mac/Makefile dependencies on /Developer which no longer exists with Xcode 4; the referenced tools have been installed into the usr/bin tool root since Xcode 3. - Support adding the SDK usr/bin tool root to the installer's PATH via the SDK_TOOLS_BIN environment variable. files: Mac/BuildScript/build-installer.py | 32 ++++++++++++++--- Mac/Makefile.in | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ This script is used to build "official" universal installers on Mac OS X. -It requires at least Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK for +It requires at least Mac OS X 10.5, Xcode 3, and the 10.4u SDK for 32-bit builds. 64-bit or four-way universal builds require at least OS X 10.5 and the 10.5 SDK. @@ -10,6 +10,20 @@ which is used to build the documentation, currently requires at least Python 2.4. +In addition to what is supplied with OS X 10.5+ and Xcode 3+, the script +requires an installed version of hg and a third-party version of +Tcl/Tk 8.4 (for OS X 10.4 and 10.5 deployment targets) or Tcl/TK 8.5 +(for 10.6 or later) installed in /Library/Frameworks. When installed, +the Python built by this script will attempt to dynamically link first to +Tcl and Tk frameworks in /Library/Frameworks if available otherwise fall +back to the ones in /System/Library/Framework. For the build, we recommend +installing the most recent ActiveTcl 8.4 or 8.5 version. + +32-bit-only installer builds are still possible on OS X 10.4 with Xcode 2.5 +and the installation of additional components, such as a newer Python +(2.5 is needed for Python parser updates), hg, and svn (for the documentation +build). + Usage: see USAGE variable in the script. """ import platform, os, sys, getopt, textwrap, shutil, stat, time, pwd, grp @@ -342,9 +356,7 @@ source="/pydocs", readme="""\ This package installs the python documentation at a location - that is useable for pydoc and IDLE. If you have installed Xcode - it will also install a link to the documentation in - /Developer/Documentation/Python + that is useable for pydoc and IDLE. """, postflight="scripts/postflight.documentation", required=False, @@ -511,7 +523,15 @@ ev, os.environ[ev])) del os.environ[ev] - os.environ['PATH'] = '/bin:/sbin:/usr/bin:/usr/sbin' + base_path = '/bin:/sbin:/usr/bin:/usr/sbin' + if 'SDK_TOOLS_BIN' in os.environ: + base_path = os.environ['SDK_TOOLS_BIN'] + ':' + base_path + # Xcode 2.5 on OS X 10.4 does not include SetFile in its usr/bin; + # add its fixed location here if it exists + OLD_DEVELOPER_TOOLS = '/Developer/Tools' + if os.path.isdir(OLD_DEVELOPER_TOOLS): + base_path = base_path + ':' + OLD_DEVELOPER_TOOLS + os.environ['PATH'] = base_path print("Setting default PATH: %s"%(os.environ['PATH'])) @@ -1204,7 +1224,7 @@ # Custom icon for the DMG, shown when the DMG is mounted. shutil.copy("../Icons/Disk Image.icns", os.path.join(WORKDIR, "mnt", volname, ".VolumeIcon.icns")) - runCommand("/Developer/Tools/SetFile -a C %s/"%( + runCommand("SetFile -a C %s/"%( shellQuote(os.path.join(WORKDIR, "mnt", volname)),)) runCommand("hdiutil detach %s"%(shellQuote(os.path.join(WORKDIR, "mnt", volname)))) diff --git a/Mac/Makefile.in b/Mac/Makefile.in --- a/Mac/Makefile.in +++ b/Mac/Makefile.in @@ -40,7 +40,7 @@ INSTALL_DATA=@INSTALL_DATA@ LN=@LN@ STRIPFLAG=-s -CPMAC=/Developer/Tools/CpMac +CPMAC=CpMac APPTEMPLATE=$(srcdir)/Resources/app APPSUBDIRS=MacOS Resources -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 15:42:46 2012 From: python-checkins at python.org (ned.deily) Date: Mon, 6 Aug 2012 15:42:46 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315037=3A_Build_OS?= =?utf-8?q?_X_installers_with_local_copy_of_ncurses_5=2E9_libraries?= Message-ID: <3WrKmk2Y96zPpH@mail.python.org> http://hg.python.org/cpython/rev/8282e4846e43 changeset: 78452:8282e4846e43 user: Ned Deily date: Mon Aug 06 06:40:48 2012 -0700 summary: Issue #15037: Build OS X installers with local copy of ncurses 5.9 libraries to avoid curses.unget_wch bug present in older versions of ncurses such as those shipped with OS X. files: Mac/BuildScript/build-installer.py | 158 +++++++++------- Mac/BuildScript/ncurses-5.5.patch | 36 --- Misc/NEWS | 4 + 3 files changed, 93 insertions(+), 105 deletions(-) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -198,7 +198,43 @@ configure_pre=[ '--disable-dependency-tracking', ] - ) + ), + dict( + name="NCurses 5.9", + url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz", + checksum='8cb9c412e5f2d96bc6f459aa8c6282a1', + configure_pre=[ + "--enable-widec", + "--without-cxx", + "--without-cxx-binding", + "--without-ada", + "--without-curses-h", + "--enable-shared", + "--with-shared", + "--without-debug", + "--without-normal", + "--without-termlib", + "--without-ticlib", + "--without-tests", + "--without-manpages", + "--datadir=/usr/share", + "--sysconfdir=/etc", + "--sharedstatedir=/usr/com", + "--with-terminfo-dirs=/usr/share/terminfo", + "--with-default-terminfo-dir=/usr/share/terminfo", + "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), + ], + patchscripts=[ + ("ftp://invisible-island.net/ncurses//5.9/ncurses-5.9-20120616-patch.sh.bz2", + "f54bf02a349f96a7c4f0d00922f3a0d4"), + ], + useLDFlags=False, + install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( + shellQuote(os.path.join(WORKDIR, 'libraries')), + shellQuote(os.path.join(WORKDIR, 'libraries')), + getVersion(), + ), + ), ]) if DEPTARGET < '10.5': @@ -236,8 +272,10 @@ patches=[ # The readline maintainers don't do actual micro releases, but # just ship a set of patches. - 'http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-001', - 'http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-002', + ('http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-001', + 'c642f2e84d820884b0bf9fd176bc6c3f'), + ('http://ftp.gnu.org/pub/gnu/readline/readline-6.1-patches/readline61-002', + '1a76781a1ea734e831588285db7ec9b1'), ] ), dict( @@ -258,36 +296,6 @@ '--disable-dependency-tracking', ] ), - dict( - name="NCurses 5.5", - url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.5.tar.gz", - checksum='e73c1ac10b4bfc46db43b2ddfd6244ef', - configure_pre=[ - "--enable-widec", - "--without-cxx", - "--without-ada", - "--without-progs", - "--without-curses-h", - "--enable-shared", - "--with-shared", - "--datadir=/usr/share", - "--sysconfdir=/etc", - "--sharedstatedir=/usr/com", - "--with-terminfo-dirs=/usr/share/terminfo", - "--with-default-terminfo-dir=/usr/share/terminfo", - "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), - "--enable-termcap", - ], - patches=[ - "ncurses-5.5.patch", - ], - useLDFlags=False, - install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( - shellQuote(os.path.join(WORKDIR, 'libraries')), - shellQuote(os.path.join(WORKDIR, 'libraries')), - getVersion(), - ), - ), ]) if not PYTHON_3: @@ -660,23 +668,10 @@ finally: os.chdir(curdir) -KNOWNSIZES = { - "http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz": 7952742, - "http://downloads.sleepycat.com/db-4.4.20.tar.gz": 2030276, -} - def downloadURL(url, fname): """ Download the contents of the url into the file. """ - try: - size = os.path.getsize(fname) - except OSError: - pass - else: - if KNOWNSIZES.get(url) == size: - print("Using existing file for", url) - return fpIn = urllib_request.urlopen(url) fpOut = open(fname, 'wb') block = fpIn.read(10240) @@ -692,6 +687,24 @@ except: pass +def verifyThirdPartyFile(url, checksum, fname): + """ + Download file from url to filename fname if it does not already exist. + Abort if file contents does not match supplied md5 checksum. + """ + name = os.path.basename(fname) + if os.path.exists(fname): + print("Using local copy of %s"%(name,)) + else: + print("Did not find local copy of %s"%(name,)) + print("Downloading %s"%(name,)) + downloadURL(url, fname) + print("Archive for %s stored as %s"%(name, fname)) + if os.system( + 'MD5=$(openssl md5 %s) ; test "${MD5##*= }" = "%s"' + % (shellQuote(fname), checksum) ): + fatal('MD5 checksum mismatch for file %s' % fname) + def buildRecipe(recipe, basedir, archList): """ Build software using a recipe. This function does the @@ -712,16 +725,7 @@ if not os.path.exists(DEPSRC): os.mkdir(DEPSRC) - - if os.path.exists(sourceArchive): - print("Using local copy of %s"%(name,)) - - else: - print("Did not find local copy of %s"%(name,)) - print("Downloading %s"%(name,)) - downloadURL(url, sourceArchive) - print("Archive for %s stored as %s"%(name, sourceArchive)) - + verifyThirdPartyFile(url, recipe['checksum'], sourceArchive) print("Extracting archive for %s"%(name,)) buildDir=os.path.join(WORKDIR, '_bld') if not os.path.exists(buildDir): @@ -732,18 +736,31 @@ if 'buildDir' in recipe: os.chdir(recipe['buildDir']) - - for fn in recipe.get('patches', ()): - if fn.startswith('http://'): - # Download the patch before applying it. - path = os.path.join(DEPSRC, os.path.basename(fn)) - downloadURL(fn, path) - fn = path - - fn = os.path.join(curdir, fn) + for patch in recipe.get('patches', ()): + if isinstance(patch, tuple): + url, checksum = patch + fn = os.path.join(DEPSRC, os.path.basename(url)) + verifyThirdPartyFile(url, checksum, fn) + else: + # patch is a file in the source directory + fn = os.path.join(curdir, patch) runCommand('patch -p%s < %s'%(recipe.get('patchlevel', 1), shellQuote(fn),)) + for patchscript in recipe.get('patchscripts', ()): + if isinstance(patchscript, tuple): + url, checksum = patchscript + fn = os.path.join(DEPSRC, os.path.basename(url)) + verifyThirdPartyFile(url, checksum, fn) + else: + # patch is a file in the source directory + fn = os.path.join(curdir, patchscript) + if fn.endswith('.bz2'): + runCommand('bunzip2 -fk %s' % shellQuote(fn)) + fn = fn[:-4] + runCommand('sh %s' % shellQuote(fn)) + os.unlink(fn) + if configure is not None: configure_args = [ "--prefix=/usr/local", @@ -762,25 +779,28 @@ if recipe.get('useLDFlags', 1): configure_args.extend([ - "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( + "CFLAGS=-mmacosx-version-min=%s -arch %s -isysroot %s -I%s/usr/local/include"%( + DEPTARGET, ' -arch '.join(archList), shellQuote(SDKPATH)[1:-1], shellQuote(basedir)[1:-1],), - "LDFLAGS=-syslibroot,%s -L%s/usr/local/lib -arch %s"%( + "LDFLAGS=-mmacosx-version-min=%s -syslibroot,%s -L%s/usr/local/lib -arch %s"%( + DEPTARGET, shellQuote(SDKPATH)[1:-1], shellQuote(basedir)[1:-1], ' -arch '.join(archList)), ]) else: configure_args.extend([ - "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( + "CFLAGS=-mmacosx-version-min=%s -arch %s -isysroot %s -I%s/usr/local/include"%( + DEPTARGET, ' -arch '.join(archList), shellQuote(SDKPATH)[1:-1], shellQuote(basedir)[1:-1],), ]) if 'configure_post' in recipe: - configure_args = configure_args = list(recipe['configure_post']) + configure_args = configure_args + list(recipe['configure_post']) configure_args.insert(0, configure) configure_args = [ shellQuote(a) for a in configure_args ] diff --git a/Mac/BuildScript/ncurses-5.5.patch b/Mac/BuildScript/ncurses-5.5.patch deleted file mode 100644 --- a/Mac/BuildScript/ncurses-5.5.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff -r -u ncurses-5.5-orig/test/Makefile.in ncurses-5.5/test/Makefile.in ---- ncurses-5.5-orig/test/Makefile.in 2006-03-24 12:47:40.000000000 +0100 -+++ ncurses-5.5/test/Makefile.in 2006-03-24 12:47:50.000000000 +0100 -@@ -75,7 +75,7 @@ - MATH_LIB = @MATH_LIB@ - - LD = @LD@ --LINK = @LINK_TESTS@ $(LIBTOOL_LINK) $(CC) $(CFLAGS) -+LINK = @LINK_TESTS@ $(LIBTOOL_LINK) $(CC) - - usFLAGS = @LD_MODEL@ @LOCAL_LDFLAGS@ @LDFLAGS@ - -diff -ru ncurses-5.5-orig/ncurses/tinfo/read_entry.c ncurses-5.5/ncurses/tinfo/read_entry.c ---- ncurses-5.5-orig/ncurses/tinfo/read_entry.c 2004-01-11 02:57:05.000000000 +0100 -+++ ncurses-5.5/ncurses/tinfo/read_entry.c 2006-03-25 22:49:39.000000000 +0100 -@@ -474,7 +474,7 @@ - } - - /* truncate the terminal name to prevent buffer overflow */ -- (void) sprintf(ttn, "%c/%.*s", *tn, (int) sizeof(ttn) - 3, tn); -+ (void) sprintf(ttn, "%x/%.*s", *tn, (int) sizeof(ttn) - 3, tn); - - /* This is System V behavior, in conjunction with our requirements for - * writing terminfo entries. -diff -ru ncurses-5.5-orig/configure ncurses-5.5/configure ---- ncurses-5.5-orig/configure 2005-09-24 23:50:50.000000000 +0200 -+++ ncurses-5.5/configure 2006-03-26 22:24:59.000000000 +0200 -@@ -5027,7 +5027,7 @@ - darwin*) - EXTRA_CFLAGS="-no-cpp-precomp" - CC_SHARED_OPTS="-dynamic" -- MK_SHARED_LIB='$(CC) -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $@` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $@' -+ MK_SHARED_LIB='$(CC) $(CFLAGS) -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $@` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $@' - test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=abi - cf_cv_shlib_version_infix=yes - ;; diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -304,6 +304,10 @@ Build ----- +- Issue #15037: Build OS X installers with local copy of ncurses 5.9 libraries + to avoid curses.unget_wch bug present in older versions of ncurses such as + those shipped with OS X. + - Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. - Issue #8847: Disable COMDAT folding in Windows PGO builds. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 22:09:48 2012 From: python-checkins at python.org (r.david.murray) Date: Mon, 6 Aug 2012 22:09:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1NTU0OiBjbGFy?= =?utf-8?q?ify_splitlines/split_differences=2E?= Message-ID: <3WrVMJ69P5zPmb@mail.python.org> http://hg.python.org/cpython/rev/768b188262e7 changeset: 78453:768b188262e7 branch: 3.2 parent: 78449:3fe01f7520e2 user: R David Murray date: Mon Aug 06 16:08:09 2012 -0400 summary: #15554: clarify splitlines/split differences. Patch by Chris Jerdonek. files: Doc/library/stdtypes.rst | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1327,16 +1327,19 @@ .. method:: str.splitlines([keepends]) - Return a list of the lines in the string, breaking at line boundaries. Line - breaks are not included in the resulting list unless *keepends* is given and - true. This method uses the universal newlines approach to splitting lines. - Unlike :meth:`~str.split`, if the string ends with line boundary characters - the returned list does ``not`` have an empty last element. + Return a list of the lines in the string, breaking at line boundaries. + This method uses the universal newlines approach to splitting lines. + Line breaks are not included in the resulting list unless *keepends* is + given and true. For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + Unlike :meth:`~str.split` when a delimiter string *sep* is given, this + method returns an empty list for the empty string, and a terminal line + break does not result in an extra line. + .. method:: str.startswith(prefix[, start[, end]]) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 22:09:50 2012 From: python-checkins at python.org (r.david.murray) Date: Mon, 6 Aug 2012 22:09:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315554=3A_clarify_splitlines/split_differences?= =?utf-8?q?=2E?= Message-ID: <3WrVML48pxzPpP@mail.python.org> http://hg.python.org/cpython/rev/0d6eea2330d0 changeset: 78454:0d6eea2330d0 parent: 78452:8282e4846e43 parent: 78453:768b188262e7 user: R David Murray date: Mon Aug 06 16:08:40 2012 -0400 summary: Merge #15554: clarify splitlines/split differences. Patch by Chris Jerdonek. files: Doc/library/stdtypes.rst | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1351,16 +1351,19 @@ .. method:: str.splitlines([keepends]) - Return a list of the lines in the string, breaking at line boundaries. Line - breaks are not included in the resulting list unless *keepends* is given and - true. This method uses the universal newlines approach to splitting lines. - Unlike :meth:`~str.split`, if the string ends with line boundary characters - the returned list does ``not`` have an empty last element. + Return a list of the lines in the string, breaking at line boundaries. + This method uses the universal newlines approach to splitting lines. + Line breaks are not included in the resulting list unless *keepends* is + given and true. For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + Unlike :meth:`~str.split` when a delimiter string *sep* is given, this + method returns an empty list for the empty string, and a terminal line + break does not result in an extra line. + .. method:: str.startswith(prefix[, start[, end]]) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 22:09:52 2012 From: python-checkins at python.org (r.david.murray) Date: Mon, 6 Aug 2012 22:09:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1NTU0OiBjbGFy?= =?utf-8?q?ify_splitlines/split_differences=2E?= Message-ID: <3WrVMN5KwHzPqm@mail.python.org> http://hg.python.org/cpython/rev/e057a7d18fa2 changeset: 78455:e057a7d18fa2 branch: 2.7 parent: 78442:ef6c6d8adcf5 user: R David Murray date: Mon Aug 06 16:09:09 2012 -0400 summary: #15554: clarify splitlines/split differences. Patch by Chris Jerdonek. files: Doc/library/stdtypes.rst | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1183,16 +1183,19 @@ .. method:: str.splitlines([keepends]) - Return a list of the lines in the string, breaking at line boundaries. Line - breaks are not included in the resulting list unless *keepends* is given and - true. This method uses the universal newlines approach to splitting lines. - Unlike :meth:`~str.split`, if the string ends with line boundary characters - the returned list does ``not`` have an empty last element. + Return a list of the lines in the string, breaking at line boundaries. + This method uses the universal newlines approach to splitting lines. + Line breaks are not included in the resulting list unless *keepends* is + given and true. For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + Unlike :meth:`~str.split` when a delimiter string *sep* is given, this + method returns an empty list for the empty string, and a terminal line + break does not result in an extra line. + .. method:: str.startswith(prefix[, start[, end]]) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 6 22:34:55 2012 From: python-checkins at python.org (brett.cannon) Date: Mon, 6 Aug 2012 22:34:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315471=3A_Don=27t_?= =?utf-8?q?use_mutable_object_as_default_values_for_the?= Message-ID: <3WrVwH18RxzPpR@mail.python.org> http://hg.python.org/cpython/rev/4240282a9f4a changeset: 78456:4240282a9f4a parent: 78454:0d6eea2330d0 user: Brett Cannon date: Mon Aug 06 16:34:44 2012 -0400 summary: Issue #15471: Don't use mutable object as default values for the parameters of importlib.__import__(). files: Doc/library/functions.rst | 2 +- Doc/library/importlib.rst | 2 +- Lib/importlib/_bootstrap.py | 5 +- Misc/NEWS | 3 + Python/bltinmodule.c | 2 +- Python/importlib.h | 141 ++++++++++++----------- 6 files changed, 81 insertions(+), 74 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1443,7 +1443,7 @@ True -.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=0) +.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0) .. index:: statement: import diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -63,7 +63,7 @@ Functions --------- -.. function:: __import__(name, globals={}, locals={}, fromlist=list(), level=0) +.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0) An implementation of the built-in :func:`__import__` function. diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1587,7 +1587,7 @@ return [extensions, source, bytecode] -def __import__(name, globals={}, locals={}, fromlist=[], level=0): +def __import__(name, globals=None, locals=None, fromlist=(), level=0): """Import a module. The 'globals' argument is used to infer where the import is occuring from @@ -1601,7 +1601,8 @@ if level == 0: module = _gcd_import(name) else: - package = _calc___package__(globals) + globals_ = globals if globals is not None else {} + package = _calc___package__(globals_) module = _gcd_import(name, package, level) if not fromlist: # Return up to the first dot in 'name'. This is complicated by the fact diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,9 @@ Library ------- +- Issue #15471: Do not use mutable objects as defaults for + importlib.__import__(). + - Issue #15559: To avoid a problematic failure mode when passed to the bytes constructor, objects in the ipaddress module no longer implement __index__ (they still implement __int__ as appropriate) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -195,7 +195,7 @@ } PyDoc_STRVAR(import_doc, -"__import__(name, globals={}, locals={}, fromlist=[], level=0) -> module\n\ +"__import__(name, globals=None, locals=None, fromlist=(), level=0) -> module\n\ \n\ Import a module. Because this function is meant for use by the Python\n\ interpreter and not for general use it is better to use\n\ 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 Mon Aug 6 23:19:28 2012 From: python-checkins at python.org (brett.cannon) Date: Mon, 6 Aug 2012 23:19:28 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315163=3A_Pydoc_sh?= =?utf-8?q?ouldn=27t_show_=5F=5Floader=5F=5F_as_a_part_of_a_module=27s?= Message-ID: <3WrWvh5lGyzPjt@mail.python.org> http://hg.python.org/cpython/rev/6a27b9f37b05 changeset: 78457:6a27b9f37b05 user: Brett Cannon date: Mon Aug 06 17:19:22 2012 -0400 summary: Issue #15163: Pydoc shouldn't show __loader__ as a part of a module's data. Also alphabetized the attributes in the blacklist to make it easier to detect changes. Initial patch by ?ric Araujo. files: Lib/pydoc.py | 10 +++++----- Misc/NEWS | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -163,11 +163,11 @@ def visiblename(name, all=None, obj=None): """Decide whether to show documentation on a variable.""" - # Certain special names are redundant. - if name in {'__builtins__', '__doc__', '__file__', '__path__', - '__module__', '__name__', '__slots__', '__package__', - '__cached__', '__author__', '__credits__', '__date__', - '__version__', '__qualname__', '__initializing__'}: + # Certain special names are redundant or internal. + if name in {'__author__', '__builtins__', '__cached__', '__credits__', + '__date__', '__doc__', '__file__', '__initializing__', + '__loader__', '__module__', '__name__', '__package__', + '__path__', '__qualname__', '__slots__', '__version__'}: return 0 # Private names are hidden, but special names are displayed. if name.startswith('__') and name.endswith('__'): return 1 diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,8 @@ Library ------- +- Issue #15163: Pydoc shouldn't list __loader__ as module data. + - Issue #15471: Do not use mutable objects as defaults for importlib.__import__(). -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 7 02:53:26 2012 From: python-checkins at python.org (benjamin.peterson) Date: Tue, 7 Aug 2012 02:53:26 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_fix_yield_from_return_valu?= =?utf-8?q?e_on_custom_iterators_=28closes_=2315568=29?= Message-ID: <3WrcfZ28LrzPrt@mail.python.org> http://hg.python.org/cpython/rev/ee55f8e4fb50 changeset: 78458:ee55f8e4fb50 parent: 78452:8282e4846e43 user: Benjamin Peterson date: Mon Aug 06 17:53:09 2012 -0700 summary: fix yield from return value on custom iterators (closes #15568) files: Lib/test/test_pep380.py | 14 ++++++++++++++ Misc/NEWS | 3 +++ Python/ceval.c | 2 +- 3 files changed, 18 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 @@ -940,6 +940,20 @@ for stack in spam(eggs(gen())): self.assertTrue('spam' in stack and 'eggs' in stack) + def test_custom_iterator_return(self): + # See issue #15568 + class MyIter: + def __iter__(self): + return self + def __next__(self): + raise StopIteration(42) + def gen(): + nonlocal ret + ret = yield from MyIter() + ret = None + list(gen()) + self.assertEqual(ret, 42) + def test_main(): from test import support diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15568: Fix the return value of "yield from" when StopIteration is + raised by a custom iterator. + - Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on Windows, as Python 2. diff --git a/Python/ceval.c b/Python/ceval.c --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1843,7 +1843,7 @@ } else { _Py_IDENTIFIER(send); if (u == Py_None) - retval = PyIter_Next(x); + retval = Py_TYPE(x)->tp_iternext(x); else retval = _PyObject_CallMethodId(x, &PyId_send, "O", u); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 7 02:53:28 2012 From: python-checkins at python.org (benjamin.peterson) Date: Tue, 7 Aug 2012 02:53:28 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3Wrcfc1VFzzPsL@mail.python.org> http://hg.python.org/cpython/rev/0eeffeadaa1e changeset: 78459:0eeffeadaa1e parent: 78458:ee55f8e4fb50 parent: 78457:6a27b9f37b05 user: Benjamin Peterson date: Mon Aug 06 17:53:19 2012 -0700 summary: merge heads files: Doc/library/functions.rst | 2 +- Doc/library/importlib.rst | 2 +- Doc/library/stdtypes.rst | 13 +- Lib/importlib/_bootstrap.py | 5 +- Lib/pydoc.py | 10 +- Misc/NEWS | 5 + Python/bltinmodule.c | 2 +- Python/importlib.h | 141 ++++++++++++----------- 8 files changed, 96 insertions(+), 84 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1443,7 +1443,7 @@ True -.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=0) +.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0) .. index:: statement: import diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -63,7 +63,7 @@ Functions --------- -.. function:: __import__(name, globals={}, locals={}, fromlist=list(), level=0) +.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0) An implementation of the built-in :func:`__import__` function. diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1351,16 +1351,19 @@ .. method:: str.splitlines([keepends]) - Return a list of the lines in the string, breaking at line boundaries. Line - breaks are not included in the resulting list unless *keepends* is given and - true. This method uses the universal newlines approach to splitting lines. - Unlike :meth:`~str.split`, if the string ends with line boundary characters - the returned list does ``not`` have an empty last element. + Return a list of the lines in the string, breaking at line boundaries. + This method uses the universal newlines approach to splitting lines. + Line breaks are not included in the resulting list unless *keepends* is + given and true. For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + Unlike :meth:`~str.split` when a delimiter string *sep* is given, this + method returns an empty list for the empty string, and a terminal line + break does not result in an extra line. + .. method:: str.startswith(prefix[, start[, end]]) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1587,7 +1587,7 @@ return [extensions, source, bytecode] -def __import__(name, globals={}, locals={}, fromlist=[], level=0): +def __import__(name, globals=None, locals=None, fromlist=(), level=0): """Import a module. The 'globals' argument is used to infer where the import is occuring from @@ -1601,7 +1601,8 @@ if level == 0: module = _gcd_import(name) else: - package = _calc___package__(globals) + globals_ = globals if globals is not None else {} + package = _calc___package__(globals_) module = _gcd_import(name, package, level) if not fromlist: # Return up to the first dot in 'name'. This is complicated by the fact diff --git a/Lib/pydoc.py b/Lib/pydoc.py --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -163,11 +163,11 @@ def visiblename(name, all=None, obj=None): """Decide whether to show documentation on a variable.""" - # Certain special names are redundant. - if name in {'__builtins__', '__doc__', '__file__', '__path__', - '__module__', '__name__', '__slots__', '__package__', - '__cached__', '__author__', '__credits__', '__date__', - '__version__', '__qualname__', '__initializing__'}: + # Certain special names are redundant or internal. + if name in {'__author__', '__builtins__', '__cached__', '__credits__', + '__date__', '__doc__', '__file__', '__initializing__', + '__loader__', '__module__', '__name__', '__package__', + '__path__', '__qualname__', '__slots__', '__version__'}: return 0 # Private names are hidden, but special names are displayed. if name.startswith('__') and name.endswith('__'): return 1 diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -80,6 +80,11 @@ Library ------- +- Issue #15163: Pydoc shouldn't list __loader__ as module data. + +- Issue #15471: Do not use mutable objects as defaults for + importlib.__import__(). + - Issue #15559: To avoid a problematic failure mode when passed to the bytes constructor, objects in the ipaddress module no longer implement __index__ (they still implement __int__ as appropriate) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -195,7 +195,7 @@ } PyDoc_STRVAR(import_doc, -"__import__(name, globals={}, locals={}, fromlist=[], level=0) -> module\n\ +"__import__(name, globals=None, locals=None, fromlist=(), level=0) -> module\n\ \n\ Import a module. Because this function is meant for use by the Python\n\ interpreter and not for general use it is better to use\n\ 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 solipsis at pitrou.net Tue Aug 7 06:04:00 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 07 Aug 2012 06:04:00 +0200 Subject: [Python-checkins] Daily reference leaks (0eeffeadaa1e): sum=0 Message-ID: results for 0eeffeadaa1e on branch "default" -------------------------------------------- test_imp leaked [-1, 1, 0] references, sum=0 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogSmuUE0', '-x'] From python-checkins at python.org Tue Aug 7 12:12:53 2012 From: python-checkins at python.org (ned.deily) Date: Tue, 7 Aug 2012 12:12:53 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315560=3A_Ensure_c?= =?utf-8?q?onsistent_sqlite3_behavior_and_feature_availability?= Message-ID: <3Wrs453FQxzPs8@mail.python.org> http://hg.python.org/cpython/rev/59223da36dec changeset: 78460:59223da36dec user: Ned Deily date: Tue Aug 07 03:10:57 2012 -0700 summary: Issue #15560: Ensure consistent sqlite3 behavior and feature availability by building a local copy of libsqlite3 with OS X installers rather than depending on the wide range of versions supplied with various OS X releases. files: Mac/BuildScript/build-installer.py | 51 +++++++++-------- Misc/NEWS | 3 + 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -190,6 +190,8 @@ def library_recipes(): result = [] + LT_10_5 = bool(DEPTARGET < '10.5') + result.extend([ dict( name="XZ 5.0.3", @@ -235,7 +237,25 @@ getVersion(), ), ), - ]) + dict( + name="SQLite 3.7.13", + url="http://www.sqlite.org/sqlite-autoconf-3071300.tar.gz", + checksum='c97df403e8a3d5b67bb408fcd6aabd8e', + extra_cflags=('-Os ' + '-DSQLITE_ENABLE_FTS4 ' + '-DSQLITE_ENABLE_FTS3_PARENTHESIS ' + '-DSQLITE_ENABLE_RTREE ' + '-DSQLITE_TCL=0 ' + '%s' % ('','-DSQLITE_WITHOUT_ZONEMALLOC ')[LT_10_5]), + configure_pre=[ + '--enable-threadsafe', + '--enable-shared=no', + '--enable-static=yes', + '--disable-readline', + '--disable-dependency-tracking', + ] + ), + ]) if DEPTARGET < '10.5': result.extend([ @@ -278,24 +298,6 @@ '1a76781a1ea734e831588285db7ec9b1'), ] ), - dict( - name="SQLite 3.7.4", - url="http://www.sqlite.org/sqlite-autoconf-3070400.tar.gz", - checksum='8f0c690bfb33c3cbbc2471c3d9ba0158', - configure_env=('CFLAGS="-Os' - ' -DSQLITE_ENABLE_FTS3' - ' -DSQLITE_ENABLE_FTS3_PARENTHESIS' - ' -DSQLITE_ENABLE_RTREE' - ' -DSQLITE_TCL=0' - '"'), - configure_pre=[ - '--enable-threadsafe', - '--enable-shared=no', - '--enable-static=yes', - '--disable-readline', - '--disable-dependency-tracking', - ] - ), ]) if not PYTHON_3: @@ -779,7 +781,9 @@ if recipe.get('useLDFlags', 1): configure_args.extend([ - "CFLAGS=-mmacosx-version-min=%s -arch %s -isysroot %s -I%s/usr/local/include"%( + "CFLAGS=%s-mmacosx-version-min=%s -arch %s -isysroot %s " + "-I%s/usr/local/include"%( + recipe.get('extra_cflags', ''), DEPTARGET, ' -arch '.join(archList), shellQuote(SDKPATH)[1:-1], @@ -792,7 +796,9 @@ ]) else: configure_args.extend([ - "CFLAGS=-mmacosx-version-min=%s -arch %s -isysroot %s -I%s/usr/local/include"%( + "CFLAGS=%s-mmacosx-version-min=%s -arch %s -isysroot %s " + "-I%s/usr/local/include"%( + recipe.get('extra_cflags', ''), DEPTARGET, ' -arch '.join(archList), shellQuote(SDKPATH)[1:-1], @@ -805,9 +811,6 @@ configure_args.insert(0, configure) configure_args = [ shellQuote(a) for a in configure_args ] - if 'configure_env' in recipe: - configure_args.insert(0, recipe['configure_env']) - print("Running configure for %s"%(name,)) runCommand(' '.join(configure_args) + ' 2>&1') diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -317,6 +317,9 @@ those shipped with OS X. - Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. + Also, for OS X installers, ensure consistent sqlite3 behavior and feature + availability by building a local copy of libsqlite3 rather than + depending on the wide range of versions supplied with various OS X releases. - Issue #8847: Disable COMDAT folding in Windows PGO builds. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 7 20:57:56 2012 From: python-checkins at python.org (benjamin.peterson) Date: Tue, 7 Aug 2012 20:57:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_make_documente?= =?utf-8?q?d_file=28=29_kw_names_and_actual_ones_agree_=28closes_=2315572?= =?utf-8?q?=29?= Message-ID: <3Ws4jw4TNHzQ04@mail.python.org> http://hg.python.org/cpython/rev/db1b4aab53eb changeset: 78461:db1b4aab53eb branch: 2.7 parent: 78455:e057a7d18fa2 user: Benjamin Peterson date: Tue Aug 07 11:57:47 2012 -0700 summary: make documented file() kw names and actual ones agree (closes #15572) Patch by Daniel Ellis. files: Doc/library/functions.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -451,7 +451,7 @@ used reliably to modify a function's locals. -.. function:: file(filename[, mode[, bufsize]]) +.. function:: file(name[, mode[, buffering]]) Constructor function for the :class:`file` type, described further in section :ref:`bltin-file-objects`. The constructor's arguments are the same as those -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Aug 8 06:03:00 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 08 Aug 2012 06:03:00 +0200 Subject: [Python-checkins] Daily reference leaks (59223da36dec): sum=0 Message-ID: results for 59223da36dec on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogFMmxyx', '-x'] From python-checkins at python.org Wed Aug 8 12:16:18 2012 From: python-checkins at python.org (matthias.klose) Date: Wed, 8 Aug 2012 12:16:18 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_-_Issue_=2311715=3A_Fix_mu?= =?utf-8?q?ltiarch_detection_without_having_Debian_development?= Message-ID: <3WsT5Z19FLzQ0W@mail.python.org> http://hg.python.org/cpython/rev/5966c206654b changeset: 78462:5966c206654b parent: 78460:59223da36dec user: doko at ubuntu.com date: Wed Aug 08 12:15:55 2012 +0200 summary: - Issue #11715: Fix multiarch detection without having Debian development tools (dpkg-dev) installed. files: Misc/NEWS | 3 +++ setup.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -312,6 +312,9 @@ Build ----- +- Issue #11715: Fix multiarch detection without having Debian development + tools (dpkg-dev) installed. + - Issue #15037: Build OS X installers with local copy of ncurses 5.9 libraries to avoid curses.unget_wch bug present in older versions of ncurses such as those shipped with OS X. diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -379,6 +379,27 @@ def add_multiarch_paths(self): # Debian/Ubuntu multiarch support. # https://wiki.ubuntu.com/MultiarchSpec + cc = sysconfig.get_config_var('CC') + tmpfile = os.path.join(self.build_temp, 'multiarch') + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + ret = os.system( + '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile)) + multiarch_path_component = '' + try: + if ret >> 8 == 0: + with open(tmpfile) as fp: + multiarch_path_component = fp.readline().strip() + finally: + os.unlink(tmpfile) + + if multiarch_path_component != '': + add_dir_to_list(self.compiler.library_dirs, + '/usr/lib/' + multiarch_path_component) + add_dir_to_list(self.compiler.include_dirs, + '/usr/include/' + multiarch_path_component) + return + if not find_executable('dpkg-architecture'): return opt = '' -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 8 20:13:21 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 8 Aug 2012 20:13:21 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2313072=3A_Fix_test?= =?utf-8?q?=5Farray_for_Windows_with_16-bit_wchar=5Ft?= Message-ID: <3Wsgh12zRYzQ35@mail.python.org> http://hg.python.org/cpython/rev/e0f3406c43e4 changeset: 78463:e0f3406c43e4 user: Victor Stinner date: Wed Aug 08 20:09:21 2012 +0200 summary: Issue #13072: Fix test_array for Windows with 16-bit wchar_t files: Lib/test/test_array.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) 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 @@ -1029,7 +1029,7 @@ smallerexample = '\x01\u263a\x00\ufefe' biggerexample = '\x01\u263a\x01\ufeff' outside = str('\x33') - minitemsize = 4 + minitemsize = 2 def test_unicode(self): self.assertRaises(TypeError, array.array, 'b', 'foo') @@ -1041,7 +1041,7 @@ a.fromunicode('\x11abc\xff\u1234') s = a.tounicode() self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234') - self.assertEqual(a.itemsize, 4) + self.assertEqual(a.itemsize, 2) s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234' a = array.array('u', s) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 8 20:23:27 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 8 Aug 2012 20:23:27 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2313072=3A_Ooops=2C?= =?utf-8?q?_now_fix_test=5Farray_for_Linux_with_32-bit_wchar=5Ft=2E=2E=2E?= Message-ID: <3Wsgvg6hwszQ1F@mail.python.org> http://hg.python.org/cpython/rev/67a994d5657d changeset: 78464:67a994d5657d user: Victor Stinner date: Wed Aug 08 20:19:37 2012 +0200 summary: Issue #13072: Ooops, now fix test_array for Linux with 32-bit wchar_t... files: Lib/test/test_array.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) 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 @@ -3,6 +3,7 @@ Roger E. Masse """ +import ctypes import unittest from test import support import weakref @@ -1041,7 +1042,7 @@ a.fromunicode('\x11abc\xff\u1234') s = a.tounicode() self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234') - self.assertEqual(a.itemsize, 2) + self.assertEqual(a.itemsize, ctypes.sizeof(ctypes.c_wchar)) s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234' a = array.array('u', s) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 8 22:41:13 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 8 Aug 2012 22:41:13 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_regrtest=3A_give_more_info?= =?utf-8?q?rmation_when_a_child_process_fails_with_an_error?= Message-ID: <3Wskyd54djzQ05@mail.python.org> http://hg.python.org/cpython/rev/85266c6f9ae4 changeset: 78465:85266c6f9ae4 user: Victor Stinner date: Wed Aug 08 22:37:26 2012 +0200 summary: regrtest: give more information when a child process fails with an error different than KeyboardInterrupt files: Lib/test/regrtest.py | 8 +++++--- 1 files changed, 5 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 @@ -440,8 +440,11 @@ args, kwargs = json.loads(a) try: result = runtest(*args, **kwargs) + except KeyboardInterrupt: + result = INTERRUPTED, '' except BaseException as e: - result = INTERRUPTED, e.__class__.__name__ + traceback.print_exc() + result = CHILD_ERROR, str(e) sys.stdout.flush() print() # Force a newline (just in case) print(json.dumps(result)) @@ -684,8 +687,7 @@ sys.stdout.flush() sys.stderr.flush() if result[0] == INTERRUPTED: - assert result[1] == 'KeyboardInterrupt' - raise KeyboardInterrupt # What else? + raise KeyboardInterrupt if result[0] == CHILD_ERROR: raise Exception("Child error on {}: {}".format(test, result[1])) test_index += 1 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 8 23:52:37 2012 From: python-checkins at python.org (larry.hastings) Date: Wed, 8 Aug 2012 23:52:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315589=3A_Ensure_d?= =?utf-8?q?ouble-alignment_for_brute-force_capi_argument_parser_test?= Message-ID: <3WsmY16j2ZzQ0D@mail.python.org> http://hg.python.org/cpython/rev/efb30bdcfa1e changeset: 78466:efb30bdcfa1e user: Larry Hastings date: Wed Aug 08 14:52:22 2012 -0700 summary: Issue #15589: Ensure double-alignment for brute-force capi argument parser test that occasionally uses doubles. files: Modules/_testcapimodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1210,7 +1210,7 @@ int result; PyObject *return_value = NULL; - char buffers[32][8]; + double buffers[8][4]; /* double ensures alignment where necessary */ if (!PyArg_ParseTuple(args, "OOyO:parse_tuple_and_keywords", &sub_args, &sub_kwargs, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 00:47:58 2012 From: python-checkins at python.org (victor.stinner) Date: Thu, 9 Aug 2012 00:47:58 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2313072=3A_Fix_test?= =?utf-8?q?=5Farray_for_installation_without_the_ctypes_module?= Message-ID: <3Wsnmt3VxqzQ1Y@mail.python.org> http://hg.python.org/cpython/rev/4ee4cceda047 changeset: 78467:4ee4cceda047 user: Victor Stinner date: Thu Aug 09 00:43:56 2012 +0200 summary: Issue #13072: Fix test_array for installation without the ctypes module files: Lib/test/test_array.py | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) 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 @@ -3,7 +3,6 @@ Roger E. Masse """ -import ctypes import unittest from test import support import weakref @@ -1033,6 +1032,16 @@ minitemsize = 2 def test_unicode(self): + try: + import ctypes + sizeof_wchar = ctypes.sizeof(ctypes.c_wchar) + except ImportError: + import sys + if sys.platform == 'win32': + sizeof_wchar = 2 + else: + sizeof_wchar = 4 + self.assertRaises(TypeError, array.array, 'b', 'foo') a = array.array('u', '\xa0\xc2\u1234') @@ -1042,7 +1051,7 @@ a.fromunicode('\x11abc\xff\u1234') s = a.tounicode() self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234') - self.assertEqual(a.itemsize, ctypes.sizeof(ctypes.c_wchar)) + self.assertEqual(a.itemsize, sizeof_wchar) s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234' a = array.array('u', s) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 02:23:04 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 9 Aug 2012 02:23:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_use_char_instead_of_int_to?= =?utf-8?q?_please_T=5FBOOL_=28closes_=2315597=29?= Message-ID: <3Wsqtc4B7zzQ1s@mail.python.org> http://hg.python.org/cpython/rev/e2df976b8a33 changeset: 78468:e2df976b8a33 parent: 78460:59223da36dec user: Benjamin Peterson date: Wed Aug 08 17:22:50 2012 -0700 summary: use char instead of int to please T_BOOL (closes #15597) files: Include/pyerrors.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Include/pyerrors.h b/Include/pyerrors.h --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -11,7 +11,7 @@ #define PyException_HEAD PyObject_HEAD PyObject *dict;\ PyObject *args; PyObject *traceback;\ PyObject *context; PyObject *cause;\ - int suppress_context; + char suppress_context; typedef struct { PyException_HEAD -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 02:23:06 2012 From: python-checkins at python.org (benjamin.peterson) Date: Thu, 9 Aug 2012 02:23:06 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3Wsqtf2nq3zQ3h@mail.python.org> http://hg.python.org/cpython/rev/b3e56aa3cc99 changeset: 78469:b3e56aa3cc99 parent: 78468:e2df976b8a33 parent: 78467:4ee4cceda047 user: Benjamin Peterson date: Wed Aug 08 17:22:57 2012 -0700 summary: merge heads files: Lib/test/regrtest.py | 8 +++++--- Lib/test/test_array.py | 14 ++++++++++++-- Misc/NEWS | 3 +++ Modules/_testcapimodule.c | 2 +- setup.py | 21 +++++++++++++++++++++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -440,8 +440,11 @@ args, kwargs = json.loads(a) try: result = runtest(*args, **kwargs) + except KeyboardInterrupt: + result = INTERRUPTED, '' except BaseException as e: - result = INTERRUPTED, e.__class__.__name__ + traceback.print_exc() + result = CHILD_ERROR, str(e) sys.stdout.flush() print() # Force a newline (just in case) print(json.dumps(result)) @@ -684,8 +687,7 @@ sys.stdout.flush() sys.stderr.flush() if result[0] == INTERRUPTED: - assert result[1] == 'KeyboardInterrupt' - raise KeyboardInterrupt # What else? + raise KeyboardInterrupt if result[0] == CHILD_ERROR: raise Exception("Child error on {}: {}".format(test, result[1])) test_index += 1 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 @@ -1029,9 +1029,19 @@ smallerexample = '\x01\u263a\x00\ufefe' biggerexample = '\x01\u263a\x01\ufeff' outside = str('\x33') - minitemsize = 4 + minitemsize = 2 def test_unicode(self): + try: + import ctypes + sizeof_wchar = ctypes.sizeof(ctypes.c_wchar) + except ImportError: + import sys + if sys.platform == 'win32': + sizeof_wchar = 2 + else: + sizeof_wchar = 4 + self.assertRaises(TypeError, array.array, 'b', 'foo') a = array.array('u', '\xa0\xc2\u1234') @@ -1041,7 +1051,7 @@ a.fromunicode('\x11abc\xff\u1234') s = a.tounicode() self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234') - self.assertEqual(a.itemsize, 4) + self.assertEqual(a.itemsize, sizeof_wchar) s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234' a = array.array('u', s) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -312,6 +312,9 @@ Build ----- +- Issue #11715: Fix multiarch detection without having Debian development + tools (dpkg-dev) installed. + - Issue #15037: Build OS X installers with local copy of ncurses 5.9 libraries to avoid curses.unget_wch bug present in older versions of ncurses such as those shipped with OS X. diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1210,7 +1210,7 @@ int result; PyObject *return_value = NULL; - char buffers[32][8]; + double buffers[8][4]; /* double ensures alignment where necessary */ if (!PyArg_ParseTuple(args, "OOyO:parse_tuple_and_keywords", &sub_args, &sub_kwargs, diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -379,6 +379,27 @@ def add_multiarch_paths(self): # Debian/Ubuntu multiarch support. # https://wiki.ubuntu.com/MultiarchSpec + cc = sysconfig.get_config_var('CC') + tmpfile = os.path.join(self.build_temp, 'multiarch') + if not os.path.exists(self.build_temp): + os.makedirs(self.build_temp) + ret = os.system( + '%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile)) + multiarch_path_component = '' + try: + if ret >> 8 == 0: + with open(tmpfile) as fp: + multiarch_path_component = fp.readline().strip() + finally: + os.unlink(tmpfile) + + if multiarch_path_component != '': + add_dir_to_list(self.compiler.library_dirs, + '/usr/lib/' + multiarch_path_component) + add_dir_to_list(self.compiler.include_dirs, + '/usr/include/' + multiarch_path_component) + return + if not find_executable('dpkg-architecture'): return opt = '' -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 02:47:42 2012 From: python-checkins at python.org (victor.stinner) Date: Thu, 9 Aug 2012 02:47:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_faulthandler=3A_fix_the_ha?= =?utf-8?q?ndler_of_user_signals?= Message-ID: <3WsrR231FQzQ2k@mail.python.org> http://hg.python.org/cpython/rev/7d821a09a640 changeset: 78470:7d821a09a640 user: Victor Stinner date: Thu Aug 09 02:43:41 2012 +0200 summary: faulthandler: fix the handler of user signals Restore the errno before calling the previous signal handler, and not after. files: Modules/faulthandler.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -659,17 +659,22 @@ #ifdef HAVE_SIGACTION if (user->chain) { (void)sigaction(signum, &user->previous, NULL); + errno = save_errno; + /* call the previous signal handler */ raise(signum); + + save_errno = errno; (void)faulthandler_register(signum, user->chain, NULL); + errno = save_errno; } #else if (user->chain) { + errno = save_errno; /* call the previous signal handler */ user->previous(signum); } #endif - errno = save_errno; } static int -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Thu Aug 9 06:02:56 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 09 Aug 2012 06:02:56 +0200 Subject: [Python-checkins] Daily reference leaks (7d821a09a640): sum=0 Message-ID: results for 7d821a09a640 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogNljNMo', '-x'] From python-checkins at python.org Thu Aug 9 06:03:47 2012 From: python-checkins at python.org (ned.deily) Date: Thu, 9 Aug 2012 06:03:47 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE0OTky?= =?utf-8?q?=3A_Prevent_test=5Fos_test=5Fexist=5Fok=5Fs=5Fisgid=5Fdirectory?= =?utf-8?q?_test_case?= Message-ID: <3WswnH5x2hzP8w@mail.python.org> http://hg.python.org/cpython/rev/3f42c9dbd8a7 changeset: 78471:3f42c9dbd8a7 branch: 3.2 parent: 78453:768b188262e7 user: Ned Deily date: Wed Aug 08 20:57:24 2012 -0700 summary: Issue #14992: Prevent test_os test_exist_ok_s_isgid_directory test case failure on OS X built with 10.4 ABI. files: Lib/test/test_os.py | 5 ++++- 1 files changed, 4 insertions(+), 1 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 @@ -592,7 +592,10 @@ try: existing_testfn_mode = stat.S_IMODE( os.lstat(support.TESTFN).st_mode) - os.chmod(support.TESTFN, existing_testfn_mode | S_ISGID) + try: + os.chmod(support.TESTFN, existing_testfn_mode | S_ISGID) + except OSError: + raise unittest.SkipTest('Cannot set S_ISGID for dir.') if (os.lstat(support.TESTFN).st_mode & S_ISGID != S_ISGID): raise unittest.SkipTest('No support for S_ISGID dir mode.') # The os should apply S_ISGID from the parent dir for us, but -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 06:03:49 2012 From: python-checkins at python.org (ned.deily) Date: Thu, 9 Aug 2012 06:03:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2314992=3A_merge_from_3=2E2?= Message-ID: <3WswnK43qnzPc0@mail.python.org> http://hg.python.org/cpython/rev/a1c8c79e035d changeset: 78472:a1c8c79e035d parent: 78470:7d821a09a640 parent: 78471:3f42c9dbd8a7 user: Ned Deily date: Wed Aug 08 21:03:02 2012 -0700 summary: Issue #14992: merge from 3.2 files: Lib/test/test_os.py | 5 ++++- 1 files changed, 4 insertions(+), 1 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 @@ -863,7 +863,10 @@ try: existing_testfn_mode = stat.S_IMODE( os.lstat(support.TESTFN).st_mode) - os.chmod(support.TESTFN, existing_testfn_mode | S_ISGID) + try: + os.chmod(support.TESTFN, existing_testfn_mode | S_ISGID) + except PermissionError: + raise unittest.SkipTest('Cannot set S_ISGID for dir.') if (os.lstat(support.TESTFN).st_mode & S_ISGID != S_ISGID): raise unittest.SkipTest('No support for S_ISGID dir mode.') # The os should apply S_ISGID from the parent dir for us, but -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 07:21:00 2012 From: python-checkins at python.org (eli.bendersky) Date: Thu, 9 Aug 2012 07:21:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_description_of_major_c?= =?utf-8?q?hanges_in_xml=2Eetree=2EElementTree_to_whatsnew/3=2E3?= Message-ID: <3WsyVN4FZnzQ0q@mail.python.org> http://hg.python.org/cpython/rev/2c33c4475e60 changeset: 78473:2c33c4475e60 user: Eli Bendersky date: Thu Aug 09 08:20:20 2012 +0300 summary: Add description of major changes in xml.etree.ElementTree to whatsnew/3.3 files: Doc/whatsnew/3.3.rst | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) 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 @@ -1602,6 +1602,18 @@ (:issue:`13620` and :issue:`14493`) +xml.etree.ElementTree +--------------------- + +The :mod:`xml.etree.ElementTree` module now imports its C accelerator by +default; there is no longer a need to explicitly import +:mod:`xml.etree.cElementTree` (this module stays for backwards compatibility, +but is now deprecated). In addition, the ``iter`` family of methods of +:class:`~xml.etree.ElementTree.Element` has been optimized (rewritten in C). +The module's documentation has also been greatly improved with added examples +and a more detailed reference. + + Optimizations ============= -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 12:25:50 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 12:25:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_documentation_for_insp?= =?utf-8?q?ect_module_to_pass_doctest?= Message-ID: <3Wt5G63HTgzPp0@mail.python.org> http://hg.python.org/cpython/rev/4ba3e3b822d1 changeset: 78474:4ba3e3b822d1 user: Andrew Svetlov date: Thu Aug 09 13:25:32 2012 +0300 summary: Fix documentation for inspect module to pass doctest files: Doc/library/inspect.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -494,14 +494,14 @@ >>> from inspect import getcallargs >>> def f(a, b=1, *pos, **named): ... pass - >>> getcallargs(f, 1, 2, 3) - {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)} - >>> getcallargs(f, a=2, x=4) - {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()} + >>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)} + True + >>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()} + True >>> getcallargs(f) Traceback (most recent call last): ... - TypeError: f() takes at least 1 argument (0 given) + TypeError: f() missing 1 required positional argument: 'a' .. versionadded:: 3.2 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 14:28:00 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 14:28:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315501=3A_Document?= =?utf-8?q?_exception_classes_in_subprocess_module=2E?= Message-ID: <3Wt7z41dpnzQ29@mail.python.org> http://hg.python.org/cpython/rev/b863e231ad9f changeset: 78475:b863e231ad9f user: Andrew Svetlov date: Thu Aug 09 15:11:45 2012 +0300 summary: Issue #15501: Document exception classes in subprocess module. Initial patch by Anton Barkovsky. files: Doc/library/subprocess.rst | 48 ++++++++++++++++++++++++++ Misc/ACKS | 1 + 2 files changed, 49 insertions(+), 0 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -208,6 +208,54 @@ output. +.. exception:: SubprocessError + + Base class for all other exceptions from this module. + + .. versionadded:: 3.3 + + +.. exception:: TimeoutExpired + + Subclass of :exc:`SubprocessError`, raised when a timeout expires + while waiting for a child process. + + .. attribute:: cmd + + Command that was used to spawn the child process. + + .. attribute:: timeout + + Timeout in seconds. + + .. attribute:: output + + Output of the child process if this exception is raised by + :func:`check_output`. Otherwise, ``None``. + + .. versionadded:: 3.3 + + +.. exception:: CalledProcessError + + Subclass of :exc:`SubprocessError`, raised when a process run by + :func:`check_call` or :func:`check_output` returns a non-zero exit status. + + .. attribute:: returncode + + Exit status of the child process. + + .. attribute:: cmd + + Command that was used to spawn the child process. + + .. attribute:: output + + Output of the child process if this exception is raised by + :func:`check_output`. Otherwise, ``None``. + + + .. _frequently-used-arguments: Frequently Used Arguments diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -56,6 +56,7 @@ Michael J. Barber Nicolas Bareil Chris Barker +Anton Barkovsky Nick Barnes Quentin Barnes David Barnett -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 14:28:01 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 14:28:01 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NTAx?= =?utf-8?q?=3A_Document_exception_classes_in_subprocess_module=2E?= Message-ID: <3Wt7z55VxyzQ2f@mail.python.org> http://hg.python.org/cpython/rev/1e8f6d8e5c0e changeset: 78476:1e8f6d8e5c0e branch: 3.2 parent: 78471:3f42c9dbd8a7 user: Andrew Svetlov date: Thu Aug 09 15:20:45 2012 +0300 summary: Issue #15501: Document exception classes in subprocess module. Initial patch by Anton Barkovsky. files: Doc/library/subprocess.rst | 20 ++++++++++++++++++++ Misc/ACKS | 1 + 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -176,6 +176,26 @@ output. +.. exception:: CalledProcessError + + Exception raised when a process run by :func:`check_call` or + :func:`check_output` returns a non-zero exit status. + + .. attribute:: returncode + + Exit status of the child process. + + .. attribute:: cmd + + Command that was used to spawn the child process. + + .. attribute:: output + + Output of the child process if this exception is raised by + :func:`check_output`. Otherwise, ``None``. + + + .. _frequently-used-arguments: Frequently Used Arguments diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -52,6 +52,7 @@ Michael J. Barber Nicolas Bareil Chris Barker +Anton Barkovsky Nick Barnes Quentin Barnes Richard Barran -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 14:28:03 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 14:28:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NTAx?= =?utf-8?q?=3A_Document_exception_classes_in_subprocess_module=2E?= Message-ID: <3Wt7z71QCYzQ2V@mail.python.org> http://hg.python.org/cpython/rev/9c99f31a9c2a changeset: 78477:9c99f31a9c2a branch: 2.7 parent: 78461:db1b4aab53eb user: Andrew Svetlov date: Thu Aug 09 15:23:49 2012 +0300 summary: Issue #15501: Document exception classes in subprocess module. Initial patch by Anton Barkovsky. files: Doc/library/subprocess.rst | 20 ++++++++++++++++++++ Misc/ACKS | 1 + 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -172,6 +172,26 @@ output. +.. exception:: CalledProcessError + + Exception raised when a process run by :func:`check_call` or + :func:`check_output` returns a non-zero exit status. + + .. attribute:: returncode + + Exit status of the child process. + + .. attribute:: cmd + + Command that was used to spawn the child process. + + .. attribute:: output + + Output of the child process if this exception is raised by + :func:`check_output`. Otherwise, ``None``. + + + .. _frequently-used-arguments: Frequently Used Arguments diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -44,6 +44,7 @@ Matt Bandy Michael J. Barber Chris Barker +Anton Barkovsky Nick Barnes Quentin Barnes Richard Barran -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 14:28:04 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 14:28:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3Wt7z84dqBzQ2y@mail.python.org> http://hg.python.org/cpython/rev/96cc3ab243e5 changeset: 78478:96cc3ab243e5 parent: 78475:b863e231ad9f parent: 78476:1e8f6d8e5c0e user: Andrew Svetlov date: Thu Aug 09 15:27:45 2012 +0300 summary: merge heads files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 20:32:22 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 20:32:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_fix_docs_for_c?= =?utf-8?q?-api_memory_functions?= Message-ID: <3WtJ3V4fGNzPqc@mail.python.org> http://hg.python.org/cpython/rev/4787b9b2f860 changeset: 78479:4787b9b2f860 branch: 3.2 parent: 78476:1e8f6d8e5c0e user: Andrew Svetlov date: Thu Aug 09 21:26:34 2012 +0300 summary: fix docs for c-api memory functions files: Doc/c-api/memory.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst --- a/Doc/c-api/memory.rst +++ b/Doc/c-api/memory.rst @@ -98,7 +98,7 @@ Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the allocated memory, or *NULL* if the request fails. Requesting zero bytes returns - a distinct non-*NULL* pointer if possible, as if :c:func:`PyMem_Malloc(1)` had + a distinct non-*NULL* pointer if possible, as if ``PyMem_Malloc(1)`` had been called instead. The memory will not have been initialized in any way. @@ -106,7 +106,7 @@ Resizes the memory block pointed to by *p* to *n* bytes. The contents will be unchanged to the minimum of the old and the new sizes. If *p* is *NULL*, the - call is equivalent to :c:func:`PyMem_Malloc(n)`; else if *n* is equal to zero, + call is equivalent to ``PyMem_Malloc(n)``; else if *n* is equal to zero, the memory block is resized but is not freed, and the returned pointer is non-*NULL*. Unless *p* is *NULL*, it must have been returned by a previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. If the request fails, @@ -118,7 +118,7 @@ Frees the memory block pointed to by *p*, which must have been returned by a previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. Otherwise, or - if :c:func:`PyMem_Free(p)` has been called before, undefined behavior occurs. If + if ``PyMem_Free(p)`` has been called before, undefined behavior occurs. If *p* is *NULL*, no operation is performed. The following type-oriented macros are provided for convenience. Note that -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 20:32:25 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 20:32:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_fix_docs_for_c-api_memory_functions?= Message-ID: <3WtJ3Y0QH8zPqc@mail.python.org> http://hg.python.org/cpython/rev/a979b005a814 changeset: 78480:a979b005a814 parent: 78478:96cc3ab243e5 parent: 78479:4787b9b2f860 user: Andrew Svetlov date: Thu Aug 09 21:29:16 2012 +0300 summary: fix docs for c-api memory functions files: Doc/c-api/memory.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst --- a/Doc/c-api/memory.rst +++ b/Doc/c-api/memory.rst @@ -98,7 +98,7 @@ Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the allocated memory, or *NULL* if the request fails. Requesting zero bytes returns - a distinct non-*NULL* pointer if possible, as if :c:func:`PyMem_Malloc(1)` had + a distinct non-*NULL* pointer if possible, as if ``PyMem_Malloc(1)`` had been called instead. The memory will not have been initialized in any way. @@ -106,7 +106,7 @@ Resizes the memory block pointed to by *p* to *n* bytes. The contents will be unchanged to the minimum of the old and the new sizes. If *p* is *NULL*, the - call is equivalent to :c:func:`PyMem_Malloc(n)`; else if *n* is equal to zero, + call is equivalent to ``PyMem_Malloc(n)``; else if *n* is equal to zero, the memory block is resized but is not freed, and the returned pointer is non-*NULL*. Unless *p* is *NULL*, it must have been returned by a previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. If the request fails, @@ -118,7 +118,7 @@ Frees the memory block pointed to by *p*, which must have been returned by a previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. Otherwise, or - if :c:func:`PyMem_Free(p)` has been called before, undefined behavior occurs. If + if ``PyMem_Free(p)`` has been called before, undefined behavior occurs. If *p* is *NULL*, no operation is performed. The following type-oriented macros are provided for convenience. Note that -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 20:32:26 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 20:32:26 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_fix_docs_for_c?= =?utf-8?q?-api_memory_functions?= Message-ID: <3WtJ3Z3LYgzPrV@mail.python.org> http://hg.python.org/cpython/rev/6dab233a115e changeset: 78481:6dab233a115e branch: 2.7 parent: 78477:9c99f31a9c2a user: Andrew Svetlov date: Thu Aug 09 21:32:11 2012 +0300 summary: fix docs for c-api memory functions files: Doc/c-api/memory.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst --- a/Doc/c-api/memory.rst +++ b/Doc/c-api/memory.rst @@ -98,7 +98,7 @@ Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the allocated memory, or *NULL* if the request fails. Requesting zero bytes returns - a distinct non-*NULL* pointer if possible, as if :c:func:`PyMem_Malloc(1)` had + a distinct non-*NULL* pointer if possible, as if ``PyMem_Malloc(1)`` had been called instead. The memory will not have been initialized in any way. @@ -106,7 +106,7 @@ Resizes the memory block pointed to by *p* to *n* bytes. The contents will be unchanged to the minimum of the old and the new sizes. If *p* is *NULL*, the - call is equivalent to :c:func:`PyMem_Malloc(n)`; else if *n* is equal to zero, + call is equivalent to ``PyMem_Malloc(n)``; else if *n* is equal to zero, the memory block is resized but is not freed, and the returned pointer is non-*NULL*. Unless *p* is *NULL*, it must have been returned by a previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. If the request fails, @@ -118,7 +118,7 @@ Frees the memory block pointed to by *p*, which must have been returned by a previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. Otherwise, or - if :c:func:`PyMem_Free(p)` has been called before, undefined behavior occurs. If + if ``PyMem_Free(p)`` has been called before, undefined behavior occurs. If *p* is *NULL*, no operation is performed. The following type-oriented macros are provided for convenience. Note that -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 20:47:49 2012 From: python-checkins at python.org (georg.brandl) Date: Thu, 9 Aug 2012 20:47:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?peps=3A_3=2E3_schedule_update=2E?= Message-ID: <3WtJPK4zlDzPqQ@mail.python.org> http://hg.python.org/peps/rev/fdf8b99178c4 changeset: 4497:fdf8b99178c4 user: Georg Brandl date: Thu Aug 09 20:48:06 2012 +0200 summary: 3.3 schedule update. files: pep-0398.txt | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pep-0398.txt b/pep-0398.txt --- a/pep-0398.txt +++ b/pep-0398.txt @@ -42,10 +42,10 @@ (No new features beyond this point.) -- 3.3.0 beta 2: July 21, 2012 -- 3.3.0 candidate 1: August 4, 2012 -- 3.3.0 candidate 2: August 18, 2012 -- 3.3.0 final: September 1, 2012 +- 3.3.0 beta 2: August 11, 2012 +- 3.3.0 candidate 1: August 25, 2012 +- 3.3.0 candidate 2: September 8, 2012 +- 3.3.0 final: September 22, 2012 .. don't forget to update final date above as well -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Thu Aug 9 20:51:42 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 9 Aug 2012 20:51:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315601=3A_fix_tkin?= =?utf-8?q?ter_test=5Fvariables_failure_with_OS_X_Aqua_Tk_8=2E4?= Message-ID: <3WtJTp29F3zPrL@mail.python.org> http://hg.python.org/cpython/rev/20a46c73855f changeset: 78482:20a46c73855f parent: 78480:a979b005a814 user: Andrew Svetlov date: Thu Aug 09 21:51:21 2012 +0300 summary: Issue #15601: fix tkinter test_variables failure with OS X Aqua Tk 8.4 files: Lib/tkinter/test/test_tkinter/test_variables.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/tkinter/test/test_tkinter/test_variables.py b/Lib/tkinter/test/test_tkinter/test_variables.py --- a/Lib/tkinter/test/test_tkinter/test_variables.py +++ b/Lib/tkinter/test/test_tkinter/test_variables.py @@ -81,8 +81,8 @@ def test_get(self): v = StringVar(self.root, "abc", "name") self.assertEqual("abc", v.get()) - self.root.globalsetvar("name", True) - self.assertEqual("1", v.get()) + self.root.globalsetvar("name", "value") + self.assertEqual("value", v.get()) class TestIntVar(TestBase): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 9 21:42:25 2012 From: python-checkins at python.org (victor.stinner) Date: Thu, 9 Aug 2012 21:42:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Remove_now_unused_IntOrLon?= =?utf-8?q?gToString_type?= Message-ID: <3WtKcK1NvkzPmN@mail.python.org> http://hg.python.org/cpython/rev/aaa68dce117e changeset: 78483:aaa68dce117e user: Victor Stinner date: Thu Aug 09 21:38:23 2012 +0200 summary: Remove now unused IntOrLongToString type files: Python/formatter_unicode.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -802,9 +802,6 @@ /*********** long formatting ********************************************/ /************************************************************************/ -typedef PyObject* -(*IntOrLongToString)(PyObject *value, int base); - static int format_long_internal(PyObject *value, const InternalFormatSpec *format, _PyUnicodeWriter *writer) -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Fri Aug 10 06:03:13 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 10 Aug 2012 06:03:13 +0200 Subject: [Python-checkins] Daily reference leaks (aaa68dce117e): sum=2 Message-ID: results for aaa68dce117e on branch "default" -------------------------------------------- test_dbm leaked [0, 2, 0] references, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogL5vk9m', '-x'] From python-checkins at python.org Fri Aug 10 06:05:29 2012 From: python-checkins at python.org (brian.curtin) Date: Fri, 10 Aug 2012 06:05:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogRml4ICMxNTU2Ny4g?= =?utf-8?q?collections=2Edeque_wasn=27t_imported?= Message-ID: <3WtXmn2g66zPtR@mail.python.org> http://hg.python.org/cpython/rev/260f3ad7af4b changeset: 78484:260f3ad7af4b branch: 2.7 parent: 78481:6dab233a115e user: Brian Curtin date: Thu Aug 09 23:04:42 2012 -0500 summary: Fix #15567. collections.deque wasn't imported files: Lib/threading.py | 3 ++- Misc/NEWS | 2 ++ 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Lib/threading.py b/Lib/threading.py --- a/Lib/threading.py +++ b/Lib/threading.py @@ -10,6 +10,7 @@ import warnings +from collections import deque as _deque from time import time as _time, sleep as _sleep from traceback import format_exc as _format_exc @@ -913,7 +914,7 @@ self.rc = Condition(self.mon) self.wc = Condition(self.mon) self.limit = limit - self.queue = deque() + self.queue = _deque() def put(self, item): self.mon.acquire() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -92,6 +92,8 @@ Library ------- +- Issue #15567: Fix NameError when running threading._test + - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 10 18:21:23 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 10 Aug 2012 18:21:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315502=3A_Finish_b?= =?utf-8?q?ringing_importlib=2Eabc_in_line_with_the_current?= Message-ID: <3Wts5v4zWZzPvR@mail.python.org> http://hg.python.org/cpython/rev/0a75ce232f56 changeset: 78485:0a75ce232f56 parent: 78483:aaa68dce117e user: Brett Cannon date: Fri Aug 10 12:21:12 2012 -0400 summary: Issue #15502: Finish bringing importlib.abc in line with the current state of the import system. Also make importlib.invalidate_caches() work with sys.meta_path instead of sys.path_importer_cache to completely separate the path-based import system from the overall import system. Patch by Eric Snow. files: Doc/library/importlib.rst | 68 +- Lib/importlib/__init__.py | 6 +- Lib/importlib/_bootstrap.py | 12 +- Lib/importlib/abc.py | 42 +- Lib/test/test_importlib/test_abc.py | 2 + Lib/test/test_importlib/test_api.py | 10 +- Misc/NEWS | 3 + Python/importlib.h | 2362 +++++++------- 8 files changed, 1296 insertions(+), 1209 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -102,12 +102,11 @@ .. function:: invalidate_caches() - Invalidate the internal caches of the finders stored at - :data:`sys.path_importer_cache`. If a finder implements - :meth:`abc.Finder.invalidate_caches()` then it will be called to perform the - invalidation. This function may be needed if some modules are installed - while your program is running and you expect the program to notice the - changes. + Invalidate the internal caches of finders stored at + :data:`sys.meta_path`. If a finder implements ``invalidate_caches()`` then it + will be called to perform the invalidation. This function may be needed if + some modules are installed while your program is running and you expect the + program to notice the changes. .. versionadded:: 3.3 @@ -129,22 +128,17 @@ implementations should derive from (or register with) the more specific :class:`MetaPathFinder` or :class:`PathEntryFinder` ABCs. - .. method:: invalidate_caches() + .. method:: find_module(fullname, path=None) - An optional method which, when called, should invalidate any internal - cache used by the finder. Used by :func:`invalidate_caches()` when - invalidating the caches of all cached finders. - - .. versionchanged:: 3.3 - The API signatures for meta path finders and path entry finders - were separated by PEP 420. Accordingly, the Finder ABC no - longer requires implementation of a ``find_module()`` method. + An abstact method for finding a :term:`loader` for the specified + module. Originally specified in :pep:`302`, this method was meant + for use in :data:`sys.meta_path` and in the path-based import subsystem. .. class:: MetaPathFinder - An abstract base class representing a :term:`meta path finder` and - inheriting from :class:`Finder`. + An abstract base class representing a :term:`meta path finder`. For + compatibility, this is a subclass of :class:`Finder`. .. versionadded:: 3.3 @@ -156,20 +150,45 @@ will be the value of :attr:`__path__` from the parent package. If a loader cannot be found, ``None`` is returned. + .. method:: invalidate_caches() + + An optional method which, when called, should invalidate any internal + cache used by the finder. Used by :func:`invalidate_caches()` when + invalidating the caches of all finders on :data:`sys.meta_path`. + .. class:: PathEntryFinder - An abstract base class representing a :term:`path entry finder` and - inheriting from :class:`Finder`. + An abstract base class representing a :term:`path entry finder`. Though + it bears some similarities to :class:`MetaPathFinder`, ``PathEntryFinder`` + is meant for use only within the path-based import subsystem provided + by :class:`PathFinder`. This ABC is a subclass of :class:`Finder` for + compatibility. .. versionadded:: 3.3 .. method:: find_loader(fullname): An abstract method for finding a :term:`loader` for the specified - module. Returns a 2-tuple of ``(loader, portion)`` where portion is a - sequence of file system locations contributing to part of a namespace - package. The sequence may be empty. + module. Returns a 2-tuple of ``(loader, portion)`` where ``portion`` + is a sequence of file system locations contributing to part of a namespace + package. The loader may be ``None`` while specifying ``portion`` to + signify the contribution of the file system locations to a namespace + package. An empty list can be used for ``portion`` to signify the loader + is not part of a package. If ``loader`` is ``None`` and ``portion`` is + the empty list then no loader or location for a namespace package were + found (i.e. failure to find anything for the module). + + .. method:: find_module(fullname): + + A concrete implementation of :meth:`Finder.find_module` which is + equivalent to ``self.find_loader(fullname)[0]``. + + .. method:: invalidate_caches() + + An optional method which, when called, should invalidate any internal + cache used by the finder. Used by :meth:`PathFinder.invalidate_caches()` + when invalidating the caches of all cached finders. .. class:: Loader @@ -638,6 +657,11 @@ module. If no finder is ever found then ``None`` is both stored in the cache and returned. + .. classmethod:: invalidate_caches() + + Call :meth:`importlib.abc.PathEntryFinder.invalidate_caches` on all + finders stored in :attr:`sys.path_importer_cache`. + .. class:: FileFinder(path, \*loader_details) diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -38,9 +38,9 @@ def invalidate_caches(): - """Call the invalidate_caches() method on all finders stored in - sys.path_importer_caches (where implemented).""" - for finder in sys.path_importer_cache.values(): + """Call the invalidate_caches() method on all meta path finders stored in + sys.meta_path (where implemented).""" + for finder in sys.meta_path: if hasattr(finder, 'invalidate_caches'): finder.invalidate_caches() diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1186,6 +1186,14 @@ """Meta path finder for sys.path and package __path__ attributes.""" @classmethod + def invalidate_caches(cls): + """Call the invalidate_caches() method on all path entry finders + stored in sys.path_importer_caches (where implemented).""" + for finder in sys.path_importer_cache.values(): + if hasattr(finder, 'invalidate_caches'): + finder.invalidate_caches() + + @classmethod def _path_hooks(cls, path): """Search sequence of hooks for a finder for 'path'. @@ -1235,14 +1243,14 @@ portions = [] if loader is not None: # We found a loader: return it immediately. - return (loader, namespace_path) + return loader, namespace_path # This is possibly part of a namespace package. # Remember these path entries (if any) for when we # create a namespace package, and continue iterating # on path. namespace_path.extend(portions) else: - return (None, namespace_path) + return None, namespace_path @classmethod def find_module(cls, fullname, path=None): diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -25,26 +25,22 @@ class Finder(metaclass=abc.ABCMeta): - """Common abstract base class for import finders. + """Legacy abstract base class for import finders. - Finder implementations should derive from the more specific - MetaPathFinder or PathEntryFinder ABCs rather than directly from Finder. + It may be subclassed for compatibility with legacy third party + reimplementations of the import system. Otherwise, finder + implementations should derive from the more specific MetaPathFinder + or PathEntryFinder ABCs. """ + @abc.abstractmethod def find_module(self, fullname, path=None): - """An optional legacy method that should find a module. + """An abstract method that should find a module. The fullname is a str and the optional path is a str or None. Returns a Loader object. - - The path finder will use this method only if find_loader() does - not exist. It may optionally be implemented for compatibility - with legacy third party reimplementations of the import system. """ raise NotImplementedError - # invalidate_caches() is a completely optional method, so no default - # implementation is provided. See the docs for details. - class MetaPathFinder(Finder): @@ -52,12 +48,18 @@ @abc.abstractmethod def find_module(self, fullname, path): - """Abstract method which when implemented should find a module. + """Abstract method which, when implemented, should find a module. The fullname is a str and the path is a str or None. Returns a Loader object. """ raise NotImplementedError + def invalidate_caches(self): + """An optional method for clearing the finder's cache, if any. + This method is used by importlib.invalidate_caches(). + """ + return NotImplemented + _register(MetaPathFinder, machinery.BuiltinImporter, machinery.FrozenImporter, machinery.PathFinder, machinery.WindowsRegistryFinder) @@ -68,13 +70,25 @@ @abc.abstractmethod def find_loader(self, fullname): - """Abstract method which when implemented returns a module loader. + """Abstract method which, when implemented, returns a module loader. The fullname is a str. Returns a 2-tuple of (Loader, portion) where portion is a sequence of file system locations contributing to part of - a namespace package. The sequence may be empty. + a namespace package. The sequence may be empty and the loader may be + None. """ raise NotImplementedError + def find_module(self, fullname): + """Compatibility function which is the equivalent of + self.find_loader(fullname)[0].""" + return self.find_loader(fullname)[0] + + def invalidate_caches(self): + """An optional method for clearing the finder's cache, if any. + This method is used by PathFinder.invalidate_caches(). + """ + return NotImplemented + _register(PathEntryFinder, machinery.FileFinder) diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py --- a/Lib/test/test_importlib/test_abc.py +++ b/Lib/test/test_importlib/test_abc.py @@ -36,11 +36,13 @@ subclasses = [machinery.BuiltinImporter, machinery.FrozenImporter, machinery.PathFinder, machinery.WindowsRegistryFinder] + class PathEntryFinder(InheritanceTests, unittest.TestCase): superclasses = [abc.Finder] subclasses = [machinery.FileFinder] + class Loader(InheritanceTests, unittest.TestCase): subclasses = [abc.PyLoader] diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -148,11 +148,15 @@ self.called = True key = 'gobledeegook' - ins = InvalidatingNullFinder() - sys.path_importer_cache[key] = ins + meta_ins = InvalidatingNullFinder() + path_ins = InvalidatingNullFinder() + sys.meta_path.insert(0, meta_ins) self.addCleanup(lambda: sys.path_importer_cache.__delitem__(key)) + sys.path_importer_cache[key] = path_ins + self.addCleanup(lambda: sys.meta_path.remove(meta_ins)) importlib.invalidate_caches() - self.assertTrue(ins.called) + self.assertTrue(meta_ins.called) + self.assertTrue(path_ins.called) def test_method_lacking(self): # There should be no issues if the method is not defined. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -80,6 +80,9 @@ Library ------- +- Issue #15502: Have importlib.invalidate_caches() work on sys.meta_path + instead of sys.path_importer_cache. + - Issue #15163: Pydoc shouldn't list __loader__ as module data. - Issue #15471: Do not use mutable objects as defaults for 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 Fri Aug 10 19:48:04 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 10 Aug 2012 19:48:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315576=3A_Allow_ex?= =?utf-8?q?tension_modules_to_be_a_package=27s_=5F=5Finit=5F=5F?= Message-ID: <3Wtv1w332MzPxd@mail.python.org> http://hg.python.org/cpython/rev/1db6553f3f8c changeset: 78486:1db6553f3f8c user: Brett Cannon date: Fri Aug 10 13:47:54 2012 -0400 summary: Issue #15576: Allow extension modules to be a package's __init__ module again. Also took the opportunity to stop accidentally exporting _imp.extension_suffixes() as public. files: Doc/library/importlib.rst | 8 +- Lib/imp.py | 4 +- Lib/importlib/_bootstrap.py | 38 +- Lib/importlib/machinery.py | 4 +- Lib/test/test_importlib/extension/test_case_sensitivity.py | 3 +- Lib/test/test_importlib/extension/test_finder.py | 16 +- Lib/test/test_importlib/extension/test_loader.py | 12 +- Lib/test/test_importlib/extension/test_path_hook.py | 6 +- Lib/test/test_importlib/source/test_case_sensitivity.py | 6 +- Lib/test/test_importlib/source/test_finder.py | 8 +- Lib/test/test_importlib/source/test_path_hook.py | 2 +- Misc/NEWS | 2 + Python/importlib.h | 7279 +++++---- 13 files changed, 3700 insertions(+), 3688 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -671,9 +671,8 @@ The *path* argument is the directory for which the finder is in charge of searching. - The *loader_details* argument is a variable number of 3-item tuples each - containing a loader, file suffixes the loader recognizes, and a boolean - representing whether the loader handles packages. + The *loader_details* argument is a variable number of 2-item tuples each + containing a loader and a sequence of file suffixes the loader recognizes. The finder will cache the directory contents as necessary, making stat calls for each module search to verify the cache is not outdated. Because cache @@ -798,7 +797,8 @@ .. method:: is_package(fullname) - Returns ``False`` as extension modules can never be packages. + Returns ``True`` if the file path points to a package's ``__init__`` + module based on :attr:`EXTENSION_SUFFIXES`. .. method:: get_code(fullname) diff --git a/Lib/imp.py b/Lib/imp.py --- a/Lib/imp.py +++ b/Lib/imp.py @@ -9,7 +9,7 @@ from _imp import (lock_held, acquire_lock, release_lock, load_dynamic, get_frozen_object, is_frozen_package, init_builtin, init_frozen, is_builtin, is_frozen, - _fix_co_filename, extension_suffixes) + _fix_co_filename) # Directly exposed by this module from importlib._bootstrap import new_module @@ -51,7 +51,7 @@ warnings.warn('imp.get_suffixes() is deprecated; use the constants ' 'defined on importlib.machinery instead', DeprecationWarning, 2) - extensions = [(s, 'rb', C_EXTENSION) for s in extension_suffixes()] + extensions = [(s, 'rb', C_EXTENSION) for s in machinery.EXTENSION_SUFFIXES] source = [(s, 'U', PY_SOURCE) for s in machinery.SOURCE_SUFFIXES] bytecode = [(s, 'rb', PY_COMPILED) for s in machinery.BYTECODE_SUFFIXES] diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1067,6 +1067,10 @@ return None +# Filled in by _setup(). +EXTENSION_SUFFIXES = [] + + class ExtensionFileLoader: """Loader for extension modules. @@ -1089,6 +1093,8 @@ module = _call_with_frames_removed(_imp.load_dynamic, fullname, self.path) _verbose_message('extension module loaded from {!r}', self.path) + if self.is_package(fullname): + module.__path__ = [_path_split(self.path)[0]] return module except: if not is_reload and fullname in sys.modules: @@ -1097,7 +1103,12 @@ def is_package(self, fullname): """Return False as an extension module can never be a package.""" - return False + file_name = _path_split(self.path)[1] + for suffix in EXTENSION_SUFFIXES: + if file_name == '__init__' + suffix: + return True + else: + return False def get_code(self, fullname): """Return None as an extension module cannot create a code object.""" @@ -1283,14 +1294,10 @@ """Initialize with the path to search on and a variable number of 3-tuples containing the loader, file suffixes the loader recognizes, and a boolean of whether the loader handles packages.""" - packages = [] - modules = [] - for loader, suffixes, supports_packages in details: - modules.extend((suffix, loader) for suffix in suffixes) - if supports_packages: - packages.extend((suffix, loader) for suffix in suffixes) - self.packages = packages - self.modules = modules + loaders = [] + for loader, suffixes in details: + loaders.extend((suffix, loader) for suffix in suffixes) + self._loaders = loaders # Base (directory) path self.path = path or '.' self._path_mtime = -1 @@ -1336,7 +1343,7 @@ if cache_module in cache: base_path = _path_join(self.path, tail_module) if _path_isdir(base_path): - for suffix, loader in self.packages: + for suffix, loader in self._loaders: init_filename = '__init__' + suffix full_path = _path_join(base_path, init_filename) if _path_isfile(full_path): @@ -1346,7 +1353,7 @@ # find a module in the next section. is_namespace = True # Check for a file w/ a proper suffix exists. - for suffix, loader in self.modules: + for suffix, loader in self._loaders: if cache_module + suffix in cache: full_path = _path_join(self.path, tail_module + suffix) if _path_isfile(full_path): @@ -1589,9 +1596,9 @@ Each item is a tuple (loader, suffixes, allow_packages). """ - extensions = ExtensionFileLoader, _imp.extension_suffixes(), False - source = SourceFileLoader, SOURCE_SUFFIXES, True - bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES, True + extensions = ExtensionFileLoader, _imp.extension_suffixes() + source = SourceFileLoader, SOURCE_SUFFIXES + bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES return [extensions, source, bytecode] @@ -1689,9 +1696,10 @@ setattr(self_module, 'path_separators', set(path_separators)) # Constants setattr(self_module, '_relax_case', _make_relax_case()) + EXTENSION_SUFFIXES.extend(_imp.extension_suffixes()) if builtin_os == 'nt': SOURCE_SUFFIXES.append('.pyw') - if '_d.pyd' in _imp.extension_suffixes(): + if '_d.pyd' in EXTENSION_SUFFIXES: WindowsRegistryFinder.DEBUG_BUILD = True diff --git a/Lib/importlib/machinery.py b/Lib/importlib/machinery.py --- a/Lib/importlib/machinery.py +++ b/Lib/importlib/machinery.py @@ -3,7 +3,8 @@ import _imp from ._bootstrap import (SOURCE_SUFFIXES, DEBUG_BYTECODE_SUFFIXES, - OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES) + OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES, + EXTENSION_SUFFIXES) from ._bootstrap import BuiltinImporter from ._bootstrap import FrozenImporter from ._bootstrap import WindowsRegistryFinder @@ -13,7 +14,6 @@ from ._bootstrap import SourcelessFileLoader from ._bootstrap import ExtensionFileLoader -EXTENSION_SUFFIXES = _imp.extension_suffixes() def all_suffixes(): """Returns a list of all recognized module suffixes for this process""" diff --git a/Lib/test/test_importlib/extension/test_case_sensitivity.py b/Lib/test/test_importlib/extension/test_case_sensitivity.py --- a/Lib/test/test_importlib/extension/test_case_sensitivity.py +++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py @@ -16,8 +16,7 @@ assert good_name != bad_name finder = _bootstrap.FileFinder(ext_util.PATH, (_bootstrap.ExtensionFileLoader, - imp.extension_suffixes(), - False)) + _bootstrap.EXTENSION_SUFFIXES)) return finder.find_module(bad_name) def test_case_sensitive(self): diff --git a/Lib/test/test_importlib/extension/test_finder.py b/Lib/test/test_importlib/extension/test_finder.py --- a/Lib/test/test_importlib/extension/test_finder.py +++ b/Lib/test/test_importlib/extension/test_finder.py @@ -1,8 +1,7 @@ -from importlib import _bootstrap +from importlib import machinery from .. import abc from . import util -import imp import unittest class FinderTests(abc.FinderTests): @@ -10,17 +9,16 @@ """Test the finder for extension modules.""" def find_module(self, fullname): - importer = _bootstrap.FileFinder(util.PATH, - (_bootstrap.ExtensionFileLoader, - imp.extension_suffixes(), - False)) + importer = machinery.FileFinder(util.PATH, + (machinery.ExtensionFileLoader, + machinery.EXTENSION_SUFFIXES)) return importer.find_module(fullname) def test_module(self): self.assertTrue(self.find_module(util.NAME)) def test_package(self): - # Extension modules cannot be an __init__ for a package. + # No extension module as an __init__ available for testing. pass def test_module_in_package(self): @@ -28,7 +26,7 @@ pass def test_package_in_package(self): - # Extension modules cannot be an __init__ for a package. + # No extension module as an __init__ available for testing. pass def test_package_over_module(self): @@ -38,8 +36,6 @@ def test_failure(self): self.assertIsNone(self.find_module('asdfjkl;')) - # XXX Raise an exception if someone tries to use the 'path' argument? - def test_main(): from test.support import run_unittest diff --git a/Lib/test/test_importlib/extension/test_loader.py b/Lib/test/test_importlib/extension/test_loader.py --- a/Lib/test/test_importlib/extension/test_loader.py +++ b/Lib/test/test_importlib/extension/test_loader.py @@ -3,6 +3,7 @@ from .. import abc from .. import util +import os.path import sys import unittest @@ -38,11 +39,11 @@ machinery.ExtensionFileLoader) def test_package(self): - # Extensions are not found in packages. + # No extension module as __init__ available for testing. pass def test_lacking_parent(self): - # Extensions are not found in packages. + # No extension module in a package available for testing. pass def test_module_reuse(self): @@ -61,6 +62,13 @@ self.load_module(name) self.assertEqual(cm.exception.name, name) + def test_is_package(self): + self.assertFalse(self.loader.is_package(ext_util.NAME)) + for suffix in machinery.EXTENSION_SUFFIXES: + path = os.path.join('some', 'path', 'pkg', '__init__' + suffix) + loader = machinery.ExtensionFileLoader('pkg', path) + self.assertTrue(loader.is_package('pkg')) + def test_main(): from test.support import run_unittest diff --git a/Lib/test/test_importlib/extension/test_path_hook.py b/Lib/test/test_importlib/extension/test_path_hook.py --- a/Lib/test/test_importlib/extension/test_path_hook.py +++ b/Lib/test/test_importlib/extension/test_path_hook.py @@ -1,4 +1,4 @@ -from importlib import _bootstrap +from importlib import machinery from . import util import collections @@ -14,8 +14,8 @@ # XXX Should it only work for directories containing an extension module? def hook(self, entry): - return _bootstrap.FileFinder.path_hook((_bootstrap.ExtensionFileLoader, - imp.extension_suffixes(), False))(entry) + return machinery.FileFinder.path_hook((machinery.ExtensionFileLoader, + machinery.EXTENSION_SUFFIXES))(entry) def test_success(self): # Path hook should handle a directory where a known extension module diff --git a/Lib/test/test_importlib/source/test_case_sensitivity.py b/Lib/test/test_importlib/source/test_case_sensitivity.py --- a/Lib/test/test_importlib/source/test_case_sensitivity.py +++ b/Lib/test/test_importlib/source/test_case_sensitivity.py @@ -23,11 +23,9 @@ def find(self, path): finder = machinery.FileFinder(path, (machinery.SourceFileLoader, - machinery.SOURCE_SUFFIXES, - True), + machinery.SOURCE_SUFFIXES), (machinery.SourcelessFileLoader, - machinery.BYTECODE_SUFFIXES, - True)) + machinery.BYTECODE_SUFFIXES)) return finder.find_module(self.name) def sensitivity_test(self): diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py --- a/Lib/test/test_importlib/source/test_finder.py +++ b/Lib/test/test_importlib/source/test_finder.py @@ -37,9 +37,9 @@ def import_(self, root, module): loader_details = [(machinery.SourceFileLoader, - machinery.SOURCE_SUFFIXES, True), + machinery.SOURCE_SUFFIXES), (machinery.SourcelessFileLoader, - machinery.BYTECODE_SUFFIXES, True)] + machinery.BYTECODE_SUFFIXES)] finder = machinery.FileFinder(root, *loader_details) return finder.find_module(module) @@ -120,7 +120,7 @@ def test_empty_string_for_dir(self): # The empty string from sys.path means to search in the cwd. finder = machinery.FileFinder('', (machinery.SourceFileLoader, - machinery.SOURCE_SUFFIXES, True)) + machinery.SOURCE_SUFFIXES)) with open('mod.py', 'w') as file: file.write("# test file for importlib") try: @@ -132,7 +132,7 @@ def test_invalidate_caches(self): # invalidate_caches() should reset the mtime. finder = machinery.FileFinder('', (machinery.SourceFileLoader, - machinery.SOURCE_SUFFIXES, True)) + machinery.SOURCE_SUFFIXES)) finder._path_mtime = 42 finder.invalidate_caches() self.assertEqual(finder._path_mtime, -1) diff --git a/Lib/test/test_importlib/source/test_path_hook.py b/Lib/test/test_importlib/source/test_path_hook.py --- a/Lib/test/test_importlib/source/test_path_hook.py +++ b/Lib/test/test_importlib/source/test_path_hook.py @@ -11,7 +11,7 @@ def path_hook(self): return machinery.FileFinder.path_hook((machinery.SourceFileLoader, - machinery.SOURCE_SUFFIXES, True)) + machinery.SOURCE_SUFFIXES)) def test_success(self): with source_util.create_modules('dummy') as mapping: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -80,6 +80,8 @@ Library ------- +- Issue #15576: Allow extension modules to act as a package's __init__ module. + - Issue #15502: Have importlib.invalidate_caches() work on sys.meta_path instead of sys.path_importer_cache. 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 Fri Aug 10 22:17:04 2012 From: python-checkins at python.org (philip.jenvey) Date: Fri, 10 Aug 2012 22:17:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_update_docstring_per_the_e?= =?utf-8?q?xtension_package_fix=2C_refactor?= Message-ID: <3WtyKr20cfzPHX@mail.python.org> http://hg.python.org/cpython/rev/e024f6ba5ed8 changeset: 78487:e024f6ba5ed8 user: Philip Jenvey date: Fri Aug 10 11:53:54 2012 -0700 summary: update docstring per the extension package fix, refactor files: Lib/importlib/_bootstrap.py | 9 +- Python/importlib.h | 3353 +++++++++++----------- 2 files changed, 1685 insertions(+), 1677 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1102,13 +1102,10 @@ raise def is_package(self, fullname): - """Return False as an extension module can never be a package.""" + """Return if the extension module is a package.""" file_name = _path_split(self.path)[1] - for suffix in EXTENSION_SUFFIXES: - if file_name == '__init__' + suffix: - return True - else: - return False + return any(file_name == '__init__' + suffix + for suffix in EXTENSION_SUFFIXES) def get_code(self, fullname): """Return None as an extension module cannot create a code object.""" 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 Fri Aug 10 22:55:51 2012 From: python-checkins at python.org (senthil.kumaran) Date: Fri, 10 Aug 2012 22:55:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_issue_=2315607=3A_Upda?= =?utf-8?q?te_the_print_builtin_function_docstring_with_the_new?= Message-ID: <3WtzBb1kmJzQ44@mail.python.org> http://hg.python.org/cpython/rev/e4877d59613d changeset: 78488:e4877d59613d user: Senthil Kumaran date: Fri Aug 10 13:53:45 2012 -0700 summary: Fix issue #15607: Update the print builtin function docstring with the new flush keyword. Patch contributed by Daniel Ellis. files: Python/bltinmodule.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1590,13 +1590,14 @@ } PyDoc_STRVAR(print_doc, -"print(value, ..., sep=' ', end='\\n', file=sys.stdout)\n\ +"print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\ \n\ Prints the values to a stream, or to sys.stdout by default.\n\ Optional keyword arguments:\n\ -file: a file-like object (stream); defaults to the current sys.stdout.\n\ -sep: string inserted between values, default a space.\n\ -end: string appended after the last value, default a newline."); +file: a file-like object (stream); defaults to the current sys.stdout.\n\ +sep: string inserted between values, default a space.\n\ +end: string appended after the last value, default a newline.\n\ +flush: whether to forcibly flush the stream."); static PyObject * -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 10 23:41:32 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 10 Aug 2012 23:41:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315502=3A_Refactor?= =?utf-8?q?_some_code=2E?= Message-ID: <3Wv0CJ4BF3zPW1@mail.python.org> http://hg.python.org/cpython/rev/e7a67f1bf604 changeset: 78489:e7a67f1bf604 user: Brett Cannon date: Fri Aug 10 17:41:23 2012 -0400 summary: Issue #15502: Refactor some code. files: Lib/importlib/_bootstrap.py | 27 +- Lib/importlib/abc.py | 5 +- Python/importlib.h | 8337 +++++++++++----------- 3 files changed, 4186 insertions(+), 4183 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -607,6 +607,21 @@ return _requires_frozen_wrapper +def _find_module_shim(self, fullname): + """Try to find a loader for the specified module by delegating to + self.find_loader().""" + # Call find_loader(). If it returns a string (indicating this + # is a namespace package portion), generate a warning and + # return None. + loader, portions = self.find_loader(fullname) + if loader is None and len(portions): + msg = "Not importing directory {}: missing __init__" + _warnings.warn(msg.format(portions[0]), ImportWarning) + return loader + + + + # Loaders ##################################################################### class BuiltinImporter: @@ -1305,17 +1320,7 @@ """Invalidate the directory mtime.""" self._path_mtime = -1 - def find_module(self, fullname): - """Try to find a loader for the specified module.""" - # Call find_loader(). If it returns a string (indicating this - # is a namespace package portion), generate a warning and - # return None. - loader, portions = self.find_loader(fullname) - assert len(portions) in [0, 1] - if loader is None and len(portions): - msg = "Not importing directory {}: missing __init__" - _warnings.warn(msg.format(portions[0]), ImportWarning) - return loader + find_module = _find_module_shim def find_loader(self, fullname): """Try to find a loader for the specified module, or the namespace diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -78,10 +78,7 @@ """ raise NotImplementedError - def find_module(self, fullname): - """Compatibility function which is the equivalent of - self.find_loader(fullname)[0].""" - return self.find_loader(fullname)[0] + find_module = _bootstrap._find_module_shim def invalidate_caches(self): """An optional method for clearing the finder's cache, if any. 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 ericsnowcurrently at gmail.com Sat Aug 11 00:15:27 2012 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Fri, 10 Aug 2012 16:15:27 -0600 Subject: [Python-checkins] cpython: update docstring per the extension package fix, refactor In-Reply-To: <3WtyKr20cfzPHX@mail.python.org> References: <3WtyKr20cfzPHX@mail.python.org> Message-ID: On Fri, Aug 10, 2012 at 2:17 PM, philip.jenvey wrote: > http://hg.python.org/cpython/rev/e024f6ba5ed8 > changeset: 78487:e024f6ba5ed8 > user: Philip Jenvey > date: Fri Aug 10 11:53:54 2012 -0700 > summary: > update docstring per the extension package fix, refactor > > files: > Lib/importlib/_bootstrap.py | 9 +- > Python/importlib.h | 3353 +++++++++++----------- > 2 files changed, 1685 insertions(+), 1677 deletions(-) > > > diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py > --- a/Lib/importlib/_bootstrap.py > +++ b/Lib/importlib/_bootstrap.py > @@ -1102,13 +1102,10 @@ > raise > > def is_package(self, fullname): > - """Return False as an extension module can never be a package.""" > + """Return if the extension module is a package.""" s/Return if/Return True if/ -eric From python-checkins at python.org Sat Aug 11 00:55:16 2012 From: python-checkins at python.org (brett.cannon) Date: Sat, 11 Aug 2012 00:55:16 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315610=3A_The_PyIm?= =?utf-8?q?port=5FImportModuleEx_macro_now_calls?= Message-ID: <3Wv1rN54HqzPnJ@mail.python.org> http://hg.python.org/cpython/rev/9804aec74d4a changeset: 78490:9804aec74d4a user: Brett Cannon date: Fri Aug 10 18:55:08 2012 -0400 summary: Issue #15610: The PyImport_ImportModuleEx macro now calls PyImport_ImportModuleLevel() with a 'level' of 0 instead of -1 as the latter is no longer a valid value. Also added a versionchanged note for PyImport_ImportModuleLevel() just in case people don't make the connection between changes to __import__() and this C function. files: Doc/c-api/import.rst | 6 ++++-- Doc/whatsnew/3.3.rst | 5 +++++ Include/import.h | 2 +- Misc/NEWS | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -44,8 +44,7 @@ .. index:: builtin: __import__ Import a module. This is best described by referring to the built-in Python - function :func:`__import__`, as the standard :func:`__import__` function calls - this function directly. + function :func:`__import__`. The return value is a new reference to the imported module or top-level package, or *NULL* with an exception set on failure. Like for @@ -76,6 +75,9 @@ Similar to :c:func:`PyImport_ImportModuleLevelObject`, but the name is an UTF-8 encoded string instead of a Unicode object. + .. versionchanged:: 3.3 + Negative values for **level** are no longer accepted. + .. c:function:: PyObject* PyImport_Import(PyObject *name) This is a higher-level interface that calls the current "import hook 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 @@ -1880,6 +1880,11 @@ * :c:func:`PyImport_GetMagicNumber` now returns -1 upon failure. +* As a negative value for the **level** argument to :func:`__import__` is no + longer valid, the same now holds for :c:func:`PyImport_ImportModuleLevel`. + This also means that the value of **level** used by + :c:func:`PyImport_ImportModuleEx` is now 0 instead of -1. + Building C extensions --------------------- diff --git a/Include/import.h b/Include/import.h --- a/Include/import.h +++ b/Include/import.h @@ -62,7 +62,7 @@ ); #define PyImport_ImportModuleEx(n, g, l, f) \ - PyImport_ImportModuleLevel(n, g, l, f, -1) + PyImport_ImportModuleLevel(n, g, l, f, 0) PyAPI_FUNC(PyObject *) PyImport_GetImporter(PyObject *path); PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name); diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -237,6 +237,9 @@ C API ----- +- Issue #15610: PyImport_ImportModuleEx() now uses a 'level' of 0 instead of + -1. + - Issues #15169, #14599: Strip out the C implementation of imp.source_from_cache() used by PyImport_ExecCodeModuleWithPathnames() and used the Python code instead. Leads to PyImport_ExecCodeModuleObject() to not -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 01:53:28 2012 From: python-checkins at python.org (philip.jenvey) Date: Sat, 11 Aug 2012 01:53:28 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_fix_docstring_wording?= Message-ID: <3Wv37X3zghzPnq@mail.python.org> http://hg.python.org/cpython/rev/f7b59e890e30 changeset: 78491:f7b59e890e30 user: Philip Jenvey date: Fri Aug 10 16:21:35 2012 -0700 summary: fix docstring wording files: Lib/importlib/_bootstrap.py | 6 +- Python/importlib.h | 5265 +++++++++++----------- 2 files changed, 2636 insertions(+), 2635 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -731,7 +731,7 @@ @classmethod @_requires_frozen def is_package(cls, fullname): - """Return if the frozen module is a package.""" + """Return True if the frozen module is a package.""" return _imp.is_frozen_package(fullname) @@ -1025,7 +1025,7 @@ """Concrete implementation of SourceLoader using the file system.""" def path_stats(self, path): - """Return the metadat for the path.""" + """Return the metadata for the path.""" st = _os.stat(path) return {'mtime': st.st_mtime, 'size': st.st_size} @@ -1117,7 +1117,7 @@ raise def is_package(self, fullname): - """Return if the extension module is a package.""" + """Return True if the extension module is a package.""" file_name = _path_split(self.path)[1] return any(file_name == '__init__' + suffix for suffix in EXTENSION_SUFFIXES) 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 solipsis at pitrou.net Sat Aug 11 06:02:32 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 11 Aug 2012 06:02:32 +0200 Subject: [Python-checkins] Daily reference leaks (f7b59e890e30): sum=0 Message-ID: results for f7b59e890e30 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog81Ll8V', '-x'] From python-checkins at python.org Sat Aug 11 06:26:51 2012 From: python-checkins at python.org (meador.inge) Date: Sat, 11 Aug 2012 06:26:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NDI0?= =?utf-8?q?=3A_Add_a_=5F=5Fsizeof=5F=5F_implementation_for_array_objects?= =?utf-8?q?=2E?= Message-ID: <3Wv9Bz3Ht9zPpn@mail.python.org> http://hg.python.org/cpython/rev/91382d4e2dfb changeset: 78492:91382d4e2dfb branch: 2.7 parent: 78484:260f3ad7af4b user: Meador Inge date: Fri Aug 10 22:05:45 2012 -0500 summary: Issue #15424: Add a __sizeof__ implementation for array objects. Patch by Ludwig H?hne. files: Lib/test/test_array.py | 13 +++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/arraymodule.c | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 0 deletions(-) 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 @@ -985,6 +985,19 @@ upper = long(pow(2, a.itemsize * 8)) - 1L self.check_overflow(lower, upper) + @test_support.cpython_only + def test_sizeof_with_buffer(self): + a = array.array(self.typecode, self.example) + basesize = test_support.calcvobjsize('4P') + buffer_size = a.buffer_info()[1] * a.itemsize + test_support.check_sizeof(self, a, basesize + buffer_size) + + @test_support.cpython_only + def test_sizeof_without_buffer(self): + a = array.array(self.typecode) + basesize = test_support.calcvobjsize('4P') + test_support.check_sizeof(self, a, basesize) + class ByteTest(SignedNumberTest): typecode = 'b' diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -393,6 +393,7 @@ Greg Humphreys Eric Huss Jeremy Hylton +Ludwig H?hne Gerhard H?ring Fredrik H??rd Catalin Iacob diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -94,6 +94,9 @@ - Issue #15567: Fix NameError when running threading._test +- Issue #15424: Add a __sizeof__ implementation for array objects. + Patch by Ludwig H?hne. + - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1533,6 +1533,19 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); static PyObject * +array_sizeof(arrayobject *self, PyObject *unused) +{ + Py_ssize_t res; + res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize; + return PyLong_FromSsize_t(res); +} + +PyDoc_STRVAR(sizeof_doc, +"__sizeof__() -> int\n\ +\n\ +Size of the array in memory, in bytes."); + +static PyObject * array_get_typecode(arrayobject *a, void *closure) { char tc = a->ob_descr->typecode; @@ -1606,6 +1619,8 @@ #endif {"write", (PyCFunction)array_tofile_as_write, METH_O, tofile_doc}, + {"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS, + sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 06:26:53 2012 From: python-checkins at python.org (meador.inge) Date: Sat, 11 Aug 2012 06:26:53 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NDI0?= =?utf-8?q?=3A_Add_a_=5F=5Fsizeof=5F=5F_implementation_for_array_objects?= =?utf-8?q?=2E?= Message-ID: <3Wv9C12tbnzPqJ@mail.python.org> http://hg.python.org/cpython/rev/45ef9bc8739f changeset: 78493:45ef9bc8739f branch: 3.2 parent: 78479:4787b9b2f860 user: Meador Inge date: Fri Aug 10 22:35:45 2012 -0500 summary: Issue #15424: Add a __sizeof__ implementation for array objects. Patch by Ludwig H?hne. files: Lib/test/test_array.py | 13 +++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/arraymodule.c | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 0 deletions(-) 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 @@ -988,6 +988,19 @@ a = array.array('H', b"1234") self.assertEqual(len(a) * a.itemsize, 4) + @support.cpython_only + def test_sizeof_with_buffer(self): + a = array.array(self.typecode, self.example) + basesize = support.calcvobjsize('4Pi') + buffer_size = a.buffer_info()[1] * a.itemsize + support.check_sizeof(self, a, basesize + buffer_size) + + @support.cpython_only + def test_sizeof_without_buffer(self): + a = array.array(self.typecode) + basesize = support.calcvobjsize('4Pi') + support.check_sizeof(self, a, basesize) + class StringTest(BaseTest): diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -434,6 +434,7 @@ Greg Humphreys Eric Huss Jeremy Hylton +Ludwig H?hne Gerhard H?ring Fredrik H??rd Mihai Ibanescu diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,9 @@ Library ------- +- Issue #15424: Add a __sizeof__ implementation for array objects. + Patch by Ludwig H?hne. + - Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog ended with '\'. Patch by Roger Serwy. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1510,6 +1510,19 @@ an array of some other type."); +static PyObject * +array_sizeof(arrayobject *self, PyObject *unused) +{ + Py_ssize_t res; + res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize; + return PyLong_FromSsize_t(res); +} + +PyDoc_STRVAR(sizeof_doc, +"__sizeof__() -> int\n\ +\n\ +Size of the array in memory, in bytes."); + /*********************** Pickling support ************************/ @@ -2077,6 +2090,8 @@ tobytes_doc}, {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, tounicode_doc}, + {"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS, + sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 06:26:54 2012 From: python-checkins at python.org (meador.inge) Date: Sat, 11 Aug 2012 06:26:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315424=3A_Add_a_=5F=5Fsizeof=5F=5F_implementatio?= =?utf-8?q?n_for_array_objects=2E?= Message-ID: <3Wv9C26JJRzPqt@mail.python.org> http://hg.python.org/cpython/rev/7d82a60850fd changeset: 78494:7d82a60850fd parent: 78491:f7b59e890e30 parent: 78493:45ef9bc8739f user: Meador Inge date: Fri Aug 10 23:21:39 2012 -0500 summary: Issue #15424: Add a __sizeof__ implementation for array objects. Patch by Ludwig H?hne. files: Lib/test/test_array.py | 13 +++++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/arraymodule.c | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 0 deletions(-) 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 @@ -1015,6 +1015,19 @@ a = array.array('H', b"1234") self.assertEqual(len(a) * a.itemsize, 4) + @support.cpython_only + def test_sizeof_with_buffer(self): + a = array.array(self.typecode, self.example) + basesize = support.calcvobjsize('Pn2Pi') + buffer_size = a.buffer_info()[1] * a.itemsize + support.check_sizeof(self, a, basesize + buffer_size) + + @support.cpython_only + def test_sizeof_without_buffer(self): + a = array.array(self.typecode) + basesize = support.calcvobjsize('Pn2Pi') + support.check_sizeof(self, a, basesize) + class StringTest(BaseTest): diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -479,6 +479,7 @@ Eric Huss Taihyun Hwang Jeremy Hylton +Ludwig H?hne Gerhard H?ring Fredrik H??rd Catalin Iacob diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -80,6 +80,9 @@ Library ------- +- Issue #15424: Add a __sizeof__ implementation for array objects. + Patch by Ludwig H?hne. + - Issue #15576: Allow extension modules to act as a package's __init__ module. - Issue #15502: Have importlib.invalidate_caches() work on sys.meta_path diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1567,6 +1567,19 @@ an array of some other type."); +static PyObject * +array_sizeof(arrayobject *self, PyObject *unused) +{ + Py_ssize_t res; + res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize; + return PyLong_FromSsize_t(res); +} + +PyDoc_STRVAR(sizeof_doc, +"__sizeof__() -> int\n\ +\n\ +Size of the array in memory, in bytes."); + /*********************** Pickling support ************************/ @@ -2143,6 +2156,8 @@ tobytes_doc}, {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, tounicode_doc}, + {"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS, + sizeof_doc}, {NULL, NULL} /* sentinel */ }; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 08:49:33 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 08:49:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_markup_errors_and_upda?= =?utf-8?q?te_pydoc_topics=2E?= Message-ID: <3WvDMd6NbvzPnj@mail.python.org> http://hg.python.org/cpython/rev/102fa1b964e6 changeset: 78495:102fa1b964e6 user: Georg Brandl date: Sat Aug 11 08:43:59 2012 +0200 summary: Fix markup errors and update pydoc topics. files: Doc/reference/import.rst | 2 +- Doc/tools/sphinxext/susp-ignored.csv | 18 ++++++++++++++++ Doc/whatsnew/3.3.rst | 2 +- Lib/pydoc_data/topics.py | 14 ++++++------ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -358,7 +358,7 @@ iterable, but may be empty if ``__path__`` has no further significance to the importer. If ``__path__`` is not empty, it must produce strings when iterated over. More details on the semantics of ``__path__`` are - given :ref`below `. + given :ref:`below `. * The ``__loader__`` attribute must be set to the loader object that loaded the module. This is mostly for introspection and reloading, but can be diff --git a/Doc/tools/sphinxext/susp-ignored.csv b/Doc/tools/sphinxext/susp-ignored.csv --- a/Doc/tools/sphinxext/susp-ignored.csv +++ b/Doc/tools/sphinxext/susp-ignored.csv @@ -64,6 +64,10 @@ howto/ipaddress,,::,IPv6Address('2001::1') howto/ipaddress,,::,IPv6Address('2001::ffff:ffff') howto/ipaddress,,:ffff,IPv6Address('2001::ffff:ffff') +howto/ipaddress,,:db8,'2001:db8::' +howto/ipaddress,,::,'2001:db8::' +howto/ipaddress,,:db8,'2001:db8::/96' +howto/ipaddress,,::,'2001:db8::/96' howto/logging,,:And,"WARNING:And this, too" howto/logging,,:And,"WARNING:root:And this, too" howto/logging,,:Doing,INFO:root:Doing something @@ -151,6 +155,20 @@ library/ipaddress,,::,IPv6Address('ffff:ffff:ffff:ffff:ffff:ffff::') library/ipaddress,,:db8,">>> ipaddress.IPv6Network('2001:db8::1000/96', strict=False)" library/ipaddress,,::,">>> ipaddress.IPv6Network('2001:db8::1000/96', strict=False)" +library/ipaddress,,::,"""::abc:7:def""" +library/ipaddress,,:def,"""::abc:7:def""" +library/ipaddress,,::,::FFFF/96 +library/ipaddress,,::,2002::/16 +library/ipaddress,,::,2001::/32 +library/ipaddress,,::,>>> str(ipaddress.IPv6Address('::1')) +library/ipaddress,,::,'::1' +library/ipaddress,,::,>>> int(ipaddress.IPv6Address('::1')) +library/ipaddress,,:ff00,ffff:ff00:: +library/ipaddress,,:db00,2001:db00::0/24 +library/ipaddress,,::,2001:db00::0/24 +library/ipaddress,,:db00,2001:db00::0/ffff:ff00:: +library/ipaddress,,::,2001:db00::0/ffff:ff00:: +library/ipaddress,,:ff00,2001:db00::0/ffff:ff00:: library/itertools,,:step,elements from seq[start:stop:step] library/itertools,,:stop,elements from seq[start:stop:step] library/linecache,,:sys,"sys:x:3:3:sys:/dev:/bin/sh" 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 @@ -1135,7 +1135,7 @@ -- It is now possible to register callbacks invoked by the garbage collector -before and after collection using the new :`data:`~gc.callbacks` list. +before and after collection using the new :data:`~gc.callbacks` list. hmac diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py --- a/Lib/pydoc_data/topics.py +++ b/Lib/pydoc_data/topics.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Autogenerated by Sphinx on Tue Jun 26 09:10:52 2012 +# Autogenerated by Sphinx on Sat Aug 11 08:41:05 2012 topics = {'assert': '\nThe ``assert`` statement\n************************\n\nAssert statements are a convenient way to insert debugging assertions\ninto a program:\n\n assert_stmt ::= "assert" expression ["," expression]\n\nThe simple form, ``assert expression``, is equivalent to\n\n if __debug__:\n if not expression: raise AssertionError\n\nThe extended form, ``assert expression1, expression2``, is equivalent\nto\n\n if __debug__:\n if not expression1: raise AssertionError(expression2)\n\nThese equivalences assume that ``__debug__`` and ``AssertionError``\nrefer to the built-in variables with those names. In the current\nimplementation, the built-in variable ``__debug__`` is ``True`` under\nnormal circumstances, ``False`` when optimization is requested\n(command line option -O). The current code generator emits no code\nfor an assert statement when optimization is requested at compile\ntime. Note that it is unnecessary to include the source code for the\nexpression that failed in the error message; it will be displayed as\npart of the stack trace.\n\nAssignments to ``__debug__`` are illegal. The value for the built-in\nvariable is determined when the interpreter starts.\n', 'assignment': '\nAssignment statements\n*********************\n\nAssignment statements are used to (re)bind names to values and to\nmodify attributes or items of mutable objects:\n\n assignment_stmt ::= (target_list "=")+ (expression_list | yield_expression)\n target_list ::= target ("," target)* [","]\n target ::= identifier\n | "(" target_list ")"\n | "[" target_list "]"\n | attributeref\n | subscription\n | slicing\n | "*" target\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn assignment statement evaluates the expression list (remember that\nthis can be a single expression or a comma-separated list, the latter\nyielding a tuple) and assigns the single resulting object to each of\nthe target lists, from left to right.\n\nAssignment is defined recursively depending on the form of the target\n(list). When a target is part of a mutable object (an attribute\nreference, subscription or slicing), the mutable object must\nultimately perform the assignment and decide about its validity, and\nmay raise an exception if the assignment is unacceptable. The rules\nobserved by various types and the exceptions raised are given with the\ndefinition of the object types (see section *The standard type\nhierarchy*).\n\nAssignment of an object to a target list, optionally enclosed in\nparentheses or square brackets, is recursively defined as follows.\n\n* If the target list is a single target: The object is assigned to\n that target.\n\n* If the target list is a comma-separated list of targets: The object\n must be an iterable with the same number of items as there are\n targets in the target list, and the items are assigned, from left to\n right, to the corresponding targets.\n\n * If the target list contains one target prefixed with an asterisk,\n called a "starred" target: The object must be a sequence with at\n least as many items as there are targets in the target list, minus\n one. The first items of the sequence are assigned, from left to\n right, to the targets before the starred target. The final items\n of the sequence are assigned to the targets after the starred\n target. A list of the remaining items in the sequence is then\n assigned to the starred target (the list can be empty).\n\n * Else: The object must be a sequence with the same number of items\n as there are targets in the target list, and the items are\n assigned, from left to right, to the corresponding targets.\n\nAssignment of an object to a single target is recursively defined as\nfollows.\n\n* If the target is an identifier (name):\n\n * If the name does not occur in a ``global`` or ``nonlocal``\n statement in the current code block: the name is bound to the\n object in the current local namespace.\n\n * Otherwise: the name is bound to the object in the global namespace\n or the outer namespace determined by ``nonlocal``, respectively.\n\n The name is rebound if it was already bound. This may cause the\n reference count for the object previously bound to the name to reach\n zero, causing the object to be deallocated and its destructor (if it\n has one) to be called.\n\n* If the target is a target list enclosed in parentheses or in square\n brackets: The object must be an iterable with the same number of\n items as there are targets in the target list, and its items are\n assigned, from left to right, to the corresponding targets.\n\n* If the target is an attribute reference: The primary expression in\n the reference is evaluated. It should yield an object with\n assignable attributes; if this is not the case, ``TypeError`` is\n raised. That object is then asked to assign the assigned object to\n the given attribute; if it cannot perform the assignment, it raises\n an exception (usually but not necessarily ``AttributeError``).\n\n Note: If the object is a class instance and the attribute reference\n occurs on both sides of the assignment operator, the RHS expression,\n ``a.x`` can access either an instance attribute or (if no instance\n attribute exists) a class attribute. The LHS target ``a.x`` is\n always set as an instance attribute, creating it if necessary.\n Thus, the two occurrences of ``a.x`` do not necessarily refer to the\n same attribute: if the RHS expression refers to a class attribute,\n the LHS creates a new instance attribute as the target of the\n assignment:\n\n class Cls:\n x = 3 # class variable\n inst = Cls()\n inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x as 3\n\n This description does not necessarily apply to descriptor\n attributes, such as properties created with ``property()``.\n\n* If the target is a subscription: The primary expression in the\n reference is evaluated. It should yield either a mutable sequence\n object (such as a list) or a mapping object (such as a dictionary).\n Next, the subscript expression is evaluated.\n\n If the primary is a mutable sequence object (such as a list), the\n subscript must yield an integer. If it is negative, the sequence\'s\n length is added to it. The resulting value must be a nonnegative\n integer less than the sequence\'s length, and the sequence is asked\n to assign the assigned object to its item with that index. If the\n index is out of range, ``IndexError`` is raised (assignment to a\n subscripted sequence cannot add new items to a list).\n\n If the primary is a mapping object (such as a dictionary), the\n subscript must have a type compatible with the mapping\'s key type,\n and the mapping is then asked to create a key/datum pair which maps\n the subscript to the assigned object. This can either replace an\n existing key/value pair with the same key value, or insert a new\n key/value pair (if no key with the same value existed).\n\n For user-defined objects, the ``__setitem__()`` method is called\n with appropriate arguments.\n\n* If the target is a slicing: The primary expression in the reference\n is evaluated. It should yield a mutable sequence object (such as a\n list). The assigned object should be a sequence object of the same\n type. Next, the lower and upper bound expressions are evaluated,\n insofar they are present; defaults are zero and the sequence\'s\n length. The bounds should evaluate to integers. If either bound is\n negative, the sequence\'s length is added to it. The resulting\n bounds are clipped to lie between zero and the sequence\'s length,\n inclusive. Finally, the sequence object is asked to replace the\n slice with the items of the assigned sequence. The length of the\n slice may be different from the length of the assigned sequence,\n thus changing the length of the target sequence, if the object\n allows it.\n\n**CPython implementation detail:** In the current implementation, the\nsyntax for targets is taken to be the same as for expressions, and\ninvalid syntax is rejected during the code generation phase, causing\nless detailed error messages.\n\nWARNING: Although the definition of assignment implies that overlaps\nbetween the left-hand side and the right-hand side are \'safe\' (for\nexample ``a, b = b, a`` swaps two variables), overlaps *within* the\ncollection of assigned-to variables are not safe! For instance, the\nfollowing program prints ``[0, 2]``:\n\n x = [0, 1]\n i = 0\n i, x[i] = 1, 2\n print(x)\n\nSee also:\n\n **PEP 3132** - Extended Iterable Unpacking\n The specification for the ``*target`` feature.\n\n\nAugmented assignment statements\n===============================\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like ``x += 1`` can be rewritten as\n``x = x + 1`` to achieve a similar, but not exactly equal effect. In\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n', 'atom-identifiers': '\nIdentifiers (Names)\n*******************\n\nAn identifier occurring as an atom is a name. See section\n*Identifiers and keywords* for lexical definition and section *Naming\nand binding* for documentation of naming and binding.\n\nWhen the name is bound to an object, evaluation of the atom yields\nthat object. When a name is not bound, an attempt to evaluate it\nraises a ``NameError`` exception.\n\n**Private name mangling:** When an identifier that textually occurs in\na class definition begins with two or more underscore characters and\ndoes not end in two or more underscores, it is considered a *private\nname* of that class. Private names are transformed to a longer form\nbefore code is generated for them. The transformation inserts the\nclass name in front of the name, with leading underscores removed, and\na single underscore inserted in front of the class name. For example,\nthe identifier ``__spam`` occurring in a class named ``Ham`` will be\ntransformed to ``_Ham__spam``. This transformation is independent of\nthe syntactical context in which the identifier is used. If the\ntransformed name is extremely long (longer than 255 characters),\nimplementation defined truncation may happen. If the class name\nconsists only of underscores, no transformation is done.\n', @@ -23,7 +23,7 @@ 'context-managers': '\nWith Statement Context Managers\n*******************************\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n', 'continue': '\nThe ``continue`` statement\n**************************\n\n continue_stmt ::= "continue"\n\n``continue`` may only occur syntactically nested in a ``for`` or\n``while`` loop, but not nested in a function or class definition or\n``finally`` clause within that loop. It continues with the next cycle\nof the nearest enclosing loop.\n\nWhen ``continue`` passes control out of a ``try`` statement with a\n``finally`` clause, that ``finally`` clause is executed before really\nstarting the next loop cycle.\n', 'conversions': '\nArithmetic conversions\n**********************\n\nWhen a description of an arithmetic operator below uses the phrase\n"the numeric arguments are converted to a common type," this means\nthat the operator implementation for built-in types works that way:\n\n* If either argument is a complex number, the other is converted to\n complex;\n\n* otherwise, if either argument is a floating point number, the other\n is converted to floating point;\n\n* otherwise, both must be integers and no conversion is necessary.\n\nSome additional rules apply for certain operators (e.g., a string left\nargument to the \'%\' operator). Extensions must define their own\nconversion behavior.\n', - 'customization': '\nBasic customization\n*******************\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n for the ``gc`` module for more information about how\n ``__del__()`` methods are handled by the cycle detector,\n particularly the description of the ``garbage`` value.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the ``str()`` built-in function and by the ``print()``\n function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: Note by default the ``__hash__()`` values of str, bytes and\n datetime objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the order in which keys are\n retrieved from a dict. Note Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n', + 'customization': '\nBasic customization\n*******************\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n for the ``gc`` module for more information about how\n ``__del__()`` methods are handled by the cycle detector,\n particularly the description of the ``garbage`` value.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the ``str()`` built-in function and by the ``print()``\n function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n', 'debugger': '\n``pdb`` --- The Python Debugger\n*******************************\n\nThe module ``pdb`` defines an interactive source code debugger for\nPython programs. It supports setting (conditional) breakpoints and\nsingle stepping at the source line level, inspection of stack frames,\nsource code listing, and evaluation of arbitrary Python code in the\ncontext of any stack frame. It also supports post-mortem debugging\nand can be called under program control.\n\nThe debugger is extensible -- it is actually defined as the class\n``Pdb``. This is currently undocumented but easily understood by\nreading the source. The extension interface uses the modules ``bdb``\nand ``cmd``.\n\nThe debugger\'s prompt is ``(Pdb)``. Typical usage to run a program\nunder control of the debugger is:\n\n >>> import pdb\n >>> import mymodule\n >>> pdb.run(\'mymodule.test()\')\n > (0)?()\n (Pdb) continue\n > (1)?()\n (Pdb) continue\n NameError: \'spam\'\n > (1)?()\n (Pdb)\n\nChanged in version 3.3: Tab-completion via the ``readline`` module is\navailable for commands and command arguments, e.g. the current global\nand local names are offered as arguments of the ``print`` command.\n\n``pdb.py`` can also be invoked as a script to debug other scripts.\nFor example:\n\n python3 -m pdb myscript.py\n\nWhen invoked as a script, pdb will automatically enter post-mortem\ndebugging if the program being debugged exits abnormally. After post-\nmortem debugging (or after normal exit of the program), pdb will\nrestart the program. Automatic restarting preserves pdb\'s state (such\nas breakpoints) and in most cases is more useful than quitting the\ndebugger upon program\'s exit.\n\nNew in version 3.2: ``pdb.py`` now accepts a ``-c`` option that\nexecutes commands as if given in a ``.pdbrc`` file, see *Debugger\nCommands*.\n\nThe typical usage to break into the debugger from a running program is\nto insert\n\n import pdb; pdb.set_trace()\n\nat the location you want to break into the debugger. You can then\nstep through the code following this statement, and continue running\nwithout the debugger using the ``continue`` command.\n\nThe typical usage to inspect a crashed program is:\n\n >>> import pdb\n >>> import mymodule\n >>> mymodule.test()\n Traceback (most recent call last):\n File "", line 1, in ?\n File "./mymodule.py", line 4, in test\n test2()\n File "./mymodule.py", line 3, in test2\n print(spam)\n NameError: spam\n >>> pdb.pm()\n > ./mymodule.py(3)test2()\n -> print(spam)\n (Pdb)\n\nThe module defines the following functions; each enters the debugger\nin a slightly different way:\n\npdb.run(statement, globals=None, locals=None)\n\n Execute the *statement* (given as a string or a code object) under\n debugger control. The debugger prompt appears before any code is\n executed; you can set breakpoints and type ``continue``, or you can\n step through the statement using ``step`` or ``next`` (all these\n commands are explained below). The optional *globals* and *locals*\n arguments specify the environment in which the code is executed; by\n default the dictionary of the module ``__main__`` is used. (See\n the explanation of the built-in ``exec()`` or ``eval()``\n functions.)\n\npdb.runeval(expression, globals=None, locals=None)\n\n Evaluate the *expression* (given as a string or a code object)\n under debugger control. When ``runeval()`` returns, it returns the\n value of the expression. Otherwise this function is similar to\n ``run()``.\n\npdb.runcall(function, *args, **kwds)\n\n Call the *function* (a function or method object, not a string)\n with the given arguments. When ``runcall()`` returns, it returns\n whatever the function call returned. The debugger prompt appears\n as soon as the function is entered.\n\npdb.set_trace()\n\n Enter the debugger at the calling stack frame. This is useful to\n hard-code a breakpoint at a given point in a program, even if the\n code is not otherwise being debugged (e.g. when an assertion\n fails).\n\npdb.post_mortem(traceback=None)\n\n Enter post-mortem debugging of the given *traceback* object. If no\n *traceback* is given, it uses the one of the exception that is\n currently being handled (an exception must be being handled if the\n default is to be used).\n\npdb.pm()\n\n Enter post-mortem debugging of the traceback found in\n ``sys.last_traceback``.\n\nThe ``run*`` functions and ``set_trace()`` are aliases for\ninstantiating the ``Pdb`` class and calling the method of the same\nname. If you want to access further features, you have to do this\nyourself:\n\nclass class pdb.Pdb(completekey=\'tab\', stdin=None, stdout=None, skip=None, nosigint=False)\n\n ``Pdb`` is the debugger class.\n\n The *completekey*, *stdin* and *stdout* arguments are passed to the\n underlying ``cmd.Cmd`` class; see the description there.\n\n The *skip* argument, if given, must be an iterable of glob-style\n module name patterns. The debugger will not step into frames that\n originate in a module that matches one of these patterns. [1]\n\n By default, Pdb sets a handler for the SIGINT signal (which is sent\n when the user presses Ctrl-C on the console) when you give a\n ``continue`` command. This allows you to break into the debugger\n again by pressing Ctrl-C. If you want Pdb not to touch the SIGINT\n handler, set *nosigint* tot true.\n\n Example call to enable tracing with *skip*:\n\n import pdb; pdb.Pdb(skip=[\'django.*\']).set_trace()\n\n New in version 3.1: The *skip* argument.\n\n New in version 3.2: The *nosigint* argument. Previously, a SIGINT\n handler was never set by Pdb.\n\n run(statement, globals=None, locals=None)\n runeval(expression, globals=None, locals=None)\n runcall(function, *args, **kwds)\n set_trace()\n\n See the documentation for the functions explained above.\n\n\nDebugger Commands\n=================\n\nThe commands recognized by the debugger are listed below. Most\ncommands can be abbreviated to one or two letters as indicated; e.g.\n``h(elp)`` means that either ``h`` or ``help`` can be used to enter\nthe help command (but not ``he`` or ``hel``, nor ``H`` or ``Help`` or\n``HELP``). Arguments to commands must be separated by whitespace\n(spaces or tabs). Optional arguments are enclosed in square brackets\n(``[]``) in the command syntax; the square brackets must not be typed.\nAlternatives in the command syntax are separated by a vertical bar\n(``|``).\n\nEntering a blank line repeats the last command entered. Exception: if\nthe last command was a ``list`` command, the next 11 lines are listed.\n\nCommands that the debugger doesn\'t recognize are assumed to be Python\nstatements and are executed in the context of the program being\ndebugged. Python statements can also be prefixed with an exclamation\npoint (``!``). This is a powerful way to inspect the program being\ndebugged; it is even possible to change a variable or call a function.\nWhen an exception occurs in such a statement, the exception name is\nprinted but the debugger\'s state is not changed.\n\nThe debugger supports *aliases*. Aliases can have parameters which\nallows one a certain level of adaptability to the context under\nexamination.\n\nMultiple commands may be entered on a single line, separated by\n``;;``. (A single ``;`` is not used as it is the separator for\nmultiple commands in a line that is passed to the Python parser.) No\nintelligence is applied to separating the commands; the input is split\nat the first ``;;`` pair, even if it is in the middle of a quoted\nstring.\n\nIf a file ``.pdbrc`` exists in the user\'s home directory or in the\ncurrent directory, it is read in and executed as if it had been typed\nat the debugger prompt. This is particularly useful for aliases. If\nboth files exist, the one in the home directory is read first and\naliases defined there can be overridden by the local file.\n\nChanged in version 3.2: ``.pdbrc`` can now contain commands that\ncontinue debugging, such as ``continue`` or ``next``. Previously,\nthese commands had no effect.\n\nh(elp) [command]\n\n Without argument, print the list of available commands. With a\n *command* as argument, print help about that command. ``help pdb``\n displays the full documentation (the docstring of the ``pdb``\n module). Since the *command* argument must be an identifier,\n ``help exec`` must be entered to get help on the ``!`` command.\n\nw(here)\n\n Print a stack trace, with the most recent frame at the bottom. An\n arrow indicates the current frame, which determines the context of\n most commands.\n\nd(own) [count]\n\n Move the current frame *count* (default one) levels down in the\n stack trace (to a newer frame).\n\nu(p) [count]\n\n Move the current frame *count* (default one) levels up in the stack\n trace (to an older frame).\n\nb(reak) [([filename:]lineno | function) [, condition]]\n\n With a *lineno* argument, set a break there in the current file.\n With a *function* argument, set a break at the first executable\n statement within that function. The line number may be prefixed\n with a filename and a colon, to specify a breakpoint in another\n file (probably one that hasn\'t been loaded yet). The file is\n searched on ``sys.path``. Note that each breakpoint is assigned a\n number to which all the other breakpoint commands refer.\n\n If a second argument is present, it is an expression which must\n evaluate to true before the breakpoint is honored.\n\n Without argument, list all breaks, including for each breakpoint,\n the number of times that breakpoint has been hit, the current\n ignore count, and the associated condition if any.\n\ntbreak [([filename:]lineno | function) [, condition]]\n\n Temporary breakpoint, which is removed automatically when it is\n first hit. The arguments are the same as for ``break``.\n\ncl(ear) [filename:lineno | bpnumber [bpnumber ...]]\n\n With a *filename:lineno* argument, clear all the breakpoints at\n this line. With a space separated list of breakpoint numbers, clear\n those breakpoints. Without argument, clear all breaks (but first\n ask confirmation).\n\ndisable [bpnumber [bpnumber ...]]\n\n Disable the breakpoints given as a space separated list of\n breakpoint numbers. Disabling a breakpoint means it cannot cause\n the program to stop execution, but unlike clearing a breakpoint, it\n remains in the list of breakpoints and can be (re-)enabled.\n\nenable [bpnumber [bpnumber ...]]\n\n Enable the breakpoints specified.\n\nignore bpnumber [count]\n\n Set the ignore count for the given breakpoint number. If count is\n omitted, the ignore count is set to 0. A breakpoint becomes active\n when the ignore count is zero. When non-zero, the count is\n decremented each time the breakpoint is reached and the breakpoint\n is not disabled and any associated condition evaluates to true.\n\ncondition bpnumber [condition]\n\n Set a new *condition* for the breakpoint, an expression which must\n evaluate to true before the breakpoint is honored. If *condition*\n is absent, any existing condition is removed; i.e., the breakpoint\n is made unconditional.\n\ncommands [bpnumber]\n\n Specify a list of commands for breakpoint number *bpnumber*. The\n commands themselves appear on the following lines. Type a line\n containing just ``end`` to terminate the commands. An example:\n\n (Pdb) commands 1\n (com) print some_variable\n (com) end\n (Pdb)\n\n To remove all commands from a breakpoint, type commands and follow\n it immediately with ``end``; that is, give no commands.\n\n With no *bpnumber* argument, commands refers to the last breakpoint\n set.\n\n You can use breakpoint commands to start your program up again.\n Simply use the continue command, or step, or any other command that\n resumes execution.\n\n Specifying any command resuming execution (currently continue,\n step, next, return, jump, quit and their abbreviations) terminates\n the command list (as if that command was immediately followed by\n end). This is because any time you resume execution (even with a\n simple next or step), you may encounter another breakpoint--which\n could have its own command list, leading to ambiguities about which\n list to execute.\n\n If you use the \'silent\' command in the command list, the usual\n message about stopping at a breakpoint is not printed. This may be\n desirable for breakpoints that are to print a specific message and\n then continue. If none of the other commands print anything, you\n see no sign that the breakpoint was reached.\n\ns(tep)\n\n Execute the current line, stop at the first possible occasion\n (either in a function that is called or on the next line in the\n current function).\n\nn(ext)\n\n Continue execution until the next line in the current function is\n reached or it returns. (The difference between ``next`` and\n ``step`` is that ``step`` stops inside a called function, while\n ``next`` executes called functions at (nearly) full speed, only\n stopping at the next line in the current function.)\n\nunt(il) [lineno]\n\n Without argument, continue execution until the line with a number\n greater than the current one is reached.\n\n With a line number, continue execution until a line with a number\n greater or equal to that is reached. In both cases, also stop when\n the current frame returns.\n\n Changed in version 3.2: Allow giving an explicit line number.\n\nr(eturn)\n\n Continue execution until the current function returns.\n\nc(ont(inue))\n\n Continue execution, only stop when a breakpoint is encountered.\n\nj(ump) lineno\n\n Set the next line that will be executed. Only available in the\n bottom-most frame. This lets you jump back and execute code again,\n or jump forward to skip code that you don\'t want to run.\n\n It should be noted that not all jumps are allowed -- for instance\n it is not possible to jump into the middle of a ``for`` loop or out\n of a ``finally`` clause.\n\nl(ist) [first[, last]]\n\n List source code for the current file. Without arguments, list 11\n lines around the current line or continue the previous listing.\n With ``.`` as argument, list 11 lines around the current line.\n With one argument, list 11 lines around at that line. With two\n arguments, list the given range; if the second argument is less\n than the first, it is interpreted as a count.\n\n The current line in the current frame is indicated by ``->``. If\n an exception is being debugged, the line where the exception was\n originally raised or propagated is indicated by ``>>``, if it\n differs from the current line.\n\n New in version 3.2: The ``>>`` marker.\n\nll | longlist\n\n List all source code for the current function or frame.\n Interesting lines are marked as for ``list``.\n\n New in version 3.2.\n\na(rgs)\n\n Print the argument list of the current function.\n\np(rint) expression\n\n Evaluate the *expression* in the current context and print its\n value.\n\npp expression\n\n Like the ``print`` command, except the value of the expression is\n pretty-printed using the ``pprint`` module.\n\nwhatis expression\n\n Print the type of the *expression*.\n\nsource expression\n\n Try to get source code for the given object and display it.\n\n New in version 3.2.\n\ndisplay [expression]\n\n Display the value of the expression if it changed, each time\n execution stops in the current frame.\n\n Without expression, list all display expressions for the current\n frame.\n\n New in version 3.2.\n\nundisplay [expression]\n\n Do not display the expression any more in the current frame.\n Without expression, clear all display expressions for the current\n frame.\n\n New in version 3.2.\n\ninteract\n\n Start an interative interpreter (using the ``code`` module) whose\n global namespace contains all the (global and local) names found in\n the current scope.\n\n New in version 3.2.\n\nalias [name [command]]\n\n Create an alias called *name* that executes *command*. The command\n must *not* be enclosed in quotes. Replaceable parameters can be\n indicated by ``%1``, ``%2``, and so on, while ``%*`` is replaced by\n all the parameters. If no command is given, the current alias for\n *name* is shown. If no arguments are given, all aliases are listed.\n\n Aliases may be nested and can contain anything that can be legally\n typed at the pdb prompt. Note that internal pdb commands *can* be\n overridden by aliases. Such a command is then hidden until the\n alias is removed. Aliasing is recursively applied to the first\n word of the command line; all other words in the line are left\n alone.\n\n As an example, here are two useful aliases (especially when placed\n in the ``.pdbrc`` file):\n\n # Print instance variables (usage "pi classInst")\n alias pi for k in %1.__dict__.keys(): print("%1.",k,"=",%1.__dict__[k])\n # Print instance variables in self\n alias ps pi self\n\nunalias name\n\n Delete the specified alias.\n\n! statement\n\n Execute the (one-line) *statement* in the context of the current\n stack frame. The exclamation point can be omitted unless the first\n word of the statement resembles a debugger command. To set a\n global variable, you can prefix the assignment command with a\n ``global`` statement on the same line, e.g.:\n\n (Pdb) global list_options; list_options = [\'-l\']\n (Pdb)\n\nrun [args ...]\nrestart [args ...]\n\n Restart the debugged Python program. If an argument is supplied,\n it is split with ``shlex`` and the result is used as the new\n ``sys.argv``. History, breakpoints, actions and debugger options\n are preserved. ``restart`` is an alias for ``run``.\n\nq(uit)\n\n Quit from the debugger. The program being executed is aborted.\n\n-[ Footnotes ]-\n\n[1] Whether a frame is considered to originate in a certain module is\n determined by the ``__name__`` in the frame globals.\n', 'del': '\nThe ``del`` statement\n*********************\n\n del_stmt ::= "del" target_list\n\nDeletion is recursively defined very similar to the way assignment is\ndefined. Rather than spelling it out in full details, here are some\nhints.\n\nDeletion of a target list recursively deletes each target, from left\nto right.\n\nDeletion of a name removes the binding of that name from the local or\nglobal namespace, depending on whether the name occurs in a ``global``\nstatement in the same code block. If the name is unbound, a\n``NameError`` exception will be raised.\n\nDeletion of attribute references, subscriptions and slicings is passed\nto the primary object involved; deletion of a slicing is in general\nequivalent to assignment of an empty slice of the right type (but even\nthis is determined by the sliced object).\n\nChanged in version 3.2: Previously it was illegal to delete a name\nfrom the local namespace if it occurs as a free variable in a nested\nblock.\n', 'dict': '\nDictionary displays\n*******************\n\nA dictionary display is a possibly empty series of key/datum pairs\nenclosed in curly braces:\n\n dict_display ::= "{" [key_datum_list | dict_comprehension] "}"\n key_datum_list ::= key_datum ("," key_datum)* [","]\n key_datum ::= expression ":" expression\n dict_comprehension ::= expression ":" expression comp_for\n\nA dictionary display yields a new dictionary object.\n\nIf a comma-separated sequence of key/datum pairs is given, they are\nevaluated from left to right to define the entries of the dictionary:\neach key object is used as a key into the dictionary to store the\ncorresponding datum. This means that you can specify the same key\nmultiple times in the key/datum list, and the final dictionary\'s value\nfor that key will be the last one given.\n\nA dict comprehension, in contrast to list and set comprehensions,\nneeds two expressions separated with a colon followed by the usual\n"for" and "if" clauses. When the comprehension is run, the resulting\nkey and value elements are inserted in the new dictionary in the order\nthey are produced.\n\nRestrictions on the types of the key values are listed earlier in\nsection *The standard type hierarchy*. (To summarize, the key type\nshould be *hashable*, which excludes all mutable objects.) Clashes\nbetween duplicate keys are not detected; the last datum (textually\nrightmost in the display) stored for a given key value prevails.\n', @@ -41,7 +41,7 @@ 'identifiers': '\nIdentifiers and keywords\n************************\n\nIdentifiers (also referred to as *names*) are described by the\nfollowing lexical definitions.\n\nThe syntax of identifiers in Python is based on the Unicode standard\nannex UAX-31, with elaboration and changes as defined below; see also\n**PEP 3131** for further details.\n\nWithin the ASCII range (U+0001..U+007F), the valid characters for\nidentifiers are the same as in Python 2.x: the uppercase and lowercase\nletters ``A`` through ``Z``, the underscore ``_`` and, except for the\nfirst character, the digits ``0`` through ``9``.\n\nPython 3.0 introduces additional characters from outside the ASCII\nrange (see **PEP 3131**). For these characters, the classification\nuses the version of the Unicode Character Database as included in the\n``unicodedata`` module.\n\nIdentifiers are unlimited in length. Case is significant.\n\n identifier ::= xid_start xid_continue*\n id_start ::= \n id_continue ::= \n xid_start ::= \n xid_continue ::= \n\nThe Unicode category codes mentioned above stand for:\n\n* *Lu* - uppercase letters\n\n* *Ll* - lowercase letters\n\n* *Lt* - titlecase letters\n\n* *Lm* - modifier letters\n\n* *Lo* - other letters\n\n* *Nl* - letter numbers\n\n* *Mn* - nonspacing marks\n\n* *Mc* - spacing combining marks\n\n* *Nd* - decimal numbers\n\n* *Pc* - connector punctuations\n\n* *Other_ID_Start* - explicit list of characters in PropList.txt to\n support backwards compatibility\n\n* *Other_ID_Continue* - likewise\n\nAll identifiers are converted into the normal form NFKC while parsing;\ncomparison of identifiers is based on NFKC.\n\nA non-normative HTML file listing all valid identifier characters for\nUnicode 4.1 can be found at http://www.dcl.hpi.uni-\npotsdam.de/home/loewis/table-3131.html.\n\n\nKeywords\n========\n\nThe following identifiers are used as reserved words, or *keywords* of\nthe language, and cannot be used as ordinary identifiers. They must\nbe spelled exactly as written here:\n\n False class finally is return\n None continue for lambda try\n True def from nonlocal while\n and del global not with\n as elif if or yield\n assert else import pass\n break except in raise\n\n\nReserved classes of identifiers\n===============================\n\nCertain classes of identifiers (besides keywords) have special\nmeanings. These classes are identified by the patterns of leading and\ntrailing underscore characters:\n\n``_*``\n Not imported by ``from module import *``. The special identifier\n ``_`` is used in the interactive interpreter to store the result of\n the last evaluation; it is stored in the ``builtins`` module. When\n not in interactive mode, ``_`` has no special meaning and is not\n defined. See section *The import statement*.\n\n Note: The name ``_`` is often used in conjunction with\n internationalization; refer to the documentation for the\n ``gettext`` module for more information on this convention.\n\n``__*__``\n System-defined names. These names are defined by the interpreter\n and its implementation (including the standard library). Current\n system names are discussed in the *Special method names* section\n and elsewhere. More will likely be defined in future versions of\n Python. *Any* use of ``__*__`` names, in any context, that does\n not follow explicitly documented use, is subject to breakage\n without warning.\n\n``__*``\n Class-private names. Names in this category, when used within the\n context of a class definition, are re-written to use a mangled form\n to help avoid name clashes between "private" attributes of base and\n derived classes. See section *Identifiers (Names)*.\n', 'if': '\nThe ``if`` statement\n********************\n\nThe ``if`` statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section *Boolean operations*\nfor the definition of true and false); then that suite is executed\n(and no other part of the ``if`` statement is executed or evaluated).\nIf all expressions are false, the suite of the ``else`` clause, if\npresent, is executed.\n', 'imaginary': '\nImaginary literals\n******************\n\nImaginary literals are described by the following lexical definitions:\n\n imagnumber ::= (floatnumber | intpart) ("j" | "J")\n\nAn imaginary literal yields a complex number with a real part of 0.0.\nComplex numbers are represented as a pair of floating point numbers\nand have the same restrictions on their range. To create a complex\nnumber with a nonzero real part, add a floating point number to it,\ne.g., ``(3+4j)``. Some examples of imaginary literals:\n\n 3.14j 10.j 10j .001j 1e100j 3.14e-10j\n', - 'import': '\nThe ``import`` statement\n************************\n\n import_stmt ::= "import" module ["as" name] ( "," module ["as" name] )*\n | "from" relative_module "import" identifier ["as" name]\n ( "," identifier ["as" name] )*\n | "from" relative_module "import" "(" identifier ["as" name]\n ( "," identifier ["as" name] )* [","] ")"\n | "from" module "import" "*"\n module ::= (identifier ".")* identifier\n relative_module ::= "."* module | "."+\n name ::= identifier\n\nImport statements are executed in two steps: (1) find a module, and\ninitialize it if necessary; (2) define a name or names in the local\nnamespace (of the scope where the ``import`` statement occurs). The\nstatement comes in two forms differing on whether it uses the ``from``\nkeyword. The first form (without ``from``) repeats these steps for\neach identifier in the list. The form with ``from`` performs step (1)\nonce, and then performs step (2) repeatedly. For a reference\nimplementation of step (1), see the ``importlib`` module.\n\nTo understand how step (1) occurs, one must first understand how\nPython handles hierarchical naming of modules. To help organize\nmodules and provide a hierarchy in naming, Python has a concept of\npackages. A package can contain other packages and modules while\nmodules cannot contain other modules or packages. From a file system\nperspective, packages are directories and modules are files. The\noriginal specification for packages is still available to read,\nalthough minor details have changed since the writing of that\ndocument.\n\nOnce the name of the module is known (unless otherwise specified, the\nterm "module" will refer to both packages and modules), searching for\nthe module or package can begin. The first place checked is\n``sys.modules``, the cache of all modules that have been imported\npreviously. If the module is found there then it is used in step (2)\nof import unless ``None`` is found in ``sys.modules``, in which case\n``ImportError`` is raised.\n\nIf the module is not found in the cache, then ``sys.meta_path`` is\nsearched (the specification for ``sys.meta_path`` can be found in\n**PEP 302**). The object is a list of *finder* objects which are\nqueried in order as to whether they know how to load the module by\ncalling their ``find_module()`` method with the name of the module. If\nthe module happens to be contained within a package (as denoted by the\nexistence of a dot in the name), then a second argument to\n``find_module()`` is given as the value of the ``__path__`` attribute\nfrom the parent package (everything up to the last dot in the name of\nthe module being imported). If a finder can find the module it returns\na *loader* (discussed later) or returns ``None``.\n\nIf none of the finders on ``sys.meta_path`` are able to find the\nmodule then some implicitly defined finders are queried.\nImplementations of Python vary in what implicit meta path finders are\ndefined. The one they all do define, though, is one that handles\n``sys.path_hooks``, ``sys.path_importer_cache``, and ``sys.path``.\n\nThe implicit finder searches for the requested module in the "paths"\nspecified in one of two places ("paths" do not have to be file system\npaths). If the module being imported is supposed to be contained\nwithin a package then the second argument passed to ``find_module()``,\n``__path__`` on the parent package, is used as the source of paths. If\nthe module is not contained in a package then ``sys.path`` is used as\nthe source of paths.\n\nOnce the source of paths is chosen it is iterated over to find a\nfinder that can handle that path. The dict at\n``sys.path_importer_cache`` caches finders for paths and is checked\nfor a finder. If the path does not have a finder cached then\n``sys.path_hooks`` is searched by calling each object in the list with\na single argument of the path, returning a finder or raises\n``ImportError``. If a finder is returned then it is cached in\n``sys.path_importer_cache`` and then used for that path entry. If no\nfinder can be found but the path exists then a value of ``None`` is\nstored in ``sys.path_importer_cache`` to signify that an implicit,\nfile-based finder that handles modules stored as individual files\nshould be used for that path. If the path does not exist then a finder\nwhich always returns ``None`` is placed in the cache for the path.\n\nIf no finder can find the module then ``ImportError`` is raised.\nOtherwise some finder returned a loader whose ``load_module()`` method\nis called with the name of the module to load (see **PEP 302** for the\noriginal definition of loaders). A loader has several responsibilities\nto perform on a module it loads. First, if the module already exists\nin ``sys.modules`` (a possibility if the loader is called outside of\nthe import machinery) then it is to use that module for initialization\nand not a new module. But if the module does not exist in\n``sys.modules`` then it is to be added to that dict before\ninitialization begins. If an error occurs during loading of the module\nand it was added to ``sys.modules`` it is to be removed from the dict.\nIf an error occurs but the module was already in ``sys.modules`` it is\nleft in the dict.\n\nThe loader must set several attributes on the module. ``__name__`` is\nto be set to the name of the module. ``__file__`` is to be the "path"\nto the file unless the module is built-in (and thus listed in\n``sys.builtin_module_names``) in which case the attribute is not set.\nIf what is being imported is a package then ``__path__`` is to be set\nto a list of paths to be searched when looking for modules and\npackages contained within the package being imported. ``__package__``\nis optional but should be set to the name of package that contains the\nmodule or package (the empty string is used for module not contained\nin a package). ``__loader__`` is also optional but should be set to\nthe loader object that is loading the module. While loaders are\nrequired to return the module they loaded, import itself always\nretrieves any modules it returns from ``sys.modules``.\n\nIf an error occurs during loading then the loader raises\n``ImportError`` if some other exception is not already being\npropagated. Otherwise the loader returns the module that was loaded\nand initialized.\n\nWhen step (1) finishes without raising an exception, step (2) can\nbegin.\n\nThe first form of ``import`` statement binds the module name in the\nlocal namespace to the module object, and then goes on to import the\nnext identifier, if any. If the module name is followed by ``as``,\nthe name following ``as`` is used as the local name for the module.\n\nThe ``from`` form does not bind the module name: it goes through the\nlist of identifiers, looks each one of them up in the module found in\nstep (1), and binds the name in the local namespace to the object thus\nfound. As with the first form of ``import``, an alternate local name\ncan be supplied by specifying "``as`` localname". If a name is not\nfound, ``ImportError`` is raised. If the list of identifiers is\nreplaced by a star (``\'*\'``), all public names defined in the module\nare bound in the local namespace of the ``import`` statement.\n\nThe *public names* defined by a module are determined by checking the\nmodule\'s namespace for a variable named ``__all__``; if defined, it\nmust be a sequence of strings which are names defined or imported by\nthat module. The names given in ``__all__`` are all considered public\nand are required to exist. If ``__all__`` is not defined, the set of\npublic names includes all names found in the module\'s namespace which\ndo not begin with an underscore character (``\'_\'``). ``__all__``\nshould contain the entire public API. It is intended to avoid\naccidentally exporting items that are not part of the API (such as\nlibrary modules which were imported and used within the module).\n\nThe ``from`` form with ``*`` may only occur in a module scope. The\nwild card form of import --- ``import *`` --- is only allowed at the\nmodule level. Attempting to use it in class or function definitions\nwill raise a ``SyntaxError``.\n\nWhen specifying what module to import you do not have to specify the\nabsolute name of the module. When a module or package is contained\nwithin another package it is possible to make a relative import within\nthe same top package without having to mention the package name. By\nusing leading dots in the specified module or package after ``from``\nyou can specify how high to traverse up the current package hierarchy\nwithout specifying exact names. One leading dot means the current\npackage where the module making the import exists. Two dots means up\none package level. Three dots is up two levels, etc. So if you execute\n``from . import mod`` from a module in the ``pkg`` package then you\nwill end up importing ``pkg.mod``. If you execute ``from ..subpkg2\nimport mod`` from within ``pkg.subpkg1`` you will import\n``pkg.subpkg2.mod``. The specification for relative imports is\ncontained within **PEP 328**.\n\n``importlib.import_module()`` is provided to support applications that\ndetermine which modules need to be loaded dynamically.\n\n\nFuture statements\n=================\n\nA *future statement* is a directive to the compiler that a particular\nmodule should be compiled using syntax or semantics that will be\navailable in a specified future release of Python. The future\nstatement is intended to ease migration to future versions of Python\nthat introduce incompatible changes to the language. It allows use of\nthe new features on a per-module basis before the release in which the\nfeature becomes standard.\n\n future_statement ::= "from" "__future__" "import" feature ["as" name]\n ("," feature ["as" name])*\n | "from" "__future__" "import" "(" feature ["as" name]\n ("," feature ["as" name])* [","] ")"\n feature ::= identifier\n name ::= identifier\n\nA future statement must appear near the top of the module. The only\nlines that can appear before a future statement are:\n\n* the module docstring (if any),\n\n* comments,\n\n* blank lines, and\n\n* other future statements.\n\nThe features recognized by Python 3.0 are ``absolute_import``,\n``division``, ``generators``, ``unicode_literals``,\n``print_function``, ``nested_scopes`` and ``with_statement``. They\nare all redundant because they are always enabled, and only kept for\nbackwards compatibility.\n\nA future statement is recognized and treated specially at compile\ntime: Changes to the semantics of core constructs are often\nimplemented by generating different code. It may even be the case\nthat a new feature introduces new incompatible syntax (such as a new\nreserved word), in which case the compiler may need to parse the\nmodule differently. Such decisions cannot be pushed off until\nruntime.\n\nFor any given release, the compiler knows which feature names have\nbeen defined, and raises a compile-time error if a future statement\ncontains a feature not known to it.\n\nThe direct runtime semantics are the same as for any import statement:\nthere is a standard module ``__future__``, described later, and it\nwill be imported in the usual way at the time the future statement is\nexecuted.\n\nThe interesting runtime semantics depend on the specific feature\nenabled by the future statement.\n\nNote that there is nothing special about the statement:\n\n import __future__ [as name]\n\nThat is not a future statement; it\'s an ordinary import statement with\nno special semantics or syntax restrictions.\n\nCode compiled by calls to the built-in functions ``exec()`` and\n``compile()`` that occur in a module ``M`` containing a future\nstatement will, by default, use the new syntax or semantics associated\nwith the future statement. This can be controlled by optional\narguments to ``compile()`` --- see the documentation of that function\nfor details.\n\nA future statement typed at an interactive interpreter prompt will\ntake effect for the rest of the interpreter session. If an\ninterpreter is started with the *-i* option, is passed a script name\nto execute, and the script includes a future statement, it will be in\neffect in the interactive session started after the script is\nexecuted.\n\nSee also:\n\n **PEP 236** - Back to the __future__\n The original proposal for the __future__ mechanism.\n', + 'import': '\nThe ``import`` statement\n************************\n\n import_stmt ::= "import" module ["as" name] ( "," module ["as" name] )*\n | "from" relative_module "import" identifier ["as" name]\n ( "," identifier ["as" name] )*\n | "from" relative_module "import" "(" identifier ["as" name]\n ( "," identifier ["as" name] )* [","] ")"\n | "from" module "import" "*"\n module ::= (identifier ".")* identifier\n relative_module ::= "."* module | "."+\n name ::= identifier\n\nThe basic import statement (no ``from`` clause) is executed in two\nsteps:\n\n1. find a module, loading and initializing it if necessary\n\n2. define a name or names in the local namespace for the scope where\n the ``import`` statement occurs.\n\nWhen the statement contains multiple clauses (separated by commas) the\ntwo steps are carried out separately for each clause, just as though\nthe clauses had been separated out into individiual import statements.\n\nThe details of the first step, finding and loading modules is\ndescribed in greater detail in the section on the *import system*,\nwhich also describes the various types of packages and modules that\ncan be imported, as well as all the hooks that can be used to\ncustomize the import system. Note that failures in this step may\nindicate either that the module could not be located, *or* that an\nerror occurred while initializing the module, which includes execution\nof the module\'s code.\n\nIf the requested module is retrieved successfully, it will be made\navailable in the local namespace in one of three ways:\n\n* If the module name is followed by ``as``, then the name following\n ``as`` is bound directly to the imported module.\n\n* If no other name is specified, and the module being imported is a\n top level module, the module\'s name is bound in the local namespace\n as a reference to the imported module\n\n* If the module being imported is *not* a top level module, then the\n name of the top level package that contains the module is bound in\n the local namespace as a reference to the top level package. The\n imported module must be accessed using its full qualified name\n rather than directly\n\nThe ``from`` form uses a slightly more complex process:\n\n1. find the module specified in the ``from`` clause loading and\n initializing it if necessary;\n\n2. for each of the identifiers specified in the ``import`` clauses:\n\n 1. check if the imported module has an attribute by that name\n\n 2. if not, attempt to import a submodule with that name and then\n check the imported module again for that attribute\n\n 3. if the attribute is not found, ``ImportError`` is raised.\n\n 4. otherwise, a reference to that value is bound in the local\n namespace, using the name in the ``as`` clause if it is present,\n otherwise using the attribute name\n\nExamples:\n\n import foo # foo imported and bound locally\n import foo.bar.baz # foo.bar.baz imported, foo bound locally\n import foo.bar.baz as fbb # foo.bar.baz imported and bound as fbb\n from foo.bar import baz # foo.bar.baz imported and bound as baz\n from foo import attr # foo imported and foo.attr bound as attr\n\nIf the list of identifiers is replaced by a star (``\'*\'``), all public\nnames defined in the module are bound in the local namespace for the\nscope where the ``import`` statement occurs.\n\nThe *public names* defined by a module are determined by checking the\nmodule\'s namespace for a variable named ``__all__``; if defined, it\nmust be a sequence of strings which are names defined or imported by\nthat module. The names given in ``__all__`` are all considered public\nand are required to exist. If ``__all__`` is not defined, the set of\npublic names includes all names found in the module\'s namespace which\ndo not begin with an underscore character (``\'_\'``). ``__all__``\nshould contain the entire public API. It is intended to avoid\naccidentally exporting items that are not part of the API (such as\nlibrary modules which were imported and used within the module).\n\nThe ``from`` form with ``*`` may only occur in a module scope.\nAttempting to use it in class or function definitions will raise a\n``SyntaxError``.\n\nThe *public names* defined by a module are determined by checking the\nmodule\'s namespace for a variable named ``__all__``; if defined, it\nmust be a sequence of strings which are names defined or imported by\nthat module. The names given in ``__all__`` are all considered public\nand are required to exist. If ``__all__`` is not defined, the set of\npublic names includes all names found in the module\'s namespace which\ndo not begin with an underscore character (``\'_\'``). ``__all__``\nshould contain the entire public API. It is intended to avoid\naccidentally exporting items that are not part of the API (such as\nlibrary modules which were imported and used within the module).\n\nThe ``from`` form with ``*`` may only occur in a module scope. The\nwild card form of import --- ``import *`` --- is only allowed at the\nmodule level. Attempting to use it in class or function definitions\nwill raise a ``SyntaxError``.\n\nWhen specifying what module to import you do not have to specify the\nabsolute name of the module. When a module or package is contained\nwithin another package it is possible to make a relative import within\nthe same top package without having to mention the package name. By\nusing leading dots in the specified module or package after ``from``\nyou can specify how high to traverse up the current package hierarchy\nwithout specifying exact names. One leading dot means the current\npackage where the module making the import exists. Two dots means up\none package level. Three dots is up two levels, etc. So if you execute\n``from . import mod`` from a module in the ``pkg`` package then you\nwill end up importing ``pkg.mod``. If you execute ``from ..subpkg2\nimport mod`` from within ``pkg.subpkg1`` you will import\n``pkg.subpkg2.mod``. The specification for relative imports is\ncontained within **PEP 328**.\n\n``importlib.import_module()`` is provided to support applications that\ndetermine which modules need to be loaded dynamically.\n\n\nFuture statements\n=================\n\nA *future statement* is a directive to the compiler that a particular\nmodule should be compiled using syntax or semantics that will be\navailable in a specified future release of Python. The future\nstatement is intended to ease migration to future versions of Python\nthat introduce incompatible changes to the language. It allows use of\nthe new features on a per-module basis before the release in which the\nfeature becomes standard.\n\n future_statement ::= "from" "__future__" "import" feature ["as" name]\n ("," feature ["as" name])*\n | "from" "__future__" "import" "(" feature ["as" name]\n ("," feature ["as" name])* [","] ")"\n feature ::= identifier\n name ::= identifier\n\nA future statement must appear near the top of the module. The only\nlines that can appear before a future statement are:\n\n* the module docstring (if any),\n\n* comments,\n\n* blank lines, and\n\n* other future statements.\n\nThe features recognized by Python 3.0 are ``absolute_import``,\n``division``, ``generators``, ``unicode_literals``,\n``print_function``, ``nested_scopes`` and ``with_statement``. They\nare all redundant because they are always enabled, and only kept for\nbackwards compatibility.\n\nA future statement is recognized and treated specially at compile\ntime: Changes to the semantics of core constructs are often\nimplemented by generating different code. It may even be the case\nthat a new feature introduces new incompatible syntax (such as a new\nreserved word), in which case the compiler may need to parse the\nmodule differently. Such decisions cannot be pushed off until\nruntime.\n\nFor any given release, the compiler knows which feature names have\nbeen defined, and raises a compile-time error if a future statement\ncontains a feature not known to it.\n\nThe direct runtime semantics are the same as for any import statement:\nthere is a standard module ``__future__``, described later, and it\nwill be imported in the usual way at the time the future statement is\nexecuted.\n\nThe interesting runtime semantics depend on the specific feature\nenabled by the future statement.\n\nNote that there is nothing special about the statement:\n\n import __future__ [as name]\n\nThat is not a future statement; it\'s an ordinary import statement with\nno special semantics or syntax restrictions.\n\nCode compiled by calls to the built-in functions ``exec()`` and\n``compile()`` that occur in a module ``M`` containing a future\nstatement will, by default, use the new syntax or semantics associated\nwith the future statement. This can be controlled by optional\narguments to ``compile()`` --- see the documentation of that function\nfor details.\n\nA future statement typed at an interactive interpreter prompt will\ntake effect for the rest of the interpreter session. If an\ninterpreter is started with the *-i* option, is passed a script name\nto execute, and the script includes a future statement, it will be in\neffect in the interactive session started after the script is\nexecuted.\n\nSee also:\n\n **PEP 236** - Back to the __future__\n The original proposal for the __future__ mechanism.\n', 'in': '\nComparisons\n***********\n\nUnlike C, all comparison operations in Python have the same priority,\nwhich is lower than that of any arithmetic, shifting or bitwise\noperation. Also unlike C, expressions like ``a < b < c`` have the\ninterpretation that is conventional in mathematics:\n\n comparison ::= or_expr ( comp_operator or_expr )*\n comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!="\n | "is" ["not"] | ["not"] "in"\n\nComparisons yield boolean values: ``True`` or ``False``.\n\nComparisons can be chained arbitrarily, e.g., ``x < y <= z`` is\nequivalent to ``x < y and y <= z``, except that ``y`` is evaluated\nonly once (but in both cases ``z`` is not evaluated at all when ``x <\ny`` is found to be false).\n\nFormally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*,\n*op2*, ..., *opN* are comparison operators, then ``a op1 b op2 c ... y\nopN z`` is equivalent to ``a op1 b and b op2 c and ... y opN z``,\nexcept that each expression is evaluated at most once.\n\nNote that ``a op1 b op2 c`` doesn\'t imply any kind of comparison\nbetween *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal\n(though perhaps not pretty).\n\nThe operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare\nthe values of two objects. The objects need not have the same type.\nIf both are numbers, they are converted to a common type. Otherwise,\nthe ``==`` and ``!=`` operators *always* consider objects of different\ntypes to be unequal, while the ``<``, ``>``, ``>=`` and ``<=``\noperators raise a ``TypeError`` when comparing objects of different\ntypes that do not implement these operators for the given pair of\ntypes. You can control comparison behavior of objects of non-built-in\ntypes by defining rich comparison methods like ``__gt__()``, described\nin section *Basic customization*.\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* The values ``float(\'NaN\')`` and ``Decimal(\'NaN\')`` are special. The\n are identical to themselves, ``x is x`` but are not equal to\n themselves, ``x != x``. Additionally, comparing any value to a\n not-a-number value will return ``False``. For example, both ``3 <\n float(\'NaN\')`` and ``float(\'NaN\') < 3`` will return ``False``.\n\n* Bytes objects are compared lexicographically using the numeric\n values of their elements.\n\n* Strings are compared lexicographically using the numeric equivalents\n (the result of the built-in function ``ord()``) of their characters.\n [3] String and bytes object can\'t be compared!\n\n* Tuples and lists are compared lexicographically using comparison of\n corresponding elements. This means that to compare equal, each\n element must compare equal and the two sequences must be of the same\n type and have the same length.\n\n If not equal, the sequences are ordered the same as their first\n differing elements. For example, ``[1,2,x] <= [1,2,y]`` has the\n same value as ``x <= y``. If the corresponding element does not\n exist, the shorter sequence is ordered first (for example, ``[1,2] <\n [1,2,3]``).\n\n* Mappings (dictionaries) compare equal if and only if they have the\n same ``(key, value)`` pairs. Order comparisons ``(\'<\', \'<=\', \'>=\',\n \'>\')`` raise ``TypeError``.\n\n* Sets and frozensets define comparison operators to mean subset and\n superset tests. Those relations do not define total orderings (the\n two sets ``{1,2}`` and {2,3} are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering.\n For example, ``min()``, ``max()``, and ``sorted()`` produce\n undefined results given a list of sets as inputs.\n\n* Most other objects of built-in types compare unequal unless they are\n the same object; the choice whether one object is considered smaller\n or larger than another one is made arbitrarily but consistently\n within one execution of a program.\n\nComparison of objects of the differing types depends on whether either\nof the types provide explicit support for the comparison. Most\nnumeric types can be compared with one another, but comparisons of\n``float`` and ``Decimal`` are not supported to avoid the inevitable\nconfusion arising from representation issues such as ``float(\'1.1\')``\nbeing inexactly represented and therefore not exactly equal to\n``Decimal(\'1.1\')`` which is. When cross-type comparison is not\nsupported, the comparison method returns ``NotImplemented``. This can\ncreate the illusion of non-transitivity between supported cross-type\ncomparisons and unsupported comparisons. For example, ``Decimal(2) ==\n2`` and ``2 == float(2)`` but ``Decimal(2) != float(2)``.\n\nThe operators ``in`` and ``not in`` test for membership. ``x in s``\nevaluates to true if *x* is a member of *s*, and false otherwise. ``x\nnot in s`` returns the negation of ``x in s``. All built-in sequences\nand set types support this as well as dictionary, for which ``in``\ntests whether a the dictionary has a given key. For container types\nsuch as list, tuple, set, frozenset, dict, or collections.deque, the\nexpression ``x in y`` is equivalent to ``any(x is e or x == e for e in\ny)``.\n\nFor the string and bytes types, ``x in y`` is true if and only if *x*\nis a substring of *y*. An equivalent test is ``y.find(x) != -1``.\nEmpty strings are always considered to be a substring of any other\nstring, so ``"" in "abc"`` will return ``True``.\n\nFor user-defined classes which define the ``__contains__()`` method,\n``x in y`` is true if and only if ``y.__contains__(x)`` is true.\n\nFor user-defined classes which do not define ``__contains__()`` but do\ndefine ``__iter__()``, ``x in y`` is true if some value ``z`` with ``x\n== z`` is produced while iterating over ``y``. If an exception is\nraised during the iteration, it is as if ``in`` raised that exception.\n\nLastly, the old-style iteration protocol is tried: if a class defines\n``__getitem__()``, ``x in y`` is true if and only if there is a non-\nnegative integer index *i* such that ``x == y[i]``, and all lower\ninteger indices do not raise ``IndexError`` exception. (If any other\nexception is raised, it is as if ``in`` raised that exception).\n\nThe operator ``not in`` is defined to have the inverse true value of\n``in``.\n\nThe operators ``is`` and ``is not`` test for object identity: ``x is\ny`` is true if and only if *x* and *y* are the same object. ``x is\nnot y`` yields the inverse truth value. [4]\n', 'integers': '\nInteger literals\n****************\n\nInteger literals are described by the following lexical definitions:\n\n integer ::= decimalinteger | octinteger | hexinteger | bininteger\n decimalinteger ::= nonzerodigit digit* | "0"+\n nonzerodigit ::= "1"..."9"\n digit ::= "0"..."9"\n octinteger ::= "0" ("o" | "O") octdigit+\n hexinteger ::= "0" ("x" | "X") hexdigit+\n bininteger ::= "0" ("b" | "B") bindigit+\n octdigit ::= "0"..."7"\n hexdigit ::= digit | "a"..."f" | "A"..."F"\n bindigit ::= "0" | "1"\n\nThere is no limit for the length of integer literals apart from what\ncan be stored in available memory.\n\nNote that leading zeros in a non-zero decimal number are not allowed.\nThis is for disambiguation with C-style octal literals, which Python\nused before version 3.0.\n\nSome examples of integer literals:\n\n 7 2147483647 0o177 0b100110111\n 3 79228162514264337593543950336 0o377 0x100000000\n 79228162514264337593543950336 0xdeadbeef\n', 'lambda': '\nLambdas\n*******\n\n lambda_form ::= "lambda" [parameter_list]: expression\n lambda_form_nocond ::= "lambda" [parameter_list]: expression_nocond\n\nLambda forms (lambda expressions) have the same syntactic position as\nexpressions. They are a shorthand to create anonymous functions; the\nexpression ``lambda arguments: expression`` yields a function object.\nThe unnamed object behaves like a function object defined with\n\n def (arguments):\n return expression\n\nSee section *Function definitions* for the syntax of parameter lists.\nNote that functions created with lambda forms cannot contain\nstatements or annotations.\n', @@ -60,18 +60,18 @@ 'shifting': '\nShifting operations\n*******************\n\nThe shifting operations have lower priority than the arithmetic\noperations:\n\n shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr\n\nThese operators accept integers as arguments. They shift the first\nargument to the left or right by the number of bits given by the\nsecond argument.\n\nA right shift by *n* bits is defined as division by ``pow(2,n)``. A\nleft shift by *n* bits is defined as multiplication with ``pow(2,n)``.\n\nNote: In the current implementation, the right-hand operand is required to\n be at most ``sys.maxsize``. If the right-hand operand is larger\n than ``sys.maxsize`` an ``OverflowError`` exception is raised.\n', 'slicings': '\nSlicings\n********\n\nA slicing selects a range of items in a sequence object (e.g., a\nstring, tuple or list). Slicings may be used as expressions or as\ntargets in assignment or ``del`` statements. The syntax for a\nslicing:\n\n slicing ::= primary "[" slice_list "]"\n slice_list ::= slice_item ("," slice_item)* [","]\n slice_item ::= expression | proper_slice\n proper_slice ::= [lower_bound] ":" [upper_bound] [ ":" [stride] ]\n lower_bound ::= expression\n upper_bound ::= expression\n stride ::= expression\n\nThere is ambiguity in the formal syntax here: anything that looks like\nan expression list also looks like a slice list, so any subscription\ncan be interpreted as a slicing. Rather than further complicating the\nsyntax, this is disambiguated by defining that in this case the\ninterpretation as a subscription takes priority over the\ninterpretation as a slicing (this is the case if the slice list\ncontains no proper slice).\n\nThe semantics for a slicing are as follows. The primary must evaluate\nto a mapping object, and it is indexed (using the same\n``__getitem__()`` method as normal subscription) with a key that is\nconstructed from the slice list, as follows. If the slice list\ncontains at least one comma, the key is a tuple containing the\nconversion of the slice items; otherwise, the conversion of the lone\nslice item is the key. The conversion of a slice item that is an\nexpression is that expression. The conversion of a proper slice is a\nslice object (see section *The standard type hierarchy*) whose\n``start``, ``stop`` and ``step`` attributes are the values of the\nexpressions given as lower bound, upper bound and stride,\nrespectively, substituting ``None`` for missing expressions.\n', 'specialattrs': '\nSpecial Attributes\n******************\n\nThe implementation adds a few special read-only attributes to several\nobject types, where they are relevant. Some of these are not reported\nby the ``dir()`` built-in function.\n\nobject.__dict__\n\n A dictionary or other mapping object used to store an object\'s\n (writable) attributes.\n\ninstance.__class__\n\n The class to which a class instance belongs.\n\nclass.__bases__\n\n The tuple of base classes of a class object.\n\nclass.__name__\n\n The name of the class or type.\n\nclass.__qualname__\n\n The *qualified name* of the class or type.\n\n New in version 3.3.\n\nclass.__mro__\n\n This attribute is a tuple of classes that are considered when\n looking for base classes during method resolution.\n\nclass.mro()\n\n This method can be overridden by a metaclass to customize the\n method resolution order for its instances. It is called at class\n instantiation, and its result is stored in ``__mro__``.\n\nclass.__subclasses__()\n\n Each class keeps a list of weak references to its immediate\n subclasses. This method returns a list of all those references\n still alive. Example:\n\n >>> int.__subclasses__()\n []\n\n-[ Footnotes ]-\n\n[1] Additional information on these special methods may be found in\n the Python Reference Manual (*Basic customization*).\n\n[2] As a consequence, the list ``[1, 2]`` is considered equal to\n ``[1.0, 2.0]``, and similarly for tuples.\n\n[3] They must have since the parser can\'t tell the type of the\n operands.\n\n[4] Cased characters are those with general category property being\n one of "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt"\n (Letter, titlecase).\n\n[5] To format only a tuple you should therefore provide a singleton\n tuple whose only element is the tuple to be formatted.\n', - 'specialnames': '\nSpecial method names\n********************\n\nA class can implement certain operations that are invoked by special\nsyntax (such as arithmetic operations or subscripting and slicing) by\ndefining methods with special names. This is Python\'s approach to\n*operator overloading*, allowing classes to define their own behavior\nwith respect to language operators. For instance, if a class defines\na method named ``__getitem__()``, and ``x`` is an instance of this\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``TypeError``).\n\nWhen implementing a class that emulates any built-in type, it is\nimportant that the emulation only be implemented to the degree that it\nmakes sense for the object being modelled. For example, some\nsequences may work well with retrieval of individual elements, but\nextracting a slice may not make sense. (One example of this is the\n``NodeList`` interface in the W3C\'s Document Object Model.)\n\n\nBasic customization\n===================\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n for the ``gc`` module for more information about how\n ``__del__()`` methods are handled by the cycle detector,\n particularly the description of the ``garbage`` value.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the ``str()`` built-in function and by the ``print()``\n function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: Note by default the ``__hash__()`` values of str, bytes and\n datetime objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the order in which keys are\n retrieved from a dict. Note Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n\n\nCustomizing attribute access\n============================\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n--------------------\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n---------\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\n\nThe following methods are used to override the default behavior of the\n``isinstance()`` and ``issubclass()`` built-in functions.\n\nIn particular, the metaclass ``abc.ABCMeta`` implements these methods\nin order to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n ``isinstance(instance, class)``.\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n ``issubclass(subclass, class)``.\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also:\n\n **PEP 3119** - Introducing Abstract Base Classes\n Includes the specification for customizing ``isinstance()`` and\n ``issubclass()`` behavior through ``__instancecheck__()`` and\n ``__subclasscheck__()``, with motivation for this functionality\n in the context of adding Abstract Base Classes (see the ``abc``\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, ``x(arg1, arg2, ...)`` is a shorthand for\n ``x.__call__(arg1, arg2, ...)``.\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which ``0 <= k < N``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function ``len()``. Should return\n the length of the object, an integer ``>=`` 0. Also, an object\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\nNote: Slicing is done exclusively with the following three methods. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n should be raised.\n\n Note: ``for`` loops expect that an ``IndexError`` will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the ``__getitem__()`` method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the ``__getitem__()``\n method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method ``keys()``.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the ``reversed()`` built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the ``__reversed__()`` method is not provided, the\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\n\nThe membership test operators (``in`` and ``not in``) are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define ``__contains__()``, the membership\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__truediv__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return ``NotImplemented``.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\n ``**=``, ``<<=``, ``>>=``, ``&=``, ``^=``, ``|=``). These methods\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n considered, as with the evaluation of ``x + y``.\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations (``-``, ``+``,\n ``abs()`` and ``~``).\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: object of type \'C\' has no len()\n\nThe rationale behind this behaviour lies with a number of special\nmethods such as ``__hash__()`` and ``__repr__()`` that are implemented\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen invoked on the type object itself:\n\n >>> 1 .__hash__() == hash(1)\n True\n >>> int.__hash__() == hash(int)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe ``__getattribute__()`` method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print("Metaclass getattribute invoked")\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object, metaclass=Meta):\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print("Class getattribute invoked")\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the ``__getattribute__()`` machinery in this fashion\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n handled incorrectly.\n\n[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', - 'string-methods': '\nString Methods\n**************\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. Line breaks are not included in the resulting list\n unless *keepends* is given and true. This method uses the universal\n newlines approach to splitting lines. Unlike ``split()``, if the\n string ends with line boundary characters the returned list does\n ``not`` have an empty last element.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', + 'specialnames': '\nSpecial method names\n********************\n\nA class can implement certain operations that are invoked by special\nsyntax (such as arithmetic operations or subscripting and slicing) by\ndefining methods with special names. This is Python\'s approach to\n*operator overloading*, allowing classes to define their own behavior\nwith respect to language operators. For instance, if a class defines\na method named ``__getitem__()``, and ``x`` is an instance of this\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``TypeError``).\n\nWhen implementing a class that emulates any built-in type, it is\nimportant that the emulation only be implemented to the degree that it\nmakes sense for the object being modelled. For example, some\nsequences may work well with retrieval of individual elements, but\nextracting a slice may not make sense. (One example of this is the\n``NodeList`` interface in the W3C\'s Document Object Model.)\n\n\nBasic customization\n===================\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n for the ``gc`` module for more information about how\n ``__del__()`` methods are handled by the cycle detector,\n particularly the description of the ``garbage`` value.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the ``str()`` built-in function and by the ``print()``\n function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n\n\nCustomizing attribute access\n============================\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n--------------------\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n---------\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\n\nThe following methods are used to override the default behavior of the\n``isinstance()`` and ``issubclass()`` built-in functions.\n\nIn particular, the metaclass ``abc.ABCMeta`` implements these methods\nin order to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n ``isinstance(instance, class)``.\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n ``issubclass(subclass, class)``.\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also:\n\n **PEP 3119** - Introducing Abstract Base Classes\n Includes the specification for customizing ``isinstance()`` and\n ``issubclass()`` behavior through ``__instancecheck__()`` and\n ``__subclasscheck__()``, with motivation for this functionality\n in the context of adding Abstract Base Classes (see the ``abc``\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, ``x(arg1, arg2, ...)`` is a shorthand for\n ``x.__call__(arg1, arg2, ...)``.\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which ``0 <= k < N``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function ``len()``. Should return\n the length of the object, an integer ``>=`` 0. Also, an object\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\nNote: Slicing is done exclusively with the following three methods. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n should be raised.\n\n Note: ``for`` loops expect that an ``IndexError`` will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the ``__getitem__()`` method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the ``__getitem__()``\n method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method ``keys()``.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the ``reversed()`` built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the ``__reversed__()`` method is not provided, the\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\n\nThe membership test operators (``in`` and ``not in``) are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define ``__contains__()``, the membership\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__truediv__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return ``NotImplemented``.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\n ``**=``, ``<<=``, ``>>=``, ``&=``, ``^=``, ``|=``). These methods\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n considered, as with the evaluation of ``x + y``.\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations (``-``, ``+``,\n ``abs()`` and ``~``).\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: object of type \'C\' has no len()\n\nThe rationale behind this behaviour lies with a number of special\nmethods such as ``__hash__()`` and ``__repr__()`` that are implemented\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen invoked on the type object itself:\n\n >>> 1 .__hash__() == hash(1)\n True\n >>> int.__hash__() == hash(int)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe ``__getattribute__()`` method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print("Metaclass getattribute invoked")\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object, metaclass=Meta):\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print("Class getattribute invoked")\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the ``__getattribute__()`` machinery in this fashion\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n handled incorrectly.\n\n[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', + 'string-methods': '\nString Methods\n**************\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the universal newlines approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', 'strings': '\nString and Bytes literals\n*************************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "R" | "U"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'" | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | stringescapeseq\n longstringitem ::= longstringchar | stringescapeseq\n shortstringchar ::= \n longstringchar ::= \n stringescapeseq ::= "\\" \n\n bytesliteral ::= bytesprefix(shortbytes | longbytes)\n bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"\n shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' shortbytesitem* \'"\'\n longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' longbytesitem* \'"""\'\n shortbytesitem ::= shortbyteschar | bytesescapeseq\n longbytesitem ::= longbyteschar | bytesescapeseq\n shortbyteschar ::= \n longbyteschar ::= \n bytesescapeseq ::= "\\" \n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the ``stringprefix`` or\n``bytesprefix`` and the rest of the literal. The source character set\nis defined by the encoding declaration; it is UTF-8 if no encoding\ndeclaration is given in the source file; see section *Encoding\ndeclarations*.\n\nIn plain English: Both types of literals can be enclosed in matching\nsingle quotes (``\'``) or double quotes (``"``). They can also be\nenclosed in matching groups of three single or double quotes (these\nare generally referred to as *triple-quoted strings*). The backslash\n(``\\``) character is used to escape characters that otherwise have a\nspecial meaning, such as newline, backslash itself, or the quote\ncharacter.\n\nBytes literals are always prefixed with ``\'b\'`` or ``\'B\'``; they\nproduce an instance of the ``bytes`` type instead of the ``str`` type.\nThey may only contain ASCII characters; bytes with a numeric value of\n128 or greater must be expressed with escapes.\n\nAs of Python 3.3 it is possible again to prefix unicode strings with a\n``u`` prefix to simplify maintenance of dual 2.x and 3.x codebases.\n\nBoth string and bytes literals may optionally be prefixed with a\nletter ``\'r\'`` or ``\'R\'``; such strings are called *raw strings* and\ntreat backslashes as literal characters. As a result, in string\nliterals, ``\'\\U\'`` and ``\'\\u\'`` escapes in raw strings are not treated\nspecially. Given that Python 2.x\'s raw unicode literals behave\ndifferently than Python 3.x\'s the ``\'ur\'`` syntax is not supported.\n\n New in version 3.3: The ``\'rb\'`` prefix of raw bytes literals has\n been added as a synonym of ``\'br\'``.\n\n New in version 3.3: Support for the unicode legacy literal\n (``u\'value\'``) was reintroduced to simplify the maintenance of dual\n Python 2.x and 3.x codebases. See **PEP 414** for more information.\n\nIn triple-quoted strings, unescaped newlines and quotes are allowed\n(and are retained), except that three unescaped quotes in a row\nterminate the string. (A "quote" is the character used to open the\nstring, i.e. either ``\'`` or ``"``.)\n\nUnless an ``\'r\'`` or ``\'R\'`` prefix is present, escape sequences in\nstrings are interpreted according to rules similar to those used by\nStandard C. The recognized escape sequences are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\newline`` | Backslash and newline ignored | |\n+-------------------+-----------------------------------+---------+\n| ``\\\\`` | Backslash (``\\``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\\'`` | Single quote (``\'``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\"`` | Double quote (``"``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\a`` | ASCII Bell (BEL) | |\n+-------------------+-----------------------------------+---------+\n| ``\\b`` | ASCII Backspace (BS) | |\n+-------------------+-----------------------------------+---------+\n| ``\\f`` | ASCII Formfeed (FF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\n`` | ASCII Linefeed (LF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\r`` | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| ``\\t`` | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| ``\\v`` | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| ``\\ooo`` | Character with octal value *ooo* | (1,3) |\n+-------------------+-----------------------------------+---------+\n| ``\\xhh`` | Character with hex value *hh* | (2,3) |\n+-------------------+-----------------------------------+---------+\n\nEscape sequences only recognized in string literals are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\N{name}`` | Character named *name* in the | (4) |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (5) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (6) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, exactly two hex digits are required.\n\n3. In a bytes literal, hexadecimal and octal escapes denote the byte\n with the given value. In a string literal, these escapes denote a\n Unicode character with the given value.\n\n4. Changed in version 3.3: Support for name aliases [1] has been\n added.\n\n5. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Exactly four hex digits are\n required.\n\n6. Any Unicode character can be encoded this way, but characters\n outside the Basic Multilingual Plane (BMP) will be encoded using a\n surrogate pair if Python is compiled to use 16-bit code units (the\n default). Exactly eight hex digits are required.\n\nUnlike Standard C, all unrecognized escape sequences are left in the\nstring unchanged, i.e., *the backslash is left in the string*. (This\nbehavior is useful when debugging: if an escape sequence is mistyped,\nthe resulting output is more easily recognized as broken.) It is also\nimportant to note that the escape sequences only recognized in string\nliterals fall into the category of unrecognized escapes for bytes\nliterals.\n\nEven in a raw string, string quotes can be escaped with a backslash,\nbut the backslash remains in the string; for example, ``r"\\""`` is a\nvalid string literal consisting of two characters: a backslash and a\ndouble quote; ``r"\\"`` is not a valid string literal (even a raw\nstring cannot end in an odd number of backslashes). Specifically, *a\nraw string cannot end in a single backslash* (since the backslash\nwould escape the following quote character). Note also that a single\nbackslash followed by a newline is interpreted as those two characters\nas part of the string, *not* as a line continuation.\n', 'subscriptions': '\nSubscriptions\n*************\n\nA subscription selects an item of a sequence (string, tuple or list)\nor mapping (dictionary) object:\n\n subscription ::= primary "[" expression_list "]"\n\nThe primary must evaluate to an object that supports subscription,\ne.g. a list or dictionary. User-defined objects can support\nsubscription by defining a ``__getitem__()`` method.\n\nFor built-in objects, there are two types of objects that support\nsubscription:\n\nIf the primary is a mapping, the expression list must evaluate to an\nobject whose value is one of the keys of the mapping, and the\nsubscription selects the value in the mapping that corresponds to that\nkey. (The expression list is a tuple except if it has exactly one\nitem.)\n\nIf the primary is a sequence, the expression (list) must evaluate to\nan integer or a slice (as discussed in the following section).\n\nThe formal syntax makes no special provision for negative indices in\nsequences; however, built-in sequences all provide a ``__getitem__()``\nmethod that interprets negative indices by adding the length of the\nsequence to the index (so that ``x[-1]`` selects the last item of\n``x``). The resulting value must be a nonnegative integer less than\nthe number of items in the sequence, and the subscription selects the\nitem whose index is that value (counting from zero). Since the support\nfor negative indices and slicing occurs in the object\'s\n``__getitem__()`` method, subclasses overriding this method will need\nto explicitly add that support.\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n', 'truth': "\nTruth Value Testing\n*******************\n\nAny object can be tested for truth value, for use in an ``if`` or\n``while`` condition or as operand of the Boolean operations below. The\nfollowing values are considered false:\n\n* ``None``\n\n* ``False``\n\n* zero of any numeric type, for example, ``0``, ``0.0``, ``0j``.\n\n* any empty sequence, for example, ``''``, ``()``, ``[]``.\n\n* any empty mapping, for example, ``{}``.\n\n* instances of user-defined classes, if the class defines a\n ``__bool__()`` or ``__len__()`` method, when that method returns the\n integer zero or ``bool`` value ``False``. [1]\n\nAll other values are considered true --- so objects of many types are\nalways true.\n\nOperations and built-in functions that have a Boolean result always\nreturn ``0`` or ``False`` for false and ``1`` or ``True`` for true,\nunless otherwise stated. (Important exception: the Boolean operations\n``or`` and ``and`` always return one of their operands.)\n", 'try': '\nThe ``try`` statement\n*********************\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception, it is re-raised at the end\nof the ``finally`` clause. If the ``finally`` clause raises another\nexception or executes a ``return`` or ``break`` statement, the saved\nexception is set as the context of the new exception. The exception\ninformation is not available to the program during execution of the\n``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', - 'types': '\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.), although such additions\nwill often be provided via the standard library instead.\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name ``None``.\n It is used to signify the absence of a value in many situations,\n e.g., it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n ``NotImplemented``. Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the literal ``...`` or the\n built-in name ``Ellipsis``. Its truth value is true.\n\n``numbers.Number``\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n ``numbers.Integral``\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are two types of integers:\n\n Integers (``int``)\n\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, and Boolean values behave like the values 0 and 1,\n respectively, in almost all contexts, the exception being\n that when converted to a string, the strings ``"False"`` or\n ``"True"`` are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers.\n\n ``numbers.Real`` (``float``)\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these is\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n ``numbers.Complex`` (``complex``)\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number ``z`` can be retrieved through the read-only\n attributes ``z.real`` and ``z.imag``.\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function ``len()`` returns the number of\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is selected by ``a[i]``.\n\n Sequences also support slicing: ``a[i:j]`` selects all items with\n index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: ``a[i:j:k]`` selects all items of *a* with index *x*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'`` and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and ``del`` (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in ``bytearray()`` constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module ``array`` provides an additional example of\n a mutable sequence type, as does the ``collections`` module.\n\nSet types\n These represent unordered, finite sets of unique, immutable\n objects. As such, they cannot be indexed by any subscript. However,\n they can be iterated over, and the built-in function ``len()``\n returns the number of items in a set. Common uses for sets are fast\n membership testing, removing duplicates from a sequence, and\n computing mathematical operations such as intersection, union,\n difference, and symmetric difference.\n\n For set elements, the same immutability rules apply as for\n dictionary keys. Note that numeric types obey the normal rules for\n numeric comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``), only one of them can be contained in a set.\n\n There are currently two intrinsic set types:\n\n Sets\n These represent a mutable set. They are created by the built-in\n ``set()`` constructor and can be modified afterwards by several\n methods, such as ``add()``.\n\n Frozen sets\n These represent an immutable set. They are created by the\n built-in ``frozenset()`` constructor. As a frozenset is\n immutable and *hashable*, it can be used again as an element of\n another set, or as a dictionary key.\n\nMappings\n These represent finite sets of objects indexed by arbitrary index\n sets. The subscript notation ``a[k]`` selects the item indexed by\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``len()`` returns the number of items in a mapping.\n\n There is currently a single intrinsic mapping type:\n\n Dictionaries\n These represent finite sets of objects indexed by nearly\n arbitrary values. The only types of values not acceptable as\n keys are values containing lists or dictionaries or other\n mutable types that are compared by value rather than by object\n identity, the reason being that the efficient implementation of\n dictionaries requires a key\'s hash value to remain constant.\n Numeric types used for keys obey the normal rules for numeric\n comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``) then they can be used interchangeably to index the same\n dictionary entry.\n\n Dictionaries are mutable; they can be created by the ``{...}``\n notation (see section *Dictionary displays*).\n\n The extension modules ``dbm.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\n\nCallable types\n These are the types to which the function call operation (see\n section *Calls*) can be applied:\n\n User-defined functions\n A user-defined function object is created by a function\n definition (see section *Function definitions*). It should be\n called with an argument list containing the same number of items\n as the function\'s formal parameter list.\n\n Special attributes:\n\n +---------------------------+---------------------------------+-------------+\n | Attribute | Meaning | |\n +===========================+=================================+=============+\n | ``__doc__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\n +---------------------------+---------------------------------+-------------+\n | ``__module__`` | The name of the module the | Writable |\n | | function was defined in, or | |\n | | ``None`` if unavailable. | |\n +---------------------------+---------------------------------+-------------+\n | ``__defaults__`` | A tuple containing default | Writable |\n | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | that holds the function\'s | |\n | | global variables --- the global | |\n | | namespace of the module in | |\n | | which the function was defined. | |\n +---------------------------+---------------------------------+-------------+\n | ``__dict__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | or ``\'return\'`` for the return | |\n | | annotation, if provided. | |\n +---------------------------+---------------------------------+-------------+\n | ``__kwdefaults__`` | A dict containing defaults for | Writable |\n | | keyword-only parameters. | |\n +---------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\n\n Function objects also support getting and setting arbitrary\n attributes, which can be used, for example, to attach metadata\n to functions. Regular attribute dot-notation is used to get and\n set such attributes. *Note that the current implementation only\n supports function attributes on user-defined functions. Function\n attributes on built-in functions may be supported in the\n future.*\n\n Additional information about a function\'s definition can be\n retrieved from its code object; see the description of internal\n types below.\n\n Instance methods\n An instance method object combines a class, a class instance and\n any callable object (normally a user-defined function).\n\n Special read-only attributes: ``__self__`` is the class instance\n object, ``__func__`` is the function object; ``__doc__`` is the\n method\'s documentation (same as ``__func__.__doc__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\n\n Methods also support accessing (but not setting) the arbitrary\n function attributes on the underlying function object.\n\n User-defined method objects may be created when getting an\n attribute of a class (perhaps via an instance of that class), if\n that attribute is a user-defined function object or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__func__``\n attribute is the original function object.\n\n When a user-defined method object is created by retrieving\n another method object from a class or instance, the behaviour is\n the same as for a function object, except that the ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n of the class.\n\n Generator functions\n A function or method which uses the ``yield`` statement (see\n section *The yield statement*) is called a *generator function*.\n Such a function, when called, always returns an iterator object\n which can be used to execute the body of the function: calling\n the iterator\'s ``__next__()`` method will cause the function to\n execute until it provides a value using the ``yield`` statement.\n When the function executes a ``return`` statement or falls off\n the end, a ``StopIteration`` exception is raised and the\n iterator will have reached the end of the set of values to be\n returned.\n\n Built-in functions\n A built-in function object is a wrapper around a C function.\n Examples of built-in functions are ``len()`` and ``math.sin()``\n (``math`` is a standard built-in module). The number and type of\n the arguments are determined by the C function. Special read-\n only attributes: ``__doc__`` is the function\'s documentation\n string, or ``None`` if unavailable; ``__name__`` is the\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined in or ``None`` if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n ``alist.append()``, assuming *alist* is a list object. In this\n case, the special read-only attribute ``__self__`` is set to the\n object denoted by *alist*.\n\n Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are imported by the ``import`` statement (see section *The\n import statement*). A module object has a namespace implemented by\n a dictionary object (this is the dictionary referenced by the\n __globals__ attribute of functions defined in the module).\n Attribute references are translated to lookups in this dictionary,\n e.g., ``m.x`` is equivalent to ``m.__dict__["x"]``. A module object\n does not contain the code object used to initialize the module\n (since it isn\'t needed once the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., ``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.\n\n Special read-only attribute: ``__dict__`` is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: ``__name__`` is the module\'s\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute is not present for C modules that are\n statically linked into the interpreter; for extension modules\n loaded dynamically from a shared library, it is the pathname of the\n shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\n\n Class attribute assignments update the class\'s dictionary, never\n the dictionary of a base class.\n\n A class object can be called (see above) to yield a class instance\n (see below).\n\n Special attributes: ``__name__`` is the class name; ``__module__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n undefined.\n\nClass instances\n A class instance is created by calling a class object (see above).\n A class instance has a namespace implemented as a dictionary which\n is the first place in which attribute references are searched.\n When an attribute is not found there, and the instance\'s class has\n an attribute by that name, the search continues with the class\n attributes. If a class attribute is found that is a user-defined\n function object, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n lookup.\n\n Attribute assignments and deletions update the instance\'s\n dictionary, never a class\'s dictionary. If the class has a\n ``__setattr__()`` or ``__delattr__()`` method, this is called\n instead of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n *Special method names*.\n\n Special attributes: ``__dict__`` is the attribute dictionary;\n ``__class__`` is the instance\'s class.\n\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: ``co_name`` gives the function\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n the filename from which the code was compiled;\n ``co_firstlineno`` is the first line number of the function;\n ``co_lnotab`` is a string encoding the mapping from bytecode\n offsets to line numbers (for details see the source code of the\n interpreter); ``co_stacksize`` is the required stack size\n (including local variables); ``co_flags`` is an integer encoding\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of Python.\n\n Other bits in ``co_flags`` are reserved for internal use.\n\n If a code object represents a function, the first item in\n ``co_consts`` is the documentation string of the function, or\n ``None`` if undefined.\n\n Frame objects\n Frame objects represent execution frames. They may occur in\n traceback objects (see below).\n\n Special read-only attributes: ``f_back`` is to the previous\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string of the code object).\n\n Special writable attributes: ``f_trace``, if not ``None``, is a\n function called at the start of each source code line (this is\n used by the debugger); ``f_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n by writing to f_lineno.\n\n Traceback objects\n Traceback objects represent a stack trace of an exception. A\n traceback object is created when an exception occurs. When the\n search for an exception handler unwinds the execution stack, at\n each unwound level a traceback object is inserted in front of\n the current traceback. When an exception handler is entered,\n the stack trace is made available to the program. (See section\n *The try statement*.) It is accessible as the third item of the\n tuple returned by ``sys.exc_info()``. When the program contains\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n ``staticmethod()`` constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in ``classmethod()`` constructor.\n', + 'types': '\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.), although such additions\nwill often be provided via the standard library instead.\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name ``None``.\n It is used to signify the absence of a value in many situations,\n e.g., it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n ``NotImplemented``. Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the literal ``...`` or the\n built-in name ``Ellipsis``. Its truth value is true.\n\n``numbers.Number``\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n ``numbers.Integral``\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are two types of integers:\n\n Integers (``int``)\n\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, and Boolean values behave like the values 0 and 1,\n respectively, in almost all contexts, the exception being\n that when converted to a string, the strings ``"False"`` or\n ``"True"`` are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers.\n\n ``numbers.Real`` (``float``)\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these is\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n ``numbers.Complex`` (``complex``)\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number ``z`` can be retrieved through the read-only\n attributes ``z.real`` and ``z.imag``.\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function ``len()`` returns the number of\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is selected by ``a[i]``.\n\n Sequences also support slicing: ``a[i:j]`` selects all items with\n index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: ``a[i:j:k]`` selects all items of *a* with index *x*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'`` and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and ``del`` (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in ``bytearray()`` constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module ``array`` provides an additional example of\n a mutable sequence type, as does the ``collections`` module.\n\nSet types\n These represent unordered, finite sets of unique, immutable\n objects. As such, they cannot be indexed by any subscript. However,\n they can be iterated over, and the built-in function ``len()``\n returns the number of items in a set. Common uses for sets are fast\n membership testing, removing duplicates from a sequence, and\n computing mathematical operations such as intersection, union,\n difference, and symmetric difference.\n\n For set elements, the same immutability rules apply as for\n dictionary keys. Note that numeric types obey the normal rules for\n numeric comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``), only one of them can be contained in a set.\n\n There are currently two intrinsic set types:\n\n Sets\n These represent a mutable set. They are created by the built-in\n ``set()`` constructor and can be modified afterwards by several\n methods, such as ``add()``.\n\n Frozen sets\n These represent an immutable set. They are created by the\n built-in ``frozenset()`` constructor. As a frozenset is\n immutable and *hashable*, it can be used again as an element of\n another set, or as a dictionary key.\n\nMappings\n These represent finite sets of objects indexed by arbitrary index\n sets. The subscript notation ``a[k]`` selects the item indexed by\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``len()`` returns the number of items in a mapping.\n\n There is currently a single intrinsic mapping type:\n\n Dictionaries\n These represent finite sets of objects indexed by nearly\n arbitrary values. The only types of values not acceptable as\n keys are values containing lists or dictionaries or other\n mutable types that are compared by value rather than by object\n identity, the reason being that the efficient implementation of\n dictionaries requires a key\'s hash value to remain constant.\n Numeric types used for keys obey the normal rules for numeric\n comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``) then they can be used interchangeably to index the same\n dictionary entry.\n\n Dictionaries are mutable; they can be created by the ``{...}``\n notation (see section *Dictionary displays*).\n\n The extension modules ``dbm.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\n\nCallable types\n These are the types to which the function call operation (see\n section *Calls*) can be applied:\n\n User-defined functions\n A user-defined function object is created by a function\n definition (see section *Function definitions*). It should be\n called with an argument list containing the same number of items\n as the function\'s formal parameter list.\n\n Special attributes:\n\n +---------------------------+---------------------------------+-------------+\n | Attribute | Meaning | |\n +===========================+=================================+=============+\n | ``__doc__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\n +---------------------------+---------------------------------+-------------+\n | ``__module__`` | The name of the module the | Writable |\n | | function was defined in, or | |\n | | ``None`` if unavailable. | |\n +---------------------------+---------------------------------+-------------+\n | ``__defaults__`` | A tuple containing default | Writable |\n | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | that holds the function\'s | |\n | | global variables --- the global | |\n | | namespace of the module in | |\n | | which the function was defined. | |\n +---------------------------+---------------------------------+-------------+\n | ``__dict__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | or ``\'return\'`` for the return | |\n | | annotation, if provided. | |\n +---------------------------+---------------------------------+-------------+\n | ``__kwdefaults__`` | A dict containing defaults for | Writable |\n | | keyword-only parameters. | |\n +---------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\n\n Function objects also support getting and setting arbitrary\n attributes, which can be used, for example, to attach metadata\n to functions. Regular attribute dot-notation is used to get and\n set such attributes. *Note that the current implementation only\n supports function attributes on user-defined functions. Function\n attributes on built-in functions may be supported in the\n future.*\n\n Additional information about a function\'s definition can be\n retrieved from its code object; see the description of internal\n types below.\n\n Instance methods\n An instance method object combines a class, a class instance and\n any callable object (normally a user-defined function).\n\n Special read-only attributes: ``__self__`` is the class instance\n object, ``__func__`` is the function object; ``__doc__`` is the\n method\'s documentation (same as ``__func__.__doc__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\n\n Methods also support accessing (but not setting) the arbitrary\n function attributes on the underlying function object.\n\n User-defined method objects may be created when getting an\n attribute of a class (perhaps via an instance of that class), if\n that attribute is a user-defined function object or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__func__``\n attribute is the original function object.\n\n When a user-defined method object is created by retrieving\n another method object from a class or instance, the behaviour is\n the same as for a function object, except that the ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n of the class.\n\n Generator functions\n A function or method which uses the ``yield`` statement (see\n section *The yield statement*) is called a *generator function*.\n Such a function, when called, always returns an iterator object\n which can be used to execute the body of the function: calling\n the iterator\'s ``__next__()`` method will cause the function to\n execute until it provides a value using the ``yield`` statement.\n When the function executes a ``return`` statement or falls off\n the end, a ``StopIteration`` exception is raised and the\n iterator will have reached the end of the set of values to be\n returned.\n\n Built-in functions\n A built-in function object is a wrapper around a C function.\n Examples of built-in functions are ``len()`` and ``math.sin()``\n (``math`` is a standard built-in module). The number and type of\n the arguments are determined by the C function. Special read-\n only attributes: ``__doc__`` is the function\'s documentation\n string, or ``None`` if unavailable; ``__name__`` is the\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined in or ``None`` if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n ``alist.append()``, assuming *alist* is a list object. In this\n case, the special read-only attribute ``__self__`` is set to the\n object denoted by *alist*.\n\n Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the ``import``\n statement (see ``import``), or by calling functions such as\n ``importlib.import_module()`` and built-in ``__import__()``. A\n module object has a namespace implemented by a dictionary object\n (this is the dictionary referenced by the ``__globals__`` attribute\n of functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., ``m.x`` is\n equivalent to ``m.__dict__["x"]``. A module object does not contain\n the code object used to initialize the module (since it isn\'t\n needed once the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., ``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.\n\n Special read-only attribute: ``__dict__`` is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: ``__name__`` is the module\'s\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute may be missing for certain types of modules,\n such as C modules that are statically linked into the interpreter;\n for extension modules loaded dynamically from a shared library, it\n is the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\n\n Class attribute assignments update the class\'s dictionary, never\n the dictionary of a base class.\n\n A class object can be called (see above) to yield a class instance\n (see below).\n\n Special attributes: ``__name__`` is the class name; ``__module__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n undefined.\n\nClass instances\n A class instance is created by calling a class object (see above).\n A class instance has a namespace implemented as a dictionary which\n is the first place in which attribute references are searched.\n When an attribute is not found there, and the instance\'s class has\n an attribute by that name, the search continues with the class\n attributes. If a class attribute is found that is a user-defined\n function object, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n lookup.\n\n Attribute assignments and deletions update the instance\'s\n dictionary, never a class\'s dictionary. If the class has a\n ``__setattr__()`` or ``__delattr__()`` method, this is called\n instead of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n *Special method names*.\n\n Special attributes: ``__dict__`` is the attribute dictionary;\n ``__class__`` is the instance\'s class.\n\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: ``co_name`` gives the function\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n the filename from which the code was compiled;\n ``co_firstlineno`` is the first line number of the function;\n ``co_lnotab`` is a string encoding the mapping from bytecode\n offsets to line numbers (for details see the source code of the\n interpreter); ``co_stacksize`` is the required stack size\n (including local variables); ``co_flags`` is an integer encoding\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of Python.\n\n Other bits in ``co_flags`` are reserved for internal use.\n\n If a code object represents a function, the first item in\n ``co_consts`` is the documentation string of the function, or\n ``None`` if undefined.\n\n Frame objects\n Frame objects represent execution frames. They may occur in\n traceback objects (see below).\n\n Special read-only attributes: ``f_back`` is to the previous\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string of the code object).\n\n Special writable attributes: ``f_trace``, if not ``None``, is a\n function called at the start of each source code line (this is\n used by the debugger); ``f_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n by writing to f_lineno.\n\n Traceback objects\n Traceback objects represent a stack trace of an exception. A\n traceback object is created when an exception occurs. When the\n search for an exception handler unwinds the execution stack, at\n each unwound level a traceback object is inserted in front of\n the current traceback. When an exception handler is entered,\n the stack trace is made available to the program. (See section\n *The try statement*.) It is accessible as the third item of the\n tuple returned by ``sys.exc_info()``. When the program contains\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n ``staticmethod()`` constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in ``classmethod()`` constructor.\n', 'typesfunctions': '\nFunctions\n*********\n\nFunction objects are created by function definitions. The only\noperation on a function object is to call it: ``func(argument-list)``.\n\nThere are really two flavors of function objects: built-in functions\nand user-defined functions. Both support the same operation (to call\nthe function), but the implementation is different, hence the\ndifferent object types.\n\nSee *Function definitions* for more information.\n', 'typesmapping': '\nMapping Types --- ``dict``\n**************************\n\nA *mapping* object maps *hashable* values to arbitrary objects.\nMappings are mutable objects. There is currently only one standard\nmapping type, the *dictionary*. (For other containers see the built\nin ``list``, ``set``, and ``tuple`` classes, and the ``collections``\nmodule.)\n\nA dictionary\'s keys are *almost* arbitrary values. Values that are\nnot *hashable*, that is, values containing lists, dictionaries or\nother mutable types (that are compared by value rather than by object\nidentity) may not be used as keys. Numeric types used for keys obey\nthe normal rules for numeric comparison: if two numbers compare equal\n(such as ``1`` and ``1.0``) then they can be used interchangeably to\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict([arg])\n\n Return a new dictionary initialized from an optional positional\n argument or from a set of keyword arguments. If no arguments are\n given, return a new empty dictionary. If the positional argument\n *arg* is a mapping object, return a dictionary mapping the same\n keys to the same values as does the mapping object. Otherwise the\n positional argument must be a sequence, a container that supports\n iteration, or an iterator object. The elements of the argument\n must each also be of one of those kinds, and each must in turn\n contain exactly two objects. The first is used as a key in the new\n dictionary, and the second as the key\'s value. If a given key is\n seen more than once, the last value associated with it is retained\n in the new dictionary.\n\n If keyword arguments are given, the keywords themselves with their\n associated values are added as items to the dictionary. If a key\n is specified both in the positional argument and as a keyword\n argument, the value associated with the keyword is retained in the\n dictionary. For example, these all return a dictionary equal to\n ``{"one": 1, "two": 2}``:\n\n * ``dict(one=1, two=2)``\n\n * ``dict({\'one\': 1, \'two\': 2})``\n\n * ``dict(zip((\'one\', \'two\'), (1, 2)))``\n\n * ``dict([[\'two\', 2], [\'one\', 1]])``\n\n The first example only works for keys that are valid Python\n identifiers; the others work with any valid keys.\n\n These are the operations that dictionaries support (and therefore,\n custom mapping types should support too):\n\n len(d)\n\n Return the number of items in the dictionary *d*.\n\n d[key]\n\n Return the item of *d* with key *key*. Raises a ``KeyError`` if\n *key* is not in the map.\n\n If a subclass of dict defines a method ``__missing__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\n\n d[key] = value\n\n Set ``d[key]`` to *value*.\n\n del d[key]\n\n Remove ``d[key]`` from *d*. Raises a ``KeyError`` if *key* is\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n classmethod fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n ``fromkeys()`` is a class method that returns a new dictionary.\n *value* defaults to ``None``.\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to ``None``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a ``KeyError`` is raised.\n\n popitem()\n\n Remove and return an arbitrary ``(key, value)`` pair from the\n dictionary.\n\n ``popitem()`` is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling ``popitem()`` raises a ``KeyError``.\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to ``None``.\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return ``None``.\n\n ``update()`` accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: ``d.update(red=1,\n blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` are *view objects*. They provide a dynamic view on\nthe dictionary\'s entries, which means that when the dictionary\nchanges, the view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of ``(key, value)``) in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of ``(value, key)`` pairs\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n d.items()]``.\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a ``RuntimeError`` or fail to iterate over all entries.\n\nx in dictview\n\n Return ``True`` if *x* is in the underlying dictionary\'s keys,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that ``(key, value)`` pairs are unique\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', 'typesmethods': "\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as ``append()`` on\nlists) and class instance methods. Built-in methods are described\nwith the types that support them.\n\nIf you access a method (a function defined in a class namespace)\nthrough an instance, you get a special object: a *bound method* (also\ncalled *instance method*) object. When called, it will add the\n``self`` argument to the argument list. Bound methods have two\nspecial read-only attributes: ``m.__self__`` is the object on which\nthe method operates, and ``m.__func__`` is the function implementing\nthe method. Calling ``m(arg-1, arg-2, ..., arg-n)`` is completely\nequivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,\narg-n)``.\n\nLike function objects, bound method objects support getting arbitrary\nattributes. However, since method attributes are actually stored on\nthe underlying function object (``meth.__func__``), setting method\nattributes on bound methods is disallowed. Attempting to set a method\nattribute results in a ``TypeError`` being raised. In order to set a\nmethod attribute, you need to explicitly set it on the underlying\nfunction object:\n\n class C:\n def method(self):\n pass\n\n c = C()\n c.method.__func__.whoami = 'my name is c'\n\nSee *The standard type hierarchy* for more information.\n", 'typesmodules': "\nModules\n*******\n\nThe only special operation on a module is attribute access:\n``m.name``, where *m* is a module and *name* accesses a name defined\nin *m*'s symbol table. Module attributes can be assigned to. (Note\nthat the ``import`` statement is not, strictly speaking, an operation\non a module object; ``import foo`` does not require a module object\nnamed *foo* to exist, rather it requires an (external) *definition*\nfor a module named *foo* somewhere.)\n\nA special attribute of every module is ``__dict__``. This is the\ndictionary containing the module's symbol table. Modifying this\ndictionary will actually change the module's symbol table, but direct\nassignment to the ``__dict__`` attribute is not possible (you can\nwrite ``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but\nyou can't write ``m.__dict__ = {}``). Modifying ``__dict__`` directly\nis not recommended.\n\nModules built into the interpreter are written like this: ````. If loaded from a file, they are written as\n````.\n", - 'typesseq': '\nSequence Types --- ``str``, ``bytes``, ``bytearray``, ``list``, ``tuple``, ``range``\n************************************************************************************\n\nThere are six sequence types: strings, byte sequences (``bytes``\nobjects), byte arrays (``bytearray`` objects), lists, tuples, and\nrange objects. For other containers see the built in ``dict`` and\n``set`` classes, and the ``collections`` module.\n\nStrings contain Unicode characters. Their literals are written in\nsingle or double quotes: ``\'xyzzy\'``, ``"frobozz"``. See *String and\nBytes literals* for more about string literals. In addition to the\nfunctionality described here, there are also string-specific methods\ndescribed in the *String Methods* section.\n\nBytes and bytearray objects contain single bytes -- the former is\nimmutable while the latter is a mutable sequence. Bytes objects can be\nconstructed by using the constructor, ``bytes()``, and from literals;\nuse a ``b`` prefix with normal string syntax: ``b\'xyzzy\'``. To\nconstruct byte arrays, use the ``bytearray()`` function.\n\nWhile string objects are sequences of characters (represented by\nstrings of length 1), bytes and bytearray objects are sequences of\n*integers* (between 0 and 255), representing the ASCII value of single\nbytes. That means that for a bytes or bytearray object *b*, ``b[0]``\nwill be an integer, while ``b[0:1]`` will be a bytes or bytearray\nobject of length 1. The representation of bytes objects uses the\nliteral format (``b\'...\'``) since it is generally more useful than\ne.g. ``bytes([50, 19, 100])``. You can always convert a bytes object\ninto a list of integers using ``list(b)``.\n\nAlso, while in previous Python versions, byte strings and Unicode\nstrings could be exchanged for each other rather freely (barring\nencoding issues), strings and bytes are now completely separate\nconcepts. There\'s no implicit en-/decoding if you pass an object of\nthe wrong type. A string always compares unequal to a bytes or\nbytearray object.\n\nLists are constructed with square brackets, separating items with\ncommas: ``[a, b, c]``. Tuples are constructed by the comma operator\n(not within square brackets), with or without enclosing parentheses,\nbut an empty tuple must have the enclosing parentheses, such as ``a,\nb, c`` or ``()``. A single item tuple must have a trailing comma,\nsuch as ``(d,)``.\n\nObjects of type range are created using the ``range()`` function.\nThey don\'t support concatenation or repetition, and using ``min()`` or\n``max()`` on them is inefficient.\n\nMost sequence types support the following operations. The ``in`` and\n``not in`` operations have the same priorities as the comparison\noperations. The ``+`` and ``*`` operations have the same priority as\nthe corresponding numeric operations. [3] Additional methods are\nprovided for *Mutable Sequence Types*.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type; *n*, *i*, *j* and *k* are\nintegers.\n\n+--------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+====================+==================================+============+\n| ``x in s`` | ``True`` if an item of *s* is | (1) |\n| | equal to *x*, else ``False`` | |\n+--------------------+----------------------------------+------------+\n| ``x not in s`` | ``False`` if an item of *s* is | (1) |\n| | equal to *x*, else ``True`` | |\n+--------------------+----------------------------------+------------+\n| ``s + t`` | the concatenation of *s* and *t* | (6) |\n+--------------------+----------------------------------+------------+\n| ``s * n, n * s`` | *n* shallow copies of *s* | (2) |\n| | concatenated | |\n+--------------------+----------------------------------+------------+\n| ``s[i]`` | *i*th item of *s*, origin 0 | (3) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+--------------------+----------------------------------+------------+\n| ``len(s)`` | length of *s* | |\n+--------------------+----------------------------------+------------+\n| ``min(s)`` | smallest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``max(s)`` | largest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.index(i)`` | index of the first occurence of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.count(i)`` | total number of occurences of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n\nSequence types also support comparisons. In particular, tuples and\nlists are compared lexicographically by comparing corresponding\nelements. This means that to compare equal, every element must\ncompare equal and the two sequences must be of the same type and have\nthe same length. (For full details see *Comparisons* in the language\nreference.)\n\nNotes:\n\n1. When *s* is a string object, the ``in`` and ``not in`` operations\n act like a substring test.\n\n2. Values of *n* less than ``0`` are treated as ``0`` (which yields an\n empty sequence of the same type as *s*). Note also that the copies\n are shallow; nested structures are not copied. This often haunts\n new Python programmers; consider:\n\n >>> lists = [[]] * 3\n >>> lists\n [[], [], []]\n >>> lists[0].append(3)\n >>> lists\n [[3], [3], [3]]\n\n What has happened is that ``[[]]`` is a one-element list containing\n an empty list, so all three elements of ``[[]] * 3`` are (pointers\n to) this single empty list. Modifying any of the elements of\n ``lists`` modifies this single list. You can create a list of\n different lists this way:\n\n >>> lists = [[] for i in range(3)]\n >>> lists[0].append(3)\n >>> lists[1].append(5)\n >>> lists[2].append(7)\n >>> lists\n [[3], [5], [7]]\n\n3. If *i* or *j* is negative, the index is relative to the end of the\n string: ``len(s) + i`` or ``len(s) + j`` is substituted. But note\n that ``-0`` is still ``0``.\n\n4. The slice of *s* from *i* to *j* is defined as the sequence of\n items with index *k* such that ``i <= k < j``. If *i* or *j* is\n greater than ``len(s)``, use ``len(s)``. If *i* is omitted or\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n empty.\n\n5. The slice of *s* from *i* to *j* with step *k* is defined as the\n sequence of items with index ``x = i + n*k`` such that ``0 <= n <\n (j-i)/k``. In other words, the indices are ``i``, ``i+k``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable strings always results in a new object.\n This means that building up a string by repeated concatenation will\n have a quadratic runtime cost in the total string length. To get a\n linear runtime cost, you must switch to one of the alternatives\n below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end;\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()``, or you can do in-place concatenation with a\n ``bytearray`` object. ``bytearray`` objects are mutable and have\n an efficient overallocation mechanism.\n\n\nString Methods\n==============\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. Line breaks are not included in the resulting list\n unless *keepends* is given and true. This method uses the universal\n newlines approach to splitting lines. Unlike ``split()``, if the\n string ends with line boundary characters the returned list does\n ``not`` have an empty last element.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n\n\nOld String Formatting Operations\n================================\n\nNote: The formatting operations described here are modelled on C\'s\n printf() syntax. They only support formatting of certain builtin\n types. The use of a binary operator means that care may be needed\n in order to format tuples and dictionaries correctly. As the new\n *String Formatting* syntax is more flexible and handles tuples and\n dictionaries naturally, it is recommended for new code. However,\n there are no current plans to deprecate printf-style formatting.\n\nString objects have one unique built-in operation: the ``%`` operator\n(modulo). This is also known as the string *formatting* or\n*interpolation* operator. Given ``format % values`` (where *format* is\na string), ``%`` conversion specifications in *format* are replaced\nwith zero or more elements of *values*. The effect is similar to the\nusing ``sprintf()`` in the C language.\n\nIf *format* requires a single argument, *values* may be a single non-\ntuple object. [5] Otherwise, *values* must be a tuple with exactly\nthe number of items specified by the format string, or a single\nmapping object (for example, a dictionary).\n\nA conversion specifier contains two or more characters and has the\nfollowing components, which must occur in this order:\n\n1. The ``\'%\'`` character, which marks the start of the specifier.\n\n2. Mapping key (optional), consisting of a parenthesised sequence of\n characters (for example, ``(somename)``).\n\n3. Conversion flags (optional), which affect the result of some\n conversion types.\n\n4. Minimum field width (optional). If specified as an ``\'*\'``\n (asterisk), the actual width is read from the next element of the\n tuple in *values*, and the object to convert comes after the\n minimum field width and optional precision.\n\n5. Precision (optional), given as a ``\'.\'`` (dot) followed by the\n precision. If specified as ``\'*\'`` (an asterisk), the actual\n precision is read from the next element of the tuple in *values*,\n and the value to convert comes after the precision.\n\n6. Length modifier (optional).\n\n7. Conversion type.\n\nWhen the right argument is a dictionary (or other mapping type), then\nthe formats in the string *must* include a parenthesised mapping key\ninto that dictionary inserted immediately after the ``\'%\'`` character.\nThe mapping key selects the value to be formatted from the mapping.\nFor example:\n\n>>> print(\'%(language)s has %(number)03d quote types.\' %\n... {\'language\': "Python", "number": 2})\nPython has 002 quote types.\n\nIn this case no ``*`` specifiers may occur in a format (since they\nrequire a sequential parameter list).\n\nThe conversion flag characters are:\n\n+-----------+-----------------------------------------------------------------------+\n| Flag | Meaning |\n+===========+=======================================================================+\n| ``\'#\'`` | The value conversion will use the "alternate form" (where defined |\n| | below). |\n+-----------+-----------------------------------------------------------------------+\n| ``\'0\'`` | The conversion will be zero padded for numeric values. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'-\'`` | The converted value is left adjusted (overrides the ``\'0\'`` |\n| | conversion if both are given). |\n+-----------+-----------------------------------------------------------------------+\n| ``\' \'`` | (a space) A blank should be left before a positive number (or empty |\n| | string) produced by a signed conversion. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'+\'`` | A sign character (``\'+\'`` or ``\'-\'``) will precede the conversion |\n| | (overrides a "space" flag). |\n+-----------+-----------------------------------------------------------------------+\n\nA length modifier (``h``, ``l``, or ``L``) may be present, but is\nignored as it is not necessary for Python -- so e.g. ``%ld`` is\nidentical to ``%d``.\n\nThe conversion types are:\n\n+--------------+-------------------------------------------------------+---------+\n| Conversion | Meaning | Notes |\n+==============+=======================================================+=========+\n| ``\'d\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'i\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'o\'`` | Signed octal value. | (1) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'u\'`` | Obsolete type -- it is identical to ``\'d\'``. | (7) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'x\'`` | Signed hexadecimal (lowercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'X\'`` | Signed hexadecimal (uppercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'e\'`` | Floating point exponential format (lowercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'E\'`` | Floating point exponential format (uppercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'f\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'F\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'g\'`` | Floating point format. Uses lowercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'G\'`` | Floating point format. Uses uppercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'c\'`` | Single character (accepts integer or single character | |\n| | string). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'r\'`` | String (converts any Python object using ``repr()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'s\'`` | String (converts any Python object using ``str()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'a\'`` | String (converts any Python object using | (5) |\n| | ``ascii()``). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'%\'`` | No argument is converted, results in a ``\'%\'`` | |\n| | character in the result. | |\n+--------------+-------------------------------------------------------+---------+\n\nNotes:\n\n1. The alternate form causes a leading zero (``\'0\'``) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n2. The alternate form causes a leading ``\'0x\'`` or ``\'0X\'`` (depending\n on whether the ``\'x\'`` or ``\'X\'`` format was used) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n3. The alternate form causes the result to always contain a decimal\n point, even if no digits follow it.\n\n The precision determines the number of digits after the decimal\n point and defaults to 6.\n\n4. The alternate form causes the result to always contain a decimal\n point, and trailing zeroes are not removed as they would otherwise\n be.\n\n The precision determines the number of significant digits before\n and after the decimal point and defaults to 6.\n\n5. If precision is ``N``, the output is truncated to ``N`` characters.\n\n1. See **PEP 237**.\n\nSince Python strings have an explicit length, ``%s`` conversions do\nnot assume that ``\'\\0\'`` is the end of the string.\n\nChanged in version 3.1: ``%f`` conversions for numbers whose absolute\nvalue is over 1e50 are no longer replaced by ``%g`` conversions.\n\nAdditional string operations are defined in standard modules\n``string`` and ``re``.\n\n\nRange Type\n==========\n\nThe ``range`` type is an immutable sequence which is commonly used for\nlooping. The advantage of the ``range`` type is that an ``range``\nobject will always take the same amount of memory, no matter the size\nof the range it represents.\n\nRange objects have relatively little behavior: they support indexing,\ncontains, iteration, the ``len()`` function, and the following\nmethods:\n\nrange.count(x)\n\n Return the number of *i*\'s for which ``s[i] == x``.\n\n New in version 3.2.\n\nrange.index(x)\n\n Return the smallest *i* such that ``s[i] == x``. Raises\n ``ValueError`` when *x* is not in the range.\n\n New in version 3.2.\n\n\nMutable Sequence Types\n======================\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | remove all items from ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | return a shallow copy of ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.count(x)`` | return number of *i*\'s for which | |\n| | ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.index(x[, i[, j]])`` | return smallest *k* such that | (3) |\n| | ``s[k] == x`` and ``i <= k < j`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | (5) |\n| | return x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | (3) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (6) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. *x* can be any iterable object.\n\n3. Raises ``ValueError`` when *x* is not found in *s*. When a negative\n index is passed as the second or third parameter to the ``index()``\n method, the sequence length is added, as for slice indices. If it\n is still negative, it is truncated to zero, as for slice indices.\n\n4. When a negative index is passed as the first parameter to the\n ``insert()`` method, the sequence length is added, as for slice\n indices. If it is still negative, it is truncated to zero, as for\n slice indices.\n\n5. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n6. The ``sort()`` and ``reverse()`` methods modify the sequence in\n place for economy of space when sorting or reversing a large\n sequence. To remind you that they operate by side effect, they\n don\'t return the sorted or reversed sequence.\n\n7. The ``sort()`` method takes optional arguments for controlling the\n comparisons. Each must be specified as a keyword argument.\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: ``key=str.lower``. The\n default value is ``None``. Use ``functools.cmp_to_key()`` to\n convert an old-style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n The ``sort()`` method is guaranteed to be stable. A sort is stable\n if it guarantees not to change the relative order of elements that\n compare equal --- this is helpful for sorting in multiple passes\n (for example, sort by department, then by salary grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can detect\n that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nBytes and Byte Array Methods\n============================\n\nBytes and bytearray objects, being "strings of bytes", have all\nmethods found on strings, with the exception of ``encode()``,\n``format()`` and ``isidentifier()``, which do not make sense with\nthese types. For converting the objects to strings, they have a\n``decode()`` method.\n\nWherever one of these methods needs to interpret the bytes as\ncharacters (e.g. the ``is...()`` methods), the ASCII character set is\nassumed.\n\nNew in version 3.3: The functions ``count()``, ``find()``,\n``index()``, ``rfind()`` and ``rindex()`` have additional semantics\ncompared to the corresponding string functions: They also accept an\ninteger in range 0 to 255 (a byte) as their first argument.\n\nNote: The methods on bytes and bytearray objects don\'t accept strings as\n their arguments, just as the methods on strings don\'t accept bytes\n as their arguments. For example, you have to write\n\n a = "abc"\n b = a.replace("a", "f")\n\n and\n\n a = b"abc"\n b = a.replace(b"a", b"f")\n\nbytes.decode(encoding="utf-8", errors="strict")\nbytearray.decode(encoding="utf-8", errors="strict")\n\n Return a string decoded from the given bytes. Default encoding is\n ``\'utf-8\'``. *errors* may be given to set a different error\n handling scheme. The default for *errors* is ``\'strict\'``, meaning\n that encoding errors raise a ``UnicodeError``. Other possible\n values are ``\'ignore\'``, ``\'replace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Added support for keyword arguments.\n\nThe bytes and bytearray types have an additional class method:\n\nclassmethod bytes.fromhex(string)\nclassmethod bytearray.fromhex(string)\n\n This ``bytes`` class method returns a bytes or bytearray object,\n decoding the given string object. The string must contain two\n hexadecimal digits per byte, spaces are ignored.\n\n >>> bytes.fromhex(\'f0 f1f2 \')\n b\'\\xf0\\xf1\\xf2\'\n\nThe maketrans and translate methods differ in semantics from the\nversions available on strings:\n\nbytes.translate(table[, delete])\nbytearray.translate(table[, delete])\n\n Return a copy of the bytes or bytearray object where all bytes\n occurring in the optional argument *delete* are removed, and the\n remaining bytes have been mapped through the given translation\n table, which must be a bytes object of length 256.\n\n You can use the ``bytes.maketrans()`` method to create a\n translation table.\n\n Set the *table* argument to ``None`` for translations that only\n delete characters:\n\n >>> b\'read this short text\'.translate(None, b\'aeiou\')\n b\'rd ths shrt txt\'\n\nstatic bytes.maketrans(from, to)\nstatic bytearray.maketrans(from, to)\n\n This static method returns a translation table usable for\n ``bytes.translate()`` that will map each character in *from* into\n the character at the same position in *to*; *from* and *to* must be\n bytes objects and have the same length.\n\n New in version 3.1.\n', + 'typesseq': '\nSequence Types --- ``str``, ``bytes``, ``bytearray``, ``list``, ``tuple``, ``range``\n************************************************************************************\n\nThere are six sequence types: strings, byte sequences (``bytes``\nobjects), byte arrays (``bytearray`` objects), lists, tuples, and\nrange objects. For other containers see the built in ``dict`` and\n``set`` classes, and the ``collections`` module.\n\nStrings contain Unicode characters. Their literals are written in\nsingle or double quotes: ``\'xyzzy\'``, ``"frobozz"``. See *String and\nBytes literals* for more about string literals. In addition to the\nfunctionality described here, there are also string-specific methods\ndescribed in the *String Methods* section.\n\nBytes and bytearray objects contain single bytes -- the former is\nimmutable while the latter is a mutable sequence. Bytes objects can be\nconstructed by using the constructor, ``bytes()``, and from literals;\nuse a ``b`` prefix with normal string syntax: ``b\'xyzzy\'``. To\nconstruct byte arrays, use the ``bytearray()`` function.\n\nWhile string objects are sequences of characters (represented by\nstrings of length 1), bytes and bytearray objects are sequences of\n*integers* (between 0 and 255), representing the ASCII value of single\nbytes. That means that for a bytes or bytearray object *b*, ``b[0]``\nwill be an integer, while ``b[0:1]`` will be a bytes or bytearray\nobject of length 1. The representation of bytes objects uses the\nliteral format (``b\'...\'``) since it is generally more useful than\ne.g. ``bytes([50, 19, 100])``. You can always convert a bytes object\ninto a list of integers using ``list(b)``.\n\nAlso, while in previous Python versions, byte strings and Unicode\nstrings could be exchanged for each other rather freely (barring\nencoding issues), strings and bytes are now completely separate\nconcepts. There\'s no implicit en-/decoding if you pass an object of\nthe wrong type. A string always compares unequal to a bytes or\nbytearray object.\n\nLists are constructed with square brackets, separating items with\ncommas: ``[a, b, c]``. Tuples are constructed by the comma operator\n(not within square brackets), with or without enclosing parentheses,\nbut an empty tuple must have the enclosing parentheses, such as ``a,\nb, c`` or ``()``. A single item tuple must have a trailing comma,\nsuch as ``(d,)``.\n\nObjects of type range are created using the ``range()`` function.\nThey don\'t support concatenation or repetition, and using ``min()`` or\n``max()`` on them is inefficient.\n\nMost sequence types support the following operations. The ``in`` and\n``not in`` operations have the same priorities as the comparison\noperations. The ``+`` and ``*`` operations have the same priority as\nthe corresponding numeric operations. [3] Additional methods are\nprovided for *Mutable Sequence Types*.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type; *n*, *i*, *j* and *k* are\nintegers.\n\n+--------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+====================+==================================+============+\n| ``x in s`` | ``True`` if an item of *s* is | (1) |\n| | equal to *x*, else ``False`` | |\n+--------------------+----------------------------------+------------+\n| ``x not in s`` | ``False`` if an item of *s* is | (1) |\n| | equal to *x*, else ``True`` | |\n+--------------------+----------------------------------+------------+\n| ``s + t`` | the concatenation of *s* and *t* | (6) |\n+--------------------+----------------------------------+------------+\n| ``s * n, n * s`` | *n* shallow copies of *s* | (2) |\n| | concatenated | |\n+--------------------+----------------------------------+------------+\n| ``s[i]`` | *i*th item of *s*, origin 0 | (3) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+--------------------+----------------------------------+------------+\n| ``len(s)`` | length of *s* | |\n+--------------------+----------------------------------+------------+\n| ``min(s)`` | smallest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``max(s)`` | largest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.index(i)`` | index of the first occurence of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.count(i)`` | total number of occurences of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n\nSequence types also support comparisons. In particular, tuples and\nlists are compared lexicographically by comparing corresponding\nelements. This means that to compare equal, every element must\ncompare equal and the two sequences must be of the same type and have\nthe same length. (For full details see *Comparisons* in the language\nreference.)\n\nNotes:\n\n1. When *s* is a string object, the ``in`` and ``not in`` operations\n act like a substring test.\n\n2. Values of *n* less than ``0`` are treated as ``0`` (which yields an\n empty sequence of the same type as *s*). Note also that the copies\n are shallow; nested structures are not copied. This often haunts\n new Python programmers; consider:\n\n >>> lists = [[]] * 3\n >>> lists\n [[], [], []]\n >>> lists[0].append(3)\n >>> lists\n [[3], [3], [3]]\n\n What has happened is that ``[[]]`` is a one-element list containing\n an empty list, so all three elements of ``[[]] * 3`` are (pointers\n to) this single empty list. Modifying any of the elements of\n ``lists`` modifies this single list. You can create a list of\n different lists this way:\n\n >>> lists = [[] for i in range(3)]\n >>> lists[0].append(3)\n >>> lists[1].append(5)\n >>> lists[2].append(7)\n >>> lists\n [[3], [5], [7]]\n\n3. If *i* or *j* is negative, the index is relative to the end of the\n string: ``len(s) + i`` or ``len(s) + j`` is substituted. But note\n that ``-0`` is still ``0``.\n\n4. The slice of *s* from *i* to *j* is defined as the sequence of\n items with index *k* such that ``i <= k < j``. If *i* or *j* is\n greater than ``len(s)``, use ``len(s)``. If *i* is omitted or\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n empty.\n\n5. The slice of *s* from *i* to *j* with step *k* is defined as the\n sequence of items with index ``x = i + n*k`` such that ``0 <= n <\n (j-i)/k``. In other words, the indices are ``i``, ``i+k``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable strings always results in a new object.\n This means that building up a string by repeated concatenation will\n have a quadratic runtime cost in the total string length. To get a\n linear runtime cost, you must switch to one of the alternatives\n below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end;\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()``, or you can do in-place concatenation with a\n ``bytearray`` object. ``bytearray`` objects are mutable and have\n an efficient overallocation mechanism.\n\n\nString Methods\n==============\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the universal newlines approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n\n\nOld String Formatting Operations\n================================\n\nNote: The formatting operations described here are modelled on C\'s\n printf() syntax. They only support formatting of certain builtin\n types. The use of a binary operator means that care may be needed\n in order to format tuples and dictionaries correctly. As the new\n *String Formatting* syntax is more flexible and handles tuples and\n dictionaries naturally, it is recommended for new code. However,\n there are no current plans to deprecate printf-style formatting.\n\nString objects have one unique built-in operation: the ``%`` operator\n(modulo). This is also known as the string *formatting* or\n*interpolation* operator. Given ``format % values`` (where *format* is\na string), ``%`` conversion specifications in *format* are replaced\nwith zero or more elements of *values*. The effect is similar to the\nusing ``sprintf()`` in the C language.\n\nIf *format* requires a single argument, *values* may be a single non-\ntuple object. [5] Otherwise, *values* must be a tuple with exactly\nthe number of items specified by the format string, or a single\nmapping object (for example, a dictionary).\n\nA conversion specifier contains two or more characters and has the\nfollowing components, which must occur in this order:\n\n1. The ``\'%\'`` character, which marks the start of the specifier.\n\n2. Mapping key (optional), consisting of a parenthesised sequence of\n characters (for example, ``(somename)``).\n\n3. Conversion flags (optional), which affect the result of some\n conversion types.\n\n4. Minimum field width (optional). If specified as an ``\'*\'``\n (asterisk), the actual width is read from the next element of the\n tuple in *values*, and the object to convert comes after the\n minimum field width and optional precision.\n\n5. Precision (optional), given as a ``\'.\'`` (dot) followed by the\n precision. If specified as ``\'*\'`` (an asterisk), the actual\n precision is read from the next element of the tuple in *values*,\n and the value to convert comes after the precision.\n\n6. Length modifier (optional).\n\n7. Conversion type.\n\nWhen the right argument is a dictionary (or other mapping type), then\nthe formats in the string *must* include a parenthesised mapping key\ninto that dictionary inserted immediately after the ``\'%\'`` character.\nThe mapping key selects the value to be formatted from the mapping.\nFor example:\n\n>>> print(\'%(language)s has %(number)03d quote types.\' %\n... {\'language\': "Python", "number": 2})\nPython has 002 quote types.\n\nIn this case no ``*`` specifiers may occur in a format (since they\nrequire a sequential parameter list).\n\nThe conversion flag characters are:\n\n+-----------+-----------------------------------------------------------------------+\n| Flag | Meaning |\n+===========+=======================================================================+\n| ``\'#\'`` | The value conversion will use the "alternate form" (where defined |\n| | below). |\n+-----------+-----------------------------------------------------------------------+\n| ``\'0\'`` | The conversion will be zero padded for numeric values. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'-\'`` | The converted value is left adjusted (overrides the ``\'0\'`` |\n| | conversion if both are given). |\n+-----------+-----------------------------------------------------------------------+\n| ``\' \'`` | (a space) A blank should be left before a positive number (or empty |\n| | string) produced by a signed conversion. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'+\'`` | A sign character (``\'+\'`` or ``\'-\'``) will precede the conversion |\n| | (overrides a "space" flag). |\n+-----------+-----------------------------------------------------------------------+\n\nA length modifier (``h``, ``l``, or ``L``) may be present, but is\nignored as it is not necessary for Python -- so e.g. ``%ld`` is\nidentical to ``%d``.\n\nThe conversion types are:\n\n+--------------+-------------------------------------------------------+---------+\n| Conversion | Meaning | Notes |\n+==============+=======================================================+=========+\n| ``\'d\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'i\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'o\'`` | Signed octal value. | (1) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'u\'`` | Obsolete type -- it is identical to ``\'d\'``. | (7) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'x\'`` | Signed hexadecimal (lowercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'X\'`` | Signed hexadecimal (uppercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'e\'`` | Floating point exponential format (lowercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'E\'`` | Floating point exponential format (uppercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'f\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'F\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'g\'`` | Floating point format. Uses lowercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'G\'`` | Floating point format. Uses uppercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'c\'`` | Single character (accepts integer or single character | |\n| | string). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'r\'`` | String (converts any Python object using ``repr()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'s\'`` | String (converts any Python object using ``str()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'a\'`` | String (converts any Python object using | (5) |\n| | ``ascii()``). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'%\'`` | No argument is converted, results in a ``\'%\'`` | |\n| | character in the result. | |\n+--------------+-------------------------------------------------------+---------+\n\nNotes:\n\n1. The alternate form causes a leading zero (``\'0\'``) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n2. The alternate form causes a leading ``\'0x\'`` or ``\'0X\'`` (depending\n on whether the ``\'x\'`` or ``\'X\'`` format was used) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n3. The alternate form causes the result to always contain a decimal\n point, even if no digits follow it.\n\n The precision determines the number of digits after the decimal\n point and defaults to 6.\n\n4. The alternate form causes the result to always contain a decimal\n point, and trailing zeroes are not removed as they would otherwise\n be.\n\n The precision determines the number of significant digits before\n and after the decimal point and defaults to 6.\n\n5. If precision is ``N``, the output is truncated to ``N`` characters.\n\n1. See **PEP 237**.\n\nSince Python strings have an explicit length, ``%s`` conversions do\nnot assume that ``\'\\0\'`` is the end of the string.\n\nChanged in version 3.1: ``%f`` conversions for numbers whose absolute\nvalue is over 1e50 are no longer replaced by ``%g`` conversions.\n\nAdditional string operations are defined in standard modules\n``string`` and ``re``.\n\n\nRange Type\n==========\n\nThe ``range`` type is an immutable sequence which is commonly used for\nlooping. The advantage of the ``range`` type is that an ``range``\nobject will always take the same amount of memory, no matter the size\nof the range it represents.\n\nRange objects have relatively little behavior: they support indexing,\ncontains, iteration, the ``len()`` function, and the following\nmethods:\n\nrange.count(x)\n\n Return the number of *i*\'s for which ``s[i] == x``.\n\n New in version 3.2.\n\nrange.index(x)\n\n Return the smallest *i* such that ``s[i] == x``. Raises\n ``ValueError`` when *x* is not in the range.\n\n New in version 3.2.\n\n\nMutable Sequence Types\n======================\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | remove all items from ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | return a shallow copy of ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.count(x)`` | return number of *i*\'s for which | |\n| | ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.index(x[, i[, j]])`` | return smallest *k* such that | (3) |\n| | ``s[k] == x`` and ``i <= k < j`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | (5) |\n| | return x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | (3) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (6) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. *x* can be any iterable object.\n\n3. Raises ``ValueError`` when *x* is not found in *s*. When a negative\n index is passed as the second or third parameter to the ``index()``\n method, the sequence length is added, as for slice indices. If it\n is still negative, it is truncated to zero, as for slice indices.\n\n4. When a negative index is passed as the first parameter to the\n ``insert()`` method, the sequence length is added, as for slice\n indices. If it is still negative, it is truncated to zero, as for\n slice indices.\n\n5. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n6. The ``sort()`` and ``reverse()`` methods modify the sequence in\n place for economy of space when sorting or reversing a large\n sequence. To remind you that they operate by side effect, they\n don\'t return the sorted or reversed sequence.\n\n7. The ``sort()`` method takes optional arguments for controlling the\n comparisons. Each must be specified as a keyword argument.\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: ``key=str.lower``. The\n default value is ``None``. Use ``functools.cmp_to_key()`` to\n convert an old-style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n The ``sort()`` method is guaranteed to be stable. A sort is stable\n if it guarantees not to change the relative order of elements that\n compare equal --- this is helpful for sorting in multiple passes\n (for example, sort by department, then by salary grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can detect\n that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nBytes and Byte Array Methods\n============================\n\nBytes and bytearray objects, being "strings of bytes", have all\nmethods found on strings, with the exception of ``encode()``,\n``format()`` and ``isidentifier()``, which do not make sense with\nthese types. For converting the objects to strings, they have a\n``decode()`` method.\n\nWherever one of these methods needs to interpret the bytes as\ncharacters (e.g. the ``is...()`` methods), the ASCII character set is\nassumed.\n\nNew in version 3.3: The functions ``count()``, ``find()``,\n``index()``, ``rfind()`` and ``rindex()`` have additional semantics\ncompared to the corresponding string functions: They also accept an\ninteger in range 0 to 255 (a byte) as their first argument.\n\nNote: The methods on bytes and bytearray objects don\'t accept strings as\n their arguments, just as the methods on strings don\'t accept bytes\n as their arguments. For example, you have to write\n\n a = "abc"\n b = a.replace("a", "f")\n\n and\n\n a = b"abc"\n b = a.replace(b"a", b"f")\n\nbytes.decode(encoding="utf-8", errors="strict")\nbytearray.decode(encoding="utf-8", errors="strict")\n\n Return a string decoded from the given bytes. Default encoding is\n ``\'utf-8\'``. *errors* may be given to set a different error\n handling scheme. The default for *errors* is ``\'strict\'``, meaning\n that encoding errors raise a ``UnicodeError``. Other possible\n values are ``\'ignore\'``, ``\'replace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Added support for keyword arguments.\n\nThe bytes and bytearray types have an additional class method:\n\nclassmethod bytes.fromhex(string)\nclassmethod bytearray.fromhex(string)\n\n This ``bytes`` class method returns a bytes or bytearray object,\n decoding the given string object. The string must contain two\n hexadecimal digits per byte, spaces are ignored.\n\n >>> bytes.fromhex(\'f0 f1f2 \')\n b\'\\xf0\\xf1\\xf2\'\n\nThe maketrans and translate methods differ in semantics from the\nversions available on strings:\n\nbytes.translate(table[, delete])\nbytearray.translate(table[, delete])\n\n Return a copy of the bytes or bytearray object where all bytes\n occurring in the optional argument *delete* are removed, and the\n remaining bytes have been mapped through the given translation\n table, which must be a bytes object of length 256.\n\n You can use the ``bytes.maketrans()`` method to create a\n translation table.\n\n Set the *table* argument to ``None`` for translations that only\n delete characters:\n\n >>> b\'read this short text\'.translate(None, b\'aeiou\')\n b\'rd ths shrt txt\'\n\nstatic bytes.maketrans(from, to)\nstatic bytearray.maketrans(from, to)\n\n This static method returns a translation table usable for\n ``bytes.translate()`` that will map each character in *from* into\n the character at the same position in *to*; *from* and *to* must be\n bytes objects and have the same length.\n\n New in version 3.1.\n', 'typesseq-mutable': '\nMutable Sequence Types\n**********************\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | remove all items from ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | return a shallow copy of ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.count(x)`` | return number of *i*\'s for which | |\n| | ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.index(x[, i[, j]])`` | return smallest *k* such that | (3) |\n| | ``s[k] == x`` and ``i <= k < j`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | (5) |\n| | return x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | (3) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (6) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. *x* can be any iterable object.\n\n3. Raises ``ValueError`` when *x* is not found in *s*. When a negative\n index is passed as the second or third parameter to the ``index()``\n method, the sequence length is added, as for slice indices. If it\n is still negative, it is truncated to zero, as for slice indices.\n\n4. When a negative index is passed as the first parameter to the\n ``insert()`` method, the sequence length is added, as for slice\n indices. If it is still negative, it is truncated to zero, as for\n slice indices.\n\n5. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n6. The ``sort()`` and ``reverse()`` methods modify the sequence in\n place for economy of space when sorting or reversing a large\n sequence. To remind you that they operate by side effect, they\n don\'t return the sorted or reversed sequence.\n\n7. The ``sort()`` method takes optional arguments for controlling the\n comparisons. Each must be specified as a keyword argument.\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: ``key=str.lower``. The\n default value is ``None``. Use ``functools.cmp_to_key()`` to\n convert an old-style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n The ``sort()`` method is guaranteed to be stable. A sort is stable\n if it guarantees not to change the relative order of elements that\n compare equal --- this is helpful for sorting in multiple passes\n (for example, sort by department, then by salary grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can detect\n that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n', 'unary': '\nUnary arithmetic and bitwise operations\n***************************************\n\nAll unary arithmetic and bitwise operations have the same priority:\n\n u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n\nThe unary ``-`` (minus) operator yields the negation of its numeric\nargument.\n\nThe unary ``+`` (plus) operator yields its numeric argument unchanged.\n\nThe unary ``~`` (invert) operator yields the bitwise inversion of its\ninteger argument. The bitwise inversion of ``x`` is defined as\n``-(x+1)``. It only applies to integral numbers.\n\nIn all three cases, if the argument does not have the proper type, a\n``TypeError`` exception is raised.\n', 'while': '\nThe ``while`` statement\n***********************\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n', -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 08:49:35 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 08:49:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Bump_to_3=2E3b2=2E?= Message-ID: <3WvDMg6ZYjzPpJ@mail.python.org> http://hg.python.org/cpython/rev/4972a8f1b2aa changeset: 78496:4972a8f1b2aa user: Georg Brandl date: Sat Aug 11 08:49:20 2012 +0200 summary: Bump to 3.3b2. files: Include/patchlevel.h | 4 +- Lib/distutils/__init__.py | 2 +- Lib/idlelib/idlever.py | 2 +- Misc/NEWS | 301 ++++++++++++------------- Misc/RPM/python-3.3.spec | 2 +- README | 2 +- 6 files changed, 155 insertions(+), 158 deletions(-) diff --git a/Include/patchlevel.h b/Include/patchlevel.h --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -20,10 +20,10 @@ #define PY_MINOR_VERSION 3 #define PY_MICRO_VERSION 0 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_BETA -#define PY_RELEASE_SERIAL 1 +#define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.3.0b1" +#define PY_VERSION "3.3.0b2" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Lib/distutils/__init__.py b/Lib/distutils/__init__.py --- a/Lib/distutils/__init__.py +++ b/Lib/distutils/__init__.py @@ -13,5 +13,5 @@ # Updated automatically by the Python release process. # #--start constants-- -__version__ = "3.3.0b1" +__version__ = "3.3.0b2" #--end constants-- diff --git a/Lib/idlelib/idlever.py b/Lib/idlelib/idlever.py --- a/Lib/idlelib/idlever.py +++ b/Lib/idlelib/idlever.py @@ -1,1 +1,1 @@ -IDLE_VERSION = "3.3.0b1" +IDLE_VERSION = "3.3.0b2" diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -5,7 +5,7 @@ What's New in Python 3.3.0 Beta 2? ================================== -*Release date: xx-xxx-2012* +*Release date: 12-Aug-2012* Core and Builtins ----------------- @@ -19,38 +19,38 @@ - Issue #15534: Fix the fast-search function for non-ASCII Unicode strings. - Issue #15508: Fix the docstring for __import__ to have the proper default - value of 0 for 'level' and to not mention negative levels since they are - not supported. + value of 0 for 'level' and to not mention negative levels since they are not + supported. - Issue #15425: Eliminated traceback noise from more situations involving - importlib + importlib. - Issue #14578: Support modules registered in the Windows registry again. -- Issue #15466: Stop using TYPE_INT64 in marshal, to make importlib.h - (and other byte code files) equal between 32-bit and 64-bit systems. - -- Issue #1692335: Move initial args assignment to - BaseException.__new__ to help pickling of naive subclasses. +- Issue #15466: Stop using TYPE_INT64 in marshal, to make importlib.h (and other + byte code files) equal between 32-bit and 64-bit systems. + +- Issue #1692335: Move initial exception args assignment to + "BaseException.__new__" to help pickling of naive subclasses. - Issue #12834: Fix PyBuffer_ToContiguous() for non-contiguous arrays. -- Issue #15456: Fix code __sizeof__ after #12399 change. - Patch by Serhiy Storchaka. +- Issue #15456: Fix code __sizeof__ after #12399 change. Patch by Serhiy + Storchaka. - Issue #15404: Refleak in PyMethodObject repr. -- Issue #15394: An issue in PyModule_Create that caused references to - be leaked on some error paths has been fixed. Patch by Julia Lawall. - -- Issue #15368: An issue that caused bytecode generation to be - non-deterministic has been fixed. - -- Issue #15202: Consistently use the name "follow_symlinks" for - new parameters in os and shutil functions. - -- Issue #15314: __main__.__loader__ is now set correctly during - interpreter startup +- Issue #15394: An issue in PyModule_Create that caused references to be leaked + on some error paths has been fixed. Patch by Julia Lawall. + +- Issue #15368: An issue that caused bytecode generation to be non-deterministic + has been fixed. + +- Issue #15202: Consistently use the name "follow_symlinks" for new parameters + in os and shutil functions. + +- Issue #15314: __main__.__loader__ is now set correctly during interpreter + startup. - Issue #15111: When a module imported using 'from import' has an ImportError inside itself, don't mask that fact behind a generic ImportError for the @@ -61,8 +61,8 @@ - Issue #15291: Fix a memory leak where AST nodes where not properly deallocated. -- Issue #15110: Fix the tracebacks generated by "import xxx" to not show - the importlib stack frames. +- Issue #15110: Fix the tracebacks generated by "import xxx" to not show the + importlib stack frames. - Issue #15020: The program name used to search for Python's path is now "python3" under Unix, not "python". @@ -71,22 +71,22 @@ return the proper failure return value (1). Patch contributed by Jeff Knupp. - Issue #15229: An OSError subclass whose __init__ doesn't call back - OSError.__init__ could produce incomplete instances, leading to crashes - when calling str() on them. - -- Issue 15307: Virtual environments now use symlinks with framework builds - on Mac OS X, like other POSIX builds. + OSError.__init__ could produce incomplete instances, leading to crashes when + calling str() on them. + +- Issue 15307: Virtual environments now use symlinks with framework builds on + Mac OS X, like other POSIX builds. Library ------- -- Issue #15424: Add a __sizeof__ implementation for array objects. - Patch by Ludwig H?hne. +- Issue #15424: Add a __sizeof__ implementation for array objects. Patch by + Ludwig H?hne. - Issue #15576: Allow extension modules to act as a package's __init__ module. -- Issue #15502: Have importlib.invalidate_caches() work on sys.meta_path - instead of sys.path_importer_cache. +- Issue #15502: Have importlib.invalidate_caches() work on sys.meta_path instead + of sys.path_importer_cache. - Issue #15163: Pydoc shouldn't list __loader__ as module data. @@ -104,81 +104,80 @@ ended with '\'. Patch by Roger Serwy. - Issue #12655: Instead of requiring a custom type, os.sched_getaffinity and - os.sched_setaffinity now use regular sets of integers to represent the CPUs - a process is restricted to. - -- Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() - emulation code. Patch by Philipp Hagemeister. - -- Issue #15519: Properly expose WindowsRegistryFinder in importlib (and use - the correct term for it). Original patch by Eric Snow. - -- Issue #15502: Bring the importlib ABCs into line with the current state - of the import protocols given PEP 420. Original patch by Eric Snow. - -- Issue #15499: Launching a webbrowser in Unix used to sleep for a few - seconds. Original patch by Anton Barkovsky. - -- Issue #15463: the faulthandler module truncates strings to 500 characters, - instead of 100, to be able to display long file paths - -- Issue #6056: Make multiprocessing use setblocking(True) on the - sockets it uses. Original patch by J Derek Wilson. - -- Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an - absolute path. - -- Issue #15041: update "see also" list in tkinter documentation. + os.sched_setaffinity now use regular sets of integers to represent the CPUs a + process is restricted to. + +- Issue #15538: Fix compilation of the getnameinfo() / getaddrinfo() emulation + code. Patch by Philipp Hagemeister. + +- Issue #15519: Properly expose WindowsRegistryFinder in importlib (and use the + correct term for it). Original patch by Eric Snow. + +- Issue #15502: Bring the importlib ABCs into line with the current state of the + import protocols given PEP 420. Original patch by Eric Snow. + +- Issue #15499: Launching a webbrowser in Unix used to sleep for a few seconds. + Original patch by Anton Barkovsky. + +- Issue #15463: The faulthandler module truncates strings to 500 characters, + instead of 100, to be able to display long file paths. + +- Issue #6056: Make multiprocessing use setblocking(True) on the sockets it + uses. Original patch by J Derek Wilson. + +- Issue #15364: Fix sysconfig.get_config_var('srcdir') to be an absolute path. + +- Issue #15041: Update "see also" list in tkinter documentation. - Issue #15413: os.times() had disappeared under Windows. - Issue #15402: An issue in the struct module that caused sys.getsizeof to - return incorrect results for struct.Struct instances has been fixed. - Initial patch by Serhiy Storchaka. - -- Issue #15232: when mangle_from is True, email.Generator now correctly mangles + return incorrect results for struct.Struct instances has been fixed. Initial + patch by Serhiy Storchaka. + +- Issue #15232: When mangle_from is True, email.Generator now correctly mangles lines that start with 'From ' that occur in a MIME preamble or epilogue. -- Issue #15094: Incorrectly placed #endif in _tkinter.c. - Patch by Serhiy Storchaka. - -- Issue #13922: argparse no longer incorrectly strips '--'s that appear - after the first one. +- Issue #15094: Incorrectly placed #endif in _tkinter.c. Patch by Serhiy + Storchaka. + +- Issue #13922: argparse no longer incorrectly strips '--'s that appear after + the first one. - Issue #12353: argparse now correctly handles null argument values. -- Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with +- Issue #10017, issue #14998: Fix TypeError using pprint on dictionaries with user-defined types as keys or other unorderable keys. -- Issue #15397: inspect.getmodulename() is now based directly on importlib - via a new importlib.machinery.all_suffixes() API. - -- Issue #14635: telnetlib will use poll() rather than select() when possible - to avoid failing due to the select() file descriptor limit. - -- Issue #15180: Clarify posixpath.join() error message when mixing str & bytes - -- Issue #15343: pkgutil now includes an iter_importer_modules implementation - for importlib.machinery.FileFinder (similar to the way it already handled - zipimport.zipimporter) - -- Issue #15314: runpy now sets __main__.__loader__ correctly - -- Issue #15357: The import emulation in pkgutil is now deprecated. pkgutil - uses importlib internally rather than the emulation - -- Issue #15233: Python now guarantees that callables registered with - the atexit module will be called in a deterministic order. +- Issue #15397: inspect.getmodulename() is now based directly on importlib via a + new importlib.machinery.all_suffixes() API. + +- Issue #14635: telnetlib will use poll() rather than select() when possible to + avoid failing due to the select() file descriptor limit. + +- Issue #15180: Clarify posixpath.join() error message when mixing str & bytes. + +- Issue #15343: pkgutil now includes an iter_importer_modules implementation for + importlib.machinery.FileFinder (similar to the way it already handled + zipimport.zipimporter). + +- Issue #15314: runpy now sets __main__.__loader__ correctly. + +- Issue #15357: The import emulation in pkgutil is now deprecated. pkgutil uses + importlib internally rather than the emulation. + +- Issue #15233: Python now guarantees that callables registered with the atexit + module will be called in a deterministic order. - Issue #15238: shutil.copystat now copies Linux "extended attributes". -- Issue #15230: runpy.run_path now correctly sets __package__ as described - in the documentation +- Issue #15230: runpy.run_path now correctly sets __package__ as described in + the documentation. - Issue #15315: Support VS 2010 in distutils cygwincompiler. -- Issue #15294: Fix a regression in pkgutil.extend_path()'s handling of - nested namespace packages. +- Issue #15294: Fix a regression in pkgutil.extend_path()'s handling of nested + namespace packages. - Issue #15056: imp.cache_from_source() and source_from_cache() raise NotImplementedError when sys.implementation.cache_tag is set to None. @@ -186,62 +185,60 @@ - Issue #15256: Grammatical mistake in exception raised by imp.find_module(). - Issue #5931: wsgiref environ variable SERVER_SOFTWARE will specify an - implementation specific term like Cpython, Jython instead of generic "Python" - -- Issue #13248: Remove obsolete argument "max_buffer_size" of BufferedWriter - and BufferedRWPair, from the io module. + implementation specific term like CPython, Jython instead of generic "Python". + +- Issue #13248: Remove obsolete argument "max_buffer_size" of BufferedWriter and + BufferedRWPair, from the io module. - Issue #13248: Remove obsolete argument "version" of argparse.ArgumentParser. -- Issue #14814: implement more consistent ordering and sorting behaviour - for ipaddress objects - -- Issue #14814: ipaddress network objects correctly return NotImplemented - when compared to arbitrary objects instead of raising TypeError - -- Issue #14990: Correctly fail with SyntaxError on invalid encoding - declaration. +- Issue #14814: Implement more consistent ordering and sorting behaviour for + ipaddress objects. + +- Issue #14814: ipaddress network objects correctly return NotImplemented when + compared to arbitrary objects instead of raising TypeError. + +- Issue #14990: Correctly fail with SyntaxError on invalid encoding declaration. - Issue #14814: ipaddress now provides more informative error messages when constructing instances directly (changes permitted during beta due to - provisional API status) - -- Issue #15247: FileIO now raises an error when given a file descriptor - pointing to a directory. + provisional API status). + +- Issue #15247: FileIO now raises an error when given a file descriptor pointing + to a directory. - Issue #15261: Stop os.stat(fd) crashing on Windows when fd not open. - Issue #15166: Implement imp.get_tag() using sys.implementation.cache_tag. -- Issue #15210: Catch KeyError when imprortlib.__init__ can't find +- Issue #15210: Catch KeyError when importlib.__init__ can't find _frozen_importlib in sys.modules, not ImportError. - Issue #15030: importlib.abc.PyPycLoader now supports the new source size header field in .pyc files. -- Issue #5346: Preserve permissions of mbox, MMDF and Babyl mailbox - files on flush(). - -- Issue #10571: Fix the "--sign" option of distutils' upload command. - Patch by Jakub Wilk. - -- Issue #9559: If messages were only added, a new file is no longer - created and renamed over the old file when flush() is called on an - mbox, MMDF or Babyl mailbox. - -- Issue 10924: Fixed mksalt() to use a RNG that is suitable for cryptographic - purpose. - -- Issue #15184: Ensure consistent results of OS X configuration - tailoring for universal builds by factoring out common OS X-specific - customizations from sysconfig, distutils.sysconfig, distutils.util, - and distutils.unixccompiler into a new module _osx_support. +- Issue #5346: Preserve permissions of mbox, MMDF and Babyl mailbox files on + flush(). + +- Issue #10571: Fix the "--sign" option of distutils' upload command. Patch by + Jakub Wilk. + +- Issue #9559: If messages were only added, a new file is no longer created and + renamed over the old file when flush() is called on an mbox, MMDF or Babyl + mailbox. + +- Issue 10924: Fixed crypt.mksalt() to use a RNG that is suitable for + cryptographic purpose. + +- Issue #15184: Ensure consistent results of OS X configuration tailoring for + universal builds by factoring out common OS X-specific customizations from + sysconfig, distutils.sysconfig, distutils.util, and distutils.unixccompiler + into a new module _osx_support. C API ----- -- Issue #15610: PyImport_ImportModuleEx() now uses a 'level' of 0 instead of - -1. +- Issue #15610: PyImport_ImportModuleEx() now uses a 'level' of 0 instead of -1. - Issues #15169, #14599: Strip out the C implementation of imp.source_from_cache() used by PyImport_ExecCodeModuleWithPathnames() and @@ -260,14 +257,14 @@ Tools/Demos ----------- -- Issue #15458: python-config gets a new option --configdir to print the - $LIBPL value. +- Issue #15458: python-config gets a new option --configdir to print the $LIBPL + value. - Move importlib.test.benchmark to Tools/importbench. -- Issue #12605: The gdb hooks for debugging CPython (within Tools/gdb) have - been enhanced to show information on more C frames relevant to CPython within - the "py-bt" and "py-bt-full" commands: +- Issue #12605: The gdb hooks for debugging CPython (within Tools/gdb) have been + enhanced to show information on more C frames relevant to CPython within the + "py-bt" and "py-bt-full" commands: * C frames that are waiting on the GIL * C frames that are garbage-collecting * C frames that are due to the invocation of a PyCFunction @@ -277,8 +274,8 @@ - Issue #15295: Reorganize and rewrite the documentation on the import system. -- Issue #15230: Clearly document some of the limitations of the runpy - module and nudge readers towards importlib when appropriate. +- Issue #15230: Clearly document some of the limitations of the runpy module and + nudge readers towards importlib when appropriate. - Issue #15053: Copy Python 3.3 import lock change notice to all relevant functions in imp instead of just at the top of the relevant section. @@ -297,11 +294,11 @@ Tests ----- -- Issue #15467: Move helpers for __sizeof__ tests into test_support. - Patch by Serhiy Storchaka. - -- Issue #15320: Make iterating the list of tests thread-safe when running - tests in multiprocess mode. Patch by Chris Jerdonek. +- Issue #15467: Move helpers for __sizeof__ tests into test_support. Patch by + Serhiy Storchaka. + +- Issue #15320: Make iterating the list of tests thread-safe when running tests + in multiprocess mode. Patch by Chris Jerdonek. - Issue #15168: Move importlib.test to test.test_importlib. @@ -317,33 +314,33 @@ - Issue #15284: Skip {send,recv}msg tests in test_socket when IPv6 is not enabled. Patch by Brian Brazil. -- Issue #15277: Fix a resource leak in support.py when IPv6 is disabled. - Patch by Brian Brazil. +- Issue #15277: Fix a resource leak in support.py when IPv6 is disabled. Patch + by Brian Brazil. Build ----- -- Issue #11715: Fix multiarch detection without having Debian development - tools (dpkg-dev) installed. +- Issue #11715: Fix multiarch detection without having Debian development tools + (dpkg-dev) installed. - Issue #15037: Build OS X installers with local copy of ncurses 5.9 libraries to avoid curses.unget_wch bug present in older versions of ncurses such as those shipped with OS X. -- Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. - Also, for OS X installers, ensure consistent sqlite3 behavior and feature - availability by building a local copy of libsqlite3 rather than - depending on the wide range of versions supplied with various OS X releases. +- Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. Also, for + OS X installers, ensure consistent sqlite3 behavior and feature availability + by building a local copy of libsqlite3 rather than depending on the wide range + of versions supplied with various OS X releases. - Issue #8847: Disable COMDAT folding in Windows PGO builds. - Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. -- Issue #15431: Add _freeze_importlib project to regenerate importlib.h - on Windows. Patch by Kristj?n Valur J?nsson. - -- Issue #14197: For OS X framework builds, ensure links to the shared - library are created with the proper ABI suffix. +- Issue #15431: Add _freeze_importlib project to regenerate importlib.h on + Windows. Patch by Kristj?n Valur J?nsson. + +- Issue #14197: For OS X framework builds, ensure links to the shared library + are created with the proper ABI suffix. - Issue #14330: For cross builds, don't use host python, use host search paths for host compiler. diff --git a/Misc/RPM/python-3.3.spec b/Misc/RPM/python-3.3.spec --- a/Misc/RPM/python-3.3.spec +++ b/Misc/RPM/python-3.3.spec @@ -39,7 +39,7 @@ %define name python #--start constants-- -%define version 3.3.0b1 +%define version 3.3.0b2 %define libvers 3.3 #--end constants-- %define release 1pydotorg diff --git a/README b/README --- a/README +++ b/README @@ -1,4 +1,4 @@ -This is Python version 3.3.0 beta 1 +This is Python version 3.3.0 beta 2 =================================== Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 08:53:20 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 08:53:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Added_tag_v3=2E3=2E0b2_for?= =?utf-8?q?_changeset_4972a8f1b2aa?= Message-ID: <3WvDS022jwzNfV@mail.python.org> http://hg.python.org/cpython/rev/ecad81ceea05 changeset: 78497:ecad81ceea05 user: Georg Brandl date: Sat Aug 11 08:53:23 2012 +0200 summary: Added tag v3.3.0b2 for changeset 4972a8f1b2aa files: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -104,3 +104,4 @@ 0b53b70a40a00013505eb35e3660057b62be77be v3.3.0a3 7c51388a3aa7ce76a8541bbbdfc05d2d259a162c v3.3.0a4 e15c554cd43eb23bc0a528a4e8741da9bbec9607 v3.3.0b1 +4972a8f1b2aa3d7cdd64dc96aa7fa112fe1ea343 v3.3.0b2 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 10:59:32 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 10:59:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogQ2xvc2VzICMxNTYy?= =?utf-8?q?0=3A_check_for_presence_of_readline=2Eclear=5Fhistory=28=29=2C_?= =?utf-8?q?which_is?= Message-ID: <3WvHFc4qBLzPjl@mail.python.org> http://hg.python.org/cpython/rev/961a15aff2a6 changeset: 78498:961a15aff2a6 branch: 3.2 parent: 78493:45ef9bc8739f user: Georg Brandl date: Sat Aug 11 10:59:23 2012 +0200 summary: Closes #15620: check for presence of readline.clear_history(), which is apparently missing on some readline versions, before calling it in the test. files: Lib/test/test_readline.py | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -17,7 +17,9 @@ "The history update test cannot be run because the " "clear_history method is not available.") def testHistoryUpdates(self): - readline.clear_history() + # Some GNU versions of readline do not support clear_history + if hasattr('readline', 'clear_history'): + readline.clear_history() readline.add_history("first line") readline.add_history("second line") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 10:59:34 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 10:59:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2Ugd2l0aCAzLjIu?= Message-ID: <3WvHFf5SNvzPp8@mail.python.org> http://hg.python.org/cpython/rev/36563c91e585 changeset: 78499:36563c91e585 parent: 78497:ecad81ceea05 parent: 78498:961a15aff2a6 user: Georg Brandl date: Sat Aug 11 10:59:45 2012 +0200 summary: Merge with 3.2. files: Lib/test/test_readline.py | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -17,7 +17,9 @@ "The history update test cannot be run because the " "clear_history method is not available.") def testHistoryUpdates(self): - readline.clear_history() + # Some GNU versions of readline do not support clear_history + if hasattr('readline', 'clear_history'): + readline.clear_history() readline.add_history("first line") readline.add_history("second line") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 11:02:09 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 11:02:09 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Revert_961a15a?= =?utf-8?q?ff2a6=2C_this_is_already_checked_in_another_way=2E?= Message-ID: <3WvHJd1rXjzPpR@mail.python.org> http://hg.python.org/cpython/rev/e9e9f3e46148 changeset: 78500:e9e9f3e46148 branch: 3.2 parent: 78498:961a15aff2a6 user: Georg Brandl date: Sat Aug 11 11:02:14 2012 +0200 summary: Revert 961a15aff2a6, this is already checked in another way. files: Lib/test/test_readline.py | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -17,9 +17,7 @@ "The history update test cannot be run because the " "clear_history method is not available.") def testHistoryUpdates(self): - # Some GNU versions of readline do not support clear_history - if hasattr('readline', 'clear_history'): - readline.clear_history() + readline.clear_history() readline.add_history("first line") readline.add_history("second line") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 11:02:10 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 11:02:10 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2Ugd2l0aCAzLjIu?= Message-ID: <3WvHJf6y9pzPpR@mail.python.org> http://hg.python.org/cpython/rev/a07d0ff419c2 changeset: 78501:a07d0ff419c2 parent: 78499:36563c91e585 parent: 78500:e9e9f3e46148 user: Georg Brandl date: Sat Aug 11 11:02:23 2012 +0200 summary: Merge with 3.2. files: Lib/test/test_readline.py | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -17,9 +17,7 @@ "The history update test cannot be run because the " "clear_history method is not available.") def testHistoryUpdates(self): - # Some GNU versions of readline do not support clear_history - if hasattr('readline', 'clear_history'): - readline.clear_history() + readline.clear_history() readline.add_history("first line") readline.add_history("second line") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 11:07:52 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 11:07:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDIuNyk6?= =?utf-8?q?_Graft_a89d654adaa2_from_3=2E2_branch=2E_Fixes_=2315620=2E?= Message-ID: <3WvHRD179RzPmZ@mail.python.org> http://hg.python.org/cpython/rev/dda08ec9fbd5 changeset: 78502:dda08ec9fbd5 branch: 2.7 parent: 78492:91382d4e2dfb parent: 68469:a89d654adaa2 user: Georg Brandl date: Sat Aug 11 11:08:04 2012 +0200 summary: Graft a89d654adaa2 from 3.2 branch. Fixes #15620. files: Lib/test/test_readline.py | 4 ++++ Misc/ACKS | 1 + 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -12,6 +12,10 @@ readline = import_module('readline') class TestHistoryManipulation (unittest.TestCase): + + @unittest.skipIf(not hasattr(readline, 'clear_history'), + "The history update test cannot be run because the " + "clear_history method is not available.") def testHistoryUpdates(self): readline.clear_history() diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -74,6 +74,7 @@ Steven Bethard Stephen Bevan Ron Bickers +Natalia B. Bidart David Binger Dominic Binks Philippe Biondi -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 11:12:46 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 11:12:46 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_casing_of_?= =?utf-8?q?SocketServer_module_in_2=2E7=2E?= Message-ID: <3WvHXt2F0hzPn7@mail.python.org> http://hg.python.org/cpython/rev/e06ef4881136 changeset: 78503:e06ef4881136 branch: 2.7 user: Georg Brandl date: Sat Aug 11 11:12:55 2012 +0200 summary: Fix casing of SocketServer module in 2.7. files: Doc/howto/logging-cookbook.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -295,17 +295,17 @@ logger2.warning('Jail zesty vixen who grabbed pay from quack.') logger2.error('The five boxing wizards jump quickly.') -At the receiving end, you can set up a receiver using the :mod:`socketserver` +At the receiving end, you can set up a receiver using the :mod:`SocketServer` module. Here is a basic working example:: import pickle import logging import logging.handlers - import socketserver + import SocketServer import struct - class LogRecordStreamHandler(socketserver.StreamRequestHandler): + class LogRecordStreamHandler(SocketServer.StreamRequestHandler): """Handler for a streaming logging request. This basically logs the record using whatever logging policy is @@ -347,7 +347,7 @@ # cycles and network bandwidth! logger.handle(record) - class LogRecordSocketReceiver(socketserver.ThreadingTCPServer): + class LogRecordSocketReceiver(SocketServer.ThreadingTCPServer): """ Simple TCP socket-based logging receiver suitable for testing. """ @@ -357,7 +357,7 @@ def __init__(self, host='localhost', port=logging.handlers.DEFAULT_TCP_LOGGING_PORT, handler=LogRecordStreamHandler): - socketserver.ThreadingTCPServer.__init__(self, (host, port), handler) + SocketServer.ThreadingTCPServer.__init__(self, (host, port), handler) self.abort = 0 self.timeout = 1 self.logname = None -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 11:16:15 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 11:16:15 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Remove_unused_?= =?utf-8?q?variables_in_parsetok=28=29=2E?= Message-ID: <3WvHcv4Q7bzPnX@mail.python.org> http://hg.python.org/cpython/rev/aeda45d58729 changeset: 78504:aeda45d58729 branch: 3.2 parent: 78500:e9e9f3e46148 user: Georg Brandl date: Sat Aug 11 11:16:18 2012 +0200 summary: Remove unused variables in parsetok(). files: Parser/parsetok.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Parser/parsetok.c b/Parser/parsetok.c --- a/Parser/parsetok.c +++ b/Parser/parsetok.c @@ -127,7 +127,7 @@ { parser_state *ps; node *n; - int started = 0, handling_import = 0, handling_with = 0; + int started = 0; if ((ps = PyParser_New(g, start)) == NULL) { fprintf(stderr, "no mem for new parser\n"); @@ -154,7 +154,6 @@ } if (type == ENDMARKER && started) { type = NEWLINE; /* Add an extra newline */ - handling_with = handling_import = 0; started = 0; /* Add the right number of dedent tokens, except if a certain flag is given -- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 11:16:17 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 11:16:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2Ugd2l0aCAzLjIu?= Message-ID: <3WvHcx1TKzzPrC@mail.python.org> http://hg.python.org/cpython/rev/ecb8b965c93e changeset: 78505:ecb8b965c93e parent: 78501:a07d0ff419c2 parent: 78504:aeda45d58729 user: Georg Brandl date: Sat Aug 11 11:16:26 2012 +0200 summary: Merge with 3.2. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 11:17:34 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 11 Aug 2012 11:17:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Remove_unused_?= =?utf-8?q?variables_in_parsetok=28=29=2E?= Message-ID: <3WvHfQ0Y16zNfV@mail.python.org> http://hg.python.org/cpython/rev/a82fc1f366b4 changeset: 78506:a82fc1f366b4 branch: 2.7 parent: 78503:e06ef4881136 user: Georg Brandl date: Sat Aug 11 11:16:18 2012 +0200 summary: Remove unused variables in parsetok(). files: Parser/parsetok.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/Parser/parsetok.c b/Parser/parsetok.c --- a/Parser/parsetok.c +++ b/Parser/parsetok.c @@ -131,7 +131,7 @@ { parser_state *ps; node *n; - int started = 0, handling_import = 0, handling_with = 0; + int started = 0; if ((ps = PyParser_New(g, start)) == NULL) { fprintf(stderr, "no mem for new parser\n"); @@ -163,7 +163,6 @@ } if (type == ENDMARKER && started) { type = NEWLINE; /* Add an extra newline */ - handling_with = handling_import = 0; started = 0; /* Add the right number of dedent tokens, except if a certain flag is given -- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 15:53:54 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 11 Aug 2012 15:53:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_Daniel_Holth=27s_binary_c?= =?utf-8?q?ompatibility_tag_PEP?= Message-ID: <3WvPnG2tSdzPqk@mail.python.org> http://hg.python.org/peps/rev/2a7dc13e5c62 changeset: 4498:2a7dc13e5c62 user: Nick Coghlan date: Sat Aug 11 23:53:43 2012 +1000 summary: Add Daniel Holth's binary compatibility tag PEP files: pep-0425.txt | 240 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 240 insertions(+), 0 deletions(-) diff --git a/pep-0425.txt b/pep-0425.txt new file mode 100644 --- /dev/null +++ b/pep-0425.txt @@ -0,0 +1,240 @@ +PEP: 425 +Title: Compatibility Tags for Built Distributions +Version: $Revision$ +Last-Modified: 07-Aug-2012 +Author: Daniel Holth +Status: Draft +Type: Standards Track +Content-Type: text/x-rst +Created: 27-Jul-2012 +Python-Version: 3.4 +Post-History: 8-Aug-2012 + + +Abstract +======== + +This PEP specifies a tagging system to indicate with which versions of +Python a built or binary distribution is compatible. A set of three +tags indicate which Python implementation and language version, ABI, +and platform a built distribution requires. The tags are terse because +they will be included in filenames. + + +PEP Editor's Note +================= + +While the naming scheme described in this PEP will not be supported directly +in the standard library until Python 3.4 at the earliest, draft +implementations may be made available in third party projects. + + +Rationale +========= + +Today "python setup.py bdist" generates the same filename on PyPy +and CPython, but an incompatible archive, making it inconvenient to +share built distributions in the same folder or index. Instead, built +distributions should have a file naming convention that includes enough +information to decide whether or not a particular archive is compatible +with a particular implementation. + +Previous efforts come from a time where CPython was the only important +implementation and the ABI was the same as the Python language release. +This specification improves upon the older schemes by including the Python +implementation, language version, ABI, and platform as a set of tags. + +By comparing the tags it supports with the tags listed by the +distribution, an installer can make an educated decision about whether +to download a particular built distribution without having to read its +full metadata. + +Overview +======== + +The tag format is {python tag}-{abi tag}-{platform tag} + +python tag + ?py27?, ?cp33? +abi tag + ?cp33dmu?, ?none? +platform tag + ?linux_x86_64?, ?any? + +For example, the tag py27-none-any indicates compatible with Python 2.7 +(any Python 2.7 implementation) with no abi requirement, on any platform. + +Details +======= + +Python Tag +---------- + +The Python tag indicates both the implementation and the language version +required by a distribution. Major implementations have abbreviated +codes, initially: + +* py: Generic Python (does not require implementation-specific features) +* cp: CPython +* ip: IronPython +* pp: PyPy +* jy: Jython + +Other Python implementations should use `sys.implementation.name`. + +The language version is `py_version_nodot`, or just the major version +`2` or `3` for many pure-Python distributions. CPython gets away with +no dot, but if one is needed the underscore `_` is used instead. + +A single-source Python 2/3 compatible distribution can use the compound +tag `py2.py3`. See `Compressed Tag Sets`, below. + +ABI Tag +------- + +The ABI tag indicates which Python ABI is required by any included +extension modules. For implementation-specific ABIs, the implementation +is abbreviated in the same way as the Python Tag, e.g. `cp33d` would be +the CPython 3.3 ABI with debugging. + +As a special case, the CPython stable ABI starts with `py`; `py32` +is that ABI with only the operations available from Python 3.2 onward. + +Implementations with a very unstable ABI may use the first 6 bytes (as +8 base64-encoded characters) of the SHA-256 hash of ther source code +revision and compiler flags, etc, but will probably not have a great need +to distribute binary distributions. Each implementation's community may +decide how to best use the ABI tag. + +Platform Tag +------------ + +The platform tag is simply `distutils.util.get_platform()` with all +hyphens `-` and periods `.` replaced with underscore `_`. + +Use +=== + +The tags are used by installers to decide which built distribution +(if any) to download from a list of potential built distributions. +Installers will have a list of (python, abi, plat) that the current +Python installation can run sorted by order of preference. Each built +distribution recieves a score based on its tag's position in the list, +and the most-preferred distribution is the one that is installed. +If no built distribution matches the list of supported tag tuples then +the installer falls back to installing from the source distribution. +Tags are only compared for equality; they are never greater or less than +another tag, and a tag that 'startswith' another tag is not a subset of +the shorter tag. + +For example, an installer running under CPython 3.3 on an imaginary MMIX +system might prefer, in order:: + + 1. (cp33, cp33, mmix) # built for this specific version of Python + 2. (cp33, py32, mmix) # using the stable ABI as defined by Python 3.2 + 3. (cp33, none, mmix) # using no ABI, but still depending on the specific + platform (e.g. through ctypes or os.system) + 4. (cp33, none, any) # pure-Python distribution for the current Python + 5. (py33, none, any) # pure-Python distribution for the current (generic) + Python + 6. (py32, none, any) # pure-Python distributions for older versions of + Python + 7. (py31, none, any) # "" + 8. (py30, none, any) # "" + 9. (py3, none, any) # "" + +A distribution that requires CPython 3.3 or CPython 2.7 and has an +optional extension module could distribute built distributions tagged +`cp33-cp3-mmix`, `cp33-none-any`, and `cp27-none-any`. (Our imaginary +program is using 2to3, so the built distribution is not compatible across +major releases.) `cp33-cp3-mmix` gets a score of 1, `cp33-none-any` +gets a score of 3, and `cp27-none-any` is not in the list at all. Since +`cp33-cp3-mmix` has the best score, that built distribution is installed. + +A user could instruct their installer to fall back to building from an +sdist more or less often by configuring this list of tags. + +Compressed Tag Sets +=================== + +To allow for compact filenames of bdists that work with more than +one compatibility tag triple, each tag in a filename can instead be a +'.'-separated, sorted, set of tags. For example, pip, a pure-Python +package that is written to run under Python 2 and 3 with the same source +code, could distribute a bdist with the tag `py2.py3-none-any`. +The full list of simple tags is:: + + for x in pytag.split('.'): + for y in abitag.split('.'): + for z in archtag.split('.'): + yield '-'.join((x, y, z)) + +A bdist format that implements this scheme should include the expanded +tags in bdist-specific metadata. This compression scheme can generate +large numbers of unsupported tags and "impossible" tags that are supported +by no Python implementation e.g. "cp33-cp31u-win64", so use it sparingly. + +FAQ +=== + +Can I have a tag `py32+` to indicate a minimum Python minor release? + No. Inspect the Trove classifiers to determine this level of + cross-release compatibility. Similar to the announcements "beaglevote + versions 3.2 and above no longer supports Python 1.52", you will + have to manually keep track of the maximum (PEP-386) release that + still supports your version of Python. + +Why isn't there a `.` in the Python version number? + CPython has lasted 20+ years without a 3-digit major release. This + should continue for some time. Other implementations may use _ as + a delimeter, since both - and . delimit the surrounding filename. + +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. + +Does the compatibility tag go into METADATA or PKG-INFO? + No. The compatibility tag is part of the built distribution's + metadata. METADATA / PKG-INFO should be valid for an entire + distribution, not a single build of that distribution. + +Why didn't you mention my favorite Python implementation? + The abbreviated tags facilitate sharing compiled Python code in a + public index. Your Python implementation can use this specification + too, but with longer tags. + Recall that all "pure Python" built distributions just use 'py'. + +References +========== + +.. [1] Egg Filename-Embedded Metadata + (http://peak.telecommunity.com/DevCenter/EggFormats#filename-embedded-metadata) + +.. [2] Creating Built Distributions + (http://docs.python.org/distutils/builtdist.html) + +.. [3] PEP 3147 -- PYC Repository Directories + (http://www.python.org/dev/peps/pep-3147/) + +Acknowledgements +================ + +The author thanks Paul Moore, Nick Coughlan, Mark Abramowitz, and +Mr. Michele Lacchia for their valuable advice and help with this effort. + +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 Sat Aug 11 15:58:12 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 11 Aug 2012 15:58:12 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?peps=3A_Fix_typo?= Message-ID: <3WvPtD5LmYzPkC@mail.python.org> http://hg.python.org/peps/rev/ad5b90e74018 changeset: 4499:ad5b90e74018 user: Nick Coghlan date: Sat Aug 11 23:58:03 2012 +1000 summary: Fix typo files: pep-0425.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-0425.txt b/pep-0425.txt --- a/pep-0425.txt +++ b/pep-0425.txt @@ -220,7 +220,7 @@ Acknowledgements ================ -The author thanks Paul Moore, Nick Coughlan, Mark Abramowitz, and +The author thanks Paul Moore, Nick Coghlan, Mark Abramowitz, and Mr. Michele Lacchia for their valuable advice and help with this effort. Copyright -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Sat Aug 11 16:57:20 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 11 Aug 2012 16:57:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NDQ0?= =?utf-8?q?=3A_Use_proper_spelling_for_non-ASCII_contributor_names=2E?= Message-ID: <3WvRBS5MsqzPqx@mail.python.org> http://hg.python.org/cpython/rev/3654c711019a changeset: 78507:3654c711019a branch: 3.2 parent: 78504:aeda45d58729 user: Antoine Pitrou date: Sat Aug 11 16:51:50 2012 +0200 summary: Issue #15444: Use proper spelling for non-ASCII contributor names. Patch by Serhiy Storchaka. files: Doc/c-api/unicode.rst | 2 +- Doc/library/codecs.rst | 4 ++-- Doc/library/platform.rst | 2 +- Doc/library/unicodedata.rst | 4 ++-- Doc/tutorial/introduction.rst | 2 +- Doc/whatsnew/2.4.rst | 2 +- Doc/whatsnew/2.6.rst | 16 ++++++++-------- Doc/whatsnew/2.7.rst | 4 ++-- Misc/ACKS | 2 +- Misc/HISTORY | 4 ++-- Misc/NEWS | 3 +++ 11 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -5,7 +5,7 @@ Unicode Objects and Codecs -------------------------- -.. sectionauthor:: Marc-Andre Lemburg +.. sectionauthor:: Marc-Andr? Lemburg Unicode Objects ^^^^^^^^^^^^^^^ diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst --- a/Doc/library/codecs.rst +++ b/Doc/library/codecs.rst @@ -3,8 +3,8 @@ .. module:: codecs :synopsis: Encode and decode data and streams. -.. moduleauthor:: Marc-Andre Lemburg -.. sectionauthor:: Marc-Andre Lemburg +.. moduleauthor:: Marc-Andr? Lemburg +.. sectionauthor:: Marc-Andr? Lemburg .. sectionauthor:: Martin v. L?wis diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -3,7 +3,7 @@ .. module:: platform :synopsis: Retrieves as much platform identifying data as possible. -.. moduleauthor:: Marc-Andre Lemburg +.. moduleauthor:: Marc-Andr? Lemburg .. sectionauthor:: Bjorn Pettersen **Source code:** :source:`Lib/platform.py` diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst --- a/Doc/library/unicodedata.rst +++ b/Doc/library/unicodedata.rst @@ -3,8 +3,8 @@ .. module:: unicodedata :synopsis: Access the Unicode Database. -.. moduleauthor:: Marc-Andre Lemburg -.. sectionauthor:: Marc-Andre Lemburg +.. moduleauthor:: Marc-Andr? Lemburg +.. sectionauthor:: Marc-Andr? Lemburg .. sectionauthor:: Martin v. L?wis diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -413,7 +413,7 @@ About Unicode ------------- -.. sectionauthor:: Marc-Andre Lemburg +.. sectionauthor:: Marc-Andr? Lemburg Starting with Python 3.0 all strings support Unicode (see diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1279,7 +1279,7 @@ interface, accessed only by :mod:`atexit`. * The :mod:`tarfile` module now generates GNU-format tar files by default. - (Contributed by Lars Gustaebel.) + (Contributed by Lars Gust?bel.) * The :mod:`threading` module now has an elegantly simple way to support thread-local data. The module contains a :class:`local` class whose attribute diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -175,7 +175,7 @@ Hosting of the Python bug tracker is kindly provided by `Upfront Systems `__ -of Stellenbosch, South Africa. Martin von Loewis put a +of Stellenbosch, South Africa. Martin von L?wis put a lot of effort into importing existing bugs and patches from SourceForge; his scripts for this import operation are at http://svn.python.org/view/tracker/importer/ and may be useful to @@ -193,7 +193,7 @@ Roundup downloads and documentation. http://svn.python.org/view/tracker/importer/ - Martin von Loewis's conversion scripts. + Martin von L?wis's conversion scripts. New Documentation Format: reStructuredText Using Sphinx ----------------------------------------------------------- @@ -1100,7 +1100,7 @@ :pep:`3116` - New I/O PEP written by Daniel Stutzbach, Mike Verdone, and Guido van Rossum. Code by Guido van Rossum, Georg Brandl, Walter Doerwald, - Jeremy Hylton, Martin von Loewis, Tony Lownds, and others. + Jeremy Hylton, Martin von L?wis, Tony Lownds, and others. .. ====================================================================== @@ -1774,7 +1774,7 @@ ``latin-1``; the optional *errorhandler* part specifies what to do with characters that can't be handled by the encoding, and should be one of "error", "ignore", or "replace". (Contributed -by Martin von Loewis.) +by Martin von L?wis.) .. ====================================================================== @@ -1792,7 +1792,7 @@ were applied. (Maintained by Josiah Carlson; see :issue:`1736190` for one patch.) -* The :mod:`bsddb` module also has a new maintainer, Jes?s Cea Avion, and the package +* The :mod:`bsddb` module also has a new maintainer, Jes?s Cea Avi?n, and the package is now available as a standalone package. The web page for the package is `www.jcea.es/programacion/pybsddb.htm `__. @@ -2384,7 +2384,7 @@ (Contributed by Pedro Werneck and Jeffrey Yasskin; :issue:`742598`, :issue:`1193577`.) -* The :mod:`sqlite3` module, maintained by Gerhard Haering, +* The :mod:`sqlite3` module, maintained by Gerhard H?ring, has been updated from version 2.3.2 in Python 2.5 to version 2.4.1. @@ -2597,7 +2597,7 @@ * The Unicode database provided by the :mod:`unicodedata` module has been updated to version 5.1.0. (Updated by - Martin von Loewis; :issue:`3811`.) + Martin von L?wis; :issue:`3811`.) * The :mod:`warnings` module's :func:`formatwarning` and :func:`showwarning` gained an optional *line* argument that can be used to supply the @@ -3104,7 +3104,7 @@ :file:`PCbuild` directory supports cross compilation for X64, debug builds and Profile Guided Optimization (PGO). PGO builds are roughly 10% faster than normal builds. (Contributed by Christian Heimes - with help from Amaury Forgeot d'Arc and Martin von Loewis.) + with help from Amaury Forgeot d'Arc and Martin von L?wis.) * The :mod:`msvcrt` module now supports both the normal and wide char variants of the console I/O diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1434,7 +1434,7 @@ * The :mod:`signal` module no longer re-installs the signal handler unless this is truly necessary, which fixes a bug that could make it impossible to catch the EINTR signal robustly. (Fixed by - Charles-Francois Natali; :issue:`8354`.) + Charles-Fran?ois Natali; :issue:`8354`.) * New functions: in the :mod:`site` module, three new functions return various site- and user-specific paths. @@ -2331,7 +2331,7 @@ attributes of the resulting code objects are overwritten when the original filename is obsolete. This can happen if the file has been renamed, moved, or is accessed through different paths. (Patch by - Ziga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.) + ?iga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.) * The :file:`regrtest.py` script now takes a :option:`--randseed=` switch that takes an integer that will be used as the random seed diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -855,7 +855,7 @@ Steven Scott Barry Scott Nick Seidenman -?iga Seilnach +?iga Seilnacht Yury Selivanov Fred Sells Jiwon Seo diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -2676,7 +2676,7 @@ subclasses of str always behaved. int/long/float, conversion of an instance to the base class has been moved to the proper nb_* magic slot and out of PyNumber_*(). - Thanks Walter D?rwald. + Thanks Walter D?rwald. - Descriptors defined in C with a PyGetSetDef structure, where the setter is NULL, now raise an AttributeError when attempting to set or delete the @@ -13998,7 +13998,7 @@ required for asynchronous connects simpler and more efficient. - New "locale" module with (still experimental) interface to the -standard C library locale interface, courtesy Martin von Loewis. This +standard C library locale interface, courtesy Martin von L?wis. This does not repeat my mistake in 1.5a4 of always calling setlocale(LC_ALL, ""). In fact, we've pretty much decided that Python's standard numerical formatting operations should always use diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -468,6 +468,9 @@ Documentation ------------- +- Issue #15444: Use proper spelling for non-ASCII contributor names. Patch + by Serhiy Storchaka. + - Issue 15482: Properly document the default 'level' value for __import__() while warning about using negative values. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 16:57:22 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 11 Aug 2012 16:57:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315444=3A_Use_proper_spelling_for_non-ASCII_cont?= =?utf-8?q?ributor_names=2E?= Message-ID: <3WvRBV5wzNzPrT@mail.python.org> http://hg.python.org/cpython/rev/867de88b69f0 changeset: 78508:867de88b69f0 parent: 78505:ecb8b965c93e parent: 78507:3654c711019a user: Antoine Pitrou date: Sat Aug 11 16:54:27 2012 +0200 summary: Issue #15444: Use proper spelling for non-ASCII contributor names. Patch by Serhiy Storchaka. files: Doc/c-api/unicode.rst | 2 +- Doc/library/codecs.rst | 4 ++-- Doc/library/platform.rst | 2 +- Doc/library/unicodedata.rst | 4 ++-- Doc/tutorial/introduction.rst | 2 +- Doc/whatsnew/2.4.rst | 2 +- Doc/whatsnew/2.6.rst | 16 ++++++++-------- Doc/whatsnew/2.7.rst | 4 ++-- Misc/ACKS | 2 +- Misc/HISTORY | 4 ++-- Misc/NEWS | 3 +++ 11 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -5,7 +5,7 @@ Unicode Objects and Codecs -------------------------- -.. sectionauthor:: Marc-Andre Lemburg +.. sectionauthor:: Marc-Andr? Lemburg .. sectionauthor:: Georg Brandl Unicode Objects diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst --- a/Doc/library/codecs.rst +++ b/Doc/library/codecs.rst @@ -3,8 +3,8 @@ .. module:: codecs :synopsis: Encode and decode data and streams. -.. moduleauthor:: Marc-Andre Lemburg -.. sectionauthor:: Marc-Andre Lemburg +.. moduleauthor:: Marc-Andr? Lemburg +.. sectionauthor:: Marc-Andr? Lemburg .. sectionauthor:: Martin v. L?wis diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -3,7 +3,7 @@ .. module:: platform :synopsis: Retrieves as much platform identifying data as possible. -.. moduleauthor:: Marc-Andre Lemburg +.. moduleauthor:: Marc-Andr? Lemburg .. sectionauthor:: Bjorn Pettersen **Source code:** :source:`Lib/platform.py` diff --git a/Doc/library/unicodedata.rst b/Doc/library/unicodedata.rst --- a/Doc/library/unicodedata.rst +++ b/Doc/library/unicodedata.rst @@ -3,8 +3,8 @@ .. module:: unicodedata :synopsis: Access the Unicode Database. -.. moduleauthor:: Marc-Andre Lemburg -.. sectionauthor:: Marc-Andre Lemburg +.. moduleauthor:: Marc-Andr? Lemburg +.. sectionauthor:: Marc-Andr? Lemburg .. sectionauthor:: Martin v. L?wis diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -413,7 +413,7 @@ About Unicode ------------- -.. sectionauthor:: Marc-Andre Lemburg +.. sectionauthor:: Marc-Andr? Lemburg Starting with Python 3.0 all strings support Unicode (see diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1279,7 +1279,7 @@ interface, accessed only by :mod:`atexit`. * The :mod:`tarfile` module now generates GNU-format tar files by default. - (Contributed by Lars Gustaebel.) + (Contributed by Lars Gust?bel.) * The :mod:`threading` module now has an elegantly simple way to support thread-local data. The module contains a :class:`local` class whose attribute diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -175,7 +175,7 @@ Hosting of the Python bug tracker is kindly provided by `Upfront Systems `__ -of Stellenbosch, South Africa. Martin von Loewis put a +of Stellenbosch, South Africa. Martin von L?wis put a lot of effort into importing existing bugs and patches from SourceForge; his scripts for this import operation are at http://svn.python.org/view/tracker/importer/ and may be useful to @@ -193,7 +193,7 @@ Roundup downloads and documentation. http://svn.python.org/view/tracker/importer/ - Martin von Loewis's conversion scripts. + Martin von L?wis's conversion scripts. New Documentation Format: reStructuredText Using Sphinx ----------------------------------------------------------- @@ -1100,7 +1100,7 @@ :pep:`3116` - New I/O PEP written by Daniel Stutzbach, Mike Verdone, and Guido van Rossum. Code by Guido van Rossum, Georg Brandl, Walter Doerwald, - Jeremy Hylton, Martin von Loewis, Tony Lownds, and others. + Jeremy Hylton, Martin von L?wis, Tony Lownds, and others. .. ====================================================================== @@ -1774,7 +1774,7 @@ ``latin-1``; the optional *errorhandler* part specifies what to do with characters that can't be handled by the encoding, and should be one of "error", "ignore", or "replace". (Contributed -by Martin von Loewis.) +by Martin von L?wis.) .. ====================================================================== @@ -1792,7 +1792,7 @@ were applied. (Maintained by Josiah Carlson; see :issue:`1736190` for one patch.) -* The :mod:`bsddb` module also has a new maintainer, Jes?s Cea Avion, and the package +* The :mod:`bsddb` module also has a new maintainer, Jes?s Cea Avi?n, and the package is now available as a standalone package. The web page for the package is `www.jcea.es/programacion/pybsddb.htm `__. @@ -2384,7 +2384,7 @@ (Contributed by Pedro Werneck and Jeffrey Yasskin; :issue:`742598`, :issue:`1193577`.) -* The :mod:`sqlite3` module, maintained by Gerhard Haering, +* The :mod:`sqlite3` module, maintained by Gerhard H?ring, has been updated from version 2.3.2 in Python 2.5 to version 2.4.1. @@ -2597,7 +2597,7 @@ * The Unicode database provided by the :mod:`unicodedata` module has been updated to version 5.1.0. (Updated by - Martin von Loewis; :issue:`3811`.) + Martin von L?wis; :issue:`3811`.) * The :mod:`warnings` module's :func:`formatwarning` and :func:`showwarning` gained an optional *line* argument that can be used to supply the @@ -3104,7 +3104,7 @@ :file:`PCbuild` directory supports cross compilation for X64, debug builds and Profile Guided Optimization (PGO). PGO builds are roughly 10% faster than normal builds. (Contributed by Christian Heimes - with help from Amaury Forgeot d'Arc and Martin von Loewis.) + with help from Amaury Forgeot d'Arc and Martin von L?wis.) * The :mod:`msvcrt` module now supports both the normal and wide char variants of the console I/O diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -1434,7 +1434,7 @@ * The :mod:`signal` module no longer re-installs the signal handler unless this is truly necessary, which fixes a bug that could make it impossible to catch the EINTR signal robustly. (Fixed by - Charles-Francois Natali; :issue:`8354`.) + Charles-Fran?ois Natali; :issue:`8354`.) * New functions: in the :mod:`site` module, three new functions return various site- and user-specific paths. @@ -2331,7 +2331,7 @@ attributes of the resulting code objects are overwritten when the original filename is obsolete. This can happen if the file has been renamed, moved, or is accessed through different paths. (Patch by - Ziga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.) + ?iga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.) * The :file:`regrtest.py` script now takes a :option:`--randseed=` switch that takes an integer that will be used as the random seed diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -952,7 +952,7 @@ Barry Scott Steven Scott Nick Seidenman -?iga Seilnach +?iga Seilnacht Yury Selivanov Fred Sells Jiwon Seo diff --git a/Misc/HISTORY b/Misc/HISTORY --- a/Misc/HISTORY +++ b/Misc/HISTORY @@ -2676,7 +2676,7 @@ subclasses of str always behaved. int/long/float, conversion of an instance to the base class has been moved to the proper nb_* magic slot and out of PyNumber_*(). - Thanks Walter D?rwald. + Thanks Walter D?rwald. - Descriptors defined in C with a PyGetSetDef structure, where the setter is NULL, now raise an AttributeError when attempting to set or delete the @@ -13998,7 +13998,7 @@ required for asynchronous connects simpler and more efficient. - New "locale" module with (still experimental) interface to the -standard C library locale interface, courtesy Martin von Loewis. This +standard C library locale interface, courtesy Martin von L?wis. This does not repeat my mistake in 1.5a4 of always calling setlocale(LC_ALL, ""). In fact, we've pretty much decided that Python's standard numerical formatting operations should always use diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -272,6 +272,9 @@ Documentation ------------- +- Issue #15444: Use proper spelling for non-ASCII contributor names. Patch + by Serhiy Storchaka. + - Issue #15295: Reorganize and rewrite the documentation on the import system. - Issue #15230: Clearly document some of the limitations of the runpy module and -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 11 20:15:14 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 11 Aug 2012 20:15:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315527=3A_fix_docs?= =?utf-8?q?=2C_remove_double_parens_by_changing_markup=2E?= Message-ID: <3WvWZp1RFGzPhs@mail.python.org> http://hg.python.org/cpython/rev/5e025dc7d728 changeset: 78509:5e025dc7d728 user: Andrew Svetlov date: Sat Aug 11 21:14:08 2012 +0300 summary: Issue #15527: fix docs, remove double parens by changing markup. Patch by Serhiy Storchaka. files: Doc/library/os.rst | 2 +- Doc/library/platform.rst | 4 +- Doc/whatsnew/2.0.rst | 10 ++-- Doc/whatsnew/2.1.rst | 8 +- Doc/whatsnew/2.2.rst | 22 +++++----- Doc/whatsnew/2.3.rst | 40 +++++++++--------- Doc/whatsnew/2.4.rst | 44 ++++++++++---------- Doc/whatsnew/2.5.rst | 60 ++++++++++++++-------------- Doc/whatsnew/3.0.rst | 2 +- 9 files changed, 96 insertions(+), 96 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -450,7 +450,7 @@ .. function:: setpgrp() - Call the system call :c:func:`setpgrp` or :c:func:`setpgrp(0, 0)` depending on + Call the system call :c:func:`setpgrp` or ``setpgrp(0, 0)`` depending on which version is implemented (if any). See the Unix manual for the semantics. Availability: Unix. diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -30,8 +30,8 @@ returned as strings. Values that cannot be determined are returned as given by the parameter presets. - If bits is given as ``''``, the :c:func:`sizeof(pointer)` (or - :c:func:`sizeof(long)` on Python version < 1.5.2) is used as indicator for the + If bits is given as ``''``, the ``sizeof(pointer)`` (or + ``sizeof(long)`` on Python version < 1.5.2) is used as indicator for the supported pointer size. The function relies on the system's :file:`file` command to do the actual work. diff --git a/Doc/whatsnew/2.0.rst b/Doc/whatsnew/2.0.rst --- a/Doc/whatsnew/2.0.rst +++ b/Doc/whatsnew/2.0.rst @@ -166,7 +166,7 @@ registering new encodings that are then available throughout a Python program. If an encoding isn't specified, the default encoding is usually 7-bit ASCII, though it can be changed for your Python installation by calling the -:func:`sys.setdefaultencoding(encoding)` function in a customised version of +``sys.setdefaultencoding(encoding)`` function in a customised version of :file:`site.py`. Combining 8-bit and Unicode strings always coerces to Unicode, using the default @@ -203,7 +203,7 @@ The :mod:`codecs` module contains functions to look up existing encodings and register new ones. Unless you want to implement a new encoding, you'll most -often use the :func:`codecs.lookup(encoding)` function, which returns a +often use the ``codecs.lookup(encoding)`` function, which returns a 4-element tuple: ``(encode_func, decode_func, stream_reader, stream_writer)``. * *encode_func* is a function that takes a Unicode string, and returns a 2-tuple @@ -600,7 +600,7 @@ Changes to Built-in Functions ----------------------------- -A new built-in, :func:`zip(seq1, seq2, ...)`, has been added. :func:`zip` +A new built-in, ``zip(seq1, seq2, ...)``, has been added. :func:`zip` returns a list of tuples where each tuple contains the i-th element from each of the argument sequences. The difference between :func:`zip` and ``map(None, seq1, seq2)`` is that :func:`map` pads the sequences with ``None`` if the @@ -619,7 +619,7 @@ would be ``(2, 0, 1, 'beta', 1)``. *level* is a string such as ``"alpha"``, ``"beta"``, or ``"final"`` for a final release. -Dictionaries have an odd new method, :meth:`setdefault(key, default)`, which +Dictionaries have an odd new method, ``setdefault(key, default)``, which behaves similarly to the existing :meth:`get` method. However, if the key is missing, :meth:`setdefault` both returns the value of *default* as :meth:`get` would do, and also inserts it into the dictionary as the value for *key*. Thus, @@ -1038,7 +1038,7 @@ is an implementation of the Secure Socket Layer, which encrypts the data being sent over a socket. When compiling Python, you can edit :file:`Modules/Setup` to include SSL support, which adds an additional function to the :mod:`socket` -module: :func:`socket.ssl(socket, keyfile, certfile)`, which takes a socket +module: ``socket.ssl(socket, keyfile, certfile)``, which takes a socket object and returns an SSL socket. The :mod:`httplib` and :mod:`urllib` modules were also changed to support ``https://`` URLs, though no one has implemented FTP or SMTP over SSL. diff --git a/Doc/whatsnew/2.1.rst b/Doc/whatsnew/2.1.rst --- a/Doc/whatsnew/2.1.rst +++ b/Doc/whatsnew/2.1.rst @@ -204,7 +204,7 @@ list, or any other Python object. Alternatively they can raise an exception if the comparison is impossible, inconsistent, or otherwise meaningless. -The built-in :func:`cmp(A,B)` function can use the rich comparison machinery, +The built-in ``cmp(A,B)`` function can use the rich comparison machinery, and now accepts an optional argument specifying which comparison operation to use; this is given as one of the strings ``"<"``, ``"<="``, ``">"``, ``">="``, ``"=="``, or ``"!="``. If called without the optional third argument, @@ -350,7 +350,7 @@ and another being circular references in data structures such as trees. For example, consider a memoizing function that caches the results of another -function :func:`f(x)` by storing the function's argument and its result in a +function ``f(x)`` by storing the function's argument and its result in a dictionary:: _cache = {} @@ -656,7 +656,7 @@ use :mod:`ftplib` to retrieve files and then don't work from behind a firewall. It's deemed unlikely that this will cause problems for anyone, because Netscape defaults to passive mode and few people complain, but if passive mode is - unsuitable for your application or network setup, call :meth:`set_pasv(0)` on + unsuitable for your application or network setup, call ``set_pasv(0)`` on FTP objects to disable passive mode. * Support for raw socket access has been added to the :mod:`socket` module, @@ -666,7 +666,7 @@ for displaying timing profiles for Python programs, invoked when the module is run as a script. Contributed by Eric S. Raymond. -* A new implementation-dependent function, :func:`sys._getframe([depth])`, has +* A new implementation-dependent function, ``sys._getframe([depth])``, has been added to return a given frame object from the current call stack. :func:`sys._getframe` returns the frame at the top of the call stack; if the optional integer argument *depth* is supplied, the function returns the frame diff --git a/Doc/whatsnew/2.2.rst b/Doc/whatsnew/2.2.rst --- a/Doc/whatsnew/2.2.rst +++ b/Doc/whatsnew/2.2.rst @@ -173,12 +173,12 @@ * :attr:`__doc__` is the attribute's docstring. -* :meth:`__get__(object)` is a method that retrieves the attribute value from +* ``__get__(object)`` is a method that retrieves the attribute value from *object*. -* :meth:`__set__(object, value)` sets the attribute on *object* to *value*. +* ``__set__(object, value)`` sets the attribute on *object* to *value*. -* :meth:`__delete__(object, value)` deletes the *value* attribute of *object*. +* ``__delete__(object, value)`` deletes the *value* attribute of *object*. For example, when you write ``obj.x``, the steps that Python actually performs are:: @@ -288,7 +288,7 @@ which is the behaviour we're after. This lookup rule is the same as the one followed by Common Lisp. A new built-in function, :func:`super`, provides a way to get at a class's superclasses without having to reimplement Python's -algorithm. The most commonly used form will be :func:`super(class, obj)`, which +algorithm. The most commonly used form will be ``super(class, obj)``, which returns a bound superclass object (not the actual class object). This form will be used in methods to call a method in the superclass; for example, :class:`D`'s :meth:`save` method would look like this:: @@ -301,7 +301,7 @@ ... :func:`super` can also return unbound superclass objects when called as -:func:`super(class)` or :func:`super(class1, class2)`, but this probably won't +``super(class)`` or ``super(class1, class2)``, but this probably won't often be useful. @@ -314,13 +314,13 @@ ``obj.parent`` into a method call such as ``obj.get_parent``. Python 2.2 adds some new ways of controlling attribute access. -First, :meth:`__getattr__(attr_name)` is still supported by new-style classes, +First, ``__getattr__(attr_name)`` is still supported by new-style classes, and nothing about it has changed. As before, it will be called when an attempt is made to access ``obj.foo`` and no attribute named ``foo`` is found in the instance's dictionary. New-style classes also support a new method, -:meth:`__getattribute__(attr_name)`. The difference between the two methods is +``__getattribute__(attr_name)``. The difference between the two methods is that :meth:`__getattribute__` is *always* called whenever any attribute is accessed, while the old :meth:`__getattr__` is only called if ``foo`` isn't found in the instance's dictionary. @@ -441,8 +441,8 @@ In Python 2.2, iteration can be implemented separately, and :meth:`__getitem__` methods can be limited to classes that really do support random access. The -basic idea of iterators is simple. A new built-in function, :func:`iter(obj)` -or ``iter(C, sentinel)``, is used to get an iterator. :func:`iter(obj)` returns +basic idea of iterators is simple. A new built-in function, ``iter(obj)`` +or ``iter(C, sentinel)``, is used to get an iterator. ``iter(obj)`` returns an iterator for the object *obj*, while ``iter(C, sentinel)`` returns an iterator that will invoke the callable object *C* until it returns *sentinel* to signal that the iterator is done. @@ -793,7 +793,7 @@ Another change is simpler to explain. Since their introduction, Unicode strings have supported an :meth:`encode` method to convert the string to a selected -encoding such as UTF-8 or Latin-1. A symmetric :meth:`decode([*encoding*])` +encoding such as UTF-8 or Latin-1. A symmetric ``decode([*encoding*])`` method has been added to 8-bit strings (though not to Unicode strings) in 2.2. :meth:`decode` assumes that the string is in the specified encoding and decodes it, returning whatever is returned by the codec. @@ -1203,7 +1203,7 @@ to an MBCS encoded string, as used by the Microsoft file APIs. As MBCS is explicitly used by the file APIs, Python's choice of ASCII as the default encoding turns out to be an annoyance. On Unix, the locale's character set is - used if :func:`locale.nl_langinfo(CODESET)` is available. (Windows support was + used if ``locale.nl_langinfo(CODESET)`` is available. (Windows support was contributed by Mark Hammond with assistance from Marc-Andr? Lemburg. Unix support was added by Martin von L?wis.) diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -501,8 +501,8 @@ ZeroDivisionError: integer division or modulo by zero Slightly more advanced programs will use a logger other than the root logger. -The :func:`getLogger(name)` function is used to get a particular log, creating -it if it doesn't exist yet. :func:`getLogger(None)` returns the root logger. :: +The ``getLogger(name)`` function is used to get a particular log, creating +it if it doesn't exist yet. ``getLogger(None)`` returns the root logger. :: log = logging.getLogger('server') ... @@ -721,10 +721,10 @@ objects to it. Additional built-in and frozen modules can be imported by an object added to this list. -Importer objects must have a single method, :meth:`find_module(fullname, -path=None)`. *fullname* will be a module or package name, e.g. ``string`` or +Importer objects must have a single method, ``find_module(fullname, +path=None)``. *fullname* will be a module or package name, e.g. ``string`` or ``distutils.core``. :meth:`find_module` must return a loader object that has a -single method, :meth:`load_module(fullname)`, that creates and returns the +single method, ``load_module(fullname)``, that creates and returns the corresponding module object. Pseudo-code for Python's new import logic, therefore, looks something like this @@ -932,7 +932,7 @@ [0, 2, 4] To simplify implementing sequences that support extended slicing, slice objects -now have a method :meth:`indices(length)` which, given the length of a sequence, +now have a method ``indices(length)`` which, given the length of a sequence, returns a ``(start, stop, step)`` tuple that can be passed directly to :func:`range`. :meth:`indices` handles omitted and out-of-bounds indices in a manner consistent with regular slices (and this innocuous phrase hides a welter @@ -981,7 +981,7 @@ * Built-in types now support the extended slicing syntax, as described in section :ref:`section-slices` of this document. -* A new built-in function, :func:`sum(iterable, start=0)`, adds up the numeric +* A new built-in function, ``sum(iterable, start=0)``, adds up the numeric items in the iterable object and returns their sum. :func:`sum` only accepts numbers, meaning that you can't use it to concatenate a bunch of strings. (Contributed by Alex Martelli.) @@ -995,7 +995,7 @@ its index, now takes optional *start* and *stop* arguments to limit the search to only part of the list. -* Dictionaries have a new method, :meth:`pop(key[, *default*])`, that returns +* Dictionaries have a new method, ``pop(key[, *default*])``, that returns the value corresponding to *key* and removes that key/value pair from the dictionary. If the requested key isn't present in the dictionary, *default* is returned if it's specified and :exc:`KeyError` raised if it isn't. :: @@ -1017,7 +1017,7 @@ {} >>> - There's also a new class method, :meth:`dict.fromkeys(iterable, value)`, that + There's also a new class method, ``dict.fromkeys(iterable, value)``, that creates a dictionary with keys taken from the supplied iterator *iterable* and all values set to *value*, defaulting to ``None``. @@ -1090,7 +1090,7 @@ 100 bytecodes, speeding up single-threaded applications by reducing the switching overhead. Some multithreaded applications may suffer slower response time, but that's easily fixed by setting the limit back to a lower number using - :func:`sys.setcheckinterval(N)`. The limit can be retrieved with the new + ``sys.setcheckinterval(N)``. The limit can be retrieved with the new :func:`sys.getcheckinterval` function. * One minor but far-reaching change is that the names of extension types defined @@ -1269,10 +1269,10 @@ * Previously the :mod:`doctest` module would only search the docstrings of public methods and functions for test cases, but it now also examines private - ones as well. The :func:`DocTestSuite(` function creates a + ones as well. The :func:`DocTestSuite` function creates a :class:`unittest.TestSuite` object from a set of :mod:`doctest` tests. -* The new :func:`gc.get_referents(object)` function returns a list of all the +* The new ``gc.get_referents(object)`` function returns a list of all the objects referenced by *object*. * The :mod:`getopt` module gained a new function, :func:`gnu_getopt`, that @@ -1344,8 +1344,8 @@ documentation for details. (Contributed by Raymond Hettinger.) -* Two new functions in the :mod:`math` module, :func:`degrees(rads)` and - :func:`radians(degs)`, convert between radians and degrees. Other functions in +* Two new functions in the :mod:`math` module, ``degrees(rads)`` and + ``radians(degs)``, convert between radians and degrees. Other functions in the :mod:`math` module such as :func:`math.sin` and :func:`math.cos` have always required input values measured in radians. Also, an optional *base* argument was added to :func:`math.log` to make it easier to compute logarithms for bases @@ -1402,7 +1402,7 @@ and therefore faster performance. Setting the parser object's :attr:`buffer_text` attribute to :const:`True` will enable buffering. -* The :func:`sample(population, k)` function was added to the :mod:`random` +* The ``sample(population, k)`` function was added to the :mod:`random` module. *population* is a sequence or :class:`xrange` object containing the elements of a population, and :func:`sample` chooses *k* elements from the population without replacing chosen elements. *k* can be any value up to @@ -1448,7 +1448,7 @@ encryption is not believed to be secure. If you need encryption, use one of the several AES Python modules that are available separately. -* The :mod:`shutil` module gained a :func:`move(src, dest)` function that +* The :mod:`shutil` module gained a ``move(src, dest)`` function that recursively moves a file or directory to a new location. * Support for more advanced POSIX signal handling was added to the :mod:`signal` @@ -1456,7 +1456,7 @@ platforms. * The :mod:`socket` module now supports timeouts. You can call the - :meth:`settimeout(t)` method on a socket object to set a timeout of *t* seconds. + ``settimeout(t)`` method on a socket object to set a timeout of *t* seconds. Subsequent socket operations that take longer than *t* seconds to complete will abort and raise a :exc:`socket.timeout` exception. @@ -1477,9 +1477,9 @@ :program:`tar`\ -format archive files. (Contributed by Lars Gust?bel.) * The new :mod:`textwrap` module contains functions for wrapping strings - containing paragraphs of text. The :func:`wrap(text, width)` function takes a + containing paragraphs of text. The ``wrap(text, width)`` function takes a string and returns a list containing the text split into lines of no more than - the chosen width. The :func:`fill(text, width)` function returns a single + the chosen width. The ``fill(text, width)`` function returns a single string, reformatted to fit into lines no longer than the chosen width. (As you can guess, :func:`fill` is built on top of :func:`wrap`. For example:: @@ -1900,7 +1900,7 @@ short int`, ``I`` for :c:type:`unsigned int`, and ``K`` for :c:type:`unsigned long long`. -* A new function, :c:func:`PyObject_DelItemString(mapping, char \*key)` was added +* A new function, ``PyObject_DelItemString(mapping, char *key)`` was added as shorthand for ``PyObject_DelItem(mapping, PyString_New(key))``. * File objects now manage their internal string buffer differently, increasing diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -37,7 +37,7 @@ Python 2.3 introduced the :mod:`sets` module. C implementations of set data types have now been added to the Python core as two new built-in types, -:func:`set(iterable)` and :func:`frozenset(iterable)`. They provide high speed +``set(iterable)`` and ``frozenset(iterable)``. They provide high speed operations for membership testing, for eliminating duplicates from sequences, and for mathematical operations like unions, intersections, differences, and symmetric differences. :: @@ -346,7 +346,7 @@ PEP 322: Reverse Iteration ========================== -A new built-in function, :func:`reversed(seq)`, takes a sequence and returns an +A new built-in function, ``reversed(seq)``, takes a sequence and returns an iterator that loops over the elements of the sequence in reverse order. :: >>> for i in reversed(xrange(1,4)): @@ -384,7 +384,7 @@ The standard library provides a number of ways to execute a subprocess, offering different features and different levels of complexity. -:func:`os.system(command)` is easy to use, but slow (it runs a shell process +``os.system(command)`` is easy to use, but slow (it runs a shell process which executes the command) and dangerous (you have to be careful about escaping the shell's metacharacters). The :mod:`popen2` module offers classes that can capture standard output and standard error from the subprocess, but the naming @@ -428,8 +428,8 @@ Once you've created the :class:`Popen` instance, you can call its :meth:`wait` method to pause until the subprocess has exited, :meth:`poll` to check if it's -exited without pausing, or :meth:`communicate(data)` to send the string *data* -to the subprocess's standard input. :meth:`communicate(data)` then reads any +exited without pausing, or ``communicate(data)`` to send the string *data* +to the subprocess's standard input. ``communicate(data)`` then reads any data that the subprocess has sent to its standard output or standard error, returning a tuple ``(stdout_data, stderr_data)``. @@ -746,10 +746,10 @@ The solution described in the PEP is to add three new functions to the Python API that perform ASCII-only conversions, ignoring the locale setting: -* :c:func:`PyOS_ascii_strtod(str, ptr)` and :c:func:`PyOS_ascii_atof(str, ptr)` +* ``PyOS_ascii_strtod(str, ptr)`` and ``PyOS_ascii_atof(str, ptr)`` both convert a string to a C :c:type:`double`. -* :c:func:`PyOS_ascii_formatd(buffer, buf_len, format, d)` converts a +* ``PyOS_ascii_formatd(buffer, buf_len, format, d)`` converts a :c:type:`double` to an ASCII string. The code for these functions came from the GLib library @@ -775,7 +775,7 @@ * Decorators for functions and methods were added (:pep:`318`). * Built-in :func:`set` and :func:`frozenset` types were added (:pep:`218`). - Other new built-ins include the :func:`reversed(seq)` function (:pep:`322`). + Other new built-ins include the ``reversed(seq)`` function (:pep:`322`). * Generator expressions were added (:pep:`289`). @@ -854,7 +854,7 @@ (All changes to :meth:`sort` contributed by Raymond Hettinger.) -* There is a new built-in function :func:`sorted(iterable)` that works like the +* There is a new built-in function ``sorted(iterable)`` that works like the in-place :meth:`list.sort` method but can be used in expressions. The differences are: @@ -895,8 +895,8 @@ For example, you can now run the Python profiler with ``python -m profile``. (Contributed by Nick Coghlan.) -* The :func:`eval(expr, globals, locals)` and :func:`execfile(filename, globals, - locals)` functions and the ``exec`` statement now accept any mapping type +* The ``eval(expr, globals, locals)`` and ``execfile(filename, globals, + locals)`` functions and the ``exec`` statement now accept any mapping type for the *locals* parameter. Previously this had to be a regular Python dictionary. (Contributed by Raymond Hettinger.) @@ -1087,7 +1087,7 @@ Yves Dionne) and new :meth:`deleteacl` and :meth:`myrights` methods (contributed by Arnaud Mazin). -* The :mod:`itertools` module gained a :func:`groupby(iterable[, *func*])` +* The :mod:`itertools` module gained a ``groupby(iterable[, *func*])`` function. *iterable* is something that can be iterated over to return a stream of elements, and the optional *func* parameter is a function that takes an element and returns a key value; if omitted, the key is simply the element @@ -1136,7 +1136,7 @@ (Contributed by Hye-Shik Chang.) -* :mod:`itertools` also gained a function named :func:`tee(iterator, N)` that +* :mod:`itertools` also gained a function named ``tee(iterator, N)`` that returns *N* independent iterators that replicate *iterator*. If *N* is omitted, the default is 2. :: @@ -1174,7 +1174,7 @@ level=0, # Log all messages format='%(levelname):%(process):%(thread):%(message)') - Other additions to the :mod:`logging` package include a :meth:`log(level, msg)` + Other additions to the :mod:`logging` package include a ``log(level, msg)`` convenience method, as well as a :class:`TimedRotatingFileHandler` class that rotates its log files at a timed interval. The module already had :class:`RotatingFileHandler`, which rotated logs once the file exceeded a @@ -1193,7 +1193,7 @@ group or for a range of groups. (Contributed by J?rgen A. Erhard.) * Two new functions were added to the :mod:`operator` module, - :func:`attrgetter(attr)` and :func:`itemgetter(index)`. Both functions return + ``attrgetter(attr)`` and ``itemgetter(index)``. Both functions return callables that take a single argument and return the corresponding attribute or item; these callables make excellent data extractors when used with :func:`map` or :func:`sorted`. For example:: @@ -1220,14 +1220,14 @@ replacement for :func:`rfc822.formatdate`. You may want to write new e-mail processing code with this in mind. (Change implemented by Anthony Baxter.) -* A new :func:`urandom(n)` function was added to the :mod:`os` module, returning +* A new ``urandom(n)`` function was added to the :mod:`os` module, returning a string containing *n* bytes of random data. This function provides access to platform-specific sources of randomness such as :file:`/dev/urandom` on Linux or the Windows CryptoAPI. (Contributed by Trevor Perrin.) -* Another new function: :func:`os.path.lexists(path)` returns true if the file +* Another new function: ``os.path.lexists(path)`` returns true if the file specified by *path* exists, whether or not it's a symbolic link. This differs - from the existing :func:`os.path.exists(path)` function, which returns false if + from the existing ``os.path.exists(path)`` function, which returns false if *path* is a symlink that points to a destination that doesn't exist. (Contributed by Beni Cherniavsky.) @@ -1240,7 +1240,7 @@ * The :mod:`profile` module can now profile C extension functions. (Contributed by Nick Bastin.) -* The :mod:`random` module has a new method called :meth:`getrandbits(N)` that +* The :mod:`random` module has a new method called ``getrandbits(N)`` that returns a long integer *N* bits in length. The existing :meth:`randrange` method now uses :meth:`getrandbits` where appropriate, making generation of arbitrarily large random numbers more efficient. (Contributed by Raymond @@ -1269,7 +1269,7 @@ this, but 2.4 will raise a :exc:`RuntimeError` exception. * Two new functions were added to the :mod:`socket` module. :func:`socketpair` - returns a pair of connected sockets and :func:`getservbyport(port)` looks up the + returns a pair of connected sockets and ``getservbyport(port)`` looks up the service name for a given port number. (Contributed by Dave Cole and Barry Warsaw.) @@ -1451,11 +1451,11 @@ * Another new macro, :c:macro:`Py_CLEAR(obj)`, decreases the reference count of *obj* and sets *obj* to the null pointer. (Contributed by Jim Fulton.) -* A new function, :c:func:`PyTuple_Pack(N, obj1, obj2, ..., objN)`, constructs +* A new function, ``PyTuple_Pack(N, obj1, obj2, ..., objN)``, constructs tuples from a variable length argument list of Python objects. (Contributed by Raymond Hettinger.) -* A new function, :c:func:`PyDict_Contains(d, k)`, implements fast dictionary +* A new function, ``PyDict_Contains(d, k)``, implements fast dictionary lookups without masking exceptions raised during the look-up process. (Contributed by Raymond Hettinger.) diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -171,7 +171,7 @@ popup_menu.append( ("Open", open_func, 1) ) Another function in the :mod:`functools` module is the -:func:`update_wrapper(wrapper, wrapped)` function that helps you write well- +``update_wrapper(wrapper, wrapped)`` function that helps you write well- behaved decorators. :func:`update_wrapper` copies the name, module, and docstring attribute to a wrapper function so that tracebacks inside the wrapped function are easier to understand. For example, you might write:: @@ -454,7 +454,7 @@ ``val = yield i`` but have to use parentheses when there's an operation, as in ``val = (yield i) + 12``.) -Values are sent into a generator by calling its :meth:`send(value)` method. The +Values are sent into a generator by calling its ``send(value)`` method. The generator's code is then resumed and the :keyword:`yield` expression returns the specified *value*. If the regular :meth:`next` method is called, the :keyword:`yield` returns :const:`None`. @@ -496,7 +496,7 @@ In addition to :meth:`send`, there are two other new methods on generators: -* :meth:`throw(type, value=None, traceback=None)` is used to raise an exception +* ``throw(type, value=None, traceback=None)`` is used to raise an exception inside the generator; the exception is raised by the :keyword:`yield` expression where the generator's execution is paused. @@ -660,7 +660,7 @@ * The code in *BLOCK* is executed. -* If *BLOCK* raises an exception, the :meth:`__exit__(type, value, traceback)` +* If *BLOCK* raises an exception, the ``__exit__(type, value, traceback)`` is called with the exception details, the same values returned by :func:`sys.exc_info`. The method's return value controls whether the exception is re-raised: any false value re-raises the exception, and ``True`` will result @@ -773,7 +773,7 @@ with db_transaction(db) as cursor: ... -The :mod:`contextlib` module also has a :func:`nested(mgr1, mgr2, ...)` function +The :mod:`contextlib` module also has a ``nested(mgr1, mgr2, ...)`` function that combines a number of context managers so you don't need to write nested ':keyword:`with`' statements. In this example, the single ':keyword:`with`' statement both starts a database transaction and acquires a thread lock:: @@ -782,7 +782,7 @@ with nested (db_transaction(db), lock) as (cursor, locked): ... -Finally, the :func:`closing(object)` function returns *object* so that it can be +Finally, the ``closing(object)`` function returns *object* so that it can be bound to a variable, and calls ``object.close`` at the end of the block. :: import urllib, sys @@ -955,7 +955,7 @@ A corresponding :attr:`nb_index` slot was added to the C-level :c:type:`PyNumberMethods` structure to let C extensions implement this protocol. -:c:func:`PyNumber_Index(obj)` can be used in extension code to call the +``PyNumber_Index(obj)`` can be used in extension code to call the :meth:`__index__` function and retrieve its result. @@ -976,7 +976,7 @@ * The :class:`dict` type has a new hook for letting subclasses provide a default value when a key isn't contained in the dictionary. When a key isn't found, the - dictionary's :meth:`__missing__(key)` method will be called. This hook is used + dictionary's ``__missing__(key)`` method will be called. This hook is used to implement the new :class:`defaultdict` class in the :mod:`collections` module. The following example defines a dictionary that returns zero for any missing key:: @@ -989,16 +989,16 @@ print d[1], d[2] # Prints 1, 2 print d[3], d[4] # Prints 0, 0 -* Both 8-bit and Unicode strings have new :meth:`partition(sep)` and - :meth:`rpartition(sep)` methods that simplify a common use case. - - The :meth:`find(S)` method is often used to get an index which is then used to +* Both 8-bit and Unicode strings have new ``partition(sep)`` and + ``rpartition(sep)`` methods that simplify a common use case. + + The ``find(S)`` method is often used to get an index which is then used to slice the string and obtain the pieces that are before and after the separator. - :meth:`partition(sep)` condenses this pattern into a single method call that + ``partition(sep)`` condenses this pattern into a single method call that returns a 3-tuple containing the substring before the separator, the separator itself, and the substring after the separator. If the separator isn't found, the first element of the tuple is the entire string and the other two elements - are empty. :meth:`rpartition(sep)` also returns a 3-tuple but starts searching + are empty. ``rpartition(sep)`` also returns a 3-tuple but starts searching from the end of the string; the ``r`` stands for 'reverse'. Some examples:: @@ -1157,7 +1157,7 @@ .. Patch 1313939, 1359618 -* The :func:`long(str, base)` function is now faster on long digit strings +* The ``long(str, base)`` function is now faster on long digit strings because fewer intermediate results are calculated. The peak is for strings of around 800--1000 digits where the function is 6 times faster. (Contributed by Alan McIntyre and committed at the NeedForSpeed sprint.) @@ -1268,7 +1268,7 @@ (Contributed by Guido van Rossum.) * The :class:`deque` double-ended queue type supplied by the :mod:`collections` - module now has a :meth:`remove(value)` method that removes the first occurrence + module now has a ``remove(value)`` method that removes the first occurrence of *value* in the queue, raising :exc:`ValueError` if the value isn't found. (Contributed by Raymond Hettinger.) @@ -1291,7 +1291,7 @@ * The :mod:`csv` module, which parses files in comma-separated value format, received several enhancements and a number of bugfixes. You can now set the maximum size in bytes of a field by calling the - :meth:`csv.field_size_limit(new_limit)` function; omitting the *new_limit* + ``csv.field_size_limit(new_limit)`` function; omitting the *new_limit* argument will return the currently-set limit. The :class:`reader` class now has a :attr:`line_num` attribute that counts the number of physical lines read from the source; records can span multiple physical lines, so :attr:`line_num` is not @@ -1308,7 +1308,7 @@ (Contributed by Skip Montanaro and Andrew McNamara.) * The :class:`datetime` class in the :mod:`datetime` module now has a - :meth:`strptime(string, format)` method for parsing date strings, contributed + ``strptime(string, format)`` method for parsing date strings, contributed by Josh Spoerri. It uses the same format characters as :func:`time.strptime` and :func:`time.strftime`:: @@ -1399,7 +1399,7 @@ * The :mod:`mailbox` module underwent a massive rewrite to add the capability to modify mailboxes in addition to reading them. A new set of classes that include :class:`mbox`, :class:`MH`, and :class:`Maildir` are used to read mailboxes, and - have an :meth:`add(message)` method to add messages, :meth:`remove(key)` to + have an ``add(message)`` method to add messages, ``remove(key)`` to remove messages, and :meth:`lock`/:meth:`unlock` to lock/unlock the mailbox. The following example converts a maildir-format mailbox into an mbox-format one:: @@ -1454,7 +1454,7 @@ :func:`wait4` return additional information. :func:`wait3` doesn't take a process ID as input, so it waits for any child process to exit and returns a 3-tuple of *process-id*, *exit-status*, *resource-usage* as returned from the - :func:`resource.getrusage` function. :func:`wait4(pid)` does take a process ID. + :func:`resource.getrusage` function. ``wait4(pid)`` does take a process ID. (Contributed by Chad J. Schroeder.) On FreeBSD, the :func:`os.stat` function now returns times with nanosecond @@ -1528,8 +1528,8 @@ In Python code, netlink addresses are represented as a tuple of 2 integers, ``(pid, group_mask)``. - Two new methods on socket objects, :meth:`recv_into(buffer)` and - :meth:`recvfrom_into(buffer)`, store the received data in an object that + Two new methods on socket objects, ``recv_into(buffer)`` and + ``recvfrom_into(buffer)``, store the received data in an object that supports the buffer protocol instead of returning the data as a string. This means you can put the data directly into an array or a memory-mapped file. @@ -1553,8 +1553,8 @@ year, number, name = s.unpack(data) You can also pack and unpack data to and from buffer objects directly using the - :meth:`pack_into(buffer, offset, v1, v2, ...)` and :meth:`unpack_from(buffer, - offset)` methods. This lets you store data directly into an array or a memory- + ``pack_into(buffer, offset, v1, v2, ...)`` and ``unpack_from(buffer, + offset)`` methods. This lets you store data directly into an array or a memory- mapped file. (:class:`Struct` objects were implemented by Bob Ippolito at the NeedForSpeed @@ -1588,7 +1588,7 @@ .. patch 918101 * The :mod:`threading` module now lets you set the stack size used when new - threads are created. The :func:`stack_size([*size*])` function returns the + threads are created. The ``stack_size([*size*])`` function returns the currently configured stack size, and supplying the optional *size* parameter sets a new value. Not all platforms support changing the stack size, but Windows, POSIX threading, and OS/2 all do. (Contributed by Andrew MacIntyre.) @@ -1907,7 +1907,7 @@ h = hashlib.new('md5') # Provide algorithm as a string Once a hash object has been created, its methods are the same as before: -:meth:`update(string)` hashes the specified string into the current digest +``update(string)`` hashes the specified string into the current digest state, :meth:`digest` and :meth:`hexdigest` return the digest value as a binary string or a string of hex digits, and :meth:`copy` returns a new hashing object with the same digest state. @@ -2164,20 +2164,20 @@ * Two new macros can be used to indicate C functions that are local to the current file so that a faster calling convention can be used. - :c:func:`Py_LOCAL(type)` declares the function as returning a value of the + ``Py_LOCAL(type)`` declares the function as returning a value of the specified *type* and uses a fast-calling qualifier. - :c:func:`Py_LOCAL_INLINE(type)` does the same thing and also requests the + ``Py_LOCAL_INLINE(type)`` does the same thing and also requests the function be inlined. If :c:func:`PY_LOCAL_AGGRESSIVE` is defined before :file:`python.h` is included, a set of more aggressive optimizations are enabled for the module; you should benchmark the results to find out if these optimizations actually make the code faster. (Contributed by Fredrik Lundh at the NeedForSpeed sprint.) -* :c:func:`PyErr_NewException(name, base, dict)` can now accept a tuple of base +* ``PyErr_NewException(name, base, dict)`` can now accept a tuple of base classes as its *base* argument. (Contributed by Georg Brandl.) * The :c:func:`PyErr_Warn` function for issuing warnings is now deprecated in - favour of :c:func:`PyErr_WarnEx(category, message, stacklevel)` which lets you + favour of ``PyErr_WarnEx(category, message, stacklevel)`` which lets you specify the number of stack frames separating this function and the caller. A *stacklevel* of 1 is the function calling :c:func:`PyErr_WarnEx`, 2 is the function above that, and so forth. (Added by Neal Norwitz.) diff --git a/Doc/whatsnew/3.0.rst b/Doc/whatsnew/3.0.rst --- a/Doc/whatsnew/3.0.rst +++ b/Doc/whatsnew/3.0.rst @@ -812,7 +812,7 @@ * The :func:`round` function rounding strategy and return type have changed. Exact halfway cases are now rounded to the nearest even result instead of away from zero. (For example, ``round(2.5)`` now - returns ``2`` rather than ``3``.) :func:`round(x[, n])` now + returns ``2`` rather than ``3``.) ``round(x[, n])`` now delegates to ``x.__round__([n])`` instead of always returning a float. It generally returns an integer when called with a single argument and a value of the same type as ``x`` when called with two -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 01:43:53 2012 From: python-checkins at python.org (brett.cannon) Date: Sun, 12 Aug 2012 01:43:53 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Minor_doc_formatting_clean?= =?utf-8?b?dXAu?= Message-ID: <3Wvft12VdxzPjx@mail.python.org> http://hg.python.org/cpython/rev/e3c12af74bec changeset: 78510:e3c12af74bec user: Brett Cannon date: Sat Aug 11 19:41:27 2012 -0400 summary: Minor doc formatting cleanup. files: Doc/library/importlib.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -153,8 +153,8 @@ .. method:: invalidate_caches() An optional method which, when called, should invalidate any internal - cache used by the finder. Used by :func:`invalidate_caches()` when - invalidating the caches of all finders on :data:`sys.meta_path`. + cache used by the finder. Used by :func:`importlib.invalidate_caches` + when invalidating the caches of all finders on :data:`sys.meta_path`. .. class:: PathEntryFinder @@ -187,7 +187,7 @@ .. method:: invalidate_caches() An optional method which, when called, should invalidate any internal - cache used by the finder. Used by :meth:`PathFinder.invalidate_caches()` + cache used by the finder. Used by :meth:`PathFinder.invalidate_caches` when invalidating the caches of all cached finders. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 01:43:54 2012 From: python-checkins at python.org (brett.cannon) Date: Sun, 12 Aug 2012 01:43:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Don=27t_overwrite_a_=5F=5F?= =?utf-8?q?path=5F=5F_value_from_extension_modules_if_already?= Message-ID: <3Wvft272PTzPjx@mail.python.org> http://hg.python.org/cpython/rev/34d5ec8a1019 changeset: 78511:34d5ec8a1019 user: Brett Cannon date: Sat Aug 11 19:43:29 2012 -0400 summary: Don't overwrite a __path__ value from extension modules if already set. files: Lib/importlib/_bootstrap.py | 2 +- Python/importlib.h | 3341 +++++++++++----------- 2 files changed, 1673 insertions(+), 1670 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1108,7 +1108,7 @@ module = _call_with_frames_removed(_imp.load_dynamic, fullname, self.path) _verbose_message('extension module loaded from {!r}', self.path) - if self.is_package(fullname): + if self.is_package(fullname) and not hasattr(module, '__path__'): module.__path__ = [_path_split(self.path)[0]] return module except: 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 solipsis at pitrou.net Sun Aug 12 06:05:23 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 12 Aug 2012 06:05:23 +0200 Subject: [Python-checkins] Daily reference leaks (34d5ec8a1019): sum=0 Message-ID: results for 34d5ec8a1019 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogfzyyja', '-x'] From python-checkins at python.org Sun Aug 12 10:25:22 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 10:25:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogemlwKCkgcmV0dXJu?= =?utf-8?q?s_an_iterator=2C_make_a_list=28=29_of_it=3B_thanks_to_Martin_fr?= =?utf-8?q?om_docs=40?= Message-ID: <3WvtRk6prQzPr6@mail.python.org> http://hg.python.org/cpython/rev/233673503217 changeset: 78512:233673503217 branch: 3.2 parent: 78507:3654c711019a user: Sandro Tosi date: Sun Aug 12 10:24:50 2012 +0200 summary: zip() returns an iterator, make a list() of it; thanks to Martin from docs@ files: Doc/tutorial/datastructures.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -292,7 +292,7 @@ In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case:: - >>> zip(*matrix) + >>> list(zip(*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] See :ref:`tut-unpacking-arguments` for details on the asterisk in this line. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 10:25:24 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 10:25:24 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3WvtRm3rBrzPrw@mail.python.org> http://hg.python.org/cpython/rev/71e33d4e5b3a changeset: 78513:71e33d4e5b3a parent: 78511:34d5ec8a1019 parent: 78512:233673503217 user: Sandro Tosi date: Sun Aug 12 10:25:10 2012 +0200 summary: merge with 3.2 files: Doc/tutorial/datastructures.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -297,7 +297,7 @@ In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case:: - >>> zip(*matrix) + >>> list(zip(*matrix)) [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] See :ref:`tut-unpacking-arguments` for details on the asterisk in this line. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 10:37:32 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 10:37:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_update_CodeTools_link=3B_t?= =?utf-8?q?hanks_to_Robert_Kern_from_docs=40?= Message-ID: <3Wvtjm1bgwzPrZ@mail.python.org> http://hg.python.org/cpython/rev/c5b1d716c4d1 changeset: 78514:c5b1d716c4d1 user: Sandro Tosi date: Sun Aug 12 10:37:23 2012 +0200 summary: update CodeTools link; thanks to Robert Kern from docs@ 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 @@ -98,7 +98,7 @@ .. seealso:: * The `MultiContext class - `_ + `_ in the Enthought `CodeTools package `_ has options to support writing to any mapping in the chain. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 10:49:55 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 10:49:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_add_missing_pa?= =?utf-8?q?renthesis_to_=27action=27_argparse_doc=3B_thanks_to_kishkin_fro?= =?utf-8?q?m_docs=40?= Message-ID: <3Wvv034jdZzPZN@mail.python.org> http://hg.python.org/cpython/rev/a13f99dc91b3 changeset: 78515:a13f99dc91b3 branch: 2.7 parent: 78506:a82fc1f366b4 user: Sandro Tosi date: Sun Aug 12 10:49:07 2012 +0200 summary: add missing parenthesis to 'action' argparse doc; thanks to kishkin from docs@ 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 @@ -749,7 +749,7 @@ * ``values`` - The associated command-line arguments, with any type conversions applied. (Type conversions are specified with the type_ keyword argument to - :meth:`~ArgumentParser.add_argument`. + :meth:`~ArgumentParser.add_argument`.) * ``option_string`` - The option string that was used to invoke this action. The ``option_string`` argument is optional, and will be absent if the action -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 10:49:57 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 10:49:57 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_add_missing_pa?= =?utf-8?q?renthesis_to_=27action=27_argparse_doc=3B_thanks_to_kishkin_fro?= =?utf-8?q?m_docs=40?= Message-ID: <3Wvv051sbRzPs8@mail.python.org> http://hg.python.org/cpython/rev/a790357c452f changeset: 78516:a790357c452f branch: 3.2 parent: 78512:233673503217 user: Sandro Tosi date: Sun Aug 12 10:49:26 2012 +0200 summary: add missing parenthesis to 'action' argparse doc; thanks to kishkin from docs@ 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 @@ -747,7 +747,7 @@ * ``values`` - The associated command-line arguments, with any type conversions applied. (Type conversions are specified with the type_ keyword argument to - :meth:`~ArgumentParser.add_argument`. + :meth:`~ArgumentParser.add_argument`.) * ``option_string`` - The option string that was used to invoke this action. The ``option_string`` argument is optional, and will be absent if the action -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 10:49:58 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 10:49:58 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3Wvv064b3VzPrw@mail.python.org> http://hg.python.org/cpython/rev/bb7d1eabc57e changeset: 78517:bb7d1eabc57e parent: 78514:c5b1d716c4d1 parent: 78516:a790357c452f user: Sandro Tosi date: Sun Aug 12 10:49:40 2012 +0200 summary: 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 @@ -766,7 +766,7 @@ * ``values`` - The associated command-line arguments, with any type conversions applied. (Type conversions are specified with the type_ keyword argument to - :meth:`~ArgumentParser.add_argument`. + :meth:`~ArgumentParser.add_argument`.) * ``option_string`` - The option string that was used to invoke this action. The ``option_string`` argument is optional, and will be absent if the action -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 11:02:36 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 11:02:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_update_Geany_U?= =?utf-8?q?RL=3B_thanks_to_Karl_Tarbet_from_docs=40?= Message-ID: <3WvvGh3B3FzPn3@mail.python.org> http://hg.python.org/cpython/rev/8f78fc269c1b changeset: 78518:8f78fc269c1b branch: 2.7 parent: 78515:a13f99dc91b3 user: Sandro Tosi date: Sun Aug 12 11:01:50 2012 +0200 summary: update Geany URL; thanks to Karl Tarbet from docs@ files: Doc/using/unix.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/using/unix.rst b/Doc/using/unix.rst --- a/Doc/using/unix.rst +++ b/Doc/using/unix.rst @@ -145,7 +145,7 @@ * http://sourceforge.net/projects/python-mode Geany is an excellent IDE with support for a lot of languages. For more -information, read: http://geany.uvena.de/ +information, read: http://www.geany.org/ Komodo edit is another extremely good IDE. It also has support for a lot of languages. For more information, read: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 11:02:37 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 11:02:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_update_Geany_U?= =?utf-8?q?RL=3B_thanks_to_Karl_Tarbet_from_docs=40?= Message-ID: <3WvvGj6kGlzPns@mail.python.org> http://hg.python.org/cpython/rev/b2907d1e5341 changeset: 78519:b2907d1e5341 branch: 3.2 parent: 78516:a790357c452f user: Sandro Tosi date: Sun Aug 12 11:02:03 2012 +0200 summary: update Geany URL; thanks to Karl Tarbet from docs@ files: Doc/using/unix.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/using/unix.rst b/Doc/using/unix.rst --- a/Doc/using/unix.rst +++ b/Doc/using/unix.rst @@ -141,7 +141,7 @@ * http://sourceforge.net/projects/python-mode Geany is an excellent IDE with support for a lot of languages. For more -information, read: http://geany.uvena.de/ +information, read: http://www.geany.org/ Komodo edit is another extremely good IDE. It also has support for a lot of languages. For more information, read: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 11:02:39 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 11:02:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3WvvGl2F0nzPrw@mail.python.org> http://hg.python.org/cpython/rev/508c9f9b701a changeset: 78520:508c9f9b701a parent: 78517:bb7d1eabc57e parent: 78519:b2907d1e5341 user: Sandro Tosi date: Sun Aug 12 11:02:17 2012 +0200 summary: merge with 3.2 files: Doc/using/unix.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/using/unix.rst b/Doc/using/unix.rst --- a/Doc/using/unix.rst +++ b/Doc/using/unix.rst @@ -141,7 +141,7 @@ * http://sourceforge.net/projects/python-mode Geany is an excellent IDE with support for a lot of languages. For more -information, read: http://geany.uvena.de/ +information, read: http://www.geany.org/ Komodo edit is another extremely good IDE. It also has support for a lot of languages. For more information, read: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 12:36:03 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 12:36:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_add_missing_qu?= =?utf-8?q?ote_in_splitlines=28=29_example=3B_thanks_to_Yevgen_Yampolskiy_?= =?utf-8?q?from?= Message-ID: <3WvxLW6PyGzPpb@mail.python.org> http://hg.python.org/cpython/rev/61f1bf70db95 changeset: 78521:61f1bf70db95 branch: 2.7 parent: 78518:8f78fc269c1b user: Sandro Tosi date: Sun Aug 12 12:34:57 2012 +0200 summary: add missing quote in splitlines() example; thanks to Yevgen Yampolskiy from docs@ files: Doc/library/stdtypes.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1190,7 +1190,7 @@ For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` - returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + returns ``['ab c\n', '\n', 'de fg\r', 'kl\r\n']``. Unlike :meth:`~str.split` when a delimiter string *sep* is given, this method returns an empty list for the empty string, and a terminal line -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 12:36:05 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 12:36:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_add_missing_qu?= =?utf-8?q?ote_in_splitlines=28=29_example=3B_thanks_to_Yevgen_Yampolskiy_?= =?utf-8?q?from?= Message-ID: <3WvxLY3fNDzPsF@mail.python.org> http://hg.python.org/cpython/rev/7346821faf68 changeset: 78522:7346821faf68 branch: 3.2 parent: 78519:b2907d1e5341 user: Sandro Tosi date: Sun Aug 12 12:35:14 2012 +0200 summary: add missing quote in splitlines() example; thanks to Yevgen Yampolskiy from docs@ files: Doc/library/stdtypes.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1334,7 +1334,7 @@ For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` - returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + returns ``['ab c\n', '\n', 'de fg\r', 'kl\r\n']``. Unlike :meth:`~str.split` when a delimiter string *sep* is given, this method returns an empty list for the empty string, and a terminal line -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 12:36:06 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 12:36:06 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3WvxLZ6dNszPsD@mail.python.org> http://hg.python.org/cpython/rev/770020baf8e2 changeset: 78523:770020baf8e2 parent: 78520:508c9f9b701a parent: 78522:7346821faf68 user: Sandro Tosi date: Sun Aug 12 12:35:31 2012 +0200 summary: merge with 3.2 files: Doc/library/stdtypes.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1358,7 +1358,7 @@ For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` - returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + returns ``['ab c\n', '\n', 'de fg\r', 'kl\r\n']``. Unlike :meth:`~str.split` when a delimiter string *sep* is given, this method returns an empty list for the empty string, and a terminal line -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 14:16:52 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 12 Aug 2012 14:16:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_fix_doctest_for_email=2Ehe?= =?utf-8?q?ader_docs?= Message-ID: <3WvzZr4DsgzPsg@mail.python.org> http://hg.python.org/cpython/rev/c71ae4007aa0 changeset: 78524:c71ae4007aa0 user: Andrew Svetlov date: Sun Aug 12 14:49:59 2012 +0300 summary: fix doctest for email.header docs files: Doc/library/email.header.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/email.header.rst b/Doc/library/email.header.rst --- a/Doc/library/email.header.rst +++ b/Doc/library/email.header.rst @@ -31,8 +31,8 @@ >>> msg = Message() >>> h = Header('p\xf6stal', 'iso-8859-1') >>> msg['Subject'] = h - >>> print(msg.as_string()) - Subject: =?iso-8859-1?q?p=F6stal?= + >>> msg.as_string() + 'Subject: =?iso-8859-1?q?p=F6stal?=\n\n' @@ -176,7 +176,7 @@ >>> from email.header import decode_header >>> decode_header('=?iso-8859-1?q?p=F6stal?=') - [('p\xf6stal', 'iso-8859-1')] + [(b'p\xf6stal', 'iso-8859-1')] .. function:: make_header(decoded_seq, maxlinelen=None, header_name=None, continuation_ws=' ') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 14:16:54 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 12 Aug 2012 14:16:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_update_doctests?= Message-ID: <3WvzZt0ZvJzPsg@mail.python.org> http://hg.python.org/cpython/rev/90a559ce9151 changeset: 78525:90a559ce9151 user: Andrew Svetlov date: Sun Aug 12 15:16:42 2012 +0300 summary: update doctests files: Doc/library/email.parser.rst | 2 +- Doc/library/functions.rst | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Doc/library/email.parser.rst b/Doc/library/email.parser.rst --- a/Doc/library/email.parser.rst +++ b/Doc/library/email.parser.rst @@ -251,7 +251,7 @@ Here's an example of how you might use this at an interactive Python prompt:: >>> import email - >>> msg = email.message_from_string(myString) + >>> msg = email.message_from_string(myString) # doctest: +SKIP Additional notes diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -305,17 +305,18 @@ >>> import struct >>> dir() # show the names in the module namespace - ['__builtins__', '__doc__', '__name__', 'struct'] - >>> dir(struct) # show the names in the struct module - ['Struct', '__builtins__', '__doc__', '__file__', '__name__', - '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', + ['__builtins__', '__name__', 'struct'] + >>> dir(struct) # show the names in the struct module # doctest: +SKIP + ['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', + '__initializing__', '__loader__', '__name__', '__package__', + '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', 'unpack', 'unpack_from'] >>> class Shape(object): - def __dir__(self): - return ['area', 'perimeter', 'location'] + ... def __dir__(self): + ... return ['area', 'perimeter', 'location'] >>> s = Shape() >>> dir(s) - ['area', 'perimeter', 'location'] + ['area', 'location', 'perimeter'] .. note:: @@ -614,9 +615,9 @@ to a string (stripping a trailing newline), and returns that. When EOF is read, :exc:`EOFError` is raised. Example:: - >>> s = input('--> ') + >>> s = input('--> ') # doctest: +SKIP --> Monty Python's Flying Circus - >>> s + >>> s # doctest: +SKIP "Monty Python's Flying Circus" If the :mod:`readline` module was loaded, then :func:`input` will use it -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 15:12:54 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 15:12:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogaXQncyBnZXRzdGF0?= =?utf-8?q?us=28=29_not_setstatus=28=29=3B_thanks_to_Shaddi_Hasan_from_doc?= =?utf-8?q?s=40?= Message-ID: <3Ww0qV15PwzPvC@mail.python.org> http://hg.python.org/cpython/rev/e87fb826c092 changeset: 78526:e87fb826c092 branch: 3.2 parent: 78522:7346821faf68 user: Sandro Tosi date: Sun Aug 12 15:12:15 2012 +0200 summary: it's getstatus() not setstatus(); thanks to Shaddi Hasan from docs@ files: Doc/library/random.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/random.rst b/Doc/library/random.rst --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -74,7 +74,7 @@ *state* should have been obtained from a previous call to :func:`getstate`, and :func:`setstate` restores the internal state of the generator to what it was at - the time :func:`setstate` was called. + the time :func:`getstate` was called. .. function:: getrandbits(k) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 15:12:56 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 15:12:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogaXQncyBnZXRzdGF0?= =?utf-8?q?us=28=29_not_setstatus=28=29=3B_thanks_to_Shaddi_Hasan_from_doc?= =?utf-8?q?s=40?= Message-ID: <3Ww0qX0QW2zPvY@mail.python.org> http://hg.python.org/cpython/rev/df337391f9f5 changeset: 78527:df337391f9f5 branch: 2.7 parent: 78521:61f1bf70db95 user: Sandro Tosi date: Sun Aug 12 15:11:58 2012 +0200 summary: it's getstatus() not setstatus(); thanks to Shaddi Hasan from docs@ files: Doc/library/random.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/random.rst b/Doc/library/random.rst --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -90,7 +90,7 @@ *state* should have been obtained from a previous call to :func:`getstate`, and :func:`setstate` restores the internal state of the generator to what it was at - the time :func:`setstate` was called. + the time :func:`getstate` was called. .. versionadded:: 2.1 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 15:12:57 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 15:12:57 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3Ww0qY37f4zPtr@mail.python.org> http://hg.python.org/cpython/rev/f3e5545cf40c changeset: 78528:f3e5545cf40c parent: 78525:90a559ce9151 parent: 78526:e87fb826c092 user: Sandro Tosi date: Sun Aug 12 15:12:32 2012 +0200 summary: merge with 3.2 files: Doc/library/random.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/random.rst b/Doc/library/random.rst --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -80,7 +80,7 @@ *state* should have been obtained from a previous call to :func:`getstate`, and :func:`setstate` restores the internal state of the generator to what it was at - the time :func:`setstate` was called. + the time :func:`getstate` was called. .. function:: getrandbits(k) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 15:35:57 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 15:35:57 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogZXNjYXBlICdcJzsg?= =?utf-8?q?thanks_to_Steve_Holden_from_docs=40?= Message-ID: <3Ww1L55wjzzPmV@mail.python.org> http://hg.python.org/cpython/rev/5617c4a0c035 changeset: 78529:5617c4a0c035 branch: 3.2 parent: 78526:e87fb826c092 user: Sandro Tosi date: Sun Aug 12 15:35:25 2012 +0200 summary: escape '\'; thanks to Steve Holden from docs@ files: Doc/library/smtpd.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/smtpd.rst b/Doc/library/smtpd.rst --- a/Doc/library/smtpd.rst +++ b/Doc/library/smtpd.rst @@ -109,7 +109,7 @@ .. attribute:: received_lines Holds a list of the line strings (decoded using UTF-8) received from - the client. The lines have their "\r\n" line ending translated to "\n". + the client. The lines have their "\\r\\n" line ending translated to "\\n". .. attribute:: smtp_state -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 15:35:59 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 15:35:59 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3Ww1L72wxNzPrF@mail.python.org> http://hg.python.org/cpython/rev/0d9222f32510 changeset: 78530:0d9222f32510 parent: 78528:f3e5545cf40c parent: 78529:5617c4a0c035 user: Sandro Tosi date: Sun Aug 12 15:35:43 2012 +0200 summary: merge with 3.2 files: Doc/library/smtpd.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/smtpd.rst b/Doc/library/smtpd.rst --- a/Doc/library/smtpd.rst +++ b/Doc/library/smtpd.rst @@ -116,7 +116,7 @@ .. attribute:: received_lines Holds a list of the line strings (decoded using UTF-8) received from - the client. The lines have their "\r\n" line ending translated to "\n". + the client. The lines have their "\\r\\n" line ending translated to "\\n". .. attribute:: smtp_state -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 16:59:04 2012 From: python-checkins at python.org (georg.brandl) Date: Sun, 12 Aug 2012 16:59:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Post-release_updates=2E?= Message-ID: <3Ww3B048fKzPt7@mail.python.org> http://hg.python.org/cpython/rev/04788fa08adc changeset: 78531:04788fa08adc user: Georg Brandl date: Sun Aug 12 16:58:55 2012 +0200 summary: Post-release updates. files: Include/patchlevel.h | 2 +- Misc/NEWS | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/Include/patchlevel.h b/Include/patchlevel.h --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.3.0b2" +#define PY_VERSION "3.3.0b2+" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2,6 +2,18 @@ Python News +++++++++++ +What's New in Python 3.3.0 Release Candidate 1? +=============================================== + +*Release date: XX-Aug-2012* + +Core and Builtins +----------------- + +Library +------- + + What's New in Python 3.3.0 Beta 2? ================================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 17:34:30 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 17:34:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_add_usage_exam?= =?utf-8?q?ple_from_cli=3B_thanks_to_Christian_Clauss_from_docs=40?= Message-ID: <3Ww3yt0199zPr9@mail.python.org> http://hg.python.org/cpython/rev/c88822747c92 changeset: 78532:c88822747c92 branch: 2.7 parent: 78527:df337391f9f5 user: Sandro Tosi date: Sun Aug 12 17:33:41 2012 +0200 summary: add usage example from cli; thanks to Christian Clauss from docs@ files: Doc/library/webbrowser.rst | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -36,7 +36,9 @@ module. It accepts an URL as the argument. It accepts the following optional parameters: ``-n`` opens the URL in a new browser window, if possible; ``-t`` opens the URL in a new browser page ("tab"). The options are, -naturally, mutually exclusive. +naturally, mutually exclusive. Usage example:: + + python -m webbrowser -t "http://www.python.org" The following exception is defined: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 17:34:31 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 17:34:31 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_add_usage_exam?= =?utf-8?q?ple_from_cli=3B_thanks_to_Christian_Clauss_from_docs=40?= Message-ID: <3Ww3yv3QhJzPtS@mail.python.org> http://hg.python.org/cpython/rev/df4ace12e413 changeset: 78533:df4ace12e413 branch: 3.2 parent: 78529:5617c4a0c035 user: Sandro Tosi date: Sun Aug 12 17:34:00 2012 +0200 summary: add usage example from cli; thanks to Christian Clauss from docs@ files: Doc/library/webbrowser.rst | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -36,7 +36,9 @@ module. It accepts an URL as the argument. It accepts the following optional parameters: ``-n`` opens the URL in a new browser window, if possible; ``-t`` opens the URL in a new browser page ("tab"). The options are, -naturally, mutually exclusive. +naturally, mutually exclusive. Usage example:: + + python -m webbrowser -t "http://www.python.org" The following exception is defined: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 17:34:32 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 17:34:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3Ww3yw6byQzPtr@mail.python.org> http://hg.python.org/cpython/rev/bae08aad33cf changeset: 78534:bae08aad33cf parent: 78531:04788fa08adc parent: 78533:df4ace12e413 user: Sandro Tosi date: Sun Aug 12 17:34:13 2012 +0200 summary: merge with 3.2 files: Doc/library/webbrowser.rst | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Doc/library/webbrowser.rst b/Doc/library/webbrowser.rst --- a/Doc/library/webbrowser.rst +++ b/Doc/library/webbrowser.rst @@ -36,7 +36,9 @@ module. It accepts an URL as the argument. It accepts the following optional parameters: ``-n`` opens the URL in a new browser window, if possible; ``-t`` opens the URL in a new browser page ("tab"). The options are, -naturally, mutually exclusive. +naturally, mutually exclusive. Usage example:: + + python -m webbrowser -t "http://www.python.org" The following exception is defined: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 18:48:07 2012 From: python-checkins at python.org (sandro.tosi) Date: Sun, 12 Aug 2012 18:48:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_complete_cgi?= =?utf-8?q?=2Eparse=28=29_signature=3B_thanks_to_Aaron_Bingham_from_docs?= =?utf-8?q?=40?= Message-ID: <3Ww5bq75lFzPJ9@mail.python.org> http://hg.python.org/cpython/rev/387ceee4e0dd changeset: 78535:387ceee4e0dd branch: 2.7 parent: 78532:c88822747c92 user: Sandro Tosi date: Sun Aug 12 18:47:45 2012 +0200 summary: complete cgi.parse() signature; thanks to Aaron Bingham from docs@ files: Doc/library/cgi.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/cgi.rst b/Doc/library/cgi.rst --- a/Doc/library/cgi.rst +++ b/Doc/library/cgi.rst @@ -284,10 +284,10 @@ algorithms implemented in this module in other circumstances. -.. function:: parse(fp[, keep_blank_values[, strict_parsing]]) +.. function:: parse(fp[, environ[, keep_blank_values[, strict_parsing]]]) Parse a query in the environment or from a file (the file defaults to - ``sys.stdin``). The *keep_blank_values* and *strict_parsing* parameters are + ``sys.stdin`` and environment defaults to ``os.environ``). The *keep_blank_values* and *strict_parsing* parameters are passed to :func:`urlparse.parse_qs` unchanged. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 21:15:43 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 12 Aug 2012 21:15:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NjMw?= =?utf-8?q?=3A_Add_an_example_for_=22continue=22_statement_in_the_tutorial?= =?utf-8?q?=2E_Patch_by?= Message-ID: <3Ww8t748fhzPvx@mail.python.org> http://hg.python.org/cpython/rev/a4d5ac78a76b changeset: 78536:a4d5ac78a76b branch: 2.7 user: Senthil Kumaran date: Sun Aug 12 11:58:53 2012 -0700 summary: Issue #15630: Add an example for "continue" statement in the tutorial. Patch by Daniel Ellis. files: Doc/tutorial/controlflow.rst | 19 ++++++++++++++++--- Misc/NEWS | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -129,9 +129,6 @@ The :keyword:`break` statement, like in C, breaks out of the smallest enclosing :keyword:`for` or :keyword:`while` loop. -The :keyword:`continue` statement, also borrowed from C, continues with the next -iteration of the loop. - Loop statements may have an ``else`` clause; it is executed when the loop terminates through exhaustion of the list (with :keyword:`for`) or when the condition becomes false (with :keyword:`while`), but not when the loop is @@ -166,6 +163,22 @@ occurs. For more on the :keyword:`try` statement and exceptions, see :ref:`tut-handling`. +The :keyword:`continue` statement, also borrowed from C, continues with the next +iteration of the loop:: + + >>> for num in range(2, 10): + ... if x % 2 == 0: + ... print("Found an even number", num) + ... continue + ... print("Found a number", num) + Found an even number 2 + Found a number 3 + Found an even number 4 + Found a number 5 + Found an even number 6 + Found a number 7 + Found an even number 8 + Found a number 9 .. _tut-pass: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -350,6 +350,9 @@ Documentation ------------- +- Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by + Daniel Ellis. + - Issue #13557: Clarify effect of giving two different namespaces to exec or execfile(). -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 21:15:45 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 12 Aug 2012 21:15:45 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NjMw?= =?utf-8?q?=3A_Add_an_example_for_=22continue=22_statement_in_the_tutorial?= =?utf-8?q?=2E_Patch_by?= Message-ID: <3Ww8t92GHCzPwW@mail.python.org> http://hg.python.org/cpython/rev/e855e6c26dfb changeset: 78537:e855e6c26dfb branch: 3.2 parent: 78533:df4ace12e413 user: Senthil Kumaran date: Sun Aug 12 12:01:47 2012 -0700 summary: Issue #15630: Add an example for "continue" statement in the tutorial. Patch by Daniel Ellis. files: Doc/tutorial/controlflow.rst | 19 ++++++++++++++++--- Misc/NEWS | 3 +++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -157,9 +157,6 @@ The :keyword:`break` statement, like in C, breaks out of the smallest enclosing :keyword:`for` or :keyword:`while` loop. -The :keyword:`continue` statement, also borrowed from C, continues with the next -iteration of the loop. - Loop statements may have an ``else`` clause; it is executed when the loop terminates through exhaustion of the list (with :keyword:`for`) or when the condition becomes false (with :keyword:`while`), but not when the loop is @@ -194,6 +191,22 @@ occurs. For more on the :keyword:`try` statement and exceptions, see :ref:`tut-handling`. +The :keyword:`continue` statement, also borrowed from C, continues with the next +iteration of the loop:: + + >>> for num in range(2, 10): + ... if x % 2 == 0: + ... print("Found an even number", num) + ... continue + ... print("Found a number", num) + Found an even number 2 + Found a number 3 + Found an even number 4 + Found a number 5 + Found an even number 6 + Found a number 7 + Found an even number 8 + Found a number 9 .. _tut-pass: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -468,6 +468,9 @@ Documentation ------------- +- Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by + Daniel Ellis. + - Issue #15444: Use proper spelling for non-ASCII contributor names. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 12 21:15:50 2012 From: python-checkins at python.org (senthil.kumaran) Date: Sun, 12 Aug 2012 21:15:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_from_3=2E2?= Message-ID: <3Ww8tG1QMmzPwr@mail.python.org> http://hg.python.org/cpython/rev/dd41c287cf7c changeset: 78538:dd41c287cf7c parent: 78534:bae08aad33cf parent: 78537:e855e6c26dfb user: Senthil Kumaran date: Sun Aug 12 12:13:38 2012 -0700 summary: merge from 3.2 Issue #15630: Add an example for "continue" statement in the tutorial. Patch by Daniel Ellis. files: Doc/tutorial/controlflow.rst | 19 ++++++++++++++++--- Misc/NEWS | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -157,9 +157,6 @@ The :keyword:`break` statement, like in C, breaks out of the smallest enclosing :keyword:`for` or :keyword:`while` loop. -The :keyword:`continue` statement, also borrowed from C, continues with the next -iteration of the loop. - Loop statements may have an ``else`` clause; it is executed when the loop terminates through exhaustion of the list (with :keyword:`for`) or when the condition becomes false (with :keyword:`while`), but not when the loop is @@ -194,6 +191,22 @@ occurs. For more on the :keyword:`try` statement and exceptions, see :ref:`tut-handling`. +The :keyword:`continue` statement, also borrowed from C, continues with the next +iteration of the loop:: + + >>> for num in range(2, 10): + ... if x % 2 == 0: + ... print("Found an even number", num) + ... continue + ... print("Found a number", num) + Found an even number 2 + Found a number 3 + Found an even number 4 + Found a number 5 + Found an even number 6 + Found a number 7 + Found an even number 8 + Found a number 9 .. _tut-pass: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,22 @@ Library ------- +C API +----- + +Extension Modules +----------------- + +Tools/Demos +----------- + +Documentation +------------- + +- Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by + Daniel Ellis. + + What's New in Python 3.3.0 Beta 2? ================================== -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Aug 13 06:05:02 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 13 Aug 2012 06:05:02 +0200 Subject: [Python-checkins] Daily reference leaks (dd41c287cf7c): sum=0 Message-ID: results for dd41c287cf7c on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogsq5zOs', '-x'] From python-checkins at python.org Mon Aug 13 12:00:06 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 12:00:06 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NjI0?= =?utf-8?q?=3A_clarify_newline_documentation_for_open_and_io=2ETextIOWrapp?= =?utf-8?q?er?= Message-ID: <3WwXVZ2KxvzPjy@mail.python.org> http://hg.python.org/cpython/rev/5b629e9fde61 changeset: 78539:5b629e9fde61 branch: 3.2 parent: 78537:e855e6c26dfb user: Andrew Svetlov date: Mon Aug 13 12:58:02 2012 +0300 summary: Issue #15624: clarify newline documentation for open and io.TextIOWrapper Thanks to Chris Jerdonek files: Doc/library/functions.rst | 25 ++++++++++++++----------- Doc/library/io.rst | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -878,18 +878,21 @@ mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * On input, if *newline* is ``None``, universal newlines mode is enabled. - Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these - are translated into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are returned to - the caller untranslated. If it has any of the other legal values, input - lines are only terminated by the given string, and the line ending is - returned to the caller untranslated. + * When reading input from the stream, if *newline* is ``None``, + universal newlines mode is enabled. Lines in the input can end + in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated + into ``'\n'`` before being returned to the caller. If it is + ``''``, universal newline mode is enabled, but line endings are + returned to the caller untranslated. If it has any of the other + legal values, input lines are only terminated by the given + string, and the line ending is returned to the caller + untranslated. - * On output, if *newline* is ``None``, any ``'\n'`` characters written are - translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* - is any of the other legal values, any ``'\n'`` characters written are + * When writing output to the stream, if *newline* is ``None``, any + ``'\n'`` characters written are translated to the system default + line separator, :data:`os.linesep`. If *newline* is ``''`` or + ``'\n'``, no translation takes place. If *newline* is any of the + other legal values, any ``'\n'`` characters written are translated to the given string. If *closefd* is ``False`` and a file descriptor rather than a filename was diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -760,18 +760,21 @@ *newline* controls how line endings are handled. It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * On input, if *newline* is ``None``, universal newlines mode is enabled. - Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these - are translated into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are returned to - the caller untranslated. If it has any of the other legal values, input - lines are only terminated by the given string, and the line ending is - returned to the caller untranslated. + * When reading input from the stream, if *newline* is ``None``, + universal newlines mode is enabled. Lines in the input can end + in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated + into ``'\n'`` before being returned to the caller. If it is + ``''``, universal newline mode is enabled, but line endings are + returned to the caller untranslated. If it has any of the other + legal values, input lines are only terminated by the given + string, and the line ending is returned to the caller + untranslated. - * On output, if *newline* is ``None``, any ``'\n'`` characters written are - translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* - is any of the other legal values, any ``'\n'`` characters written are + * When writing output to the stream, if *newline* is ``None``, any + ``'\n'`` characters written are translated to the system default + line separator, :data:`os.linesep`. If *newline* is ``''`` or + ``'\n'``, no translation takes place. If *newline* is any of the + other legal values, any ``'\n'`` characters written are translated to the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 12:00:08 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 12:00:08 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315624=3A_clarify_newline_documentation_for_open?= =?utf-8?q?_and_io=2ETextIOWrapper?= Message-ID: <3WwXVc2hQNzPk1@mail.python.org> http://hg.python.org/cpython/rev/9e098890ea2c changeset: 78540:9e098890ea2c parent: 78538:dd41c287cf7c parent: 78539:5b629e9fde61 user: Andrew Svetlov date: Mon Aug 13 12:59:00 2012 +0300 summary: Issue #15624: clarify newline documentation for open and io.TextIOWrapper Thanks to Chris Jerdonek files: Doc/library/functions.rst | 25 ++++++++++++++----------- Doc/library/io.rst | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -878,18 +878,21 @@ mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * On input, if *newline* is ``None``, universal newlines mode is enabled. - Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these - are translated into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are returned to - the caller untranslated. If it has any of the other legal values, input - lines are only terminated by the given string, and the line ending is - returned to the caller untranslated. + * When reading input from the stream, if *newline* is ``None``, + universal newlines mode is enabled. Lines in the input can end + in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated + into ``'\n'`` before being returned to the caller. If it is + ``''``, universal newline mode is enabled, but line endings are + returned to the caller untranslated. If it has any of the other + legal values, input lines are only terminated by the given + string, and the line ending is returned to the caller + untranslated. - * On output, if *newline* is ``None``, any ``'\n'`` characters written are - translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* - is any of the other legal values, any ``'\n'`` characters written are + * When writing output to the stream, if *newline* is ``None``, any + ``'\n'`` characters written are translated to the system default + line separator, :data:`os.linesep`. If *newline* is ``''`` or + ``'\n'``, no translation takes place. If *newline* is any of the + other legal values, any ``'\n'`` characters written are translated to the given string. If *closefd* is ``False`` and a file descriptor rather than a filename was diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -770,18 +770,21 @@ *newline* controls how line endings are handled. It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * On input, if *newline* is ``None``, universal newlines mode is enabled. - Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these - are translated into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are returned to - the caller untranslated. If it has any of the other legal values, input - lines are only terminated by the given string, and the line ending is - returned to the caller untranslated. + * When reading input from the stream, if *newline* is ``None``, + universal newlines mode is enabled. Lines in the input can end + in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated + into ``'\n'`` before being returned to the caller. If it is + ``''``, universal newline mode is enabled, but line endings are + returned to the caller untranslated. If it has any of the other + legal values, input lines are only terminated by the given + string, and the line ending is returned to the caller + untranslated. - * On output, if *newline* is ``None``, any ``'\n'`` characters written are - translated to the system default line separator, :data:`os.linesep`. If - *newline* is ``''`` or ``'\n'``, no translation takes place. If *newline* - is any of the other legal values, any ``'\n'`` characters written are + * When writing output to the stream, if *newline* is ``None``, any + ``'\n'`` characters written are translated to the system default + line separator, :data:`os.linesep`. If *newline* is ``''`` or + ``'\n'``, no translation takes place. If *newline* is any of the + other legal values, any ``'\n'`` characters written are translated to the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 15:10:12 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 15:10:12 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315571=3A_comment_?= =?utf-8?q?the_fact_what_python_impl_of_TextIOWrapper_always_works?= Message-ID: <3Wwcjw46J3zPfw@mail.python.org> http://hg.python.org/cpython/rev/ba055ccd99ef changeset: 78541:ba055ccd99ef user: Andrew Svetlov date: Mon Aug 13 16:09:54 2012 +0300 summary: Issue #15571: comment the fact what python impl of TextIOWrapper always works in write_throuth mode files: Lib/_pyio.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1461,6 +1461,9 @@ _CHUNK_SIZE = 2048 + # The write_through argument has no effect here since this + # implementation always writes through. The argument is present only + # so that the signature can match the signature of the C version. def __init__(self, buffer, encoding=None, errors=None, newline=None, line_buffering=False, write_through=False): if newline is not None and not isinstance(newline, str): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 16:10:42 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 16:10:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315151=3A_PEP_362_?= =?utf-8?q?=E2=80=94_document_signature_and_related_classes_for_inspect=2E?= =?utf-8?q?py?= Message-ID: <3Wwf3k0GXQzPjK@mail.python.org> http://hg.python.org/cpython/rev/814462492fbd changeset: 78542:814462492fbd user: Andrew Svetlov date: Mon Aug 13 17:10:28 2012 +0300 summary: Issue #15151: PEP 362 ? document signature and related classes for inspect.py Initial patch by Yury Selivanov files: Doc/library/inspect.rst | 268 ++++++++++++++++++++++++++++ 1 files changed, 268 insertions(+), 0 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -395,6 +395,267 @@ onwards is removed. Also, all tabs are expanded to spaces. +.. _inspect-signature-object: + +Introspecting callables with Signature Object +--------------------------------------------- + +Signature object represents the call signature of a callable object and its +return annotation. To get a Signature object use the :func:`signature` +function. + + +.. versionadded:: 3.3 + +.. seealso:: + + :pep:`362` - Function Signature Object. + The detailed specification, implementation details and examples. + + +.. function:: signature(callable) + + Returns a :class:`Signature` object for the given ``callable``:: + + >>> from inspect import signature + >>> def foo(a, *, b:int, **kwargs): + ... pass + + >>> sig = signature(foo) + + >>> str(sig) + '(a, *, b:int, **kwargs)' + + >>> str(sig.parameters['b']) + 'b:int' + + >>> sig.parameters['b'].annotation + + + Accepts a wide range of python callables, from plain functions and classes + to :func:`functools.partial` objects. + + .. note:: + + Some callables may not be introspectable in certain implementations + of Python. For example, in CPython, built-in functions defined in C + provide no metadata about their arguments. + + +.. class:: Signature + + A Signature object represents the call signature of a function and its + return annotation. For each parameter accepted by the function it + stores a :class:`Parameter` object in its :attr:`parameters` collection. + + Signature objects are *immutable*. Use :meth:`Signature.replace` to make + a modified copy. + + .. attribute:: Signature.empty + + A special class-level marker to specify absence of a return annotation. + + .. attribute:: Signature.parameters + + An ordered mapping of parameters' names to the corresponding + :class:`Parameter` objects. + + .. attribute:: Signature.return_annotation + + The "return" annotation for the callable. If the callable has + no "return" annotation, this attribute is set to + :attr:`Signature.empty`. + + .. method:: Signature.bind(*args, **kwargs) + + Creates a mapping from positional and keyword arguments to parameters. + Returns :class:`BoundArguments` if ``*args`` and ``**kwargs`` match + the signature, or raises a :exc:`TypeError`. + + .. method:: Signature.bind_partial(*args, **kwargs) + + Works the same way as :meth:`Signature.bind`, but allows the + omission of some required arguments (mimics :func:`functools.partial` + behavior.) Returns :class:`BoundArguments`, or raises a :exc:`TypeError` + if the passed arguments do not match the signature. + + .. method:: Signature.replace([parameters], *, [return_annotation]) + + Creates a new Signature instance based on the instance replace was + invoked on. It is possible to pass different ``parameters`` and/or + ``return_annotation`` to override the corresponding properties of + the base signature. To remove return_annotation from the copied + Signature, pass in :attr:`Signature.empty`. + + :: + + >>> def test(a, b): + ... pass + >>> sig = signature(test) + >>> new_sig = sig.replace(return_annotation="new return anno") + >>> str(new_sig) + "(a, b) -> 'new return anno'" + + + +.. class:: Parameter + + Parameter objects are *immutable*. Instead of modifying a Parameter object, + you can use :meth:`Parameter.replace` to create a modified copy. + + .. attribute:: Parameter.empty + + A special class-level marker to specify absence of default + values and annotations. + + .. attribute:: Parameter.name + + The name of the parameter as a string. Must be a valid python identifier + name (with the exception of ``POSITIONAL_ONLY`` parameters, which can + have it set to ``None``.) + + .. attribute:: Parameter.default + + The default value for the parameter. If the parameter has no default + value, this attribute is set to :attr:`Parameter.empty`. + + .. attribute:: Parameter.annotation + + The annotation for the parameter. If the parameter has no annotation, + this attribute is set to :attr:`Parameter.empty`. + + .. attribute:: Parameter.kind + + Describes how argument values are bound to the parameter. + Possible values (accessible via :class:`Parameter`, like + ``Parameter.KEYWORD_ONLY``): + + +------------------------+----------------------------------------------+ + | Name | Meaning | + +========================+==============================================+ + | *POSITIONAL_ONLY* | Value must be supplied as a positional | + | | argument. | + | | | + | | Python has no explicit syntax for defining | + | | positional-only parameters, but many built-in| + | | and extension module functions (especially | + | | those that accept only one or two parameters)| + | | accept them. | + +------------------------+----------------------------------------------+ + | *POSITIONAL_OR_KEYWORD*| Value may be supplied as either a keyword or | + | | positional argument (this is the standard | + | | binding behaviour for functions implemented | + | | in Python.) | + +------------------------+----------------------------------------------+ + | *VAR_POSITIONAL* | A tuple of positional arguments that aren't | + | | bound to any other parameter. This | + | | corresponds to a ``*args`` parameter in a | + | | Python function definition. | + +------------------------+----------------------------------------------+ + | *KEYWORD_ONLY* | Value must be supplied as a keyword argument.| + | | Keyword only parameters are those which | + | | appear after a ``*`` or ``*args`` entry in a | + | | Python function definition. | + +------------------------+----------------------------------------------+ + | *VAR_KEYWORD* | A dict of keyword arguments that aren't bound| + | | to any other parameter. This corresponds to a| + | | ``**kwargs`` parameter in a Python function | + | | definition. | + +------------------------+----------------------------------------------+ + + Print all keyword-only arguments without default values:: + + >>> def foo(a, b, *, c, d=10): + ... pass + + >>> sig = signature(foo) + >>> for param in sig.parameters.values(): + ... if (param.kind == param.KEYWORD_ONLY and + ... param.default is param.empty): + ... print('Parameter:', param) + Parameter: c + + .. method:: Parameter.replace(*, [name], [kind], [default], [annotation]) + + Creates a new Parameter instance based on the instance replaced was + invoked on. To override a :class:`Parameter` attribute, pass the + corresponding argument. To remove a default value or/and an annotation + from a Parameter, pass :attr:`Parameter.empty`. + + :: + + >>> from inspect import Parameter + >>> param = Parameter('foo', Parameter.KEYWORD_ONLY, default=42) + >>> str(param) + 'foo=42' + + >>> str(param.replace()) # Will create a shallow copy of 'param' + 'foo=42' + + >>> str(param.replace(default=Parameter.empty, annotation='spam')) + "foo:'spam'" + + +.. class:: BoundArguments + + Result of a :meth:`Signature.bind` or :meth:`Signature.bind_partial` call. + Holds the mapping of arguments to the function's parameters. + + .. attribute:: BoundArguments.arguments + + An ordered, mutable mapping (:class:`collections.OrderedDict`) of + parameters' names to arguments' values. Contains only explicitly + bound arguments. Changes in :attr:`arguments` will reflect in + :attr:`args` and :attr:`kwargs`. + + Should be used in conjunction with :attr:`Signature.parameters` for + any arguments processing purposes. + + .. note:: + + Arguments for which :meth:`Signature.bind` or + :meth:`Signature.bind_partial` relied on a default value are skipped. + However, if needed, it's easy to include them + + :: + + >>> def foo(a, b=10): + ... pass + + >>> sig = signature(foo) + >>> ba = sig.bind(5) + + >>> ba.args, ba.kwargs + ((5,), {}) + + >>> for param in sig.parameters.values(): + ... if param.name not in ba.arguments: + ... ba.arguments[param.name] = param.default + + >>> ba.args, ba.kwargs + ((5, 10), {}) + + + .. attribute:: BoundArguments.args + + Tuple of positional arguments values. Dynamically computed + from the :attr:`arguments` attribute. + + .. attribute:: BoundArguments.kwargs + + Dict of keyword arguments values. Dynamically computed + from the :attr:`arguments` attribute. + + :attr:`args` and :attr:`kwargs` properties can be used to invoke functions:: + + def test(a, *, b): + ... + + sig = signature(test) + ba = sig.bind(10, b=20) + test(*ba.args, **ba.kwargs) + + .. _inspect-classes-functions: Classes and functions @@ -443,6 +704,10 @@ The first four items in the tuple correspond to :func:`getargspec`. + .. note:: + Consider using the new :ref:`Signature Object ` + interface, which provides a better way of introspecting functions. + .. function:: getargvalues(frame) @@ -505,6 +770,9 @@ .. versionadded:: 3.2 + .. note:: + Consider using the new :meth:`Signature.bind` instead. + .. function:: getclosurevars(func) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 17:24:05 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 17:24:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Minor_update_of_docs_for_i?= =?utf-8?q?nspect_module=2E?= Message-ID: <3WwghP4T7TzPjx@mail.python.org> http://hg.python.org/cpython/rev/843e0da7e91f changeset: 78543:843e0da7e91f user: Andrew Svetlov date: Mon Aug 13 18:23:54 2012 +0300 summary: Minor update of docs for inspect module. files: Doc/library/inspect.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -563,7 +563,7 @@ | | definition. | +------------------------+----------------------------------------------+ - Print all keyword-only arguments without default values:: + Example: print all keyword-only arguments without default values:: >>> def foo(a, b, *, c, d=10): ... pass -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 20:28:07 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 20:28:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Mention_PEP_362=3A_Functio?= =?utf-8?q?n_Signature_Object_in_whatsnew=2E?= Message-ID: <3Wwlml4TlxzPn6@mail.python.org> http://hg.python.org/cpython/rev/db96fe40de54 changeset: 78544:db96fe40de54 user: Andrew Svetlov date: Mon Aug 13 21:27:56 2012 +0300 summary: Mention PEP 362: Function Signature Object in whatsnew. files: Doc/whatsnew/3.3.rst | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) 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 @@ -501,6 +501,23 @@ consumption of programs creating many instances of non-builtin types. +PEP 362: Function Signature Object +================================== + +:pep:`362`: - Function Signature Object + PEP written by Brett Cannon, Yury Selivanov, Larry Hastings, Jiwon Seo. + Implemented by Yury Selivanov. + +A new function :func:`inspect.signature` makes introspection of python +callables easy and straightforward. A broad range of callables is supported: +python functions, decorated or not, classes, and :func:`functools.partial` +objects. New classes :class:`inspect.Signature`, :class:`inspect.Parameter` +and :class:`inspect.BoundArguments` hold information about the call signatures, +such as, annotations, default values, parameters kinds, and bound arguments, +which considerably simplifies writing decorators and any code that validates +or amends calling signatures or arguments. + + Using importlib as the Implementation of Import =============================================== :issue:`2377` - Replace __import__ w/ importlib.__import__ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 20:31:59 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 20:31:59 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?peps=3A_Minor_corrections_in_PEP_362?= =?utf-8?q?=2C_sent_by_Yury_Selivanov=2E?= Message-ID: <3WwlsC1b06zPn6@mail.python.org> http://hg.python.org/peps/rev/872b93d9b814 changeset: 4500:872b93d9b814 user: Andrew Svetlov date: Mon Aug 13 21:31:39 2012 +0300 summary: Minor corrections in PEP 362, sent by Yury Selivanov. files: pep-0362.txt | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-) diff --git a/pep-0362.txt b/pep-0362.txt --- a/pep-0362.txt +++ b/pep-0362.txt @@ -176,7 +176,7 @@ * ``Parameter.VAR_KEYWORD`` - a dict of keyword arguments that aren't bound to any other parameter. This corresponds - to a "\*\*kwds" parameter in a Python function definition. + to a "\*\*kwargs" parameter in a Python function definition. Always use ``Parameter.*`` constants for setting and checking value of the ``kind`` attribute. @@ -391,9 +391,9 @@ def decorator(f): @wraps(f) - def wrapper(*args, **kwds): + def wrapper(*args, **kwargs): full_args = shared_args + args - return f(*full_args, **kwds) + return f(*full_args, **kwargs) # Override signature sig = signature(f) @@ -488,14 +488,9 @@ # If the argument has a type specified, let's check that its # default value (if present) conforms with the type. - try: - default = param.default - except AttributeError: - continue - else: - if not isinstance(default, type_): - raise ValueError("{func}: wrong type of a default value for {arg!r}". \ - format(func=func.__qualname__, arg=param.name)) + if param.default is not param.empty and not isinstance(param.default, type_): + raise ValueError("{func}: wrong type of a default value for {arg!r}". \ + format(func=func.__qualname__, arg=param.name)) def check_type(sig, arg_name, arg_type, arg_value): # Internal function that encapsulates arguments type checking -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Mon Aug 13 21:11:27 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 21:11:27 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NTYx?= =?utf-8?q?=3A_Update_subprocess_docs_to_reference_io=2ETextIOWrapper=2E?= Message-ID: <3Wwmkl3VXdzPpc@mail.python.org> http://hg.python.org/cpython/rev/381aaf79c254 changeset: 78545:381aaf79c254 branch: 3.2 parent: 78539:5b629e9fde61 user: Andrew Svetlov date: Mon Aug 13 22:09:04 2012 +0300 summary: Issue #15561: Update subprocess docs to reference io.TextIOWrapper. Patch by Chris Jerdonek. files: Doc/library/subprocess.rst | 40 +++++++++++++------------ 1 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -136,7 +136,7 @@ decoding to text will often need to be handled at the application level. This behaviour may be overridden by setting *universal_newlines* to - :const:`True` as described below in :ref:`frequently-used-arguments`. + ``True`` as described below in :ref:`frequently-used-arguments`. To also capture standard error in the result, use ``stderr=subprocess.STDOUT``:: @@ -224,13 +224,24 @@ the stderr data from the child process should be captured into the same file handle as for stdout. - When *stdout* or *stderr* are pipes and *universal_newlines* is - :const:`True` then the output data is assumed to be encoded as UTF-8 and - will automatically be decoded to text. All line endings will be converted - to ``'\n'`` as described for the universal newlines ``'U'`` mode argument - to :func:`open`. + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* + and *stderr* will be opened as text streams with universal newlines support, + using the encoding returned by :func:`locale.getpreferredencoding`. + For *stdin*, line ending characters ``'\n'`` in the input will be converted + to the default line separator :data:`os.linesep`. For *stdout* and + *stderr*, all line endings in the output will be converted to ``'\n'``. + For more information see the documentation of the :class:`io.TextIOWrapper` + class when the *newline* argument to its constructor is ``None``. - If *shell* is :const:`True`, the specified command will be executed through + .. note:: + + The *universal_newlines* feature is supported only if Python is built + with universal newline support (the default). Also, the newlines + attribute of the file objects :attr:`Popen.stdin`, :attr:`Popen.stdout` + and :attr:`Popen.stderr` are not updated by the + :meth:`Popen.communicate` method. + + If *shell* is ``True``, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want access to other shell features such as filename wildcards, shell pipes and @@ -428,18 +439,9 @@ .. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly - If *universal_newlines* is :const:`True`, the file objects stdout and stderr are - opened as text files, but lines may be terminated by any of ``'\n'``, the Unix - end-of-line convention, ``'\r'``, the old Macintosh convention or ``'\r\n'``, the - Windows convention. All of these external representations are seen as ``'\n'`` - by the Python program. - - .. note:: - - This feature is only available if Python is built with universal newline - support (the default). Also, the newlines attribute of the file objects - :attr:`stdout`, :attr:`stdin` and :attr:`stderr` are not updated by the - :meth:`communicate` method. + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* + and *stderr* are opened as text files with universal newlines support, as + described above in :ref:`frequently-used-arguments`. If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is passed to the underlying ``CreateProcess`` function. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 21:11:29 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 21:11:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315561=3A_Update_subprocess_docs_to_reference_io?= =?utf-8?q?=2ETextIOWrapper=2E?= Message-ID: <3Wwmkn41ZmzPrC@mail.python.org> http://hg.python.org/cpython/rev/0cd9423770fa changeset: 78546:0cd9423770fa parent: 78544:db96fe40de54 parent: 78545:381aaf79c254 user: Andrew Svetlov date: Mon Aug 13 22:11:14 2012 +0300 summary: Issue #15561: Update subprocess docs to reference io.TextIOWrapper. Patch by Chris Jerdonek. files: Doc/library/io.rst | 3 +- Doc/library/subprocess.rst | 46 +++++++++++++++---------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -754,7 +754,8 @@ It inherits :class:`TextIOBase`. *encoding* gives the name of the encoding that the stream will be decoded or - encoded with. It defaults to ``locale.getpreferredencoding(False)``. + encoded with. It defaults to + :func:`locale.getpreferredencoding(False) `. *errors* is an optional string that specifies how encoding and decoding errors are to be handled. Pass ``'strict'`` to raise a :exc:`ValueError` diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -156,7 +156,7 @@ decoding to text will often need to be handled at the application level. This behaviour may be overridden by setting *universal_newlines* to - :const:`True` as described below in :ref:`frequently-used-arguments`. + ``True`` as described below in :ref:`frequently-used-arguments`. To also capture standard error in the result, use ``stderr=subprocess.STDOUT``:: @@ -285,18 +285,35 @@ :data:`STDOUT`, which indicates that the stderr data from the child process should be captured into the same file handle as for *stdout*. - When *stdout* or *stderr* are pipes and *universal_newlines* is - :const:`True` then the output data is assumed to be encoded as UTF-8 and - will automatically be decoded to text. All line endings will be converted - to ``'\n'`` as described for the universal newlines ``'U'`` mode argument - to :func:`open`. + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* + and *stderr* will be opened as text streams with universal newlines support, + using the encoding returned by :func:`locale.getpreferredencoding`. + For *stdin*, line ending characters ``'\n'`` in the input will be converted + to the default line separator :data:`os.linesep`. For *stdout* and + *stderr*, all line endings in the output will be converted to ``'\n'``. + For more information see the documentation of the :class:`io.TextIOWrapper` + class when the *newline* argument to its constructor is ``None``. - If *shell* is :const:`True`, the specified command will be executed through + .. note:: + + The *universal_newlines* feature is supported only if Python is built + with universal newline support (the default). Also, the newlines + attribute of the file objects :attr:`Popen.stdin`, :attr:`Popen.stdout` + and :attr:`Popen.stderr` are not updated by the + :meth:`Popen.communicate` method. + + If *shell* is ``True``, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the enhanced control flow it offers over most system shells and still want access to other shell features such as filename wildcards, shell pipes and environment variable expansion. + .. versionchanged:: 3.3 + When *universal_newlines* is ``True``, the class uses the encoding + :func:`locale.getpreferredencoding(False) ` + instead of ``locale.getpreferredencoding()``. See the + :class:`io.TextIOWrapper` class for more information on this change. + .. warning:: Executing shell commands that incorporate unsanitized input from an @@ -490,18 +507,9 @@ .. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly - If *universal_newlines* is :const:`True`, the file objects stdout and stderr are - opened as text files, but lines may be terminated by any of ``'\n'``, the Unix - end-of-line convention, ``'\r'``, the old Macintosh convention or ``'\r\n'``, the - Windows convention. All of these external representations are seen as ``'\n'`` - by the Python program. - - .. note:: - - This feature is only available if Python is built with universal newline - support (the default). Also, the newlines attribute of the file objects - :attr:`stdout`, :attr:`stdin` and :attr:`stderr` are not updated by the - :meth:`communicate` method. + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* + and *stderr* are opened as text files with universal newlines support, as + described above in :ref:`frequently-used-arguments`. If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is passed to the underlying ``CreateProcess`` function. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 21:19:10 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 21:19:10 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Push_importlib_ABC_hierarc?= =?utf-8?q?hy_chart=2E?= Message-ID: <3Wwmvf0TfYzPmf@mail.python.org> http://hg.python.org/cpython/rev/1c8a6df94602 changeset: 78547:1c8a6df94602 user: Andrew Svetlov date: Mon Aug 13 22:19:01 2012 +0300 summary: Push importlib ABC hierarchy chart. files: Doc/library/importlib.rst | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -121,6 +121,21 @@ used by :keyword:`import`. Some subclasses of the core abstract base classes are also provided to help in implementing the core ABCs. +ABC hierarchy:: + + object + +-- Finder + | +-- MetaPathFinder + | +-- PathEntryFinder + +-- Loader + +-- ResourceLoader --------+ + +-- InspectLoader | + +-- ExecutionLoader --+ + +-- FileLoader + +-- SourceLoader + +-- PyLoader + +-- PyPycLoader + .. class:: Finder -- Repository URL: http://hg.python.org/cpython From brett at python.org Mon Aug 13 21:37:46 2012 From: brett at python.org (Brett Cannon) Date: Mon, 13 Aug 2012 15:37:46 -0400 Subject: [Python-checkins] cpython: Push importlib ABC hierarchy chart. In-Reply-To: <3Wwmvf0TfYzPmf@mail.python.org> References: <3Wwmvf0TfYzPmf@mail.python.org> Message-ID: For documentation, this appears to be for http://bugs.python.org/issue15628 . On Mon, Aug 13, 2012 at 3:19 PM, andrew.svetlov wrote: > http://hg.python.org/cpython/rev/1c8a6df94602 > changeset: 78547:1c8a6df94602 > user: Andrew Svetlov > date: Mon Aug 13 22:19:01 2012 +0300 > summary: > Push importlib ABC hierarchy chart. > > files: > Doc/library/importlib.rst | 15 +++++++++++++++ > 1 files changed, 15 insertions(+), 0 deletions(-) > > > diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst > --- a/Doc/library/importlib.rst > +++ b/Doc/library/importlib.rst > @@ -121,6 +121,21 @@ > used by :keyword:`import`. Some subclasses of the core abstract base > classes > are also provided to help in implementing the core ABCs. > > +ABC hierarchy:: > + > + object > + +-- Finder > + | +-- MetaPathFinder > + | +-- PathEntryFinder > + +-- Loader > + +-- ResourceLoader --------+ > + +-- InspectLoader | > + +-- ExecutionLoader --+ > + +-- FileLoader > + +-- SourceLoader > + +-- PyLoader > + +-- PyPycLoader > + > > .. class:: Finder > > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Mon Aug 13 22:26:48 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 22:26:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NDk3?= =?utf-8?q?=3A_Correct_characters_in_TextWrapper=2Ereplace=5Fwhitespace_do?= =?utf-8?b?Y3Mu?= Message-ID: <3WwpPh50BRzPrd@mail.python.org> http://hg.python.org/cpython/rev/90a8a462d2f7 changeset: 78548:90a8a462d2f7 branch: 3.2 parent: 78545:381aaf79c254 user: Andrew Svetlov date: Mon Aug 13 23:22:23 2012 +0300 summary: Issue #15497: Correct characters in TextWrapper.replace_whitespace docs. Patch by Chris Jerdonek. files: Doc/library/textwrap.rst | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/library/textwrap.rst b/Doc/library/textwrap.rst --- a/Doc/library/textwrap.rst +++ b/Doc/library/textwrap.rst @@ -109,9 +109,11 @@ .. attribute:: replace_whitespace - (default: ``True``) If true, each whitespace character (as defined by - ``string.whitespace``) remaining after tab expansion will be replaced by a - single space. + (default: ``True``) If true, after tab expansion but before wrapping, + the :meth:`wrap` method will replace each whitespace character + with a single space. The whitespace characters replaced are + as follows: tab, newline, vertical tab, formfeed, and carriage + return (``'\t\n\v\f\r'``). .. note:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 22:26:50 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 22:26:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315497=3A_Correct_characters_in_TextWrapper=2Ere?= =?utf-8?q?place=5Fwhitespace_docs=2E?= Message-ID: <3WwpPk425dzPsZ@mail.python.org> http://hg.python.org/cpython/rev/edcbf3edf701 changeset: 78549:edcbf3edf701 parent: 78547:1c8a6df94602 parent: 78548:90a8a462d2f7 user: Andrew Svetlov date: Mon Aug 13 23:23:02 2012 +0300 summary: Issue #15497: Correct characters in TextWrapper.replace_whitespace docs. Patch by Chris Jerdonek. files: Doc/library/textwrap.rst | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/library/textwrap.rst b/Doc/library/textwrap.rst --- a/Doc/library/textwrap.rst +++ b/Doc/library/textwrap.rst @@ -145,9 +145,11 @@ .. attribute:: replace_whitespace - (default: ``True``) If true, each whitespace character (as defined by - ``string.whitespace``) remaining after tab expansion will be replaced by a - single space. + (default: ``True``) If true, after tab expansion but before wrapping, + the :meth:`wrap` method will replace each whitespace character + with a single space. The whitespace characters replaced are + as follows: tab, newline, vertical tab, formfeed, and carriage + return (``'\t\n\v\f\r'``). .. note:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 13 22:26:52 2012 From: python-checkins at python.org (andrew.svetlov) Date: Mon, 13 Aug 2012 22:26:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NDk3?= =?utf-8?q?=3A_Correct_characters_in_TextWrapper=2Ereplace=5Fwhitespace_do?= =?utf-8?b?Y3Mu?= Message-ID: <3WwpPm1yfPzPt5@mail.python.org> http://hg.python.org/cpython/rev/3bddc965e2ea changeset: 78550:3bddc965e2ea branch: 2.7 parent: 78536:a4d5ac78a76b user: Andrew Svetlov date: Mon Aug 13 23:26:28 2012 +0300 summary: Issue #15497: Correct characters in TextWrapper.replace_whitespace docs. Patch by Chris Jerdonek. files: Doc/library/textwrap.rst | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/library/textwrap.rst b/Doc/library/textwrap.rst --- a/Doc/library/textwrap.rst +++ b/Doc/library/textwrap.rst @@ -112,9 +112,11 @@ .. attribute:: replace_whitespace - (default: ``True``) If true, each whitespace character (as defined by - ``string.whitespace``) remaining after tab expansion will be replaced by a - single space. + (default: ``True``) If true, after tab expansion but before wrapping, + the :meth:`wrap` method will replace each whitespace character + with a single space. The whitespace characters replaced are + as follows: tab, newline, vertical tab, formfeed, and carriage + return (``'\t\n\v\f\r'``). .. note:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 00:13:14 2012 From: python-checkins at python.org (brian.curtin) Date: Tue, 14 Aug 2012 00:13:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogRml4ICMxNTQ5Ni4g?= =?utf-8?q?Add_directory_removal_helpers_to_make_Windows_tests_more_reliab?= =?utf-8?b?bGUu?= Message-ID: <3WwrmV3dYMzPt2@mail.python.org> http://hg.python.org/cpython/rev/fcad4566910b changeset: 78551:fcad4566910b branch: 3.2 parent: 78548:90a8a462d2f7 user: Brian Curtin date: Mon Aug 13 17:05:57 2012 -0500 summary: Fix #15496. Add directory removal helpers to make Windows tests more reliable. Patch by Jeremy Kloth files: Lib/test/support.py | 68 ++++++++++++++++++++++++++++++++- Misc/NEWS | 3 + 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -200,17 +200,81 @@ except KeyError: pass +if sys.platform.startswith("win"): + def _waitfor(func, pathname, waitall=False): + # Peform the operation + func(pathname) + # Now setup the wait loop + if waitall: + dirname = pathname + else: + dirname, name = os.path.split(pathname) + dirname = dirname or '.' + # Check for `pathname` to be removed from the filesystem. + # The exponential backoff of the timeout amounts to a total + # of ~1 second after which the deletion is probably an error + # anyway. + # Testing on a i7 at 4.3GHz shows that usually only 1 iteration is + # required when contention occurs. + timeout = 0.001 + while timeout < 1.0: + # Note we are only testing for the existance of the file(s) in + # the contents of the directory regardless of any security or + # access rights. If we have made it this far, we have sufficient + # permissions to do that much using Python's equivalent of the + # Windows API FindFirstFile. + # Other Windows APIs can fail or give incorrect results when + # dealing with files that are pending deletion. + L = os.listdir(dirname) + if not (L if waitall else name in L): + return + # Increase the timeout and try again + time.sleep(timeout) + timeout *= 2 + warnings.warn('tests may fail, delete still pending for ' + pathname, + RuntimeWarning, stacklevel=4) + + def _unlink(filename): + _waitfor(os.unlink, filename) + + def _rmdir(dirname): + _waitfor(os.rmdir, dirname) + + def _rmtree(path): + def _rmtree_inner(path): + for name in os.listdir(path): + fullname = os.path.join(path, name) + if os.path.isdir(fullname): + _waitfor(_rmtree_inner, fullname, waitall=True) + os.rmdir(fullname) + else: + os.unlink(fullname) + _waitfor(_rmtree_inner, path, waitall=True) + _waitfor(os.rmdir, path) +else: + _unlink = os.unlink + _rmdir = os.rmdir + _rmtree = shutil.rmtree + def unlink(filename): try: - os.unlink(filename) + _unlink(filename) except OSError as error: # The filename need not exist. if error.errno not in (errno.ENOENT, errno.ENOTDIR): raise +def rmdir(dirname): + try: + _rmdir(dirname) + except OSError as error: + # The directory need not exist. + if error.errno != errno.ENOENT: + raise + def rmtree(path): try: - shutil.rmtree(path) + _rmtree(path) except OSError as error: # Unix returns ENOENT, Windows returns ESRCH. if error.errno not in (errno.ENOENT, errno.ESRCH): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -413,6 +413,9 @@ Tests ----- +- Issue #15496: Add directory removal helpers for tests on Windows. + Patch by Jeremy Kloth. + - Issue #15467: Move helpers for __sizeof__ tests into test_support. Patch by Serhiy Storchaka. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 00:13:16 2012 From: python-checkins at python.org (brian.curtin) Date: Tue, 14 Aug 2012 00:13:16 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4y?= Message-ID: <3WwrmX1nQgzPtV@mail.python.org> http://hg.python.org/cpython/rev/256bfee696c5 changeset: 78552:256bfee696c5 parent: 78549:edcbf3edf701 parent: 78551:fcad4566910b user: Brian Curtin date: Mon Aug 13 17:12:02 2012 -0500 summary: Merge 3.2 files: Lib/test/support.py | 68 +++++++- Misc/NEWS | 265 ++++++++++++++++++++++++++++++++ 2 files changed, 331 insertions(+), 2 deletions(-) diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -225,17 +225,81 @@ except KeyError: pass +if sys.platform.startswith("win"): + def _waitfor(func, pathname, waitall=False): + # Peform the operation + func(pathname) + # Now setup the wait loop + if waitall: + dirname = pathname + else: + dirname, name = os.path.split(pathname) + dirname = dirname or '.' + # Check for `pathname` to be removed from the filesystem. + # The exponential backoff of the timeout amounts to a total + # of ~1 second after which the deletion is probably an error + # anyway. + # Testing on a i7 at 4.3GHz shows that usually only 1 iteration is + # required when contention occurs. + timeout = 0.001 + while timeout < 1.0: + # Note we are only testing for the existance of the file(s) in + # the contents of the directory regardless of any security or + # access rights. If we have made it this far, we have sufficient + # permissions to do that much using Python's equivalent of the + # Windows API FindFirstFile. + # Other Windows APIs can fail or give incorrect results when + # dealing with files that are pending deletion. + L = os.listdir(dirname) + if not (L if waitall else name in L): + return + # Increase the timeout and try again + time.sleep(timeout) + timeout *= 2 + warnings.warn('tests may fail, delete still pending for ' + pathname, + RuntimeWarning, stacklevel=4) + + def _unlink(filename): + _waitfor(os.unlink, filename) + + def _rmdir(dirname): + _waitfor(os.rmdir, dirname) + + def _rmtree(path): + def _rmtree_inner(path): + for name in os.listdir(path): + fullname = os.path.join(path, name) + if os.path.isdir(fullname): + _waitfor(_rmtree_inner, fullname, waitall=True) + os.rmdir(fullname) + else: + os.unlink(fullname) + _waitfor(_rmtree_inner, path, waitall=True) + _waitfor(os.rmdir, path) +else: + _unlink = os.unlink + _rmdir = os.rmdir + _rmtree = shutil.rmtree + def unlink(filename): try: - os.unlink(filename) + _unlink(filename) except OSError as error: # The filename need not exist. if error.errno not in (errno.ENOENT, errno.ENOTDIR): raise +def rmdir(dirname): + try: + _rmdir(dirname) + except OSError as error: + # The directory need not exist. + if error.errno != errno.ENOENT: + raise + def rmtree(path): try: - shutil.rmtree(path) + _rmtree(path) except OSError as error: if error.errno != errno.ENOENT: raise diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2004,6 +2004,271 @@ - Issue #8033: sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures. Initial patch by Philippe Devalkeneer. +<<<<<<< local +======= +Extension Modules +----------------- + +- Issue #6493: An issue in ctypes on Windows that caused structure bitfields + of type ctypes.c_uint32 and width 32 to incorrectly be set has been fixed. + +- Issue #15000: Support the "unique" x32 architecture in _posixsubprocess.c. + +- Issue #9041: An issue in ctypes.c_longdouble, ctypes.c_double, and + ctypes.c_float that caused an incorrect exception to be returned in the + case of overflow has been fixed. + +- Issue #14212: The re module didn't retain a reference to buffers it was + scanning, resulting in segfaults. + +Tests +----- + +- Issue #15496: Add directory removal helpers for tests on Windows. + Patch by Jeremy Kloth. + +- Issue #15467: Move helpers for __sizeof__ tests into test_support. + Patch by Serhiy Storchaka. + +- Issue #15320: Make iterating the list of tests thread-safe when running + tests in multiprocess mode. Patch by Chris Jerdonek. + +- Issue #15230: Adopted a more systematic approach in the runpy tests + +- Issue #15300: Ensure the temporary test working directories are in the same + parent folder when running tests in multiprocess mode from a Python build. + Patch by Chris Jerdonek. + +- test_nntplib now tolerates being run from behind NNTP gateways that add + "X-Antivirus" headers to articles + +- Issue #15043: test_gdb is now skipped entirely if gdb security settings + block loading of the gdb hooks + +- Issue #14026: In test_cmd_line_script, check that sys.argv is populated + correctly for the various invocation approaches (Patch by Jason Yeo) + +- Issue #14032: Fix incorrect variable name in test_cmd_line_script debugging + message (Patch by Jason Yeo) + +- Issue #14589: Update certificate chain for sha256.tbs-internet.com, fixing + a test failure in test_ssl. + +Build +----- + +- Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. + +- Issue #8847: Disable COMDAT folding in Windows PGO builds. + +- Issue #14197: For OS X framework builds, ensure links to the shared + library are created with the proper ABI suffix. + +- Issue #14472: Update .gitignore. Patch by Matej Cepl. + +- The Windows build now uses OpenSSL 1.0.0j and bzip2 1.0.6. + +- Issue #14557: Fix extensions build on HP-UX. Patch by Adi Roiban. + +- Issue #14437: Fix building the _io module under Cygwin. + +- Issue #14387: Do not include accu.h from Python.h. + +- Issue #14359: Only use O_CLOEXEC in _posixmodule.c if it is defined. + Based on patch from Herv? Coatanhay. + +- Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. + +Documentation +------------- + +- Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by + Daniel Ellis. + +- Issue #15444: Use proper spelling for non-ASCII contributor names. Patch + by Serhiy Storchaka. + +- Issue 15482: Properly document the default 'level' value for __import__() + while warning about using negative values. + +- Issue #15230: Clearly document some of the limitations of the runpy + module and nudge readers towards importlib when appropriate. + +- Issue #13557: Clarify effect of giving two different namespaces to exec or + execfile(). + +- Issue #8799: Fix and improve the threading.Condition documentation. + +- Issue #14943: Correct a default argument value for winreg.OpenKey + and correctly list the argument names in the function's explanation. + +- Issue #14034: added the argparse tutorial. + +- Issue #15250: Document that filecmp.dircmp compares files shallowly. Patch + contributed by Chris Jerdonek. + +Tools/Demos +----------- + +- Issue #14695: Fix missing support for starred assignments in + Tools/parser/unparse.py. + + +What's New in Python 3.2.3? +=========================== + +*Release date: 10-Apr-2012* + +Build +----- + +- Issue #14387: Work around a problem building extension modules under Windows + by undefining ``small`` before use in the Python headers. + + +What's New in Python 3.2.3 release candidate 2? +=============================================== + +*Release date: 18-Mar-2012* + +Library +------- + +- Issue #6884: Fix long-standing bugs with MANIFEST.in parsing in distutils + on Windows. + +Extension Modules +----------------- + +- Issue #14234: CVE-2012-0876: Randomize hashes of xml attributes in the hash + table internal to the pyexpat module's copy of the expat library to avoid a + denial of service due to hash collisions. Patch by David Malcolm with some + modifications by the expat project. + + +What's New in Python 3.2.3 release candidate 1? +=============================================== + +*Release date: 24-Feb-2012* + +Core and Builtins +----------------- + +- Issue #13703: oCERT-2011-003: add -R command-line option and PYTHONHASHSEED + environment variable, to provide an opt-in way to protect against denial of + service attacks due to hash collisions within the dict and set types. Patch + by David Malcolm, based on work by Victor Stinner. + +- Issue #14084: Fix a file descriptor leak when importing a module with a + bad encoding. + +- Issue #13020: Fix a reference leak when allocating a structsequence object + fails. Patch by Suman Saha. + +- Issue #13908: Ready types returned from PyType_FromSpec. + +- Issue #11235: Fix OverflowError when trying to import a source file whose + modification time doesn't fit in a 32-bit timestamp. + +- Fix the builtin module initialization code to store the init function for + future reinitialization. + +- Issue #8052: The posix subprocess module would take a long time closing + all possible file descriptors in the child process rather than just open + file descriptors. It now closes only the open fds if possible for the + default close_fds=True behavior. + +- Issue #13629: Renumber the tokens in token.h so that they match the indexes + into _PyParser_TokenNames. + +- Fix the fix for issue #12149: it was incorrect, although it had the side + effect of appearing to resolve the issue. Thanks to Mark Shannon for + noticing. + +- Issue #13505: Pickle bytes objects in a way that is compatible with + Python 2 when using protocols <= 2. + +- Issue #11147: Fix an unused argument in _Py_ANNOTATE_MEMORY_ORDER. (Fix + given by Campbell Barton). + +- Issue #7111: Python can now be run without a stdin, stdout or stderr + stream. It was already the case with Python 2. However, the corresponding + sys module entries are now set to None (instead of an unusable file object). + +- Issue #13436: Fix a bogus error message when an AST object was passed + an invalid integer value. + +- Issue #13338: Handle all enumerations in _Py_ANNOTATE_MEMORY_ORDER + to allow compiling extension modules with -Wswitch-enum on gcc. + Initial patch by Floris Bruynooghe. + +- Issue #13333: The UTF-7 decoder now accepts lone surrogates (the encoder + already accepts them). + +- Issue #13342: input() used to ignore sys.stdin's and sys.stdout's unicode + error handler in interactive mode (when calling into PyOS_Readline()). + +- Issue #13343: Fix a SystemError when a lambda expression uses a global + variable in the default value of a keyword-only argument: + (lambda *, arg=GLOBAL_NAME: None) + +- Issue #10519: Avoid unnecessary recursive function calls in + setobject.c. + +- Issue #10363: Deallocate global locks in Py_Finalize(). + +- Issue #13018: Fix reference leaks in error paths in dictobject.c. + Patch by Suman Saha. + +- Issue #1294232: In a few cases involving metaclass inheritance, the + interpreter would sometimes invoke the wrong metaclass when building a new + class object. These cases now behave correctly. Patch by Daniel Urban. + +- Issue #12604: VTRACE macro expanded to no-op in _sre.c to avoid compiler + warnings. Patch by Josh Triplett and Petri Lehtinen. + +- Issue #13188: When called without an explicit traceback argument, + generator.throw() now gets the traceback from the passed exception's + ``__traceback__`` attribute. Patch by Petri Lehtinen. + +- Issue #7833: Extension modules built using distutils on Windows will no + longer include a "manifest" to prevent them failing at import time in some + embedded situations. + +- Issue #13063: the Windows error ERROR_NO_DATA (numbered 232 and described + as "The pipe is being closed") is now mapped to POSIX errno EPIPE + (previously EINVAL). + +- Issue #12911: Fix memory consumption when calculating the repr() of huge + tuples or lists. + +- Issue #7732: Don't open a directory as a file anymore while importing a + module. Ignore the direcotry if its name matchs the module name (e.g. + "__init__.py") and raise a ImportError instead. + +- Issue #13021: Missing decref on an error path. Thanks to Suman Saha for + finding the bug and providing a patch. + +- Issue #12973: Fix overflow checks that relied on undefined behaviour in + list_repeat (listobject.c) and islice_next (itertoolsmodule.c). These bugs + caused test failures with recent versions of Clang. + +- Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now + mapped to POSIX errno ENOTDIR (previously EINVAL). + +- Issue #9200: The str.is* methods now work with strings that contain non-BMP + characters even in narrow Unicode builds. + +- Issue #12791: Break reference cycles early when a generator exits with + an exception. + +- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase + titlecased and cased non-letter characters. + +Library +------- + +>>>>>>> other - HTMLParser is now able to handle slashes in the start tag. - Issue #13641: Decoding functions in the base64 module now accept ASCII-only -- Repository URL: http://hg.python.org/cpython From brian at python.org Tue Aug 14 00:15:06 2012 From: brian at python.org (Brian Curtin) Date: Mon, 13 Aug 2012 17:15:06 -0500 Subject: [Python-checkins] cpython (merge 3.2 -> default): Merge 3.2 In-Reply-To: <3WwrmX1nQgzPtV@mail.python.org> References: <3WwrmX1nQgzPtV@mail.python.org> Message-ID: On Mon, Aug 13, 2012 at 5:13 PM, brian.curtin wrote: > http://hg.python.org/cpython/rev/256bfee696c5 > changeset: 78552:256bfee696c5 > parent: 78549:edcbf3edf701 > parent: 78551:fcad4566910b > user: Brian Curtin > date: Mon Aug 13 17:12:02 2012 -0500 > summary: > Merge 3.2 > > files: > Lib/test/support.py | 68 +++++++- > Misc/NEWS | 265 ++++++++++++++++++++++++++++++++ this Misc/NEWS disaster didn't appear in the diff. Fixing now... From python-checkins at python.org Tue Aug 14 00:20:16 2012 From: python-checkins at python.org (brian.curtin) Date: Tue, 14 Aug 2012 00:20:16 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_errant_merge_problem_commi?= =?utf-8?q?tted?= Message-ID: <3Wwrwc13QdzPtr@mail.python.org> http://hg.python.org/cpython/rev/70f7559e6d0f changeset: 78553:70f7559e6d0f user: Brian Curtin date: Mon Aug 13 17:20:00 2012 -0500 summary: errant merge problem committed files: Misc/NEWS | 265 ------------------------------------------ 1 files changed, 0 insertions(+), 265 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2004,271 +2004,6 @@ - Issue #8033: sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures. Initial patch by Philippe Devalkeneer. -<<<<<<< local -======= -Extension Modules ------------------ - -- Issue #6493: An issue in ctypes on Windows that caused structure bitfields - of type ctypes.c_uint32 and width 32 to incorrectly be set has been fixed. - -- Issue #15000: Support the "unique" x32 architecture in _posixsubprocess.c. - -- Issue #9041: An issue in ctypes.c_longdouble, ctypes.c_double, and - ctypes.c_float that caused an incorrect exception to be returned in the - case of overflow has been fixed. - -- Issue #14212: The re module didn't retain a reference to buffers it was - scanning, resulting in segfaults. - -Tests ------ - -- Issue #15496: Add directory removal helpers for tests on Windows. - Patch by Jeremy Kloth. - -- Issue #15467: Move helpers for __sizeof__ tests into test_support. - Patch by Serhiy Storchaka. - -- Issue #15320: Make iterating the list of tests thread-safe when running - tests in multiprocess mode. Patch by Chris Jerdonek. - -- Issue #15230: Adopted a more systematic approach in the runpy tests - -- Issue #15300: Ensure the temporary test working directories are in the same - parent folder when running tests in multiprocess mode from a Python build. - Patch by Chris Jerdonek. - -- test_nntplib now tolerates being run from behind NNTP gateways that add - "X-Antivirus" headers to articles - -- Issue #15043: test_gdb is now skipped entirely if gdb security settings - block loading of the gdb hooks - -- Issue #14026: In test_cmd_line_script, check that sys.argv is populated - correctly for the various invocation approaches (Patch by Jason Yeo) - -- Issue #14032: Fix incorrect variable name in test_cmd_line_script debugging - message (Patch by Jason Yeo) - -- Issue #14589: Update certificate chain for sha256.tbs-internet.com, fixing - a test failure in test_ssl. - -Build ------ - -- Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. - -- Issue #8847: Disable COMDAT folding in Windows PGO builds. - -- Issue #14197: For OS X framework builds, ensure links to the shared - library are created with the proper ABI suffix. - -- Issue #14472: Update .gitignore. Patch by Matej Cepl. - -- The Windows build now uses OpenSSL 1.0.0j and bzip2 1.0.6. - -- Issue #14557: Fix extensions build on HP-UX. Patch by Adi Roiban. - -- Issue #14437: Fix building the _io module under Cygwin. - -- Issue #14387: Do not include accu.h from Python.h. - -- Issue #14359: Only use O_CLOEXEC in _posixmodule.c if it is defined. - Based on patch from Herv? Coatanhay. - -- Issue #14018: Fix OS X Tcl/Tk framework checking when using OS X SDKs. - -Documentation -------------- - -- Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by - Daniel Ellis. - -- Issue #15444: Use proper spelling for non-ASCII contributor names. Patch - by Serhiy Storchaka. - -- Issue 15482: Properly document the default 'level' value for __import__() - while warning about using negative values. - -- Issue #15230: Clearly document some of the limitations of the runpy - module and nudge readers towards importlib when appropriate. - -- Issue #13557: Clarify effect of giving two different namespaces to exec or - execfile(). - -- Issue #8799: Fix and improve the threading.Condition documentation. - -- Issue #14943: Correct a default argument value for winreg.OpenKey - and correctly list the argument names in the function's explanation. - -- Issue #14034: added the argparse tutorial. - -- Issue #15250: Document that filecmp.dircmp compares files shallowly. Patch - contributed by Chris Jerdonek. - -Tools/Demos ------------ - -- Issue #14695: Fix missing support for starred assignments in - Tools/parser/unparse.py. - - -What's New in Python 3.2.3? -=========================== - -*Release date: 10-Apr-2012* - -Build ------ - -- Issue #14387: Work around a problem building extension modules under Windows - by undefining ``small`` before use in the Python headers. - - -What's New in Python 3.2.3 release candidate 2? -=============================================== - -*Release date: 18-Mar-2012* - -Library -------- - -- Issue #6884: Fix long-standing bugs with MANIFEST.in parsing in distutils - on Windows. - -Extension Modules ------------------ - -- Issue #14234: CVE-2012-0876: Randomize hashes of xml attributes in the hash - table internal to the pyexpat module's copy of the expat library to avoid a - denial of service due to hash collisions. Patch by David Malcolm with some - modifications by the expat project. - - -What's New in Python 3.2.3 release candidate 1? -=============================================== - -*Release date: 24-Feb-2012* - -Core and Builtins ------------------ - -- Issue #13703: oCERT-2011-003: add -R command-line option and PYTHONHASHSEED - environment variable, to provide an opt-in way to protect against denial of - service attacks due to hash collisions within the dict and set types. Patch - by David Malcolm, based on work by Victor Stinner. - -- Issue #14084: Fix a file descriptor leak when importing a module with a - bad encoding. - -- Issue #13020: Fix a reference leak when allocating a structsequence object - fails. Patch by Suman Saha. - -- Issue #13908: Ready types returned from PyType_FromSpec. - -- Issue #11235: Fix OverflowError when trying to import a source file whose - modification time doesn't fit in a 32-bit timestamp. - -- Fix the builtin module initialization code to store the init function for - future reinitialization. - -- Issue #8052: The posix subprocess module would take a long time closing - all possible file descriptors in the child process rather than just open - file descriptors. It now closes only the open fds if possible for the - default close_fds=True behavior. - -- Issue #13629: Renumber the tokens in token.h so that they match the indexes - into _PyParser_TokenNames. - -- Fix the fix for issue #12149: it was incorrect, although it had the side - effect of appearing to resolve the issue. Thanks to Mark Shannon for - noticing. - -- Issue #13505: Pickle bytes objects in a way that is compatible with - Python 2 when using protocols <= 2. - -- Issue #11147: Fix an unused argument in _Py_ANNOTATE_MEMORY_ORDER. (Fix - given by Campbell Barton). - -- Issue #7111: Python can now be run without a stdin, stdout or stderr - stream. It was already the case with Python 2. However, the corresponding - sys module entries are now set to None (instead of an unusable file object). - -- Issue #13436: Fix a bogus error message when an AST object was passed - an invalid integer value. - -- Issue #13338: Handle all enumerations in _Py_ANNOTATE_MEMORY_ORDER - to allow compiling extension modules with -Wswitch-enum on gcc. - Initial patch by Floris Bruynooghe. - -- Issue #13333: The UTF-7 decoder now accepts lone surrogates (the encoder - already accepts them). - -- Issue #13342: input() used to ignore sys.stdin's and sys.stdout's unicode - error handler in interactive mode (when calling into PyOS_Readline()). - -- Issue #13343: Fix a SystemError when a lambda expression uses a global - variable in the default value of a keyword-only argument: - (lambda *, arg=GLOBAL_NAME: None) - -- Issue #10519: Avoid unnecessary recursive function calls in - setobject.c. - -- Issue #10363: Deallocate global locks in Py_Finalize(). - -- Issue #13018: Fix reference leaks in error paths in dictobject.c. - Patch by Suman Saha. - -- Issue #1294232: In a few cases involving metaclass inheritance, the - interpreter would sometimes invoke the wrong metaclass when building a new - class object. These cases now behave correctly. Patch by Daniel Urban. - -- Issue #12604: VTRACE macro expanded to no-op in _sre.c to avoid compiler - warnings. Patch by Josh Triplett and Petri Lehtinen. - -- Issue #13188: When called without an explicit traceback argument, - generator.throw() now gets the traceback from the passed exception's - ``__traceback__`` attribute. Patch by Petri Lehtinen. - -- Issue #7833: Extension modules built using distutils on Windows will no - longer include a "manifest" to prevent them failing at import time in some - embedded situations. - -- Issue #13063: the Windows error ERROR_NO_DATA (numbered 232 and described - as "The pipe is being closed") is now mapped to POSIX errno EPIPE - (previously EINVAL). - -- Issue #12911: Fix memory consumption when calculating the repr() of huge - tuples or lists. - -- Issue #7732: Don't open a directory as a file anymore while importing a - module. Ignore the direcotry if its name matchs the module name (e.g. - "__init__.py") and raise a ImportError instead. - -- Issue #13021: Missing decref on an error path. Thanks to Suman Saha for - finding the bug and providing a patch. - -- Issue #12973: Fix overflow checks that relied on undefined behaviour in - list_repeat (listobject.c) and islice_next (itertoolsmodule.c). These bugs - caused test failures with recent versions of Clang. - -- Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now - mapped to POSIX errno ENOTDIR (previously EINVAL). - -- Issue #9200: The str.is* methods now work with strings that contain non-BMP - characters even in narrow Unicode builds. - -- Issue #12791: Break reference cycles early when a generator exits with - an exception. - -- Issue #12266: Fix str.capitalize() to correctly uppercase/lowercase - titlecased and cased non-letter characters. - -Library -------- - ->>>>>>> other - HTMLParser is now able to handle slashes in the start tag. - Issue #13641: Decoding functions in the base64 module now accept ASCII-only -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 00:27:17 2012 From: python-checkins at python.org (brian.curtin) Date: Tue, 14 Aug 2012 00:27:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogRml4ICMxNTQ5Ni4g?= =?utf-8?q?Add_directory_removal_helpers_to_make_Windows_tests_more_reliab?= =?utf-8?b?bGUu?= Message-ID: <3Wws4j0T18zPt2@mail.python.org> http://hg.python.org/cpython/rev/c863dadc65eb changeset: 78554:c863dadc65eb branch: 2.7 parent: 78550:3bddc965e2ea user: Brian Curtin date: Mon Aug 13 17:26:48 2012 -0500 summary: Fix #15496. Add directory removal helpers to make Windows tests more reliable. Patch by Jeremy Kloth files: Lib/test/test_support.py | 68 +++++++++++++++++++++++++++- Misc/NEWS | 3 + 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -181,15 +181,79 @@ except KeyError: pass +if sys.platform.startswith("win"): + def _waitfor(func, pathname, waitall=False): + # Peform the operation + func(pathname) + # Now setup the wait loop + if waitall: + dirname = pathname + else: + dirname, name = os.path.split(pathname) + dirname = dirname or '.' + # Check for `pathname` to be removed from the filesystem. + # The exponential backoff of the timeout amounts to a total + # of ~1 second after which the deletion is probably an error + # anyway. + # Testing on a i7 at 4.3GHz shows that usually only 1 iteration is + # required when contention occurs. + timeout = 0.001 + while timeout < 1.0: + # Note we are only testing for the existance of the file(s) in + # the contents of the directory regardless of any security or + # access rights. If we have made it this far, we have sufficient + # permissions to do that much using Python's equivalent of the + # Windows API FindFirstFile. + # Other Windows APIs can fail or give incorrect results when + # dealing with files that are pending deletion. + L = os.listdir(dirname) + if not (L if waitall else name in L): + return + # Increase the timeout and try again + time.sleep(timeout) + timeout *= 2 + warnings.warn('tests may fail, delete still pending for ' + pathname, + RuntimeWarning, stacklevel=4) + + def _unlink(filename): + _waitfor(os.unlink, filename) + + def _rmdir(dirname): + _waitfor(os.rmdir, dirname) + + def _rmtree(path): + def _rmtree_inner(path): + for name in os.listdir(path): + fullname = os.path.join(path, name) + if os.path.isdir(fullname): + _waitfor(_rmtree_inner, fullname, waitall=True) + os.rmdir(fullname) + else: + os.unlink(fullname) + _waitfor(_rmtree_inner, path, waitall=True) + _waitfor(os.rmdir, path) +else: + _unlink = os.unlink + _rmdir = os.rmdir + _rmtree = shutil.rmtree + def unlink(filename): try: - os.unlink(filename) + _unlink(filename) except OSError: pass +def rmdir(dirname): + try: + _rmdir(dirname) + except OSError as error: + # The directory need not exist. + if error.errno != errno.ENOENT: + raise + def rmtree(path): try: - shutil.rmtree(path) + _rmtree(path) except OSError, e: # Unix returns ENOENT, Windows returns ESRCH. if e.errno not in (errno.ENOENT, errno.ESRCH): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -323,6 +323,9 @@ Tests ----- +- Issue #15496: Add directory removal helpers for tests on Windows. + Patch by Jeremy Kloth. + - Issue #15043: test_gdb is now skipped entirely if gdb security settings block loading of the gdb hooks -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 04:04:51 2012 From: python-checkins at python.org (r.david.murray) Date: Tue, 14 Aug 2012 04:04:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzkxNjE6IGFkZCB0?= =?utf-8?q?est_for_the_bug_fixed_by_r82581=2E?= Message-ID: <3Wwxvl4vmvzPwN@mail.python.org> http://hg.python.org/cpython/rev/4c86a860e3d2 changeset: 78555:4c86a860e3d2 branch: 2.7 user: R David Murray date: Mon Aug 13 22:04:30 2012 -0400 summary: #9161: add test for the bug fixed by r82581. Patch by Michael Johnson. files: Lib/test/test_optparse.py | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py --- a/Lib/test/test_optparse.py +++ b/Lib/test/test_optparse.py @@ -769,6 +769,13 @@ self.assertParseFail(["-test"], "no such option: -e") + def test_flag_accepts_unicode(self): + try: + self.parser.add_option(u"-u", u"--unicode") + self.parser.parse_args() + except TypeError: + self.fail("Failed parsing flag passed to add_option() as unicode.") + class TestBool(BaseTest): def setUp(self): options = [make_option("-v", -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Tue Aug 14 06:00:37 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 14 Aug 2012 06:00:37 +0200 Subject: [Python-checkins] Daily reference leaks (70f7559e6d0f): sum=0 Message-ID: results for 70f7559e6d0f on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogLCqbhw', '-x'] From python-checkins at python.org Tue Aug 14 06:21:03 2012 From: python-checkins at python.org (eli.bendersky) Date: Tue, 14 Aug 2012 06:21:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315586=3A_add_some?= =?utf-8?q?_examples_to_ElementTree_documentation=2E_Patch_by_Daniel?= Message-ID: <3Wx0wv1jD9zPwJ@mail.python.org> http://hg.python.org/cpython/rev/fc66730dae4c changeset: 78556:fc66730dae4c parent: 78553:70f7559e6d0f user: Eli Bendersky date: Tue Aug 14 07:19:33 2012 +0300 summary: Issue #15586: add some examples to ElementTree documentation. Patch by Daniel Ellis. files: Doc/library/xml.etree.elementtree.rst | 111 ++++++++++++- 1 files changed, 100 insertions(+), 11 deletions(-) diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -35,10 +35,11 @@ Parsing XML ^^^^^^^^^^^ -We'll be using the following XML document contained in a Python string as the -sample data for this section:: +We'll be using the following XML document as the sample data for this section: - countrydata = r''' +.. code-block:: xml + + 1 @@ -61,18 +62,20 @@ - ''' -First, import the module and parse the data:: +We can import this data by reading from a file:: import xml.etree.ElementTree as ET + tree = ET.parse('country_data.xml') + root = tree.getroot() - root = ET.fromstring(countrydata) +Or directly from a string:: + + root = ET.fromstring(country_data_as_string) :func:`fromstring` parses XML from a string directly into an :class:`Element`, which is the root element of the parsed tree. Other parsing functions may -create an :class:`ElementTree`. Make sure to check the documentation to be -sure. +create an :class:`ElementTree`. Check the documentation to be sure. As an :class:`Element`, ``root`` has a tag and a dictionary of attributes:: @@ -111,13 +114,27 @@ {'name': 'Costa Rica', 'direction': 'W'} {'name': 'Colombia', 'direction': 'E'} +:meth:`Element.findall` finds only elements with a tag which are direct +children of the current element. :meth:`Element.find` finds the *first* child +with a particular tag, and :meth:`Element.text` accesses the element's text +content. :meth:`Element.get` accesses the element's attributes:: + + >>> for country in root.findall('country'): + ... rank = country.find('rank').text + ... name = country.get('name') + ... print(name, rank) + ... + Liechtenshtein 1 + Singapore 4 + Panama 68 + More sophisticated specification of which elements to look for is possible by using :ref:`XPath `. -Building XML documents -^^^^^^^^^^^^^^^^^^^^^^ +Modifying an XML File +^^^^^^^^^^^^^^^^^^^^^ -``ET`` provides a simple way to build XML documents and write them to files. +:class:`ElementTree` provides a simple way to build XML documents and write them to files. The :meth:`ElementTree.write` method serves this purpose. Once created, an :class:`Element` object may be manipulated by directly changing @@ -125,6 +142,78 @@ (:meth:`Element.set` method), as well as adding new children (for example with :meth:`Element.append`). +Let's say we want to add one to each country's rank, and add an ``updated`` +attribute to the rank element:: + + >>> for rank in root.iter('rank'): + ... new_rank = int(rank.text) + 1 + ... rank.text = str(new_rank) + ... rank.set('updated', 'yes') + ... + ... tree.write('output.xml') + +Our XML now looks like this: + +.. code-block:: xml + + + + + 2 + 2008 + 141100 + + + + + 5 + 2011 + 59900 + + + + 69 + 2011 + 13600 + + + + + +We can remove elements using :meth:`Element.remove`. Let's say we want to +remove all countries with a rank higher than 50:: + + >>> for country in root.findall('country'): + ... rank = int(country.find('rank').text) + ... if rank > 50: + ... root.remove(country) + ... + ... tree.write('output.xml') + +Our XML now looks like this: + +.. code-block:: xml + + + + + 2 + 2008 + 141100 + + + + + 5 + 2011 + 59900 + + + + +Building XML documents +^^^^^^^^^^^^^^^^^^^^^^ + The :func:`SubElement` function also provides a convenient way to create new sub-elements for a given element:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 06:21:05 2012 From: python-checkins at python.org (eli.bendersky) Date: Tue, 14 Aug 2012 06:21:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_Daniel_Ellis_to_Misc/A?= =?utf-8?q?CKS?= Message-ID: <3Wx0wx6qtnzPy0@mail.python.org> http://hg.python.org/cpython/rev/71918a3c89ef changeset: 78557:71918a3c89ef user: Eli Bendersky date: Tue Aug 14 07:20:06 2012 +0300 summary: Add Daniel Ellis to Misc/ACKS 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 @@ -293,6 +293,7 @@ Andrew Eland Julien ?lie Lance Ellinghaus +Daniel Ellis David Ely Jeff Epler Jeff McNeil -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 09:40:33 2012 From: python-checkins at python.org (georg.brandl) Date: Tue, 14 Aug 2012 09:40:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Restore_origin?= =?utf-8?q?al_line_lengths=2E?= Message-ID: <3Wx5M54RJJzPhy@mail.python.org> http://hg.python.org/cpython/rev/1c9f1c2bd840 changeset: 78558:1c9f1c2bd840 branch: 3.2 parent: 78551:fcad4566910b user: Georg Brandl date: Tue Aug 14 09:39:07 2012 +0200 summary: Restore original line lengths. files: Doc/library/functions.rst | 27 ++++++++++++--------------- Doc/library/io.rst | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -878,22 +878,19 @@ mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * When reading input from the stream, if *newline* is ``None``, - universal newlines mode is enabled. Lines in the input can end - in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated - into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are - returned to the caller untranslated. If it has any of the other - legal values, input lines are only terminated by the given - string, and the line ending is returned to the caller - untranslated. + * When reading input from the stream, if *newline* is ``None``, universal + newlines mode is enabled. Lines in the input can end in ``'\n'``, + ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before + being returned to the caller. If it is ``''``, universal newline mode is + enabled, but line endings are returned to the caller untranslated. If it + has any of the other legal values, input lines are only terminated by the + given string, and the line ending is returned to the caller untranslated. - * When writing output to the stream, if *newline* is ``None``, any - ``'\n'`` characters written are translated to the system default - line separator, :data:`os.linesep`. If *newline* is ``''`` or - ``'\n'``, no translation takes place. If *newline* is any of the - other legal values, any ``'\n'`` characters written are - translated to the given string. + * When writing output to the stream, if *newline* is ``None``, any ``'\n'`` + characters written are translated to the system default line separator, + :data:`os.linesep`. If *newline* is ``''`` or ``'\n'``, no translation + takes place. If *newline* is any of the other legal values, any ``'\n'`` + characters written are translated to the given string. If *closefd* is ``False`` and a file descriptor rather than a filename was given, the underlying file descriptor will be kept open when the file is diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -760,22 +760,19 @@ *newline* controls how line endings are handled. It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * When reading input from the stream, if *newline* is ``None``, - universal newlines mode is enabled. Lines in the input can end - in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated - into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are - returned to the caller untranslated. If it has any of the other - legal values, input lines are only terminated by the given - string, and the line ending is returned to the caller - untranslated. + * When reading input from the stream, if *newline* is ``None``, universal + newlines mode is enabled. Lines in the input can end in ``'\n'``, + ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before + being returned to the caller. If it is ``''``, universal newline mode is + enabled, but line endings are returned to the caller untranslated. If it + has any of the other legal values, input lines are only terminated by the + given string, and the line ending is returned to the caller untranslated. - * When writing output to the stream, if *newline* is ``None``, any - ``'\n'`` characters written are translated to the system default - line separator, :data:`os.linesep`. If *newline* is ``''`` or - ``'\n'``, no translation takes place. If *newline* is any of the - other legal values, any ``'\n'`` characters written are - translated to the given string. + * When writing output to the stream, if *newline* is ``None``, any ``'\n'`` + characters written are translated to the system default line separator, + :data:`os.linesep`. If *newline* is ``''`` or ``'\n'``, no translation + takes place. If *newline* is any of the other legal values, any ``'\n'`` + characters written are translated to the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 09:40:35 2012 From: python-checkins at python.org (georg.brandl) Date: Tue, 14 Aug 2012 09:40:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3Wx5M73v63zQ0g@mail.python.org> http://hg.python.org/cpython/rev/891e3555ed3f changeset: 78559:891e3555ed3f parent: 78557:71918a3c89ef parent: 78558:1c9f1c2bd840 user: Georg Brandl date: Tue Aug 14 09:40:26 2012 +0200 summary: merge with 3.2 files: Doc/library/functions.rst | 27 ++++++++++++--------------- Doc/library/io.rst | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -878,22 +878,19 @@ mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * When reading input from the stream, if *newline* is ``None``, - universal newlines mode is enabled. Lines in the input can end - in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated - into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are - returned to the caller untranslated. If it has any of the other - legal values, input lines are only terminated by the given - string, and the line ending is returned to the caller - untranslated. + * When reading input from the stream, if *newline* is ``None``, universal + newlines mode is enabled. Lines in the input can end in ``'\n'``, + ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before + being returned to the caller. If it is ``''``, universal newline mode is + enabled, but line endings are returned to the caller untranslated. If it + has any of the other legal values, input lines are only terminated by the + given string, and the line ending is returned to the caller untranslated. - * When writing output to the stream, if *newline* is ``None``, any - ``'\n'`` characters written are translated to the system default - line separator, :data:`os.linesep`. If *newline* is ``''`` or - ``'\n'``, no translation takes place. If *newline* is any of the - other legal values, any ``'\n'`` characters written are - translated to the given string. + * When writing output to the stream, if *newline* is ``None``, any ``'\n'`` + characters written are translated to the system default line separator, + :data:`os.linesep`. If *newline* is ``''`` or ``'\n'``, no translation + takes place. If *newline* is any of the other legal values, any ``'\n'`` + characters written are translated to the given string. If *closefd* is ``False`` and a file descriptor rather than a filename was given, the underlying file descriptor will be kept open when the file is diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -771,22 +771,19 @@ *newline* controls how line endings are handled. It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * When reading input from the stream, if *newline* is ``None``, - universal newlines mode is enabled. Lines in the input can end - in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated - into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are - returned to the caller untranslated. If it has any of the other - legal values, input lines are only terminated by the given - string, and the line ending is returned to the caller - untranslated. + * When reading input from the stream, if *newline* is ``None``, universal + newlines mode is enabled. Lines in the input can end in ``'\n'``, + ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before + being returned to the caller. If it is ``''``, universal newline mode is + enabled, but line endings are returned to the caller untranslated. If it + has any of the other legal values, input lines are only terminated by the + given string, and the line ending is returned to the caller untranslated. - * When writing output to the stream, if *newline* is ``None``, any - ``'\n'`` characters written are translated to the system default - line separator, :data:`os.linesep`. If *newline* is ``''`` or - ``'\n'``, no translation takes place. If *newline* is any of the - other legal values, any ``'\n'`` characters written are - translated to the given string. + * When writing output to the stream, if *newline* is ``None``, any ``'\n'`` + characters written are translated to the system default line separator, + :data:`os.linesep`. If *newline* is ``''`` or ``'\n'``, no translation + takes place. If *newline* is any of the other legal values, any ``'\n'`` + characters written are translated to the given string. If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 09:45:32 2012 From: python-checkins at python.org (georg.brandl) Date: Tue, 14 Aug 2012 09:45:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Review_of_signature_docs?= =?utf-8?q?=2E?= Message-ID: <3Wx5Sr22MhzQ0c@mail.python.org> http://hg.python.org/cpython/rev/e1e7d628c0b9 changeset: 78560:e1e7d628c0b9 user: Georg Brandl date: Tue Aug 14 09:45:28 2012 +0200 summary: Review of signature docs. files: Doc/library/inspect.rst | 127 +++++++++++++-------------- 1 files changed, 62 insertions(+), 65 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -397,25 +397,18 @@ .. _inspect-signature-object: -Introspecting callables with Signature Object ---------------------------------------------- - -Signature object represents the call signature of a callable object and its -return annotation. To get a Signature object use the :func:`signature` -function. - +Introspecting callables with the Signature object +------------------------------------------------- .. versionadded:: 3.3 -.. seealso:: - - :pep:`362` - Function Signature Object. - The detailed specification, implementation details and examples. - +The Signature object represents the call signature of a callable object and its +return annotation. To retrieve a Signature object, use the :func:`signature` +function. .. function:: signature(callable) - Returns a :class:`Signature` object for the given ``callable``:: + Return a :class:`Signature` object for the given ``callable``:: >>> from inspect import signature >>> def foo(a, *, b:int, **kwargs): @@ -432,24 +425,24 @@ >>> sig.parameters['b'].annotation - Accepts a wide range of python callables, from plain functions and classes - to :func:`functools.partial` objects. + Accepts a wide range of python callables, from plain functions and classes to + :func:`functools.partial` objects. .. note:: - Some callables may not be introspectable in certain implementations - of Python. For example, in CPython, built-in functions defined in C - provide no metadata about their arguments. + Some callables may not be introspectable in certain implementations of + Python. For example, in CPython, built-in functions defined in C provide + no metadata about their arguments. .. class:: Signature - A Signature object represents the call signature of a function and its - return annotation. For each parameter accepted by the function it - stores a :class:`Parameter` object in its :attr:`parameters` collection. + A Signature object represents the call signature of a function and its return + annotation. For each parameter accepted by the function it stores a + :class:`Parameter` object in its :attr:`parameters` collection. - Signature objects are *immutable*. Use :meth:`Signature.replace` to make - a modified copy. + Signature objects are *immutable*. Use :meth:`Signature.replace` to make a + modified copy. .. attribute:: Signature.empty @@ -462,30 +455,29 @@ .. attribute:: Signature.return_annotation - The "return" annotation for the callable. If the callable has - no "return" annotation, this attribute is set to - :attr:`Signature.empty`. + The "return" annotation for the callable. If the callable has no "return" + annotation, this attribute is set to :attr:`Signature.empty`. .. method:: Signature.bind(*args, **kwargs) - Creates a mapping from positional and keyword arguments to parameters. - Returns :class:`BoundArguments` if ``*args`` and ``**kwargs`` match - the signature, or raises a :exc:`TypeError`. + Create a mapping from positional and keyword arguments to parameters. + Returns :class:`BoundArguments` if ``*args`` and ``**kwargs`` match the + signature, or raises a :exc:`TypeError`. .. method:: Signature.bind_partial(*args, **kwargs) - Works the same way as :meth:`Signature.bind`, but allows the - omission of some required arguments (mimics :func:`functools.partial` - behavior.) Returns :class:`BoundArguments`, or raises a :exc:`TypeError` - if the passed arguments do not match the signature. + Works the same way as :meth:`Signature.bind`, but allows the omission of + some required arguments (mimics :func:`functools.partial` behavior.) + Returns :class:`BoundArguments`, or raises a :exc:`TypeError` if the + passed arguments do not match the signature. .. method:: Signature.replace([parameters], *, [return_annotation]) - Creates a new Signature instance based on the instance replace was - invoked on. It is possible to pass different ``parameters`` and/or - ``return_annotation`` to override the corresponding properties of - the base signature. To remove return_annotation from the copied - Signature, pass in :attr:`Signature.empty`. + Create a new Signature instance based on the instance replace was invoked + on. It is possible to pass different ``parameters`` and/or + ``return_annotation`` to override the corresponding properties of the base + signature. To remove return_annotation from the copied Signature, pass in + :attr:`Signature.empty`. :: @@ -497,38 +489,36 @@ "(a, b) -> 'new return anno'" - .. class:: Parameter - Parameter objects are *immutable*. Instead of modifying a Parameter object, + Parameter objects are *immutable*. Instead of modifying a Parameter object, you can use :meth:`Parameter.replace` to create a modified copy. .. attribute:: Parameter.empty - A special class-level marker to specify absence of default - values and annotations. + A special class-level marker to specify absence of default values and + annotations. .. attribute:: Parameter.name - The name of the parameter as a string. Must be a valid python identifier - name (with the exception of ``POSITIONAL_ONLY`` parameters, which can - have it set to ``None``.) + The name of the parameter as a string. Must be a valid python identifier + name (with the exception of ``POSITIONAL_ONLY`` parameters, which can have + it set to ``None``). .. attribute:: Parameter.default - The default value for the parameter. If the parameter has no default + The default value for the parameter. If the parameter has no default value, this attribute is set to :attr:`Parameter.empty`. .. attribute:: Parameter.annotation - The annotation for the parameter. If the parameter has no annotation, + The annotation for the parameter. If the parameter has no annotation, this attribute is set to :attr:`Parameter.empty`. .. attribute:: Parameter.kind - Describes how argument values are bound to the parameter. - Possible values (accessible via :class:`Parameter`, like - ``Parameter.KEYWORD_ONLY``): + Describes how argument values are bound to the parameter. Possible values + (accessible via :class:`Parameter`, like ``Parameter.KEYWORD_ONLY``): +------------------------+----------------------------------------------+ | Name | Meaning | @@ -577,10 +567,10 @@ .. method:: Parameter.replace(*, [name], [kind], [default], [annotation]) - Creates a new Parameter instance based on the instance replaced was - invoked on. To override a :class:`Parameter` attribute, pass the - corresponding argument. To remove a default value or/and an annotation - from a Parameter, pass :attr:`Parameter.empty`. + Create a new Parameter instance based on the instance replaced was invoked + on. To override a :class:`Parameter` attribute, pass the corresponding + argument. To remove a default value or/and an annotation from a + Parameter, pass :attr:`Parameter.empty`. :: @@ -604,18 +594,18 @@ .. attribute:: BoundArguments.arguments An ordered, mutable mapping (:class:`collections.OrderedDict`) of - parameters' names to arguments' values. Contains only explicitly - bound arguments. Changes in :attr:`arguments` will reflect in - :attr:`args` and :attr:`kwargs`. + parameters' names to arguments' values. Contains only explicitly bound + arguments. Changes in :attr:`arguments` will reflect in :attr:`args` and + :attr:`kwargs`. - Should be used in conjunction with :attr:`Signature.parameters` for - any arguments processing purposes. + Should be used in conjunction with :attr:`Signature.parameters` for any + argument processing purposes. .. note:: Arguments for which :meth:`Signature.bind` or :meth:`Signature.bind_partial` relied on a default value are skipped. - However, if needed, it's easy to include them + However, if needed, it is easy to include them. :: @@ -638,15 +628,16 @@ .. attribute:: BoundArguments.args - Tuple of positional arguments values. Dynamically computed - from the :attr:`arguments` attribute. + A tuple of positional arguments values. Dynamically computed from the + :attr:`arguments` attribute. .. attribute:: BoundArguments.kwargs - Dict of keyword arguments values. Dynamically computed - from the :attr:`arguments` attribute. + A dict of keyword arguments values. Dynamically computed from the + :attr:`arguments` attribute. - :attr:`args` and :attr:`kwargs` properties can be used to invoke functions:: + The :attr:`args` and :attr:`kwargs` properties can be used to invoke + functions:: def test(a, *, b): ... @@ -656,6 +647,12 @@ test(*ba.args, **ba.kwargs) +.. seealso:: + + :pep:`362` - Function Signature Object. + The detailed specification, implementation details and examples. + + .. _inspect-classes-functions: Classes and functions -- Repository URL: http://hg.python.org/cpython From andrew.svetlov at gmail.com Tue Aug 14 10:46:25 2012 From: andrew.svetlov at gmail.com (Andrew Svetlov) Date: Tue, 14 Aug 2012 11:46:25 +0300 Subject: [Python-checkins] cpython: Review of signature docs. In-Reply-To: <3Wx5Sr22MhzQ0c@mail.python.org> References: <3Wx5Sr22MhzQ0c@mail.python.org> Message-ID: Thank you for review. On Tue, Aug 14, 2012 at 10:45 AM, georg.brandl wrote: > http://hg.python.org/cpython/rev/e1e7d628c0b9 > changeset: 78560:e1e7d628c0b9 > user: Georg Brandl > date: Tue Aug 14 09:45:28 2012 +0200 > summary: > Review of signature docs. > > files: > Doc/library/inspect.rst | 127 +++++++++++++-------------- > 1 files changed, 62 insertions(+), 65 deletions(-) > > > diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst > --- a/Doc/library/inspect.rst > +++ b/Doc/library/inspect.rst > @@ -397,25 +397,18 @@ > > .. _inspect-signature-object: > > -Introspecting callables with Signature Object > ---------------------------------------------- > - > -Signature object represents the call signature of a callable object and its > -return annotation. To get a Signature object use the :func:`signature` > -function. > - > +Introspecting callables with the Signature object > +------------------------------------------------- > > .. versionadded:: 3.3 > > -.. seealso:: > - > - :pep:`362` - Function Signature Object. > - The detailed specification, implementation details and examples. > - > +The Signature object represents the call signature of a callable object and its > +return annotation. To retrieve a Signature object, use the :func:`signature` > +function. > > .. function:: signature(callable) > > - Returns a :class:`Signature` object for the given ``callable``:: > + Return a :class:`Signature` object for the given ``callable``:: > > >>> from inspect import signature > >>> def foo(a, *, b:int, **kwargs): > @@ -432,24 +425,24 @@ > >>> sig.parameters['b'].annotation > > > - Accepts a wide range of python callables, from plain functions and classes > - to :func:`functools.partial` objects. > + Accepts a wide range of python callables, from plain functions and classes to > + :func:`functools.partial` objects. > > .. note:: > > - Some callables may not be introspectable in certain implementations > - of Python. For example, in CPython, built-in functions defined in C > - provide no metadata about their arguments. > + Some callables may not be introspectable in certain implementations of > + Python. For example, in CPython, built-in functions defined in C provide > + no metadata about their arguments. > > > .. class:: Signature > > - A Signature object represents the call signature of a function and its > - return annotation. For each parameter accepted by the function it > - stores a :class:`Parameter` object in its :attr:`parameters` collection. > + A Signature object represents the call signature of a function and its return > + annotation. For each parameter accepted by the function it stores a > + :class:`Parameter` object in its :attr:`parameters` collection. > > - Signature objects are *immutable*. Use :meth:`Signature.replace` to make > - a modified copy. > + Signature objects are *immutable*. Use :meth:`Signature.replace` to make a > + modified copy. > > .. attribute:: Signature.empty > > @@ -462,30 +455,29 @@ > > .. attribute:: Signature.return_annotation > > - The "return" annotation for the callable. If the callable has > - no "return" annotation, this attribute is set to > - :attr:`Signature.empty`. > + The "return" annotation for the callable. If the callable has no "return" > + annotation, this attribute is set to :attr:`Signature.empty`. > > .. method:: Signature.bind(*args, **kwargs) > > - Creates a mapping from positional and keyword arguments to parameters. > - Returns :class:`BoundArguments` if ``*args`` and ``**kwargs`` match > - the signature, or raises a :exc:`TypeError`. > + Create a mapping from positional and keyword arguments to parameters. > + Returns :class:`BoundArguments` if ``*args`` and ``**kwargs`` match the > + signature, or raises a :exc:`TypeError`. > > .. method:: Signature.bind_partial(*args, **kwargs) > > - Works the same way as :meth:`Signature.bind`, but allows the > - omission of some required arguments (mimics :func:`functools.partial` > - behavior.) Returns :class:`BoundArguments`, or raises a :exc:`TypeError` > - if the passed arguments do not match the signature. > + Works the same way as :meth:`Signature.bind`, but allows the omission of > + some required arguments (mimics :func:`functools.partial` behavior.) > + Returns :class:`BoundArguments`, or raises a :exc:`TypeError` if the > + passed arguments do not match the signature. > > .. method:: Signature.replace([parameters], *, [return_annotation]) > > - Creates a new Signature instance based on the instance replace was > - invoked on. It is possible to pass different ``parameters`` and/or > - ``return_annotation`` to override the corresponding properties of > - the base signature. To remove return_annotation from the copied > - Signature, pass in :attr:`Signature.empty`. > + Create a new Signature instance based on the instance replace was invoked > + on. It is possible to pass different ``parameters`` and/or > + ``return_annotation`` to override the corresponding properties of the base > + signature. To remove return_annotation from the copied Signature, pass in > + :attr:`Signature.empty`. > > :: > > @@ -497,38 +489,36 @@ > "(a, b) -> 'new return anno'" > > > - > .. class:: Parameter > > - Parameter objects are *immutable*. Instead of modifying a Parameter object, > + Parameter objects are *immutable*. Instead of modifying a Parameter object, > you can use :meth:`Parameter.replace` to create a modified copy. > > .. attribute:: Parameter.empty > > - A special class-level marker to specify absence of default > - values and annotations. > + A special class-level marker to specify absence of default values and > + annotations. > > .. attribute:: Parameter.name > > - The name of the parameter as a string. Must be a valid python identifier > - name (with the exception of ``POSITIONAL_ONLY`` parameters, which can > - have it set to ``None``.) > + The name of the parameter as a string. Must be a valid python identifier > + name (with the exception of ``POSITIONAL_ONLY`` parameters, which can have > + it set to ``None``). > > .. attribute:: Parameter.default > > - The default value for the parameter. If the parameter has no default > + The default value for the parameter. If the parameter has no default > value, this attribute is set to :attr:`Parameter.empty`. > > .. attribute:: Parameter.annotation > > - The annotation for the parameter. If the parameter has no annotation, > + The annotation for the parameter. If the parameter has no annotation, > this attribute is set to :attr:`Parameter.empty`. > > .. attribute:: Parameter.kind > > - Describes how argument values are bound to the parameter. > - Possible values (accessible via :class:`Parameter`, like > - ``Parameter.KEYWORD_ONLY``): > + Describes how argument values are bound to the parameter. Possible values > + (accessible via :class:`Parameter`, like ``Parameter.KEYWORD_ONLY``): > > +------------------------+----------------------------------------------+ > | Name | Meaning | > @@ -577,10 +567,10 @@ > > .. method:: Parameter.replace(*, [name], [kind], [default], [annotation]) > > - Creates a new Parameter instance based on the instance replaced was > - invoked on. To override a :class:`Parameter` attribute, pass the > - corresponding argument. To remove a default value or/and an annotation > - from a Parameter, pass :attr:`Parameter.empty`. > + Create a new Parameter instance based on the instance replaced was invoked > + on. To override a :class:`Parameter` attribute, pass the corresponding > + argument. To remove a default value or/and an annotation from a > + Parameter, pass :attr:`Parameter.empty`. > > :: > > @@ -604,18 +594,18 @@ > .. attribute:: BoundArguments.arguments > > An ordered, mutable mapping (:class:`collections.OrderedDict`) of > - parameters' names to arguments' values. Contains only explicitly > - bound arguments. Changes in :attr:`arguments` will reflect in > - :attr:`args` and :attr:`kwargs`. > + parameters' names to arguments' values. Contains only explicitly bound > + arguments. Changes in :attr:`arguments` will reflect in :attr:`args` and > + :attr:`kwargs`. > > - Should be used in conjunction with :attr:`Signature.parameters` for > - any arguments processing purposes. > + Should be used in conjunction with :attr:`Signature.parameters` for any > + argument processing purposes. > > .. note:: > > Arguments for which :meth:`Signature.bind` or > :meth:`Signature.bind_partial` relied on a default value are skipped. > - However, if needed, it's easy to include them > + However, if needed, it is easy to include them. > > :: > > @@ -638,15 +628,16 @@ > > .. attribute:: BoundArguments.args > > - Tuple of positional arguments values. Dynamically computed > - from the :attr:`arguments` attribute. > + A tuple of positional arguments values. Dynamically computed from the > + :attr:`arguments` attribute. > > .. attribute:: BoundArguments.kwargs > > - Dict of keyword arguments values. Dynamically computed > - from the :attr:`arguments` attribute. > + A dict of keyword arguments values. Dynamically computed from the > + :attr:`arguments` attribute. > > - :attr:`args` and :attr:`kwargs` properties can be used to invoke functions:: > + The :attr:`args` and :attr:`kwargs` properties can be used to invoke > + functions:: > > def test(a, *, b): > ... > @@ -656,6 +647,12 @@ > test(*ba.args, **ba.kwargs) > > > +.. seealso:: > + > + :pep:`362` - Function Signature Object. > + The detailed specification, implementation details and examples. > + > + > .. _inspect-classes-functions: > > Classes and functions > > -- > 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 Aug 14 13:55:22 2012 From: python-checkins at python.org (richard.oudkerk) Date: Tue, 14 Aug 2012 13:55:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NjQ2?= =?utf-8?q?=3A_Prevent_equivalent_of_a_fork_bomb_when_using_multiprocessin?= =?utf-8?q?g?= Message-ID: <3WxC161WmFzQ2m@mail.python.org> http://hg.python.org/cpython/rev/e4fe1daef9f7 changeset: 78561:e4fe1daef9f7 branch: 2.7 parent: 78555:4c86a860e3d2 user: Richard Oudkerk date: Tue Aug 14 11:41:19 2012 +0100 summary: Issue #15646: Prevent equivalent of a fork bomb when using multiprocessing on Windows without the "if __name__ == '__main__'" idiom. files: Lib/multiprocessing/forking.py | 2 +- Lib/test/mp_fork_bomb.py | 16 +++++++++++++ Lib/test/test_multiprocessing.py | 23 +++++++++++++++++++- Misc/NEWS | 4 +++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py +++ b/Lib/multiprocessing/forking.py @@ -336,7 +336,7 @@ ''' Returns prefix of command line used for spawning a child process ''' - if process.current_process()._identity==() and is_forking(sys.argv): + if getattr(process.current_process(), '_inheriting', False): raise RuntimeError(''' Attempt to start a new process before the current process has finished its bootstrapping phase. diff --git a/Lib/test/mp_fork_bomb.py b/Lib/test/mp_fork_bomb.py new file mode 100644 --- /dev/null +++ b/Lib/test/mp_fork_bomb.py @@ -0,0 +1,16 @@ +import multiprocessing + +def foo(conn): + conn.send("123") + +# Because "if __name__ == '__main__'" is missing this will not work +# correctly on Windows. However, we should get a RuntimeError rather +# than the Windows equivalent of a fork bomb. + +r, w = multiprocessing.Pipe(False) +p = multiprocessing.Process(target=foo, args=(w,)) +p.start() +w.close() +print(r.recv()) +r.close() +p.join() 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 @@ -16,6 +16,7 @@ import random import logging import errno +import test.script_helper from test import test_support from StringIO import StringIO _multiprocessing = test_support.import_module('_multiprocessing') @@ -2349,8 +2350,28 @@ finally: socket.setdefaulttimeout(old_timeout) +# +# Test what happens with no "if __name__ == '__main__'" +# + +class TestNoForkBomb(unittest.TestCase): + def test_noforkbomb(self): + name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py') + if WIN32: + rc, out, err = test.script_helper.assert_python_failure(name) + self.assertEqual('', out.decode('ascii')) + self.assertIn('RuntimeError', err.decode('ascii')) + else: + rc, out, err = test.script_helper.assert_python_ok(name) + self.assertEqual('123', out.decode('ascii').rstrip()) + self.assertEqual('', err.decode('ascii')) + +# +# +# + testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, - TestStdinBadfiledescriptor, TestTimeouts] + TestStdinBadfiledescriptor, TestTimeouts, TestNoForkBomb] # # diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -92,6 +92,10 @@ Library ------- +- Issue #15646: Prevent equivalent of a fork bomb when using + multiprocessing on Windows without the "if __name__ == '__main__'" + idiom. + - Issue #15567: Fix NameError when running threading._test - Issue #15424: Add a __sizeof__ implementation for array objects. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 13:55:23 2012 From: python-checkins at python.org (richard.oudkerk) Date: Tue, 14 Aug 2012 13:55:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NjQ2?= =?utf-8?q?=3A_Prevent_equivalent_of_a_fork_bomb_when_using_multiprocessin?= =?utf-8?q?g?= Message-ID: <3WxC17737bzPkD@mail.python.org> http://hg.python.org/cpython/rev/20f8a2455ffb changeset: 78562:20f8a2455ffb branch: 3.2 parent: 78558:1c9f1c2bd840 user: Richard Oudkerk date: Tue Aug 14 11:41:32 2012 +0100 summary: Issue #15646: Prevent equivalent of a fork bomb when using multiprocessing on Windows without the "if __name__ == '__main__'" idiom. files: Lib/multiprocessing/forking.py | 2 +- Lib/test/mp_fork_bomb.py | 13 +++++++++++ Lib/test/test_multiprocessing.py | 23 +++++++++++++++++++- Misc/NEWS | 4 +++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py +++ b/Lib/multiprocessing/forking.py @@ -331,7 +331,7 @@ ''' Returns prefix of command line used for spawning a child process ''' - if process.current_process()._identity==() and is_forking(sys.argv): + if getattr(process.current_process(), '_inheriting', False): raise RuntimeError(''' Attempt to start a new process before the current process has finished its bootstrapping phase. diff --git a/Lib/test/mp_fork_bomb.py b/Lib/test/mp_fork_bomb.py new file mode 100644 --- /dev/null +++ b/Lib/test/mp_fork_bomb.py @@ -0,0 +1,13 @@ +import multiprocessing, sys + +def foo(): + print("123") + +# Because "if __name__ == '__main__'" is missing this will not work +# correctly on Windows. However, we should get a RuntimeError rather +# than the Windows equivalent of a fork bomb. + +p = multiprocessing.Process(target=foo) +p.start() +p.join() +sys.exit(p.exitcode) 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 @@ -18,6 +18,7 @@ import random import logging import test.support +import test.script_helper # Skip tests if _multiprocessing wasn't built. @@ -2429,9 +2430,29 @@ finally: socket.setdefaulttimeout(old_timeout) +# +# Test what happens with no "if __name__ == '__main__'" +# + +class TestNoForkBomb(unittest.TestCase): + def test_noforkbomb(self): + name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py') + if WIN32: + rc, out, err = test.script_helper.assert_python_failure(name) + self.assertEqual('', out.decode('ascii')) + self.assertIn('RuntimeError', err.decode('ascii')) + else: + rc, out, err = test.script_helper.assert_python_ok(name) + self.assertEqual('123', out.decode('ascii').rstrip()) + self.assertEqual('', err.decode('ascii')) + +# +# +# + testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, TestStdinBadfiledescriptor, TestInvalidFamily, - TestTimeouts] + TestTimeouts, TestNoForkBomb] # # diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,10 @@ Library ------- +- Issue #15646: Prevent equivalent of a fork bomb when using + multiprocessing on Windows without the "if __name__ == '__main__'" + idiom. + - Issue #15424: Add a __sizeof__ implementation for array objects. Patch by Ludwig H?hne. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 13:55:25 2012 From: python-checkins at python.org (richard.oudkerk) Date: Tue, 14 Aug 2012 13:55:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4y?= Message-ID: <3WxC195hqKzPkD@mail.python.org> http://hg.python.org/cpython/rev/8208f3ef3202 changeset: 78563:8208f3ef3202 parent: 78560:e1e7d628c0b9 parent: 78562:20f8a2455ffb user: Richard Oudkerk date: Tue Aug 14 12:51:14 2012 +0100 summary: Merge 3.2 files: Lib/multiprocessing/forking.py | 2 +- Lib/test/mp_fork_bomb.py | 13 +++++++++++ Lib/test/test_multiprocessing.py | 23 +++++++++++++++++++- Misc/NEWS | 4 +++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py --- a/Lib/multiprocessing/forking.py +++ b/Lib/multiprocessing/forking.py @@ -305,7 +305,7 @@ ''' Returns prefix of command line used for spawning a child process ''' - if process.current_process()._identity==() and is_forking(sys.argv): + if getattr(process.current_process(), '_inheriting', False): raise RuntimeError(''' Attempt to start a new process before the current process has finished its bootstrapping phase. diff --git a/Lib/test/mp_fork_bomb.py b/Lib/test/mp_fork_bomb.py new file mode 100644 --- /dev/null +++ b/Lib/test/mp_fork_bomb.py @@ -0,0 +1,13 @@ +import multiprocessing, sys + +def foo(): + print("123") + +# Because "if __name__ == '__main__'" is missing this will not work +# correctly on Windows. However, we should get a RuntimeError rather +# than the Windows equivalent of a fork bomb. + +p = multiprocessing.Process(target=foo) +p.start() +p.join() +sys.exit(p.exitcode) 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 @@ -20,6 +20,7 @@ import logging import struct import test.support +import test.script_helper # Skip tests if _multiprocessing wasn't built. @@ -3346,9 +3347,29 @@ finally: socket.setdefaulttimeout(old_timeout) +# +# Test what happens with no "if __name__ == '__main__'" +# + +class TestNoForkBomb(unittest.TestCase): + def test_noforkbomb(self): + name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py') + if WIN32: + rc, out, err = test.script_helper.assert_python_failure(name) + self.assertEqual('', out.decode('ascii')) + self.assertIn('RuntimeError', err.decode('ascii')) + else: + rc, out, err = test.script_helper.assert_python_ok(name) + self.assertEqual('123', out.decode('ascii').rstrip()) + self.assertEqual('', err.decode('ascii')) + +# +# +# + testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, TestStdinBadfiledescriptor, TestWait, TestInvalidFamily, - TestFlags, TestTimeouts] + TestFlags, TestTimeouts, TestNoForkBomb] # # diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,10 @@ Library ------- +- Issue #15646: Prevent equivalent of a fork bomb when using + multiprocessing on Windows without the "if __name__ == '__main__'" + idiom. + C API ----- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 14:45:33 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 14:45:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE0MTY3?= =?utf-8?q?=3A_Document_return_statement_in_finally_blocks=2E?= Message-ID: <3WxD714V7KzQ1n@mail.python.org> http://hg.python.org/cpython/rev/e0e8e70e4035 changeset: 78564:e0e8e70e4035 branch: 3.2 parent: 78562:20f8a2455ffb user: Andrew Svetlov date: Tue Aug 14 15:38:15 2012 +0300 summary: Issue #14167: Document return statement in finally blocks. Patch by Yury Selivanov. files: Doc/reference/compound_stmts.rst | 23 ++++++++++++++----- 1 files changed, 17 insertions(+), 6 deletions(-) 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 @@ -307,12 +307,23 @@ :keyword:`try` clause is executed, including any :keyword:`except` and :keyword:`else` clauses. If an exception occurs in any of the clauses and is not handled, the exception is temporarily saved. The :keyword:`finally` clause -is executed. If there is a saved exception, it is re-raised at the end of the -:keyword:`finally` clause. If the :keyword:`finally` clause raises another -exception or executes a :keyword:`return` or :keyword:`break` statement, the -saved exception is set as the context of the new exception. The exception -information is not available to the program during execution of the -:keyword:`finally` clause. +is executed. If there is a saved exception or :keyword:`break` statement, +it is re-raised at the end of the :keyword:`finally` clause. If the +:keyword:`finally` clause raises another exception the saved exception +is set as the context of the new exception; if the :keyword:`finally` clause +executes a :keyword:`return` statement, the saved exception is discarded:: + + def f(): + try: + 1/0 + finally: + return 42 + + >>> f() + 42 + +The exception information is not available to the program during execution of +the :keyword:`finally` clause. .. index:: statement: return -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 14:45:35 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 14:45:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2314167=3A_Document_return_statement_in_finally_b?= =?utf-8?q?locks=2E?= Message-ID: <3WxD734KFvzQ3K@mail.python.org> http://hg.python.org/cpython/rev/05714e9811fa changeset: 78565:05714e9811fa parent: 78563:8208f3ef3202 parent: 78564:e0e8e70e4035 user: Andrew Svetlov date: Tue Aug 14 15:38:58 2012 +0300 summary: Issue #14167: Document return statement in finally blocks. Patch by Yury Selivanov. files: Doc/reference/compound_stmts.rst | 23 ++++++++++++++----- 1 files changed, 17 insertions(+), 6 deletions(-) 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 @@ -307,12 +307,23 @@ :keyword:`try` clause is executed, including any :keyword:`except` and :keyword:`else` clauses. If an exception occurs in any of the clauses and is not handled, the exception is temporarily saved. The :keyword:`finally` clause -is executed. If there is a saved exception, it is re-raised at the end of the -:keyword:`finally` clause. If the :keyword:`finally` clause raises another -exception or executes a :keyword:`return` or :keyword:`break` statement, the -saved exception is set as the context of the new exception. The exception -information is not available to the program during execution of the -:keyword:`finally` clause. +is executed. If there is a saved exception or :keyword:`break` statement, +it is re-raised at the end of the :keyword:`finally` clause. If the +:keyword:`finally` clause raises another exception the saved exception +is set as the context of the new exception; if the :keyword:`finally` clause +executes a :keyword:`return` statement, the saved exception is discarded:: + + def f(): + try: + 1/0 + finally: + return 42 + + >>> f() + 42 + +The exception information is not available to the program during execution of +the :keyword:`finally` clause. .. index:: statement: return -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 14:45:37 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 14:45:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE0MTY3?= =?utf-8?q?=3A_Document_return_statement_in_finally_blocks=2E?= Message-ID: <3WxD7506slzQ30@mail.python.org> http://hg.python.org/cpython/rev/bef098bd3fa5 changeset: 78566:bef098bd3fa5 branch: 2.7 parent: 78561:e4fe1daef9f7 user: Andrew Svetlov date: Tue Aug 14 15:44:53 2012 +0300 summary: Issue #14167: Document return statement in finally blocks. Patch by Yury Selivanov. files: Doc/reference/compound_stmts.rst | 31 ++++++++++++++----- 1 files changed, 22 insertions(+), 9 deletions(-) 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 @@ -290,15 +290,28 @@ .. index:: keyword: finally -If :keyword:`finally` is present, it specifies a 'cleanup' handler. The -:keyword:`try` clause is executed, including any :keyword:`except` and -:keyword:`else` clauses. If an exception occurs in any of the clauses and is -not handled, the exception is temporarily saved. The :keyword:`finally` clause -is executed. If there is a saved exception, it is re-raised at the end of the -:keyword:`finally` clause. If the :keyword:`finally` clause raises another -exception or executes a :keyword:`return` or :keyword:`break` statement, the -saved exception is lost. The exception information is not available to the -program during execution of the :keyword:`finally` clause. +If :keyword:`finally` is present, it specifies a 'cleanup' handler. +The :keyword:`try` clause is executed, including any :keyword:`except` +and :keyword:`else` clauses. If an exception occurs in any of the +clauses and is not handled, the exception is temporarily saved. The +:keyword:`finally` clause is executed. If there is a saved exception +or :keyword:`break` statement, it is re-raised at the end of the +:keyword:`finally` clause. If the :keyword:`finally` clause raises +another exception the saved exception is set as the context of the new +exception; if the :keyword:`finally` clause executes a +:keyword:`return` statement, the saved exception is discarded:: + + def f(): + try: + 1/0 + finally: + return 42 + + >>> f() + 42 + +The exception information is not available to the program during execution of +the :keyword:`finally` clause. .. index:: statement: return -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 15:14:53 2012 From: python-checkins at python.org (r.david.murray) Date: Tue, 14 Aug 2012 15:14:53 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzkxNjE6IEZpeCB0?= =?utf-8?q?est_to_use_standard_optparse_test_pattern_=28what_was_I_thinkin?= =?utf-8?b?Zz8p?= Message-ID: <3WxDms29XXzQ30@mail.python.org> http://hg.python.org/cpython/rev/ffd70c371fee changeset: 78567:ffd70c371fee branch: 2.7 user: R David Murray date: Tue Aug 14 09:14:37 2012 -0400 summary: #9161: Fix test to use standard optparse test pattern (what was I thinking?) files: Lib/test/test_optparse.py | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py --- a/Lib/test/test_optparse.py +++ b/Lib/test/test_optparse.py @@ -769,12 +769,12 @@ self.assertParseFail(["-test"], "no such option: -e") - def test_flag_accepts_unicode(self): - try: - self.parser.add_option(u"-u", u"--unicode") - self.parser.parse_args() - except TypeError: - self.fail("Failed parsing flag passed to add_option() as unicode.") + def test_add_option_accepts_unicode(self): + self.parser.add_option(u"-u", u"--unicode", action="store_true") + self.assertParseOK(["-u"], + {'a': None, 'boo': None, 'foo': None, 'unicode': True}, + []) + class TestBool(BaseTest): def setUp(self): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:27:10 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 14 Aug 2012 17:27:10 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Modules/socket?= =?utf-8?q?module=2Ec=3A_netdb=5Flock=3A_define_static=2E?= Message-ID: <3WxHjV3x7szQ4D@mail.python.org> http://hg.python.org/cpython/rev/b7d4a13c736e changeset: 78568:b7d4a13c736e branch: 2.7 user: Matthias Klose date: Tue Aug 14 17:24:47 2012 +0200 summary: Modules/socketmodule.c: netdb_lock: define static. files: Modules/socketmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -761,7 +761,7 @@ /* Lock to allow python interpreter to continue, but only allow one thread to be in gethostbyname or getaddrinfo */ #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) -PyThread_type_lock netdb_lock; +static PyThread_type_lock netdb_lock; #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:33:01 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 14 Aug 2012 17:33:01 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Modules/socket?= =?utf-8?q?module=2Ec=3A_netdb=5Flock=3A_define_static=2E?= Message-ID: <3WxHrF66djzQ4n@mail.python.org> http://hg.python.org/cpython/rev/6ec9e646ffc7 changeset: 78569:6ec9e646ffc7 branch: 3.2 parent: 78564:e0e8e70e4035 user: Matthias Klose date: Tue Aug 14 17:29:04 2012 +0200 summary: Modules/socketmodule.c: netdb_lock: define static. files: Modules/socketmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -804,7 +804,7 @@ /* Lock to allow python interpreter to continue, but only allow one thread to be in gethostbyname or getaddrinfo */ #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) -PyThread_type_lock netdb_lock; +static PyThread_type_lock netdb_lock; #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:33:03 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 14 Aug 2012 17:33:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4y?= Message-ID: <3WxHrH2nT0zQ4n@mail.python.org> http://hg.python.org/cpython/rev/cdf85b7453c9 changeset: 78570:cdf85b7453c9 parent: 78565:05714e9811fa parent: 78569:6ec9e646ffc7 user: Matthias Klose date: Tue Aug 14 17:30:12 2012 +0200 summary: merge 3.2 files: Modules/socketmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -840,7 +840,7 @@ /* Lock to allow python interpreter to continue, but only allow one thread to be in gethostbyname or getaddrinfo */ #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) -PyThread_type_lock netdb_lock; +static PyThread_type_lock netdb_lock; #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:43:11 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 17:43:11 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Add_test_to_ex?= =?utf-8?q?plicit_check_the_absence_regression_in_subprocess_=28issue_=231?= =?utf-8?b?NTU5Miku?= Message-ID: <3WxJ3z3wQdzQ4t@mail.python.org> http://hg.python.org/cpython/rev/839bd8f98539 changeset: 78571:839bd8f98539 branch: 3.2 parent: 78564:e0e8e70e4035 user: Andrew Svetlov date: Tue Aug 14 18:35:17 2012 +0300 summary: Add test to explicit check the absence regression in subprocess (issue #15592). Patch by Chris Jerdonek. files: Lib/test/test_subprocess.py | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 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 @@ -548,6 +548,18 @@ (stdout, stderr) = p.communicate("line1\nline3\n") self.assertEqual(p.returncode, 0) + def test_universal_newlines_communicate_input_none(self): + # Test communicate(input=None) with universal newlines. + # + # We set stdout to PIPE because, as of this writing, a different + # code path is tested when the number of pipes is zero or one. + p = subprocess.Popen([sys.executable, "-c", "pass"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True) + p.communicate() + self.assertEqual(p.returncode, 0) + def test_no_leaking(self): # Make sure we leak no resources if not mswindows: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:43:13 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 17:43:13 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315592=2E_Fix_regression=3A_subprocess=2Ecommuni?= =?utf-8?q?cate=28=29_breaks_on_no_input_with?= Message-ID: <3WxJ413PF6zQ4t@mail.python.org> http://hg.python.org/cpython/rev/9d86480cc177 changeset: 78572:9d86480cc177 parent: 78565:05714e9811fa parent: 78571:839bd8f98539 user: Andrew Svetlov date: Tue Aug 14 18:40:21 2012 +0300 summary: Issue #15592. Fix regression: subprocess.communicate() breaks on no input with universal newlines true. Patch by Chris Jerdonek. files: Lib/subprocess.py | 25 +++++++++++++------------ Lib/test/test_subprocess.py | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1536,6 +1536,17 @@ return (stdout, stderr) + def _save_input(self, input): + # This method is called from the _communicate_with_*() methods + # so that if we time out while communicating, we can continue + # sending input if we retry. + if self.stdin and self._input is None: + self._input_offset = 0 + self._input = input + if self.universal_newlines and input is not None: + self._input = self._input.encode(self.stdin.encoding) + + def _communicate_with_poll(self, input, endtime, orig_timeout): stdout = None # Return stderr = None # Return @@ -1572,13 +1583,7 @@ register_and_append(self.stderr, select_POLLIN_POLLPRI) stderr = self._fd2output[self.stderr.fileno()] - # Save the input here so that if we time out while communicating, - # we can continue sending input if we retry. - if self.stdin and self._input is None: - self._input_offset = 0 - self._input = input - if self.universal_newlines: - self._input = self._input.encode(self.stdin.encoding) + self._save_input(input) while self._fd2file: timeout = self._remaining_time(endtime) @@ -1632,11 +1637,7 @@ if self.stderr: self._read_set.append(self.stderr) - if self.stdin and self._input is None: - self._input_offset = 0 - self._input = input - if self.universal_newlines: - self._input = self._input.encode(self.stdin.encoding) + self._save_input(input) stdout = None # Return stderr = None # Return 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 @@ -615,8 +615,6 @@ universal_newlines=1) self.addCleanup(p.stdout.close) self.addCleanup(p.stderr.close) - # BUG: can't give a non-empty stdin because it breaks both the - # select- and poll-based communicate() implementations. (stdout, stderr) = p.communicate() self.assertEqual(stdout, "line2\nline4\nline5\nline6\nline7\nline8") @@ -635,6 +633,18 @@ (stdout, stderr) = p.communicate("line1\nline3\n") self.assertEqual(p.returncode, 0) + def test_universal_newlines_communicate_input_none(self): + # Test communicate(input=None) with universal newlines. + # + # We set stdout to PIPE because, as of this writing, a different + # code path is tested when the number of pipes is zero or one. + p = subprocess.Popen([sys.executable, "-c", "pass"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True) + p.communicate() + self.assertEqual(p.returncode, 0) + def test_no_leaking(self): # Make sure we leak no resources if not mswindows: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:43:14 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 17:43:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMik6?= =?utf-8?q?_Merge_3=2E2?= Message-ID: <3WxJ426y3vzQ4b@mail.python.org> http://hg.python.org/cpython/rev/84899daa4309 changeset: 78573:84899daa4309 branch: 3.2 parent: 78571:839bd8f98539 parent: 78569:6ec9e646ffc7 user: Andrew Svetlov date: Tue Aug 14 18:41:40 2012 +0300 summary: Merge 3.2 files: Modules/socketmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -804,7 +804,7 @@ /* Lock to allow python interpreter to continue, but only allow one thread to be in gethostbyname or getaddrinfo */ #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) -PyThread_type_lock netdb_lock; +static PyThread_type_lock netdb_lock; #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:43:16 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 17:43:16 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E2_to_default?= Message-ID: <3WxJ443c84zQ55@mail.python.org> http://hg.python.org/cpython/rev/ff1dbee53cb2 changeset: 78574:ff1dbee53cb2 parent: 78572:9d86480cc177 parent: 78573:84899daa4309 user: Andrew Svetlov date: Tue Aug 14 18:42:10 2012 +0300 summary: Merge 3.2 to default files: Modules/socketmodule.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -840,7 +840,7 @@ /* Lock to allow python interpreter to continue, but only allow one thread to be in gethostbyname or getaddrinfo */ #if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) -PyThread_type_lock netdb_lock; +static PyThread_type_lock netdb_lock; #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:43:17 2012 From: python-checkins at python.org (andrew.svetlov) Date: Tue, 14 Aug 2012 17:43:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge_heads?= Message-ID: <3WxJ456Xq5zQ4y@mail.python.org> http://hg.python.org/cpython/rev/e2e85ed7f8ba changeset: 78575:e2e85ed7f8ba parent: 78574:ff1dbee53cb2 parent: 78570:cdf85b7453c9 user: Andrew Svetlov date: Tue Aug 14 18:42:54 2012 +0300 summary: Merge heads files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 17:45:52 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 14 Aug 2012 17:45:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogLSBJc3N1ZSAjMTU2?= =?utf-8?q?47=3A_Make_isdir_static_for_windows_and_posix?= Message-ID: <3WxJ746x3mzPqV@mail.python.org> http://hg.python.org/cpython/rev/bdd1b2228c14 changeset: 78576:bdd1b2228c14 branch: 2.7 parent: 78568:b7d4a13c736e user: Matthias Klose date: Tue Aug 14 17:42:45 2012 +0200 summary: - Issue #15647: Make isdir static for windows and posix files: Python/import.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -115,7 +115,7 @@ #endif #ifdef MS_WINDOWS -int isdir(char *path) { +static int isdir(char *path) { DWORD rv; /* see issue1293 and issue3677: * stat() on Windows doesn't recognise paths like @@ -128,7 +128,7 @@ } #else #ifdef HAVE_STAT -int isdir(char *path) { +static int isdir(char *path) { struct stat statbuf; return stat(path, &statbuf) == 0 && S_ISDIR(statbuf.st_mode); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 19:52:40 2012 From: python-checkins at python.org (sandro.tosi) Date: Tue, 14 Aug 2012 19:52:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_fix_typo?= Message-ID: <3WxLxN2MXPzQ5J@mail.python.org> http://hg.python.org/cpython/rev/0dbdaa0ff648 changeset: 78577:0dbdaa0ff648 branch: 2.7 user: Sandro Tosi date: Tue Aug 14 19:51:31 2012 +0200 summary: fix typo files: Doc/tutorial/inputoutput.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -37,7 +37,7 @@ The :func:`str` function is meant to return representations of values which are fairly human-readable, while :func:`repr` is meant to generate representations which can be read by the interpreter (or will force a :exc:`SyntaxError` if -there is not equivalent syntax). For objects which don't have a particular +there is no equivalent syntax). For objects which don't have a particular representation for human consumption, :func:`str` will return the same value as :func:`repr`. Many values, such as numbers or structures like lists and dictionaries, have the same representation using either function. Strings and -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 19:52:42 2012 From: python-checkins at python.org (sandro.tosi) Date: Tue, 14 Aug 2012 19:52:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_fix_typo?= Message-ID: <3WxLxQ085jzQ5W@mail.python.org> http://hg.python.org/cpython/rev/7e56c46f5707 changeset: 78578:7e56c46f5707 branch: 3.2 parent: 78573:84899daa4309 user: Sandro Tosi date: Tue Aug 14 19:51:43 2012 +0200 summary: fix typo files: Doc/tutorial/inputoutput.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -37,7 +37,7 @@ The :func:`str` function is meant to return representations of values which are fairly human-readable, while :func:`repr` is meant to generate representations which can be read by the interpreter (or will force a :exc:`SyntaxError` if -there is not equivalent syntax). For objects which don't have a particular +there is no equivalent syntax). For objects which don't have a particular representation for human consumption, :func:`str` will return the same value as :func:`repr`. Many values, such as numbers or structures like lists and dictionaries, have the same representation using either function. Strings, in -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 14 19:52:43 2012 From: python-checkins at python.org (sandro.tosi) Date: Tue, 14 Aug 2012 19:52:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3WxLxR3QWSzQ5k@mail.python.org> http://hg.python.org/cpython/rev/ba9b35fb9c40 changeset: 78579:ba9b35fb9c40 parent: 78575:e2e85ed7f8ba parent: 78578:7e56c46f5707 user: Sandro Tosi date: Tue Aug 14 19:52:04 2012 +0200 summary: merge with 3.2 files: Doc/tutorial/inputoutput.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -37,7 +37,7 @@ The :func:`str` function is meant to return representations of values which are fairly human-readable, while :func:`repr` is meant to generate representations which can be read by the interpreter (or will force a :exc:`SyntaxError` if -there is not equivalent syntax). For objects which don't have a particular +there is no equivalent syntax). For objects which don't have a particular representation for human consumption, :func:`str` will return the same value as :func:`repr`. Many values, such as numbers or structures like lists and dictionaries, have the same representation using either function. Strings, in -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 03:51:23 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 03:51:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1MjY5OiBkb2N1?= =?utf-8?q?ment_dircmp=2Eleft_and_right=2C_and_add_tests_for_them=2E?= Message-ID: <3WxYYl07sszQ7P@mail.python.org> http://hg.python.org/cpython/rev/7590dec388a7 changeset: 78580:7590dec388a7 branch: 3.2 parent: 78578:7e56c46f5707 user: R David Murray date: Tue Aug 14 21:40:13 2012 -0400 summary: #15269: document dircmp.left and right, and add tests for them. Patch by Chris Jerdonek. files: Doc/library/filecmp.rst | 25 +++++++++++++++++++++++++ Lib/test/test_filecmp.py | 10 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Doc/library/filecmp.rst b/Doc/library/filecmp.rst --- a/Doc/library/filecmp.rst +++ b/Doc/library/filecmp.rst @@ -106,6 +106,16 @@ to compute are used. + .. attribute:: left + + The directory *a*. + + + .. attribute:: right + + The directory *b*. + + .. attribute:: left_list Files and subdirectories in *a*, filtered by *hide* and *ignore*. @@ -169,3 +179,18 @@ A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp` objects. + +Here is a simplified example of using the ``subdirs`` attribute to search +recursively through two directories to show common different files:: + + >>> from filecmp import dircmp + >>> def print_diff_files(dcmp): + ... for name in dcmp.diff_files: + ... print("diff_file %s found in %s and %s" % (name, dcmp.left, + ... dcmp.right)) + ... for sub_dcmp in dcmp.subdirs.values(): + ... print_diff_files(sub_dcmp) + ... + >>> dcmp = dircmp('dir1', 'dir2') + >>> print_diff_files(dcmp) + diff --git a/Lib/test/test_filecmp.py b/Lib/test/test_filecmp.py --- a/Lib/test/test_filecmp.py +++ b/Lib/test/test_filecmp.py @@ -98,7 +98,10 @@ def test_dircmp(self): # Check attributes for comparison of two identical directories - d = filecmp.dircmp(self.dir, self.dir_same) + left_dir, right_dir = self.dir, self.dir_same + d = filecmp.dircmp(left_dir, right_dir) + self.assertEqual(d.left, left_dir) + self.assertEqual(d.right, right_dir) if self.caseinsensitive: self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) else: @@ -109,7 +112,10 @@ self.assertEqual(d.diff_files, []) # Check attributes for comparison of two different directories - d = filecmp.dircmp(self.dir, self.dir_diff) + left_dir, right_dir = self.dir, self.dir_diff + d = filecmp.dircmp(left_dir, right_dir) + self.assertEqual(d.left, left_dir) + self.assertEqual(d.right, right_dir) self.assertEqual(d.left_list, ['file']) self.assertTrue(d.right_list == ['file', 'file2']) self.assertEqual(d.common, ['file']) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 03:51:25 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 03:51:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315269=3A_document_dircmp=2Eleft_and_right=2C_an?= =?utf-8?q?d_add_tests_for_them=2E?= Message-ID: <3WxYYn5pYZzQ8K@mail.python.org> http://hg.python.org/cpython/rev/c592e5a8fa4f changeset: 78581:c592e5a8fa4f parent: 78579:ba9b35fb9c40 parent: 78580:7590dec388a7 user: R David Murray date: Tue Aug 14 21:45:25 2012 -0400 summary: Merge #15269: document dircmp.left and right, and add tests for them. Patch by Chris Jerdonek. files: Doc/library/filecmp.rst | 25 +++++++++++++++++++++++++ Lib/test/test_filecmp.py | 10 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Doc/library/filecmp.rst b/Doc/library/filecmp.rst --- a/Doc/library/filecmp.rst +++ b/Doc/library/filecmp.rst @@ -91,6 +91,16 @@ to compute are used. + .. attribute:: left + + The directory *a*. + + + .. attribute:: right + + The directory *b*. + + .. attribute:: left_list Files and subdirectories in *a*, filtered by *hide* and *ignore*. @@ -154,3 +164,18 @@ A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp` objects. + +Here is a simplified example of using the ``subdirs`` attribute to search +recursively through two directories to show common different files:: + + >>> from filecmp import dircmp + >>> def print_diff_files(dcmp): + ... for name in dcmp.diff_files: + ... print("diff_file %s found in %s and %s" % (name, dcmp.left, + ... dcmp.right)) + ... for sub_dcmp in dcmp.subdirs.values(): + ... print_diff_files(sub_dcmp) + ... + >>> dcmp = dircmp('dir1', 'dir2') + >>> print_diff_files(dcmp) + diff --git a/Lib/test/test_filecmp.py b/Lib/test/test_filecmp.py --- a/Lib/test/test_filecmp.py +++ b/Lib/test/test_filecmp.py @@ -98,7 +98,10 @@ def test_dircmp(self): # Check attributes for comparison of two identical directories - d = filecmp.dircmp(self.dir, self.dir_same) + left_dir, right_dir = self.dir, self.dir_same + d = filecmp.dircmp(left_dir, right_dir) + self.assertEqual(d.left, left_dir) + self.assertEqual(d.right, right_dir) if self.caseinsensitive: self.assertEqual([d.left_list, d.right_list],[['file'], ['FiLe']]) else: @@ -109,7 +112,10 @@ self.assertEqual(d.diff_files, []) # Check attributes for comparison of two different directories - d = filecmp.dircmp(self.dir, self.dir_diff) + left_dir, right_dir = self.dir, self.dir_diff + d = filecmp.dircmp(left_dir, right_dir) + self.assertEqual(d.left, left_dir) + self.assertEqual(d.right, right_dir) self.assertEqual(d.left_list, ['file']) self.assertTrue(d.right_list == ['file', 'file2']) self.assertEqual(d.common, ['file']) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 03:51:27 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 03:51:27 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1MjY5OiBkb2N1?= =?utf-8?q?ment_dircmp=2Eleft_and_right=2E?= Message-ID: <3WxYYq1T2zzQ7v@mail.python.org> http://hg.python.org/cpython/rev/e64d4518b23c changeset: 78582:e64d4518b23c branch: 2.7 parent: 78577:0dbdaa0ff648 user: R David Murray date: Tue Aug 14 21:50:38 2012 -0400 summary: #15269: document dircmp.left and right. Based on patch by Chris Jerdonek. files: Doc/library/filecmp.rst | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/Doc/library/filecmp.rst b/Doc/library/filecmp.rst --- a/Doc/library/filecmp.rst +++ b/Doc/library/filecmp.rst @@ -106,6 +106,16 @@ to compute are used. + .. attribute:: left + + The directory *a*. + + + .. attribute:: right + + The directory *b*. + + .. attribute:: left_list Files and subdirectories in *a*, filtered by *hide* and *ignore*. @@ -168,3 +178,18 @@ A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp` objects. + +Here is a simplified example of using the ``subdirs`` attribute to search +recursively through two directories to show common different files:: + + >>> from filecmp import dircmp + >>> def print_diff_files(dcmp): + ... for name in dcmp.diff_files: + ... print "diff_file %s found in %s and %s" % (name, dcmp.left, + ... dcmp.right) + ... for sub_dcmp in dcmp.subdirs.values(): + ... print_diff_files(sub_dcmp) + ... + >>> dcmp = dircmp('dir1', 'dir2') + >>> print_diff_files(dcmp) + -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Aug 15 05:59:50 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 15 Aug 2012 05:59:50 +0200 Subject: [Python-checkins] Daily reference leaks (ba9b35fb9c40): sum=0 Message-ID: results for ba9b35fb9c40 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogFpTxNu', '-x'] From python-checkins at python.org Wed Aug 15 13:27:27 2012 From: python-checkins at python.org (eli.bendersky) Date: Wed, 15 Aug 2012 13:27:27 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315586=3A_typo_fix?= =?utf-8?q?=2E_This_commit_is_accompanied_by_an_apology_for_all?= Message-ID: <3WxpLR6rBpzQBM@mail.python.org> http://hg.python.org/cpython/rev/8d90fde35cc6 changeset: 78583:8d90fde35cc6 parent: 78581:c592e5a8fa4f user: Eli Bendersky date: Wed Aug 15 14:26:30 2012 +0300 summary: Issue #15586: typo fix. This commit is accompanied by an apology for all Liechtensteiners out there, and a thanks to Eric Araujo for noticing. files: Doc/library/xml.etree.elementtree.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -41,7 +41,7 @@ - + 1 2008 141100 @@ -89,7 +89,7 @@ >>> for child in root: ... print(child.tag, child.attrib) ... - country {'name': 'Liechtenshtein'} + country {'name': 'Liechtenstein'} country {'name': 'Singapore'} country {'name': 'Panama'} @@ -124,7 +124,7 @@ ... name = country.get('name') ... print(name, rank) ... - Liechtenshtein 1 + Liechtenstein 1 Singapore 4 Panama 68 @@ -158,7 +158,7 @@ - + 2 2008 141100 @@ -196,7 +196,7 @@ - + 2 2008 141100 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 13:42:20 2012 From: python-checkins at python.org (petri.lehtinen) Date: Wed, 15 Aug 2012 13:42:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzExMDYyOiBGaXgg?= =?utf-8?q?adding_a_message_from_file_to_Babyl_mailbox?= Message-ID: <3Wxpgc4LMTzQBS@mail.python.org> http://hg.python.org/cpython/rev/ad8c9725c041 changeset: 78584:ad8c9725c041 branch: 2.7 parent: 78582:e64d4518b23c user: Petri Lehtinen date: Wed Aug 15 14:22:46 2012 +0300 summary: #11062: Fix adding a message from file to Babyl mailbox files: Lib/mailbox.py | 2 +- Lib/test/test_mailbox.py | 13 +++++++++++++ Misc/NEWS | 2 ++ 3 files changed, 16 insertions(+), 1 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1386,9 +1386,9 @@ line = message.readline() self._file.write(line.replace('\n', os.linesep)) if line == '\n' or line == '': - self._file.write('*** EOOH ***' + os.linesep) if first_pass: first_pass = False + self._file.write('*** EOOH ***' + os.linesep) message.seek(original_pos) else: break diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -8,6 +8,7 @@ import re import shutil import StringIO +import tempfile from test import test_support import unittest import mailbox @@ -75,6 +76,18 @@ for i in (1, 2, 3, 4): self._check_sample(self._box[keys[i]]) + def test_add_file(self): + with tempfile.TemporaryFile('w+') as f: + f.write(_sample_message) + f.seek(0) + key = self._box.add(f) + self.assertEqual(self._box.get_string(key).split('\n'), + _sample_message.split('\n')) + + def test_add_StringIO(self): + key = self._box.add(StringIO.StringIO(self._template % "0")) + self.assertEqual(self._box.get_string(key), self._template % "0") + def test_remove(self): # Remove messages using remove() self._test_remove_or_delitem(self._box.remove) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -92,6 +92,8 @@ Library ------- +- Issue #11062: Fix adding a message from file to Babyl mailbox. + - Issue #15646: Prevent equivalent of a fork bomb when using multiprocessing on Windows without the "if __name__ == '__main__'" idiom. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 13:42:22 2012 From: python-checkins at python.org (petri.lehtinen) Date: Wed, 15 Aug 2012 13:42:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzExMDYyOiBGaXgg?= =?utf-8?q?adding_a_message_from_file_to_Babyl_mailbox?= Message-ID: <3Wxpgf1GqTzQBh@mail.python.org> http://hg.python.org/cpython/rev/cbc1dc8cda06 changeset: 78585:cbc1dc8cda06 branch: 3.2 parent: 78580:7590dec388a7 user: Petri Lehtinen date: Wed Aug 15 14:00:40 2012 +0300 summary: #11062: Fix adding a message from file to Babyl mailbox files: Lib/mailbox.py | 2 +- Lib/test/test_mailbox.py | 18 ++++++------------ Misc/NEWS | 2 ++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1443,9 +1443,9 @@ line = line[:-1] + b'\n' self._file.write(line.replace(b'\n', linesep)) if line == b'\n' or not line: - self._file.write(b'*** EOOH ***' + linesep) if first_pass: first_pass = False + self._file.write(b'*** EOOH ***' + linesep) message.seek(original_pos) else: break diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -148,20 +148,16 @@ f.write(_bytes_sample_message) f.seek(0) key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - _bytes_sample_message.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + _bytes_sample_message.split(b'\n')) def test_add_binary_nonascii_file(self): with tempfile.TemporaryFile('wb+') as f: f.write(self._non_latin_bin_msg) f.seek(0) key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - self._non_latin_bin_msg.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + self._non_latin_bin_msg.split(b'\n')) def test_add_text_file_warns(self): with tempfile.TemporaryFile('w+') as f: @@ -169,10 +165,8 @@ f.seek(0) with self.assertWarns(DeprecationWarning): key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - _bytes_sample_message.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + _bytes_sample_message.split(b'\n')) def test_add_StringIO_warns(self): with self.assertWarns(DeprecationWarning): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,8 @@ Library ------- +- Issue #11062: Fix adding a message from file to Babyl mailbox. + - Issue #15646: Prevent equivalent of a fork bomb when using multiprocessing on Windows without the "if __name__ == '__main__'" idiom. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 13:42:23 2012 From: python-checkins at python.org (petri.lehtinen) Date: Wed, 15 Aug 2012 13:42:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_=2311062=3A_Fix_adding_a_message_from_file_to_Babyl_mail?= =?utf-8?q?box?= Message-ID: <3Wxpgg4QByzQBX@mail.python.org> http://hg.python.org/cpython/rev/7c8c6b905a18 changeset: 78586:7c8c6b905a18 parent: 78583:8d90fde35cc6 parent: 78585:cbc1dc8cda06 user: Petri Lehtinen date: Wed Aug 15 14:36:14 2012 +0300 summary: #11062: Fix adding a message from file to Babyl mailbox files: Lib/mailbox.py | 2 +- Lib/test/test_mailbox.py | 18 ++++++------------ Misc/NEWS | 2 ++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1440,9 +1440,9 @@ line = line[:-1] + b'\n' self._file.write(line.replace(b'\n', linesep)) if line == b'\n' or not line: - self._file.write(b'*** EOOH ***' + linesep) if first_pass: first_pass = False + self._file.write(b'*** EOOH ***' + linesep) message.seek(original_pos) else: break diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -152,20 +152,16 @@ f.write(_bytes_sample_message) f.seek(0) key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - _bytes_sample_message.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + _bytes_sample_message.split(b'\n')) def test_add_binary_nonascii_file(self): with tempfile.TemporaryFile('wb+') as f: f.write(self._non_latin_bin_msg) f.seek(0) key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - self._non_latin_bin_msg.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + self._non_latin_bin_msg.split(b'\n')) def test_add_text_file_warns(self): with tempfile.TemporaryFile('w+') as f: @@ -173,10 +169,8 @@ f.seek(0) with self.assertWarns(DeprecationWarning): key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - _bytes_sample_message.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + _bytes_sample_message.split(b'\n')) def test_add_StringIO_warns(self): with self.assertWarns(DeprecationWarning): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,8 @@ Library ------- +- Issue #11062: Fix adding a message from file to Babyl mailbox. + - Issue #15646: Prevent equivalent of a fork bomb when using multiprocessing on Windows without the "if __name__ == '__main__'" idiom. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 13:52:28 2012 From: python-checkins at python.org (eli.bendersky) Date: Wed, 15 Aug 2012 13:52:28 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NjU2?= =?utf-8?q?=3A_fixing_code_sample_in_extending_doc?= Message-ID: <3WxpvJ1LmvzP1Q@mail.python.org> http://hg.python.org/cpython/rev/599376deeeac changeset: 78587:599376deeeac branch: 3.2 parent: 78580:7590dec388a7 user: Eli Bendersky date: Wed Aug 15 14:49:49 2012 +0300 summary: Issue #15656: fixing code sample in extending doc files: Doc/extending/extending.rst | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -735,13 +735,18 @@ {NULL, NULL, 0, NULL} /* sentinel */ }; -:: + static struct PyModuleDef keywdargmodule = { + PyModuleDef_HEAD_INIT, + "keywdarg", + NULL, + -1, + keywdarg_methods + }; - void - initkeywdarg(void) + PyMODINIT_FUNC + PyInit_keywdarg(void) { - /* Create the module and add the functions */ - Py_InitModule("keywdarg", keywdarg_methods); + return PyModule_Create(&keywdargmodule); } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 13:52:30 2012 From: python-checkins at python.org (eli.bendersky) Date: Wed, 15 Aug 2012 13:52:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMy4yIC0+IDMuMik6?= =?utf-8?q?_merge_heads_in_3=2E2_branch?= Message-ID: <3WxpvL08tzzQC6@mail.python.org> http://hg.python.org/cpython/rev/a4ad88218dca changeset: 78588:a4ad88218dca branch: 3.2 parent: 78587:599376deeeac parent: 78585:cbc1dc8cda06 user: Eli Bendersky date: Wed Aug 15 14:50:52 2012 +0300 summary: merge heads in 3.2 branch files: Lib/mailbox.py | 2 +- Lib/test/test_mailbox.py | 18 ++++++------------ Misc/NEWS | 2 ++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1443,9 +1443,9 @@ line = line[:-1] + b'\n' self._file.write(line.replace(b'\n', linesep)) if line == b'\n' or not line: - self._file.write(b'*** EOOH ***' + linesep) if first_pass: first_pass = False + self._file.write(b'*** EOOH ***' + linesep) message.seek(original_pos) else: break diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -148,20 +148,16 @@ f.write(_bytes_sample_message) f.seek(0) key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - _bytes_sample_message.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + _bytes_sample_message.split(b'\n')) def test_add_binary_nonascii_file(self): with tempfile.TemporaryFile('wb+') as f: f.write(self._non_latin_bin_msg) f.seek(0) key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - self._non_latin_bin_msg.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + self._non_latin_bin_msg.split(b'\n')) def test_add_text_file_warns(self): with tempfile.TemporaryFile('w+') as f: @@ -169,10 +165,8 @@ f.seek(0) with self.assertWarns(DeprecationWarning): key = self._box.add(f) - # See issue 11062 - if not isinstance(self._box, mailbox.Babyl): - self.assertEqual(self._box.get_bytes(key).split(b'\n'), - _bytes_sample_message.split(b'\n')) + self.assertEqual(self._box.get_bytes(key).split(b'\n'), + _bytes_sample_message.split(b'\n')) def test_add_StringIO_warns(self): with self.assertWarns(DeprecationWarning): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -101,6 +101,8 @@ Library ------- +- Issue #11062: Fix adding a message from file to Babyl mailbox. + - Issue #15646: Prevent equivalent of a fork bomb when using multiprocessing on Windows without the "if __name__ == '__main__'" idiom. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 13:52:31 2012 From: python-checkins at python.org (eli.bendersky) Date: Wed, 15 Aug 2012 13:52:31 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4y?= Message-ID: <3WxpvM2xDrzQCJ@mail.python.org> http://hg.python.org/cpython/rev/f46b4b7b817c changeset: 78589:f46b4b7b817c parent: 78586:7c8c6b905a18 parent: 78588:a4ad88218dca user: Eli Bendersky date: Wed Aug 15 14:51:08 2012 +0300 summary: merge 3.2 files: Doc/extending/extending.rst | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -732,13 +732,18 @@ {NULL, NULL, 0, NULL} /* sentinel */ }; -:: + static struct PyModuleDef keywdargmodule = { + PyModuleDef_HEAD_INIT, + "keywdarg", + NULL, + -1, + keywdarg_methods + }; - void - initkeywdarg(void) + PyMODINIT_FUNC + PyInit_keywdarg(void) { - /* Create the module and add the functions */ - Py_InitModule("keywdarg", keywdarg_methods); + return PyModule_Create(&keywdargmodule); } -- Repository URL: http://hg.python.org/cpython From andrew.svetlov at gmail.com Wed Aug 15 16:17:16 2012 From: andrew.svetlov at gmail.com (Andrew Svetlov) Date: Wed, 15 Aug 2012 17:17:16 +0300 Subject: [Python-checkins] cpython (merge 3.2 -> default): #11062: Fix adding a message from file to Babyl mailbox In-Reply-To: <3Wxpgg4QByzQBX@mail.python.org> References: <3Wxpgg4QByzQBX@mail.python.org> Message-ID: Looks like it is the source of buildbot fail on Windows box. On Wed, Aug 15, 2012 at 2:42 PM, petri.lehtinen wrote: > http://hg.python.org/cpython/rev/7c8c6b905a18 > changeset: 78586:7c8c6b905a18 > parent: 78583:8d90fde35cc6 > parent: 78585:cbc1dc8cda06 > user: Petri Lehtinen > date: Wed Aug 15 14:36:14 2012 +0300 > summary: > #11062: Fix adding a message from file to Babyl mailbox > > files: > Lib/mailbox.py | 2 +- > Lib/test/test_mailbox.py | 18 ++++++------------ > Misc/NEWS | 2 ++ > 3 files changed, 9 insertions(+), 13 deletions(-) > > > diff --git a/Lib/mailbox.py b/Lib/mailbox.py > --- a/Lib/mailbox.py > +++ b/Lib/mailbox.py > @@ -1440,9 +1440,9 @@ > line = line[:-1] + b'\n' > self._file.write(line.replace(b'\n', linesep)) > if line == b'\n' or not line: > - self._file.write(b'*** EOOH ***' + linesep) > if first_pass: > first_pass = False > + self._file.write(b'*** EOOH ***' + linesep) > message.seek(original_pos) > else: > break > diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py > --- a/Lib/test/test_mailbox.py > +++ b/Lib/test/test_mailbox.py > @@ -152,20 +152,16 @@ > f.write(_bytes_sample_message) > f.seek(0) > key = self._box.add(f) > - # See issue 11062 > - if not isinstance(self._box, mailbox.Babyl): > - self.assertEqual(self._box.get_bytes(key).split(b'\n'), > - _bytes_sample_message.split(b'\n')) > + self.assertEqual(self._box.get_bytes(key).split(b'\n'), > + _bytes_sample_message.split(b'\n')) > > def test_add_binary_nonascii_file(self): > with tempfile.TemporaryFile('wb+') as f: > f.write(self._non_latin_bin_msg) > f.seek(0) > key = self._box.add(f) > - # See issue 11062 > - if not isinstance(self._box, mailbox.Babyl): > - self.assertEqual(self._box.get_bytes(key).split(b'\n'), > - self._non_latin_bin_msg.split(b'\n')) > + self.assertEqual(self._box.get_bytes(key).split(b'\n'), > + self._non_latin_bin_msg.split(b'\n')) > > def test_add_text_file_warns(self): > with tempfile.TemporaryFile('w+') as f: > @@ -173,10 +169,8 @@ > f.seek(0) > with self.assertWarns(DeprecationWarning): > key = self._box.add(f) > - # See issue 11062 > - if not isinstance(self._box, mailbox.Babyl): > - self.assertEqual(self._box.get_bytes(key).split(b'\n'), > - _bytes_sample_message.split(b'\n')) > + self.assertEqual(self._box.get_bytes(key).split(b'\n'), > + _bytes_sample_message.split(b'\n')) > > def test_add_StringIO_warns(self): > with self.assertWarns(DeprecationWarning): > diff --git a/Misc/NEWS b/Misc/NEWS > --- a/Misc/NEWS > +++ b/Misc/NEWS > @@ -13,6 +13,8 @@ > Library > ------- > > +- Issue #11062: Fix adding a message from file to Babyl mailbox. > + > - Issue #15646: Prevent equivalent of a fork bomb when using > multiprocessing on Windows without the "if __name__ == '__main__'" > idiom. > > -- > 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 Wed Aug 15 16:36:25 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 15 Aug 2012 16:36:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Cleanup_universal=5Fnewlin?= =?utf-8?q?es_usage_for_subprocess=2EPopen=2C_remove_unused_param=2E?= Message-ID: <3WxtXT2hRmzPrb@mail.python.org> http://hg.python.org/cpython/rev/65ef6ae39ea3 changeset: 78590:65ef6ae39ea3 user: Andrew Svetlov date: Wed Aug 15 17:36:15 2012 +0300 summary: Cleanup universal_newlines usage for subprocess.Popen, remove unused param. files: Lib/subprocess.py | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -797,7 +797,7 @@ if p2cwrite != -1: self.stdin = io.open(p2cwrite, 'wb', bufsize) - if self.universal_newlines: + if universal_newlines: self.stdin = io.TextIOWrapper(self.stdin, write_through=True) if c2pread != -1: self.stdout = io.open(c2pread, 'rb', bufsize) @@ -810,7 +810,7 @@ try: self._execute_child(args, executable, preexec_fn, close_fds, - pass_fds, cwd, env, universal_newlines, + pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, @@ -1035,7 +1035,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, - pass_fds, cwd, env, universal_newlines, + pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, @@ -1307,7 +1307,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, - pass_fds, cwd, env, universal_newlines, + pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 17:23:54 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 17:23:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1NTQzOiBnbG9z?= =?utf-8?q?sary_entry_for_and_=27universal_newlines=27=2C_and_links_to_it?= =?utf-8?q?=2E?= Message-ID: <3WxvbG1sQdzPp1@mail.python.org> http://hg.python.org/cpython/rev/273df9789796 changeset: 78591:273df9789796 branch: 3.2 parent: 78588:a4ad88218dca user: R David Murray date: Wed Aug 15 10:43:58 2012 -0400 summary: #15543: glossary entry for and 'universal newlines', and links to it. Patch by Chris Jerdonek. files: Doc/glossary.rst | 7 +++++++ Doc/library/bz2.rst | 5 ++++- Doc/library/csv.rst | 6 +++++- Doc/library/functions.rst | 12 ++++++++---- Doc/library/importlib.rst | 7 ++++++- Doc/library/io.rst | 17 ++++++++++++----- Doc/library/stdtypes.rst | 5 ++++- Doc/library/subprocess.rst | 9 ++++++--- Doc/library/zipfile.rst | 8 ++++++-- Doc/whatsnew/2.3.rst | 6 +++++- Doc/whatsnew/2.4.rst | 5 ++++- Doc/whatsnew/2.5.rst | 8 ++++++-- Doc/whatsnew/2.6.rst | 5 ++++- 13 files changed, 77 insertions(+), 23 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -600,6 +600,13 @@ object has a type. An object's type is accessible as its :attr:`__class__` attribute or can be retrieved with ``type(obj)``. + universal newlines + A manner of interpreting text streams in which all of the following are + recognized as ending a line: the Unix end-of-line convention ``'\n'``, + the Windows convention ``'\r\n'``, and the old Macintosh convention + ``'\r'``. See :pep:`278` and :pep:`3116`, as well as + :func:`str.splitlines` for an additional use. + view The objects returned from :meth:`dict.keys`, :meth:`dict.values`, and :meth:`dict.items` are called dictionary views. They are lazy sequences diff --git a/Doc/library/bz2.rst b/Doc/library/bz2.rst --- a/Doc/library/bz2.rst +++ b/Doc/library/bz2.rst @@ -40,6 +40,9 @@ Handling of compressed files is offered by the :class:`BZ2File` class. +.. index:: + single: universal newlines; bz2.BZ2File class + .. class:: BZ2File(filename, mode='r', buffering=0, compresslevel=9) Open a bz2 file. Mode can be either ``'r'`` or ``'w'``, for reading (default) @@ -48,7 +51,7 @@ unbuffered, and larger numbers specify the buffer size; the default is ``0``. If *compresslevel* is given, it must be a number between ``1`` and ``9``; the default is ``9``. Add a ``'U'`` to mode to open the file for input - with universal newline support. Any line ending in the input file will be + in :term:`universal newlines` mode. Any line ending in the input file will be seen as a ``'\n'`` in Python. Also, a file so opened gains the attribute :attr:`newlines`; the value for this attribute is one of ``None`` (no newline read yet), ``'\r'``, ``'\n'``, ``'\r\n'`` or a tuple containing all the diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -46,6 +46,9 @@ The :mod:`csv` module defines the following functions: +.. index:: + single: universal newlines; csv.reader function + .. function:: reader(csvfile, dialect='excel', **fmtparams) Return a reader object which will iterate over lines in the given *csvfile*. @@ -486,4 +489,5 @@ .. [1] If ``newline=''`` is not specified, newlines embedded inside quoted fields will not be interpreted correctly, and on platforms that use ``\r\n`` linendings on write an extra ``\r`` will be added. It should always be safe to specify - ``newline=''``, since the csv module does its own (universal) newline handling. + ``newline=''``, since the csv module does its own + (:term:`universal `) newline handling. diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -819,7 +819,7 @@ ``'b'`` binary mode ``'t'`` text mode (default) ``'+'`` open a disk file for updating (reading and writing) - ``'U'`` universal newline mode (for backwards compatibility; should + ``'U'`` universal newlines mode (for backwards compatibility; should not be used in new code) ========= =============================================================== @@ -874,14 +874,18 @@ used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. - *newline* controls how universal newlines works (it only applies to text - mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It + .. index:: + single: universal newlines; open() built-in function + + *newline* controls how :term:`universal newlines` mode works (it only + applies to text mode). + It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: * When reading input from the stream, if *newline* is ``None``, universal newlines mode is enabled. Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before - being returned to the caller. If it is ``''``, universal newline mode is + being returned to the caller. If it is ``''``, universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -189,10 +189,15 @@ (e.g. built-in module). :exc:`ImportError` is raised if loader cannot find the requested module. + .. index:: + single: universal newlines; importlib.abc.InspectLoader.get_source method + .. method:: get_source(fullname) An abstract method to return the source of a module. It is returned as - a text string with universal newlines. Returns ``None`` if no + a text string using :term:`universal newlines`, translating all + recognized line separators into ``'\n'`` characters. + Returns ``None`` if no source is available (e.g. a built-in module). Raises :exc:`ImportError` if the loader cannot find the module specified. diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -757,13 +757,17 @@ sequences) can be used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. + .. index:: + single: universal newlines; io.TextIOWrapper class + *newline* controls how line endings are handled. It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * When reading input from the stream, if *newline* is ``None``, universal - newlines mode is enabled. Lines in the input can end in ``'\n'``, + * When reading input from the stream, if *newline* is ``None``, + :term:`universal newlines` mode is enabled. Lines in the input can end + in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before - being returned to the caller. If it is ``''``, universal newline mode is + being returned to the caller. If it is ``''``, universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. @@ -819,10 +823,13 @@ output.close() +.. index:: + single: universal newlines; io.IncrementalNewlineDecoder class + .. class:: IncrementalNewlineDecoder - A helper codec that decodes newlines for universal newlines mode. It - inherits :class:`codecs.IncrementalDecoder`. + A helper codec that decodes newlines for :term:`universal newlines` mode. + It inherits :class:`codecs.IncrementalDecoder`. Performance diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1325,10 +1325,13 @@ ``' 1 2 3 '.split(None, 1)`` returns ``['1', '2 3 ']``. +.. index:: + single: universal newlines; str.splitlines method + .. method:: str.splitlines([keepends]) Return a list of the lines in the string, breaking at line boundaries. - This method uses the universal newlines approach to splitting lines. + This method uses the :term:`universal newlines` approach to splitting lines. Line breaks are not included in the resulting list unless *keepends* is given and true. diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -224,9 +224,12 @@ the stderr data from the child process should be captured into the same file handle as for stdout. + .. index:: + single: universal newlines; subprocess module + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* - and *stderr* will be opened as text streams with universal newlines support, - using the encoding returned by :func:`locale.getpreferredencoding`. + and *stderr* will be opened as text streams in :term:`universal newlines` + mode using the encoding returned by :func:`locale.getpreferredencoding`. For *stdin*, line ending characters ``'\n'`` in the input will be converted to the default line separator :data:`os.linesep`. For *stdout* and *stderr*, all line endings in the output will be converted to ``'\n'``. @@ -440,7 +443,7 @@ .. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* - and *stderr* are opened as text files with universal newlines support, as + and *stderr* are opened as text streams in universal newlines mode, as described above in :ref:`frequently-used-arguments`. If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -169,13 +169,17 @@ Return a list of archive members by name. +.. index:: + single: universal newlines; zipfile.ZipFile.open method + .. method:: ZipFile.open(name, mode='r', pwd=None) Extract a member from the archive as a file-like object (ZipExtFile). *name* is the name of the file in the archive, or a :class:`ZipInfo` object. The *mode* parameter, if included, must be one of the following: ``'r'`` (the default), - ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable universal newline - support in the read-only object. *pwd* is the password used for encrypted files. + ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable + :term:`universal newlines` support in the read-only object. + *pwd* is the password used for encrypted files. Calling :meth:`open` on a closed ZipFile will raise a :exc:`RuntimeError`. .. note:: diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -366,6 +366,9 @@ .. ====================================================================== +.. index:: + single: universal newlines; What's new + PEP 278: Universal Newline Support ================================== @@ -378,7 +381,8 @@ Python's file objects can now support end of line conventions other than the one followed by the platform on which Python is running. Opening a file with the -mode ``'U'`` or ``'rU'`` will open a file for reading in universal newline mode. +mode ``'U'`` or ``'rU'`` will open a file for reading in +:term:`universal newlines` mode. All three line ending conventions will be translated to a ``'\n'`` in the strings returned by the various file methods such as :meth:`read` and :meth:`readline`. diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -411,6 +411,9 @@ you can use the constant ``subprocess.PIPE`` to create a pipe between the subprocess and the parent. +.. index:: + single: universal newlines; What's new + The constructor has a number of handy options: * *close_fds* requests that all file descriptors be closed before running the @@ -424,7 +427,7 @@ * *preexec_fn* is a function that gets called before the child is started. * *universal_newlines* opens the child's input and output using Python's - universal newline feature. + :term:`universal newlines` feature. Once you've created the :class:`Popen` instance, you can call its :meth:`wait` method to pause until the subprocess has exited, :meth:`poll` to check if it's diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1338,10 +1338,14 @@ .. XXX need to provide some more detail here + .. index:: + single: universal newlines; What's new + * The :mod:`fileinput` module was made more flexible. Unicode filenames are now supported, and a *mode* parameter that defaults to ``"r"`` was added to the - :func:`input` function to allow opening files in binary or universal-newline - mode. Another new parameter, *openhook*, lets you use a function other than + :func:`input` function to allow opening files in binary or + :term:`universal newlines` mode. + Another new parameter, *openhook*, lets you use a function other than :func:`open` to open the input files. Once you're iterating over the set of files, the :class:`FileInput` object's new :meth:`fileno` returns the file descriptor for the currently opened file. (Contributed by Georg Brandl.) diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -1071,9 +1071,12 @@ The :class:`BytesIO` class supports reading, writing, and seeking over an in-memory buffer. + .. index:: + single: universal newlines; What's new + * :class:`TextIOBase`: Provides functions for reading and writing strings (remember, strings will be Unicode in Python 3.0), - and supporting universal newlines. :class:`TextIOBase` defines + and supporting :term:`universal newlines`. :class:`TextIOBase` defines the :meth:`readline` method and supports iteration upon objects. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 17:23:55 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 17:23:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1NTQzOiByZWZs?= =?utf-8?q?ow_paragraphs=2E?= Message-ID: <3WxvbH6mzkzPpf@mail.python.org> http://hg.python.org/cpython/rev/e67042b6ad02 changeset: 78592:e67042b6ad02 branch: 3.2 user: R David Murray date: Wed Aug 15 11:05:36 2012 -0400 summary: #15543: reflow paragraphs. files: Doc/library/functions.rst | 5 ++--- Doc/library/importlib.rst | 7 +++---- Doc/library/io.rst | 14 +++++++------- Doc/library/zipfile.rst | 14 +++++++------- Doc/whatsnew/2.3.rst | 13 ++++++------- Doc/whatsnew/2.5.rst | 12 ++++++------ 6 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -878,9 +878,8 @@ single: universal newlines; open() built-in function *newline* controls how :term:`universal newlines` mode works (it only - applies to text mode). - It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It - works as follows: + applies to text mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and + ``'\r\n'``. It works as follows: * When reading input from the stream, if *newline* is ``None``, universal newlines mode is enabled. Lines in the input can end in ``'\n'``, diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -196,10 +196,9 @@ An abstract method to return the source of a module. It is returned as a text string using :term:`universal newlines`, translating all - recognized line separators into ``'\n'`` characters. - Returns ``None`` if no - source is available (e.g. a built-in module). Raises :exc:`ImportError` - if the loader cannot find the module specified. + recognized line separators into ``'\n'`` characters. Returns ``None`` + if no source is available (e.g. a built-in module). Raises + :exc:`ImportError` if the loader cannot find the module specified. .. method:: is_package(fullname) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -764,13 +764,13 @@ ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: * When reading input from the stream, if *newline* is ``None``, - :term:`universal newlines` mode is enabled. Lines in the input can end - in ``'\n'``, - ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before - being returned to the caller. If it is ``''``, universal newlines mode is - enabled, but line endings are returned to the caller untranslated. If it - has any of the other legal values, input lines are only terminated by the - given string, and the line ending is returned to the caller untranslated. + :term:`universal newlines` mode is enabled. Lines in the input can end in + ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` + before being returned to the caller. If it is ``''``, universal newlines + mode is enabled, but line endings are returned to the caller untranslated. + If it has any of the other legal values, input lines are only terminated + by the given string, and the line ending is returned to the caller + untranslated. * When writing output to the stream, if *newline* is ``None``, any ``'\n'`` characters written are translated to the system default line separator, diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -174,13 +174,13 @@ .. method:: ZipFile.open(name, mode='r', pwd=None) - Extract a member from the archive as a file-like object (ZipExtFile). *name* is - the name of the file in the archive, or a :class:`ZipInfo` object. The *mode* - parameter, if included, must be one of the following: ``'r'`` (the default), - ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable - :term:`universal newlines` support in the read-only object. - *pwd* is the password used for encrypted files. - Calling :meth:`open` on a closed ZipFile will raise a :exc:`RuntimeError`. + Extract a member from the archive as a file-like object (ZipExtFile). *name* + is the name of the file in the archive, or a :class:`ZipInfo` object. The + *mode* parameter, if included, must be one of the following: ``'r'`` (the + default), ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable + :term:`universal newlines` support in the read-only object. *pwd* is the + password used for encrypted files. Calling :meth:`open` on a closed + ZipFile will raise a :exc:`RuntimeError`. .. note:: diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -379,13 +379,12 @@ 10), MacOS uses the carriage return (ASCII character 13), and Windows uses a two-character sequence of a carriage return plus a newline. -Python's file objects can now support end of line conventions other than the one -followed by the platform on which Python is running. Opening a file with the -mode ``'U'`` or ``'rU'`` will open a file for reading in -:term:`universal newlines` mode. -All three line ending conventions will be translated to a ``'\n'`` in the -strings returned by the various file methods such as :meth:`read` and -:meth:`readline`. +Python's file objects can now support end of line conventions other than the +one followed by the platform on which Python is running. Opening a file with +the mode ``'U'`` or ``'rU'`` will open a file for reading in :term:`universal +newlines` mode. All three line ending conventions will be translated to a +``'\n'`` in the strings returned by the various file methods such as +:meth:`read` and :meth:`readline`. Universal newline support is also used when importing modules and when executing a file with the :func:`execfile` function. This means that Python modules can diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1343,12 +1343,12 @@ * The :mod:`fileinput` module was made more flexible. Unicode filenames are now supported, and a *mode* parameter that defaults to ``"r"`` was added to the - :func:`input` function to allow opening files in binary or - :term:`universal newlines` mode. - Another new parameter, *openhook*, lets you use a function other than - :func:`open` to open the input files. Once you're iterating over the set of - files, the :class:`FileInput` object's new :meth:`fileno` returns the file - descriptor for the currently opened file. (Contributed by Georg Brandl.) + :func:`input` function to allow opening files in binary or :term:`universal + newlines` mode. Another new parameter, *openhook*, lets you use a function + other than :func:`open` to open the input files. Once you're iterating over + the set of files, the :class:`FileInput` object's new :meth:`fileno` returns + the file descriptor for the currently opened file. (Contributed by Georg + Brandl.) * In the :mod:`gc` module, the new :func:`get_count` function returns a 3-tuple containing the current collection counts for the three GC generations. This is -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 17:23:57 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 17:23:57 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315543=3A_glossary_entry_for_and_=27universal_ne?= =?utf-8?q?wlines=27=2C_and_links_to_it=2E?= Message-ID: <3WxvbK5FfxzPqy@mail.python.org> http://hg.python.org/cpython/rev/04a0255de9b8 changeset: 78593:04a0255de9b8 parent: 78590:65ef6ae39ea3 parent: 78592:e67042b6ad02 user: R David Murray date: Wed Aug 15 11:11:27 2012 -0400 summary: Merge #15543: glossary entry for and 'universal newlines', and links to it. Patch by Chris Jerdonek. files: Doc/glossary.rst | 7 +++++++ Doc/library/csv.rst | 6 +++++- Doc/library/functions.rst | 13 ++++++++----- Doc/library/importlib.rst | 10 +++++++--- Doc/library/io.rst | 25 ++++++++++++++++--------- Doc/library/stdtypes.rst | 5 ++++- Doc/library/subprocess.rst | 9 ++++++--- Doc/library/zipfile.rst | 16 ++++++++++------ Doc/whatsnew/2.3.rst | 15 +++++++++------ Doc/whatsnew/2.4.rst | 5 ++++- Doc/whatsnew/2.5.rst | 14 +++++++++----- Doc/whatsnew/2.6.rst | 5 ++++- 12 files changed, 89 insertions(+), 41 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -706,6 +706,13 @@ object has a type. An object's type is accessible as its :attr:`__class__` attribute or can be retrieved with ``type(obj)``. + universal newlines + A manner of interpreting text streams in which all of the following are + recognized as ending a line: the Unix end-of-line convention ``'\n'``, + the Windows convention ``'\r\n'``, and the old Macintosh convention + ``'\r'``. See :pep:`278` and :pep:`3116`, as well as + :func:`str.splitlines` for an additional use. + view The objects returned from :meth:`dict.keys`, :meth:`dict.values`, and :meth:`dict.items` are called dictionary views. They are lazy sequences diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -46,6 +46,9 @@ The :mod:`csv` module defines the following functions: +.. index:: + single: universal newlines; csv.reader function + .. function:: reader(csvfile, dialect='excel', **fmtparams) Return a reader object which will iterate over lines in the given *csvfile*. @@ -486,4 +489,5 @@ .. [1] If ``newline=''`` is not specified, newlines embedded inside quoted fields will not be interpreted correctly, and on platforms that use ``\r\n`` linendings on write an extra ``\r`` will be added. It should always be safe to specify - ``newline=''``, since the csv module does its own (universal) newline handling. + ``newline=''``, since the csv module does its own + (:term:`universal `) newline handling. diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -819,7 +819,7 @@ ``'b'`` binary mode ``'t'`` text mode (default) ``'+'`` open a disk file for updating (reading and writing) - ``'U'`` universal newline mode (for backwards compatibility; should + ``'U'`` universal newlines mode (for backwards compatibility; should not be used in new code) ========= =============================================================== @@ -874,14 +874,17 @@ used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. - *newline* controls how universal newlines works (it only applies to text - mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It - works as follows: + .. index:: + single: universal newlines; open() built-in function + + *newline* controls how :term:`universal newlines` mode works (it only + applies to text mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and + ``'\r\n'``. It works as follows: * When reading input from the stream, if *newline* is ``None``, universal newlines mode is enabled. Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before - being returned to the caller. If it is ``''``, universal newline mode is + being returned to the caller. If it is ``''``, universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -290,12 +290,16 @@ (e.g. built-in module). :exc:`ImportError` is raised if loader cannot find the requested module. + .. index:: + single: universal newlines; importlib.abc.InspectLoader.get_source method + .. method:: get_source(fullname) An abstract method to return the source of a module. It is returned as - a text string with universal newlines. Returns ``None`` if no - source is available (e.g. a built-in module). Raises :exc:`ImportError` - if the loader cannot find the module specified. + a text string using :term:`universal newlines`, translating all + recognized line separators into ``'\n'`` characters. Returns ``None`` + if no source is available (e.g. a built-in module). Raises + :exc:`ImportError` if the loader cannot find the module specified. .. method:: is_package(fullname) diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -768,16 +768,20 @@ sequences) can be used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. + .. index:: + single: universal newlines; io.TextIOWrapper class + *newline* controls how line endings are handled. It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * When reading input from the stream, if *newline* is ``None``, universal - newlines mode is enabled. Lines in the input can end in ``'\n'``, - ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before - being returned to the caller. If it is ``''``, universal newline mode is - enabled, but line endings are returned to the caller untranslated. If it - has any of the other legal values, input lines are only terminated by the - given string, and the line ending is returned to the caller untranslated. + * When reading input from the stream, if *newline* is ``None``, + :term:`universal newlines` mode is enabled. Lines in the input can end in + ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` + before being returned to the caller. If it is ``''``, universal newlines + mode is enabled, but line endings are returned to the caller untranslated. + If it has any of the other legal values, input lines are only terminated + by the given string, and the line ending is returned to the caller + untranslated. * When writing output to the stream, if *newline* is ``None``, any ``'\n'`` characters written are translated to the system default line separator, @@ -843,10 +847,13 @@ output.close() +.. index:: + single: universal newlines; io.IncrementalNewlineDecoder class + .. class:: IncrementalNewlineDecoder - A helper codec that decodes newlines for universal newlines mode. It - inherits :class:`codecs.IncrementalDecoder`. + A helper codec that decodes newlines for :term:`universal newlines` mode. + It inherits :class:`codecs.IncrementalDecoder`. Performance diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1349,10 +1349,13 @@ ``' 1 2 3 '.split(None, 1)`` returns ``['1', '2 3 ']``. +.. index:: + single: universal newlines; str.splitlines method + .. method:: str.splitlines([keepends]) Return a list of the lines in the string, breaking at line boundaries. - This method uses the universal newlines approach to splitting lines. + This method uses the :term:`universal newlines` approach to splitting lines. Line breaks are not included in the resulting list unless *keepends* is given and true. diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -285,9 +285,12 @@ :data:`STDOUT`, which indicates that the stderr data from the child process should be captured into the same file handle as for *stdout*. + .. index:: + single: universal newlines; subprocess module + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* - and *stderr* will be opened as text streams with universal newlines support, - using the encoding returned by :func:`locale.getpreferredencoding`. + and *stderr* will be opened as text streams in :term:`universal newlines` + mode using the encoding returned by :func:`locale.getpreferredencoding`. For *stdin*, line ending characters ``'\n'`` in the input will be converted to the default line separator :data:`os.linesep`. For *stdout* and *stderr*, all line endings in the output will be converted to ``'\n'``. @@ -508,7 +511,7 @@ .. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* - and *stderr* are opened as text files with universal newlines support, as + and *stderr* are opened as text streams in universal newlines mode, as described above in :ref:`frequently-used-arguments`. If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -197,14 +197,18 @@ Return a list of archive members by name. +.. index:: + single: universal newlines; zipfile.ZipFile.open method + .. method:: ZipFile.open(name, mode='r', pwd=None) - Extract a member from the archive as a file-like object (ZipExtFile). *name* is - the name of the file in the archive, or a :class:`ZipInfo` object. The *mode* - parameter, if included, must be one of the following: ``'r'`` (the default), - ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable universal newline - support in the read-only object. *pwd* is the password used for encrypted files. - Calling :meth:`open` on a closed ZipFile will raise a :exc:`RuntimeError`. + Extract a member from the archive as a file-like object (ZipExtFile). *name* + is the name of the file in the archive, or a :class:`ZipInfo` object. The + *mode* parameter, if included, must be one of the following: ``'r'`` (the + default), ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable + :term:`universal newlines` support in the read-only object. *pwd* is the + password used for encrypted files. Calling :meth:`open` on a closed + ZipFile will raise a :exc:`RuntimeError`. .. note:: diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -366,6 +366,9 @@ .. ====================================================================== +.. index:: + single: universal newlines; What's new + PEP 278: Universal Newline Support ================================== @@ -376,12 +379,12 @@ 10), MacOS uses the carriage return (ASCII character 13), and Windows uses a two-character sequence of a carriage return plus a newline. -Python's file objects can now support end of line conventions other than the one -followed by the platform on which Python is running. Opening a file with the -mode ``'U'`` or ``'rU'`` will open a file for reading in universal newline mode. -All three line ending conventions will be translated to a ``'\n'`` in the -strings returned by the various file methods such as :meth:`read` and -:meth:`readline`. +Python's file objects can now support end of line conventions other than the +one followed by the platform on which Python is running. Opening a file with +the mode ``'U'`` or ``'rU'`` will open a file for reading in :term:`universal +newlines` mode. All three line ending conventions will be translated to a +``'\n'`` in the strings returned by the various file methods such as +:meth:`read` and :meth:`readline`. Universal newline support is also used when importing modules and when executing a file with the :func:`execfile` function. This means that Python modules can diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -411,6 +411,9 @@ you can use the constant ``subprocess.PIPE`` to create a pipe between the subprocess and the parent. +.. index:: + single: universal newlines; What's new + The constructor has a number of handy options: * *close_fds* requests that all file descriptors be closed before running the @@ -424,7 +427,7 @@ * *preexec_fn* is a function that gets called before the child is started. * *universal_newlines* opens the child's input and output using Python's - universal newline feature. + :term:`universal newlines` feature. Once you've created the :class:`Popen` instance, you can call its :meth:`wait` method to pause until the subprocess has exited, :meth:`poll` to check if it's diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1338,13 +1338,17 @@ .. XXX need to provide some more detail here + .. index:: + single: universal newlines; What's new + * The :mod:`fileinput` module was made more flexible. Unicode filenames are now supported, and a *mode* parameter that defaults to ``"r"`` was added to the - :func:`input` function to allow opening files in binary or universal-newline - mode. Another new parameter, *openhook*, lets you use a function other than - :func:`open` to open the input files. Once you're iterating over the set of - files, the :class:`FileInput` object's new :meth:`fileno` returns the file - descriptor for the currently opened file. (Contributed by Georg Brandl.) + :func:`input` function to allow opening files in binary or :term:`universal + newlines` mode. Another new parameter, *openhook*, lets you use a function + other than :func:`open` to open the input files. Once you're iterating over + the set of files, the :class:`FileInput` object's new :meth:`fileno` returns + the file descriptor for the currently opened file. (Contributed by Georg + Brandl.) * In the :mod:`gc` module, the new :func:`get_count` function returns a 3-tuple containing the current collection counts for the three GC generations. This is diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -1071,9 +1071,12 @@ The :class:`BytesIO` class supports reading, writing, and seeking over an in-memory buffer. + .. index:: + single: universal newlines; What's new + * :class:`TextIOBase`: Provides functions for reading and writing strings (remember, strings will be Unicode in Python 3.0), - and supporting universal newlines. :class:`TextIOBase` defines + and supporting :term:`universal newlines`. :class:`TextIOBase` defines the :meth:`readline` method and supports iteration upon objects. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 17:23:59 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 17:23:59 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=2315543=3A_additional_lin?= =?utf-8?q?k_in_subprocess_docs=2E?= Message-ID: <3WxvbM15bpzPr8@mail.python.org> http://hg.python.org/cpython/rev/37df50bc4ea0 changeset: 78594:37df50bc4ea0 user: R David Murray date: Wed Aug 15 11:12:15 2012 -0400 summary: #15543: additional link in subprocess docs. Patch by Chris Jerdonek. files: Doc/library/subprocess.rst | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -290,7 +290,8 @@ If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* and *stderr* will be opened as text streams in :term:`universal newlines` - mode using the encoding returned by :func:`locale.getpreferredencoding`. + mode using the encoding returned by + :func:`locale.getpreferredencoding(False) `. For *stdin*, line ending characters ``'\n'`` in the input will be converted to the default line separator :data:`os.linesep`. For *stdout* and *stderr*, all line endings in the output will be converted to ``'\n'``. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 17:24:00 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 17:24:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=2315543=3A_reflow_paragra?= =?utf-8?b?cGgu?= Message-ID: <3WxvbN3z26zPr8@mail.python.org> http://hg.python.org/cpython/rev/a2efe5eeb876 changeset: 78595:a2efe5eeb876 user: R David Murray date: Wed Aug 15 11:13:31 2012 -0400 summary: #15543: reflow paragraph. files: Doc/library/subprocess.rst | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -288,15 +288,15 @@ .. index:: single: universal newlines; subprocess module - If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* - and *stderr* will be opened as text streams in :term:`universal newlines` - mode using the encoding returned by - :func:`locale.getpreferredencoding(False) `. - For *stdin*, line ending characters ``'\n'`` in the input will be converted - to the default line separator :data:`os.linesep`. For *stdout* and - *stderr*, all line endings in the output will be converted to ``'\n'``. - For more information see the documentation of the :class:`io.TextIOWrapper` - class when the *newline* argument to its constructor is ``None``. + If *universal_newlines* is ``True``, the file objects *stdin*, *stdout* and + *stderr* will be opened as text streams in :term:`universal newlines` mode + using the encoding returned by :func:`locale.getpreferredencoding(False) + `. For *stdin*, line ending characters + ``'\n'`` in the input will be converted to the default line separator + :data:`os.linesep`. For *stdout* and *stderr*, all line endings in the + output will be converted to ``'\n'``. For more information see the + documentation of the :class:`io.TextIOWrapper` class when the *newline* + argument to its constructor is ``None``. .. note:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 17:24:02 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 17:24:02 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1NTQzOiBnbG9z?= =?utf-8?q?sary_entry_for_and_=27universal_newlines=27=2C_and_links_to_it?= =?utf-8?q?=2E?= Message-ID: <3WxvbQ2RwvzPpk@mail.python.org> http://hg.python.org/cpython/rev/8795cd3b4c8c changeset: 78596:8795cd3b4c8c branch: 2.7 parent: 78584:ad8c9725c041 user: R David Murray date: Wed Aug 15 11:15:39 2012 -0400 summary: #15543: glossary entry for and 'universal newlines', and links to it. Patch by Chris Jerdonek. files: Doc/glossary.rst | 7 ++++++ Doc/library/bz2.rst | 5 +++- Doc/library/functions.rst | 8 +++++- Doc/library/io.rst | 25 +++++++++++++++------ Doc/library/stdtypes.rst | 12 +++++++-- Doc/library/subprocess.rst | 12 +++++++--- Doc/library/urllib.rst | 2 +- Doc/library/zipfile.rst | 8 +++++- Doc/reference/simple_stmts.rst | 4 +- Doc/whatsnew/2.3.rst | 6 ++++- Doc/whatsnew/2.4.rst | 5 +++- Doc/whatsnew/2.5.rst | 5 +++- Doc/whatsnew/2.6.rst | 5 +++- 13 files changed, 78 insertions(+), 26 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -630,6 +630,13 @@ object has a type. An object's type is accessible as its :attr:`__class__` attribute or can be retrieved with ``type(obj)``. + universal newlines + A manner of interpreting text streams in which all of the following are + recognized as ending a line: the Unix end-of-line convention ``'\n'``, + the Windows convention ``'\r\n'``, and the old Macintosh convention + ``'\r'``. See :pep:`278` and :pep:`3116`, as well as + :func:`str.splitlines` for an additional use. + view The objects returned from :meth:`dict.viewkeys`, :meth:`dict.viewvalues`, and :meth:`dict.viewitems` are called dictionary views. They are lazy diff --git a/Doc/library/bz2.rst b/Doc/library/bz2.rst --- a/Doc/library/bz2.rst +++ b/Doc/library/bz2.rst @@ -42,6 +42,9 @@ Handling of compressed files is offered by the :class:`BZ2File` class. +.. index:: + single: universal newlines; bz2.BZ2File class + .. class:: BZ2File(filename[, mode[, buffering[, compresslevel]]]) Open a bz2 file. Mode can be either ``'r'`` or ``'w'``, for reading (default) @@ -50,7 +53,7 @@ unbuffered, and larger numbers specify the buffer size; the default is ``0``. If *compresslevel* is given, it must be a number between ``1`` and ``9``; the default is ``9``. Add a ``'U'`` to mode to open the file for input - with universal newline support. Any line ending in the input file will be + in :term:`universal newlines` mode. Any line ending in the input file will be seen as a ``'\n'`` in Python. Also, a file so opened gains the attribute :attr:`newlines`; the value for this attribute is one of ``None`` (no newline read yet), ``'\r'``, ``'\n'``, ``'\r\n'`` or a tuple containing all the diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -859,13 +859,17 @@ binary mode, on systems that differentiate between binary and text files; on systems that don't have this distinction, adding the ``'b'`` has no effect. + .. index:: + single: universal newlines; open() built-in function + In addition to the standard :c:func:`fopen` values *mode* may be ``'U'`` or - ``'rU'``. Python is usually built with universal newline support; supplying + ``'rU'``. Python is usually built with :term:`universal newlines` support; + supplying ``'U'`` opens the file as a text file, but lines may be terminated by any of the following: the Unix end-of-line convention ``'\n'``, the Macintosh convention ``'\r'``, or the Windows convention ``'\r\n'``. All of these external representations are seen as ``'\n'`` by the Python program. If Python is built - without universal newline support a *mode* with ``'U'`` is the same as normal + without universal newlines support a *mode* with ``'U'`` is the same as normal text mode. Note that file objects so opened also have an attribute called :attr:`newlines` which has a value of ``None`` (if no newlines have yet been seen), ``'\n'``, ``'\r'``, ``'\r\n'``, or a tuple containing all the newline diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -92,7 +92,7 @@ ``'b'`` binary mode ``'t'`` text mode (default) ``'+'`` open a disk file for updating (reading and writing) - ``'U'`` universal newline mode (for backwards compatibility; should + ``'U'`` universal newlines mode (for backwards compatibility; should not be used in new code) ========= =============================================================== @@ -141,14 +141,18 @@ used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. - *newline* controls how universal newlines works (it only applies to text + .. index:: + single: universal newlines; open() (in module io) + + *newline* controls how :term:`universal newlines` works (it only applies + to text mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: * On input, if *newline* is ``None``, universal newlines mode is enabled. Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are returned to + ``''``, universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. @@ -754,13 +758,17 @@ sequences) can be used. Any other error handling name that has been registered with :func:`codecs.register_error` is also valid. + .. index:: + single: universal newlines; io.TextIOWrapper class + *newline* controls how line endings are handled. It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: - * On input, if *newline* is ``None``, universal newlines mode is enabled. + * On input, if *newline* is ``None``, :term:`universal newlines` mode is + enabled. Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these are translated into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newline mode is enabled, but line endings are returned to + ``''``, universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. @@ -817,10 +825,13 @@ output.close() +.. index:: + single: universal newlines; io.IncrementalNewlineDecoder class + .. class:: IncrementalNewlineDecoder - A helper codec that decodes newlines for universal newlines mode. It - inherits :class:`codecs.IncrementalDecoder`. + A helper codec that decodes newlines for :term:`universal newlines` mode. + It inherits :class:`codecs.IncrementalDecoder`. Advanced topics diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1181,10 +1181,13 @@ ``' 1 2 3 '.split(None, 1)`` returns ``['1', '2 3 ']``. +.. index:: + single: universal newlines; str.splitlines method + .. method:: str.splitlines([keepends]) Return a list of the lines in the string, breaking at line boundaries. - This method uses the universal newlines approach to splitting lines. + This method uses the :term:`universal newlines` approach to splitting lines. Line breaks are not included in the resulting list unless *keepends* is given and true. @@ -2558,16 +2561,19 @@ form ``<...>``. This is a read-only attribute and may not be present on all file-like objects. + .. index:: + single: universal newlines; file.newlines attribute + .. attribute:: file.newlines - If Python was built with universal newlines enabled (the default) this + If Python was built with :term:`universal newlines` enabled (the default) this read-only attribute exists, and for files opened in universal newline read mode it keeps track of the types of newlines encountered while reading the file. The values it can take are ``'\r'``, ``'\n'``, ``'\r\n'``, ``None`` (unknown, no newlines read yet) or a tuple containing all the newline types seen, to indicate that multiple newline conventions were encountered. For - files not opened in universal newline read mode the value of this attribute + files not opened in universal newlines read mode the value of this attribute will be ``None``. diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -220,9 +220,12 @@ the stderr data from the child process should be captured into the same file handle as for stdout. + .. index:: + single: universal newlines; subprocess module + When *stdout* or *stderr* are pipes and *universal_newlines* is - :const:`True` then all line endings will be converted to ``'\n'`` as - described for the universal newlines `'U'`` mode argument to :func:`open`. + ``True`` then all line endings will be converted to ``'\n'`` as described + for the :term:`universal newlines` `'U'`` mode argument to :func:`open`. If *shell* is :const:`True`, the specified command will be executed through the shell. This can be useful if you are using Python primarily for the @@ -382,8 +385,9 @@ .. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly - If *universal_newlines* is :const:`True`, the file objects stdout and stderr are - opened as text files, but lines may be terminated by any of ``'\n'``, the Unix + If *universal_newlines* is ``True``, the file objects *stdout* and *stderr* are + opened as text files in :term:`universal newlines` mode. Lines may be + terminated by any of ``'\n'``, the Unix end-of-line convention, ``'\r'``, the old Macintosh convention or ``'\r\n'``, the Windows convention. All of these external representations are seen as ``'\n'`` by the Python program. diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst --- a/Doc/library/urllib.rst +++ b/Doc/library/urllib.rst @@ -34,7 +34,7 @@ Open a network object denoted by a URL for reading. If the URL does not have a scheme identifier, or if it has :file:`file:` as its scheme identifier, this - opens a local file (without universal newlines); otherwise it opens a socket to + opens a local file (without :term:`universal newlines`); otherwise it opens a socket to a server somewhere on the network. If the connection cannot be made the :exc:`IOError` exception is raised. If all went well, a file-like object is returned. This supports the following methods: :meth:`read`, :meth:`readline`, diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -163,13 +163,17 @@ Return a list of archive members by name. + .. index:: + single: universal newlines; zipfile.ZipFile.open method + .. method:: ZipFile.open(name[, mode[, pwd]]) Extract a member from the archive as a file-like object (ZipExtFile). *name* is the name of the file in the archive, or a :class:`ZipInfo` object. The *mode* - parameter, if included, must be one of the following: ``'r'`` (the default), - ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable universal newline + parameter, if included, must be one of the following: ``'r'`` (the default), + ``'U'``, or ``'rU'``. Choosing ``'U'`` or ``'rU'`` will enable + :term:`universal newline ` support in the read-only object. *pwd* is the password used for encrypted files. Calling :meth:`open` on a closed ZipFile will raise a :exc:`RuntimeError`. diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -1024,5 +1024,5 @@ .. rubric:: Footnotes .. [#] Note that the parser only accepts the Unix-style end of line convention. - If you are reading the code from a file, make sure to use universal - newline mode to convert Windows or Mac-style newlines. + If you are reading the code from a file, make sure to use + :term:`universal newlines` mode to convert Windows or Mac-style newlines. diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -366,6 +366,9 @@ .. ====================================================================== +.. index:: + single: universal newlines; What's new + PEP 278: Universal Newline Support ================================== @@ -378,7 +381,8 @@ Python's file objects can now support end of line conventions other than the one followed by the platform on which Python is running. Opening a file with the -mode ``'U'`` or ``'rU'`` will open a file for reading in universal newline mode. +mode ``'U'`` or ``'rU'`` will open a file for reading in +:term:`universal newlines` mode. All three line ending conventions will be translated to a ``'\n'`` in the strings returned by the various file methods such as :meth:`read` and :meth:`readline`. diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -411,6 +411,9 @@ you can use the constant ``subprocess.PIPE`` to create a pipe between the subprocess and the parent. +.. index:: + single: universal newlines; What's new + The constructor has a number of handy options: * *close_fds* requests that all file descriptors be closed before running the @@ -424,7 +427,7 @@ * *preexec_fn* is a function that gets called before the child is started. * *universal_newlines* opens the child's input and output using Python's - universal newline feature. + :term:`universal newlines` feature. Once you've created the :class:`Popen` instance, you can call its :meth:`wait` method to pause until the subprocess has exited, :meth:`poll` to check if it's diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1338,9 +1338,12 @@ .. XXX need to provide some more detail here + .. index:: + single: universal newlines; What's new + * The :mod:`fileinput` module was made more flexible. Unicode filenames are now supported, and a *mode* parameter that defaults to ``"r"`` was added to the - :func:`input` function to allow opening files in binary or universal-newline + :func:`input` function to allow opening files in binary or :term:`universal newlines` mode. Another new parameter, *openhook*, lets you use a function other than :func:`open` to open the input files. Once you're iterating over the set of files, the :class:`FileInput` object's new :meth:`fileno` returns the file diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -1067,9 +1067,12 @@ The :class:`BytesIO` class supports reading, writing, and seeking over an in-memory buffer. + .. index:: + single: universal newlines; What's new + * :class:`TextIOBase`: Provides functions for reading and writing strings (remember, strings will be Unicode in Python 3.0), - and supporting universal newlines. :class:`TextIOBase` defines + and supporting :term:`universal newlines`. :class:`TextIOBase` defines the :meth:`readline` method and supports iteration upon objects. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 17:24:03 2012 From: python-checkins at python.org (r.david.murray) Date: Wed, 15 Aug 2012 17:24:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1NTQzOiByZWZs?= =?utf-8?q?ow_paragraphs=2E?= Message-ID: <3WxvbR6ZpgzPpk@mail.python.org> http://hg.python.org/cpython/rev/35d8a638b0e2 changeset: 78597:35d8a638b0e2 branch: 2.7 user: R David Murray date: Wed Aug 15 11:22:58 2012 -0400 summary: #15543: reflow paragraphs. files: Doc/library/functions.rst | 19 +++++++++---------- Doc/library/io.rst | 20 +++++++++----------- Doc/library/subprocess.rst | 11 +++++------ Doc/library/urllib.rst | 21 +++++++++++---------- Doc/whatsnew/2.3.rst | 13 ++++++------- Doc/whatsnew/2.5.rst | 11 ++++++----- Misc/ACKS | 1 + 7 files changed, 47 insertions(+), 49 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -864,16 +864,15 @@ In addition to the standard :c:func:`fopen` values *mode* may be ``'U'`` or ``'rU'``. Python is usually built with :term:`universal newlines` support; - supplying - ``'U'`` opens the file as a text file, but lines may be terminated by any of the - following: the Unix end-of-line convention ``'\n'``, the Macintosh convention - ``'\r'``, or the Windows convention ``'\r\n'``. All of these external - representations are seen as ``'\n'`` by the Python program. If Python is built - without universal newlines support a *mode* with ``'U'`` is the same as normal - text mode. Note that file objects so opened also have an attribute called - :attr:`newlines` which has a value of ``None`` (if no newlines have yet been - seen), ``'\n'``, ``'\r'``, ``'\r\n'``, or a tuple containing all the newline - types seen. + supplying ``'U'`` opens the file as a text file, but lines may be terminated + by any of the following: the Unix end-of-line convention ``'\n'``, the + Macintosh convention ``'\r'``, or the Windows convention ``'\r\n'``. All of + these external representations are seen as ``'\n'`` by the Python program. + If Python is built without universal newlines support a *mode* with ``'U'`` + is the same as normal text mode. Note that file objects so opened also have + an attribute called :attr:`newlines` which has a value of ``None`` (if no + newlines have yet been seen), ``'\n'``, ``'\r'``, ``'\r\n'``, or a tuple + containing all the newline types seen. Python enforces that the mode, after stripping ``'U'``, begins with ``'r'``, ``'w'`` or ``'a'``. diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -144,10 +144,9 @@ .. index:: single: universal newlines; open() (in module io) - *newline* controls how :term:`universal newlines` works (it only applies - to text - mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It - works as follows: + *newline* controls how :term:`universal newlines` works (it only applies to + text mode). It can be ``None``, ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. + It works as follows: * On input, if *newline* is ``None``, universal newlines mode is enabled. Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these @@ -765,13 +764,12 @@ ``''``, ``'\n'``, ``'\r'``, and ``'\r\n'``. It works as follows: * On input, if *newline* is ``None``, :term:`universal newlines` mode is - enabled. - Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, and these - are translated into ``'\n'`` before being returned to the caller. If it is - ``''``, universal newlines mode is enabled, but line endings are returned to - the caller untranslated. If it has any of the other legal values, input - lines are only terminated by the given string, and the line ending is - returned to the caller untranslated. + enabled. Lines in the input can end in ``'\n'``, ``'\r'``, or ``'\r\n'``, + and these are translated into ``'\n'`` before being returned to the + caller. If it is ``''``, universal newlines mode is enabled, but line + endings are returned to the caller untranslated. If it has any of the + other legal values, input lines are only terminated by the given string, + and the line ending is returned to the caller untranslated. * On output, if *newline* is ``None``, any ``'\n'`` characters written are translated to the system default line separator, :data:`os.linesep`. If diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -385,12 +385,11 @@ .. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly - If *universal_newlines* is ``True``, the file objects *stdout* and *stderr* are - opened as text files in :term:`universal newlines` mode. Lines may be - terminated by any of ``'\n'``, the Unix - end-of-line convention, ``'\r'``, the old Macintosh convention or ``'\r\n'``, the - Windows convention. All of these external representations are seen as ``'\n'`` - by the Python program. + If *universal_newlines* is ``True``, the file objects *stdout* and *stderr* + are opened as text files in :term:`universal newlines` mode. Lines may be + terminated by any of ``'\n'``, the Unix end-of-line convention, ``'\r'``, + the old Macintosh convention or ``'\r\n'``, the Windows convention. All of + these external representations are seen as ``'\n'`` by the Python program. .. note:: diff --git a/Doc/library/urllib.rst b/Doc/library/urllib.rst --- a/Doc/library/urllib.rst +++ b/Doc/library/urllib.rst @@ -32,16 +32,17 @@ .. function:: urlopen(url[, data[, proxies]]) - Open a network object denoted by a URL for reading. If the URL does not have a - scheme identifier, or if it has :file:`file:` as its scheme identifier, this - opens a local file (without :term:`universal newlines`); otherwise it opens a socket to - a server somewhere on the network. If the connection cannot be made the - :exc:`IOError` exception is raised. If all went well, a file-like object is - returned. This supports the following methods: :meth:`read`, :meth:`readline`, - :meth:`readlines`, :meth:`fileno`, :meth:`close`, :meth:`info`, :meth:`getcode` and - :meth:`geturl`. It also has proper support for the :term:`iterator` protocol. One - caveat: the :meth:`read` method, if the size argument is omitted or negative, - may not read until the end of the data stream; there is no good way to determine + Open a network object denoted by a URL for reading. If the URL does not + have a scheme identifier, or if it has :file:`file:` as its scheme + identifier, this opens a local file (without :term:`universal newlines`); + otherwise it opens a socket to a server somewhere on the network. If the + connection cannot be made the :exc:`IOError` exception is raised. If all + went well, a file-like object is returned. This supports the following + methods: :meth:`read`, :meth:`readline`, :meth:`readlines`, :meth:`fileno`, + :meth:`close`, :meth:`info`, :meth:`getcode` and :meth:`geturl`. It also + has proper support for the :term:`iterator` protocol. One caveat: the + :meth:`read` method, if the size argument is omitted or negative, may not + read until the end of the data stream; there is no good way to determine that the entire stream from a socket has been read in the general case. Except for the :meth:`info`, :meth:`getcode` and :meth:`geturl` methods, diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -379,13 +379,12 @@ 10), MacOS uses the carriage return (ASCII character 13), and Windows uses a two-character sequence of a carriage return plus a newline. -Python's file objects can now support end of line conventions other than the one -followed by the platform on which Python is running. Opening a file with the -mode ``'U'`` or ``'rU'`` will open a file for reading in -:term:`universal newlines` mode. -All three line ending conventions will be translated to a ``'\n'`` in the -strings returned by the various file methods such as :meth:`read` and -:meth:`readline`. +Python's file objects can now support end of line conventions other than the +one followed by the platform on which Python is running. Opening a file with +the mode ``'U'`` or ``'rU'`` will open a file for reading in :term:`universal +newlines` mode. All three line ending conventions will be translated to a +``'\n'`` in the strings returned by the various file methods such as +:meth:`read` and :meth:`readline`. Universal newline support is also used when importing modules and when executing a file with the :func:`execfile` function. This means that Python modules can diff --git a/Doc/whatsnew/2.5.rst b/Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst +++ b/Doc/whatsnew/2.5.rst @@ -1343,11 +1343,12 @@ * The :mod:`fileinput` module was made more flexible. Unicode filenames are now supported, and a *mode* parameter that defaults to ``"r"`` was added to the - :func:`input` function to allow opening files in binary or :term:`universal newlines` - mode. Another new parameter, *openhook*, lets you use a function other than - :func:`open` to open the input files. Once you're iterating over the set of - files, the :class:`FileInput` object's new :meth:`fileno` returns the file - descriptor for the currently opened file. (Contributed by Georg Brandl.) + :func:`input` function to allow opening files in binary or :term:`universal + newlines` mode. Another new parameter, *openhook*, lets you use a function + other than :func:`open` to open the input files. Once you're iterating over + the set of files, the :class:`FileInput` object's new :meth:`fileno` returns + the file descriptor for the currently opened file. (Contributed by Georg + Brandl.) * In the :mod:`gc` module, the new :func:`get_count` function returns a 3-tuple containing the current collection counts for the three GC generations. This is diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -418,6 +418,7 @@ Drew Jenkins Flemming Kj?r Jensen Philip Jenvey +Chris Jerdonek Jiba Orjan Johansen Fredrik Johansson -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 21:38:31 2012 From: python-checkins at python.org (sandro.tosi) Date: Wed, 15 Aug 2012 21:38:31 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_clarify_in/not?= =?utf-8?q?_in_in_case_of_infinite_iterators=3B_thanks_to_Sergey_Skovorodk?= =?utf-8?q?in?= Message-ID: <3Wy1F32FDbzPlj@mail.python.org> http://hg.python.org/cpython/rev/59f520542c1c changeset: 78598:59f520542c1c branch: 2.7 user: Sandro Tosi date: Wed Aug 15 21:37:19 2012 +0200 summary: clarify in/not in in case of infinite iterators; thanks to Sergey Skovorodkin from docs@ files: Doc/howto/functional.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst --- a/Doc/howto/functional.rst +++ b/Doc/howto/functional.rst @@ -244,9 +244,9 @@ iterator argument and will return the largest or smallest element. The ``"in"`` and ``"not in"`` operators also support iterators: ``X in iterator`` is true if X is found in the stream returned by the iterator. You'll run into obvious -problems if the iterator is infinite; ``max()``, ``min()``, and ``"not in"`` +problems if the iterator is infinite; ``max()``, ``min()`` will never return, and if the element X never appears in the stream, the -``"in"`` operator won't return either. +``"in"`` and ``"not in"`` operators won't return either. Note that you can only go forward in an iterator; there's no way to get the previous element, reset the iterator, or make a copy of it. Iterator objects -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 21:38:32 2012 From: python-checkins at python.org (sandro.tosi) Date: Wed, 15 Aug 2012 21:38:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_clarify_in/not?= =?utf-8?q?_in_in_case_of_infinite_iterators=3B_thanks_to_Sergey_Skovorodk?= =?utf-8?q?in?= Message-ID: <3Wy1F46hz0zPqC@mail.python.org> http://hg.python.org/cpython/rev/fa9eedea0b48 changeset: 78599:fa9eedea0b48 branch: 3.2 parent: 78592:e67042b6ad02 user: Sandro Tosi date: Wed Aug 15 21:37:35 2012 +0200 summary: clarify in/not in in case of infinite iterators; thanks to Sergey Skovorodkin from docs@ files: Doc/howto/functional.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst --- a/Doc/howto/functional.rst +++ b/Doc/howto/functional.rst @@ -246,9 +246,9 @@ iterator argument and will return the largest or smallest element. The ``"in"`` and ``"not in"`` operators also support iterators: ``X in iterator`` is true if X is found in the stream returned by the iterator. You'll run into obvious -problems if the iterator is infinite; ``max()``, ``min()``, and ``"not in"`` +problems if the iterator is infinite; ``max()``, ``min()`` will never return, and if the element X never appears in the stream, the -``"in"`` operator won't return either. +``"in"`` and ``"not in"`` operators won't return either. Note that you can only go forward in an iterator; there's no way to get the previous element, reset the iterator, or make a copy of it. Iterator objects -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 21:38:34 2012 From: python-checkins at python.org (sandro.tosi) Date: Wed, 15 Aug 2012 21:38:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3Wy1F63fPBzPqF@mail.python.org> http://hg.python.org/cpython/rev/c0cfa5b2c703 changeset: 78600:c0cfa5b2c703 parent: 78595:a2efe5eeb876 parent: 78599:fa9eedea0b48 user: Sandro Tosi date: Wed Aug 15 21:37:56 2012 +0200 summary: merge with 3.2 files: Doc/howto/functional.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst --- a/Doc/howto/functional.rst +++ b/Doc/howto/functional.rst @@ -246,9 +246,9 @@ iterator argument and will return the largest or smallest element. The ``"in"`` and ``"not in"`` operators also support iterators: ``X in iterator`` is true if X is found in the stream returned by the iterator. You'll run into obvious -problems if the iterator is infinite; ``max()``, ``min()``, and ``"not in"`` +problems if the iterator is infinite; ``max()``, ``min()`` will never return, and if the element X never appears in the stream, the -``"in"`` operator won't return either. +``"in"`` and ``"not in"`` operators won't return either. Note that you can only go forward in an iterator; there's no way to get the previous element, reset the iterator, or make a copy of it. Iterator objects -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 21:54:06 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 15 Aug 2012 21:54:06 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_yet_another_test_for_s?= =?utf-8?q?ubprocess=2EPopen=2Ecommunicate?= Message-ID: <3Wy1b22K93zPlj@mail.python.org> http://hg.python.org/cpython/rev/4af2c0687970 changeset: 78601:4af2c0687970 parent: 78595:a2efe5eeb876 user: Andrew Svetlov date: Wed Aug 15 22:46:43 2012 +0300 summary: Add yet another test for subprocess.Popen.communicate files: Lib/test/test_subprocess.py | 28 +++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 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 @@ -645,6 +645,34 @@ p.communicate() self.assertEqual(p.returncode, 0) + def test_universal_newlines_communicate_stdin_stdout_stderr(self): + # universal newlines through communicate(), with only stdin + p = subprocess.Popen([sys.executable, "-c", + 'import sys,os;' + SETBINARY + '''\nif True: + s = sys.stdin.readline() + sys.stdout.write(s) + sys.stdout.write("line2\\r") + sys.stderr.write("eline2\\n") + s = sys.stdin.read() + sys.stdout.write(s+"line4\\n") + sys.stdout.write(s+"line5\\r\\n") + sys.stderr.write("eline6\\n") + sys.stderr.write("eline7\\r") + sys.stderr.write("eline8\\r\\n") + '''], + stdin=subprocess.PIPE, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=1) + self.addCleanup(p.stdout.close) + self.addCleanup(p.stderr.close) + (stdout, stderr) = p.communicate("line1\nline3\n") + self.assertEqual(p.returncode, 0) + self.assertEqual("line1\nline2\nline3\nline4\nline3\nline5\n", stdout) + # Python debug build push something like "[42442 refs]\n" + # to stderr at exit of subprocess. + self.assertTrue(stderr.startswith("eline2\neline6\neline7\neline8\n")) + def test_no_leaking(self): # Make sure we leak no resources if not mswindows: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 21:54:07 2012 From: python-checkins at python.org (andrew.svetlov) Date: Wed, 15 Aug 2012 21:54:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3Wy1b36W4RzPpl@mail.python.org> http://hg.python.org/cpython/rev/5dc2b4a542f1 changeset: 78602:5dc2b4a542f1 parent: 78600:c0cfa5b2c703 parent: 78601:4af2c0687970 user: Andrew Svetlov date: Wed Aug 15 22:53:56 2012 +0300 summary: merge heads files: Lib/test/test_subprocess.py | 28 +++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 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 @@ -645,6 +645,34 @@ p.communicate() self.assertEqual(p.returncode, 0) + def test_universal_newlines_communicate_stdin_stdout_stderr(self): + # universal newlines through communicate(), with only stdin + p = subprocess.Popen([sys.executable, "-c", + 'import sys,os;' + SETBINARY + '''\nif True: + s = sys.stdin.readline() + sys.stdout.write(s) + sys.stdout.write("line2\\r") + sys.stderr.write("eline2\\n") + s = sys.stdin.read() + sys.stdout.write(s+"line4\\n") + sys.stdout.write(s+"line5\\r\\n") + sys.stderr.write("eline6\\n") + sys.stderr.write("eline7\\r") + sys.stderr.write("eline8\\r\\n") + '''], + stdin=subprocess.PIPE, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=1) + self.addCleanup(p.stdout.close) + self.addCleanup(p.stderr.close) + (stdout, stderr) = p.communicate("line1\nline3\n") + self.assertEqual(p.returncode, 0) + self.assertEqual("line1\nline2\nline3\nline4\nline3\nline5\n", stdout) + # Python debug build push something like "[42442 refs]\n" + # to stderr at exit of subprocess. + self.assertTrue(stderr.startswith("eline2\neline6\neline7\neline8\n")) + def test_no_leaking(self): # Make sure we leak no resources if not mswindows: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 23:27:25 2012 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 15 Aug 2012 23:27:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NjA0?= =?utf-8?q?=3A_Update_uses_of_PyObject=5FIsTrue=28=29_to_check_for_and_han?= =?utf-8?q?dle_errors?= Message-ID: <3Wy3fj3XW6zPjK@mail.python.org> http://hg.python.org/cpython/rev/ba1c48f8b571 changeset: 78603:ba1c48f8b571 branch: 2.7 parent: 78598:59f520542c1c user: Antoine Pitrou date: Wed Aug 15 23:16:51 2012 +0200 summary: Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. files: Misc/NEWS | 3 + Modules/_csv.c | 8 +++- Modules/_io/textio.c | 5 ++- Modules/_ssl.c | 6 ++- Modules/cStringIO.c | 6 ++- Modules/itertoolsmodule.c | 17 ++++++-- Modules/parsermodule.c | 18 ++++++-- Modules/pyexpat.c | 54 +++++++++++++++------------ Objects/typeobject.c | 12 +++-- Python/bltinmodule.c | 22 ++++++++--- Python/import.c | 13 +++++- 11 files changed, 112 insertions(+), 52 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ Core and Builtins ----------------- +- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle + errors correctly. Patch by Serhiy Storchaka. + - Issue #15041: Update "see also" list in tkinter documentation. - Issue #14579: Fix error handling bug in the utf-16 decoder. Patch by diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -208,8 +208,12 @@ { if (src == NULL) *target = dflt; - else - *target = PyObject_IsTrue(src); + else { + int b = PyObject_IsTrue(src); + if (b < 0) + return -1; + *target = b; + } return 0; } diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1013,8 +1013,11 @@ res = PyObject_CallMethod(buffer, "seekable", NULL); if (res == NULL) goto error; - self->seekable = self->telling = PyObject_IsTrue(res); + r = PyObject_IsTrue(res); Py_DECREF(res); + if (r < 0) + goto error; + self->seekable = self->telling = r; self->encoding_start_of_stream = 0; if (self->seekable && self->encoder) { diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1005,6 +1005,7 @@ int len; int verification; PyObject *binary_mode = Py_None; + int b; if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode)) return NULL; @@ -1012,7 +1013,10 @@ if (!self->peer_cert) Py_RETURN_NONE; - if (PyObject_IsTrue(binary_mode)) { + b = PyObject_IsTrue(binary_mode); + if (b < 0) + return NULL; + if (b) { /* return cert in DER-encoded format */ unsigned char *bytes_buf = NULL; diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -127,12 +127,16 @@ static PyObject * IO_getval(IOobject *self, PyObject *args) { PyObject *use_pos=Py_None; + int b; Py_ssize_t s; if (!IO__opencheck(self)) return NULL; if (!PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL; - if (PyObject_IsTrue(use_pos)) { + b = PyObject_IsTrue(use_pos); + if (b < 0) + return NULL; + if (b) { s=self->pos; if (s > self->string_size) s=self->string_size; } diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -903,11 +903,13 @@ } ok = PyObject_IsTrue(good); Py_DECREF(good); - if (!ok) { + if (ok == 0) { lz->start = 1; return item; } Py_DECREF(item); + if (ok < 0) + return NULL; } } @@ -1043,10 +1045,11 @@ } ok = PyObject_IsTrue(good); Py_DECREF(good); - if (ok) + if (ok > 0) return item; Py_DECREF(item); - lz->stop = 1; + if (ok == 0) + lz->stop = 1; return NULL; } @@ -3001,9 +3004,11 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (ok) + if (ok > 0) return item; Py_DECREF(item); + if (ok < 0) + return NULL; } } @@ -3144,9 +3149,11 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (!ok) + if (ok == 0) return item; Py_DECREF(item); + if (ok < 0) + return NULL; } } diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -350,10 +350,14 @@ int lineno = 0; int col_offset = 0; if (line_option != NULL) { - lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0; + lineno = PyObject_IsTrue(line_option); + if (lineno < 0) + return NULL; } if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; + col_offset = PyObject_IsTrue(col_option); + if (col_offset < 0) + return NULL; } /* * Convert ST into a tuple representation. Use Guido's function, @@ -401,10 +405,14 @@ int lineno = 0; int col_offset = 0; if (line_option != 0) { - lineno = PyObject_IsTrue(line_option) ? 1 : 0; + lineno = PyObject_IsTrue(line_option); + if (lineno < 0) + return NULL; } - if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; + if (col_option != 0) { + col_offset = PyObject_IsTrue(col_option); + if (col_offset < 0) + return NULL; } /* * Convert ST into a tuple representation. Use Guido's function, diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1174,13 +1174,16 @@ xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) { PyObject *flagobj = NULL; - XML_Bool flag = XML_TRUE; + int flag = 1; enum XML_Error rc; - if (!PyArg_UnpackTuple(args, "UseForeignDTD", 0, 1, &flagobj)) + if (!PyArg_ParseTuple(args, "O:UseForeignDTD", &flagobj)) return NULL; - if (flagobj != NULL) - flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE; - rc = XML_UseForeignDTD(self->itself, flag); + if (flagobj != NULL) { + flag = PyObject_IsTrue(flagobj); + if (flag < 0) + return NULL; + } + rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE); if (rc != XML_ERROR_NONE) { return set_error(self, rc); } @@ -1549,7 +1552,10 @@ return -1; } if (strcmp(name, "buffer_text") == 0) { - if (PyObject_IsTrue(v)) { + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + if (b) { if (self->buffer == NULL) { self->buffer = malloc(self->buffer_size); if (self->buffer == NULL) { @@ -1568,39 +1574,39 @@ return 0; } if (strcmp(name, "namespace_prefixes") == 0) { - if (PyObject_IsTrue(v)) - self->ns_prefixes = 1; - else - self->ns_prefixes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ns_prefixes = b; XML_SetReturnNSTriplet(self->itself, self->ns_prefixes); return 0; } if (strcmp(name, "ordered_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->ordered_attributes = 1; - else - self->ordered_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ordered_attributes = b; return 0; } if (strcmp(name, "returns_unicode") == 0) { - if (PyObject_IsTrue(v)) { + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; #ifndef Py_USING_UNICODE + if (b) { PyErr_SetString(PyExc_ValueError, "Unicode support not available"); return -1; -#else - self->returns_unicode = 1; + } #endif - } - else - self->returns_unicode = 0; + self->returns_unicode = b; return 0; } if (strcmp(name, "specified_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->specified_attributes = 1; - else - self->specified_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->specified_attributes = b; return 0; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -327,11 +327,15 @@ abc.ABCMeta.__new__, so this function doesn't do anything special to update subclasses. */ - int res; + int abstract, res; if (value != NULL) { + abstract = PyObject_IsTrue(value); + if (abstract < 0) + return -1; res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value); } else { + abstract = 0; res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__"); if (res && PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_SetString(PyExc_AttributeError, "__abstractmethods__"); @@ -340,12 +344,10 @@ } if (res == 0) { PyType_Modified(type); - if (value && PyObject_IsTrue(value)) { + if (abstract) type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT; - } - else { + else type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT; - } } return res; } diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -313,7 +313,7 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (ok) { + if (ok > 0) { if (j < len) PyList_SET_ITEM(result, j, item); else { @@ -324,8 +324,11 @@ } ++j; } - else + else { Py_DECREF(item); + if (ok < 0) + goto Fail_result_it; + } } @@ -2784,12 +2787,15 @@ } ok = PyObject_IsTrue(good); Py_DECREF(good); - if (ok) { + if (ok > 0) { if (PyTuple_SetItem(result, j++, item) < 0) goto Fail_1; } - else + else { Py_DECREF(item); + if (ok < 0) + goto Fail_1; + } } if (_PyTuple_Resize(&result, j) < 0) @@ -2851,7 +2857,7 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (ok) { + if (ok > 0) { Py_ssize_t reslen; if (!PyString_Check(item)) { PyErr_SetString(PyExc_TypeError, "can't filter str to str:" @@ -2917,6 +2923,8 @@ } } Py_DECREF(item); + if (ok < 0) + goto Fail_1; } if (j < outlen) @@ -2977,7 +2985,7 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (ok) { + if (ok > 0) { Py_ssize_t reslen; if (!PyUnicode_Check(item)) { PyErr_SetString(PyExc_TypeError, @@ -3032,6 +3040,8 @@ } } Py_DECREF(item); + if (ok < 0) + goto Fail_1; } if (j < outlen) diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -1043,7 +1043,10 @@ name, pathname); if (cpathname) { PyObject *ro = PySys_GetObject("dont_write_bytecode"); - if (ro == NULL || !PyObject_IsTrue(ro)) + int b = (ro == NULL) ? 0 : PyObject_IsTrue(ro); + if (b < 0) + goto error_exit; + if (!b) write_compiled_module(co, cpathname, &st); } } @@ -2200,7 +2203,13 @@ } if (fromlist != NULL) { - if (fromlist == Py_None || !PyObject_IsTrue(fromlist)) + int b = (fromlist == Py_None) ? 0 : PyObject_IsTrue(fromlist); + if (b < 0) { + Py_DECREF(tail); + Py_DECREF(head); + goto error_exit; + } + if (!b) fromlist = NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 23:27:27 2012 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 15 Aug 2012 23:27:27 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NjA0?= =?utf-8?q?=3A_Update_uses_of_PyObject=5FIsTrue=28=29_to_check_for_and_han?= =?utf-8?q?dle_errors?= Message-ID: <3Wy3fl3tF4zPpc@mail.python.org> http://hg.python.org/cpython/rev/56dc7b09f390 changeset: 78604:56dc7b09f390 branch: 3.2 parent: 78599:fa9eedea0b48 user: Antoine Pitrou date: Wed Aug 15 23:18:25 2012 +0200 summary: Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. files: Misc/NEWS | 3 + Modules/_csv.c | 8 +++- Modules/_io/textio.c | 5 ++- Modules/_posixsubprocess.c | 2 + Modules/_ssl.c | 6 +++- Modules/itertoolsmodule.c | 13 +++++-- Modules/parsermodule.c | 18 ++++++++--- Modules/pyexpat.c | 42 ++++++++++++++----------- Objects/typeobject.c | 12 ++++--- Python/bltinmodule.c | 4 +- Python/import.c | 13 ++++++- 11 files changed, 87 insertions(+), 39 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle + errors correctly. Patch by Serhiy Storchaka. + - Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on Windows, as Python 2. diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -166,8 +166,12 @@ { if (src == NULL) *target = dflt; - else - *target = PyObject_IsTrue(src); + else { + int b = PyObject_IsTrue(src); + if (b < 0) + return -1; + *target = b; + } return 0; } diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1046,8 +1046,11 @@ res = PyObject_CallMethod(buffer, "seekable", NULL); if (res == NULL) goto error; - self->seekable = self->telling = PyObject_IsTrue(res); + r = PyObject_IsTrue(res); Py_DECREF(res); + if (r < 0) + goto error; + self->seekable = self->telling = r; self->has_read1 = PyObject_HasAttrString(buffer, "read1"); diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -525,6 +525,8 @@ return NULL; close_fds = PyObject_IsTrue(py_close_fds); + if (close_fds < 0) + return NULL; if (close_fds && errpipe_write < 3) { /* precondition */ PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3"); return NULL; diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -883,6 +883,7 @@ int len; int verification; PyObject *binary_mode = Py_None; + int b; if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode)) return NULL; @@ -890,7 +891,10 @@ if (!self->peer_cert) Py_RETURN_NONE; - if (PyObject_IsTrue(binary_mode)) { + b = PyObject_IsTrue(binary_mode); + if (b < 0) + return NULL; + if (b) { /* return cert in DER-encoded format */ unsigned char *bytes_buf = NULL; diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -903,11 +903,13 @@ } ok = PyObject_IsTrue(good); Py_DECREF(good); - if (!ok) { + if (ok == 0) { lz->start = 1; return item; } Py_DECREF(item); + if (ok < 0) + return NULL; } } @@ -1043,10 +1045,11 @@ } ok = PyObject_IsTrue(good); Py_DECREF(good); - if (ok) + if (ok > 0) return item; Py_DECREF(item); - lz->stop = 1; + if (ok == 0) + lz->stop = 1; return NULL; } @@ -2959,9 +2962,11 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (!ok) + if (ok == 0) return item; Py_DECREF(item); + if (ok < 0) + return NULL; } } diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -401,10 +401,14 @@ int lineno = 0; int col_offset = 0; if (line_option != NULL) { - lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0; + lineno = PyObject_IsTrue(line_option); + if (lineno < 0) + return NULL; } if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; + col_offset = PyObject_IsTrue(col_option); + if (col_offset < 0) + return NULL; } /* * Convert ST into a tuple representation. Use Guido's function, @@ -444,10 +448,14 @@ int lineno = 0; int col_offset = 0; if (line_option != 0) { - lineno = PyObject_IsTrue(line_option) ? 1 : 0; + lineno = PyObject_IsTrue(line_option); + if (lineno < 0) + return NULL; } - if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; + if (col_option != 0) { + col_offset = PyObject_IsTrue(col_option); + if (col_offset < 0) + return NULL; } /* * Convert ST into a tuple representation. Use Guido's function, diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1033,13 +1033,16 @@ xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) { PyObject *flagobj = NULL; - XML_Bool flag = XML_TRUE; + int flag = 1; enum XML_Error rc; - if (!PyArg_UnpackTuple(args, "UseForeignDTD", 0, 1, &flagobj)) + if (!PyArg_ParseTuple(args, "O:UseForeignDTD", &flagobj)) return NULL; - if (flagobj != NULL) - flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE; - rc = XML_UseForeignDTD(self->itself, flag); + if (flagobj != NULL) { + flag = PyObject_IsTrue(flagobj); + if (flag < 0) + return NULL; + } + rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE); if (rc != XML_ERROR_NONE) { return set_error(self, rc); } @@ -1397,7 +1400,10 @@ } assert(PyUnicode_Check(name)); if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) { - if (PyObject_IsTrue(v)) { + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + if (b) { if (self->buffer == NULL) { self->buffer = malloc(self->buffer_size); if (self->buffer == NULL) { @@ -1416,25 +1422,25 @@ return 0; } if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) { - if (PyObject_IsTrue(v)) - self->ns_prefixes = 1; - else - self->ns_prefixes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ns_prefixes = b; XML_SetReturnNSTriplet(self->itself, self->ns_prefixes); return 0; } if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->ordered_attributes = 1; - else - self->ordered_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ordered_attributes = b; return 0; } if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->specified_attributes = 1; - else - self->specified_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->specified_attributes = b; return 0; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -340,11 +340,15 @@ abc.ABCMeta.__new__, so this function doesn't do anything special to update subclasses. */ - int res; + int abstract, res; if (value != NULL) { + abstract = PyObject_IsTrue(value); + if (abstract < 0) + return -1; res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value); } else { + abstract = 0; res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__"); if (res && PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_SetString(PyExc_AttributeError, "__abstractmethods__"); @@ -353,12 +357,10 @@ } if (res == 0) { PyType_Modified(type); - if (value && PyObject_IsTrue(value)) { + if (abstract) type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT; - } - else { + else type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT; - } } return res; } diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -428,9 +428,11 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (ok) + if (ok > 0) return item; Py_DECREF(item); + if (ok < 0) + return NULL; } } diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -1338,7 +1338,10 @@ name, pathname); if (cpathname) { PyObject *ro = PySys_GetObject("dont_write_bytecode"); - if (ro == NULL || !PyObject_IsTrue(ro)) + int b = (ro == NULL) ? 0 : PyObject_IsTrue(ro); + if (b < 0) + goto error_exit; + if (!b) write_compiled_module(co, cpathname, &st); } } @@ -2504,7 +2507,13 @@ } if (fromlist != NULL) { - if (fromlist == Py_None || !PyObject_IsTrue(fromlist)) + int b = (fromlist == Py_None) ? 0 : PyObject_IsTrue(fromlist); + if (b < 0) { + Py_DECREF(tail); + Py_DECREF(head); + goto error_exit; + } + if (!b) fromlist = NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 15 23:27:29 2012 From: python-checkins at python.org (antoine.pitrou) Date: Wed, 15 Aug 2012 23:27:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315604=3A_Update_uses_of_PyObject=5FIsTrue=28=29?= =?utf-8?q?_to_check_for_and_handle_errors?= Message-ID: <3Wy3fn2H3jzPrd@mail.python.org> http://hg.python.org/cpython/rev/b878df1d23b1 changeset: 78605:b878df1d23b1 parent: 78602:5dc2b4a542f1 parent: 78604:56dc7b09f390 user: Antoine Pitrou date: Wed Aug 15 23:20:39 2012 +0200 summary: Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. files: Misc/NEWS | 3 + Modules/_csv.c | 8 +++- Modules/_io/textio.c | 5 ++- Modules/_posixsubprocess.c | 7 +-- Modules/_ssl.c | 6 +- Modules/itertoolsmodule.c | 19 ++++++--- Modules/parsermodule.c | 48 ++++++++----------------- Modules/pyexpat.c | 38 ++++++++++---------- Objects/typeobject.c | 12 +++-- Python/bltinmodule.c | 4 +- 10 files changed, 76 insertions(+), 74 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle + errors correctly. Patch by Serhiy Storchaka. + Library ------- diff --git a/Modules/_csv.c b/Modules/_csv.c --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -196,8 +196,12 @@ { if (src == NULL) *target = dflt; - else - *target = PyObject_IsTrue(src); + else { + int b = PyObject_IsTrue(src); + if (b < 0) + return -1; + *target = b; + } return 0; } diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1056,8 +1056,11 @@ res = _PyObject_CallMethodId(buffer, &PyId_seekable, NULL); if (res == NULL) goto error; - self->seekable = self->telling = PyObject_IsTrue(res); + r = PyObject_IsTrue(res); Py_DECREF(res); + if (r < 0) + goto error; + self->seekable = self->telling = r; self->has_read1 = _PyObject_HasAttrId(buffer, &PyId_read1); diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -503,7 +503,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args) { PyObject *gc_module = NULL; - PyObject *executable_list, *py_close_fds, *py_fds_to_keep; + PyObject *executable_list, *py_fds_to_keep; PyObject *env_list, *preexec_fn; PyObject *process_args, *converted_args = NULL, *fast_args = NULL; PyObject *preexec_fn_args_tuple = NULL; @@ -518,15 +518,14 @@ Py_ssize_t arg_num; if (!PyArg_ParseTuple( - args, "OOOOOOiiiiiiiiiiO:fork_exec", - &process_args, &executable_list, &py_close_fds, &py_fds_to_keep, + args, "OOpOOOiiiiiiiiiiO:fork_exec", + &process_args, &executable_list, &close_fds, &py_fds_to_keep, &cwd_obj, &env_list, &p2cread, &p2cwrite, &c2pread, &c2pwrite, &errread, &errwrite, &errpipe_read, &errpipe_write, &restore_signals, &call_setsid, &preexec_fn)) return NULL; - close_fds = PyObject_IsTrue(py_close_fds); if (close_fds && errpipe_write < 3) { /* precondition */ PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3"); return NULL; diff --git a/Modules/_ssl.c b/Modules/_ssl.c --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1037,15 +1037,15 @@ PyObject *retval = NULL; int len; int verification; - PyObject *binary_mode = Py_None; + int binary_mode = 0; - if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode)) + if (!PyArg_ParseTuple(args, "|p:peer_certificate", &binary_mode)) return NULL; if (!self->peer_cert) Py_RETURN_NONE; - if (PyObject_IsTrue(binary_mode)) { + if (binary_mode) { /* return cert in DER-encoded format */ unsigned char *bytes_buf = NULL; diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -1105,11 +1105,13 @@ } ok = PyObject_IsTrue(good); Py_DECREF(good); - if (!ok) { + if (ok == 0) { lz->start = 1; return item; } Py_DECREF(item); + if (ok < 0) + return NULL; } } @@ -1124,7 +1126,7 @@ dropwhile_setstate(dropwhileobject *lz, PyObject *state) { int start = PyObject_IsTrue(state); - if (start == -1) + if (start < 0) return NULL; lz->start = start; Py_RETURN_NONE; @@ -1270,10 +1272,11 @@ } ok = PyObject_IsTrue(good); Py_DECREF(good); - if (ok) + if (ok == 1) return item; Py_DECREF(item); - lz->stop = 1; + if (ok == 0) + lz->stop = 1; return NULL; } @@ -1288,7 +1291,7 @@ takewhile_reduce_setstate(takewhileobject *lz, PyObject *state) { int stop = PyObject_IsTrue(state); - if (stop == -1) + if (stop < 0) return NULL; lz->stop = stop; Py_RETURN_NONE; @@ -3536,7 +3539,7 @@ if (ok == 1) return datum; Py_DECREF(datum); - if (ok == -1) + if (ok < 0) return NULL; } } @@ -3692,9 +3695,11 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (!ok) + if (ok == 0) return item; Py_DECREF(item); + if (ok < 0) + return NULL; } } diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -382,36 +382,28 @@ static PyObject* parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw) { - PyObject *line_option = 0; - PyObject *col_option = 0; + int line_info = 0; + int col_info = 0; PyObject *res = 0; int ok; static char *keywords[] = {"st", "line_info", "col_info", NULL}; if (self == NULL || PyModule_Check(self)) { - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords, - &PyST_Type, &self, &line_option, - &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2tuple", keywords, + &PyST_Type, &self, &line_info, + &col_info); } else - ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:totuple", &keywords[1], - &line_option, &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:totuple", &keywords[1], + &line_info, &col_info); if (ok != 0) { - int lineno = 0; - int col_offset = 0; - if (line_option != NULL) { - lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0; - } - if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; - } /* * Convert ST into a tuple representation. Use Guido's function, * since it's known to work already. */ res = node2tuple(((PyST_Object*)self)->st_node, - PyTuple_New, PyTuple_SetItem, lineno, col_offset); + PyTuple_New, PyTuple_SetItem, line_info, col_info); } return (res); } @@ -426,35 +418,27 @@ static PyObject* parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw) { - PyObject *line_option = 0; - PyObject *col_option = 0; + int line_info = 0; + int col_info = 0; PyObject *res = 0; int ok; static char *keywords[] = {"st", "line_info", "col_info", NULL}; if (self == NULL || PyModule_Check(self)) - ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords, - &PyST_Type, &self, &line_option, - &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2list", keywords, + &PyST_Type, &self, &line_info, + &col_info); else - ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:tolist", &keywords[1], - &line_option, &col_option); + ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:tolist", &keywords[1], + &line_info, &col_info); if (ok) { - int lineno = 0; - int col_offset = 0; - if (line_option != 0) { - lineno = PyObject_IsTrue(line_option) ? 1 : 0; - } - if (col_option != NULL) { - col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0; - } /* * Convert ST into a tuple representation. Use Guido's function, * since it's known to work already. */ res = node2tuple(self->st_node, - PyList_New, PyList_SetItem, lineno, col_offset); + PyList_New, PyList_SetItem, line_info, col_info); } return (res); } diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1033,14 +1033,11 @@ static PyObject * xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) { - PyObject *flagobj = NULL; - XML_Bool flag = XML_TRUE; + int flag = 1; enum XML_Error rc; - if (!PyArg_UnpackTuple(args, "UseForeignDTD", 0, 1, &flagobj)) + if (!PyArg_ParseTuple(args, "p:UseForeignDTD", &flag)) return NULL; - if (flagobj != NULL) - flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE; - rc = XML_UseForeignDTD(self->itself, flag); + rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE); if (rc != XML_ERROR_NONE) { return set_error(self, rc); } @@ -1405,7 +1402,10 @@ } assert(PyUnicode_Check(name)); if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) { - if (PyObject_IsTrue(v)) { + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + if (b) { if (self->buffer == NULL) { self->buffer = malloc(self->buffer_size); if (self->buffer == NULL) { @@ -1424,25 +1424,25 @@ return 0; } if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) { - if (PyObject_IsTrue(v)) - self->ns_prefixes = 1; - else - self->ns_prefixes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ns_prefixes = b; XML_SetReturnNSTriplet(self->itself, self->ns_prefixes); return 0; } if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->ordered_attributes = 1; - else - self->ordered_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ordered_attributes = b; return 0; } if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->specified_attributes = 1; - else - self->specified_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->specified_attributes = b; return 0; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -383,11 +383,15 @@ abc.ABCMeta.__new__, so this function doesn't do anything special to update subclasses. */ - int res; + int abstract, res; if (value != NULL) { + abstract = PyObject_IsTrue(value); + if (abstract < 0) + return -1; res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value); } else { + abstract = 0; res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__"); if (res && PyErr_ExceptionMatches(PyExc_KeyError)) { PyErr_SetString(PyExc_AttributeError, "__abstractmethods__"); @@ -396,12 +400,10 @@ } if (res == 0) { PyType_Modified(type); - if (value && PyObject_IsTrue(value)) { + if (abstract) type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT; - } - else { + else type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT; - } } return res; } diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -429,9 +429,11 @@ ok = PyObject_IsTrue(good); Py_DECREF(good); } - if (ok) + if (ok > 0) return item; Py_DECREF(item); + if (ok < 0) + return NULL; } } -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Thu Aug 16 06:00:11 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 16 Aug 2012 06:00:11 +0200 Subject: [Python-checkins] Daily reference leaks (b878df1d23b1): sum=0 Message-ID: results for b878df1d23b1 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogYsLQOr', '-x'] From python-checkins at python.org Thu Aug 16 06:14:49 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 16 Aug 2012 06:14:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_str_docstr?= =?utf-8?q?ing?= Message-ID: <3WyDhn6RL3zPrh@mail.python.org> http://hg.python.org/cpython/rev/8ff172a1b679 changeset: 78606:8ff172a1b679 branch: 3.2 parent: 78604:56dc7b09f390 user: Nick Coghlan date: Thu Aug 16 14:13:07 2012 +1000 summary: Fix str docstring files: Objects/unicodeobject.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9963,11 +9963,15 @@ } PyDoc_STRVAR(unicode_doc, - "str(string[, encoding[, errors]]) -> str\n\ + "str(object[, encoding[, errors]]) -> str\n\ \n\ -Create a new string object from the given encoded string.\n\ -encoding defaults to the current default string encoding.\n\ -errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'."); +Create a new string object from the given object. If encoding or\n\ +errors is specified, then the object must expose a data buffer\n\ +that will be decoded using the given encoding and error handler.\n\ +Otherwise, returns the result of object.__str__() (if defined)\n\ +or repr(object).\n\ +encoding defaults to sys.getdefaultencoding().\n\ +errors defaults to 'strict'."); static PyObject *unicode_iter(PyObject *seq); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 16 06:14:51 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 16 Aug 2012 06:14:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_str_docstring_fix_from_3=2E2?= Message-ID: <3WyDhq4rDdzPtJ@mail.python.org> http://hg.python.org/cpython/rev/1b6a7fc45772 changeset: 78607:1b6a7fc45772 parent: 78605:b878df1d23b1 parent: 78606:8ff172a1b679 user: Nick Coghlan date: Thu Aug 16 14:14:30 2012 +1000 summary: Merge str docstring fix from 3.2 files: Objects/unicodeobject.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14083,11 +14083,15 @@ } PyDoc_STRVAR(unicode_doc, - "str(string[, encoding[, errors]]) -> str\n\ + "str(object[, encoding[, errors]]) -> str\n\ \n\ -Create a new string object from the given encoded string.\n\ -encoding defaults to the current default string encoding.\n\ -errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'."); +Create a new string object from the given object. If encoding or\n\ +errors is specified, then the object must expose a data buffer\n\ +that will be decoded using the given encoding and error handler.\n\ +Otherwise, returns the result of object.__str__() (if defined)\n\ +or repr(object).\n\ +encoding defaults to sys.getdefaultencoding().\n\ +errors defaults to 'strict'."); static PyObject *unicode_iter(PyObject *seq); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 16 06:30:14 2012 From: python-checkins at python.org (petri.lehtinen) Date: Thu, 16 Aug 2012 06:30:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzExMDYyOiBGaXgg?= =?utf-8?q?universal_newline_support_in_Babyl=2E=5Finstall=5Fmessage=28=29?= Message-ID: <3WyF2Z1dd1zPsY@mail.python.org> http://hg.python.org/cpython/rev/770ffc91a82e changeset: 78608:770ffc91a82e branch: 3.2 parent: 78606:8ff172a1b679 user: Petri Lehtinen date: Thu Aug 16 07:22:15 2012 +0300 summary: #11062: Fix universal newline support in Babyl._install_message() When adding a message from a binary file, \r\n was translated to \r\r\n in the message body. files: Lib/mailbox.py | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1450,10 +1450,17 @@ else: break while True: - buffer = message.read(4096) # Buffer size is arbitrary. - if not buffer: + line = message.readline() + if not line: break - self._file.write(buffer.replace(b'\n', linesep)) + # Universal newline support. + if line.endswith(b'\r\n'): + line = line[:-2] + linesep + elif line.endswith(b'\r'): + line = line[:-1] + linesep + elif line.endswith(b'\n'): + line = line[:-1] + linesep + self._file.write(line) else: raise TypeError('Invalid message type: %s' % type(message)) stop = self._file.tell() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 16 06:30:16 2012 From: python-checkins at python.org (petri.lehtinen) Date: Thu, 16 Aug 2012 06:30:16 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_=2311062=3A_Fix_universal_newline_support_in_Babyl=2E=5F?= =?utf-8?q?install=5Fmessage=28=29?= Message-ID: <3WyF2c0ZKWzPt6@mail.python.org> http://hg.python.org/cpython/rev/5206b9dbf1ac changeset: 78609:5206b9dbf1ac parent: 78607:1b6a7fc45772 parent: 78608:770ffc91a82e user: Petri Lehtinen date: Thu Aug 16 07:27:47 2012 +0300 summary: #11062: Fix universal newline support in Babyl._install_message() files: Lib/mailbox.py | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1447,10 +1447,17 @@ else: break while True: - buffer = message.read(4096) # Buffer size is arbitrary. - if not buffer: + line = message.readline() + if not line: break - self._file.write(buffer.replace(b'\n', linesep)) + # Universal newline support. + if line.endswith(b'\r\n'): + line = line[:-2] + linesep + elif line.endswith(b'\r'): + line = line[:-1] + linesep + elif line.endswith(b'\n'): + line = line[:-1] + linesep + self._file.write(line) else: raise TypeError('Invalid message type: %s' % type(message)) stop = self._file.tell() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 16 15:49:35 2012 From: python-checkins at python.org (nick.coghlan) Date: Thu, 16 Aug 2012 15:49:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devinabox=3A_Allow_devinabox_to_be_us?= =?utf-8?q?ed_to_update_an_existing_version=2C_and_miscellaneous?= Message-ID: <3WyTRz132FzPw8@mail.python.org> http://hg.python.org/devinabox/rev/a3d0b2b293a3 changeset: 41:a3d0b2b293a3 user: Nick Coghlan date: Thu Aug 16 23:43:52 2012 +1000 summary: Allow devinabox to be used to update an existing version, and miscellaneous fixes to get it working again files: make_a_box.py | 27 +++++++++------------------ 1 files changed, 9 insertions(+), 18 deletions(-) diff --git a/make_a_box.py b/make_a_box.py --- a/make_a_box.py +++ b/make_a_box.py @@ -88,22 +88,11 @@ def create(self): """Clone an Hg repository to 'directory'.""" - cmd = ['hg', 'clone', self.url] - subprocess.check_call(cmd) - - -class SvnProvider(Provider): - - """Provide an svn checkout.""" - - @abc.abstractproperty - def url(self): - """Location of the repository.""" - raise NotImplementedError - - def create(self): - """Check out the svn repository to 'directory'.""" - subprocess.check_call(['svn', 'checkout', self.url, self.directory]) + if os.path.exists(self.directory): + subprocess.check_call(['hg', 'pull', '-u', self.url], + cwd = self.directory) + else: + subprocess.check_call(['hg', 'clone', self.url, self.directory]) @rename('Visual C++ Express') @@ -134,7 +123,7 @@ """Clone of coverage.py (WARNING: building takes a while)""" - url = 'https://brettsky at bitbucket.org/ned/coveragepy' + url = 'https://bitbucket.org/ned/coveragepy' size = 133 # Includes the coverage report docs = os.path.join('coverage_report', 'index.html') @@ -181,12 +170,14 @@ latest_release = hg_versions[-1] # Mercurial keeps releases on their servers release_data = pypi.release_data('Mercurial', latest_release) + fname = "mercurial-%s.tar.gz" % latest_release try: - return release_data['download_url'] + release_url = release_data['download_url'] except KeyError: print('Mercurial has changed how it releases software on PyPI; ' 'please report this to bugs.python.org') sys.exit(1) + return os.path.join(release_url, fname) def _url_filename(self, url): """Find the filename from the URL.""" -- Repository URL: http://hg.python.org/devinabox From python-checkins at python.org Thu Aug 16 17:51:21 2012 From: python-checkins at python.org (richard.oudkerk) Date: Thu, 16 Aug 2012 17:51:21 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2314669=3A_Fix_pick?= =?utf-8?q?ling_of_connections_and_sockets_on_MacOSX?= Message-ID: <3WyX8T0MJHzQ1f@mail.python.org> http://hg.python.org/cpython/rev/4307b985209b changeset: 78610:4307b985209b user: Richard Oudkerk date: Thu Aug 16 16:48:55 2012 +0100 summary: Issue #14669: Fix pickling of connections and sockets on MacOSX by sending/receiving an acknowledgment after file descriptor transfer. TestPicklingConnection has been reenabled for MacOSX. files: Lib/multiprocessing/reduction.py | 8 ++++++++ Lib/test/test_multiprocessing.py | 2 -- Misc/NEWS | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/reduction.py b/Lib/multiprocessing/reduction.py --- a/Lib/multiprocessing/reduction.py +++ b/Lib/multiprocessing/reduction.py @@ -120,16 +120,24 @@ else: # Unix + + # On MacOSX we should acknowledge receipt of fds -- see Issue14669 + ACKNOWLEDGE = sys.platform == 'darwin' + def send_handle(conn, handle, destination_pid): with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s: s.sendmsg([b'x'], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, struct.pack("@i", handle))]) + if ACKNOWLEDGE and conn.recv_bytes() != b'ACK': + raise RuntimeError('did not receive acknowledgement of fd') def recv_handle(conn): size = struct.calcsize("@i") with socket.fromfd(conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM) as s: msg, ancdata, flags, addr = s.recvmsg(1, socket.CMSG_LEN(size)) try: + if ACKNOWLEDGE: + conn.send_bytes(b'ACK') cmsg_level, cmsg_type, cmsg_data = ancdata[0] if (cmsg_level == socket.SOL_SOCKET and cmsg_type == socket.SCM_RIGHTS): 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 @@ -2446,8 +2446,6 @@ # Test of sending connection and socket objects between processes # -# Intermittent fails on Mac OS X -- see Issue14669 and Issue12958 - at unittest.skipIf(sys.platform == "darwin", "fd passing unreliable on Mac OS X") @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction") class _TestPicklingConnections(BaseTestCase): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,10 @@ Library ------- +- Issue #14669: Fix pickling of connections and sockets on MacOSX + by sending/receiving an acknowledgment after file descriptor transfer. + TestPicklingConnection has been reenabled for MacOSX. + - Issue #11062: Fix adding a message from file to Babyl mailbox. - Issue #15646: Prevent equivalent of a fork bomb when using -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 16 19:17:57 2012 From: python-checkins at python.org (andrew.svetlov) Date: Thu, 16 Aug 2012 19:17:57 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_subprocess_test_broken?= =?utf-8?q?_on_Windows?= Message-ID: <3WyZ4P6FB4zQ3B@mail.python.org> http://hg.python.org/cpython/rev/150fa296f5b9 changeset: 78611:150fa296f5b9 user: Andrew Svetlov date: Thu Aug 16 20:17:47 2012 +0300 summary: Fix subprocess test broken on Windows files: Lib/test/test_subprocess.py | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 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 @@ -650,15 +650,15 @@ p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + '''\nif True: s = sys.stdin.readline() - sys.stdout.write(s) - sys.stdout.write("line2\\r") - sys.stderr.write("eline2\\n") + sys.stdout.buffer.write(s.encode()) + sys.stdout.buffer.write(b"line2\\r") + sys.stderr.buffer.write(b"eline2\\n") s = sys.stdin.read() - sys.stdout.write(s+"line4\\n") - sys.stdout.write(s+"line5\\r\\n") - sys.stderr.write("eline6\\n") - sys.stderr.write("eline7\\r") - sys.stderr.write("eline8\\r\\n") + sys.stdout.buffer.write(s.encode()) + sys.stdout.buffer.write(b"line4\\n") + sys.stdout.buffer.write(b"line5\\r\\n") + sys.stderr.buffer.write(b"eline6\\r") + sys.stderr.buffer.write(b"eline7\\r\\nz") '''], stdin=subprocess.PIPE, stderr=subprocess.PIPE, @@ -668,10 +668,11 @@ self.addCleanup(p.stderr.close) (stdout, stderr) = p.communicate("line1\nline3\n") self.assertEqual(p.returncode, 0) - self.assertEqual("line1\nline2\nline3\nline4\nline3\nline5\n", stdout) + self.assertEqual("line1\nline2\nline3\nline4\nline5\n", stdout) # Python debug build push something like "[42442 refs]\n" # to stderr at exit of subprocess. - self.assertTrue(stderr.startswith("eline2\neline6\neline7\neline8\n")) + # Don't use assertStderrEqual because it strips CR and LF from output. + self.assertTrue(stderr.startswith("eline2\neline6\neline7\n")) def test_no_leaking(self): # Make sure we leak no resources -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 16 22:21:42 2012 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 16 Aug 2012 22:21:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Update_the_get?= =?utf-8?q?peercert=28=29_example_with_a_real-world_cert_showing_non-trivi?= =?utf-8?q?al?= Message-ID: <3Wyf8Q2PbGzPyR@mail.python.org> http://hg.python.org/cpython/rev/ce49599b9fdf changeset: 78612:ce49599b9fdf branch: 3.2 parent: 78608:770ffc91a82e user: Antoine Pitrou date: Thu Aug 16 22:14:43 2012 +0200 summary: Update the getpeercert() example with a real-world cert showing non-trivial issuer, subject and subjectAltName. files: Doc/library/ssl.rst | 46 ++++++++++++++++++++++---------- 1 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst --- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -427,23 +427,39 @@ If the parameter ``binary_form`` is :const:`False`, and a certificate was received from the peer, this method returns a :class:`dict` instance. If the certificate was not validated, the dict is empty. If the certificate was - validated, it returns a dict with the keys ``subject`` (the principal for - which the certificate was issued), and ``notAfter`` (the time after which the - certificate should not be trusted). If a certificate contains an instance - of the *Subject Alternative Name* extension (see :rfc:`3280`), there will - also be a ``subjectAltName`` key in the dictionary. + validated, it returns a dict with several keys, amongst them ``subject`` + (the principal for which the certificate was issued) and ``issuer`` + (the principal issuing the certificate). If a certificate contains an + instance of the *Subject Alternative Name* extension (see :rfc:`3280`), + there will also be a ``subjectAltName`` key in the dictionary. - The "subject" field is a tuple containing the sequence of relative - distinguished names (RDNs) given in the certificate's data structure for the - principal, and each RDN is a sequence of name-value pairs:: + The ``subject`` and ``issuer`` fields are tuples containing the sequence + of relative distinguished names (RDNs) given in the certificate's data + structure for the respective fields, and each RDN is a sequence of + name-value pairs. Here is a real-world example:: - {'notAfter': 'Feb 16 16:54:50 2013 GMT', - 'subject': ((('countryName', 'US'),), - (('stateOrProvinceName', 'Delaware'),), - (('localityName', 'Wilmington'),), - (('organizationName', 'Python Software Foundation'),), - (('organizationalUnitName', 'SSL'),), - (('commonName', 'somemachine.python.org'),))} + {'issuer': ((('countryName', 'IL'),), + (('organizationName', 'StartCom Ltd.'),), + (('organizationalUnitName', + 'Secure Digital Certificate Signing'),), + (('commonName', + 'StartCom Class 2 Primary Intermediate Server CA'),)), + 'notAfter': 'Nov 22 08:15:19 2013 GMT', + 'notBefore': 'Nov 21 03:09:52 2011 GMT', + 'serialNumber': '95F0', + 'subject': ((('description', '571208-SLe257oHY9fVQ07Z'),), + (('countryName', 'US'),), + (('stateOrProvinceName', 'California'),), + (('localityName', 'San Francisco'),), + (('organizationName', 'Electronic Frontier Foundation, Inc.'),), + (('commonName', '*.eff.org'),), + (('emailAddress', 'hostmaster at eff.org'),)), + 'subjectAltName': (('DNS', '*.eff.org'), ('DNS', 'eff.org')), + 'version': 3} + + .. note:: + To validate a certificate for a particular service, you can use the + :func:`match_hostname` function. If the ``binary_form`` parameter is :const:`True`, and a certificate was provided, this method returns the DER-encoded form of the entire certificate -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 16 22:21:44 2012 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 16 Aug 2012 22:21:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Update_the_getpeercert=28=29_example_with_a_real-world_c?= =?utf-8?q?ert_showing_non-trivial?= Message-ID: <3Wyf8S0mQ2zQ0Q@mail.python.org> http://hg.python.org/cpython/rev/12c062dbe746 changeset: 78613:12c062dbe746 parent: 78611:150fa296f5b9 parent: 78612:ce49599b9fdf user: Antoine Pitrou date: Thu Aug 16 22:18:37 2012 +0200 summary: Update the getpeercert() example with a real-world cert showing non-trivial issuer, subject and subjectAltName. files: Doc/library/ssl.rst | 46 ++++++++++++++++++++++---------- 1 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst --- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -576,23 +576,39 @@ If the parameter ``binary_form`` is :const:`False`, and a certificate was received from the peer, this method returns a :class:`dict` instance. If the certificate was not validated, the dict is empty. If the certificate was - validated, it returns a dict with the keys ``subject`` (the principal for - which the certificate was issued), and ``notAfter`` (the time after which the - certificate should not be trusted). If a certificate contains an instance - of the *Subject Alternative Name* extension (see :rfc:`3280`), there will - also be a ``subjectAltName`` key in the dictionary. + validated, it returns a dict with several keys, amongst them ``subject`` + (the principal for which the certificate was issued) and ``issuer`` + (the principal issuing the certificate). If a certificate contains an + instance of the *Subject Alternative Name* extension (see :rfc:`3280`), + there will also be a ``subjectAltName`` key in the dictionary. - The "subject" field is a tuple containing the sequence of relative - distinguished names (RDNs) given in the certificate's data structure for the - principal, and each RDN is a sequence of name-value pairs:: + The ``subject`` and ``issuer`` fields are tuples containing the sequence + of relative distinguished names (RDNs) given in the certificate's data + structure for the respective fields, and each RDN is a sequence of + name-value pairs. Here is a real-world example:: - {'notAfter': 'Feb 16 16:54:50 2013 GMT', - 'subject': ((('countryName', 'US'),), - (('stateOrProvinceName', 'Delaware'),), - (('localityName', 'Wilmington'),), - (('organizationName', 'Python Software Foundation'),), - (('organizationalUnitName', 'SSL'),), - (('commonName', 'somemachine.python.org'),))} + {'issuer': ((('countryName', 'IL'),), + (('organizationName', 'StartCom Ltd.'),), + (('organizationalUnitName', + 'Secure Digital Certificate Signing'),), + (('commonName', + 'StartCom Class 2 Primary Intermediate Server CA'),)), + 'notAfter': 'Nov 22 08:15:19 2013 GMT', + 'notBefore': 'Nov 21 03:09:52 2011 GMT', + 'serialNumber': '95F0', + 'subject': ((('description', '571208-SLe257oHY9fVQ07Z'),), + (('countryName', 'US'),), + (('stateOrProvinceName', 'California'),), + (('localityName', 'San Francisco'),), + (('organizationName', 'Electronic Frontier Foundation, Inc.'),), + (('commonName', '*.eff.org'),), + (('emailAddress', 'hostmaster at eff.org'),)), + 'subjectAltName': (('DNS', '*.eff.org'), ('DNS', 'eff.org')), + 'version': 3} + + .. note:: + To validate a certificate for a particular service, you can use the + :func:`match_hostname` function. If the ``binary_form`` parameter is :const:`True`, and a certificate was provided, this method returns the DER-encoded form of the entire certificate -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Fri Aug 17 06:19:53 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 17 Aug 2012 06:19:53 +0200 Subject: [Python-checkins] Daily reference leaks (12c062dbe746): sum=0 Message-ID: results for 12c062dbe746 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogl9Ehmo', '-x'] From python-checkins at python.org Fri Aug 17 15:43:36 2012 From: python-checkins at python.org (richard.oudkerk) Date: Fri, 17 Aug 2012 15:43:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE0NTAx?= =?utf-8?q?=3A_Clarify_that_authentication_keys_are_byte_strings?= Message-ID: <3Wz5Gc2tP6zPym@mail.python.org> http://hg.python.org/cpython/rev/636f75da4b9e changeset: 78614:636f75da4b9e branch: 3.2 parent: 78612:ce49599b9fdf user: Richard Oudkerk date: Fri Aug 17 14:39:18 2012 +0100 summary: Issue #14501: Clarify that authentication keys are byte strings files: Doc/library/multiprocessing.rst | 41 ++++++++++---------- 1 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1151,10 +1151,10 @@ *address* is the address on which the manager process listens for new connections. If *address* is ``None`` then an arbitrary one is chosen. - *authkey* is the authentication key which will be used to check the validity - of incoming connections to the server process. If *authkey* is ``None`` then - ``current_process().authkey``. Otherwise *authkey* is used and it - must be a string. + *authkey* is the authentication key which will be used to check the + validity of incoming connections to the server process. If + *authkey* is ``None`` then ``current_process().authkey`` is used. + Otherwise *authkey* is used and it must be a byte string. .. method:: start([initializer[, initargs]]) @@ -1168,7 +1168,7 @@ :meth:`serve_forever` method:: >>> from multiprocessing.managers import BaseManager - >>> manager = BaseManager(address=('', 50000), authkey='abc') + >>> manager = BaseManager(address=('', 50000), authkey=b'abc') >>> server = manager.get_server() >>> server.serve_forever() @@ -1179,7 +1179,7 @@ Connect a local manager object to a remote manager process:: >>> from multiprocessing.managers import BaseManager - >>> m = BaseManager(address=('127.0.0.1', 5000), authkey='abc') + >>> m = BaseManager(address=('127.0.0.1', 5000), authkey=b'abc') >>> m.connect() .. method:: shutdown() @@ -1380,7 +1380,7 @@ >>> queue = queue.Queue() >>> class QueueManager(BaseManager): pass >>> QueueManager.register('get_queue', callable=lambda:queue) - >>> m = QueueManager(address=('', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('', 50000), authkey=b'abracadabra') >>> s = m.get_server() >>> s.serve_forever() @@ -1389,7 +1389,7 @@ >>> from multiprocessing.managers import BaseManager >>> class QueueManager(BaseManager): pass >>> QueueManager.register('get_queue') - >>> m = QueueManager(address=('foo.bar.org', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('foo.bar.org', 50000), authkey=b'abracadabra') >>> m.connect() >>> queue = m.get_queue() >>> queue.put('hello') @@ -1399,7 +1399,7 @@ >>> from multiprocessing.managers import BaseManager >>> class QueueManager(BaseManager): pass >>> QueueManager.register('get_queue') - >>> m = QueueManager(address=('foo.bar.org', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('foo.bar.org', 50000), authkey=b'abracadabra') >>> m.connect() >>> queue = m.get_queue() >>> queue.get() @@ -1423,7 +1423,7 @@ >>> class QueueManager(BaseManager): pass ... >>> QueueManager.register('get_queue', callable=lambda: queue) - >>> m = QueueManager(address=('', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('', 50000), authkey=b'abracadabra') >>> s = m.get_server() >>> s.serve_forever() @@ -1768,9 +1768,9 @@ generally be omitted since it can usually be inferred from the format of *address*. (See :ref:`multiprocessing-address-formats`) - If *authenticate* is ``True`` or *authkey* is a string then digest + If *authenticate* is ``True`` or *authkey* is a byte string then digest authentication is used. The key used for authentication will be either - *authkey* or ``current_process().authkey)`` if *authkey* is ``None``. + *authkey* or ``current_process().authkey`` if *authkey* is ``None``. If authentication fails then :exc:`AuthenticationError` is raised. See :ref:`multiprocessing-auth-keys`. @@ -1805,8 +1805,8 @@ If *authenticate* is ``True`` (``False`` by default) or *authkey* is not ``None`` then digest authentication is used. - If *authkey* is a string then it will be used as the authentication key; - otherwise it must be *None*. + If *authkey* is a byte string then it will be used as the + authentication key; otherwise it must be *None*. If *authkey* is ``None`` and *authenticate* is ``True`` then ``current_process().authkey`` is used as the authentication key. If @@ -1919,12 +1919,13 @@ risk. Therefore :class:`Listener` and :func:`Client` use the :mod:`hmac` module to provide digest authentication. -An authentication key is a string which can be thought of as a password: once a -connection is established both ends will demand proof that the other knows the -authentication key. (Demonstrating that both ends are using the same key does -**not** involve sending the key over the connection.) - -If authentication is requested but do authentication key is specified then the +An authentication key is a byte string which can be thought of as a +password: once a connection is established both ends will demand proof +that the other knows the authentication key. (Demonstrating that both +ends are using the same key does **not** involve sending the key over +the connection.) + +If authentication is requested but no authentication key is specified then the return value of ``current_process().authkey`` is used (see :class:`~multiprocessing.Process`). This value will automatically inherited by any :class:`~multiprocessing.Process` object that the current process creates. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 15:43:38 2012 From: python-checkins at python.org (richard.oudkerk) Date: Fri, 17 Aug 2012 15:43:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge?= Message-ID: <3Wz5Gf0cgwzPt7@mail.python.org> http://hg.python.org/cpython/rev/357d78d739f9 changeset: 78615:357d78d739f9 parent: 78613:12c062dbe746 parent: 78614:636f75da4b9e user: Richard Oudkerk date: Fri Aug 17 14:42:43 2012 +0100 summary: Merge files: Doc/library/multiprocessing.rst | 41 ++++++++++---------- 1 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1207,10 +1207,10 @@ *address* is the address on which the manager process listens for new connections. If *address* is ``None`` then an arbitrary one is chosen. - *authkey* is the authentication key which will be used to check the validity - of incoming connections to the server process. If *authkey* is ``None`` then - ``current_process().authkey``. Otherwise *authkey* is used and it - must be a string. + *authkey* is the authentication key which will be used to check the + validity of incoming connections to the server process. If + *authkey* is ``None`` then ``current_process().authkey`` is used. + Otherwise *authkey* is used and it must be a byte string. .. method:: start([initializer[, initargs]]) @@ -1224,7 +1224,7 @@ :meth:`serve_forever` method:: >>> from multiprocessing.managers import BaseManager - >>> manager = BaseManager(address=('', 50000), authkey='abc') + >>> manager = BaseManager(address=('', 50000), authkey=b'abc') >>> server = manager.get_server() >>> server.serve_forever() @@ -1235,7 +1235,7 @@ Connect a local manager object to a remote manager process:: >>> from multiprocessing.managers import BaseManager - >>> m = BaseManager(address=('127.0.0.1', 5000), authkey='abc') + >>> m = BaseManager(address=('127.0.0.1', 5000), authkey=b'abc') >>> m.connect() .. method:: shutdown() @@ -1454,7 +1454,7 @@ >>> queue = queue.Queue() >>> class QueueManager(BaseManager): pass >>> QueueManager.register('get_queue', callable=lambda:queue) - >>> m = QueueManager(address=('', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('', 50000), authkey=b'abracadabra') >>> s = m.get_server() >>> s.serve_forever() @@ -1463,7 +1463,7 @@ >>> from multiprocessing.managers import BaseManager >>> class QueueManager(BaseManager): pass >>> QueueManager.register('get_queue') - >>> m = QueueManager(address=('foo.bar.org', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('foo.bar.org', 50000), authkey=b'abracadabra') >>> m.connect() >>> queue = m.get_queue() >>> queue.put('hello') @@ -1473,7 +1473,7 @@ >>> from multiprocessing.managers import BaseManager >>> class QueueManager(BaseManager): pass >>> QueueManager.register('get_queue') - >>> m = QueueManager(address=('foo.bar.org', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('foo.bar.org', 50000), authkey=b'abracadabra') >>> m.connect() >>> queue = m.get_queue() >>> queue.get() @@ -1497,7 +1497,7 @@ >>> class QueueManager(BaseManager): pass ... >>> QueueManager.register('get_queue', callable=lambda: queue) - >>> m = QueueManager(address=('', 50000), authkey='abracadabra') + >>> m = QueueManager(address=('', 50000), authkey=b'abracadabra') >>> s = m.get_server() >>> s.serve_forever() @@ -1865,9 +1865,9 @@ generally be omitted since it can usually be inferred from the format of *address*. (See :ref:`multiprocessing-address-formats`) - If *authenticate* is ``True`` or *authkey* is a string then digest + If *authenticate* is ``True`` or *authkey* is a byte string then digest authentication is used. The key used for authentication will be either - *authkey* or ``current_process().authkey)`` if *authkey* is ``None``. + *authkey* or ``current_process().authkey`` if *authkey* is ``None``. If authentication fails then :exc:`~multiprocessing.AuthenticationError` is raised. See :ref:`multiprocessing-auth-keys`. @@ -1903,8 +1903,8 @@ If *authenticate* is ``True`` (``False`` by default) or *authkey* is not ``None`` then digest authentication is used. - If *authkey* is a string then it will be used as the authentication key; - otherwise it must be *None*. + If *authkey* is a byte string then it will be used as the + authentication key; otherwise it must be *None*. If *authkey* is ``None`` and *authenticate* is ``True`` then ``current_process().authkey`` is used as the authentication key. If @@ -2081,12 +2081,13 @@ risk. Therefore :class:`Listener` and :func:`Client` use the :mod:`hmac` module to provide digest authentication. -An authentication key is a string which can be thought of as a password: once a -connection is established both ends will demand proof that the other knows the -authentication key. (Demonstrating that both ends are using the same key does -**not** involve sending the key over the connection.) - -If authentication is requested but do authentication key is specified then the +An authentication key is a byte string which can be thought of as a +password: once a connection is established both ends will demand proof +that the other knows the authentication key. (Demonstrating that both +ends are using the same key does **not** involve sending the key over +the connection.) + +If authentication is requested but no authentication key is specified then the return value of ``current_process().authkey`` is used (see :class:`~multiprocessing.Process`). This value will automatically inherited by any :class:`~multiprocessing.Process` object that the current process creates. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 16:06:50 2012 From: python-checkins at python.org (richard.oudkerk) Date: Fri, 17 Aug 2012 16:06:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NDEy?= =?utf-8?q?=3A_Remove_erroneous_note_about_weakrefs?= Message-ID: <3Wz5nQ3KHfzQ0h@mail.python.org> http://hg.python.org/cpython/rev/78b0f294674c changeset: 78616:78b0f294674c branch: 2.7 parent: 78603:ba1c48f8b571 user: Richard Oudkerk date: Fri Aug 17 15:00:58 2012 +0100 summary: Issue #15412: Remove erroneous note about weakrefs files: Doc/library/weakref.rst | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -53,12 +53,6 @@ dictionary implementations is exposed by the :mod:`weakref` module for the benefit of advanced uses. -.. note:: - - Weak references to an object are cleared before the object's :meth:`__del__` - is called, to ensure that the weak reference callback (if any) finds the - object still alive. - Not all objects can be weakly referenced; those objects which can include class instances, functions written in Python (but not in C), methods (both bound and unbound), sets, frozensets, file objects, :term:`generator`\s, type objects, -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 16:06:52 2012 From: python-checkins at python.org (richard.oudkerk) Date: Fri, 17 Aug 2012 16:06:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NDEy?= =?utf-8?q?=3A_Remove_erroneous_note_about_weakrefs?= Message-ID: <3Wz5nS0JK1zQ0Z@mail.python.org> http://hg.python.org/cpython/rev/24b13be81d61 changeset: 78617:24b13be81d61 branch: 3.2 parent: 78614:636f75da4b9e user: Richard Oudkerk date: Fri Aug 17 15:02:47 2012 +0100 summary: Issue #15412: Remove erroneous note about weakrefs files: Doc/library/weakref.rst | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -53,12 +53,6 @@ directly. The low-level machinery used by the weak dictionary implementations is exposed by the :mod:`weakref` module for the benefit of advanced uses. -.. note:: - - Weak references to an object are cleared before the object's :meth:`__del__` - is called, to ensure that the weak reference callback (if any) finds the - object still alive. - Not all objects can be weakly referenced; those objects which can include class instances, functions written in Python (but not in C), instance methods, sets, frozensets, some :term:`file objects `, :term:`generator`\s, type -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 16:06:53 2012 From: python-checkins at python.org (richard.oudkerk) Date: Fri, 17 Aug 2012 16:06:53 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge?= Message-ID: <3Wz5nT2zJjzPyL@mail.python.org> http://hg.python.org/cpython/rev/0cd35f4a0091 changeset: 78618:0cd35f4a0091 parent: 78615:357d78d739f9 parent: 78617:24b13be81d61 user: Richard Oudkerk date: Fri Aug 17 15:05:09 2012 +0100 summary: Merge files: Doc/library/weakref.rst | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -53,12 +53,6 @@ directly. The low-level machinery used by the weak dictionary implementations is exposed by the :mod:`weakref` module for the benefit of advanced uses. -.. note:: - - Weak references to an object are cleared before the object's :meth:`__del__` - is called, to ensure that the weak reference callback (if any) finds the - object still alive. - Not all objects can be weakly referenced; those objects which can include class instances, functions written in Python (but not in C), instance methods, sets, frozensets, some :term:`file objects `, :term:`generator`\s, type -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 19:21:24 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 17 Aug 2012 19:21:24 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315715=3A_Ignore_f?= =?utf-8?q?ailed_imports_triggered_by_the_use_of_fromlist=2E?= Message-ID: <3WzB5w3k1YzQ1T@mail.python.org> http://hg.python.org/cpython/rev/0d52f125dd32 changeset: 78619:0d52f125dd32 user: Brett Cannon date: Fri Aug 17 13:21:16 2012 -0400 summary: Issue #15715: Ignore failed imports triggered by the use of fromlist. When the fromlist argument is specified for __import__() and the attribute doesn't already exist, an import is attempted. If that fails (e.g. module doesn't exist), the ImportError will now be silenced (for backwards-compatibility). This *does not* affect ``from ... import ...`` statements. Thanks to Eric Snow for the patch and Simon Feltman for reporting the regression. files: Lib/importlib/_bootstrap.py | 9 +- Lib/test/test_import.py | 6 + Misc/NEWS | 3 + Python/importlib.h | 914 ++++++++++++----------- 4 files changed, 474 insertions(+), 458 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1573,8 +1573,13 @@ fromlist.extend(module.__all__) for x in fromlist: if not hasattr(module, x): - _call_with_frames_removed(import_, - '{}.{}'.format(module.__name__, x)) + try: + _call_with_frames_removed(import_, + '{}.{}'.format(module.__name__, x)) + except ImportError: + # Backwards-compatibility dictates we ignore failed + # imports triggered by fromlist. + pass return module 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 @@ -334,6 +334,12 @@ del sys.path[0] remove_files(TESTFN) + def test_bogus_fromlist(self): + try: + __import__('http', fromlist=['blah']) + except ImportError: + self.fail("fromlist must allow bogus names") + class PycRewritingTests(unittest.TestCase): # Test that the `co_filename` attribute on code objects always points diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Library ------- +- Issue #15715: importlib.__import__() will silence an ImportError when the use + of fromlist leads to a failed import. + - Issue #14669: Fix pickling of connections and sockets on MacOSX by sending/receiving an acknowledgment after file descriptor transfer. TestPicklingConnection has been reenabled for MacOSX. 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 Fri Aug 17 20:08:32 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 17 Aug 2012 20:08:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315640=3A_Document?= =?utf-8?q?_importlib=2Eabc=2EFinder_as_deprecated=2E?= Message-ID: <3WzC8J2tkCzQ3X@mail.python.org> http://hg.python.org/cpython/rev/4bbb1ff4f7ea changeset: 78620:4bbb1ff4f7ea user: Brett Cannon date: Fri Aug 17 14:08:24 2012 -0400 summary: Issue #15640: Document importlib.abc.Finder as deprecated. The code for the class itself isn't deprecated for backwards-compatibility reasons, but the class shouldn't be directly inherited by anyone anymore as the API is no longer as widely valid as it used to be. files: Doc/library/importlib.rst | 49 +++++++++++++------------- Misc/NEWS | 2 + 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -124,7 +124,7 @@ ABC hierarchy:: object - +-- Finder + +-- Finder (deprecated) | +-- MetaPathFinder | +-- PathEntryFinder +-- Loader @@ -133,15 +133,16 @@ +-- ExecutionLoader --+ +-- FileLoader +-- SourceLoader - +-- PyLoader - +-- PyPycLoader + +-- PyLoader (deprecated) + +-- PyPycLoader (deprecated) .. class:: Finder - An abstract base class representing a :term:`finder`. Finder - implementations should derive from (or register with) the more specific - :class:`MetaPathFinder` or :class:`PathEntryFinder` ABCs. + An abstract base class representing a :term:`finder`. + + .. deprecated:: 3.3 + Use :class:`MetaPathFinder` or :class:`PathEntryFinder` instead. .. method:: find_module(fullname, path=None) @@ -656,30 +657,30 @@ .. class:: PathFinder - :term:`Finder` for :data:`sys.path` and package ``__path__`` attributes. - This class implements the :class:`importlib.abc.MetaPathFinder` ABC. + A :term:`Finder` for :data:`sys.path` and package ``__path__`` attributes. + This class implements the :class:`importlib.abc.MetaPathFinder` ABC. - Only class methods are defined by this class to alleviate the need for - instantiation. + Only class methods are defined by this class to alleviate the need for + instantiation. - .. classmethod:: find_module(fullname, path=None) + .. classmethod:: find_module(fullname, path=None) - Class method that attempts to find a :term:`loader` for the module - specified by *fullname* on :data:`sys.path` or, if defined, on - *path*. For each path entry that is searched, - :data:`sys.path_importer_cache` is checked. If a non-false object is - found then it is used as the :term:`finder` to look for the module - being searched for. If no entry is found in - :data:`sys.path_importer_cache`, then :data:`sys.path_hooks` is - searched for a finder for the path entry and, if found, is stored in - :data:`sys.path_importer_cache` along with being queried about the - module. If no finder is ever found then ``None`` is both stored in - the cache and returned. + Class method that attempts to find a :term:`loader` for the module + specified by *fullname* on :data:`sys.path` or, if defined, on + *path*. For each path entry that is searched, + :data:`sys.path_importer_cache` is checked. If a non-false object is + found then it is used as the :term:`finder` to look for the module + being searched for. If no entry is found in + :data:`sys.path_importer_cache`, then :data:`sys.path_hooks` is + searched for a finder for the path entry and, if found, is stored in + :data:`sys.path_importer_cache` along with being queried about the + module. If no finder is ever found then ``None`` is both stored in + the cache and returned. .. classmethod:: invalidate_caches() - Call :meth:`importlib.abc.PathEntryFinder.invalidate_caches` on all - finders stored in :attr:`sys.path_importer_cache`. + Calls :meth:`importlib.abc.PathEntryFinder.invalidate_caches` on all + finders stored in :attr:`sys.path_importer_cache`. .. class:: FileFinder(path, \*loader_details) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -41,6 +41,8 @@ Documentation ------------- +- Issue #15640: Document importlib.abc.Finder as deprecated. + - Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by Daniel Ellis. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 21:42:51 2012 From: python-checkins at python.org (terry.reedy) Date: Fri, 17 Aug 2012 21:42:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgMTU2NjA6?= =?utf-8?q?_Clarify_0_prefix_for_width_field_in_str=2Eformat_doc=2E?= Message-ID: <3WzFF76p6FzQ67@mail.python.org> http://hg.python.org/cpython/rev/85cd54b2d3a1 changeset: 78621:85cd54b2d3a1 branch: 2.7 parent: 78616:78b0f294674c user: Terry Jan Reedy date: Fri Aug 17 15:37:52 2012 -0400 summary: Issue 15660: Clarify 0 prefix for width field in str.format doc. files: Doc/library/string.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -389,9 +389,9 @@ *width* is a decimal integer defining the minimum field width. If not specified, then the field width will be determined by the content. -If the *width* field is preceded by a zero (``'0'``) character, this enables -zero-padding. This is equivalent to an *alignment* type of ``'='`` and a *fill* -character of ``'0'``. +Preceding the *width* field by a zero (``'0'``) character enables +sign-aware zero-padding for numeric types. This is equivalent to a *fill* +character of ``'0'`` with an *alignment* type of ``'='``. The *precision* is a decimal number indicating how many digits should be displayed after the decimal point for a floating point value formatted with -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 21:42:55 2012 From: python-checkins at python.org (terry.reedy) Date: Fri, 17 Aug 2012 21:42:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgMTU2NjA6?= =?utf-8?q?_Clarify_0_prefix_for_width_field_in_str=2Eformat_doc=2E?= Message-ID: <3WzFFC0d8MzQ6Q@mail.python.org> http://hg.python.org/cpython/rev/6bc14974024f changeset: 78622:6bc14974024f branch: 3.2 parent: 78617:24b13be81d61 user: Terry Jan Reedy date: Fri Aug 17 15:40:46 2012 -0400 summary: Issue 15660: Clarify 0 prefix for width field in str.format doc. files: Doc/library/string.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -368,9 +368,9 @@ *width* is a decimal integer defining the minimum field width. If not specified, then the field width will be determined by the content. -If the *width* field is preceded by a zero (``'0'``) character, this enables -zero-padding. This is equivalent to an *alignment* type of ``'='`` and a *fill* -character of ``'0'``. +Preceding the *width* field by a zero (``'0'``) character enables +sign-aware zero-padding for numeric types. This is equivalent to a *fill* +character of ``'0'`` with an *alignment* type of ``'='``. The *precision* is a decimal number indicating how many digits should be displayed after the decimal point for a floating point value formatted with -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 21:42:56 2012 From: python-checkins at python.org (terry.reedy) Date: Fri, 17 Aug 2012 21:42:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E2_=2315660?= Message-ID: <3WzFFD45GFzQ6M@mail.python.org> http://hg.python.org/cpython/rev/f181dd088e63 changeset: 78623:f181dd088e63 parent: 78620:4bbb1ff4f7ea parent: 78622:6bc14974024f user: Terry Jan Reedy date: Fri Aug 17 15:42:12 2012 -0400 summary: Merge with 3.2 #15660 files: Doc/library/string.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -368,9 +368,9 @@ *width* is a decimal integer defining the minimum field width. If not specified, then the field width will be determined by the content. -If the *width* field is preceded by a zero (``'0'``) character, this enables -zero-padding. This is equivalent to an *alignment* type of ``'='`` and a *fill* -character of ``'0'``. +Preceding the *width* field by a zero (``'0'``) character enables +sign-aware zero-padding for numeric types. This is equivalent to a *fill* +character of ``'0'`` with an *alignment* type of ``'='``. The *precision* is a decimal number indicating how many digits should be displayed after the decimal point for a floating point value formatted with -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 22:23:24 2012 From: python-checkins at python.org (ned.deily) Date: Fri, 17 Aug 2012 22:23:24 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315678=3A_Fix_menu?= =?utf-8?q?_customization_for_IDLE_started_from_OS_X?= Message-ID: <3WzG7w4RgrzQ4J@mail.python.org> http://hg.python.org/cpython/rev/4610ac42130e changeset: 78624:4610ac42130e user: Ned Deily date: Fri Aug 17 13:22:30 2012 -0700 summary: Issue #15678: Fix menu customization for IDLE started from OS X command lines. It was broken as a side effect of the changes to pythonw.c in b79d276041a8 for #15307. Since sys.executable no longer includes 'Python.app' in the path name, test for a framework build instead. This should give the previous behavior in nearly all cases. Whether the previous behavior is sensible is left as an issue for later releases. IDLE.app behavior was not affected as it does its own manipulation of sys.executable. files: Lib/idlelib/macosxSupport.py | 16 +++++++++++++--- Misc/NEWS | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Lib/idlelib/macosxSupport.py b/Lib/idlelib/macosxSupport.py --- a/Lib/idlelib/macosxSupport.py +++ b/Lib/idlelib/macosxSupport.py @@ -12,12 +12,22 @@ def runningAsOSXApp(): """ Returns True if Python is running from within an app on OSX. - If so, assume that Python was built with Aqua Tcl/Tk rather than - X11 Tcl/Tk. + If so, the various OS X customizations will be triggered later (menu + fixup, et al). (Originally, this test was supposed to condition + behavior on whether IDLE was running under Aqua Tk rather than + under X11 Tk but that does not work since a framework build + could be linked with X11. For several releases, this test actually + differentiates between whether IDLE is running from a framework or + not. As a future enhancement, it should be considered whether there + should be a difference based on framework and any needed X11 adaptions + should be made dependent on a new function that actually tests for X11.) """ global _appbundle if _appbundle is None: - _appbundle = (sys.platform == 'darwin' and '.app' in sys.executable) + _appbundle = sys.platform == 'darwin' + if _appbundle: + import sysconfig + _appbundle = bool(sysconfig.get_config_var('PYTHONFRAMEWORK')) return _appbundle _carbonaquatk = None diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,9 @@ multiprocessing on Windows without the "if __name__ == '__main__'" idiom. +- Issue #15678: Fix IDLE menus when started from OS X command line + (3.3.0b2 regression). + C API ----- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 17 23:14:38 2012 From: python-checkins at python.org (stefan.krah) Date: Fri, 17 Aug 2012 23:14:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Closes_=2315632=3A_regrtes?= =?utf-8?q?t=2Epy=3A_fix_spurious_refleaks_due_to_various_caches?= Message-ID: <3WzHH25Cv2zQ6X@mail.python.org> http://hg.python.org/cpython/rev/dc18d73e67a5 changeset: 78625:dc18d73e67a5 user: Stefan Krah date: Fri Aug 17 23:09:48 2012 +0200 summary: Closes #15632: regrtest.py: fix spurious refleaks due to various caches filling up with random data. files: Lib/test/regrtest.py | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -381,9 +381,9 @@ huntrleaks[1] = int(huntrleaks[1]) if len(huntrleaks) == 2 or not huntrleaks[2]: huntrleaks[2:] = ["reflog.txt"] - # Avoid false positives due to the character cache in - # stringobject.c filling slowly with random data - warm_char_cache() + # Avoid false positives due to various caches + # filling slowly with random data: + warm_caches() elif o in ('-M', '--memlimit'): support.set_memlimit(a) elif o in ('-u', '--use'): @@ -1430,10 +1430,15 @@ # Collect cyclic trash. gc.collect() -def warm_char_cache(): +def warm_caches(): + # char cache s = bytes(range(256)) for i in range(256): s[i:i+1] + # unicode cache + x = [chr(i) for i in range(256)] + # int cache + x = list(range(-5, 257)) def findtestdir(path=None): return path or os.path.dirname(__file__) or os.curdir -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:40:17 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:40:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1Njk0OiBMaW5r?= =?utf-8?q?_discussion_of_file_objects_to_glossary_entry=2E?= Message-ID: <3WzMrK7110zQ6q@mail.python.org> http://hg.python.org/cpython/rev/1d5c451a1365 changeset: 78626:1d5c451a1365 branch: 3.2 parent: 78622:6bc14974024f user: R David Murray date: Fri Aug 17 20:33:54 2012 -0400 summary: #15694: Link discussion of file objects to glossary entry. This is analogous to the link for `flie objects` in the description of 'open' that exists in the 2.7 docs, and adds a similar link to the io docs. Patch by Chris Jerdonek. files: Doc/library/functions.rst | 10 +++++++--- Doc/library/io.rst | 14 +++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -790,10 +790,13 @@ :meth:`__index__` method that returns an integer. + .. index:: + single: file object; open() built-in function + .. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True) - Open *file* and return a corresponding stream. If the file cannot be opened, - an :exc:`IOError` is raised. + Open *file* and return a corresponding :term:`file object`. If the file + cannot be opened, an :exc:`IOError` is raised. *file* is either a string or bytes object giving the pathname (absolute or relative to the current working directory) of the file to be opened or @@ -900,7 +903,8 @@ closed. If a filename is given *closefd* has no effect and must be ``True`` (the default). - The type of file object returned by the :func:`open` function depends on the + The type of :term:`file object` returned by the :func:`open` function + depends on the mode. When :func:`open` is used to open a file in a text mode (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of :class:`io.TextIOBase` (specifically :class:`io.TextIOWrapper`). When used diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -16,11 +16,15 @@ Overview -------- -The :mod:`io` module provides Python's main facilities for dealing for various -types of I/O. There are three main types of I/O: *text I/O*, *binary I/O*, *raw -I/O*. These are generic categories, and various backing stores can be used for -each of them. Concrete objects belonging to any of these categories will often -be called *streams*; another common term is *file-like objects*. +.. index:: + single: file object; io module + +The :mod:`io` module provides Python's main facilities for dealing with various +types of I/O. There are three main types of I/O: *text I/O*, *binary I/O* +and *raw I/O*. These are generic categories, and various backing stores can +be used for each of them. A concrete object belonging to any of these +categories is called a :term:`file object`. Other common terms are *stream* +and *file-like object*. Independently of its category, each concrete stream object will also have various capabilities: it can be read-only, write-only, or read-write. It can -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:40:19 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:40:19 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315694=3A_Link_discussion_of_file_objects_to_glo?= =?utf-8?q?ssary_entry=2E?= Message-ID: <3WzMrM50dMzQ6q@mail.python.org> http://hg.python.org/cpython/rev/977606940531 changeset: 78627:977606940531 parent: 78625:dc18d73e67a5 parent: 78626:1d5c451a1365 user: R David Murray date: Fri Aug 17 20:38:19 2012 -0400 summary: Merge #15694: Link discussion of file objects to glossary entry. This is analogous to the link for `flie objects` in the description of 'open' that exists in the 2.7 docs, and adds a similar link to the io docs. Patch by Chris Jerdonek. files: Doc/library/functions.rst | 10 +++++++--- Doc/library/io.rst | 14 +++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -787,10 +787,13 @@ :meth:`__index__` method that returns an integer. + .. index:: + single: file object; open() built-in function + .. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) - Open *file* and return a corresponding stream. If the file cannot be opened, - an :exc:`OSError` is raised. + Open *file* and return a corresponding :term:`file object`. If the file + cannot be opened, an :exc:`OSError` is raised. *file* is either a string or bytes object giving the pathname (absolute or relative to the current working directory) of the file to be opened or @@ -910,7 +913,8 @@ The *opener* parameter was added. The ``'x'`` mode was added. - The type of file object returned by the :func:`open` function depends on the + The type of :term:`file object` returned by the :func:`open` function + depends on the mode. When :func:`open` is used to open a file in a text mode (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of :class:`io.TextIOBase` (specifically :class:`io.TextIOWrapper`). When used diff --git a/Doc/library/io.rst b/Doc/library/io.rst --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -16,11 +16,15 @@ Overview -------- -The :mod:`io` module provides Python's main facilities for dealing for various -types of I/O. There are three main types of I/O: *text I/O*, *binary I/O*, *raw -I/O*. These are generic categories, and various backing stores can be used for -each of them. Concrete objects belonging to any of these categories will often -be called *streams*; another common term is *file-like objects*. +.. index:: + single: file object; io module + +The :mod:`io` module provides Python's main facilities for dealing with various +types of I/O. There are three main types of I/O: *text I/O*, *binary I/O* +and *raw I/O*. These are generic categories, and various backing stores can +be used for each of them. A concrete object belonging to any of these +categories is called a :term:`file object`. Other common terms are *stream* +and *file-like object*. Independently of its category, each concrete stream object will also have various capabilities: it can be read-only, write-only, or read-write. It can -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:40:21 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:40:21 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1Njk0OiByZWZs?= =?utf-8?q?ow_paragraph=2E?= Message-ID: <3WzMrP0dRhzQ7t@mail.python.org> http://hg.python.org/cpython/rev/083c37e75c49 changeset: 78628:083c37e75c49 branch: 3.2 parent: 78626:1d5c451a1365 user: R David Murray date: Fri Aug 17 20:39:21 2012 -0400 summary: #15694: reflow paragraph. files: Doc/library/functions.rst | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -904,9 +904,8 @@ (the default). The type of :term:`file object` returned by the :func:`open` function - depends on the - mode. When :func:`open` is used to open a file in a text mode (``'w'``, - ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of + depends on the mode. When :func:`open` is used to open a file in a text + mode (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of :class:`io.TextIOBase` (specifically :class:`io.TextIOWrapper`). When used to open a file in a binary mode with buffering, the returned class is a subclass of :class:`io.BufferedIOBase`. The exact class varies: in read -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:40:22 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:40:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315694=3A_reflow_paragraph=2E?= Message-ID: <3WzMrQ3PLPzQ7s@mail.python.org> http://hg.python.org/cpython/rev/d57ea50bc526 changeset: 78629:d57ea50bc526 parent: 78627:977606940531 parent: 78628:083c37e75c49 user: R David Murray date: Fri Aug 17 20:40:03 2012 -0400 summary: Merge #15694: reflow paragraph. files: Doc/library/functions.rst | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -914,9 +914,8 @@ The ``'x'`` mode was added. The type of :term:`file object` returned by the :func:`open` function - depends on the - mode. When :func:`open` is used to open a file in a text mode (``'w'``, - ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of + depends on the mode. When :func:`open` is used to open a file in a text + mode (``'w'``, ``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of :class:`io.TextIOBase` (specifically :class:`io.TextIOWrapper`). When used to open a file in a binary mode with buffering, the returned class is a subclass of :class:`io.BufferedIOBase`. The exact class varies: in read -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:50:42 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:50:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1MzU1OiBNZW50?= =?utf-8?q?ion_already-executing_Exception_in_generator_docs=2E?= Message-ID: <3WzN4L26nLzQ0v@mail.python.org> http://hg.python.org/cpython/rev/dc4b00f51c48 changeset: 78630:dc4b00f51c48 branch: 3.2 parent: 78628:083c37e75c49 user: R David Murray date: Fri Aug 17 20:48:59 2012 -0400 summary: #15355: Mention already-executing Exception in generator docs. Patch by Chris Jerdonek. files: Doc/reference/expressions.rst | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -354,8 +354,15 @@ .. index:: object: generator -The following generator's methods can be used to control the execution of a -generator function: + +Generator-iterator methods +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This subsection describes the methods of a generator iterator. They can +be used to control the execution of a generator function. + +Note that calling any of the generator methods below when the generator +is already executing raises a :exc:`ValueError` exception. .. index:: exception: StopIteration -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:50:44 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:50:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315355=3A_Mention_already-executing_Exception_in?= =?utf-8?q?_generator_docs=2E?= Message-ID: <3WzN4N0RxKzQ3D@mail.python.org> http://hg.python.org/cpython/rev/73f1ba3319dd changeset: 78631:73f1ba3319dd parent: 78629:d57ea50bc526 parent: 78630:dc4b00f51c48 user: R David Murray date: Fri Aug 17 20:49:24 2012 -0400 summary: Merge #15355: Mention already-executing Exception in generator docs. Patch by Chris Jerdonek. files: Doc/reference/expressions.rst | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -377,8 +377,15 @@ .. index:: object: generator -The following generator's methods can be used to control the execution of a -generator function: + +Generator-iterator methods +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This subsection describes the methods of a generator iterator. They can +be used to control the execution of a generator function. + +Note that calling any of the generator methods below when the generator +is already executing raises a :exc:`ValueError` exception. .. index:: exception: StopIteration -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:50:45 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:50:45 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1MzU1OiBNZW50?= =?utf-8?q?ion_already-executing_Exception_in_generator_docs=2E?= Message-ID: <3WzN4P3HTTzQ3y@mail.python.org> http://hg.python.org/cpython/rev/a62309ae88a2 changeset: 78632:a62309ae88a2 branch: 2.7 parent: 78621:85cd54b2d3a1 user: R David Murray date: Fri Aug 17 20:49:51 2012 -0400 summary: #15355: Mention already-executing Exception in generator docs. Patch by Chris Jerdonek. files: Doc/reference/expressions.rst | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -421,8 +421,15 @@ .. index:: object: generator -The following generator's methods can be used to control the execution of a -generator function: + +Generator-iterator methods +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This subsection describes the methods of a generator iterator. They can +be used to control the execution of a generator function. + +Note that calling any of the generator methods below when the generator +is already executing raises a :exc:`ValueError` exception. .. index:: exception: StopIteration -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:56:16 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:56:16 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1NjM2OiBhZGQg?= =?utf-8?q?versionadded_for_decodebytes?= Message-ID: <3WzNBm0ZRVzPyd@mail.python.org> http://hg.python.org/cpython/rev/ca5b36754892 changeset: 78633:ca5b36754892 branch: 3.2 parent: 78630:dc4b00f51c48 user: R David Murray date: Fri Aug 17 20:55:21 2012 -0400 summary: #15636: add versionadded for decodebytes files: Doc/library/base64.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/base64.rst b/Doc/library/base64.rst --- a/Doc/library/base64.rst +++ b/Doc/library/base64.rst @@ -140,6 +140,8 @@ encoded data, and return a byte string containing the resulting binary data. ``decodestring`` is a deprecated alias. + .. versionadded:: 3.1 + .. function:: encode(input, output) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 02:56:17 2012 From: python-checkins at python.org (r.david.murray) Date: Sat, 18 Aug 2012 02:56:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315636=3A_add_versionadded_for_decodebytes?= Message-ID: <3WzNBn6RQKzQ4N@mail.python.org> http://hg.python.org/cpython/rev/a343fa692bb0 changeset: 78634:a343fa692bb0 parent: 78631:73f1ba3319dd parent: 78633:ca5b36754892 user: R David Murray date: Fri Aug 17 20:55:54 2012 -0400 summary: Merge #15636: add versionadded for decodebytes files: Doc/library/base64.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Doc/library/base64.rst b/Doc/library/base64.rst --- a/Doc/library/base64.rst +++ b/Doc/library/base64.rst @@ -145,6 +145,8 @@ encoded data, and return a byte string containing the resulting binary data. ``decodestring`` is a deprecated alias. + .. versionadded:: 3.1 + .. function:: encode(input, output) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 04:41:41 2012 From: python-checkins at python.org (eli.bendersky) Date: Sat, 18 Aug 2012 04:41:41 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NTg2?= =?utf-8?q?=3A_porting_ET=27s_new_documentation_bits_to_2=2E7=2E_Patch_by_?= =?utf-8?q?Daniel_Ellis?= Message-ID: <3WzQXP644bzPtn@mail.python.org> http://hg.python.org/cpython/rev/094423a65a4e changeset: 78635:094423a65a4e branch: 2.7 parent: 78632:a62309ae88a2 user: Eli Bendersky date: Sat Aug 18 05:40:38 2012 +0300 summary: Issue #15586: porting ET's new documentation bits to 2.7. Patch by Daniel Ellis files: Doc/library/xml.etree.elementtree.rst | 315 +++++++++++++- 1 files changed, 308 insertions(+), 7 deletions(-) diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -46,11 +46,313 @@ `Introducing ElementTree 1.3 `_. +Tutorial +-------- + +This is a short tutorial for using :mod:`xml.etree.ElementTree` (``ET`` in +short). The goal is to demonstrate some of the building blocks and basic +concepts of the module. + +XML tree and elements +^^^^^^^^^^^^^^^^^^^^^ + +XML is an inherently hierarchical data format, and the most natural way to +represent it is with a tree. ``ET`` has two classes for this purpose - +:class:`ElementTree` represents the whole XML document as a tree, and +:class:`Element` represents a single node in this tree. Interactions with +the whole document (reading and writing to/from files) are usually done +on the :class:`ElementTree` level. Interactions with a single XML element +and its sub-elements are done on the :class:`Element` level. + +.. _elementtree-parsing-xml: + +Parsing XML +^^^^^^^^^^^ + +We'll be using the following XML document as the sample data for this section: + +.. code-block:: xml + + + + + 1 + 2008 + 141100 + + + + + 4 + 2011 + 59900 + + + + 68 + 2011 + 13600 + + + + + +We have a number of ways to import the data. Reading the file from disk:: + + import xml.etree.ElementTree as ET + tree = ET.parse('country_data.xml') + root = tree.getroot() + +Reading the data from a string:: + + root = ET.fromstring(country_data_as_string) + +:func:`fromstring` parses XML from a string directly into an :class:`Element`, +which is the root element of the parsed tree. Other parsing functions may +create an :class:`ElementTree`. Check the documentation to be sure. + +As an :class:`Element`, ``root`` has a tag and a dictionary of attributes:: + + >>> root.tag + 'data' + >>> root.attrib + {} + +It also has children nodes over which we can iterate:: + + >>> for child in root: + ... print child.tag, child.attrib + ... + country {'name': 'Liechtenstein'} + country {'name': 'Singapore'} + country {'name': 'Panama'} + +Children are nested, and we can access specific child nodes by index:: + + >>> root[0][1].text + '2008' + +Finding interesting elements +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +:class:`Element` has some useful methods that help iterate recursively over all +the sub-tree below it (its children, their children, and so on). For example, +:meth:`Element.iter`:: + + >>> for neighbor in root.iter('neighbor'): + ... print neighbor.attrib + ... + {'name': 'Austria', 'direction': 'E'} + {'name': 'Switzerland', 'direction': 'W'} + {'name': 'Malaysia', 'direction': 'N'} + {'name': 'Costa Rica', 'direction': 'W'} + {'name': 'Colombia', 'direction': 'E'} + +:meth:`Element.findall` finds only elements with a tag which are direct +children of the current element. :meth:`Element.find` finds the *first* child +with a particular tag, and :meth:`Element.text` accesses the element's text +content. :meth:`Element.get` accesses the element's attributes:: + + >>> for country in root.findall('country'): + ... rank = country.find('rank').text + ... name = country.get('name') + ... print name, rank + ... + Liechtenstein 1 + Singapore 4 + Panama 68 + +More sophisticated specification of which elements to look for is possible by +using :ref:`XPath `. + +Modifying an XML File +^^^^^^^^^^^^^^^^^^^^^ + +:class:`ElementTree` provides a simple way to build XML documents and write them to files. +The :meth:`ElementTree.write` method serves this purpose. + +Once created, an :class:`Element` object may be manipulated by directly changing +its fields (such as :attr:`Element.text`), adding and modifying attributes +(:meth:`Element.set` method), as well as adding new children (for example +with :meth:`Element.append`). + +Let's say we want to add one to each country's rank, and add an ``updated`` +attribute to the rank element:: + + >>> for rank in root.iter('rank'): + ... new_rank = int(rank.text) + 1 + ... rank.text = str(new_rank) + ... rank.set('updated', 'yes') + ... + >>> tree.write('output.xml') + +Our XML now looks like this: + +.. code-block:: xml + + + + + 2 + 2008 + 141100 + + + + + 5 + 2011 + 59900 + + + + 69 + 2011 + 13600 + + + + + +We can remove elements using :meth:`Element.remove`. Let's say we want to +remove all countries with a rank higher than 50:: + + >>> for country in root.findall('country'): + ... rank = int(country.find('rank').text) + ... if rank > 50: + ... root.remove(country) + ... + >>> tree.write('output.xml') + +Our XML now looks like this: + +.. code-block:: xml + + + + + 2 + 2008 + 141100 + + + + + 5 + 2011 + 59900 + + + + +Building XML documents +^^^^^^^^^^^^^^^^^^^^^^ + +The :func:`SubElement` function also provides a convenient way to create new +sub-elements for a given element:: + + >>> a = ET.Element('a') + >>> b = ET.SubElement(a, 'b') + >>> c = ET.SubElement(a, 'c') + >>> d = ET.SubElement(c, 'd') + >>> ET.dump(a) + + +Additional resources +^^^^^^^^^^^^^^^^^^^^ + +See http://effbot.org/zone/element-index.htm for tutorials and links to other +docs. + +.. _elementtree-xpath: + +XPath support +------------- + +This module provides limited support for +`XPath expressions `_ for locating elements in a +tree. The goal is to support a small subset of the abbreviated syntax; a full +XPath engine is outside the scope of the module. + +Example +^^^^^^^ + +Here's an example that demonstrates some of the XPath capabilities of the +module. We'll be using the ``countrydata`` XML document from the +:ref:`Parsing XML ` section:: + + import xml.etree.ElementTree as ET + + root = ET.fromstring(countrydata) + + # Top-level elements + root.findall(".") + + # All 'neighbor' grand-children of 'country' children of the top-level + # elements + root.findall("./country/neighbor") + + # Nodes with name='Singapore' that have a 'year' child + root.findall(".//year/..[@name='Singapore']") + + # 'year' nodes that are children of nodes with name='Singapore' + root.findall(".//*[@name='Singapore']/year") + + # All 'neighbor' nodes that are the second child of their parent + root.findall(".//neighbor[2]") + +Supported XPath syntax +^^^^^^^^^^^^^^^^^^^^^^ + ++-----------------------+------------------------------------------------------+ +| Syntax | Meaning | ++=======================+======================================================+ +| ``tag`` | Selects all child elements with the given tag. | +| | For example, ``spam`` selects all child elements | +| | named ``spam``, ``spam/egg`` selects all | +| | grandchildren named ``egg`` in all children named | +| | ``spam``. | ++-----------------------+------------------------------------------------------+ +| ``*`` | Selects all child elements. For example, ``*/egg`` | +| | selects all grandchildren named ``egg``. | ++-----------------------+------------------------------------------------------+ +| ``.`` | Selects the current node. This is mostly useful | +| | at the beginning of the path, to indicate that it's | +| | a relative path. | ++-----------------------+------------------------------------------------------+ +| ``//`` | Selects all subelements, on all levels beneath the | +| | current element. For example, ``.//egg`` selects | +| | all ``egg`` elements in the entire tree. | ++-----------------------+------------------------------------------------------+ +| ``..`` | Selects the parent element. | ++-----------------------+------------------------------------------------------+ +| ``[@attrib]`` | Selects all elements that have the given attribute. | ++-----------------------+------------------------------------------------------+ +| ``[@attrib='value']`` | Selects all elements for which the given attribute | +| | has the given value. The value cannot contain | +| | quotes. | ++-----------------------+------------------------------------------------------+ +| ``[tag]`` | Selects all elements that have a child named | +| | ``tag``. Only immediate children are supported. | ++-----------------------+------------------------------------------------------+ +| ``[position]`` | Selects all elements that are located at the given | +| | position. The position can be either an integer | +| | (1 is the first position), the expression ``last()`` | +| | (for the last position), or a position relative to | +| | the last position (e.g. ``last()-1``). | ++-----------------------+------------------------------------------------------+ + +Predicates (expressions within square brackets) must be preceded by a tag +name, an asterisk, or another predicate. ``position`` predicates must be +preceded by a tag name. + +Reference +--------- .. _elementtree-functions: Functions ---------- +^^^^^^^^^ .. function:: Comment(text=None) @@ -196,8 +498,7 @@ .. _elementtree-element-objects: Element Objects ---------------- - +^^^^^^^^^^^^^^^ .. class:: Element(tag, attrib={}, **extra) @@ -387,7 +688,7 @@ .. _elementtree-elementtree-objects: ElementTree Objects -------------------- +^^^^^^^^^^^^^^^^^^^ .. class:: ElementTree(element=None, file=None) @@ -507,7 +808,7 @@ .. _elementtree-qname-objects: QName Objects -------------- +^^^^^^^^^^^^^ .. class:: QName(text_or_uri, tag=None) @@ -523,7 +824,7 @@ .. _elementtree-treebuilder-objects: TreeBuilder Objects -------------------- +^^^^^^^^^^^^^^^^^^^ .. class:: TreeBuilder(element_factory=None) @@ -574,7 +875,7 @@ .. _elementtree-xmlparser-objects: XMLParser Objects ------------------ +^^^^^^^^^^^^^^^^^ .. class:: XMLParser(html=0, target=None, encoding=None) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 04:43:24 2012 From: python-checkins at python.org (eli.bendersky) Date: Sat, 18 Aug 2012 04:43:24 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315586=3A_fix_prom?= =?utf-8?q?pts_in_some_documentation_examples?= Message-ID: <3WzQZN368TzQ1g@mail.python.org> http://hg.python.org/cpython/rev/7012f6a74f66 changeset: 78636:7012f6a74f66 parent: 78634:a343fa692bb0 user: Eli Bendersky date: Sat Aug 18 05:42:22 2012 +0300 summary: Issue #15586: fix prompts in some documentation examples files: Doc/library/xml.etree.elementtree.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -150,7 +150,7 @@ ... rank.text = str(new_rank) ... rank.set('updated', 'yes') ... - ... tree.write('output.xml') + >>> tree.write('output.xml') Our XML now looks like this: @@ -188,7 +188,7 @@ ... if rank > 50: ... root.remove(country) ... - ... tree.write('output.xml') + >>> tree.write('output.xml') Our XML now looks like this: -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sat Aug 18 06:11:03 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 18 Aug 2012 06:11:03 +0200 Subject: [Python-checkins] Daily reference leaks (a343fa692bb0): sum=0 Message-ID: results for a343fa692bb0 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogTd4fma', '-x'] From python-checkins at python.org Sat Aug 18 08:51:36 2012 From: python-checkins at python.org (eli.bendersky) Date: Sat, 18 Aug 2012 08:51:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_tutorial_typo_?= =?utf-8?q?fix?= Message-ID: <3WzX4m0nhYzPtn@mail.python.org> http://hg.python.org/cpython/rev/826b4d06b4f3 changeset: 78637:826b4d06b4f3 branch: 3.2 parent: 78633:ca5b36754892 user: Eli Bendersky date: Sat Aug 18 09:50:09 2012 +0300 summary: tutorial typo fix files: Doc/tutorial/controlflow.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -195,7 +195,7 @@ iteration of the loop:: >>> for num in range(2, 10): - ... if x % 2 == 0: + ... if num % 2 == 0: ... print("Found an even number", num) ... continue ... print("Found a number", num) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 08:51:39 2012 From: python-checkins at python.org (eli.bendersky) Date: Sat, 18 Aug 2012 08:51:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_3=2E2=3A_tutorial_typo_fix?= Message-ID: <3WzX4q07mtzQ8v@mail.python.org> http://hg.python.org/cpython/rev/3fba718e46e5 changeset: 78638:3fba718e46e5 parent: 78636:7012f6a74f66 parent: 78637:826b4d06b4f3 user: Eli Bendersky date: Sat Aug 18 09:50:32 2012 +0300 summary: Merge 3.2: tutorial typo fix files: Doc/tutorial/controlflow.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -195,7 +195,7 @@ iteration of the loop:: >>> for num in range(2, 10): - ... if x % 2 == 0: + ... if num % 2 == 0: ... print("Found an even number", num) ... continue ... print("Found a number", num) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 08:52:38 2012 From: python-checkins at python.org (eli.bendersky) Date: Sat, 18 Aug 2012 08:52:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_typo_in_tu?= =?utf-8?q?torial?= Message-ID: <3WzX5y1rqTzPyL@mail.python.org> http://hg.python.org/cpython/rev/332566c29ab4 changeset: 78639:332566c29ab4 branch: 2.7 parent: 78635:094423a65a4e user: Eli Bendersky date: Sat Aug 18 09:51:37 2012 +0300 summary: Fix typo in tutorial files: Doc/tutorial/controlflow.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -167,7 +167,7 @@ iteration of the loop:: >>> for num in range(2, 10): - ... if x % 2 == 0: + ... if num % 2 == 0: ... print("Found an even number", num) ... continue ... print("Found a number", num) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 13:24:52 2012 From: python-checkins at python.org (mark.dickinson) Date: Sat, 18 Aug 2012 13:24:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NDc3?= =?utf-8?q?=3A_Add_workaround_for_log1p=28-0=2E0=29_on_platforms_where_it?= =?utf-8?q?=27s_broken=2E?= Message-ID: <3Wzf840Wp5zQ7n@mail.python.org> http://hg.python.org/cpython/rev/08418369da7b changeset: 78640:08418369da7b branch: 3.2 parent: 78637:826b4d06b4f3 user: Mark Dickinson date: Sat Aug 18 12:24:30 2012 +0100 summary: Issue #15477: Add workaround for log1p(-0.0) on platforms where it's broken. files: Lib/test/test_cmath.py | 4 ---- Misc/NEWS | 3 +++ Modules/_math.c | 23 +++++++++++++++++++++++ Modules/_math.h | 8 ++------ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -519,15 +519,11 @@ # of zero, then atan and atanh will also have difficulties with # the sign of complex zeros. @requires_IEEE_754 - @unittest.skipIf(sysconfig.get_config_var('LOG1P_DROPS_ZERO_SIGN'), - "system log1p() function doesn't preserve the sign") def testAtanSign(self): for z in complex_zeros: self.assertComplexIdentical(cmath.atan(z), z) @requires_IEEE_754 - @unittest.skipIf(sysconfig.get_config_var('LOG1P_DROPS_ZERO_SIGN'), - "system log1p() function doesn't preserve the sign") def testAtanhSign(self): for z in complex_zeros: self.assertComplexIdentical(cmath.atanh(z), z) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,9 @@ Library ------- +- Issue #15477: In cmath and math modules, add workaround for platforms whose + system-supplied log1p function doesn't respect signs of zeros. + - Issue #11062: Fix adding a message from file to Babyl mailbox. - Issue #15646: Prevent equivalent of a fork bomb when using diff --git a/Modules/_math.c b/Modules/_math.c --- a/Modules/_math.c +++ b/Modules/_math.c @@ -189,6 +189,27 @@ significant loss of precision that arises from direct evaluation when x is small. */ +#ifdef HAVE_LOG1P + +double +_Py_log1p(double x) +{ + /* Some platforms supply a log1p function but don't respect the sign of + zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0. + + To save fiddling with configure tests and platform checks, we handle the + special case of zero input directly on all platforms. + */ + if (x == 0.0) { + return x; + } + else { + return log1p(x); + } +} + +#else + double _Py_log1p(double x) { @@ -230,3 +251,5 @@ return log(1.+x); } } + +#endif /* ifdef HAVE_LOG1P */ diff --git a/Modules/_math.h b/Modules/_math.h --- a/Modules/_math.h +++ b/Modules/_math.h @@ -36,10 +36,6 @@ #define m_expm1 _Py_expm1 #endif -#ifdef HAVE_LOG1P -#define m_log1p log1p -#else -/* if the system doesn't have log1p, use the substitute - function defined in Modules/_math.c. */ +/* Use the substitute from _math.c on all platforms: + it includes workarounds for buggy handling of zeros. */ #define m_log1p _Py_log1p -#endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 13:26:25 2012 From: python-checkins at python.org (mark.dickinson) Date: Sat, 18 Aug 2012 13:26:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315477=3A_Merge_fix_from_3=2E2?= Message-ID: <3Wzf9s1ZCfzPsl@mail.python.org> http://hg.python.org/cpython/rev/336653319112 changeset: 78641:336653319112 parent: 78638:3fba718e46e5 parent: 78640:08418369da7b user: Mark Dickinson date: Sat Aug 18 12:26:15 2012 +0100 summary: Issue #15477: Merge fix from 3.2 files: Lib/test/test_cmath.py | 4 ---- Misc/NEWS | 3 +++ Modules/_math.c | 23 +++++++++++++++++++++++ Modules/_math.h | 8 ++------ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -519,15 +519,11 @@ # of zero, then atan and atanh will also have difficulties with # the sign of complex zeros. @requires_IEEE_754 - @unittest.skipIf(sysconfig.get_config_var('LOG1P_DROPS_ZERO_SIGN'), - "system log1p() function doesn't preserve the sign") def testAtanSign(self): for z in complex_zeros: self.assertComplexIdentical(cmath.atan(z), z) @requires_IEEE_754 - @unittest.skipIf(sysconfig.get_config_var('LOG1P_DROPS_ZERO_SIGN'), - "system log1p() function doesn't preserve the sign") def testAtanhSign(self): for z in complex_zeros: self.assertComplexIdentical(cmath.atanh(z), z) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Library ------- +- Issue #15477: In cmath and math modules, add workaround for platforms whose + system-supplied log1p function doesn't respect signs of zeros. + - Issue #15715: importlib.__import__() will silence an ImportError when the use of fromlist leads to a failed import. diff --git a/Modules/_math.c b/Modules/_math.c --- a/Modules/_math.c +++ b/Modules/_math.c @@ -189,6 +189,27 @@ significant loss of precision that arises from direct evaluation when x is small. */ +#ifdef HAVE_LOG1P + +double +_Py_log1p(double x) +{ + /* Some platforms supply a log1p function but don't respect the sign of + zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0. + + To save fiddling with configure tests and platform checks, we handle the + special case of zero input directly on all platforms. + */ + if (x == 0.0) { + return x; + } + else { + return log1p(x); + } +} + +#else + double _Py_log1p(double x) { @@ -230,3 +251,5 @@ return log(1.+x); } } + +#endif /* ifdef HAVE_LOG1P */ diff --git a/Modules/_math.h b/Modules/_math.h --- a/Modules/_math.h +++ b/Modules/_math.h @@ -36,10 +36,6 @@ #define m_expm1 _Py_expm1 #endif -#ifdef HAVE_LOG1P -#define m_log1p log1p -#else -/* if the system doesn't have log1p, use the substitute - function defined in Modules/_math.c. */ +/* Use the substitute from _math.c on all platforms: + it includes workarounds for buggy handling of zeros. */ #define m_log1p _Py_log1p -#endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 13:31:43 2012 From: python-checkins at python.org (mark.dickinson) Date: Sat, 18 Aug 2012 13:31:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Add_workaround?= =?utf-8?q?_for_log1p=28-0=2E0=29_on_platforms_where_it=27s_broken=2E?= Message-ID: <3WzfHz6N8VzQ69@mail.python.org> http://hg.python.org/cpython/rev/377036cb13e9 changeset: 78642:377036cb13e9 branch: 2.7 parent: 78639:332566c29ab4 user: Mark Dickinson date: Sat Aug 18 12:31:34 2012 +0100 summary: Add workaround for log1p(-0.0) on platforms where it's broken. files: Misc/NEWS | 3 +++ Modules/_math.c | 23 +++++++++++++++++++++++ Modules/_math.h | 8 ++------ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -95,6 +95,9 @@ Library ------- +- Issue #15477: In cmath and math modules, add workaround for platforms whose + system-supplied log1p function doesn't respect signs of zeros. + - Issue #11062: Fix adding a message from file to Babyl mailbox. - Issue #15646: Prevent equivalent of a fork bomb when using diff --git a/Modules/_math.c b/Modules/_math.c --- a/Modules/_math.c +++ b/Modules/_math.c @@ -189,6 +189,27 @@ significant loss of precision that arises from direct evaluation when x is small. */ +#ifdef HAVE_LOG1P + +double +_Py_log1p(double x) +{ + /* Some platforms supply a log1p function but don't respect the sign of + zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0. + + To save fiddling with configure tests and platform checks, we handle the + special case of zero input directly on all platforms. + */ + if (x == 0.0) { + return x; + } + else { + return log1p(x); + } +} + +#else + double _Py_log1p(double x) { @@ -230,3 +251,5 @@ return log(1.+x); } } + +#endif /* ifdef HAVE_LOG1P */ diff --git a/Modules/_math.h b/Modules/_math.h --- a/Modules/_math.h +++ b/Modules/_math.h @@ -36,10 +36,6 @@ #define m_expm1 _Py_expm1 #endif -#ifdef HAVE_LOG1P -#define m_log1p log1p -#else -/* if the system doesn't have log1p, use the substitute - function defined in Modules/_math.c. */ +/* Use the substitute from _math.c on all platforms: + it includes workarounds for buggy handling of zeros. */ #define m_log1p _Py_log1p -#endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 20:54:20 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 18 Aug 2012 20:54:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NjE1?= =?utf-8?q?=3A_Add_some_tests_for_the_json_module=27s_handling_of_invalid_?= =?utf-8?q?input?= Message-ID: <3Wzr6h5Jd3zQHK@mail.python.org> http://hg.python.org/cpython/rev/cd9a4883dd02 changeset: 78643:cd9a4883dd02 branch: 3.2 parent: 78640:08418369da7b user: Antoine Pitrou date: Sat Aug 18 20:46:23 2012 +0200 summary: Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. files: Lib/test/json_tests/test_decode.py | 9 +++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 13 insertions(+), 0 deletions(-) diff --git a/Lib/test/json_tests/test_decode.py b/Lib/test/json_tests/test_decode.py --- a/Lib/test/json_tests/test_decode.py +++ b/Lib/test/json_tests/test_decode.py @@ -54,6 +54,15 @@ self.check_keys_reuse(s, self.loads) self.check_keys_reuse(s, self.json.decoder.JSONDecoder().decode) + def test_extra_data(self): + s = '[1, 2, 3]5' + msg = 'Extra data' + self.assertRaisesRegexp(ValueError, msg, self.loads, s) + + def test_invalid_escape(self): + s = '["abc\\y"]' + msg = 'escape' + self.assertRaisesRegexp(ValueError, msg, self.loads, s) class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -218,6 +218,7 @@ Eric Daniel Scott David Daniels Ben Darnell +Kushal Das Jonathan Dasteel John DeGood Ned Deily diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -425,6 +425,9 @@ Tests ----- +- Issue #15615: Add some tests for the json module's handling of invalid + input data. Patch by Kushal Das. + - Issue #15496: Add directory removal helpers for tests on Windows. Patch by Jeremy Kloth. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 20:54:22 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 18 Aug 2012 20:54:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315615=3A_Add_some_tests_for_the_json_module=27s?= =?utf-8?q?_handling_of_invalid_input?= Message-ID: <3Wzr6k3PSbzQHV@mail.python.org> http://hg.python.org/cpython/rev/01717c3da4fb changeset: 78644:01717c3da4fb parent: 78641:336653319112 parent: 78643:cd9a4883dd02 user: Antoine Pitrou date: Sat Aug 18 20:48:17 2012 +0200 summary: Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. files: Lib/test/json_tests/test_decode.py | 9 +++++++++ Misc/ACKS | 1 + Misc/NEWS | 5 +++++ 3 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Lib/test/json_tests/test_decode.py b/Lib/test/json_tests/test_decode.py --- a/Lib/test/json_tests/test_decode.py +++ b/Lib/test/json_tests/test_decode.py @@ -54,6 +54,15 @@ self.check_keys_reuse(s, self.loads) self.check_keys_reuse(s, self.json.decoder.JSONDecoder().decode) + def test_extra_data(self): + s = '[1, 2, 3]5' + msg = 'Extra data' + self.assertRaisesRegexp(ValueError, msg, self.loads, s) + + def test_invalid_escape(self): + s = '["abc\\y"]' + msg = 'escape' + self.assertRaisesRegexp(ValueError, msg, self.loads, s) class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -238,6 +238,7 @@ Eric Daniel Scott David Daniels Ben Darnell +Kushal Das Jonathan Dasteel Pierre-Yves David Xavier de Gaye diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -52,6 +52,11 @@ - Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by Daniel Ellis. +Tests +----- + +- Issue #15615: Add some tests for the json module's handling of invalid + input data. Patch by Kushal Das. What's New in Python 3.3.0 Beta 2? -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 20:54:23 2012 From: python-checkins at python.org (antoine.pitrou) Date: Sat, 18 Aug 2012 20:54:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NjE1?= =?utf-8?q?=3A_Add_some_tests_for_the_json_module=27s_handling_of_invalid_?= =?utf-8?q?input?= Message-ID: <3Wzr6l6G4kzQHR@mail.python.org> http://hg.python.org/cpython/rev/b16a5f0d0c87 changeset: 78645:b16a5f0d0c87 branch: 2.7 parent: 78642:377036cb13e9 user: Antoine Pitrou date: Sat Aug 18 20:51:05 2012 +0200 summary: Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. files: Lib/json/tests/test_decode.py | 9 +++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 13 insertions(+), 0 deletions(-) diff --git a/Lib/json/tests/test_decode.py b/Lib/json/tests/test_decode.py --- a/Lib/json/tests/test_decode.py +++ b/Lib/json/tests/test_decode.py @@ -45,6 +45,15 @@ object_hook=lambda x: None), OrderedDict(p)) + def test_extra_data(self): + s = '[1, 2, 3]5' + msg = 'Extra data' + self.assertRaisesRegexp(ValueError, msg, self.loads, s) + + def test_invalid_escape(self): + s = '["abc\\y"]' + msg = 'escape' + self.assertRaisesRegexp(ValueError, msg, self.loads, s) class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -194,6 +194,7 @@ Eric Daniel Scott David Daniels Ben Darnell +Kushal Das Jonathan Dasteel John DeGood Ned Deily diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -335,6 +335,9 @@ Tests ----- +- Issue #15615: Add some tests for the json module's handling of invalid + input data. Patch by Kushal Das. + - Issue #15496: Add directory removal helpers for tests on Windows. Patch by Jeremy Kloth. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 21:25:41 2012 From: python-checkins at python.org (ned.deily) Date: Sat, 18 Aug 2012 21:25:41 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Allow_redemo?= =?utf-8?q?=2Epy_to_be_used_from_the_command_line_like_other_demos=2E?= Message-ID: <3Wzrps5lvrzQHp@mail.python.org> http://hg.python.org/cpython/rev/a225a27b0860 changeset: 78646:a225a27b0860 branch: 3.2 parent: 78643:cd9a4883dd02 user: Ned Deily date: Sat Aug 18 12:21:17 2012 -0700 summary: Allow redemo.py to be used from the command line like other demos. files: Tools/demo/redemo.py | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Tools/demo/redemo.py b/Tools/demo/redemo.py old mode 100644 new mode 100755 --- a/Tools/demo/redemo.py +++ b/Tools/demo/redemo.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + """Basic regular expression demostration facility (Perl style syntax).""" from tkinter import * -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 18 21:25:43 2012 From: python-checkins at python.org (ned.deily) Date: Sat, 18 Aug 2012 21:25:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Allow_redemo=2Epy_to_be_used_from_the_command_line_like_?= =?utf-8?q?other_demos=2E?= Message-ID: <3Wzrpv3JkyzQHj@mail.python.org> http://hg.python.org/cpython/rev/d693f961c5ff changeset: 78647:d693f961c5ff parent: 78644:01717c3da4fb parent: 78646:a225a27b0860 user: Ned Deily date: Sat Aug 18 12:24:56 2012 -0700 summary: Allow redemo.py to be used from the command line like other demos. files: Tools/demo/redemo.py | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Tools/demo/redemo.py b/Tools/demo/redemo.py old mode 100644 new mode 100755 --- a/Tools/demo/redemo.py +++ b/Tools/demo/redemo.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + """Basic regular expression demostration facility (Perl style syntax).""" from tkinter import * -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sun Aug 19 06:11:07 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 19 Aug 2012 06:11:07 +0200 Subject: [Python-checkins] Daily reference leaks (d693f961c5ff): sum=0 Message-ID: results for d693f961c5ff on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogaQIEge', '-x'] From python-checkins at python.org Sun Aug 19 11:27:22 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 19 Aug 2012 11:27:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Check_for_NULL?= =?utf-8?q?_return_value_in_PyStructSequence=5FNewType=28=29=2E_Found_by_C?= =?utf-8?q?overity=2E?= Message-ID: <3X0CV24BHzzQGc@mail.python.org> http://hg.python.org/cpython/rev/f5e0561e9aa9 changeset: 78648:f5e0561e9aa9 branch: 3.2 parent: 78646:a225a27b0860 user: Stefan Krah date: Sun Aug 19 11:20:41 2012 +0200 summary: Check for NULL return value in PyStructSequence_NewType(). Found by Coverity. files: Objects/structseq.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Objects/structseq.c b/Objects/structseq.c --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -383,6 +383,8 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc) { PyTypeObject *result = (PyTypeObject*)PyType_GenericAlloc(&PyType_Type, 0); - PyStructSequence_InitType(result, desc); + if (result != NULL) { + PyStructSequence_InitType(result, desc); + } return result; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 11:27:54 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 19 Aug 2012 11:27:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZWcgMy4yLg==?= Message-ID: <3X0CVf2dZLzQP1@mail.python.org> http://hg.python.org/cpython/rev/040eb15bbb6e changeset: 78649:040eb15bbb6e parent: 78647:d693f961c5ff parent: 78648:f5e0561e9aa9 user: Stefan Krah date: Sun Aug 19 11:22:28 2012 +0200 summary: Mereg 3.2. files: Objects/structseq.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Objects/structseq.c b/Objects/structseq.c --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -383,6 +383,8 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc) { PyTypeObject *result = (PyTypeObject*)PyType_GenericAlloc(&PyType_Type, 0); - PyStructSequence_InitType(result, desc); + if (result != NULL) { + PyStructSequence_InitType(result, desc); + } return result; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 12:54:35 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 19 Aug 2012 12:54:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_out-of-date_comment_in?= =?utf-8?q?_test=5Fmemoryview=2E?= Message-ID: <3X0FQg2GpyzQ94@mail.python.org> http://hg.python.org/cpython/rev/ccaf827bbf4c changeset: 78650:ccaf827bbf4c user: Stefan Krah date: Sun Aug 19 12:50:24 2012 +0200 summary: Fix out-of-date comment in test_memoryview. files: Lib/test/test_memoryview.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_memoryview.py b/Lib/test/test_memoryview.py --- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -1,6 +1,7 @@ """Unit tests for the memoryview -XXX We need more tests! Some tests are in test_bytes + Some tests are in test_bytes. Many tests that require _testbuffer.ndarray + are in test_buffer. """ import unittest -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 12:59:25 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 19 Aug 2012 12:59:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_The_latest_NumPy_revision_?= =?utf-8?q?no_longer_segfaults_here=2E?= Message-ID: <3X0FXF2Pz8zQV0@mail.python.org> http://hg.python.org/cpython/rev/a31225651233 changeset: 78651:a31225651233 user: Stefan Krah date: Sun Aug 19 12:54:50 2012 +0200 summary: The latest NumPy revision no longer segfaults here. files: Lib/test/test_buffer.py | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -1848,9 +1848,6 @@ self.assertEqual(mvlist, ylist) if numpy_array: - # XXX NumPy (as far as it compiles with 3.3) currently - # segfaults here. Wait for a stable 3.3 compatible version. - continue shape = t[3] if 0 in shape: continue # http://projects.scipy.org/numpy/ticket/1910 @@ -1930,9 +1927,6 @@ self.assertEqual(mr.tolist(), yrlist) if numpy_array: - # XXX NumPy (as far as it compiles with 3.3) currently - # segfaults here. Wait for a stable 3.3 compatible version. - continue if 0 in lshape or 0 in rshape: continue # http://projects.scipy.org/numpy/ticket/1910 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 15:25:47 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 19 Aug 2012 15:25:47 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Brush_subprocess_tests_a_b?= =?utf-8?b?aXQu?= Message-ID: <3X0Jn76lXZzQN4@mail.python.org> http://hg.python.org/cpython/rev/53fc878cc7b3 changeset: 78652:53fc878cc7b3 user: Andrew Svetlov date: Sun Aug 19 16:25:37 2012 +0300 summary: Brush subprocess tests a bit. files: Lib/test/test_subprocess.py | 41 ++++++++++++------------ 1 files changed, 21 insertions(+), 20 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 @@ -14,6 +14,7 @@ import select import shutil import gc +import textwrap try: import resource @@ -622,12 +623,12 @@ def test_universal_newlines_communicate_stdin(self): # universal newlines through communicate(), with only stdin p = subprocess.Popen([sys.executable, "-c", - 'import sys,os;' + SETBINARY + '''\nif True: - s = sys.stdin.readline() - assert s == "line1\\n", repr(s) - s = sys.stdin.read() - assert s == "line3\\n", repr(s) - '''], + 'import sys,os;' + SETBINARY + textwrap.dedent(''' + s = sys.stdin.readline() + assert s == "line1\\n", repr(s) + s = sys.stdin.read() + assert s == "line3\\n", repr(s) + ''')], stdin=subprocess.PIPE, universal_newlines=1) (stdout, stderr) = p.communicate("line1\nline3\n") @@ -646,24 +647,24 @@ self.assertEqual(p.returncode, 0) def test_universal_newlines_communicate_stdin_stdout_stderr(self): - # universal newlines through communicate(), with only stdin + # universal newlines through communicate(), with stdin, stdout, stderr p = subprocess.Popen([sys.executable, "-c", - 'import sys,os;' + SETBINARY + '''\nif True: - s = sys.stdin.readline() - sys.stdout.buffer.write(s.encode()) - sys.stdout.buffer.write(b"line2\\r") - sys.stderr.buffer.write(b"eline2\\n") - s = sys.stdin.read() - sys.stdout.buffer.write(s.encode()) - sys.stdout.buffer.write(b"line4\\n") - sys.stdout.buffer.write(b"line5\\r\\n") - sys.stderr.buffer.write(b"eline6\\r") - sys.stderr.buffer.write(b"eline7\\r\\nz") - '''], + 'import sys,os;' + SETBINARY + textwrap.dedent(''' + s = sys.stdin.buffer.readline() + sys.stdout.buffer.write(s) + sys.stdout.buffer.write(b"line2\\r") + sys.stderr.buffer.write(b"eline2\\n") + s = sys.stdin.buffer.read() + sys.stdout.buffer.write(s) + sys.stdout.buffer.write(b"line4\\n") + sys.stdout.buffer.write(b"line5\\r\\n") + sys.stderr.buffer.write(b"eline6\\r") + sys.stderr.buffer.write(b"eline7\\r\\nz") + ''')], stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, - universal_newlines=1) + universal_newlines=True) self.addCleanup(p.stdout.close) self.addCleanup(p.stderr.close) (stdout, stderr) = p.communicate("line1\nline3\n") -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 18:22:30 2012 From: python-checkins at python.org (brian.curtin) Date: Sun, 19 Aug 2012 18:22:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fixes_=2314668=2E_Mention_?= =?utf-8?q?Windows_Path_manipulation_option_in_the_installer=2E?= Message-ID: <3X0Nj21zVWzQMm@mail.python.org> http://hg.python.org/cpython/rev/b07a408b0291 changeset: 78653:b07a408b0291 user: Brian Curtin date: Sun Aug 19 11:22:20 2012 -0500 summary: Fixes #14668. Mention Windows Path manipulation option in the installer. files: Doc/using/windows.rst | 30 +++++++++++++++++++++--------- 1 files changed, 21 insertions(+), 9 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 --------------------------------------- @@ -133,18 +135,28 @@ Finding the Python executable ----------------------------- +.. versionchanged:: 3.3 + Besides using the automatically created start menu entry for the Python -interpreter, you might want to start Python in the DOS prompt. To make this -work, you need to set your :envvar:`%PATH%` environment variable to include the -directory of your Python distribution, delimited by a semicolon from other -entries. An example variable could look like this (assuming the first two -entries are Windows' default):: +interpreter, you might want to start Python in the command prompt. As of +Python 3.3, the installer has an option to set that up for you. - C:\WINDOWS\system32;C:\WINDOWS;C:\Python25 +At the "Customize Python 3.3" screen, an option called +"Add python.exe to search path" can be enabled to have the installer place +your installation into the :envvar:`%PATH%`. This allows you to type +:command:`python` to run the interpreter. Thus, you can also execute your +scripts with command line options, see :ref:`using-on-cmdline` documentation. -Typing :command:`python` on your command prompt will now fire up the Python -interpreter. Thus, you can also execute your scripts with command line options, -see :ref:`using-on-cmdline` documentation. +If you don't enable this option at install time, you can always re-run the +installer to choose it. + +The alternative is manually modifying the :envvar:`%PATH%` using the +directions in :ref:`setting-envvars`. You need to set your :envvar:`%PATH%` +environment variable to include the directory of your Python distribution, +delimited by a semicolon from other entries. An example variable could look +like this (assuming the first two entries are Windows' default):: + + C:\WINDOWS\system32;C:\WINDOWS;C:\Python33 Finding modules -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 19:49:49 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 19 Aug 2012 19:49:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Use_Thread=2Eis=5Falive=28?= =?utf-8?q?=29_instead_of_old-style_Thread=2EisAlive=28=29_in_subprocess?= =?utf-8?q?=2E?= Message-ID: <3X0Qdn3mNwzQKm@mail.python.org> http://hg.python.org/cpython/rev/882da270d21a changeset: 78654:882da270d21a user: Andrew Svetlov date: Sun Aug 19 20:49:39 2012 +0300 summary: Use Thread.is_alive() instead of old-style Thread.isAlive() in subprocess. 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 @@ -1188,11 +1188,11 @@ # calls communicate again. if self.stdout is not None: self.stdout_thread.join(self._remaining_time(endtime)) - if self.stdout_thread.isAlive(): + if self.stdout_thread.is_alive(): raise TimeoutExpired(self.args, orig_timeout) if self.stderr is not None: self.stderr_thread.join(self._remaining_time(endtime)) - if self.stderr_thread.isAlive(): + if self.stderr_thread.is_alive(): raise TimeoutExpired(self.args, orig_timeout) # Collect the output from and close both pipes, now that we know -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 21:20:17 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 19 Aug 2012 21:20:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NTk1?= =?utf-8?q?=3A_Fix_subprocess=2EPopen=28universal=5Fnewlines=3DTrue=29?= Message-ID: <3X0Sf90TJHzQ2q@mail.python.org> http://hg.python.org/cpython/rev/a0f7c2f79bce changeset: 78655:a0f7c2f79bce branch: 3.2 parent: 78648:f5e0561e9aa9 user: Andrew Svetlov date: Sun Aug 19 22:13:41 2012 +0300 summary: Issue #15595: Fix subprocess.Popen(universal_newlines=True) for certain locales (utf-16 and utf-32 family). Patch by Chris Jerdonek. files: Lib/subprocess.py | 4 +- Lib/test/test_subprocess.py | 33 +++++++++++++++++++++++++ Misc/NEWS | 3 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -755,8 +755,8 @@ def _translate_newlines(self, data, encoding): - data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n") - return data.decode(encoding) + data = data.decode(encoding) + return data.replace("\r\n", "\n").replace("\r", "\n") def __enter__(self): return self 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 @@ -4,6 +4,7 @@ import sys import signal import io +import locale import os import errno import tempfile @@ -560,6 +561,38 @@ p.communicate() self.assertEqual(p.returncode, 0) + def test_universal_newlines_communicate_encodings(self): + # Check that universal newlines mode works for various encodings, + # in particular for encodings in the UTF-16 and UTF-32 families. + # See issue #15595. + # + # UTF-16 and UTF-32-BE are sufficient to check both with BOM and + # without, and UTF-16 and UTF-32. + for encoding in ['utf-16', 'utf-32-be']: + old_getpreferredencoding = locale.getpreferredencoding + # Indirectly via io.TextIOWrapper, Popen() defaults to + # locale.getpreferredencoding(False) and earlier in Python 3.2 to + # locale.getpreferredencoding(). + def getpreferredencoding(do_setlocale=True): + return encoding + code = ("import sys; " + r"sys.stdout.buffer.write('1\r\n2\r3\n4'.encode('%s'))" % + encoding) + args = [sys.executable, '-c', code] + try: + locale.getpreferredencoding = getpreferredencoding + # We set stdin to be non-None because, as of this writing, + # a different code path is used when the number of pipes is + # zero or one. + popen = subprocess.Popen(args, universal_newlines=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + stdout, stderr = popen.communicate(input='') + finally: + locale.getpreferredencoding = old_getpreferredencoding + + self.assertEqual(stdout, '1\n2\n3\n4') + def test_no_leaking(self): # Make sure we leak no resources if not mswindows: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,9 @@ Library ------- +- Issue #15595: Fix subprocess.Popen(universal_newlines=True) + for certain locales (utf-16 and utf-32 family). Patch by Chris Jerdonek. + - Issue #15477: In cmath and math modules, add workaround for platforms whose system-supplied log1p function doesn't respect signs of zeros. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 21:20:48 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sun, 19 Aug 2012 21:20:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315595=3A_Fix_subprocess=2EPopen=28universal=5Fn?= =?utf-8?q?ewlines=3DTrue=29?= Message-ID: <3X0Sfm3xfJzQ4K@mail.python.org> http://hg.python.org/cpython/rev/aceb820154c3 changeset: 78656:aceb820154c3 parent: 78654:882da270d21a parent: 78655:a0f7c2f79bce user: Andrew Svetlov date: Sun Aug 19 22:20:03 2012 +0300 summary: Issue #15595: Fix subprocess.Popen(universal_newlines=True) for certain locales (utf-16 and utf-32 family). Patch by Chris Jerdonek. files: Lib/subprocess.py | 4 +- Lib/test/test_subprocess.py | 32 +++++++++++++++++++++++++ Misc/NEWS | 3 ++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -828,8 +828,8 @@ def _translate_newlines(self, data, encoding): - data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n") - return data.decode(encoding) + data = data.decode(encoding) + return data.replace("\r\n", "\n").replace("\r", "\n") def __enter__(self): return self 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 @@ -4,6 +4,7 @@ import sys import signal import io +import locale import os import errno import tempfile @@ -675,6 +676,37 @@ # Don't use assertStderrEqual because it strips CR and LF from output. self.assertTrue(stderr.startswith("eline2\neline6\neline7\n")) + def test_universal_newlines_communicate_encodings(self): + # Check that universal newlines mode works for various encodings, + # in particular for encodings in the UTF-16 and UTF-32 families. + # See issue #15595. + # + # UTF-16 and UTF-32-BE are sufficient to check both with BOM and + # without, and UTF-16 and UTF-32. + for encoding in ['utf-16', 'utf-32-be']: + old_getpreferredencoding = locale.getpreferredencoding + # Indirectly via io.TextIOWrapper, Popen() defaults to + # locale.getpreferredencoding(False) and earlier in Python 3.2 to + # locale.getpreferredencoding(). + def getpreferredencoding(do_setlocale=True): + return encoding + code = ("import sys; " + r"sys.stdout.buffer.write('1\r\n2\r3\n4'.encode('%s'))" % + encoding) + args = [sys.executable, '-c', code] + try: + locale.getpreferredencoding = getpreferredencoding + # We set stdin to be non-None because, as of this writing, + # a different code path is used when the number of pipes is + # zero or one. + popen = subprocess.Popen(args, universal_newlines=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + stdout, stderr = popen.communicate(input='') + finally: + locale.getpreferredencoding = old_getpreferredencoding + self.assertEqual(stdout, '1\n2\n3\n4') + def test_no_leaking(self): # Make sure we leak no resources if not mswindows: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Library ------- +- Issue #15595: Fix subprocess.Popen(universal_newlines=True) + for certain locales (utf-16 and utf-32 family). Patch by Chris Jerdonek. + - Issue #15477: In cmath and math modules, add workaround for platforms whose system-supplied log1p function doesn't respect signs of zeros. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 21:58:34 2012 From: python-checkins at python.org (stefan.krah) Date: Sun, 19 Aug 2012 21:58:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315728=3A_Fix_leak?= =?utf-8?q?_in_PyUnicode=5FAsWideCharString=28=29=2E_Found_by_Coverity=2E?= Message-ID: <3X0TVL5ppjzQLB@mail.python.org> http://hg.python.org/cpython/rev/2703171ddf53 changeset: 78657:2703171ddf53 user: Stefan Krah date: Sun Aug 19 21:52:43 2012 +0200 summary: Issue #15728: Fix leak in PyUnicode_AsWideCharString(). Found by Coverity. files: Objects/unicodeobject.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2935,8 +2935,10 @@ return NULL; } buflen = unicode_aswidechar(unicode, buffer, buflen); - if (buflen == -1) - return NULL; + if (buflen == -1) { + PyMem_FREE(buffer); + return NULL; + } if (size != NULL) *size = buflen; return buffer; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 23:59:09 2012 From: python-checkins at python.org (r.david.murray) Date: Sun, 19 Aug 2012 23:59:09 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzEzNTc5OiB0ZWFj?= =?utf-8?q?h_string=2EFormatter_about_=27a=27=2E?= Message-ID: <3X0X9T4JnSzQMb@mail.python.org> http://hg.python.org/cpython/rev/24b449a77e88 changeset: 78658:24b449a77e88 branch: 3.2 parent: 78655:a0f7c2f79bce user: R David Murray date: Sun Aug 19 17:26:34 2012 -0400 summary: #13579: teach string.Formatter about 'a'. Patch by Francisco Mart?n Brugu?. files: Doc/library/string.rst | 11 ++++++----- Lib/string.py | 10 ++++++---- Lib/test/test_string.py | 12 ++++++++++++ Misc/NEWS | 2 ++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -91,8 +91,8 @@ .. method:: format(format_string, *args, **kwargs) - :meth:`format` is the primary API method. It takes a format template - string, and an arbitrary set of positional and keyword argument. + :meth:`format` is the primary API method. It takes a format string and + an arbitrary set of positional and keyword arguments. :meth:`format` is just a wrapper that calls :meth:`vformat`. .. method:: vformat(format_string, args, kwargs) @@ -101,8 +101,8 @@ separate function for cases where you want to pass in a predefined dictionary of arguments, rather than unpacking and repacking the dictionary as individual arguments using the ``*args`` and ``**kwds`` - syntax. :meth:`vformat` does the work of breaking up the format template - string into character data and replacement fields. It calls the various + syntax. :meth:`vformat` does the work of breaking up the format string + into character data and replacement fields. It calls the various methods described below. In addition, the :class:`Formatter` defines a number of methods that are @@ -173,7 +173,8 @@ Converts the value (returned by :meth:`get_field`) given a conversion type (as in the tuple returned by the :meth:`parse` method). The default - version understands 'r' (repr) and 's' (str) conversion types. + version understands 's' (str), 'r' (repr) and 'a' (ascii) conversion + types. .. _formatstrings: diff --git a/Lib/string.py b/Lib/string.py --- a/Lib/string.py +++ b/Lib/string.py @@ -236,12 +236,14 @@ def convert_field(self, value, conversion): # do any conversion on the resulting object - if conversion == 'r': - return repr(value) + if conversion is None: + return value elif conversion == 's': return str(value) - elif conversion is None: - return value + elif conversion == 'r': + return repr(value) + elif conversion == 'a': + return ascii(value) raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -26,6 +26,18 @@ self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def') self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t') + def test_conversion_specifiers(self): + fmt = string.Formatter() + self.assertEqual(fmt.format("-{arg!r}-", arg='test'), "-'test'-") + self.assertEqual(fmt.format("{0!s}", 'test'), 'test') + self.assertRaises(ValueError, fmt.format, "{0!h}", 'test') + # issue13579 + self.assertEqual(fmt.format("{0!a}", 42), '42') + self.assertEqual(fmt.format("{0!a}", string.ascii_letters), + "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'") + self.assertEqual(fmt.format("{0!a}", chr(255)), "'\\xff'") + self.assertEqual(fmt.format("{0!a}", chr(256)), "'\\u0100'") + def test_formatter(self): fmt = string.Formatter() self.assertEqual(fmt.format("foo"), "foo") diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,8 @@ Library ------- +- Issue #13579: string.Formatter now understands the 'a' conversion specifier. + - Issue #15595: Fix subprocess.Popen(universal_newlines=True) for certain locales (utf-16 and utf-32 family). Patch by Chris Jerdonek. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sun Aug 19 23:59:41 2012 From: python-checkins at python.org (r.david.murray) Date: Sun, 19 Aug 2012 23:59:41 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2313579=3A_teach_string=2EFormatter_about_=27a=27?= =?utf-8?q?=2E?= Message-ID: <3X0XB523zFzQMv@mail.python.org> http://hg.python.org/cpython/rev/4feb10457c13 changeset: 78659:4feb10457c13 parent: 78657:2703171ddf53 parent: 78658:24b449a77e88 user: R David Murray date: Sun Aug 19 17:45:40 2012 -0400 summary: Merge #13579: teach string.Formatter about 'a'. Patch by Francisco Mart?n Brugu?. files: Doc/library/string.rst | 11 ++++++----- Lib/string.py | 10 ++++++---- Lib/test/test_string.py | 6 ++++++ Misc/NEWS | 2 ++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -91,8 +91,8 @@ .. method:: format(format_string, *args, **kwargs) - :meth:`format` is the primary API method. It takes a format template - string, and an arbitrary set of positional and keyword argument. + :meth:`format` is the primary API method. It takes a format string and + an arbitrary set of positional and keyword arguments. :meth:`format` is just a wrapper that calls :meth:`vformat`. .. method:: vformat(format_string, args, kwargs) @@ -101,8 +101,8 @@ separate function for cases where you want to pass in a predefined dictionary of arguments, rather than unpacking and repacking the dictionary as individual arguments using the ``*args`` and ``**kwds`` - syntax. :meth:`vformat` does the work of breaking up the format template - string into character data and replacement fields. It calls the various + syntax. :meth:`vformat` does the work of breaking up the format string + into character data and replacement fields. It calls the various methods described below. In addition, the :class:`Formatter` defines a number of methods that are @@ -173,7 +173,8 @@ Converts the value (returned by :meth:`get_field`) given a conversion type (as in the tuple returned by the :meth:`parse` method). The default - version understands 'r' (repr) and 's' (str) conversion types. + version understands 's' (str), 'r' (repr) and 'a' (ascii) conversion + types. .. _formatstrings: diff --git a/Lib/string.py b/Lib/string.py --- a/Lib/string.py +++ b/Lib/string.py @@ -220,12 +220,14 @@ def convert_field(self, value, conversion): # do any conversion on the resulting object - if conversion == 'r': - return repr(value) + if conversion is None: + return value elif conversion == 's': return str(value) - elif conversion is None: - return value + elif conversion == 'r': + return repr(value) + elif conversion == 'a': + return ascii(value) raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -37,6 +37,12 @@ self.assertEqual(fmt.format("-{arg!r}-", arg='test'), "-'test'-") self.assertEqual(fmt.format("{0!s}", 'test'), 'test') self.assertRaises(ValueError, fmt.format, "{0!h}", 'test') + # issue13579 + self.assertEqual(fmt.format("{0!a}", 42), '42') + self.assertEqual(fmt.format("{0!a}", string.ascii_letters), + "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'") + self.assertEqual(fmt.format("{0!a}", chr(255)), "'\\xff'") + self.assertEqual(fmt.format("{0!a}", chr(256)), "'\\u0100'") def test_name_lookup(self): fmt = string.Formatter() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,8 @@ Library ------- +- Issue #13579: string.Formatter now understands the 'a' conversion specifier. + - Issue #15595: Fix subprocess.Popen(universal_newlines=True) for certain locales (utf-16 and utf-32 family). Patch by Chris Jerdonek. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 00:00:12 2012 From: python-checkins at python.org (r.david.murray) Date: Mon, 20 Aug 2012 00:00:12 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzEzNTc5OiBtaW5p?= =?utf-8?q?mize_code_base_drift_for_=27a=27_string=2EFormatter_change=2E?= Message-ID: <3X0XBh5bJYzQNG@mail.python.org> http://hg.python.org/cpython/rev/c793d62cdecc changeset: 78660:c793d62cdecc branch: 2.7 parent: 78645:b16a5f0d0c87 user: R David Murray date: Sun Aug 19 17:57:29 2012 -0400 summary: #13579: minimize code base drift for 'a' string.Formatter change. 2.7 doesn't support 'a'. This changeset ports the doc change and clause-reording portions of Francisco Mart?n Brugu? patch in order to minimize code base drift. files: Doc/library/string.rst | 11 ++++++----- Lib/string.py | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Doc/library/string.rst b/Doc/library/string.rst --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -123,8 +123,8 @@ .. method:: format(format_string, *args, **kwargs) - :meth:`format` is the primary API method. It takes a format template - string, and an arbitrary set of positional and keyword argument. + :meth:`format` is the primary API method. It takes a format string and + an arbitrary set of positional and keyword arguments. :meth:`format` is just a wrapper that calls :meth:`vformat`. .. method:: vformat(format_string, args, kwargs) @@ -133,8 +133,8 @@ separate function for cases where you want to pass in a predefined dictionary of arguments, rather than unpacking and repacking the dictionary as individual arguments using the ``*args`` and ``**kwds`` - syntax. :meth:`vformat` does the work of breaking up the format template - string into character data and replacement fields. It calls the various + syntax. :meth:`vformat` does the work of breaking up the format string + into character data and replacement fields. It calls the various methods described below. In addition, the :class:`Formatter` defines a number of methods that are @@ -205,7 +205,8 @@ Converts the value (returned by :meth:`get_field`) given a conversion type (as in the tuple returned by the :meth:`parse` method). The default - version understands 'r' (repr) and 's' (str) conversion types. + version understands 's' (str), 'r' (repr) and 'a' (ascii) conversion + types. .. _formatstrings: diff --git a/Lib/string.py b/Lib/string.py --- a/Lib/string.py +++ b/Lib/string.py @@ -601,12 +601,12 @@ def convert_field(self, value, conversion): # do any conversion on the resulting object - if conversion == 'r': - return repr(value) + if conversion is None: + return value elif conversion == 's': return str(value) - elif conversion is None: - return value + elif conversion == 'r': + return repr(value) raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 02:04:45 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 02:04:45 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2314814=3A_document?= =?utf-8?q?_the_Interface_APIs_and_fix_various_problems_with_the?= Message-ID: <3X0ZyP1gyBzPx2@mail.python.org> http://hg.python.org/cpython/rev/258558e36d8a changeset: 78661:258558e36d8a parent: 78659:4feb10457c13 user: Nick Coghlan date: Mon Aug 20 10:04:26 2012 +1000 summary: Issue #14814: document the Interface APIs and fix various problems with the string representations (initial patch by Eli Bendersky). files: Doc/library/ipaddress.rst | 77 +++++++++++++++++++------ Lib/ipaddress.py | 9 ++- Lib/test/test_ipaddress.py | 16 ++--- 3 files changed, 72 insertions(+), 30 deletions(-) diff --git a/Doc/library/ipaddress.rst b/Doc/library/ipaddress.rst --- a/Doc/library/ipaddress.rst +++ b/Doc/library/ipaddress.rst @@ -642,32 +642,73 @@ .. class:: IPv4Interface(address) - Construct an IPv4 interface. *address* is a string or integer representing - the IP interface. An :exc:`AddressValueError` is raised if *address* is not - a valid IPv4 address. + Construct an IPv4 interface. The meaning of *address* is as in the + constructor of :class:`IPv4Network`, except that arbitrary host addresses + are always accepted. - The network address for the interface is determined by calling - ``IPv4Network(address, strict=False)``. + :class:`IPv4Interface` is a subclass of :class:`IPv4Address`, so it inherits + all the attributes from that class. In addition, the following attributes + are available: - >>> ipaddress.IPv4Interface('192.168.0.0/24') - IPv4Interface('192.168.0.0/24') - >>> ipaddress.IPv4Interface('192.168.0.0/24').network - IPv4Network('192.168.0.0/24') + .. attribute:: ip + + The address (:class:`IPv4Address`) without network information. + + >>> interface = IPv4Interface('192.0.2.5/24') + >>> interface.ip + IPv4Address('192.0.2.5') + + .. attribute:: network + + The network (:class:`IPv4Network`) this interface belongs to. + + >>> interface = IPv4Interface('192.0.2.5/24') + >>> interface.network + IPv4Network('192.0.2.0/24') + + .. attribute:: with_prefixlen + + A string representation of the interface with the mask in prefix notation. + + >>> interface = IPv4Interface('192.0.2.5/24') + >>> interface.with_prefixlen + '192.0.2.5/24' + + .. attribute:: with_netmask + + A string representation of the interface with the network as a net mask. + + >>> interface = IPv4Interface('192.0.2.5/24') + >>> interface.with_netmask + '192.0.2.5/255.255.255.0' + + .. attribute:: with_hostmask + + A string representation of the interface with the network as a host mask. + + >>> interface = IPv4Interface('192.0.2.5/24') + >>> interface.with_hostmask + '192.0.2.5/0.0.0.255' .. class:: IPv6Interface(address) - Construct an IPv6 interface. *address* is a string or integer representing - the IP interface. An :exc:`AddressValueError` is raised if *address* is not - a valid IPv6 address. + Construct an IPv6 interface. The meaning of *address* is as in the + constructor of :class:`IPv6Network`, except that arbitrary host addresses + are always accepted. - The network address for the interface is determined by calling - ``IPv6Network(address, strict=False)``. + :class:`IPv6Interface` is a subclass of :class:`IPv6Address`, so it inherits + all the attributes from that class. In addition, the following attributes + are available: - >>> ipaddress.IPv6Interface('2001:db8::1000/96') - IPv6Interface('2001:db8::1000/96') - >>> ipaddress.IPv6Interface('2001:db8::1000/96').network - IPv6Network('2001:db8::/96') + .. attribute:: ip + .. attribute:: network + .. attribute:: with_prefixlen + .. attribute:: with_netmask + .. attribute:: with_hostmask + + Refer to the corresponding attribute documentation in + :class:`IPv4Interface`. Other Module Level Functions diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1336,7 +1336,8 @@ @property def with_prefixlen(self): - return self + return '%s/%s' % (self._string_from_ip_int(self._ip), + self._prefixlen) @property def with_netmask(self): @@ -1948,11 +1949,13 @@ @property def with_prefixlen(self): - return self + return '%s/%s' % (self._string_from_ip_int(self._ip), + self._prefixlen) @property def with_netmask(self): - return self.with_prefixlen + return '%s/%s' % (self._string_from_ip_int(self._ip), + self.netmask) @property def with_hostmask(self): diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -1558,21 +1558,19 @@ self.assertEqual(ipaddress.IPv6Network(1).version, 6) def testWithStar(self): - self.assertEqual(str(self.ipv4_interface.with_prefixlen), "1.2.3.4/24") - self.assertEqual(str(self.ipv4_interface.with_netmask), + self.assertEqual(self.ipv4_interface.with_prefixlen, "1.2.3.4/24") + self.assertEqual(self.ipv4_interface.with_netmask, "1.2.3.4/255.255.255.0") - self.assertEqual(str(self.ipv4_interface.with_hostmask), + self.assertEqual(self.ipv4_interface.with_hostmask, "1.2.3.4/0.0.0.255") - self.assertEqual(str(self.ipv6_interface.with_prefixlen), + self.assertEqual(self.ipv6_interface.with_prefixlen, '2001:658:22a:cafe:200::1/64') - # rfc3513 sec 2.3 says that ipv6 only uses cidr notation for - # subnets - self.assertEqual(str(self.ipv6_interface.with_netmask), - '2001:658:22a:cafe:200::1/64') + self.assertEqual(self.ipv6_interface.with_netmask, + '2001:658:22a:cafe:200::1/ffff:ffff:ffff:ffff::') # this probably don't make much sense, but it's included for # compatibility with ipv4 - self.assertEqual(str(self.ipv6_interface.with_hostmask), + self.assertEqual(self.ipv6_interface.with_hostmask, '2001:658:22a:cafe:200::1/::ffff:ffff:ffff:ffff') def testNetworkElementCaching(self): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 02:19:35 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 02:19:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2314814=3A_Avoid_de?= =?utf-8?q?pending_on_struct_by_using_newer_features=2E_Also_use?= Message-ID: <3X0bHW0LVjzQSc@mail.python.org> http://hg.python.org/cpython/rev/811d91591f73 changeset: 78662:811d91591f73 user: Nick Coghlan date: Mon Aug 20 10:19:12 2012 +1000 summary: Close #14814: Avoid depending on struct by using newer features. Also use enumerate where appropriate (patch by Serhiy Storchaka). Declaring PEP 3144 final at this point - any further changes to code or docs can go in new issues. files: Lib/ipaddress.py | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -11,7 +11,6 @@ __version__ = '1.0' -import struct import functools IPV4LENGTH = 32 @@ -135,7 +134,7 @@ """ try: - return struct.pack('!I', address) + return address.to_bytes(4, 'big') except: raise ValueError("Address negative or too large for IPv4") @@ -151,7 +150,7 @@ """ try: - return struct.pack('!QQ', address >> 64, address & (2**64 - 1)) + return address.to_bytes(16, 'big') except: raise ValueError("Address negative or too large for IPv6") @@ -1195,7 +1194,7 @@ # Constructing from a packed address if isinstance(address, bytes): self._check_packed_address(address, 4) - self._ip = struct.unpack('!I', address)[0] + self._ip = int.from_bytes(address, 'big') return # Assume input argument to be string or any object representation @@ -1632,8 +1631,8 @@ best_doublecolon_len = 0 doublecolon_start = -1 doublecolon_len = 0 - for index in range(len(hextets)): - if hextets[index] == '0': + for index, hextet in enumerate(hextets): + if hextet == '0': doublecolon_len += 1 if doublecolon_start == -1: # Start of a sequence of zeros. @@ -1750,8 +1749,7 @@ # Constructing from a packed address if isinstance(address, bytes): self._check_packed_address(address, 16) - tmp = struct.unpack('!QQ', address) - self._ip = (tmp[0] << 64) | tmp[1] + self._ip = int.from_bytes(address, 'big') return # Assume input argument to be string or any object representation -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 02:26:21 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 02:26:21 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?peps=3A_ipaddress_integration_is_comp?= =?utf-8?q?lete?= Message-ID: <3X0bRK0wfHzQLQ@mail.python.org> http://hg.python.org/peps/rev/d95043db64be changeset: 4501:d95043db64be user: Nick Coghlan date: Mon Aug 20 10:26:02 2012 +1000 summary: ipaddress integration is complete files: pep-3144.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/pep-3144.txt b/pep-3144.txt --- a/pep-3144.txt +++ b/pep-3144.txt @@ -5,7 +5,7 @@ Author: Peter Moody BDFL-Delegate: Nick Coghlan Discussions-To: -Status: Accepted +Status: Final Type: Standards Track Content-Type: text/plain Created: 6-Feb-2012 -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Mon Aug 20 05:18:38 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 05:18:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2314846=3A_Handle_a?= =?utf-8?q?_sys=2Epath_entry_going_away?= Message-ID: <3X0gG63bL7zQNk@mail.python.org> http://hg.python.org/cpython/rev/bfd04bfb55c5 changeset: 78663:bfd04bfb55c5 user: Nick Coghlan date: Mon Aug 20 13:18:15 2012 +1000 summary: Close #14846: Handle a sys.path entry going away files: Lib/importlib/_bootstrap.py | 6 +- Lib/test/test_importlib/source/test_finder.py | 15 +- Misc/NEWS | 3 + Python/importlib.h | 1866 +++++---- 4 files changed, 955 insertions(+), 935 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1367,7 +1367,11 @@ def _fill_cache(self): """Fill the cache of potential modules and packages for this directory.""" path = self.path - contents = _os.listdir(path) + try: + contents = _os.listdir(path) + except FileNotFoundError: + # Directory has been removed since last import + contents = [] # We store two cached versions, to handle runtime changes of the # PYTHONCASEOK environment variable. if not sys.platform.startswith('win'): diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py --- a/Lib/test/test_importlib/source/test_finder.py +++ b/Lib/test/test_importlib/source/test_finder.py @@ -35,13 +35,15 @@ """ - def import_(self, root, module): + def get_finder(self, root): loader_details = [(machinery.SourceFileLoader, machinery.SOURCE_SUFFIXES), (machinery.SourcelessFileLoader, machinery.BYTECODE_SUFFIXES)] - finder = machinery.FileFinder(root, *loader_details) - return finder.find_module(module) + return machinery.FileFinder(root, *loader_details) + + def import_(self, root, module): + return self.get_finder(root).find_module(module) def run_test(self, test, create=None, *, compile_=None, unlink=None): """Test the finding of 'test' with the creation of modules listed in @@ -137,6 +139,13 @@ finder.invalidate_caches() self.assertEqual(finder._path_mtime, -1) + # Regression test for http://bugs.python.org/issue14846 + def test_dir_removal_handling(self): + mod = 'mod' + with source_util.create_modules(mod) as mapping: + finder = self.get_finder(mapping['.root']) + self.assertIsNotNone(finder.find_module(mod)) + self.assertIsNone(finder.find_module(mod)) def test_main(): from test.support import run_unittest diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,9 @@ - Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. +- Issue #14846: importlib.FileFinder now handles the case where the + directory being searched is removed after a previous import attempt + Library ------- 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 Mon Aug 20 05:49:25 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 05:49:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_s/path_importer/path_based?= =?utf-8?q?_finder/_=28because_the_path_based_finder_is_not_an?= Message-ID: <3X0gxd4vH0zQ5X@mail.python.org> http://hg.python.org/cpython/rev/2f9f5ab3d754 changeset: 78664:2f9f5ab3d754 user: Nick Coghlan date: Mon Aug 20 13:49:08 2012 +1000 summary: s/path importer/path based finder/ (because the path based finder is not an importer and the simpler 'path finder' is too ambiguous) files: Doc/glossary.rst | 6 +- Doc/reference/import.rst | 95 ++++++++++++++------------- Misc/NEWS | 4 + 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/Doc/glossary.rst b/Doc/glossary.rst --- a/Doc/glossary.rst +++ b/Doc/glossary.rst @@ -317,7 +317,7 @@ import path A list of locations (or :term:`path entries `) that are - searched by the :term:`path importer` for modules to import. During + searched by the :term:`path based finder` for modules to import. During import, this list of locations usually comes from :data:`sys.path`, but for subpackages it may also come from the parent package's ``__path__`` attribute. @@ -550,7 +550,7 @@ path entry A single location on the :term:`import path` which the :term:`path - importer` consults to find modules for importing. + based finder` consults to find modules for importing. path entry finder A :term:`finder` returned by a callable on :data:`sys.path_hooks` @@ -562,7 +562,7 @@ entry finder` if it knows how to find modules on a specific :term:`path entry`. - path importer + path based finder One of the default :term:`meta path finders ` which searches an :term:`import path` for modules. diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -42,6 +42,12 @@ invoked. These strategies can be modified and extended by using various hooks described in the sections below. +.. versionchanged:: 3.3 + The import system has been updated to fully implement the second phase + of PEP 302. There is no longer any implicit import machinery - the full + import system is exposed through :data:`sys.meta_path`. In addition, + native namespace package support has been implemented (see PEP 420). + :mod:`importlib` ================ @@ -213,7 +219,7 @@ interfaces are referred to as :term:`importers ` - they return themselves when they find that they can load the requested module. -By default, Python comes with several default finders and importers. One +Python includes a number of default finders and importers. One knows how to locate frozen modules, and another knows how to locate built-in modules. A third default finder searches an :term:`import path` for modules. The :term:`import path` is a list of locations that may @@ -307,7 +313,7 @@ Python's default :data:`sys.meta_path` has three meta path finders, one that knows how to import built-in modules, one that knows how to import frozen modules, and one that knows how to import modules from an :term:`import path` -(i.e. the :term:`path importer`). +(i.e. the :term:`path based finder`). Loaders @@ -356,14 +362,14 @@ * If the module is a package (either regular or namespace), the loader must set the module object's ``__path__`` attribute. The value must be iterable, but may be empty if ``__path__`` has no further significance - to the importer. If ``__path__`` is not empty, it must produce strings + to the loader. If ``__path__`` is not empty, it must produce strings when iterated over. More details on the semantics of ``__path__`` are given :ref:`below `. * The ``__loader__`` attribute must be set to the loader object that loaded the module. This is mostly for introspection and reloading, but can be - used for additional importer-specific functionality, for example getting - data associated with an importer. + used for additional loader-specific functionality, for example getting + data associated with a loader. * The module's ``__package__`` attribute should be set. Its value must be a string, but it can be the same value as its ``__name__``. If the attribute @@ -456,18 +462,18 @@ correctly for the namespace package. -The Path Importer -================= +The Path Based Finder +===================== .. index:: - single: path importer + single: path based finder As mentioned previously, Python comes with several default meta path finders. -One of these, called the :term:`path importer`, searches an :term:`import +One of these, called the :term:`path based finder`, searches an :term:`import path`, which contains a list of :term:`path entries `. Each path entry names a location to search for modules. -The path importer itself doesn't know how to import anything. Instead, it +The path based finder itself doesn't know how to import anything. Instead, it traverses the individual path entries, associating each of them with a path entry finder that knows how to handle that particular kind of path. @@ -479,10 +485,10 @@ loading all of these file types (other than shared libraries) from zipfiles. Path entries need not be limited to file system locations. They can refer to -the URLs, database queries, or any other location that can be specified as a +URLs, database queries, or any other location that can be specified as a string. -The :term:`path importer` provides additional hooks and protocols so that you +The path based finder provides additional hooks and protocols so that you can extend and customize the types of searchable path entries. For example, if you wanted to support path entries as network URLs, you could write a hook that implements HTTP semantics to find modules on the web. This hook (a @@ -498,8 +504,8 @@ In particular, meta path finders operate at the beginning of the import process, as keyed off the :data:`sys.meta_path` traversal. -On the other hand, path entry finders are in a sense an implementation detail -of the :term:`path importer`, and in fact, if the path importer were to be +By contrast, path entry finders are in a sense an implementation detail +of the path based finder, and in fact, if the path based finder were to be removed from :data:`sys.meta_path`, none of the path entry finder semantics would be invoked. @@ -513,17 +519,17 @@ single: sys.path_importer_cache single: PYTHONPATH -The :term:`path importer` is responsible for finding and loading Python +The :term:`path based finder` is responsible for finding and loading Python modules and packages whose location is specified with a string :term:`path entry`. Most path entries name locations in the file system, but they need not be limited to this. -As a meta path finder, the :term:`path importer` implements the +As a meta path finder, the :term:`path based finder` implements the :meth:`find_module()` protocol previously described, however it exposes additional hooks that can be used to customize how modules are found and loaded from the :term:`import path`. -Three variables are used by the :term:`path importer`, :data:`sys.path`, +Three variables are used by the :term:`path based finder`, :data:`sys.path`, :data:`sys.path_hooks` and :data:`sys.path_importer_cache`. The ``__path__`` attributes on package objects are also used. These provide additional ways that the import machinery can be customized. @@ -536,38 +542,40 @@ (see the :mod:`site` module) that should be searched for modules, such as URLs, or database queries. -The :term:`path importer` is a :term:`meta path finder`, so the import +The :term:`path based finder` is a :term:`meta path finder`, so the import machinery begins the :term:`import path` search by calling the path -importer's :meth:`find_module()` method as described previously. When +based finder's :meth:`find_module()` method as described previously. When the ``path`` argument to :meth:`find_module()` is given, it will be a list of string paths to traverse - typically a package's ``__path__`` attribute for an import within that package. If the ``path`` argument is ``None``, this indicates a top level import and :data:`sys.path` is used. -The :term:`path importer` iterates over every entry in the search path, and +The path based finder iterates over every entry in the search path, and for each of these, looks for an appropriate :term:`path entry finder` for the path entry. Because this can be an expensive operation (e.g. there may be -`stat()` call overheads for this search), the :term:`path importer` maintains +`stat()` call overheads for this search), the path based finder maintains a cache mapping path entries to path entry finders. This cache is maintained -in :data:`sys.path_importer_cache`. In this way, the expensive search for a -particular :term:`path entry` location's :term:`path entry finder` need only -be done once. User code is free to remove cache entries from -:data:`sys.path_importer_cache` forcing the :term:`path importer` to perform -the path entry search again [#fnpic]_. +in :data:`sys.path_importer_cache` (despite the name, this cache actually +stores finder objects rather than being limited to :term:`importer` objects). +In this way, the expensive search for a particular :term:`path entry` +location's :term:`path entry finder` need only be done once. User code is +free to remove cache entries from :data:`sys.path_importer_cache` forcing +the path based finder to perform the path entry search again [#fnpic]_. -If the path entry is not present in the cache, the path importer iterates over -every callable in :data:`sys.path_hooks`. Each of the :term:`path entry hooks -` in this list is called with a single argument, the path -entry being searched. This callable may either return a :term:`path entry -finder` that can handle the path entry, or it may raise :exc:`ImportError`. -An :exc:`ImportError` is used by the path importer to signal that the hook +If the path entry is not present in the cache, the path based finder iterates +over every callable in :data:`sys.path_hooks`. Each of the +:term:`path entry hooks ` in this list is called with a +single argument, the path entry to be searched. This callable may either +return a :term:`path entry finder` that can handle the path entry, or it may +raise :exc:`ImportError`. +An :exc:`ImportError` is used by the path based finder to signal that the hook cannot find a :term:`path entry finder` for that :term:`path entry`. The exception is ignored and :term:`import path` iteration continues. If :data:`sys.path_hooks` iteration ends with no :term:`path entry finder` -being returned, then the path importer's :meth:`find_module()` method will -store ``None`` in :data:`sys.path_importer_cache` (to indicate that there -is no finder for this path entry) and return ``None``, indicating that +being returned, then the path based finder's :meth:`find_module()` method +will store ``None`` in :data:`sys.path_importer_cache` (to indicate that +there is no finder for this path entry) and return ``None``, indicating that this :term:`meta path finder` could not find the module. If a :term:`path entry finder` *is* returned by one of the :term:`path entry @@ -594,8 +602,8 @@ must be a sequence, although it can be empty. If :meth:`find_loader()` returns a non-``None`` loader value, the portion is -ignored and the loader is returned from the path importer, terminating the -search through the path entries. +ignored and the loader is returned from the path based finder, terminating +the search through the path entries. For backwards compatibility with other implementations of the import protocol, many path entry finders also support the same, @@ -645,9 +653,6 @@ XXX runpy, pkgutil, et al in the library manual should all get "See Also" links at the top pointing to the new import system section. -XXX The :term:`path importer` is not, in fact, an :term:`importer`. That's -why the corresponding implementation class is :class:`importlib.PathFinder`. - References ========== @@ -667,8 +672,8 @@ :pep:`366` describes the addition of the ``__package__`` attribute for explicit relative imports in main modules. -:pep:`328` introduced absolute and relative imports and initially proposed -``__name__`` for semantics :pep:`366` would eventually specify for +:pep:`328` introduced absolute and explicit relative imports and initially +proposed ``__name__`` for semantics :pep:`366` would eventually specify for ``__package__``. :pep:`338` defines executing modules as scripts. @@ -679,14 +684,14 @@ .. [#fnmo] See :class:`types.ModuleType`. -.. [#fnlo] The importlib implementation appears not to use the return value +.. [#fnlo] The importlib implementation avoids using the return value directly. Instead, it gets the module object by looking the module name up - in :data:`sys.modules`.) The indirect effect of this is that an imported + in :data:`sys.modules`. The indirect effect of this is that an imported module may replace itself in :data:`sys.modules`. This is implementation-specific behavior that is not guaranteed to work in other Python implementations. .. [#fnpic] In legacy code, it is possible to find instances of :class:`imp.NullImporter` in the :data:`sys.path_importer_cache`. It - recommended that code be changed to use ``None`` instead. See + is recommended that code be changed to use ``None`` instead. See :ref:`portingpythoncode` for more details. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,10 @@ Documentation ------------- +- The "path importer" misnomer has been replaced with Eric Snow's + more-awkward-but-at-least-not-wrong suggestion of "path based finder" in + the import system reference docs + - Issue #15640: Document importlib.abc.Finder as deprecated. - Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Aug 20 06:13:10 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 20 Aug 2012 06:13:10 +0200 Subject: [Python-checkins] Daily reference leaks (811d91591f73): sum=0 Message-ID: results for 811d91591f73 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogk5U1mO', '-x'] From python-checkins at python.org Mon Aug 20 09:14:24 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 09:14:24 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=234966=3A_revamp_th?= =?utf-8?q?e_sequence_docs_in_order_to_better_explain_the_state_of?= Message-ID: <3X0mV86gLXzPcJ@mail.python.org> http://hg.python.org/cpython/rev/463f52d20314 changeset: 78665:463f52d20314 user: Nick Coghlan date: Mon Aug 20 17:14:07 2012 +1000 summary: Close #4966: revamp the sequence docs in order to better explain the state of modern Python files: Doc/library/binary.rst | 23 + Doc/library/index.rst | 3 +- Doc/library/stdtypes.rst | 1840 ++++++++++++++----------- Doc/library/strings.rst | 19 +- Doc/whatsnew/3.3.rst | 5 +- Misc/NEWS | 3 + 6 files changed, 1078 insertions(+), 815 deletions(-) diff --git a/Doc/library/binary.rst b/Doc/library/binary.rst new file mode 100644 --- /dev/null +++ b/Doc/library/binary.rst @@ -0,0 +1,23 @@ +.. _binaryservices: + +******************** +Binary Data Services +******************** + +The modules described in this chapter provide some basic services operations +for manipulation of binary data. Other operations on binary data, specifically +in relation to file formats and network protocols, are described in the +relevant sections. + +Some libraries described under :ref:`textservices` also work with either +ASCII-compatible binary formats (for example, :mod:`re`) or all binary data +(for example, :mod:`difflib`). + +In addition, see the documentation for Python's built-in binary data types in +:ref:`binaryseq`. + +.. toctree:: + + struct.rst + codecs.rst + diff --git a/Doc/library/index.rst b/Doc/library/index.rst --- a/Doc/library/index.rst +++ b/Doc/library/index.rst @@ -46,7 +46,8 @@ stdtypes.rst exceptions.rst - strings.rst + text.rst + binary.rst datatypes.rst numeric.rst functional.rst diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -672,7 +672,7 @@ To clarify the above rules, here's some example Python code, -equivalent to the builtin hash, for computing the hash of a rational +equivalent to the built-in hash, for computing the hash of a rational number, :class:`float`, or :class:`complex`:: @@ -799,110 +799,77 @@ .. _typesseq: -Sequence Types --- :class:`str`, :class:`bytes`, :class:`bytearray`, :class:`list`, :class:`tuple`, :class:`range` -================================================================================================================== - -There are six sequence types: strings, byte sequences (:class:`bytes` objects), -byte arrays (:class:`bytearray` objects), lists, tuples, and range objects. For -other containers see the built in :class:`dict` and :class:`set` classes, and -the :mod:`collections` module. - - -.. index:: - object: sequence - object: string - object: bytes - object: bytearray - object: tuple - object: list - object: range - -Strings contain Unicode characters. Their literals are written in single or -double quotes: ``'xyzzy'``, ``"frobozz"``. See :ref:`strings` for more about -string literals. In addition to the functionality described here, there are -also string-specific methods described in the :ref:`string-methods` section. - -Bytes and bytearray objects contain single bytes -- the former is immutable -while the latter is a mutable sequence. -Bytes objects can be constructed by using the -constructor, :func:`bytes`, and from literals; use a ``b`` prefix with normal -string syntax: ``b'xyzzy'``. To construct byte arrays, use the -:func:`bytearray` function. - -While string objects are sequences of characters (represented by strings of -length 1), bytes and bytearray objects are sequences of *integers* (between 0 -and 255), representing the ASCII value of single bytes. That means that for -a bytes or bytearray object *b*, ``b[0]`` will be an integer, while -``b[0:1]`` will be a bytes or bytearray object of length 1. The -representation of bytes objects uses the literal format (``b'...'``) since it -is generally more useful than e.g. ``bytes([50, 19, 100])``. You can always -convert a bytes object into a list of integers using ``list(b)``. - -Also, while in previous Python versions, byte strings and Unicode strings -could be exchanged for each other rather freely (barring encoding issues), -strings and bytes are now completely separate concepts. There's no implicit -en-/decoding if you pass an object of the wrong type. A string always -compares unequal to a bytes or bytearray object. - -Lists are constructed with square brackets, separating items with commas: ``[a, -b, c]``. Tuples are constructed by the comma operator (not within square -brackets), with or without enclosing parentheses, but an empty tuple must have -the enclosing parentheses, such as ``a, b, c`` or ``()``. A single item tuple -must have a trailing comma, such as ``(d,)``. - -Objects of type range are created using the :func:`range` function. They don't -support concatenation or repetition, and using :func:`min` or :func:`max` on -them is inefficient. - -Most sequence types support the following operations. The ``in`` and ``not in`` -operations have the same priorities as the comparison operations. The ``+`` and -``*`` operations have the same priority as the corresponding numeric operations. -[3]_ Additional methods are provided for :ref:`typesseq-mutable`. +Sequence Types --- :class:`list`, :class:`tuple`, :class:`range` +================================================================ + +There are three basic sequence types: lists, tuples, and range objects. +Additional sequence types tailored for processing of +:ref:`binary data ` and :ref:`text strings ` are +described in dedicated sections. + + +.. _typesseq-common: + +Common Sequence Operations +-------------------------- + +.. index:: object: sequence + +The operations in the following table are supported by most sequence types, +both mutable and immutable. The :class:`collections.abc.Sequence` ABC is +provided to make it easier to correctly implement these operations on +custom sequence types. This table lists the sequence operations sorted in ascending priority (operations in the same box have the same priority). In the table, *s* and *t* -are sequences of the same type; *n*, *i*, *j* and *k* are integers. - -+------------------+--------------------------------+----------+ -| Operation | Result | Notes | -+==================+================================+==========+ -| ``x in s`` | ``True`` if an item of *s* is | \(1) | -| | equal to *x*, else ``False`` | | -+------------------+--------------------------------+----------+ -| ``x not in s`` | ``False`` if an item of *s* is | \(1) | -| | equal to *x*, else ``True`` | | -+------------------+--------------------------------+----------+ -| ``s + t`` | the concatenation of *s* and | \(6) | -| | *t* | | -+------------------+--------------------------------+----------+ -| ``s * n, n * s`` | *n* shallow copies of *s* | \(2) | -| | concatenated | | -+------------------+--------------------------------+----------+ -| ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) | -+------------------+--------------------------------+----------+ -| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) | -+------------------+--------------------------------+----------+ -| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) | -| | with step *k* | | -+------------------+--------------------------------+----------+ -| ``len(s)`` | length of *s* | | -+------------------+--------------------------------+----------+ -| ``min(s)`` | smallest item of *s* | | -+------------------+--------------------------------+----------+ -| ``max(s)`` | largest item of *s* | | -+------------------+--------------------------------+----------+ -| ``s.index(i)`` | index of the first occurence | | -| | of *i* in *s* | | -+------------------+--------------------------------+----------+ -| ``s.count(i)`` | total number of occurences of | | -| | *i* in *s* | | -+------------------+--------------------------------+----------+ - -Sequence types also support comparisons. In particular, tuples and lists are -compared lexicographically by comparing corresponding elements. This means that -to compare equal, every element must compare equal and the two sequences must be -of the same type and have the same length. (For full details see -:ref:`comparisons` in the language reference.) +are sequences of the same type, *n*, *i*, *j* and *k* are integers and *x* is +an arbitrary object that meets any type and value restrictions imposed by *s*. + +The ``in`` and ``not in`` operations have the same priorities as the +comparison operations. The ``+`` (concatenation) and ``*`` (repetition) +operations have the same priority as the corresponding numeric operations. + ++--------------------------+--------------------------------+----------+ +| Operation | Result | Notes | ++==========================+================================+==========+ +| ``x in s`` | ``True`` if an item of *s* is | \(1) | +| | equal to *x*, else ``False`` | | ++--------------------------+--------------------------------+----------+ +| ``x not in s`` | ``False`` if an item of *s* is | \(1) | +| | equal to *x*, else ``True`` | | ++--------------------------+--------------------------------+----------+ +| ``s + t`` | the concatenation of *s* and | (6)(7) | +| | *t* | | ++--------------------------+--------------------------------+----------+ +| ``s * n, n * s`` | *n* shallow copies of *s* | (2)(7) | +| | concatenated | | ++--------------------------+--------------------------------+----------+ +| ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) | ++--------------------------+--------------------------------+----------+ +| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) | ++--------------------------+--------------------------------+----------+ +| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) | +| | with step *k* | | ++--------------------------+--------------------------------+----------+ +| ``len(s)`` | length of *s* | | ++--------------------------+--------------------------------+----------+ +| ``min(s)`` | smallest item of *s* | | ++--------------------------+--------------------------------+----------+ +| ``max(s)`` | largest item of *s* | | ++--------------------------+--------------------------------+----------+ +| ``s.index(x, [i[, j]])`` | index of the first occurence | \(8) | +| | of *x* in *s* (at or after | | +| | index *i* and before index *j*)| | ++--------------------------+--------------------------------+----------+ +| ``s.count(x)`` | total number of occurences of | | +| | *x* in *s* | | ++--------------------------+--------------------------------+----------+ + +Sequences of the same type also support comparisons. In particular, tuples +and lists are compared lexicographically by comparing corresponding elements. +This means that to compare equal, every element must compare equal and the +two sequences must be of the same type and have the same length. (For full +details see :ref:`comparisons` in the language reference.) .. index:: triple: operations on; sequence; types @@ -919,14 +886,19 @@ Notes: (1) - When *s* is a string object, the ``in`` and ``not in`` operations act like a - substring test. + While the ``in`` and ``not in`` operations are used only for simple + containment testing in the general case, some specialised sequences + (such as :class:`str`, :class:`bytes` and :class:`bytearray`) also use + them for subsequence testing:: + + >>> "gg" in "eggs" + True (2) Values of *n* less than ``0`` are treated as ``0`` (which yields an empty sequence of the same type as *s*). Note also that the copies are shallow; nested structures are not copied. This often haunts new Python programmers; - consider: + consider:: >>> lists = [[]] * 3 >>> lists @@ -938,7 +910,7 @@ What has happened is that ``[[]]`` is a one-element list containing an empty list, so all three elements of ``[[]] * 3`` are (pointers to) this single empty list. Modifying any of the elements of ``lists`` modifies this single list. - You can create a list of different lists this way: + You can create a list of different lists this way:: >>> lists = [[] for i in range(3)] >>> lists[0].append(3) @@ -969,33 +941,354 @@ If *k* is ``None``, it is treated like ``1``. (6) - Concatenating immutable strings always results in a new object. This means - that building up a string by repeated concatenation will have a quadratic - runtime cost in the total string length. To get a linear runtime cost, - you must switch to one of the alternatives below: + Concatenating immutable sequences always results in a new object. This + means that building up a sequence by repeated concatenation will have a + quadratic runtime cost in the total sequence length. To get a linear + runtime cost, you must switch to one of the alternatives below: * if concatenating :class:`str` objects, you can build a list and use - :meth:`str.join` at the end; + :meth:`str.join` at the end or else write to a :class:`io.StringIO` + instance and retrieve its value when complete; * if concatenating :class:`bytes` objects, you can similarly use - :meth:`bytes.join`, or you can do in-place concatenation with a - :class:`bytearray` object. :class:`bytearray` objects are mutable and - have an efficient overallocation mechanism. - + :meth:`bytes.join` or :class:`io.BytesIO`, or you can do in-place + concatenation with a :class:`bytearray` object. :class:`bytearray` + objects are mutable and have an efficient overallocation mechanism. + + * if concatenating :class:`tuple` objects, extend a :class:`list` instead. + + * for other types, investigate the relevant class documentation + + +(7) + Some sequence types (such as :class:`range`) only support item sequences + that follow specific patterns, and hence don't support sequence + concatenation or repetition. + +(8) + ``index`` raises :exc:`ValueError` when *x* is not found in *s*. + When supported, the additional arguments to the index method allow + efficient searching of subsections of the sequence. Passing the extra + arguments is roughly equivalent to using ``s[i:j].index(x)``, only + without copying any data and with the returned index being relative to + the start of the sequence rather than the start of the slice. + + +.. _typesseq-immutable: + +Immutable Sequence Types +------------------------ + +.. index:: + triple: immutable; sequence; types + object: tuple + +The only operation that immutable sequence types generally implement that is +not also implemented by mutable sequence types is support for the :func:`hash` +built-in. + +This support allows immutable sequences, such as :class:`tuple` instances, to +be used as :class:`dict` keys and stored in :class:`set` and :class:`frozenset` +instances. + +Attempting to hash an immutable sequence that contains unhashable values will +result in :exc:`TypeError`. + + +.. _typesseq-mutable: + +Mutable Sequence Types +---------------------- + +.. index:: + triple: mutable; sequence; types + object: list + object: bytearray + +The operations in the following table are defined on mutable sequence types. +The :class:`collections.abc.MutableSequence` ABC is provided to make it +easier to correctly implement these operations on custom sequence types. + +In the table *s* is an instance of a mutable sequence type, *t* is any +iterable object and *x* is an arbitrary object that meets any type +and value restrictions imposed by *s* (for example, :class:`bytearray` only +accepts integers that meet the value restriction ``0 <= x <= 255``). + + +.. index:: + triple: operations on; sequence; types + triple: operations on; list; type + pair: subscript; assignment + pair: slice; assignment + statement: del + single: append() (sequence method) + single: extend() (sequence method) + single: count() (sequence method) + single: index() (sequence method) + single: insert() (sequence method) + single: pop() (sequence method) + single: remove() (sequence method) + single: reverse() (sequence method) + ++------------------------------+--------------------------------+---------------------+ +| Operation | Result | Notes | ++==============================+================================+=====================+ +| ``s[i] = x`` | item *i* of *s* is replaced by | | +| | *x* | | ++------------------------------+--------------------------------+---------------------+ +| ``s[i:j] = t`` | slice of *s* from *i* to *j* | | +| | is replaced by the contents of | | +| | the iterable *t* | | ++------------------------------+--------------------------------+---------------------+ +| ``del s[i:j]`` | same as ``s[i:j] = []`` | | ++------------------------------+--------------------------------+---------------------+ +| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` | \(1) | +| | are replaced by those of *t* | | ++------------------------------+--------------------------------+---------------------+ +| ``del s[i:j:k]`` | removes the elements of | | +| | ``s[i:j:k]`` from the list | | ++------------------------------+--------------------------------+---------------------+ +| ``s.append(x)`` | same as ``s[len(s):len(s)] = | | +| | [x]`` | | ++------------------------------+--------------------------------+---------------------+ +| ``s.clear()`` | remove all items from ``s`` | \(5) | +| | (same as ``del s[:]``) | | ++------------------------------+--------------------------------+---------------------+ +| ``s.copy()`` | return a shallow copy of ``s`` | \(5) | +| | (same as ``s[:]``) | | ++------------------------------+--------------------------------+---------------------+ +| ``s.extend(t)`` | same as ``s[len(s):len(s)] = | | +| | t`` | | ++------------------------------+--------------------------------+---------------------+ +| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | | ++------------------------------+--------------------------------+---------------------+ +| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | \(2) | +| | return x`` | | ++------------------------------+--------------------------------+---------------------+ +| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | \(3) | ++------------------------------+--------------------------------+---------------------+ +| ``s.reverse()`` | reverses the items of *s* in | \(4) | +| | place | | ++------------------------------+--------------------------------+---------------------+ + + +Notes: + +(1) + *t* must have the same length as the slice it is replacing. + +(2) + The optional argument *i* defaults to ``-1``, so that by default the last + item is removed and returned. + +(3) + ``remove`` raises :exc:`ValueError` when *x* is not found in *s*. + +(4) + The :meth:`reverse` method modifies the sequence in place for economy of + space when reversing a large sequence. To remind users that it operates by + side effect, it does not return the reversed sequence. + +(5) + :meth:`clear` and :meth:`!copy` are included for consistency with the + interfaces of mutable containers that don't support slicing operations + (such as :class:`dict` and :class:`set`) + + .. versionadded:: 3.3 + :meth:`clear` and :meth:`!copy` methods. + + +.. _typesseq-list: + +Lists +----- + +.. index:: object: list + +Lists are mutable sequences, typically used to store collections of +homogeneous items (where the precise degree of similarity will vary by +application). + +Lists may be constructed in several ways: + +* Using a pair of square brackets to denote the empty list: ``[]`` +* Using square brackets, separating items with commas: ``[a]``, ``[a, b, c]`` +* Using a list comprehension: ``[x for x in iterable]`` +* Using the :func:`list` built-in: ``list()`` or ``list(iterable)`` + +Many other operations also produce lists, including the :func:`sorted` built-in. + +Lists implement all of the :ref:`common ` and +:ref:`mutable ` sequence operations. Lists also provide the +following additional method: + +.. method:: list.sort(*, key=None, reverse=None) + + This method sorts the list in place, using only ``<`` comparisons + between items. Exceptions are not suppressed - if any comparison operations + fail, the entire sort operation will fail (and the list will likely be left + in a partially modified state). + + *key* specifies a function of one argument that is used to extract a + comparison key from each list element (for example, ``key=str.lower``). + The key corresponding to each item in the list is calculated once and + then used for the entire sorting process. The default value of ``None`` + means that list items are sorted directly without calculating a separate + key value. + + The :func:`functools.cmp_to_key` utility is available to convert a 2.x + style *cmp* function to a *key* function. + + *reverse* is a boolean value. If set to ``True``, then the list elements + are sorted as if each comparison were reversed. + + This method modifies the sequence in place for economy of space when + sorting a large sequence. To remind users that it operates by side + effect, it does not return the sorted sequence (use :func:`sorted` to + explicitly request a new sorted list instance). + + The :meth:`sort` method is guaranteed to be stable. A sort is stable if it + guarantees not to change the relative order of elements that compare equal + --- this is helpful for sorting in multiple passes (for example, sort by + department, then by salary grade). + + .. impl-detail:: + + While a list is being sorted, the effect of attempting to mutate, or even + inspect, the list is undefined. The C implementation of Python makes the + list appear empty for the duration, and raises :exc:`ValueError` if it can + detect that the list has been mutated during a sort. + + +.. _typesseq-tuple: + +Tuples +------ + +.. index:: object: tuple + +Tuples are immutable sequences, typically used to store collections of +heterogeneous data (such as the 2-tuples produced by the :func:`enumerate` +built-in). Tuples are also used for cases where an immutable sequence of +homogeneous data is needed (such as allowing storage in a :class:`set` or +:class:`dict` instance). + +Tuples may be constructed in a number of ways: + +* Using a pair of parentheses to denote the empty tuple: ``()`` +* Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)`` +* Separating items with commas: ``a, b, c`` or ``(a, b, c)`` +* Using the :func:`tuple` built-in: ``tuple()`` or ``tuple(iterable)`` + +Note that the parentheses are optional (except in the empty tuple case, or +when needed to avoid syntactic ambiguity). It is actually the comma which +makes a tuple, not the parentheses. + +Tuples implement all of the :ref:`common ` sequence +operations. + +For heterogeneous collections of data, :func:`collections.namedtuple` may +be more appropriate than a simple tuple object. + + +.. _typesseq-range: + +Ranges +------ + +.. index:: object: range + +The :class:`range` type represents an immutable sequence of numbers and is +commonly used for looping a specific number of times. Instances are created +using the :func:`range` built-in. + +For positive indices with results between the defined ``start`` and ``stop`` +values, integers within the range are determined by the formula: +``r[i] = start + step*i`` + +For negative indices and slicing operations, a range instance determines the +appropriate result for the corresponding tuple and returns either the +appropriate integer (for negative indices) or an appropriate range object +(for slicing operations) . + +The advantage of the :class:`range` type over a regular :class:`list` or +:class:`tuple` is that a :class:`range` object will always take the same +(small) amount of memory, no matter the size of the range it represents (as it +only stores the ``start``, ``stop`` and ``step`` values, calculating individual +items and subranges as needed). + +Ranges implement all of the :ref:`common ` sequence operations +except concatenation and repetition (due to the fact that range objects can +only represent sequences that follow a strict pattern and repetition and +concatenation will usually violate that pattern). + + +.. _textseq: + +Text Sequence Type --- :class:`str` +=================================== + +.. index:: + object: string + object: bytes + object: bytearray + object: io.StringIO + + +Textual data in Python is handled with :class:`str` objects, which are +immutable sequences of Unicode code points. String literals are +written in a variety of ways: + +* Single quotes: ``'allows embedded "double" quotes'`` +* Double quotes: ``"allows embedded 'single' quotes"``. +* Triple quoted: ``'''Three single quotes'''``, ``"""Three double quotes"""`` + +Triple quoted strings may span multiple lines - all associated whitespace will +be included in the string literal. + +String literals that are part of a single expression and have only whitespace +between them will be implicitly converted to a single string literal. + +See :ref:`strings` for more about the various forms of string literal, +including supported escape sequences, and the ``r`` ("raw") prefix that +disables most escape sequence processing. + +Strings may also be created from other objects with the :func:`str` built-in. + +Since there is no separate "character" type, indexing a string produces +strings of length 1. That is, for a non-empty string *s*, ``s[0] == s[0:1]``. + +There is also no mutable string type, but :meth:`str.join` or +:class:`io.StringIO` can be used to efficiently construct strings from +multiple fragments. + +.. versionchanged:: 3.3 + For backwards compatibility with the Python 2 series, the ``u`` prefix is + once again permitted on string literals. It has no effect on the meaning + of string literals and cannot be combined with the ``r`` prefix. .. _string-methods: String Methods -------------- -.. index:: pair: string; methods - -String objects support the methods listed below. - -In addition, Python's strings support the sequence type methods described in the -:ref:`typesseq` section. To output formatted strings, see the -:ref:`string-formatting` section. Also, see the :mod:`re` module for string -functions based on regular expressions. +.. index:: + pair: string; methods + module: re + +Strings implement all of the :ref:`common ` sequence +operations, along with the additional methods described below. + +Strings also support two styles of string formatting, one providing a large +degree of flexibility and customization (see :meth:`str.format`, +:ref:`formatstrings` and :ref:`string-formatting`) and the other based on C +``printf`` style formatting that handles a narrower range of types and is +slightly harder to use correctly, but is often faster for the cases it can +handle (:ref:`old-string-formatting`). + +The :ref:`textservices` section of the standard library covers a number of +other modules that provide various text related utilities (including regular +expression support in the :mod:`re` module). .. method:: str.capitalize() @@ -1462,8 +1755,8 @@ .. _old-string-formatting: -Old String Formatting Operations --------------------------------- +``printf``-style String Formatting +---------------------------------- .. index:: single: formatting, string (%) @@ -1475,23 +1768,19 @@ single: % formatting single: % interpolation -.. XXX is the note enough? - .. note:: - The formatting operations described here are modelled on C's printf() - syntax. They only support formatting of certain builtin types. The - use of a binary operator means that care may be needed in order to - format tuples and dictionaries correctly. As the new - :ref:`string-formatting` syntax is more flexible and handles tuples and - dictionaries naturally, it is recommended for new code. However, there - are no current plans to deprecate printf-style formatting. + The formatting operations described here exhibit a variety of quirks that + lead to a number of common errors (such as failing to display tuples and + dictionaries correctly). Using the newer :meth:`str.format` interface + helps avoid these errors, and also provides a generally more powerful, + flexible and extensible approach to formatting text. String objects have one unique built-in operation: the ``%`` operator (modulo). This is also known as the string *formatting* or *interpolation* operator. Given ``format % values`` (where *format* is a string), ``%`` conversion specifications in *format* are replaced with zero or more elements of *values*. -The effect is similar to the using :c:func:`sprintf` in the C language. +The effect is similar to using the :c:func:`sprintf` in the C language. If *format* requires a single argument, *values* may be a single non-tuple object. [5]_ Otherwise, *values* must be a tuple with exactly the number of @@ -1649,229 +1938,174 @@ ``%f`` conversions for numbers whose absolute value is over 1e50 are no longer replaced by ``%g`` conversions. + +.. _binaryseq: + +Binary Sequence Types --- :class:`bytes`, :class:`bytearray`, :class:`memoryview` +================================================================================= + .. index:: - module: string - module: re - -Additional string operations are defined in standard modules :mod:`string` and -:mod:`re`. - - -.. _typesseq-range: - -Range Type ----------- - -.. index:: object: range - -The :class:`range` type is an immutable sequence which is commonly used for -looping. The advantage of the :class:`range` type is that an :class:`range` -object will always take the same amount of memory, no matter the size of the -range it represents. - -Range objects have relatively little behavior: they support indexing, contains, -iteration, the :func:`len` function, and the following methods: - -.. method:: range.count(x) - - Return the number of *i*'s for which ``s[i] == x``. - - .. versionadded:: 3.2 - -.. method:: range.index(x) - - Return the smallest *i* such that ``s[i] == x``. Raises - :exc:`ValueError` when *x* is not in the range. - - .. versionadded:: 3.2 - - -.. _typesseq-mutable: - -Mutable Sequence Types ----------------------- - -.. index:: - triple: mutable; sequence; types - object: list + object: bytes object: bytearray - -List and bytearray objects support additional operations that allow in-place -modification of the object. Other mutable sequence types (when added to the -language) should also support these operations. Strings and tuples are -immutable sequence types: such objects cannot be modified once created. The -following operations are defined on mutable sequence types (where *x* is an -arbitrary object). - -Note that while lists allow their items to be of any type, bytearray object -"items" are all integers in the range 0 <= x < 256. - -.. index:: - triple: operations on; sequence; types - triple: operations on; list; type - pair: subscript; assignment - pair: slice; assignment - statement: del - single: append() (sequence method) - single: extend() (sequence method) - single: count() (sequence method) - single: clear() (sequence method) - single: copy() (sequence method) - single: index() (sequence method) - single: insert() (sequence method) - single: pop() (sequence method) - single: remove() (sequence method) - single: reverse() (sequence method) - single: sort() (sequence method) - -+------------------------------+--------------------------------+---------------------+ -| Operation | Result | Notes | -+==============================+================================+=====================+ -| ``s[i] = x`` | item *i* of *s* is replaced by | | -| | *x* | | -+------------------------------+--------------------------------+---------------------+ -| ``s[i:j] = t`` | slice of *s* from *i* to *j* | | -| | is replaced by the contents of | | -| | the iterable *t* | | -+------------------------------+--------------------------------+---------------------+ -| ``del s[i:j]`` | same as ``s[i:j] = []`` | | -+------------------------------+--------------------------------+---------------------+ -| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` | \(1) | -| | are replaced by those of *t* | | -+------------------------------+--------------------------------+---------------------+ -| ``del s[i:j:k]`` | removes the elements of | | -| | ``s[i:j:k]`` from the list | | -+------------------------------+--------------------------------+---------------------+ -| ``s.append(x)`` | same as ``s[len(s):len(s)] = | | -| | [x]`` | | -+------------------------------+--------------------------------+---------------------+ -| ``s.extend(x)`` | same as ``s[len(s):len(s)] = | \(2) | -| | x`` | | -+------------------------------+--------------------------------+---------------------+ -| ``s.clear()`` | remove all items from ``s`` | | -| | | | -+------------------------------+--------------------------------+---------------------+ -| ``s.copy()`` | return a shallow copy of ``s`` | | -| | | | -+------------------------------+--------------------------------+---------------------+ -| ``s.count(x)`` | return number of *i*'s for | | -| | which ``s[i] == x`` | | -+------------------------------+--------------------------------+---------------------+ -| ``s.index(x[, i[, j]])`` | return smallest *k* such that | \(3) | -| | ``s[k] == x`` and ``i <= k < | | -| | j`` | | -+------------------------------+--------------------------------+---------------------+ -| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | \(4) | -+------------------------------+--------------------------------+---------------------+ -| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | \(5) | -| | return x`` | | -+------------------------------+--------------------------------+---------------------+ -| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | \(3) | -+------------------------------+--------------------------------+---------------------+ -| ``s.reverse()`` | reverses the items of *s* in | \(6) | -| | place | | -+------------------------------+--------------------------------+---------------------+ -| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) | -+------------------------------+--------------------------------+---------------------+ - - -Notes: - -(1) - *t* must have the same length as the slice it is replacing. - -(2) - *x* can be any iterable object. - -(3) - Raises :exc:`ValueError` when *x* is not found in *s*. When a negative index is - passed as the second or third parameter to the :meth:`index` method, the sequence - length is added, as for slice indices. If it is still negative, it is truncated - to zero, as for slice indices. - -(4) - When a negative index is passed as the first parameter to the :meth:`insert` - method, the sequence length is added, as for slice indices. If it is still - negative, it is truncated to zero, as for slice indices. - -(5) - The optional argument *i* defaults to ``-1``, so that by default the last - item is removed and returned. - -(6) - The :meth:`sort` and :meth:`reverse` methods modify the sequence in place for - economy of space when sorting or reversing a large sequence. To remind you - that they operate by side effect, they don't return the sorted or reversed - sequence. - -(7) - The :meth:`sort` method takes optional arguments for controlling the - comparisons. Each must be specified as a keyword argument. - - *key* specifies a function of one argument that is used to extract a comparison - key from each list element: ``key=str.lower``. The default value is ``None``. - Use :func:`functools.cmp_to_key` to convert an - old-style *cmp* function to a *key* function. - - - *reverse* is a boolean value. If set to ``True``, then the list elements are - sorted as if each comparison were reversed. - - The :meth:`sort` method is guaranteed to be stable. A - sort is stable if it guarantees not to change the relative order of elements - that compare equal --- this is helpful for sorting in multiple passes (for - example, sort by department, then by salary grade). - - .. impl-detail:: - - While a list is being sorted, the effect of attempting to mutate, or even - inspect, the list is undefined. The C implementation of Python makes the - list appear empty for the duration, and raises :exc:`ValueError` if it can - detect that the list has been mutated during a sort. - -(8) - :meth:`sort` is not supported by :class:`bytearray` objects. - - .. versionadded:: 3.3 - :meth:`clear` and :meth:`!copy` methods. + object: memoryview + module: array + +The core built-in types for manipulating binary data are :class:`bytes` and +:class:`bytearray`. They are supported by :class:`memoryview` which uses +the buffer protocol to access the memory of other binary objects without +needing to make a copy. + +The :mod:`array` module supports efficient storage of basic data types like +32-bit integers and IEEE754 double-precision floating values. + +.. _typebytes: + +Bytes +----- + +.. index:: object: bytes + +Bytes objects are immutable sequences of single bytes. Since many major +binary protocols are based on the ASCII text encoding, bytes objects offer +several methods that are only valid when working with ASCII compatible +data and are closely related to string objects in a variety of other ways. + +Firstly, the syntax for bytes literals is largely the same as that for string +literals, except that a ``b`` prefix is added: + +* Single quotes: ``b'still allows embedded "double" quotes'`` +* Double quotes: ``b"still allows embedded 'single' quotes"``. +* Triple quoted: ``b'''3 single quotes'''``, ``b"""3 double quotes"""`` + +Only ASCII characters are permitted in bytes literals (regardless of the +declared source code encoding). Any binary values over 127 must be entered +into bytes literals using the appropriate escape sequence. + +As with string literals, bytes literals may also use a ``r`` prefix to disable +processing of escape sequences. See :ref:`strings` for more about the various +forms of bytes literal, including supported escape sequences. + +While bytes literals and representations are based on ASCII text, bytes +objects actually behave like immutable sequences of integers, with each +value in the sequence restricted such that ``0 <= x < 256`` (attempts to +violate this restriction will trigger :exc:`ValueError`. This is done +deliberately to emphasise that while many binary formats include ASCII based +elements and can be usefully manipulated with some text-oriented algorithms, +this is not generally the case for arbitrary binary data (blindly applying +text processing algorithms to binary data formats that are not ASCII +compatible will usually lead to data corruption). + +In addition to the literal forms, bytes objects can be created in a number of +other ways: + +* A zero-filled bytes object of a specified length: ``bytes(10)`` +* From an iterable of integers: ``bytes(range(20))`` +* Copying existing binary data via the buffer protocol: ``bytes(obj)`` + +Since bytes objects are sequences of integers, for a bytes object *b*, +``b[0]`` will be an integer, while ``b[0:1]`` will be a bytes object of +length 1. (This contrasts with text strings, where both indexing and +slicing will produce a string of length 1) + +The representation of bytes objects uses the literal format (``b'...'``) +since it is often more useful than e.g. ``bytes([46, 46, 46])``. You can +always convert a bytes object into a list of integers using ``list(b)``. + + +.. note:: + For Python 2.x users: In the Python 2.x series, a variety of implicit + conversions between 8-bit strings (the closest thing 2.x offers to a + built-in binary data type) and Unicode strings were permitted. This was a + backwards compatibility workaround to account for the fact that Python + originally only supported 8-bit text, and Unicode text was a later + addition. In Python 3.x, those implicit conversions are gone - conversions + between 8-bit binary data and Unicode text must be explicit, and bytes and + string objects will always compare unequal. + + +.. _typebytearray: + +Bytearray Objects +----------------- + +.. index:: object: bytearray + +:class:`bytearray` objects are a mutable counterpart to :class:`bytes` +objects. There is no dedicated literal syntax for bytearray objects, instead +they are always created by calling the constructor: + +* Creating an empty instance: ``bytearray()`` +* Creating a zero-filled instance with a given length: ``bytearray(10)`` +* From an iterable of integers: ``bytearray(range(20))`` +* Copying existing binary data via the buffer protocol: ``bytearray(b'Hi!)`` + +As bytearray objects are mutable, they support the +:ref:`mutable ` sequence operations in addition to the +common bytes and bytearray operations described in :ref:`bytes-methods`. .. _bytes-methods: -Bytes and Byte Array Methods ----------------------------- +Bytes and Bytearray Operations +------------------------------ .. index:: pair: bytes; methods pair: bytearray; methods -Bytes and bytearray objects, being "strings of bytes", have all methods found on -strings, with the exception of :func:`encode`, :func:`format` and -:func:`isidentifier`, which do not make sense with these types. For converting -the objects to strings, they have a :func:`decode` method. - -Wherever one of these methods needs to interpret the bytes as characters -(e.g. the :func:`is...` methods), the ASCII character set is assumed. - -.. versionadded:: 3.3 - The functions :func:`count`, :func:`find`, :func:`index`, - :func:`rfind` and :func:`rindex` have additional semantics compared to - the corresponding string functions: They also accept an integer in - range 0 to 255 (a byte) as their first argument. +Both bytes and bytearray objects support the :ref:`common ` +sequence operations. They interoperate not just with operands of the same +type, but with any object that supports the +:ref:`buffer protocol `. Due to this flexibility, they can be +freely mixed in operations without causing errors. However, the return type +of the result may depend on the order of operands. + +Due to the common use of ASCII text as the basis for binary protocols, bytes +and bytearray objects provide almost all methods found on text strings, with +the exceptions of: + +* :meth:`str.encode` (which converts text strings to bytes objects) +* :meth:`str.format` and :meth:`str.format_map` (which are used to format + text for display to users) +* :meth:`str.isidentifier`, :meth:`str.isnumeric`, :meth:`str.isdecimal`, + :meth:`str.isprintable` (which are used to check various properties of + text strings which are not typically applicable to binary protocols). + +All other string methods are supported, although sometimes with slight +differences in functionality and semantics (as described below). .. note:: The methods on bytes and bytearray objects don't accept strings as their arguments, just as the methods on strings don't accept bytes as their - arguments. For example, you have to write :: + arguments. For example, you have to write:: a = "abc" b = a.replace("a", "f") - and :: + and:: a = b"abc" b = a.replace(b"a", b"f") +Whenever a bytes or bytearray method needs to interpret the bytes as +characters (e.g. the :meth:`is...` methods, :meth:`split`, :meth:`strip`), +the ASCII character set is assumed (text strings use Unicode semantics). + +.. note:: + Using these ASCII based methods to manipulate binary data that is not + stored in an ASCII based format may lead to data corruption. + +The search operations (:keyword:`in`, :meth:`count`, :meth:`find`, +:meth:`index`, :meth:`rfind` and :meth:`rindex`) all accept both integers +in the range 0 to 255 as well as bytes and byte array sequences. + +.. versionchanged:: 3.3 + All of the search methods also accept an integer in range 0 to 255 + (a byte) as their first argument. + + +Each bytes and bytearray instance provides a :meth:`decode` convenience +method that is the inverse of "meth:`str.encode`: .. method:: bytes.decode(encoding="utf-8", errors="strict") bytearray.decode(encoding="utf-8", errors="strict") @@ -1887,8 +2121,10 @@ .. versionchanged:: 3.1 Added support for keyword arguments. - -The bytes and bytearray types have an additional class method: +Since 2 hexadecimal digits correspond precisely to a single byte, hexadecimal +numbers are a commonly used format for describing binary data. Accordingly, +the bytes and bytearray types have an additional class method to read data in +that format: .. classmethod:: bytes.fromhex(string) bytearray.fromhex(string) @@ -1897,8 +2133,8 @@ decoding the given string object. The string must contain two hexadecimal digits per byte, spaces are ignored. - >>> bytes.fromhex('f0 f1f2 ') - b'\xf0\xf1\xf2' + >>> bytes.fromhex('2Ef0 F1f2 ') + b'.\xf0\xf1\xf2' The maketrans and translate methods differ in semantics from the versions @@ -1932,471 +2168,10 @@ .. versionadded:: 3.1 -.. _types-set: - -Set Types --- :class:`set`, :class:`frozenset` -============================================== - -.. index:: object: set - -A :dfn:`set` object is an unordered collection of distinct :term:`hashable` objects. -Common uses include membership testing, removing duplicates from a sequence, and -computing mathematical operations such as intersection, union, difference, and -symmetric difference. -(For other containers see the built in :class:`dict`, :class:`list`, -and :class:`tuple` classes, and the :mod:`collections` module.) - -Like other collections, sets support ``x in set``, ``len(set)``, and ``for x in -set``. Being an unordered collection, sets do not record element position or -order of insertion. Accordingly, sets do not support indexing, slicing, or -other sequence-like behavior. - -There are currently two built-in set types, :class:`set` and :class:`frozenset`. -The :class:`set` type is mutable --- the contents can be changed using methods -like :meth:`add` and :meth:`remove`. Since it is mutable, it has no hash value -and cannot be used as either a dictionary key or as an element of another set. -The :class:`frozenset` type is immutable and :term:`hashable` --- its contents cannot be -altered after it is created; it can therefore be used as a dictionary key or as -an element of another set. - -Non-empty sets (not frozensets) can be created by placing a comma-separated list -of elements within braces, for example: ``{'jack', 'sjoerd'}``, in addition to the -:class:`set` constructor. - -The constructors for both classes work the same: - -.. class:: set([iterable]) - frozenset([iterable]) - - Return a new set or frozenset object whose elements are taken from - *iterable*. The elements of a set must be hashable. To represent sets of - sets, the inner sets must be :class:`frozenset` objects. If *iterable* is - not specified, a new empty set is returned. - - Instances of :class:`set` and :class:`frozenset` provide the following - operations: - - .. describe:: len(s) - - Return the cardinality of set *s*. - - .. describe:: x in s - - Test *x* for membership in *s*. - - .. describe:: x not in s - - Test *x* for non-membership in *s*. - - .. method:: isdisjoint(other) - - Return True if the set has no elements in common with *other*. Sets are - disjoint if and only if their intersection is the empty set. - - .. method:: issubset(other) - set <= other - - Test whether every element in the set is in *other*. - - .. method:: set < other - - Test whether the set is a true subset of *other*, that is, - ``set <= other and set != other``. - - .. method:: issuperset(other) - set >= other - - Test whether every element in *other* is in the set. - - .. method:: set > other - - Test whether the set is a true superset of *other*, that is, ``set >= - other and set != other``. - - .. method:: union(other, ...) - set | other | ... - - Return a new set with elements from the set and all others. - - .. method:: intersection(other, ...) - set & other & ... - - Return a new set with elements common to the set and all others. - - .. method:: difference(other, ...) - set - other - ... - - Return a new set with elements in the set that are not in the others. - - .. method:: symmetric_difference(other) - set ^ other - - Return a new set with elements in either the set or *other* but not both. - - .. method:: copy() - - Return a new set with a shallow copy of *s*. - - - Note, the non-operator versions of :meth:`union`, :meth:`intersection`, - :meth:`difference`, and :meth:`symmetric_difference`, :meth:`issubset`, and - :meth:`issuperset` methods will accept any iterable as an argument. In - contrast, their operator based counterparts require their arguments to be - sets. This precludes error-prone constructions like ``set('abc') & 'cbs'`` - in favor of the more readable ``set('abc').intersection('cbs')``. - - Both :class:`set` and :class:`frozenset` support set to set comparisons. Two - sets are equal if and only if every element of each set is contained in the - other (each is a subset of the other). A set is less than another set if and - only if the first set is a proper subset of the second set (is a subset, but - is not equal). A set is greater than another set if and only if the first set - is a proper superset of the second set (is a superset, but is not equal). - - Instances of :class:`set` are compared to instances of :class:`frozenset` - based on their members. For example, ``set('abc') == frozenset('abc')`` - returns ``True`` and so does ``set('abc') in set([frozenset('abc')])``. - - The subset and equality comparisons do not generalize to a complete ordering - function. For example, any two disjoint sets are not equal and are not - subsets of each other, so *all* of the following return ``False``: ``ab``. - - Since sets only define partial ordering (subset relationships), the output of - the :meth:`list.sort` method is undefined for lists of sets. - - Set elements, like dictionary keys, must be :term:`hashable`. - - Binary operations that mix :class:`set` instances with :class:`frozenset` - return the type of the first operand. For example: ``frozenset('ab') | - set('bc')`` returns an instance of :class:`frozenset`. - - The following table lists operations available for :class:`set` that do not - apply to immutable instances of :class:`frozenset`: - - .. method:: update(other, ...) - set |= other | ... - - Update the set, adding elements from all others. - - .. method:: intersection_update(other, ...) - set &= other & ... - - Update the set, keeping only elements found in it and all others. - - .. method:: difference_update(other, ...) - set -= other | ... - - Update the set, removing elements found in others. - - .. method:: symmetric_difference_update(other) - set ^= other - - Update the set, keeping only elements found in either set, but not in both. - - .. method:: add(elem) - - Add element *elem* to the set. - - .. method:: remove(elem) - - Remove element *elem* from the set. Raises :exc:`KeyError` if *elem* is - not contained in the set. - - .. method:: discard(elem) - - Remove element *elem* from the set if it is present. - - .. method:: pop() - - Remove and return an arbitrary element from the set. Raises - :exc:`KeyError` if the set is empty. - - .. method:: clear() - - Remove all elements from the set. - - - Note, the non-operator versions of the :meth:`update`, - :meth:`intersection_update`, :meth:`difference_update`, and - :meth:`symmetric_difference_update` methods will accept any iterable as an - argument. - - Note, the *elem* argument to the :meth:`__contains__`, :meth:`remove`, and - :meth:`discard` methods may be a set. To support searching for an equivalent - frozenset, the *elem* set is temporarily mutated during the search and then - restored. During the search, the *elem* set should not be read or mutated - since it does not have a meaningful value. - - -.. _typesmapping: - -Mapping Types --- :class:`dict` -=============================== - -.. index:: - object: mapping - object: dictionary - triple: operations on; mapping; types - triple: operations on; dictionary; type - statement: del - builtin: len - -A :dfn:`mapping` object maps :term:`hashable` values to arbitrary objects. -Mappings are mutable objects. There is currently only one standard mapping -type, the :dfn:`dictionary`. (For other containers see the built in -:class:`list`, :class:`set`, and :class:`tuple` classes, and the -:mod:`collections` module.) - -A dictionary's keys are *almost* arbitrary values. Values that are not -:term:`hashable`, that is, values containing lists, dictionaries or other -mutable types (that are compared by value rather than by object identity) may -not be used as keys. Numeric types used for keys obey the normal rules for -numeric comparison: if two numbers compare equal (such as ``1`` and ``1.0``) -then they can be used interchangeably to index the same dictionary entry. (Note -however, that since computers store floating-point numbers as approximations it -is usually unwise to use them as dictionary keys.) - -Dictionaries can be created by placing a comma-separated list of ``key: value`` -pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098: -'jack', 4127: 'sjoerd'}``, or by the :class:`dict` constructor. - -.. class:: dict([arg]) - - Return a new dictionary initialized from an optional positional argument or - from a set of keyword arguments. If no arguments are given, return a new - empty dictionary. If the positional argument *arg* is a mapping object, - return a dictionary mapping the same keys to the same values as does the - mapping object. Otherwise the positional argument must be a sequence, a - container that supports iteration, or an iterator object. The elements of - the argument must each also be of one of those kinds, and each must in turn - contain exactly two objects. The first is used as a key in the new - dictionary, and the second as the key's value. If a given key is seen more - than once, the last value associated with it is retained in the new - dictionary. - - If keyword arguments are given, the keywords themselves with their associated - values are added as items to the dictionary. If a key is specified both in - the positional argument and as a keyword argument, the value associated with - the keyword is retained in the dictionary. For example, these all return a - dictionary equal to ``{"one": 1, "two": 2}``: - - * ``dict(one=1, two=2)`` - * ``dict({'one': 1, 'two': 2})`` - * ``dict(zip(('one', 'two'), (1, 2)))`` - * ``dict([['two', 2], ['one', 1]])`` - - The first example only works for keys that are valid Python identifiers; the - others work with any valid keys. - - - These are the operations that dictionaries support (and therefore, custom - mapping types should support too): - - .. describe:: len(d) - - Return the number of items in the dictionary *d*. - - .. describe:: d[key] - - Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is - not in the map. - - If a subclass of dict defines a method :meth:`__missing__`, if the key *key* - is not present, the ``d[key]`` operation calls that method with the key *key* - as argument. The ``d[key]`` operation then returns or raises whatever is - returned or raised by the ``__missing__(key)`` call if the key is not - present. No other operations or methods invoke :meth:`__missing__`. If - :meth:`__missing__` is not defined, :exc:`KeyError` is raised. - :meth:`__missing__` must be a method; it cannot be an instance variable:: - - >>> class Counter(dict): - ... def __missing__(self, key): - ... return 0 - >>> c = Counter() - >>> c['red'] - 0 - >>> c['red'] += 1 - >>> c['red'] - 1 - - See :class:`collections.Counter` for a complete implementation including - other methods helpful for accumulating and managing tallies. - - .. describe:: d[key] = value - - Set ``d[key]`` to *value*. - - .. describe:: del d[key] - - Remove ``d[key]`` from *d*. Raises a :exc:`KeyError` if *key* is not in the - map. - - .. describe:: key in d - - Return ``True`` if *d* has a key *key*, else ``False``. - - .. describe:: key not in d - - Equivalent to ``not key in d``. - - .. describe:: iter(d) - - Return an iterator over the keys of the dictionary. This is a shortcut - for ``iter(d.keys())``. - - .. method:: clear() - - Remove all items from the dictionary. - - .. method:: copy() - - Return a shallow copy of the dictionary. - - .. classmethod:: fromkeys(seq[, value]) - - Create a new dictionary with keys from *seq* and values set to *value*. - - :meth:`fromkeys` is a class method that returns a new dictionary. *value* - defaults to ``None``. - - .. method:: get(key[, default]) - - Return the value for *key* if *key* is in the dictionary, else *default*. - If *default* is not given, it defaults to ``None``, so that this method - never raises a :exc:`KeyError`. - - .. method:: items() - - Return a new view of the dictionary's items (``(key, value)`` pairs). - See the :ref:`documentation of view objects `. - - .. method:: keys() - - Return a new view of the dictionary's keys. See the :ref:`documentation - of view objects `. - - .. method:: pop(key[, default]) - - If *key* is in the dictionary, remove it and return its value, else return - *default*. If *default* is not given and *key* is not in the dictionary, - a :exc:`KeyError` is raised. - - .. method:: popitem() - - Remove and return an arbitrary ``(key, value)`` pair from the dictionary. - - :meth:`popitem` is useful to destructively iterate over a dictionary, as - often used in set algorithms. If the dictionary is empty, calling - :meth:`popitem` raises a :exc:`KeyError`. - - .. method:: setdefault(key[, default]) - - If *key* is in the dictionary, return its value. If not, insert *key* - with a value of *default* and return *default*. *default* defaults to - ``None``. - - .. method:: update([other]) - - Update the dictionary with the key/value pairs from *other*, overwriting - existing keys. Return ``None``. - - :meth:`update` accepts either another dictionary object or an iterable of - key/value pairs (as tuples or other iterables of length two). If keyword - arguments are specified, the dictionary is then updated with those - key/value pairs: ``d.update(red=1, blue=2)``. - - .. method:: values() - - Return a new view of the dictionary's values. See the - :ref:`documentation of view objects `. - -.. seealso:: - :class:`types.MappingProxyType` can be used to create a read-only view - of a :class:`dict`. - - -.. _dict-views: - -Dictionary view objects ------------------------ - -The objects returned by :meth:`dict.keys`, :meth:`dict.values` and -:meth:`dict.items` are *view objects*. They provide a dynamic view on the -dictionary's entries, which means that when the dictionary changes, the view -reflects these changes. - -Dictionary views can be iterated over to yield their respective data, and -support membership tests: - -.. describe:: len(dictview) - - Return the number of entries in the dictionary. - -.. describe:: iter(dictview) - - Return an iterator over the keys, values or items (represented as tuples of - ``(key, value)``) in the dictionary. - - Keys and values are iterated over in an arbitrary order which is non-random, - varies across Python implementations, and depends on the dictionary's history - of insertions and deletions. If keys, values and items views are iterated - over with no intervening modifications to the dictionary, the order of items - will directly correspond. This allows the creation of ``(value, key)`` pairs - using :func:`zip`: ``pairs = zip(d.values(), d.keys())``. Another way to - create the same list is ``pairs = [(v, k) for (k, v) in d.items()]``. - - Iterating views while adding or deleting entries in the dictionary may raise - a :exc:`RuntimeError` or fail to iterate over all entries. - -.. describe:: x in dictview - - Return ``True`` if *x* is in the underlying dictionary's keys, values or - items (in the latter case, *x* should be a ``(key, value)`` tuple). - - -Keys views are set-like since their entries are unique and hashable. If all -values are hashable, so that ``(key, value)`` pairs are unique and hashable, -then the items view is also set-like. (Values views are not treated as set-like -since the entries are generally not unique.) For set-like views, all of the -operations defined for the abstract base class :class:`collections.Set` are -available (for example, ``==``, ``<``, or ``^``). - -An example of dictionary view usage:: - - >>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500} - >>> keys = dishes.keys() - >>> values = dishes.values() - - >>> # iteration - >>> n = 0 - >>> for val in values: - ... n += val - >>> print(n) - 504 - - >>> # keys and values are iterated over in the same order - >>> list(keys) - ['eggs', 'bacon', 'sausage', 'spam'] - >>> list(values) - [2, 1, 1, 500] - - >>> # view objects are dynamic and reflect dict changes - >>> del dishes['eggs'] - >>> del dishes['sausage'] - >>> list(keys) - ['spam', 'bacon'] - - >>> # set operations - >>> keys & {'eggs', 'bacon', 'salad'} - {'bacon'} - >>> keys ^ {'sausage', 'juice'} - {'juice', 'sausage', 'bacon', 'spam'} - - .. _typememoryview: -memoryview type -=============== +Memory Views +------------ :class:`memoryview` objects allow Python code to access the internal data of an object that supports the :ref:`buffer protocol ` without @@ -2777,6 +2552,467 @@ .. versionadded:: 3.3 +.. _types-set: + +Set Types --- :class:`set`, :class:`frozenset` +============================================== + +.. index:: object: set + +A :dfn:`set` object is an unordered collection of distinct :term:`hashable` objects. +Common uses include membership testing, removing duplicates from a sequence, and +computing mathematical operations such as intersection, union, difference, and +symmetric difference. +(For other containers see the built in :class:`dict`, :class:`list`, +and :class:`tuple` classes, and the :mod:`collections` module.) + +Like other collections, sets support ``x in set``, ``len(set)``, and ``for x in +set``. Being an unordered collection, sets do not record element position or +order of insertion. Accordingly, sets do not support indexing, slicing, or +other sequence-like behavior. + +There are currently two built-in set types, :class:`set` and :class:`frozenset`. +The :class:`set` type is mutable --- the contents can be changed using methods +like :meth:`add` and :meth:`remove`. Since it is mutable, it has no hash value +and cannot be used as either a dictionary key or as an element of another set. +The :class:`frozenset` type is immutable and :term:`hashable` --- its contents cannot be +altered after it is created; it can therefore be used as a dictionary key or as +an element of another set. + +Non-empty sets (not frozensets) can be created by placing a comma-separated list +of elements within braces, for example: ``{'jack', 'sjoerd'}``, in addition to the +:class:`set` constructor. + +The constructors for both classes work the same: + +.. class:: set([iterable]) + frozenset([iterable]) + + Return a new set or frozenset object whose elements are taken from + *iterable*. The elements of a set must be hashable. To represent sets of + sets, the inner sets must be :class:`frozenset` objects. If *iterable* is + not specified, a new empty set is returned. + + Instances of :class:`set` and :class:`frozenset` provide the following + operations: + + .. describe:: len(s) + + Return the cardinality of set *s*. + + .. describe:: x in s + + Test *x* for membership in *s*. + + .. describe:: x not in s + + Test *x* for non-membership in *s*. + + .. method:: isdisjoint(other) + + Return True if the set has no elements in common with *other*. Sets are + disjoint if and only if their intersection is the empty set. + + .. method:: issubset(other) + set <= other + + Test whether every element in the set is in *other*. + + .. method:: set < other + + Test whether the set is a true subset of *other*, that is, + ``set <= other and set != other``. + + .. method:: issuperset(other) + set >= other + + Test whether every element in *other* is in the set. + + .. method:: set > other + + Test whether the set is a true superset of *other*, that is, ``set >= + other and set != other``. + + .. method:: union(other, ...) + set | other | ... + + Return a new set with elements from the set and all others. + + .. method:: intersection(other, ...) + set & other & ... + + Return a new set with elements common to the set and all others. + + .. method:: difference(other, ...) + set - other - ... + + Return a new set with elements in the set that are not in the others. + + .. method:: symmetric_difference(other) + set ^ other + + Return a new set with elements in either the set or *other* but not both. + + .. method:: copy() + + Return a new set with a shallow copy of *s*. + + + Note, the non-operator versions of :meth:`union`, :meth:`intersection`, + :meth:`difference`, and :meth:`symmetric_difference`, :meth:`issubset`, and + :meth:`issuperset` methods will accept any iterable as an argument. In + contrast, their operator based counterparts require their arguments to be + sets. This precludes error-prone constructions like ``set('abc') & 'cbs'`` + in favor of the more readable ``set('abc').intersection('cbs')``. + + Both :class:`set` and :class:`frozenset` support set to set comparisons. Two + sets are equal if and only if every element of each set is contained in the + other (each is a subset of the other). A set is less than another set if and + only if the first set is a proper subset of the second set (is a subset, but + is not equal). A set is greater than another set if and only if the first set + is a proper superset of the second set (is a superset, but is not equal). + + Instances of :class:`set` are compared to instances of :class:`frozenset` + based on their members. For example, ``set('abc') == frozenset('abc')`` + returns ``True`` and so does ``set('abc') in set([frozenset('abc')])``. + + The subset and equality comparisons do not generalize to a complete ordering + function. For example, any two disjoint sets are not equal and are not + subsets of each other, so *all* of the following return ``False``: ``ab``. + + Since sets only define partial ordering (subset relationships), the output of + the :meth:`list.sort` method is undefined for lists of sets. + + Set elements, like dictionary keys, must be :term:`hashable`. + + Binary operations that mix :class:`set` instances with :class:`frozenset` + return the type of the first operand. For example: ``frozenset('ab') | + set('bc')`` returns an instance of :class:`frozenset`. + + The following table lists operations available for :class:`set` that do not + apply to immutable instances of :class:`frozenset`: + + .. method:: update(other, ...) + set |= other | ... + + Update the set, adding elements from all others. + + .. method:: intersection_update(other, ...) + set &= other & ... + + Update the set, keeping only elements found in it and all others. + + .. method:: difference_update(other, ...) + set -= other | ... + + Update the set, removing elements found in others. + + .. method:: symmetric_difference_update(other) + set ^= other + + Update the set, keeping only elements found in either set, but not in both. + + .. method:: add(elem) + + Add element *elem* to the set. + + .. method:: remove(elem) + + Remove element *elem* from the set. Raises :exc:`KeyError` if *elem* is + not contained in the set. + + .. method:: discard(elem) + + Remove element *elem* from the set if it is present. + + .. method:: pop() + + Remove and return an arbitrary element from the set. Raises + :exc:`KeyError` if the set is empty. + + .. method:: clear() + + Remove all elements from the set. + + + Note, the non-operator versions of the :meth:`update`, + :meth:`intersection_update`, :meth:`difference_update`, and + :meth:`symmetric_difference_update` methods will accept any iterable as an + argument. + + Note, the *elem* argument to the :meth:`__contains__`, :meth:`remove`, and + :meth:`discard` methods may be a set. To support searching for an equivalent + frozenset, the *elem* set is temporarily mutated during the search and then + restored. During the search, the *elem* set should not be read or mutated + since it does not have a meaningful value. + + +.. _typesmapping: + +Mapping Types --- :class:`dict` +=============================== + +.. index:: + object: mapping + object: dictionary + triple: operations on; mapping; types + triple: operations on; dictionary; type + statement: del + builtin: len + +A :dfn:`mapping` object maps :term:`hashable` values to arbitrary objects. +Mappings are mutable objects. There is currently only one standard mapping +type, the :dfn:`dictionary`. (For other containers see the built in +:class:`list`, :class:`set`, and :class:`tuple` classes, and the +:mod:`collections` module.) + +A dictionary's keys are *almost* arbitrary values. Values that are not +:term:`hashable`, that is, values containing lists, dictionaries or other +mutable types (that are compared by value rather than by object identity) may +not be used as keys. Numeric types used for keys obey the normal rules for +numeric comparison: if two numbers compare equal (such as ``1`` and ``1.0``) +then they can be used interchangeably to index the same dictionary entry. (Note +however, that since computers store floating-point numbers as approximations it +is usually unwise to use them as dictionary keys.) + +Dictionaries can be created by placing a comma-separated list of ``key: value`` +pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098: +'jack', 4127: 'sjoerd'}``, or by the :class:`dict` constructor. + +.. class:: dict([arg]) + + Return a new dictionary initialized from an optional positional argument or + from a set of keyword arguments. If no arguments are given, return a new + empty dictionary. If the positional argument *arg* is a mapping object, + return a dictionary mapping the same keys to the same values as does the + mapping object. Otherwise the positional argument must be a sequence, a + container that supports iteration, or an iterator object. The elements of + the argument must each also be of one of those kinds, and each must in turn + contain exactly two objects. The first is used as a key in the new + dictionary, and the second as the key's value. If a given key is seen more + than once, the last value associated with it is retained in the new + dictionary. + + If keyword arguments are given, the keywords themselves with their associated + values are added as items to the dictionary. If a key is specified both in + the positional argument and as a keyword argument, the value associated with + the keyword is retained in the dictionary. For example, these all return a + dictionary equal to ``{"one": 1, "two": 2}``: + + * ``dict(one=1, two=2)`` + * ``dict({'one': 1, 'two': 2})`` + * ``dict(zip(('one', 'two'), (1, 2)))`` + * ``dict([['two', 2], ['one', 1]])`` + + The first example only works for keys that are valid Python identifiers; the + others work with any valid keys. + + + These are the operations that dictionaries support (and therefore, custom + mapping types should support too): + + .. describe:: len(d) + + Return the number of items in the dictionary *d*. + + .. describe:: d[key] + + Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is + not in the map. + + If a subclass of dict defines a method :meth:`__missing__`, if the key *key* + is not present, the ``d[key]`` operation calls that method with the key *key* + as argument. The ``d[key]`` operation then returns or raises whatever is + returned or raised by the ``__missing__(key)`` call if the key is not + present. No other operations or methods invoke :meth:`__missing__`. If + :meth:`__missing__` is not defined, :exc:`KeyError` is raised. + :meth:`__missing__` must be a method; it cannot be an instance variable:: + + >>> class Counter(dict): + ... def __missing__(self, key): + ... return 0 + >>> c = Counter() + >>> c['red'] + 0 + >>> c['red'] += 1 + >>> c['red'] + 1 + + See :class:`collections.Counter` for a complete implementation including + other methods helpful for accumulating and managing tallies. + + .. describe:: d[key] = value + + Set ``d[key]`` to *value*. + + .. describe:: del d[key] + + Remove ``d[key]`` from *d*. Raises a :exc:`KeyError` if *key* is not in the + map. + + .. describe:: key in d + + Return ``True`` if *d* has a key *key*, else ``False``. + + .. describe:: key not in d + + Equivalent to ``not key in d``. + + .. describe:: iter(d) + + Return an iterator over the keys of the dictionary. This is a shortcut + for ``iter(d.keys())``. + + .. method:: clear() + + Remove all items from the dictionary. + + .. method:: copy() + + Return a shallow copy of the dictionary. + + .. classmethod:: fromkeys(seq[, value]) + + Create a new dictionary with keys from *seq* and values set to *value*. + + :meth:`fromkeys` is a class method that returns a new dictionary. *value* + defaults to ``None``. + + .. method:: get(key[, default]) + + Return the value for *key* if *key* is in the dictionary, else *default*. + If *default* is not given, it defaults to ``None``, so that this method + never raises a :exc:`KeyError`. + + .. method:: items() + + Return a new view of the dictionary's items (``(key, value)`` pairs). + See the :ref:`documentation of view objects `. + + .. method:: keys() + + Return a new view of the dictionary's keys. See the :ref:`documentation + of view objects `. + + .. method:: pop(key[, default]) + + If *key* is in the dictionary, remove it and return its value, else return + *default*. If *default* is not given and *key* is not in the dictionary, + a :exc:`KeyError` is raised. + + .. method:: popitem() + + Remove and return an arbitrary ``(key, value)`` pair from the dictionary. + + :meth:`popitem` is useful to destructively iterate over a dictionary, as + often used in set algorithms. If the dictionary is empty, calling + :meth:`popitem` raises a :exc:`KeyError`. + + .. method:: setdefault(key[, default]) + + If *key* is in the dictionary, return its value. If not, insert *key* + with a value of *default* and return *default*. *default* defaults to + ``None``. + + .. method:: update([other]) + + Update the dictionary with the key/value pairs from *other*, overwriting + existing keys. Return ``None``. + + :meth:`update` accepts either another dictionary object or an iterable of + key/value pairs (as tuples or other iterables of length two). If keyword + arguments are specified, the dictionary is then updated with those + key/value pairs: ``d.update(red=1, blue=2)``. + + .. method:: values() + + Return a new view of the dictionary's values. See the + :ref:`documentation of view objects `. + +.. seealso:: + :class:`types.MappingProxyType` can be used to create a read-only view + of a :class:`dict`. + + +.. _dict-views: + +Dictionary view objects +----------------------- + +The objects returned by :meth:`dict.keys`, :meth:`dict.values` and +:meth:`dict.items` are *view objects*. They provide a dynamic view on the +dictionary's entries, which means that when the dictionary changes, the view +reflects these changes. + +Dictionary views can be iterated over to yield their respective data, and +support membership tests: + +.. describe:: len(dictview) + + Return the number of entries in the dictionary. + +.. describe:: iter(dictview) + + Return an iterator over the keys, values or items (represented as tuples of + ``(key, value)``) in the dictionary. + + Keys and values are iterated over in an arbitrary order which is non-random, + varies across Python implementations, and depends on the dictionary's history + of insertions and deletions. If keys, values and items views are iterated + over with no intervening modifications to the dictionary, the order of items + will directly correspond. This allows the creation of ``(value, key)`` pairs + using :func:`zip`: ``pairs = zip(d.values(), d.keys())``. Another way to + create the same list is ``pairs = [(v, k) for (k, v) in d.items()]``. + + Iterating views while adding or deleting entries in the dictionary may raise + a :exc:`RuntimeError` or fail to iterate over all entries. + +.. describe:: x in dictview + + Return ``True`` if *x* is in the underlying dictionary's keys, values or + items (in the latter case, *x* should be a ``(key, value)`` tuple). + + +Keys views are set-like since their entries are unique and hashable. If all +values are hashable, so that ``(key, value)`` pairs are unique and hashable, +then the items view is also set-like. (Values views are not treated as set-like +since the entries are generally not unique.) For set-like views, all of the +operations defined for the abstract base class :class:`collections.abc.Set` are +available (for example, ``==``, ``<``, or ``^``). + +An example of dictionary view usage:: + + >>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500} + >>> keys = dishes.keys() + >>> values = dishes.values() + + >>> # iteration + >>> n = 0 + >>> for val in values: + ... n += val + >>> print(n) + 504 + + >>> # keys and values are iterated over in the same order + >>> list(keys) + ['eggs', 'bacon', 'sausage', 'spam'] + >>> list(values) + [2, 1, 1, 500] + + >>> # view objects are dynamic and reflect dict changes + >>> del dishes['eggs'] + >>> del dishes['sausage'] + >>> list(keys) + ['spam', 'bacon'] + + >>> # set operations + >>> keys & {'eggs', 'bacon', 'salad'} + {'bacon'} + >>> keys ^ {'sausage', 'juice'} + {'juice', 'sausage', 'bacon', 'spam'} + + .. _typecontextmanager: Context Manager Types diff --git a/Doc/library/strings.rst b/Doc/library/text.rst rename from Doc/library/strings.rst rename to Doc/library/text.rst --- a/Doc/library/strings.rst +++ b/Doc/library/text.rst @@ -1,27 +1,24 @@ .. _stringservices: +.. _textservices: -*************** -String Services -*************** +************************ +Text Processing Services +************************ The modules described in this chapter provide a wide range of string -manipulation operations. +manipulation operations and other text processing services. -In addition, Python's built-in string classes support the sequence type methods -described in the :ref:`typesseq` section, and also the string-specific methods -described in the :ref:`string-methods` section. To output formatted strings, -see the :ref:`string-formatting` section. Also, see the :mod:`re` module for -string functions based on regular expressions. +The :mod:`codecs` module described under :ref:`binaryservices` is also +highly relevant to text processing. In addition, see the documentation for +Python's built-in string type in :ref:`textseq`. .. toctree:: string.rst re.rst - struct.rst difflib.rst textwrap.rst - codecs.rst unicodedata.rst stringprep.rst 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 @@ -830,7 +830,10 @@ * The :class:`str` type gets a new :meth:`~str.casefold` method: return a casefolded copy of the string, casefolded strings may be used for caseless matching. For example, ``'?'.casefold()`` returns ``'ss'``. - +* The sequence documentation has been substantially rewritten to better + explain the binary/text sequence distinction and to provide specific + documentation sections for the individual builtin sequence types + (:issue:`4966`) New Modules =========== diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,9 @@ Documentation ------------- +- Issue #4966: Bring the sequence docs up to date for the Py3k transition + and the many language enhancements since they were original written + - The "path importer" misnomer has been replaced with Eric Snow's more-awkward-but-at-least-not-wrong suggestion of "path based finder" in the import system reference docs -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 10:06:08 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 10:06:08 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Break_up_the_=27someos=27_?= =?utf-8?q?docs_classification_based_on_a_more_user-focused_scheme=2C?= Message-ID: <3X0ndr6wyWzQ5G@mail.python.org> http://hg.python.org/cpython/rev/717344a837ab changeset: 78666:717344a837ab user: Nick Coghlan date: Mon Aug 20 18:05:46 2012 +1000 summary: Break up the 'someos' docs classification based on a more user-focused scheme, including creation of a separate 'Concurrent Execution' section files: Doc/library/concurrency.rst | 31 +++++++++++++++++++++++++ Doc/library/datatypes.rst | 2 - Doc/library/index.rst | 2 +- Doc/library/ipc.rst | 6 ++-- Doc/library/someos.rst | 24 ------------------- Doc/library/text.rst | 2 + Misc/NEWS | 7 +++++ 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Doc/library/concurrency.rst b/Doc/library/concurrency.rst new file mode 100644 --- /dev/null +++ b/Doc/library/concurrency.rst @@ -0,0 +1,31 @@ +.. _concurrency: + +******************** +Concurrent Execution +******************** + +The modules described in this chapter provide support for concurrent +execution of code. The appropriate choice of tool will depend on the +task to be executed (CPU bound vs IO bound) and preferred style of +development (event driven cooperative multitasking vs preemptive +multitasking) Here's an overview: + + +.. toctree:: + + threading.rst + multiprocessing.rst + concurrent.futures.rst + subprocess.rst + sched.rst + queue.rst + select.rst + + +The following are support modules for some of the above services: + +.. toctree:: + + dummy_threading.rst + _thread.rst + _dummy_thread.rst diff --git a/Doc/library/datatypes.rst b/Doc/library/datatypes.rst --- a/Doc/library/datatypes.rst +++ b/Doc/library/datatypes.rst @@ -25,8 +25,6 @@ heapq.rst bisect.rst array.rst - sched.rst - queue.rst weakref.rst types.rst copy.rst diff --git a/Doc/library/index.rst b/Doc/library/index.rst --- a/Doc/library/index.rst +++ b/Doc/library/index.rst @@ -57,7 +57,7 @@ fileformats.rst crypto.rst allos.rst - someos.rst + concurrency.rst ipc.rst netdata.rst markup.rst diff --git a/Doc/library/ipc.rst b/Doc/library/ipc.rst --- a/Doc/library/ipc.rst +++ b/Doc/library/ipc.rst @@ -8,7 +8,7 @@ to communicate. Some modules only work for two processes that are on the same machine, e.g. -:mod:`signal` and :mod:`subprocess`. Other modules support networking protocols +:mod:`signal` and :mod:`mmap`. Other modules support networking protocols that two or more processes can used to communicate across machines. The list of modules described in this chapter is: @@ -16,9 +16,9 @@ .. toctree:: - subprocess.rst socket.rst ssl.rst - signal.rst asyncore.rst asynchat.rst + signal.rst + mmap.rst diff --git a/Doc/library/someos.rst b/Doc/library/someos.rst deleted file mode 100644 --- a/Doc/library/someos.rst +++ /dev/null @@ -1,24 +0,0 @@ -.. _someos: - -********************************** -Optional Operating System Services -********************************** - -The modules described in this chapter provide interfaces to operating system -features that are available on selected operating systems only. The interfaces -are generally modeled after the Unix or C interfaces but they are available on -some other systems as well (e.g. Windows). Here's an overview: - - -.. toctree:: - - select.rst - threading.rst - multiprocessing.rst - concurrent.futures.rst - mmap.rst - readline.rst - rlcompleter.rst - dummy_threading.rst - _thread.rst - _dummy_thread.rst diff --git a/Doc/library/text.rst b/Doc/library/text.rst --- a/Doc/library/text.rst +++ b/Doc/library/text.rst @@ -21,4 +21,6 @@ textwrap.rst unicodedata.rst stringprep.rst + readline.rst + rlcompleter.rst diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,13 @@ Documentation ------------- +- Create a 'Concurrent Execution' section in the docs, and split up the + 'Optional Operating System Services' section to use a more user-centric + classification scheme (splitting them across the new CE section, IPC and + text processing). Operating system limitatons can be reflected with + the Sphinx :platform: tag, it doesn't make sense as part of the Table of + Contents. + - Issue #4966: Bring the sequence docs up to date for the Py3k transition and the many language enhancements since they were original written -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 11:19:43 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 11:19:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NzMy?= =?utf-8?q?=3A_Fix_=28constructed=29_crash_in_=5FPySequence=5FBytesToCharp?= =?utf-8?b?QXJyYXkoKS4=?= Message-ID: <3X0qGl3MSSzQ8W@mail.python.org> http://hg.python.org/cpython/rev/cfddcf964ff0 changeset: 78667:cfddcf964ff0 branch: 3.2 parent: 78658:24b449a77e88 user: Stefan Krah date: Mon Aug 20 11:04:24 2012 +0200 summary: Issue #15732: Fix (constructed) crash in _PySequence_BytesToCharpArray(). Found by Coverity. files: Lib/test/test_capi.py | 13 +++++++++++++ Objects/abstract.c | 5 +++++ 2 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -11,6 +11,10 @@ import unittest from test import support try: + import _posixsubprocess +except ImportError: + _posixsubprocess = None +try: import threading except ImportError: threading = None @@ -55,6 +59,15 @@ def test_memoryview_from_NULL_pointer(self): self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer) + @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') + def test_seq_bytes_to_charp_array(self): + # Issue #15732: crash in _PySequence_BytesToCharpArray() + class Z(object): + def __len__(self): + return 1 + self.assertRaises(TypeError, _posixsubprocess.fork_exec, + 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + @unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase): diff --git a/Objects/abstract.c b/Objects/abstract.c --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2736,6 +2736,11 @@ for (i = 0; i < argc; ++i) { char *data; item = PySequence_GetItem(self, i); + if (item == NULL) { + /* NULL terminate before freeing. */ + array[i] = NULL; + goto fail; + } data = PyBytes_AsString(item); if (data == NULL) { /* NULL terminate before freeing. */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 11:20:15 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 11:20:15 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4yLg==?= Message-ID: <3X0qHM0PwdzQCT@mail.python.org> http://hg.python.org/cpython/rev/2af78f8a98e1 changeset: 78668:2af78f8a98e1 parent: 78666:717344a837ab parent: 78667:cfddcf964ff0 user: Stefan Krah date: Mon Aug 20 11:13:58 2012 +0200 summary: Merge 3.2. files: Lib/test/test_capi.py | 13 +++++++++++++ Objects/abstract.c | 5 +++++ 2 files changed, 18 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -11,6 +11,10 @@ import unittest from test import support try: + import _posixsubprocess +except ImportError: + _posixsubprocess = None +try: import threading except ImportError: threading = None @@ -78,6 +82,15 @@ else: self.assertTrue(False) + @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') + def test_seq_bytes_to_charp_array(self): + # Issue #15732: crash in _PySequence_BytesToCharpArray() + class Z(object): + def __len__(self): + return 1 + self.assertRaises(TypeError, _posixsubprocess.fork_exec, + 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + @unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase): diff --git a/Objects/abstract.c b/Objects/abstract.c --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2718,6 +2718,11 @@ for (i = 0; i < argc; ++i) { char *data; item = PySequence_GetItem(self, i); + if (item == NULL) { + /* NULL terminate before freeing. */ + array[i] = NULL; + goto fail; + } data = PyBytes_AsString(item); if (data == NULL) { /* NULL terminate before freeing. */ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 14:18:46 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 14:18:46 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Closes_=2315737=3A_Fix_pot?= =?utf-8?q?ential_NULL_dereference_in_zipimport=2Ec=2E?= Message-ID: <3X0vFL65khzQ27@mail.python.org> http://hg.python.org/cpython/rev/c89fe7dc22ee changeset: 78669:c89fe7dc22ee user: Stefan Krah date: Mon Aug 20 14:14:49 2012 +0200 summary: Closes #15737: Fix potential NULL dereference in zipimport.c. files: Modules/zipimport.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/zipimport.c b/Modules/zipimport.c --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -947,8 +947,6 @@ else charset = "cp437"; nameobj = PyUnicode_Decode(name, name_size, charset, NULL); - if (PyUnicode_READY(nameobj) == -1) - goto error; if (nameobj == NULL) { if (bootstrap) PyErr_Format(PyExc_NotImplementedError, @@ -957,6 +955,8 @@ PY_MAJOR_VERSION, PY_MINOR_VERSION); goto error; } + if (PyUnicode_READY(nameobj) == -1) + goto error; path = PyUnicode_FromFormat("%U%c%U", archive, SEP, nameobj); if (path == NULL) goto error; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 14:48:23 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 14:48:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NzM4?= =?utf-8?q?=3A_Fix_a_missing_NULL_check_in_subprocess=5Ffork=5Fexec=28=29?= =?utf-8?q?=2E?= Message-ID: <3X0vvW21nJzQDy@mail.python.org> http://hg.python.org/cpython/rev/03c98d05b140 changeset: 78670:03c98d05b140 branch: 3.2 parent: 78667:cfddcf964ff0 user: Stefan Krah date: Mon Aug 20 14:36:47 2012 +0200 summary: Issue #15738: Fix a missing NULL check in subprocess_fork_exec(). files: Lib/test/test_capi.py | 10 ++++++++++ Modules/_posixsubprocess.c | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -68,6 +68,16 @@ self.assertRaises(TypeError, _posixsubprocess.fork_exec, 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') + def test_subprocess_fork_exec(self): + class Z(object): + def __len__(self): + return 1 + + # Issue #15738: crash in subprocess_fork_exec() + self.assertRaises(TypeError, _posixsubprocess.fork_exec, + Z(),[b'1'],3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + @unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase): diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -577,6 +577,8 @@ /* Equivalent to: */ /* tuple(PyUnicode_FSConverter(arg) for arg in process_args) */ fast_args = PySequence_Fast(process_args, "argv must be a tuple"); + if (fast_args == NULL) + goto cleanup; num_args = PySequence_Fast_GET_SIZE(fast_args); converted_args = PyTuple_New(num_args); if (converted_args == NULL) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 14:48:54 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 14:48:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4yLg==?= Message-ID: <3X0vw64v3dzQ5G@mail.python.org> http://hg.python.org/cpython/rev/5b1b9cfb7fe8 changeset: 78671:5b1b9cfb7fe8 parent: 78669:c89fe7dc22ee parent: 78670:03c98d05b140 user: Stefan Krah date: Mon Aug 20 14:42:59 2012 +0200 summary: Merge 3.2. files: Lib/test/test_capi.py | 10 ++++++++++ Modules/_posixsubprocess.c | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -91,6 +91,16 @@ self.assertRaises(TypeError, _posixsubprocess.fork_exec, 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') + def test_subprocess_fork_exec(self): + class Z(object): + def __len__(self): + return 1 + + # Issue #15738: crash in subprocess_fork_exec() + self.assertRaises(TypeError, _posixsubprocess.fork_exec, + Z(),[b'1'],3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + @unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase): diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -579,6 +579,8 @@ /* Equivalent to: */ /* tuple(PyUnicode_FSConverter(arg) for arg in process_args) */ fast_args = PySequence_Fast(process_args, "argv must be a tuple"); + if (fast_args == NULL) + goto cleanup; num_args = PySequence_Fast_GET_SIZE(fast_args); converted_args = PyTuple_New(num_args); if (converted_args == NULL) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 15:02:44 2012 From: python-checkins at python.org (nick.coghlan) Date: Mon, 20 Aug 2012 15:02:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2312643=3A_Respect_?= =?utf-8?q?sys=2Eexcepthook_in_code=2EInteractiveConsole?= Message-ID: <3X0wD42sp4zQB7@mail.python.org> http://hg.python.org/cpython/rev/a812de69b493 changeset: 78672:a812de69b493 user: Nick Coghlan date: Mon Aug 20 23:02:28 2012 +1000 summary: Issue #12643: Respect sys.excepthook in code.InteractiveConsole files: Lib/code.py | 19 +++++- Lib/test/test_code_module.py | 72 ++++++++++++++++++++++++ Lib/test/test_sundry.py | 1 - Misc/ACKS | 1 + Misc/NEWS | 3 + 5 files changed, 91 insertions(+), 5 deletions(-) diff --git a/Lib/code.py b/Lib/code.py --- a/Lib/code.py +++ b/Lib/code.py @@ -105,9 +105,10 @@ The output is written by self.write(), below. """ - type, value, sys.last_traceback = sys.exc_info() + type, value, tb = sys.exc_info() sys.last_type = type sys.last_value = value + sys.last_traceback = tb if filename and type is SyntaxError: # Work hard to stuff the correct filename in the exception try: @@ -119,8 +120,13 @@ # Stuff in the right filename value = SyntaxError(msg, (filename, lineno, offset, line)) sys.last_value = value - lines = traceback.format_exception_only(type, value) - self.write(''.join(lines)) + if sys.excepthook is sys.__excepthook__: + lines = traceback.format_exception_only(type, value) + self.write(''.join(lines)) + else: + # If someone has set sys.excepthook, we let that take precedence + # over self.write + sys.excepthook(type, value, tb) def showtraceback(self): """Display the exception that just occurred. @@ -143,7 +149,12 @@ lines.extend(traceback.format_exception_only(type, value)) finally: tblist = tb = None - self.write(''.join(lines)) + if sys.excepthook is sys.__excepthook__: + self.write(''.join(lines)) + else: + # If someone has set sys.excepthook, we let that take precedence + # over self.write + sys.excepthook(type, value, tb) def write(self, data): """Write a string. diff --git a/Lib/test/test_code_module.py b/Lib/test/test_code_module.py new file mode 100644 --- /dev/null +++ b/Lib/test/test_code_module.py @@ -0,0 +1,72 @@ +"Test InteractiveConsole and InteractiveInterpreter from code module" +import sys +import unittest +from contextlib import ExitStack +from unittest import mock +from test import support + +code = support.import_module('code') + + +class TestInteractiveConsole(unittest.TestCase): + + def setUp(self): + self.console = code.InteractiveConsole() + self.mock_sys() + + def mock_sys(self): + "Mock system environment for InteractiveConsole" + # use exit stack to match patch context managers to addCleanup + stack = ExitStack() + self.addCleanup(stack.close) + self.infunc = stack.enter_context(mock.patch('code.input', + create=True)) + self.stdout = stack.enter_context(mock.patch('code.sys.stdout')) + self.stderr = stack.enter_context(mock.patch('code.sys.stderr')) + prepatch = mock.patch('code.sys', wraps=code.sys, spec=code.sys) + self.sysmod = stack.enter_context(prepatch) + if sys.excepthook is sys.__excepthook__: + self.sysmod.excepthook = self.sysmod.__excepthook__ + + def test_ps1(self): + self.infunc.side_effect = EOFError('Finished') + self.console.interact() + self.assertEqual(self.sysmod.ps1, '>>> ') + + def test_ps2(self): + self.infunc.side_effect = EOFError('Finished') + self.console.interact() + self.assertEqual(self.sysmod.ps2, '... ') + + def test_console_stderr(self): + self.infunc.side_effect = ["'antioch'", "", EOFError('Finished')] + self.console.interact() + for call in list(self.stdout.method_calls): + if 'antioch' in ''.join(call[1]): + break + else: + raise AssertionError("no console stdout") + + def test_syntax_error(self): + self.infunc.side_effect = ["undefined", EOFError('Finished')] + self.console.interact() + for call in self.stderr.method_calls: + if 'NameError:' in ''.join(call[1]): + break + else: + raise AssertionError("No syntax error from console") + + def test_sysexcepthook(self): + self.infunc.side_effect = ["raise ValueError('')", + EOFError('Finished')] + hook = mock.Mock() + self.sysmod.excepthook = hook + self.console.interact() + self.assertTrue(hook.called) + + +def test_main(): + support.run_unittest(TestInteractiveConsole) + +if __name__ == "__main__": + unittest.main() diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py --- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -9,7 +9,6 @@ with support.check_warnings(quiet=True): import bdb import cgitb - import code import distutils.bcppcompiler import distutils.ccompiler diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -487,6 +487,7 @@ Catalin Iacob Mihai Ibanescu Ali Ikinci +Aaron Iles Lars Immisch Bobby Impollonia Meador Inge diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,9 @@ Library ------- +- Issue #12643: code.InteractiveConsole now respects sys.excepthook when + displaying exceptions (Patch by Aaron Iles) + - Issue #13579: string.Formatter now understands the 'a' conversion specifier. - Issue #15595: Fix subprocess.Popen(universal_newlines=True) -- Repository URL: http://hg.python.org/cpython From barry at python.org Mon Aug 20 15:35:42 2012 From: barry at python.org (Barry Warsaw) Date: Mon, 20 Aug 2012 09:35:42 -0400 Subject: [Python-checkins] cpython: s/path importer/path based finder/ (because the path based finder is not an In-Reply-To: <3X0gxd4vH0zQ5X@mail.python.org> References: <3X0gxd4vH0zQ5X@mail.python.org> Message-ID: <20120820093542.49e04a51@limelight.wooz.org> On Aug 20, 2012, at 05:49 AM, nick.coghlan wrote: > s/path importer/path based finder/ (because the path based finder is not an > importer and the simpler 'path finder' is too ambiguous) +1! -Barry From python-checkins at python.org Mon Aug 20 16:11:43 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 16:11:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Check_return_value_of_asdl?= =?utf-8?b?X3NlcV9uZXcoKS4gRm91bmQgYnkgQ292ZXJpdHku?= Message-ID: <3X0xlg47lrzQ6c@mail.python.org> http://hg.python.org/cpython/rev/663de4dbb88a changeset: 78673:663de4dbb88a user: Stefan Krah date: Mon Aug 20 16:07:38 2012 +0200 summary: Check return value of asdl_seq_new(). Found by Coverity. files: Python/ast.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Python/ast.c b/Python/ast.c --- a/Python/ast.c +++ b/Python/ast.c @@ -3502,6 +3502,8 @@ n_items = (NCH(n) - 2) / 2; items = asdl_seq_new(n_items, c->c_arena); + if (!items) + return NULL; for (i = 1; i < NCH(n) - 2; i += 2) { withitem_ty item = ast_for_with_item(c, CHILD(n, i)); if (!item) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 17:36:17 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 17:36:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NzQx?= =?utf-8?q?=3A_Fix_potential_NULL_dereference=2E_Found_by_Coverity=2E?= Message-ID: <3X0zdF0WTkzQDf@mail.python.org> http://hg.python.org/cpython/rev/d5ee1a06101f changeset: 78674:d5ee1a06101f branch: 3.2 parent: 78670:03c98d05b140 user: Stefan Krah date: Mon Aug 20 17:19:50 2012 +0200 summary: Issue #15741: Fix potential NULL dereference. Found by Coverity. files: Python/bltinmodule.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -631,6 +631,8 @@ mod_ty mod; arena = PyArena_New(); + if (arena == NULL) + goto error; mod = PyAST_obj2mod(cmd, arena, mode); if (mod == NULL) { PyArena_Free(arena); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 17:36:23 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 17:36:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4yLg==?= Message-ID: <3X0zdM46vXzQH5@mail.python.org> http://hg.python.org/cpython/rev/0a3149b30f20 changeset: 78675:0a3149b30f20 parent: 78673:663de4dbb88a parent: 78674:d5ee1a06101f user: Stefan Krah date: Mon Aug 20 17:20:46 2012 +0200 summary: Merge 3.2. files: Python/bltinmodule.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -639,6 +639,8 @@ mod_ty mod; arena = PyArena_New(); + if (arena == NULL) + goto error; mod = PyAST_obj2mod(cmd, arena, mode); if (mod == NULL) { PyArena_Free(arena); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 17:36:54 2012 From: python-checkins at python.org (stefan.krah) Date: Mon, 20 Aug 2012 17:36:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NzQx?= =?utf-8?q?=3A_Fix_potential_NULL_dereference=2E_Found_by_Coverity=2E?= Message-ID: <3X0zdy6jp4zQGm@mail.python.org> http://hg.python.org/cpython/rev/2b4f6770877e changeset: 78676:2b4f6770877e branch: 2.7 parent: 78660:c793d62cdecc user: Stefan Krah date: Mon Aug 20 17:31:22 2012 +0200 summary: Issue #15741: Fix potential NULL dereference. Found by Coverity. files: Python/bltinmodule.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -523,6 +523,8 @@ mod_ty mod; arena = PyArena_New(); + if (arena == NULL) + return NULL; mod = PyAST_obj2mod(cmd, arena, mode); if (mod == NULL) { PyArena_Free(arena); -- Repository URL: http://hg.python.org/cpython From tjreedy at udel.edu Mon Aug 20 19:01:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Aug 2012 13:01:33 -0400 Subject: [Python-checkins] cpython: Close #4966: revamp the sequence docs in order to better explain the state of In-Reply-To: <3X0mV86gLXzPcJ@mail.python.org> References: <3X0mV86gLXzPcJ@mail.python.org> Message-ID: <50326D6D.3050701@udel.edu> On 8/20/2012 3:14 AM, nick.coghlan wrote: > +(5) > + :meth:`clear` and :meth:`!copy` are included for consistency with the > + interfaces of mutable containers that don't support slicing operations > + (such as :class:`dict` and :class:`set`) > + > + .. versionadded:: 3.3 > + :meth:`clear` and :meth:`!copy` methods. Should !copy be copy (both places) or is '!' some markup I don't know about? From brett at python.org Mon Aug 20 19:08:48 2012 From: brett at python.org (Brett Cannon) Date: Mon, 20 Aug 2012 13:08:48 -0400 Subject: [Python-checkins] cpython: s/path importer/path based finder/ (because the path based finder is not an In-Reply-To: <3X0gxd4vH0zQ5X@mail.python.org> References: <3X0gxd4vH0zQ5X@mail.python.org> Message-ID: Should that be "path-based"? On Sun, Aug 19, 2012 at 11:49 PM, nick.coghlan wrote: > http://hg.python.org/cpython/rev/2f9f5ab3d754 > changeset: 78664:2f9f5ab3d754 > user: Nick Coghlan > date: Mon Aug 20 13:49:08 2012 +1000 > summary: > s/path importer/path based finder/ (because the path based finder is not > an importer and the simpler 'path finder' is too ambiguous) > > files: > Doc/glossary.rst | 6 +- > Doc/reference/import.rst | 95 ++++++++++++++------------- > Misc/NEWS | 4 + > 3 files changed, 57 insertions(+), 48 deletions(-) > > > diff --git a/Doc/glossary.rst b/Doc/glossary.rst > --- a/Doc/glossary.rst > +++ b/Doc/glossary.rst > @@ -317,7 +317,7 @@ > > import path > A list of locations (or :term:`path entries `) that are > - searched by the :term:`path importer` for modules to import. During > + searched by the :term:`path based finder` for modules to import. > During > import, this list of locations usually comes from :data:`sys.path`, > but > for subpackages it may also come from the parent package's > ``__path__`` > attribute. > @@ -550,7 +550,7 @@ > > path entry > A single location on the :term:`import path` which the :term:`path > - importer` consults to find modules for importing. > + based finder` consults to find modules for importing. > > path entry finder > A :term:`finder` returned by a callable on :data:`sys.path_hooks` > @@ -562,7 +562,7 @@ > entry finder` if it knows how to find modules on a specific > :term:`path > entry`. > > - path importer > + path based finder > One of the default :term:`meta path finders ` > which > searches an :term:`import path` for modules. > > diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst > --- a/Doc/reference/import.rst > +++ b/Doc/reference/import.rst > @@ -42,6 +42,12 @@ > invoked. These strategies can be modified and extended by using various > hooks > described in the sections below. > > +.. versionchanged:: 3.3 > + The import system has been updated to fully implement the second phase > + of PEP 302. There is no longer any implicit import machinery - the full > + import system is exposed through :data:`sys.meta_path`. In addition, > + native namespace package support has been implemented (see PEP 420). > + > > :mod:`importlib` > ================ > @@ -213,7 +219,7 @@ > interfaces are referred to as :term:`importers ` - they return > themselves when they find that they can load the requested module. > > -By default, Python comes with several default finders and importers. One > +Python includes a number of default finders and importers. One > knows how to locate frozen modules, and another knows how to locate > built-in modules. A third default finder searches an :term:`import path` > for modules. The :term:`import path` is a list of locations that may > @@ -307,7 +313,7 @@ > Python's default :data:`sys.meta_path` has three meta path finders, one > that > knows how to import built-in modules, one that knows how to import frozen > modules, and one that knows how to import modules from an :term:`import > path` > -(i.e. the :term:`path importer`). > +(i.e. the :term:`path based finder`). > > > Loaders > @@ -356,14 +362,14 @@ > * If the module is a package (either regular or namespace), the loader > must > set the module object's ``__path__`` attribute. The value must be > iterable, but may be empty if ``__path__`` has no further significance > - to the importer. If ``__path__`` is not empty, it must produce strings > + to the loader. If ``__path__`` is not empty, it must produce strings > when iterated over. More details on the semantics of ``__path__`` are > given :ref:`below `. > > * The ``__loader__`` attribute must be set to the loader object that > loaded > the module. This is mostly for introspection and reloading, but can be > - used for additional importer-specific functionality, for example > getting > - data associated with an importer. > + used for additional loader-specific functionality, for example getting > + data associated with a loader. > > * The module's ``__package__`` attribute should be set. Its value must > be a > string, but it can be the same value as its ``__name__``. If the > attribute > @@ -456,18 +462,18 @@ > correctly for the namespace package. > > > -The Path Importer > -================= > +The Path Based Finder > +===================== > > .. index:: > - single: path importer > + single: path based finder > > As mentioned previously, Python comes with several default meta path > finders. > -One of these, called the :term:`path importer`, searches an :term:`import > +One of these, called the :term:`path based finder`, searches an > :term:`import > path`, which contains a list of :term:`path entries `. Each > path > entry names a location to search for modules. > > -The path importer itself doesn't know how to import anything. Instead, it > +The path based finder itself doesn't know how to import anything. > Instead, it > traverses the individual path entries, associating each of them with a > path entry finder that knows how to handle that particular kind of path. > > @@ -479,10 +485,10 @@ > loading all of these file types (other than shared libraries) from > zipfiles. > > Path entries need not be limited to file system locations. They can > refer to > -the URLs, database queries, or any other location that can be specified > as a > +URLs, database queries, or any other location that can be specified as a > string. > > -The :term:`path importer` provides additional hooks and protocols so that > you > +The path based finder provides additional hooks and protocols so that you > can extend and customize the types of searchable path entries. For > example, > if you wanted to support path entries as network URLs, you could write a > hook > that implements HTTP semantics to find modules on the web. This hook (a > @@ -498,8 +504,8 @@ > In particular, meta path finders operate at the beginning of the import > process, as keyed off the :data:`sys.meta_path` traversal. > > -On the other hand, path entry finders are in a sense an implementation > detail > -of the :term:`path importer`, and in fact, if the path importer were to be > +By contrast, path entry finders are in a sense an implementation detail > +of the path based finder, and in fact, if the path based finder were to be > removed from :data:`sys.meta_path`, none of the path entry finder > semantics > would be invoked. > > @@ -513,17 +519,17 @@ > single: sys.path_importer_cache > single: PYTHONPATH > > -The :term:`path importer` is responsible for finding and loading Python > +The :term:`path based finder` is responsible for finding and loading > Python > modules and packages whose location is specified with a string :term:`path > entry`. Most path entries name locations in the file system, but they > need > not be limited to this. > > -As a meta path finder, the :term:`path importer` implements the > +As a meta path finder, the :term:`path based finder` implements the > :meth:`find_module()` protocol previously described, however it exposes > additional hooks that can be used to customize how modules are found and > loaded from the :term:`import path`. > > -Three variables are used by the :term:`path importer`, :data:`sys.path`, > +Three variables are used by the :term:`path based finder`, > :data:`sys.path`, > :data:`sys.path_hooks` and :data:`sys.path_importer_cache`. The > ``__path__`` > attributes on package objects are also used. These provide additional > ways > that the import machinery can be customized. > @@ -536,38 +542,40 @@ > (see the :mod:`site` module) that should be searched for modules, such as > URLs, or database queries. > > -The :term:`path importer` is a :term:`meta path finder`, so the import > +The :term:`path based finder` is a :term:`meta path finder`, so the import > machinery begins the :term:`import path` search by calling the path > -importer's :meth:`find_module()` method as described previously. When > +based finder's :meth:`find_module()` method as described previously. When > the ``path`` argument to :meth:`find_module()` is given, it will be a > list of string paths to traverse - typically a package's ``__path__`` > attribute for an import within that package. If the ``path`` argument > is ``None``, this indicates a top level import and :data:`sys.path` is > used. > > -The :term:`path importer` iterates over every entry in the search path, > and > +The path based finder iterates over every entry in the search path, and > for each of these, looks for an appropriate :term:`path entry finder` for > the > path entry. Because this can be an expensive operation (e.g. there may be > -`stat()` call overheads for this search), the :term:`path importer` > maintains > +`stat()` call overheads for this search), the path based finder maintains > a cache mapping path entries to path entry finders. This cache is > maintained > -in :data:`sys.path_importer_cache`. In this way, the expensive search > for a > -particular :term:`path entry` location's :term:`path entry finder` need > only > -be done once. User code is free to remove cache entries from > -:data:`sys.path_importer_cache` forcing the :term:`path importer` to > perform > -the path entry search again [#fnpic]_. > +in :data:`sys.path_importer_cache` (despite the name, this cache actually > +stores finder objects rather than being limited to :term:`importer` > objects). > +In this way, the expensive search for a particular :term:`path entry` > +location's :term:`path entry finder` need only be done once. User code is > +free to remove cache entries from :data:`sys.path_importer_cache` forcing > +the path based finder to perform the path entry search again [#fnpic]_. > > -If the path entry is not present in the cache, the path importer iterates > over > -every callable in :data:`sys.path_hooks`. Each of the :term:`path entry > hooks > -` in this list is called with a single argument, the path > -entry being searched. This callable may either return a :term:`path entry > -finder` that can handle the path entry, or it may raise > :exc:`ImportError`. > -An :exc:`ImportError` is used by the path importer to signal that the hook > +If the path entry is not present in the cache, the path based finder > iterates > +over every callable in :data:`sys.path_hooks`. Each of the > +:term:`path entry hooks ` in this list is called with a > +single argument, the path entry to be searched. This callable may either > +return a :term:`path entry finder` that can handle the path entry, or it > may > +raise :exc:`ImportError`. > +An :exc:`ImportError` is used by the path based finder to signal that the > hook > cannot find a :term:`path entry finder` for that :term:`path entry`. The > exception is ignored and :term:`import path` iteration continues. > > If :data:`sys.path_hooks` iteration ends with no :term:`path entry finder` > -being returned, then the path importer's :meth:`find_module()` method will > -store ``None`` in :data:`sys.path_importer_cache` (to indicate that there > -is no finder for this path entry) and return ``None``, indicating that > +being returned, then the path based finder's :meth:`find_module()` method > +will store ``None`` in :data:`sys.path_importer_cache` (to indicate that > +there is no finder for this path entry) and return ``None``, indicating > that > this :term:`meta path finder` could not find the module. > > If a :term:`path entry finder` *is* returned by one of the :term:`path > entry > @@ -594,8 +602,8 @@ > must be a sequence, although it can be empty. > > If :meth:`find_loader()` returns a non-``None`` loader value, the portion > is > -ignored and the loader is returned from the path importer, terminating the > -search through the path entries. > +ignored and the loader is returned from the path based finder, terminating > +the search through the path entries. > > For backwards compatibility with other implementations of the import > protocol, many path entry finders also support the same, > @@ -645,9 +653,6 @@ > XXX runpy, pkgutil, et al in the library manual should all get "See Also" > links at the top pointing to the new import system section. > > -XXX The :term:`path importer` is not, in fact, an :term:`importer`. That's > -why the corresponding implementation class is > :class:`importlib.PathFinder`. > - > > References > ========== > @@ -667,8 +672,8 @@ > :pep:`366` describes the addition of the ``__package__`` attribute for > explicit relative imports in main modules. > > -:pep:`328` introduced absolute and relative imports and initially proposed > -``__name__`` for semantics :pep:`366` would eventually specify for > +:pep:`328` introduced absolute and explicit relative imports and initially > +proposed ``__name__`` for semantics :pep:`366` would eventually specify > for > ``__package__``. > > :pep:`338` defines executing modules as scripts. > @@ -679,14 +684,14 @@ > > .. [#fnmo] See :class:`types.ModuleType`. > > -.. [#fnlo] The importlib implementation appears not to use the return > value > +.. [#fnlo] The importlib implementation avoids using the return value > directly. Instead, it gets the module object by looking the module > name up > - in :data:`sys.modules`.) The indirect effect of this is that an > imported > + in :data:`sys.modules`. The indirect effect of this is that an > imported > module may replace itself in :data:`sys.modules`. This is > implementation-specific behavior that is not guaranteed to work in > other > Python implementations. > > .. [#fnpic] In legacy code, it is possible to find instances of > :class:`imp.NullImporter` in the :data:`sys.path_importer_cache`. It > - recommended that code be changed to use ``None`` instead. See > + is recommended that code be changed to use ``None`` instead. See > :ref:`portingpythoncode` for more details. > diff --git a/Misc/NEWS b/Misc/NEWS > --- a/Misc/NEWS > +++ b/Misc/NEWS > @@ -55,6 +55,10 @@ > Documentation > ------------- > > +- The "path importer" misnomer has been replaced with Eric Snow's > + more-awkward-but-at-least-not-wrong suggestion of "path based finder" in > + the import system reference docs > + > - Issue #15640: Document importlib.abc.Finder as deprecated. > > - Issue #15630: Add an example for "continue" stmt in the tutorial. Patch > by > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Mon Aug 20 19:38:27 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 20 Aug 2012 19:38:27 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NzI2?= =?utf-8?q?=3A_Fix_incorrect_bounds_checking_in_PyState=5FFindModule=2E?= Message-ID: <3X12LC0MHtzPxm@mail.python.org> http://hg.python.org/cpython/rev/b96a4b1e7ecb changeset: 78677:b96a4b1e7ecb branch: 3.2 parent: 78674:d5ee1a06101f user: Antoine Pitrou date: Mon Aug 20 19:30:46 2012 +0200 summary: Issue #15726: Fix incorrect bounds checking in PyState_FindModule. Patch by Robin Schreiber. files: Misc/ACKS | 1 + Misc/NEWS | 3 +++ Python/pystate.c | 2 +- 3 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -848,6 +848,7 @@ Michael Schneider Peter Schneider-Kamp Arvin Schnell +Robin Schreiber Chad J. Schroeder Sam Schulenburg Stefan Schwarzer diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15726: Fix incorrect bounds checking in PyState_FindModule. + Patch by Robin Schreiber. + - Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. diff --git a/Python/pystate.c b/Python/pystate.c --- a/Python/pystate.c +++ b/Python/pystate.c @@ -248,7 +248,7 @@ return NULL; if (state->modules_by_index == NULL) return NULL; - if (index > PyList_GET_SIZE(state->modules_by_index)) + if (index >= PyList_GET_SIZE(state->modules_by_index)) return NULL; res = PyList_GET_ITEM(state->modules_by_index, index); return res==Py_None ? NULL : res; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 19:38:58 2012 From: python-checkins at python.org (antoine.pitrou) Date: Mon, 20 Aug 2012 19:38:58 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315726=3A_Fix_incorrect_bounds_checking_in_PySta?= =?utf-8?q?te=5FFindModule=2E?= Message-ID: <3X12Lp4yS3zQH8@mail.python.org> http://hg.python.org/cpython/rev/7789111afe05 changeset: 78678:7789111afe05 parent: 78675:0a3149b30f20 parent: 78677:b96a4b1e7ecb user: Antoine Pitrou date: Mon Aug 20 19:31:52 2012 +0200 summary: Issue #15726: Fix incorrect bounds checking in PyState_FindModule. Patch by Robin Schreiber. files: Misc/NEWS | 3 +++ Python/pystate.c | 2 +- 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15726: Fix incorrect bounds checking in PyState_FindModule. + Patch by Robin Schreiber. + - Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. diff --git a/Python/pystate.c b/Python/pystate.c --- a/Python/pystate.c +++ b/Python/pystate.c @@ -248,7 +248,7 @@ return NULL; if (state->modules_by_index == NULL) return NULL; - if (index > PyList_GET_SIZE(state->modules_by_index)) + if (index >= PyList_GET_SIZE(state->modules_by_index)) return NULL; res = PyList_GET_ITEM(state->modules_by_index, index); return res==Py_None ? NULL : res; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 20:17:59 2012 From: python-checkins at python.org (r.david.murray) Date: Mon, 20 Aug 2012 20:17:59 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1NzQyOiBjbGFy?= =?utf-8?q?ify_sqlite_parameter_substitution_example=2E?= Message-ID: <3X13Cq3NrzzQGb@mail.python.org> http://hg.python.org/cpython/rev/80b15cf2611e changeset: 78679:80b15cf2611e branch: 3.2 parent: 78677:b96a4b1e7ecb user: R David Murray date: Mon Aug 20 14:14:18 2012 -0400 summary: #15742: clarify sqlite parameter substitution example. Suggestion and patch by Mike Hoy. files: Doc/library/sqlite3.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -60,7 +60,7 @@ c.execute("select * from stocks where symbol = '%s'" % symbol) # Do this instead - t = (symbol,) + t = ('IBM',) c.execute('select * from stocks where symbol=?', t) # Larger example -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 20:18:04 2012 From: python-checkins at python.org (r.david.murray) Date: Mon, 20 Aug 2012 20:18:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315742=3A_clarify_sqlite_parameter_substitution_?= =?utf-8?q?example=2E?= Message-ID: <3X13Cw4lkpzQLf@mail.python.org> http://hg.python.org/cpython/rev/2eafe04cb6ed changeset: 78680:2eafe04cb6ed parent: 78678:7789111afe05 parent: 78679:80b15cf2611e user: R David Murray date: Mon Aug 20 14:14:46 2012 -0400 summary: Merge #15742: clarify sqlite parameter substitution example. Suggestion and patch by Mike Hoy. files: Doc/library/sqlite3.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -60,7 +60,7 @@ c.execute("select * from stocks where symbol = '%s'" % symbol) # Do this instead - t = (symbol,) + t = ('IBM',) c.execute('select * from stocks where symbol=?', t) # Larger example -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 20:18:36 2012 From: python-checkins at python.org (r.david.murray) Date: Mon, 20 Aug 2012 20:18:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1NzQyOiBjbGFy?= =?utf-8?q?ify_sqlite_parameter_substitution_example=2E?= Message-ID: <3X13DX08XVzQKG@mail.python.org> http://hg.python.org/cpython/rev/857c9e1fdd1e changeset: 78681:857c9e1fdd1e branch: 2.7 parent: 78676:2b4f6770877e user: R David Murray date: Mon Aug 20 14:17:22 2012 -0400 summary: #15742: clarify sqlite parameter substitution example. files: Doc/library/sqlite3.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst +++ b/Doc/library/sqlite3.rst @@ -67,7 +67,7 @@ c.execute("SELECT * FROM stocks WHERE symbol = '%s'" % symbol) # Do this instead - t = (symbol,) + t = ('RHAT',) c.execute('SELECT * FROM stocks WHERE symbol=?', t) print c.fetchone() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 20:35:24 2012 From: python-checkins at python.org (petri.lehtinen) Date: Mon, 20 Aug 2012 20:35:24 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1MTk5OiBGaXgg?= =?utf-8?q?JavaScript=27s_default_MIME_type_to_application/javascript?= Message-ID: <3X13bw13vfzQGc@mail.python.org> http://hg.python.org/cpython/rev/20985f52b65e changeset: 78682:20985f52b65e branch: 2.7 user: Petri Lehtinen date: Mon Aug 20 21:05:56 2012 +0300 summary: #15199: Fix JavaScript's default MIME type to application/javascript files: Lib/mimetypes.py | 2 +- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -437,7 +437,7 @@ '.jpe' : 'image/jpeg', '.jpeg' : 'image/jpeg', '.jpg' : 'image/jpeg', - '.js' : 'application/x-javascript', + '.js' : 'application/javascript', '.ksh' : 'text/plain', '.latex' : 'application/x-latex', '.m1v' : 'video/mpeg', diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -436,6 +436,7 @@ Sijin Joseph Andreas Jung Tattoo Mabonzo K. +Bohuslav Kabrda Bob Kahn Kurt B. Kaiser Tamito Kajiyama diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -95,6 +95,9 @@ Library ------- +- Issue #15199: Fix JavaScript's default MIME type to application/javascript. + Patch by Bohuslav Kabrda. + - Issue #15477: In cmath and math modules, add workaround for platforms whose system-supplied log1p function doesn't respect signs of zeros. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 20:35:55 2012 From: python-checkins at python.org (petri.lehtinen) Date: Mon, 20 Aug 2012 20:35:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1MTk5OiBGaXgg?= =?utf-8?q?JavaScript=27s_default_MIME_type_to_application/javascript?= Message-ID: <3X13cW5FNTzQ98@mail.python.org> http://hg.python.org/cpython/rev/b64947b6f947 changeset: 78683:b64947b6f947 branch: 3.2 parent: 78679:80b15cf2611e user: Petri Lehtinen date: Mon Aug 20 21:05:56 2012 +0300 summary: #15199: Fix JavaScript's default MIME type to application/javascript files: Lib/mimetypes.py | 2 +- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -430,7 +430,7 @@ '.jpe' : 'image/jpeg', '.jpeg' : 'image/jpeg', '.jpg' : 'image/jpeg', - '.js' : 'application/x-javascript', + '.js' : 'application/javascript', '.ksh' : 'text/plain', '.latex' : 'application/x-latex', '.m1v' : 'video/mpeg', diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -480,6 +480,7 @@ Sijin Joseph Andreas Jung Tattoo Mabonzo K. +Bohuslav Kabrda Bob Kahn Kurt B. Kaiser Tamito Kajiyama diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -107,6 +107,9 @@ Library ------- +- Issue #15199: Fix JavaScript's default MIME type to application/javascript. + Patch by Bohuslav Kabrda. + - Issue #13579: string.Formatter now understands the 'a' conversion specifier. - Issue #15595: Fix subprocess.Popen(universal_newlines=True) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 20:36:27 2012 From: python-checkins at python.org (petri.lehtinen) Date: Mon, 20 Aug 2012 20:36:27 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_=2315199=3A_Fix_JavaScript=27s_default_MIME_type_to_appl?= =?utf-8?q?ication/javascript?= Message-ID: <3X13d70sbYzQK1@mail.python.org> http://hg.python.org/cpython/rev/d4d5cfef5323 changeset: 78684:d4d5cfef5323 parent: 78680:2eafe04cb6ed parent: 78683:b64947b6f947 user: Petri Lehtinen date: Mon Aug 20 21:30:03 2012 +0300 summary: #15199: Fix JavaScript's default MIME type to application/javascript files: Lib/mimetypes.py | 2 +- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 3 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -429,7 +429,7 @@ '.jpe' : 'image/jpeg', '.jpeg' : 'image/jpeg', '.jpg' : 'image/jpeg', - '.js' : 'application/x-javascript', + '.js' : 'application/javascript', '.ksh' : 'text/plain', '.latex' : 'application/x-latex', '.m1v' : 'video/mpeg', diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -533,6 +533,7 @@ Sijin Joseph Andreas Jung Tattoo Mabonzo K. +Bohuslav Kabrda Bob Kahn Kurt B. Kaiser Tamito Kajiyama diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,9 @@ Library ------- +- Issue #15199: Fix JavaScript's default MIME type to application/javascript. + Patch by Bohuslav Kabrda. + - Issue #12643: code.InteractiveConsole now respects sys.excepthook when displaying exceptions (Patch by Aaron Iles) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 20 22:46:26 2012 From: python-checkins at python.org (senthil.kumaran) Date: Mon, 20 Aug 2012 22:46:26 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_Issue_15743_-_improve_?= =?utf-8?q?urllib_tests_by_removing_deprecated_method_usages=2E?= Message-ID: <3X16W66v5fzQPn@mail.python.org> http://hg.python.org/cpython/rev/9b28dff66ac3 changeset: 78685:9b28dff66ac3 user: Senthil Kumaran date: Mon Aug 20 13:43:59 2012 -0700 summary: Fix Issue 15743 - improve urllib tests by removing deprecated method usages. Patch by Jeff Knupp. files: Lib/test/test_urllib2.py | 64 ++++++++++++++------------- Misc/NEWS | 3 + 2 files changed, 36 insertions(+), 31 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 @@ -622,10 +622,10 @@ with self.assertWarns(DeprecationWarning): req.add_data("data") with self.assertWarns(DeprecationWarning): + req.get_data() + with self.assertWarns(DeprecationWarning): req.has_data() with self.assertWarns(DeprecationWarning): - req.get_data() - with self.assertWarns(DeprecationWarning): req.get_host() with self.assertWarns(DeprecationWarning): req.get_selector() @@ -633,6 +633,8 @@ req.is_unverifiable() with self.assertWarns(DeprecationWarning): req.get_origin_req_host() + with self.assertWarns(DeprecationWarning): + req.get_type() def sanepathname2url(path): @@ -989,8 +991,8 @@ newreq = h.http_request(req) self.assertIs(cj.ach_req, req) self.assertIs(cj.ach_req, newreq) - self.assertEqual(req.get_origin_req_host(), "example.com") - self.assertFalse(req.is_unverifiable()) + self.assertEqual(req.origin_req_host, "example.com") + self.assertFalse(req.unverifiable) newr = h.http_response(req, r) self.assertIs(cj.ec_req, req) self.assertIs(cj.ec_r, r) @@ -1022,7 +1024,7 @@ try: self.assertEqual(o.req.get_method(), "GET") except AttributeError: - self.assertFalse(o.req.has_data()) + self.assertFalse(o.req.data) # now it's a GET, there should not be headers regarding content # (possibly dragged from before being a POST) @@ -1138,9 +1140,9 @@ handlers = add_ordered_mock_handlers(o, meth_spec) req = Request("http://acme.example.com/") - self.assertEqual(req.get_host(), "acme.example.com") + self.assertEqual(req.host, "acme.example.com") r = o.open(req) - self.assertEqual(req.get_host(), "proxy.example.com:3128") + self.assertEqual(req.host, "proxy.example.com:3128") self.assertEqual([(handlers[0], "http_open")], [tup[0:2] for tup in o.calls]) @@ -1151,13 +1153,13 @@ ph = urllib.request.ProxyHandler(dict(http="proxy.example.com")) o.add_handler(ph) req = Request("http://www.perl.org/") - self.assertEqual(req.get_host(), "www.perl.org") + self.assertEqual(req.host, "www.perl.org") r = o.open(req) - self.assertEqual(req.get_host(), "proxy.example.com") + self.assertEqual(req.host, "proxy.example.com") req = Request("http://www.python.org") - self.assertEqual(req.get_host(), "www.python.org") + self.assertEqual(req.host, "www.python.org") r = o.open(req) - self.assertEqual(req.get_host(), "www.python.org") + self.assertEqual(req.host, "www.python.org") del os.environ['no_proxy'] def test_proxy_no_proxy_all(self): @@ -1166,9 +1168,9 @@ ph = urllib.request.ProxyHandler(dict(http="proxy.example.com")) o.add_handler(ph) req = Request("http://www.python.org") - self.assertEqual(req.get_host(), "www.python.org") + self.assertEqual(req.host, "www.python.org") r = o.open(req) - self.assertEqual(req.get_host(), "www.python.org") + self.assertEqual(req.host, "www.python.org") del os.environ['no_proxy'] @@ -1182,9 +1184,9 @@ handlers = add_ordered_mock_handlers(o, meth_spec) req = Request("https://www.example.com/") - self.assertEqual(req.get_host(), "www.example.com") + self.assertEqual(req.host, "www.example.com") r = o.open(req) - self.assertEqual(req.get_host(), "proxy.example.com:3128") + self.assertEqual(req.host, "proxy.example.com:3128") self.assertEqual([(handlers[0], "https_open")], [tup[0:2] for tup in o.calls]) @@ -1197,7 +1199,7 @@ req = Request("https://www.example.com/") req.add_header("Proxy-Authorization","FooBar") req.add_header("User-Agent","Grail") - self.assertEqual(req.get_host(), "www.example.com") + self.assertEqual(req.host, "www.example.com") self.assertIsNone(req._tunnel_host) r = o.open(req) # Verify Proxy-Authorization gets tunneled to request. @@ -1208,7 +1210,7 @@ self.assertIn(("User-Agent","Grail"), https_handler.httpconn.req_headers) self.assertIsNotNone(req._tunnel_host) - self.assertEqual(req.get_host(), "proxy.example.com:3128") + self.assertEqual(req.host, "proxy.example.com:3128") self.assertEqual(req.get_header("Proxy-authorization"),"FooBar") # TODO: This should be only for OSX @@ -1445,11 +1447,11 @@ self.assertEqual("POST", self.post.get_method()) self.assertEqual("GET", self.get.get_method()) - def test_add_data(self): - self.assertFalse(self.get.has_data()) + def test_data(self): + self.assertFalse(self.get.data) self.assertEqual("GET", self.get.get_method()) - self.get.add_data("spam") - self.assertTrue(self.get.has_data()) + self.get.data = "spam" + self.assertTrue(self.get.data) self.assertEqual("POST", self.get.get_method()) def test_get_full_url(self): @@ -1457,36 +1459,36 @@ self.get.get_full_url()) def test_selector(self): - self.assertEqual("/~jeremy/", self.get.get_selector()) + self.assertEqual("/~jeremy/", self.get.selector) req = Request("http://www.python.org/") - self.assertEqual("/", req.get_selector()) + self.assertEqual("/", req.selector) def test_get_type(self): - self.assertEqual("http", self.get.get_type()) + self.assertEqual("http", self.get.type) def test_get_host(self): - self.assertEqual("www.python.org", self.get.get_host()) + self.assertEqual("www.python.org", self.get.host) def test_get_host_unquote(self): req = Request("http://www.%70ython.org/") - self.assertEqual("www.python.org", req.get_host()) + self.assertEqual("www.python.org", req.host) def test_proxy(self): self.assertFalse(self.get.has_proxy()) self.get.set_proxy("www.perl.org", "http") self.assertTrue(self.get.has_proxy()) - self.assertEqual("www.python.org", self.get.get_origin_req_host()) - self.assertEqual("www.perl.org", self.get.get_host()) + self.assertEqual("www.python.org", self.get.origin_req_host) + self.assertEqual("www.perl.org", self.get.host) def test_wrapped_url(self): req = Request("") - self.assertEqual("www.python.org", req.get_host()) + self.assertEqual("www.python.org", req.host) def test_url_fragment(self): req = Request("http://www.python.org/?qs=query#fragment=true") - self.assertEqual("/?qs=query", req.get_selector()) + self.assertEqual("/?qs=query", req.selector) req = Request("http://www.python.org/#fun=true") - self.assertEqual("/", req.get_selector()) + self.assertEqual("/", req.selector) # Issue 11703: geturl() omits fragment in the original URL. url = 'http://docs.python.org/library/urllib2.html#OK' diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -86,6 +86,9 @@ Tests ----- +- Issue #15743: Remove the deprecated method usage in urllib tests. Patch by + Jeff Knupp. + - Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 00:02:19 2012 From: python-checkins at python.org (sandro.tosi) Date: Tue, 21 Aug 2012 00:02:19 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Issue_=2312415=3A_describ?= =?utf-8?q?e_where_the_documentation_files_are_=28patch_by_=C3=89ric_Arauj?= =?utf-8?q?o=29?= Message-ID: <3X18Bg2C5dzQ8j@mail.python.org> http://hg.python.org/devguide/rev/e0d68c73e351 changeset: 540:e0d68c73e351 user: Sandro Tosi date: Tue Aug 21 00:01:53 2012 +0200 summary: Issue #12415: describe where the documentation files are (patch by ?ric Araujo) files: documenting.rst | 13 ++++++++++--- setup.rst | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/documenting.rst b/documenting.rst --- a/documenting.rst +++ b/documenting.rst @@ -12,6 +12,10 @@ custom reStructuredText markup introduced by Sphinx to support Python documentation and how it should be used. +The documentation in HTML, PDF or EPUB format is generated from text files +written using the :ref:`reStructuredText format ` and contained in the +:ref:`CPython Mercurial repository `. + .. _reStructuredText: http://docutils.sf.net/rst.html .. _docutils: http://docutils.sf.net/ .. _Sphinx: http://sphinx.pocoo.org/ @@ -1623,6 +1627,7 @@ .. XXX more (index-generating, production lists, ...) +.. _building-doc: Building the documentation ========================== @@ -1638,7 +1643,8 @@ ---------- Luckily, a Makefile has been prepared so that on Unix, provided you have -installed Python and Subversion, you can just run :: +installed Python and Subversion, you can just go to your :ref:`clone of the +CPython Mercurial repository ` and run :: cd Doc make html @@ -1679,7 +1685,8 @@ :file:`tools/sphinxext/pyspecific.py` -- pydoc needs these to show topic and keyword help. -A "make update" updates the Subversion checkouts in :file:`tools/`. +A "make update" updates the Subversion checkouts in :file:`tools/`. (These +Subversion checkouts are ignored by the main Mercurial repository.) Without make @@ -1687,7 +1694,7 @@ You'll need to install the Sphinx package, either by checking it out via :: - svn co http://svn.python.org/projects/external/Sphinx-0.6.5/sphinx tools/sphinx + svn co http://svn.python.org/projects/external/Sphinx-1.0.7/sphinx tools/sphinx or by installing it from PyPI. diff --git a/setup.rst b/setup.rst --- a/setup.rst +++ b/setup.rst @@ -54,6 +54,8 @@ use and testing. (If you change C code, you will need to recompile the affected files as described below.) +Patches for the documentation can be made from the same repository; see +:ref:`documenting`. .. _compiling: @@ -232,7 +234,7 @@ ``Doc`` The official documentation. This is what http://docs.python.org/ uses. - To build the docs, see ``Doc/README.txt``. + See also :ref:`building-doc`. ``Grammar`` Contains the :abbr:`EBNF (Extended Backus-Naur Form)` grammar file for -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Tue Aug 21 00:11:02 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 21 Aug 2012 00:11:02 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE0OTU0?= =?utf-8?q?=3A_Clarify_the_interaction_of_weak_references_and_garbage_coll?= =?utf-8?q?ection=2E?= Message-ID: <3X18Nk2lzdzQ8j@mail.python.org> http://hg.python.org/cpython/rev/8600ae913b63 changeset: 78686:8600ae913b63 branch: 3.2 parent: 78683:b64947b6f947 user: Antoine Pitrou date: Tue Aug 21 00:07:07 2012 +0200 summary: Issue #14954: Clarify the interaction of weak references and garbage collection. Patch by Ethan Furman. files: Doc/library/weakref.rst | 5 ++++- Misc/ACKS | 1 + 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -24,7 +24,10 @@ A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, :term:`garbage collection` is free to destroy the referent and reuse its memory -for something else. A primary use for weak references is to implement caches or +for something else. However, until the object is actually destroyed the weak +reference may return the object even if there are no strong references to it. + +A primary use for weak references is to implement caches or mappings holding large objects, where it's desired that a large object not be kept alive solely because it appears in a cache or mapping. diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -317,6 +317,7 @@ Tadayoshi Funaba Gyro Funch Peter Funk +Ethan Furman Geoff Furnish Ulisses Furquim Hagen F?rstenau -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 00:11:33 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 21 Aug 2012 00:11:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2314954=3A_Clarify_the_interaction_of_weak_refere?= =?utf-8?q?nces_and_garbage_collection=2E?= Message-ID: <3X18PK5b3czQB4@mail.python.org> http://hg.python.org/cpython/rev/57c9ed276332 changeset: 78687:57c9ed276332 parent: 78685:9b28dff66ac3 parent: 78686:8600ae913b63 user: Antoine Pitrou date: Tue Aug 21 00:07:35 2012 +0200 summary: Issue #14954: Clarify the interaction of weak references and garbage collection. Patch by Ethan Furman. files: Doc/library/weakref.rst | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -24,7 +24,10 @@ A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, :term:`garbage collection` is free to destroy the referent and reuse its memory -for something else. A primary use for weak references is to implement caches or +for something else. However, until the object is actually destroyed the weak +reference may return the object even if there are no strong references to it. + +A primary use for weak references is to implement caches or mappings holding large objects, where it's desired that a large object not be kept alive solely because it appears in a cache or mapping. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 00:56:23 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 21 Aug 2012 00:56:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Improved_summary_section_i?= =?utf-8?q?n_whatsnew?= Message-ID: <3X19P30JPJzQLG@mail.python.org> http://hg.python.org/cpython/rev/a22ed8b509f5 changeset: 78688:a22ed8b509f5 user: Antoine Pitrou date: Tue Aug 21 00:53:06 2012 +0200 summary: Improved summary section in whatsnew files: Doc/whatsnew/3.3.rst | 56 +++++++++++++++++++++++++------ 1 files changed, 45 insertions(+), 11 deletions(-) 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 @@ -53,17 +53,43 @@ release, so it's worth checking back even after reading earlier versions. -Summary -======= - -Major changes since Python 3.2: - - * 4 new modules: :mod:`faulthandler`, :mod:`ipaddress`, :mod:`lzma` and :mod:`venv`. - * Syntax changes: - - - ``u'unicode'`` syntax is accepted again - - Add ``yield from`` syntax - +Summary -- Release highlights +============================= + +.. This section singles out the most important changes in Python 3.3. + Brevity is key. + +New syntax features: + +* New ``yield from`` expression for :ref:`generator delegation `. +* The ``u'unicode'`` syntax is accepted again for :class:`str` objects. + +New library modules: + +* :mod:`faulthandler` (helps debugging low-level crashes) +* :mod:`ipaddress` (high-level objects representing IP addresses and masks) +* :mod:`lzma` (compress data using the XZ / LZMA algorithm) +* :mod:`venv` (Python :ref:`virtual environments `, as in the + popular ``virtualenv`` package) + +New built-in features: + +* Reworked :ref:`I/O exception hierarchy `. + +Implementation improvements: + +* Rewritten :ref:`import machinery ` based on :mod:`importlib`. +* More compact :ref:`unicode strings `. +* More compact :ref:`attribute dictionaries `. + +Security improvements: + +* Hash randomization is switched on by default. + +Please read on for a comprehensive list of user-facing changes. + + +.. _pep-405: PEP 405: Virtual Environments ============================= @@ -220,6 +246,8 @@ details). +.. _pep-3151: + PEP 3151: Reworking the OS and IO exception hierarchy ===================================================== @@ -288,6 +316,8 @@ print("You are not allowed to read document.txt") +.. _pep-380: + PEP 380: Syntax for Delegating to a Subgenerator ================================================ @@ -489,6 +519,8 @@ '' +.. _pep-412: + PEP 412: Key-Sharing Dictionary =============================== @@ -518,6 +550,8 @@ or amends calling signatures or arguments. +.. _importlib: + Using importlib as the Implementation of Import =============================================== :issue:`2377` - Replace __import__ w/ importlib.__import__ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 01:11:34 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 21 Aug 2012 01:11:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Improve_the_pyvenv_entry?= Message-ID: <3X19kZ2qqKzQN3@mail.python.org> http://hg.python.org/cpython/rev/f8eabfed9a1d changeset: 78689:f8eabfed9a1d user: Antoine Pitrou date: Tue Aug 21 01:08:17 2012 +0200 summary: Improve the pyvenv entry files: Doc/using/scripts.rst | 2 ++ Doc/whatsnew/3.3.rst | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Doc/using/scripts.rst b/Doc/using/scripts.rst --- a/Doc/using/scripts.rst +++ b/Doc/using/scripts.rst @@ -3,6 +3,8 @@ Additional Tools and Scripts ============================ +.. _scripts-pyvenv: + pyvenv - Creating virtual environments -------------------------------------- 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 @@ -94,13 +94,22 @@ PEP 405: Virtual Environments ============================= -- inspired by ``virtualenv``, a tool widely used by the community -- change to the interpreter to avoid hacks - -The :mod:`venv` module and ``pyvenv`` script (inspired by ``virtualenv``, a -tool widely used by the community). - -.. also mention the interpreter changes that avoid the hacks used in virtualenv +:pep:`405` - Python Virtual Environments + PEP written by Carl Meyer, implemented by Carl Meyer and Vinay Sajip. + +Virtual environments help create separate Python setups while sharing a +system-wide base install, for ease of maintenance. Virtual environments +have their own set of private site packages (i.e. locally-installed +libraries), and are optionally segregated from the system-wide site +packages. Their concept and implementation are inspired by the popular +``virtualenv`` third-party package, but benefit from tighter integration +with the interpreter core. + +This PEP adds the :mod:`venv` module for programmatic access, and the +:ref:`pyvenv ` script for command-line access and +administration. The Python interpreter becomes aware of a ``pvenv.cfg`` +file whose existence signals the base of a virtual environment's directory +tree. PEP 420: Namespace Packages -- Repository URL: http://hg.python.org/cpython From ncoghlan at gmail.com Tue Aug 21 03:29:54 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 21 Aug 2012 11:29:54 +1000 Subject: [Python-checkins] cpython: Close #4966: revamp the sequence docs in order to better explain the state of In-Reply-To: <50326D6D.3050701@udel.edu> References: <3X0mV86gLXzPcJ@mail.python.org> <50326D6D.3050701@udel.edu> Message-ID: On Tue, Aug 21, 2012 at 3:01 AM, Terry Reedy wrote: > > > On 8/20/2012 3:14 AM, nick.coghlan wrote: >> >> +(5) >> + :meth:`clear` and :meth:`!copy` are included for consistency with the >> + interfaces of mutable containers that don't support slicing operations >> + (such as :class:`dict` and :class:`set`) >> + >> + .. versionadded:: 3.3 >> + :meth:`clear` and :meth:`!copy` methods. > > > Should !copy be copy (both places) or is '!' some markup I don't know about? It means you get the formatting without the cross-reference. I didn't write that bit - it shows up in the diff because it was moved around. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From ncoghlan at gmail.com Tue Aug 21 03:31:38 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 21 Aug 2012 11:31:38 +1000 Subject: [Python-checkins] cpython: s/path importer/path based finder/ (because the path based finder is not an In-Reply-To: References: <3X0gxd4vH0zQ5X@mail.python.org> Message-ID: On Tue, Aug 21, 2012 at 3:08 AM, Brett Cannon wrote: > Should that be "path-based"? I don't mind either way. I ain't trawling through to change it everywhere though - I've already done that once this week :) Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From python-checkins at python.org Tue Aug 21 03:41:30 2012 From: python-checkins at python.org (trent.nelson) Date: Tue, 21 Aug 2012 03:41:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1Mjg1?= =?utf-8?q?=3A_Refactor_connect_timeout_test_in_test=5Ftimeout=2E?= Message-ID: <3X1F3Z3jLszQQs@mail.python.org> http://hg.python.org/cpython/rev/9c22222af1f9 changeset: 78690:9c22222af1f9 branch: 3.2 parent: 78686:8600ae913b63 user: Trent Nelson date: Mon Aug 20 21:22:59 2012 -0400 summary: Issue #15285: Refactor connect timeout test in test_timeout. files: Lib/test/test_timeout.py | 90 +++++++++++++++++++++++++-- Misc/NEWS | 4 + 2 files changed, 86 insertions(+), 8 deletions(-) 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 @@ -138,14 +138,88 @@ self.sock.close() def testConnectTimeout(self): - # Choose a private address that is unlikely to exist to prevent - # failures due to the connect succeeding before the timeout. - # Use a dotted IP address to avoid including the DNS lookup time - # with the connect time. This avoids failing the assertion that - # the timeout occurred fast enough. - addr = ('10.0.0.0', 12345) - with support.transient_internet(addr[0]): - self._sock_operation(1, 0.001, 'connect', addr) + # Testing connect timeout is tricky: we need to have IP connectivity + # to a host that silently drops our packets. We can't simulate this + # from Python because it's a function of the underlying TCP/IP stack. + # So, the following Snakebite host has been defined: + blackhole = ('blackhole.snakebite.net', 56666) + + # Blackhole has been configured to silently drop any incoming packets. + # No RSTs (for TCP) or ICMP UNREACH (for UDP/ICMP) will be sent back + # to hosts that attempt to connect to this address: which is exactly + # what we need to confidently test connect timeout. + + # However, we want to prevent false positives. It's not unreasonable + # to expect certain hosts may not be able to reach the blackhole, due + # to firewalling or general network configuration. In order to improve + # our confidence in testing the blackhole, a corresponding 'whitehole' + # has also been set up using one port higher: + whitehole = ('whitehole.snakebite.net', 56667) + + # This address has been configured to immediately drop any incoming + # packets as well, but it does it respectfully with regards to the + # incoming protocol. RSTs are sent for TCP packets, and ICMP UNREACH + # is sent for UDP/ICMP packets. This means our attempts to connect to + # it should be met immediately with ECONNREFUSED. The test case has + # been structured around this premise: if we get an ECONNREFUSED from + # the whitehole, we proceed with testing connect timeout against the + # blackhole. If we don't, we skip the test (with a message about not + # getting the required RST from the whitehole within the required + # timeframe). + + # For the records, the whitehole/blackhole configuration has been set + # up using the 'pf' firewall (available on BSDs), using the following: + # + # ext_if="bge0" + # + # blackhole_ip="35.8.247.6" + # whitehole_ip="35.8.247.6" + # blackhole_port="56666" + # whitehole_port="56667" + # + # block return in log quick on $ext_if proto { tcp udp } \ + # from any to $whitehole_ip port $whitehole_port + # block drop in log quick on $ext_if proto { tcp udp } \ + # from any to $blackhole_ip port $blackhole_port + # + + skip = True + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # Use a timeout of 3 seconds. Why 3? Because it's more than 1, and + # less than 5. i.e. no particular reason. Feel free to tweak it if + # you feel a different value would be more appropriate. + timeout = 3 + sock.settimeout(timeout) + try: + sock.connect((whitehole)) + except socket.timeout: + pass + except IOError as err: + if err.errno == errno.ECONNREFUSED: + skip = False + finally: + sock.close() + del sock + + if skip: + self.skipTest( + "We didn't receive a connection reset (RST) packet from " + "{}:{} within {} seconds, so we're unable to test connect " + "timeout against the corresponding {}:{} (which is " + "configured to silently drop packets)." + .format( + whitehole[0], + whitehole[1], + timeout, + blackhole[0], + blackhole[1], + ) + ) + + # All that hard work just to test if connect times out in 0.001s ;-) + self.addr_remote = blackhole + with support.transient_internet(self.addr_remote[0]): + self._sock_operation(1, 0.001, 'connect', self.addr_remote) def testRecvTimeout(self): # Test recv() timeout diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -436,6 +436,10 @@ Tests ----- +- Issue #15285: Refactor the approach for testing connect timeouts using + two external hosts that have been configured specifically for this type + of test. + - Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 03:42:03 2012 From: python-checkins at python.org (trent.nelson) Date: Tue, 21 Aug 2012 03:42:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315285=3A_Refactor_connect_timeout_test_in_test?= =?utf-8?b?X3RpbWVvdXQu?= Message-ID: <3X1F4C30NZzQTN@mail.python.org> http://hg.python.org/cpython/rev/b86f3af4746c changeset: 78691:b86f3af4746c parent: 78689:f8eabfed9a1d parent: 78690:9c22222af1f9 user: Trent Nelson date: Mon Aug 20 21:40:21 2012 -0400 summary: Issue #15285: Refactor connect timeout test in test_timeout. files: Lib/test/test_timeout.py | 90 +++++++++++++++++++++++++-- Misc/NEWS | 4 + 2 files changed, 86 insertions(+), 8 deletions(-) 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 @@ -138,14 +138,88 @@ self.sock.close() def testConnectTimeout(self): - # Choose a private address that is unlikely to exist to prevent - # failures due to the connect succeeding before the timeout. - # Use a dotted IP address to avoid including the DNS lookup time - # with the connect time. This avoids failing the assertion that - # the timeout occurred fast enough. - addr = ('10.0.0.0', 12345) - with support.transient_internet(addr[0]): - self._sock_operation(1, 0.001, 'connect', addr) + # Testing connect timeout is tricky: we need to have IP connectivity + # to a host that silently drops our packets. We can't simulate this + # from Python because it's a function of the underlying TCP/IP stack. + # So, the following Snakebite host has been defined: + blackhole = ('blackhole.snakebite.net', 56666) + + # Blackhole has been configured to silently drop any incoming packets. + # No RSTs (for TCP) or ICMP UNREACH (for UDP/ICMP) will be sent back + # to hosts that attempt to connect to this address: which is exactly + # what we need to confidently test connect timeout. + + # However, we want to prevent false positives. It's not unreasonable + # to expect certain hosts may not be able to reach the blackhole, due + # to firewalling or general network configuration. In order to improve + # our confidence in testing the blackhole, a corresponding 'whitehole' + # has also been set up using one port higher: + whitehole = ('whitehole.snakebite.net', 56667) + + # This address has been configured to immediately drop any incoming + # packets as well, but it does it respectfully with regards to the + # incoming protocol. RSTs are sent for TCP packets, and ICMP UNREACH + # is sent for UDP/ICMP packets. This means our attempts to connect to + # it should be met immediately with ECONNREFUSED. The test case has + # been structured around this premise: if we get an ECONNREFUSED from + # the whitehole, we proceed with testing connect timeout against the + # blackhole. If we don't, we skip the test (with a message about not + # getting the required RST from the whitehole within the required + # timeframe). + + # For the records, the whitehole/blackhole configuration has been set + # up using the 'pf' firewall (available on BSDs), using the following: + # + # ext_if="bge0" + # + # blackhole_ip="35.8.247.6" + # whitehole_ip="35.8.247.6" + # blackhole_port="56666" + # whitehole_port="56667" + # + # block return in log quick on $ext_if proto { tcp udp } \ + # from any to $whitehole_ip port $whitehole_port + # block drop in log quick on $ext_if proto { tcp udp } \ + # from any to $blackhole_ip port $blackhole_port + # + + skip = True + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # Use a timeout of 3 seconds. Why 3? Because it's more than 1, and + # less than 5. i.e. no particular reason. Feel free to tweak it if + # you feel a different value would be more appropriate. + timeout = 3 + sock.settimeout(timeout) + try: + sock.connect((whitehole)) + except socket.timeout: + pass + except IOError as err: + if err.errno == errno.ECONNREFUSED: + skip = False + finally: + sock.close() + del sock + + if skip: + self.skipTest( + "We didn't receive a connection reset (RST) packet from " + "{}:{} within {} seconds, so we're unable to test connect " + "timeout against the corresponding {}:{} (which is " + "configured to silently drop packets)." + .format( + whitehole[0], + whitehole[1], + timeout, + blackhole[0], + blackhole[1], + ) + ) + + # All that hard work just to test if connect times out in 0.001s ;-) + self.addr_remote = blackhole + with support.transient_internet(self.addr_remote[0]): + self._sock_operation(1, 0.001, 'connect', self.addr_remote) def testRecvTimeout(self): # Test recv() timeout diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -86,6 +86,10 @@ Tests ----- +- Issue #15285: Refactor the approach for testing connect timeouts using + two external hosts that have been configured specifically for this type + of test. + - Issue #15743: Remove the deprecated method usage in urllib tests. Patch by Jeff Knupp. -- Repository URL: http://hg.python.org/cpython From ezio.melotti at gmail.com Tue Aug 21 03:55:10 2012 From: ezio.melotti at gmail.com (Ezio Melotti) Date: Tue, 21 Aug 2012 04:55:10 +0300 Subject: [Python-checkins] cpython: Close #4966: revamp the sequence docs in order to better explain the state of In-Reply-To: <3X0mV86gLXzPcJ@mail.python.org> References: <3X0mV86gLXzPcJ@mail.python.org> Message-ID: <5032EA7E.70107@gmail.com> Hi, On 20/08/2012 10.14, nick.coghlan wrote: > http://hg.python.org/cpython/rev/463f52d20314 > changeset: 78665:463f52d20314 > user: Nick Coghlan > date: Mon Aug 20 17:14:07 2012 +1000 > summary: > Close #4966: revamp the sequence docs in order to better explain the state of modern Python > > [...] > +Sequence Types --- :class:`list`, :class:`tuple`, :class:`range` > +================================================================ > + These 3 links in the section title redirect to the functions.html page. I think it would be better if they linked to the appropriate subsection instead, and in the case of the subsections (e.g. "Text Sequence Type --- str") they shouldn't be links. The same comment can be applied to other titles as well. > +There are three basic sequence types: lists, tuples, and range objects. > +Additional sequence types tailored for processing of > +:ref:`binary data ` and :ref:`text strings ` are > +described in dedicated sections. > + > + > +.. _typesseq-common: > + > +Common Sequence Operations > +-------------------------- > + > +.. index:: object: sequence > + > [...] > +are sequences of the same type, *n*, *i*, *j* and *k* are integers and *x* is > +an arbitrary object that meets any type and value restrictions imposed by *s*. > + > +The ``in`` and ``not in`` operations have the same priorities as the > +comparison operations. The ``+`` (concatenation) and ``*`` (repetition) > +operations have the same priority as the corresponding numeric operations. > + > ++--------------------------+--------------------------------+----------+ > +| Operation | Result | Notes | > ++==========================+================================+==========+ > +| ``x in s`` | ``True`` if an item of *s* is | \(1) | > +| | equal to *x*, else ``False`` | | > ++--------------------------+--------------------------------+----------+ > +| ``x not in s`` | ``False`` if an item of *s* is | \(1) | > +| | equal to *x*, else ``True`` | | > ++--------------------------+--------------------------------+----------+ > +| ``s + t`` | the concatenation of *s* and | (6)(7) | > +| | *t* | | > ++--------------------------+--------------------------------+----------+ > +| ``s * n, n * s`` | *n* shallow copies of *s* | (2)(7) | I would use '``s * n`` or ``n * s``' here. > +| | concatenated | | > ++--------------------------+--------------------------------+----------+ > +| ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) | > ++--------------------------+--------------------------------+----------+ > +| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) | > ++--------------------------+--------------------------------+----------+ > +| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) | > +| | with step *k* | | > ++--------------------------+--------------------------------+----------+ > +| ``len(s)`` | length of *s* | | > ++--------------------------+--------------------------------+----------+ > +| ``min(s)`` | smallest item of *s* | | > ++--------------------------+--------------------------------+----------+ > +| ``max(s)`` | largest item of *s* | | > ++--------------------------+--------------------------------+----------+ > +| ``s.index(x, [i[, j]])`` | index of the first occurence | \(8) | This should be ``s.index(x[, i[, j]])`` > +| | of *x* in *s* (at or after | | > +| | index *i* and before index *j*)| | > ++--------------------------+--------------------------------+----------+ > +| ``s.count(x)`` | total number of occurences of | | > +| | *x* in *s* | | > ++--------------------------+--------------------------------+----------+ > + > +Sequences of the same type also support comparisons. In particular, tuples > +and lists are compared lexicographically by comparing corresponding elements. > +This means that to compare equal, every element must compare equal and the > +two sequences must be of the same type and have the same length. (For full > +details see :ref:`comparisons` in the language reference.) > > [...] > > (6) > - Concatenating immutable strings always results in a new object. This means > - that building up a string by repeated concatenation will have a quadratic > - runtime cost in the total string length. To get a linear runtime cost, > - you must switch to one of the alternatives below: > + Concatenating immutable sequences always results in a new object. This > + means that building up a sequence by repeated concatenation will have a > + quadratic runtime cost in the total sequence length. To get a linear > + runtime cost, you must switch to one of the alternatives below: > > * if concatenating :class:`str` objects, you can build a list and use > - :meth:`str.join` at the end; > + :meth:`str.join` at the end or else write to a :class:`io.StringIO` > + instance and retrieve its value when complete; > > * if concatenating :class:`bytes` objects, you can similarly use > - :meth:`bytes.join`, or you can do in-place concatenation with a > - :class:`bytearray` object. :class:`bytearray` objects are mutable and > - have an efficient overallocation mechanism. > - > + :meth:`bytes.join` or :class:`io.BytesIO`, or you can do in-place > + concatenation with a :class:`bytearray` object. :class:`bytearray` > + objects are mutable and have an efficient overallocation mechanism. > + > + * if concatenating :class:`tuple` objects, extend a :class:`list` instead. > + > + * for other types, investigate the relevant class documentation > + The trailing punctuation of the elements in this list is inconsistent. > [...] > + > +Mutable Sequence Types > +---------------------- > + > +.. index:: > + triple: mutable; sequence; types > + object: list > + object: bytearray > + > +The operations in the following table are defined on mutable sequence types. > +The :class:`collections.abc.MutableSequence` ABC is provided to make it > +easier to correctly implement these operations on custom sequence types. > + > +In the table *s* is an instance of a mutable sequence type, *t* is any > +iterable object and *x* is an arbitrary object that meets any type > +and value restrictions imposed by *s* (for example, :class:`bytearray` only > +accepts integers that meet the value restriction ``0 <= x <= 255``). > + > + > +.. index:: > + triple: operations on; sequence; types > + triple: operations on; list; type > + pair: subscript; assignment > + pair: slice; assignment > + statement: del > + single: append() (sequence method) > + single: extend() (sequence method) > + single: count() (sequence method) > + single: index() (sequence method) > + single: insert() (sequence method) > + single: pop() (sequence method) > + single: remove() (sequence method) > + single: reverse() (sequence method) > + You missed clear() from this list. > ++------------------------------+--------------------------------+---------------------+ > +| Operation | Result | Notes | > ++==============================+================================+=====================+ > +| ``s[i] = x`` | item *i* of *s* is replaced by | | > +| | *x* | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s[i:j] = t`` | slice of *s* from *i* to *j* | | > +| | is replaced by the contents of | | > +| | the iterable *t* | | > ++------------------------------+--------------------------------+---------------------+ > +| ``del s[i:j]`` | same as ``s[i:j] = []`` | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` | \(1) | > +| | are replaced by those of *t* | | > ++------------------------------+--------------------------------+---------------------+ > +| ``del s[i:j:k]`` | removes the elements of | | > +| | ``s[i:j:k]`` from the list | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.append(x)`` | same as ``s[len(s):len(s)] = | | > +| | [x]`` | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.clear()`` | remove all items from ``s`` | \(5) | > +| | (same as ``del s[:]``) | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.copy()`` | return a shallow copy of ``s`` | \(5) | > +| | (same as ``s[:]``) | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.extend(t)`` | same as ``s[len(s):len(s)] = | | > +| | t`` | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | \(2) | > +| | return x`` | | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | \(3) | > ++------------------------------+--------------------------------+---------------------+ > +| ``s.reverse()`` | reverses the items of *s* in | \(4) | > +| | place | | > ++------------------------------+--------------------------------+---------------------+ > + And index() from this table. Also in the "Result" column the descriptions in prose are OK, but I find some of the "same as ..." ones not very readable (or even fairly obscure). (I think I saw something similar in the doc of list.append() too.) > [...] > + > +Tuples > +------ > + > +.. index:: object: tuple > + > +Tuples are immutable sequences, typically used to store collections of > +heterogeneous data (such as the 2-tuples produced by the :func:`enumerate` > +built-in). Tuples are also used for cases where an immutable sequence of > +homogeneous data is needed (such as allowing storage in a :class:`set` or > +:class:`dict` instance). > + > +Tuples may be constructed in a number of ways: > + > +* Using a pair of parentheses to denote the empty tuple: ``()`` > +* Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)`` > +* Separating items with commas: ``a, b, c`` or ``(a, b, c)`` > +* Using the :func:`tuple` built-in: ``tuple()`` or ``tuple(iterable)`` > + > +Note that the parentheses are optional (except in the empty tuple case, or > +when needed to avoid syntactic ambiguity). It is actually the comma which > +makes a tuple, not the parentheses. > + Is it worth mentioning a function call as an example of syntactic ambiguity? Someone might wonder if foo(a, b, c) is actually passing a 3-elements tuple or 3 distinct values. > +Tuples implement all of the :ref:`common ` sequence > +operations. > + > +For heterogeneous collections of data, :func:`collections.namedtuple` may > +be more appropriate than a simple tuple object. > + This claim is maybe a bit too strong. I think the main reason to use namedtuples is being able to access the elements via t.name, rather than t[pos], and while this can be useful for basically every heterogeneous tuple, I think that plain tuples are still preferred. On a separate note, should tuple unpacking be mentioned here? (a link to a separate section of the doc is enough.) > + > +.. _typesseq-range: > + > +Ranges > +------ > + > +.. index:: object: range > + > +The :class:`range` type represents an immutable sequence of numbers and is > +commonly used for looping a specific number of times. I would mention explicitly "in :keyword:`for` loops" -- ranges don't loop on their own (I think people familiar with Ruby and/or JQuery might get confused here). > Instances are created > +using the :func:`range` built-in. > + > +For positive indices with results between the defined ``start`` and ``stop`` > +values, integers within the range are determined by the formula: > +``r[i] = start + step*i`` > + > +For negative indices and slicing operations, a range instance determines the > +appropriate result for the corresponding tuple and returns either the > +appropriate integer (for negative indices) or an appropriate range object > +(for slicing operations) . > + I thought that these two paragraphs were talking about positive and negative start/stop/step until I reached the middle of the second paragraph (the word "indices" wasn't enough to realize that these paragraphs are about indexing/slicing, probably because they are rarely used and I wasn't expecting to find them at this point of the doc). Maybe it's better to move the paragraphs at the bottom of the section. > [...] > +.. _textseq: > + > +Text Sequence Type --- :class:`str` > +=================================== > + > +.. index:: > + object: string > + object: bytes > + object: bytearray > + object: io.StringIO > + > + > +Textual data in Python is handled with :class:`str` objects, which are > +immutable sequences of Unicode code points. String literals are > +written in a variety of ways: > + > +* Single quotes: ``'allows embedded "double" quotes'`` > +* Double quotes: ``"allows embedded 'single' quotes"``. > +* Triple quoted: ``'''Three single quotes'''``, ``"""Three double quotes"""`` > + > +Triple quoted strings may span multiple lines - all associated whitespace will > +be included in the string literal. > + > +String literals that are part of a single expression and have only whitespace > +between them will be implicitly converted to a single string literal. > + Is it a string /literal/ they are converted to? Anyway a simple ('foo' 'bar') == 'foobar' example might make this sentence more understandable. > +See :ref:`strings` for more about the various forms of string literal, > +including supported escape sequences, and the ``r`` ("raw") prefix that > +disables most escape sequence processing. > + > +Strings may also be created from other objects with the :func:`str` built-in. > + > +Since there is no separate "character" type, indexing a string produces > +strings of length 1. That is, for a non-empty string *s*, ``s[0] == s[0:1]``. > + > +There is also no mutable string type, but :meth:`str.join` or > +:class:`io.StringIO` can be used to efficiently construct strings from > +multiple fragments. > + str.format() deserves to be mentioned here too. > +.. versionchanged:: 3.3 > + For backwards compatibility with the Python 2 series, the ``u`` prefix is > + once again permitted on string literals. It has no effect on the meaning > + of string literals and cannot be combined with the ``r`` prefix. > > .. _string-methods: > > String Methods > -------------- > > -.. index:: pair: string; methods > - > -String objects support the methods listed below. > - > -In addition, Python's strings support the sequence type methods described in the > -:ref:`typesseq` section. To output formatted strings, see the > -:ref:`string-formatting` section. Also, see the :mod:`re` module for string > -functions based on regular expressions. > +.. index:: > + pair: string; methods > + module: re > + > +Strings implement all of the :ref:`common ` sequence > +operations, along with the additional methods described below. > + > +Strings also support two styles of string formatting, one providing a large > +degree of flexibility and customization (see :meth:`str.format`, > +:ref:`formatstrings` and :ref:`string-formatting`) I'm not sure linking to string-formatting is useful here, if anything, I would link to the format examples instead. > and the other based on C > +``printf`` style formatting that handles a narrower range of types and is > +slightly harder to use correctly, but is often faster for the cases it can > +handle (:ref:`old-string-formatting`). > + > +The :ref:`textservices` section of the standard library covers a number of > +other modules that provide various text related utilities (including regular > +expression support in the :mod:`re` module). > > .. method:: str.capitalize() > > @@ -1462,8 +1755,8 @@ > > .. _old-string-formatting: > > -Old String Formatting Operations > --------------------------------- > +``printf``-style String Formatting > +---------------------------------- I noticed that here there's this fairly long section about the "old" string formatting and nothing about the "new" formatting. Maybe this should be moved together with the new formatting doc, so that all the detailed formatting docs are in the same place. (This would also help making this less noticeable) > > [...] > + > +Bytes > +----- > + > +.. index:: object: bytes > + > +Bytes objects are immutable sequences of single bytes. Since many major > +binary protocols are based on the ASCII text encoding, bytes objects offer > +several methods that are only valid when working with ASCII compatible > +data and are closely related to string objects in a variety of other ways. > + > +Firstly, the syntax for bytes literals is largely the same as that for string > +literals, except that a ``b`` prefix is added: > + > +* Single quotes: ``b'still allows embedded "double" quotes'`` > +* Double quotes: ``b"still allows embedded 'single' quotes"``. > +* Triple quoted: ``b'''3 single quotes'''``, ``b"""3 double quotes"""`` > + > +Only ASCII characters are permitted in bytes literals (regardless of the > +declared source code encoding). Any binary values over 127 must be entered > +into bytes literals using the appropriate escape sequence. > + > +As with string literals, bytes literals may also use a ``r`` prefix to disable > +processing of escape sequences. See :ref:`strings` for more about the various > +forms of bytes literal, including supported escape sequences. > + > +While bytes literals and representations are based on ASCII text, bytes > +objects actually behave like immutable sequences of integers, with each > +value in the sequence restricted such that ``0 <= x < 256`` (attempts to Earlier you used 0 <= x <= 255. > [...] > +All other string methods are supported, although sometimes with slight > +differences in functionality and semantics (as described below). > > .. note:: > > The methods on bytes and bytearray objects don't accept strings as their > arguments, just as the methods on strings don't accept bytes as their > - arguments. For example, you have to write :: > + arguments. For example, you have to write:: > > a = "abc" > b = a.replace("a", "f") > > - and :: > + and:: > > a = b"abc" > b = a.replace(b"a", b"f") > Using ``'abc'.replace('a', 'f')`` and ``b'abc'.replace(b'a', b'f')`` inline would be better IMHO, given that the current note takes lot of space to explain a trivial concept. > +Whenever a bytes or bytearray method needs to interpret the bytes as > +characters (e.g. the :meth:`is...` methods, :meth:`split`, :meth:`strip`), > +the ASCII character set is assumed (text strings use Unicode semantics). > + > +.. note:: > + Using these ASCII based methods to manipulate binary data that is not > + stored in an ASCII based format may lead to data corruption. > + > +The search operations (:keyword:`in`, :meth:`count`, :meth:`find`, > +:meth:`index`, :meth:`rfind` and :meth:`rindex`) all accept both integers > +in the range 0 to 255 as well as bytes and byte array sequences. > + 0 to 255 (included). Same in the note below. > +.. versionchanged:: 3.3 > + All of the search methods also accept an integer in range 0 to 255 > + (a byte) as their first argument. > + > + > +Each bytes and bytearray instance provides a :meth:`decode` convenience > +method that is the inverse of "meth:`str.encode`: s/"/:/ > > [...] > + > +Set Types --- :class:`set`, :class:`frozenset` > +============================================== > + > +.. index:: object: set > + > +A :dfn:`set` object is an unordered collection of distinct :term:`hashable` objects. > +Common uses include membership testing, removing duplicates from a sequence, and > +computing mathematical operations such as intersection, union, difference, and > +symmetric difference. > +(For other containers see the built in :class:`dict`, :class:`list`, I think this should be "built-in". The dict introduction has another occurrence of this. > [...] > + > +.. class:: dict([arg]) > + > + Return a new dictionary initialized from an optional positional argument or > + from a set of keyword arguments. If no arguments are given, return a new > + empty dictionary. If the positional argument *arg* is a mapping object, > + return a dictionary mapping the same keys to the same values as does the > + mapping object. Otherwise the positional argument must be a sequence, a > + container that supports iteration, or an iterator object. The elements of > + the argument must each also be of one of those kinds, and each must in turn > + contain exactly two objects. The first is used as a key in the new > + dictionary, and the second as the key's value. If a given key is seen more > + than once, the last value associated with it is retained in the new > + dictionary. > + > + If keyword arguments are given, the keywords themselves with their associated > + values are added as items to the dictionary. If a key is specified both in > + the positional argument and as a keyword argument, the value associated with > + the keyword is retained in the dictionary. For example, these all return a > + dictionary equal to ``{"one": 1, "two": 2}``: > + > + * ``dict(one=1, two=2)`` > + * ``dict({'one': 1, 'two': 2})`` > + * ``dict(zip(('one', 'two'), (1, 2)))`` > + * ``dict([['two', 2], ['one', 1]])`` > + I would use a list of tuples in the last example. > + The first example only works for keys that are valid Python identifiers; the > + others work with any valid keys. > + > [...] Thanks a lot for working on this! Best Regards, Ezio Melotti From solipsis at pitrou.net Tue Aug 21 06:10:04 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 21 Aug 2012 06:10:04 +0200 Subject: [Python-checkins] Daily reference leaks (f8eabfed9a1d): sum=3 Message-ID: results for f8eabfed9a1d on branch "default" -------------------------------------------- test_capi leaked [1, 1, 1] references, sum=3 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogzWFpBh', '-x'] From python-checkins at python.org Tue Aug 21 08:31:43 2012 From: python-checkins at python.org (stefan.krah) Date: Tue, 21 Aug 2012 08:31:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NzM2?= =?utf-8?q?=3A_Fix_overflow_in_=5FPySequence=5FBytesToCharpArray=28=29=2E?= Message-ID: <3X1MVR1Gm6zQK9@mail.python.org> http://hg.python.org/cpython/rev/dbbf3ccf72e8 changeset: 78692:dbbf3ccf72e8 branch: 3.2 parent: 78690:9c22222af1f9 user: Stefan Krah date: Tue Aug 21 08:16:09 2012 +0200 summary: Issue #15736: Fix overflow in _PySequence_BytesToCharpArray(). files: Lib/test/test_capi.py | 8 ++++++++ Objects/abstract.c | 7 +++++++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -67,6 +67,14 @@ return 1 self.assertRaises(TypeError, _posixsubprocess.fork_exec, 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + # Issue #15736: overflow in _PySequence_BytesToCharpArray() + class Z(object): + def __len__(self): + return sys.maxsize + def __getitem__(self, i): + return b'x' + self.assertRaises(MemoryError, _posixsubprocess.fork_exec, + 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') def test_subprocess_fork_exec(self): diff --git a/Objects/abstract.c b/Objects/abstract.c --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2728,6 +2728,13 @@ if (argc == -1) return NULL; + assert(argc >= 0); + + if ((size_t)argc > (PY_SSIZE_T_MAX-sizeof(char *)) / sizeof(char *)) { + PyErr_NoMemory(); + return NULL; + } + array = malloc((argc + 1) * sizeof(char *)); if (array == NULL) { PyErr_NoMemory(); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 08:31:44 2012 From: python-checkins at python.org (stefan.krah) Date: Tue, 21 Aug 2012 08:31:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogTWVyZ2UgMy4yLg==?= Message-ID: <3X1MVS6CNkzQK9@mail.python.org> http://hg.python.org/cpython/rev/221a640475f7 changeset: 78693:221a640475f7 parent: 78691:b86f3af4746c parent: 78692:dbbf3ccf72e8 user: Stefan Krah date: Tue Aug 21 08:25:41 2012 +0200 summary: Merge 3.2. files: Lib/test/test_capi.py | 8 ++++++++ Objects/abstract.c | 7 +++++++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -90,6 +90,14 @@ return 1 self.assertRaises(TypeError, _posixsubprocess.fork_exec, 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) + # Issue #15736: overflow in _PySequence_BytesToCharpArray() + class Z(object): + def __len__(self): + return sys.maxsize + def __getitem__(self, i): + return b'x' + self.assertRaises(MemoryError, _posixsubprocess.fork_exec, + 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') def test_subprocess_fork_exec(self): diff --git a/Objects/abstract.c b/Objects/abstract.c --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2710,6 +2710,13 @@ if (argc == -1) return NULL; + assert(argc >= 0); + + if ((size_t)argc > (PY_SSIZE_T_MAX-sizeof(char *)) / sizeof(char *)) { + PyErr_NoMemory(); + return NULL; + } + array = malloc((argc + 1) * sizeof(char *)); if (array == NULL) { PyErr_NoMemory(); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 09:43:10 2012 From: python-checkins at python.org (nick.coghlan) Date: Tue, 21 Aug 2012 09:43:10 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Address_most_of_Ezio=27s_c?= =?utf-8?q?omments=2E_str/bytes/bytearray_docs_still_need?= Message-ID: <3X1P4t3cxSzQNv@mail.python.org> http://hg.python.org/cpython/rev/28f424022c6e changeset: 78694:28f424022c6e user: Nick Coghlan date: Tue Aug 21 17:42:52 2012 +1000 summary: Address most of Ezio's comments. str/bytes/bytearray docs still need consolidation files: Doc/library/functions.rst | 109 +------ Doc/library/stdtypes.rst | 365 +++++++++++++++++-------- 2 files changed, 266 insertions(+), 208 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -17,9 +17,9 @@ :func:`bin` :func:`eval` :func:`int` :func:`open` :func:`str` :func:`bool` :func:`exec` :func:`isinstance` :func:`ord` :func:`sum` :func:`bytearray` :func:`filter` :func:`issubclass` :func:`pow` :func:`super` -:func:`bytes` :func:`float` :func:`iter` :func:`print` :func:`tuple` +:func:`bytes` :func:`float` :func:`iter` :func:`print` |func-tuple|_ :func:`callable` :func:`format` :func:`len` :func:`property` :func:`type` -:func:`chr` |func-frozenset|_ :func:`list` :func:`range` :func:`vars` +:func:`chr` |func-frozenset|_ |func-list|_ |func-range|_ :func:`vars` :func:`classmethod` :func:`getattr` :func:`locals` :func:`repr` :func:`zip` :func:`compile` :func:`globals` :func:`map` :func:`reversed` :func:`__import__` :func:`complex` :func:`hasattr` :func:`max` :func:`round` @@ -33,6 +33,9 @@ .. |func-frozenset| replace:: ``frozenset()`` .. |func-memoryview| replace:: ``memoryview()`` .. |func-set| replace:: ``set()`` +.. |func-list| replace:: ``list()`` +.. |func-tuple| replace:: ``tuple()`` +.. |func-range| replace:: ``range()`` .. function:: abs(x) @@ -93,6 +96,7 @@ .. index:: pair: Boolean; type +.. _func-bytearray: .. function:: bytearray([source[, encoding[, errors]]]) Return a new array of bytes. The :class:`bytearray` type is a mutable @@ -119,6 +123,7 @@ Without an argument, an array of size 0 is created. +.. _func-bytes: .. function:: bytes([source[, encoding[, errors]]]) Return a new "bytes" object, which is an immutable sequence of integers in @@ -692,16 +697,12 @@ sequence (string, tuple or list) or a mapping (dictionary). +.. _func-list: .. function:: list([iterable]) + :noindex: - Return a list whose items are the same and in the same order as *iterable*'s - items. *iterable* may be either a sequence, a container that supports - iteration, or an iterator object. If *iterable* is already a list, a copy is - made and returned, similar to ``iterable[:]``. For instance, ``list('abc')`` - returns ``['a', 'b', 'c']`` and ``list( (1, 2, 3) )`` returns ``[1, 2, 3]``. - If no argument is given, returns a new empty list, ``[]``. - - :class:`list` is a mutable sequence type, as documented in :ref:`typesseq`. + Rather than being a function, :class:`list` is actually a mutable + sequence type, as documented in :ref:`typesseq`. .. function:: locals() @@ -1059,79 +1060,12 @@ ``fdel`` corresponding to the constructor arguments. -.. XXX does accept objects with __index__ too +.. _func-range: .. function:: range([start,] stop[, step]) + :noindex: - This is a versatile function to create iterables yielding arithmetic - progressions. It is most often used in :keyword:`for` loops. The arguments - must be integers. If the *step* argument is omitted, it defaults to ``1``. - If the *start* argument is omitted, it defaults to ``0``. The full form - returns an iterable of integers ``[start, start + step, start + 2 * step, - ...]``. If *step* is positive, the last element is the largest ``start + i * - step`` less than *stop*; if *step* is negative, the last element is the - smallest ``start + i * step`` greater than *stop*. *step* must not be zero - (or else :exc:`ValueError` is raised). Range objects have read-only data - attributes :attr:`start`, :attr:`stop` and :attr:`step` which return the - argument values (or their default). Example: - - >>> list(range(10)) - [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - >>> list(range(1, 11)) - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - >>> list(range(0, 30, 5)) - [0, 5, 10, 15, 20, 25] - >>> list(range(0, 10, 3)) - [0, 3, 6, 9] - >>> list(range(0, -10, -1)) - [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] - >>> list(range(0)) - [] - >>> list(range(1, 0)) - [] - - Range objects implement the :class:`collections.Sequence` ABC, and provide - features such as containment tests, element index lookup, slicing and - support for negative indices (see :ref:`typesseq`): - - >>> r = range(0, 20, 2) - >>> r - range(0, 20, 2) - >>> 11 in r - False - >>> 10 in r - True - >>> r.index(10) - 5 - >>> r[5] - 10 - >>> r[:5] - range(0, 10, 2) - >>> r[-1] - 18 - - Testing range objects for equality with ``==`` and ``!=`` compares - them as sequences. That is, two range objects are considered equal if - they represent the same sequence of values. (Note that two range - objects that compare equal might have different :attr:`start`, - :attr:`stop` and :attr:`step` attributes, for example ``range(0) == - range(2, 1, 3)`` or ``range(0, 3, 2) == range(0, 4, 2)``.) - - Ranges containing absolute values larger than :data:`sys.maxsize` are permitted - but some features (such as :func:`len`) will raise :exc:`OverflowError`. - - .. versionchanged:: 3.2 - Implement the Sequence ABC. - Support slicing and negative indices. - Test integers for membership in constant time instead of iterating - through all items. - - .. versionchanged:: 3.3 - Define '==' and '!=' to compare range objects based on the - sequence of values they define (instead of comparing based on - object identity). - - .. versionadded:: 3.3 - The :attr:`start`, :attr:`stop` and :attr:`step` attributes. + Rather than being a function, :class:`range` is actually an immutable + sequence type, as documented in :ref:`typesseq`. .. function:: repr(object) @@ -1251,6 +1185,7 @@ standard type hierarchy in :ref:`types`. +.. _func-str: .. function:: str([object[, encoding[, errors]]]) Return a string version of an object, using one of the following modes: @@ -1352,16 +1287,12 @@ `_. +.. _func-tuple: .. function:: tuple([iterable]) + :noindex: - Return a tuple whose items are the same and in the same order as *iterable*'s - items. *iterable* may be a sequence, a container that supports iteration, or an - iterator object. If *iterable* is already a tuple, it is returned unchanged. - For instance, ``tuple('abc')`` returns ``('a', 'b', 'c')`` and ``tuple([1, 2, - 3])`` returns ``(1, 2, 3)``. If no argument is given, returns a new empty - tuple, ``()``. - - :class:`tuple` is an immutable sequence type, as documented in :ref:`typesseq`. + Rather than being a function, :class:`tuple` is actually an immutable + sequence type, as documented in :ref:`typesseq`. .. function:: type(object) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -829,6 +829,20 @@ comparison operations. The ``+`` (concatenation) and ``*`` (repetition) operations have the same priority as the corresponding numeric operations. +.. index:: + triple: operations on; sequence; types + builtin: len + builtin: min + builtin: max + pair: concatenation; operation + pair: repetition; operation + pair: subscript; operation + pair: slice; operation + operator: in + operator: not in + single: count() (sequence method) + single: index() (sequence method) + +--------------------------+--------------------------------+----------+ | Operation | Result | Notes | +==========================+================================+==========+ @@ -841,8 +855,8 @@ | ``s + t`` | the concatenation of *s* and | (6)(7) | | | *t* | | +--------------------------+--------------------------------+----------+ -| ``s * n, n * s`` | *n* shallow copies of *s* | (2)(7) | -| | concatenated | | +| ``s * n`` or | *n* shallow copies of *s* | (2)(7) | +| ``n * s`` | concatenated | | +--------------------------+--------------------------------+----------+ | ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) | +--------------------------+--------------------------------+----------+ @@ -857,7 +871,7 @@ +--------------------------+--------------------------------+----------+ | ``max(s)`` | largest item of *s* | | +--------------------------+--------------------------------+----------+ -| ``s.index(x, [i[, j]])`` | index of the first occurence | \(8) | +| ``s.index(x[, i[, j]])`` | index of the first occurence | \(8) | | | of *x* in *s* (at or after | | | | index *i* and before index *j*)| | +--------------------------+--------------------------------+----------+ @@ -871,18 +885,6 @@ two sequences must be of the same type and have the same length. (For full details see :ref:`comparisons` in the language reference.) -.. index:: - triple: operations on; sequence; types - builtin: len - builtin: min - builtin: max - pair: concatenation; operation - pair: repetition; operation - pair: subscript; operation - pair: slice; operation - operator: in - operator: not in - Notes: (1) @@ -948,14 +950,14 @@ * if concatenating :class:`str` objects, you can build a list and use :meth:`str.join` at the end or else write to a :class:`io.StringIO` - instance and retrieve its value when complete; + instance and retrieve its value when complete * if concatenating :class:`bytes` objects, you can similarly use :meth:`bytes.join` or :class:`io.BytesIO`, or you can do in-place concatenation with a :class:`bytearray` object. :class:`bytearray` - objects are mutable and have an efficient overallocation mechanism. - - * if concatenating :class:`tuple` objects, extend a :class:`list` instead. + objects are mutable and have an efficient overallocation mechanism + + * if concatenating :class:`tuple` objects, extend a :class:`list` instead * for other types, investigate the relevant class documentation @@ -982,6 +984,7 @@ .. index:: triple: immutable; sequence; types object: tuple + builtin: hash The only operation that immutable sequence types generally implement that is not also implemented by mutable sequence types is support for the :func:`hash` @@ -1022,9 +1025,9 @@ pair: slice; assignment statement: del single: append() (sequence method) + single: clear() (sequence method) + single: copy() (sequence method) single: extend() (sequence method) - single: count() (sequence method) - single: index() (sequence method) single: insert() (sequence method) single: pop() (sequence method) single: remove() (sequence method) @@ -1048,24 +1051,29 @@ | ``del s[i:j:k]`` | removes the elements of | | | | ``s[i:j:k]`` from the list | | +------------------------------+--------------------------------+---------------------+ -| ``s.append(x)`` | same as ``s[len(s):len(s)] = | | -| | [x]`` | | +| ``s.append(x)`` | appends *x* to the end of the | | +| | sequence (same as | | +| | ``s[len(s):len(s)] = [x]``) | | +------------------------------+--------------------------------+---------------------+ -| ``s.clear()`` | remove all items from ``s`` | \(5) | +| ``s.clear()`` | removes all items from ``s`` | \(5) | | | (same as ``del s[:]``) | | +------------------------------+--------------------------------+---------------------+ -| ``s.copy()`` | return a shallow copy of ``s`` | \(5) | +| ``s.copy()`` | creates a shallow copy of ``s``| \(5) | | | (same as ``s[:]``) | | +------------------------------+--------------------------------+---------------------+ -| ``s.extend(t)`` | same as ``s[len(s):len(s)] = | | -| | t`` | | +| ``s.extend(t)`` | extends *s* with the | | +| | contents of *t* (same as | | +| | ``s[len(s):len(s)] = t``) | | +------------------------------+--------------------------------+---------------------+ -| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | | +| ``s.insert(i, x)`` | inserts *x* into *s* at the | | +| | index given by *i* | | +| | (same as ``s[i:i] = [x]``) | | +------------------------------+--------------------------------+---------------------+ -| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | \(2) | -| | return x`` | | +| ``s.pop([i])`` | retrieves the item at *i* and | \(2) | +| | also removes it from *s* | | +------------------------------+--------------------------------+---------------------+ -| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | \(3) | +| ``s.remove(x)`` | remove the first item from *s* | \(3) | +| | where ``s[i] == x`` | | +------------------------------+--------------------------------+---------------------+ | ``s.reverse()`` | reverses the items of *s* in | \(4) | | | place | | @@ -1109,55 +1117,67 @@ homogeneous items (where the precise degree of similarity will vary by application). -Lists may be constructed in several ways: - -* Using a pair of square brackets to denote the empty list: ``[]`` -* Using square brackets, separating items with commas: ``[a]``, ``[a, b, c]`` -* Using a list comprehension: ``[x for x in iterable]`` -* Using the :func:`list` built-in: ``list()`` or ``list(iterable)`` - -Many other operations also produce lists, including the :func:`sorted` built-in. - -Lists implement all of the :ref:`common ` and -:ref:`mutable ` sequence operations. Lists also provide the -following additional method: - -.. method:: list.sort(*, key=None, reverse=None) - - This method sorts the list in place, using only ``<`` comparisons - between items. Exceptions are not suppressed - if any comparison operations - fail, the entire sort operation will fail (and the list will likely be left - in a partially modified state). - - *key* specifies a function of one argument that is used to extract a - comparison key from each list element (for example, ``key=str.lower``). - The key corresponding to each item in the list is calculated once and - then used for the entire sorting process. The default value of ``None`` - means that list items are sorted directly without calculating a separate - key value. - - The :func:`functools.cmp_to_key` utility is available to convert a 2.x - style *cmp* function to a *key* function. - - *reverse* is a boolean value. If set to ``True``, then the list elements - are sorted as if each comparison were reversed. - - This method modifies the sequence in place for economy of space when - sorting a large sequence. To remind users that it operates by side - effect, it does not return the sorted sequence (use :func:`sorted` to - explicitly request a new sorted list instance). - - The :meth:`sort` method is guaranteed to be stable. A sort is stable if it - guarantees not to change the relative order of elements that compare equal - --- this is helpful for sorting in multiple passes (for example, sort by - department, then by salary grade). - - .. impl-detail:: - - While a list is being sorted, the effect of attempting to mutate, or even - inspect, the list is undefined. The C implementation of Python makes the - list appear empty for the duration, and raises :exc:`ValueError` if it can - detect that the list has been mutated during a sort. +.. class:: list([iterable]) + + Lists may be constructed in several ways: + + * Using a pair of square brackets to denote the empty list: ``[]`` + * Using square brackets, separating items with commas: ``[a]``, ``[a, b, c]`` + * Using a list comprehension: ``[x for x in iterable]`` + * Using the type constructor: ``list()`` or ``list(iterable)`` + + The constructor builds a list whose items are the same and in the same + order as *iterable*'s items. *iterable* may be either a sequence, a + container that supports iteration, or an iterator object. If *iterable* + is already a list, a copy is made and returned, similar to ``iterable[:]``. + For example, ``list('abc')`` returns ``['a', 'b', 'c']`` and + ``list( (1, 2, 3) )`` returns ``[1, 2, 3]``. + If no argument is given, the constructor creates a new empty list, ``[]``. + + + Many other operations also produce lists, including the :func:`sorted` + built-in. + + Lists implement all of the :ref:`common ` and + :ref:`mutable ` sequence operations. Lists also provide the + following additional method: + + .. method:: list.sort(*, key=None, reverse=None) + + This method sorts the list in place, using only ``<`` comparisons + between items. Exceptions are not suppressed - if any comparison operations + fail, the entire sort operation will fail (and the list will likely be left + in a partially modified state). + + *key* specifies a function of one argument that is used to extract a + comparison key from each list element (for example, ``key=str.lower``). + The key corresponding to each item in the list is calculated once and + then used for the entire sorting process. The default value of ``None`` + means that list items are sorted directly without calculating a separate + key value. + + The :func:`functools.cmp_to_key` utility is available to convert a 2.x + style *cmp* function to a *key* function. + + *reverse* is a boolean value. If set to ``True``, then the list elements + are sorted as if each comparison were reversed. + + This method modifies the sequence in place for economy of space when + sorting a large sequence. To remind users that it operates by side + effect, it does not return the sorted sequence (use :func:`sorted` to + explicitly request a new sorted list instance). + + The :meth:`sort` method is guaranteed to be stable. A sort is stable if it + guarantees not to change the relative order of elements that compare equal + --- this is helpful for sorting in multiple passes (for example, sort by + department, then by salary grade). + + .. impl-detail:: + + While a list is being sorted, the effect of attempting to mutate, or even + inspect, the list is undefined. The C implementation of Python makes the + list appear empty for the duration, and raises :exc:`ValueError` if it can + detect that the list has been mutated during a sort. .. _typesseq-tuple: @@ -1173,22 +1193,35 @@ homogeneous data is needed (such as allowing storage in a :class:`set` or :class:`dict` instance). -Tuples may be constructed in a number of ways: - -* Using a pair of parentheses to denote the empty tuple: ``()`` -* Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)`` -* Separating items with commas: ``a, b, c`` or ``(a, b, c)`` -* Using the :func:`tuple` built-in: ``tuple()`` or ``tuple(iterable)`` - -Note that the parentheses are optional (except in the empty tuple case, or -when needed to avoid syntactic ambiguity). It is actually the comma which -makes a tuple, not the parentheses. - -Tuples implement all of the :ref:`common ` sequence -operations. - -For heterogeneous collections of data, :func:`collections.namedtuple` may -be more appropriate than a simple tuple object. +.. class:: tuple([iterable]) + + Tuples may be constructed in a number of ways: + + * Using a pair of parentheses to denote the empty tuple: ``()`` + * Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)`` + * Separating items with commas: ``a, b, c`` or ``(a, b, c)`` + * Using the :func:`tuple` built-in: ``tuple()`` or ``tuple(iterable)`` + + The constructor builds a tuple whose items are the same and in the same + order as *iterable*'s items. *iterable* may be either a sequence, a + container that supports iteration, or an iterator object. If *iterable* + is already a tuple, it is returned unchanged. For example, + ``tuple('abc')`` returns ``('a', 'b', 'c')`` and + ``tuple( [1, 2, 3] )`` returns ``(1, 2, 3)``. + If no argument is given, the constructor creates a new empty tuple, ``()``. + + Note that it is actually the comma which makes a tuple, not the parentheses. + The parentheses are optional, except in the empty tuple case, or + when they are needed to avoid syntactic ambiguity. For example, + ``f(a, b, c)`` is a function call with three arguments, while + ``f((a, b, c))`` is a function call with a 3-tuple as the sole argument. + + Tuples implement all of the :ref:`common ` sequence + operations. + +For heterogeneous collections of data where access by name is clearer than +access by index, :func:`collections.namedtuple` may be a more appropriate +choice than a simple tuple object. .. _typesseq-range: @@ -1199,17 +1232,69 @@ .. index:: object: range The :class:`range` type represents an immutable sequence of numbers and is -commonly used for looping a specific number of times. Instances are created -using the :func:`range` built-in. - -For positive indices with results between the defined ``start`` and ``stop`` -values, integers within the range are determined by the formula: -``r[i] = start + step*i`` - -For negative indices and slicing operations, a range instance determines the -appropriate result for the corresponding tuple and returns either the -appropriate integer (for negative indices) or an appropriate range object -(for slicing operations) . +commonly used for looping a specific number of times in :keyword:`for` +loops. + +.. class:: range([start, ]stop[, step]) + + The arguments to the range constructor must be integers (either built-in + :class:`int` or any object that implements the ``__index__`` special + method). If the *step* argument is omitted, it defaults to ``1``. + If the *start* argument is omitted, it defaults to ``0``. + If *step* is zero, :exc:`ValueError` is raised. + + For a positive *step*, the contents of a range ``r`` are determined by the + formula ``r[i] = start + step*i`` where ``i >= 0`` and + ``r[i] < stop``. + + For a negative *step*, the contents of the range are still determined by + the formula ``r[i] = start + step*i``, but the constraints are ``i >= 0`` + and ``r[i] > stop``. + + A range object will be empty if ``r[0]`` does not meant the value + constraint. Ranges do support negative indices, but these are interpreted + as indexing from the end of the sequence determined by the positive + indices. + + Ranges containing absolute values larger than :data:`sys.maxsize` are + permitted but some features (such as :func:`len`) may raise + :exc:`OverflowError`. + + Range examples:: + + >>> list(range(10)) + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + >>> list(range(1, 11)) + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + >>> list(range(0, 30, 5)) + [0, 5, 10, 15, 20, 25] + >>> list(range(0, 10, 3)) + [0, 3, 6, 9] + >>> list(range(0, -10, -1)) + [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] + >>> list(range(0)) + [] + >>> list(range(1, 0)) + [] + + Ranges implement all of the :ref:`common ` sequence operations + except concatenation and repetition (due to the fact that range objects can + only represent sequences that follow a strict pattern and repetition and + concatenation will usually violate that pattern). + + .. data: start + + The value of the *start* parameter (or ``0`` if the parameter was + not supplied) + + .. data: stop + + The value of the *stop* parameter + + .. data: step + + The value of the *step* parameter (or ``1`` if the parameter was + not supplied) The advantage of the :class:`range` type over a regular :class:`list` or :class:`tuple` is that a :class:`range` object will always take the same @@ -1217,10 +1302,46 @@ only stores the ``start``, ``stop`` and ``step`` values, calculating individual items and subranges as needed). -Ranges implement all of the :ref:`common ` sequence operations -except concatenation and repetition (due to the fact that range objects can -only represent sequences that follow a strict pattern and repetition and -concatenation will usually violate that pattern). +Range objects implement the :class:`collections.Sequence` ABC, and provide +features such as containment tests, element index lookup, slicing and +support for negative indices (see :ref:`typesseq`): + + >>> r = range(0, 20, 2) + >>> r + range(0, 20, 2) + >>> 11 in r + False + >>> 10 in r + True + >>> r.index(10) + 5 + >>> r[5] + 10 + >>> r[:5] + range(0, 10, 2) + >>> r[-1] + 18 + +Testing range objects for equality with ``==`` and ``!=`` compares +them as sequences. That is, two range objects are considered equal if +they represent the same sequence of values. (Note that two range +objects that compare equal might have different :attr:`start`, +:attr:`stop` and :attr:`step` attributes, for example ``range(0) == +range(2, 1, 3)`` or ``range(0, 3, 2) == range(0, 4, 2)``.) + +.. versionchanged:: 3.2 + Implement the Sequence ABC. + Support slicing and negative indices. + Test :class:`int` objects for membership in constant time instead of + iterating through all items. + +.. versionchanged:: 3.3 + Define '==' and '!=' to compare range objects based on the + sequence of values they define (instead of comparing based on + object identity). + +.. versionadded:: 3.3 + The :attr:`start`, :attr:`stop` and :attr:`step` attributes. .. _textseq: @@ -1247,13 +1368,15 @@ be included in the string literal. String literals that are part of a single expression and have only whitespace -between them will be implicitly converted to a single string literal. +between them will be implicitly converted to a single string literal. That +is, ``("spam " "eggs") == "spam eggs"``. See :ref:`strings` for more about the various forms of string literal, including supported escape sequences, and the ``r`` ("raw") prefix that disables most escape sequence processing. -Strings may also be created from other objects with the :func:`str` built-in. +Strings may also be created from other objects with the :ref:`str ` +built-in. Since there is no separate "character" type, indexing a string produces strings of length 1. That is, for a non-empty string *s*, ``s[0] == s[0:1]``. @@ -2002,6 +2125,8 @@ * From an iterable of integers: ``bytes(range(20))`` * Copying existing binary data via the buffer protocol: ``bytes(obj)`` +Also see the :ref:`bytes ` built-in. + Since bytes objects are sequences of integers, for a bytes object *b*, ``b[0]`` will be an integer, while ``b[0:1]`` will be a bytes object of length 1. (This contrasts with text strings, where both indexing and @@ -2043,6 +2168,8 @@ :ref:`mutable ` sequence operations in addition to the common bytes and bytearray operations described in :ref:`bytes-methods`. +Also see the :ref:`bytearray ` built-in. + .. _bytes-methods: @@ -2097,15 +2224,15 @@ The search operations (:keyword:`in`, :meth:`count`, :meth:`find`, :meth:`index`, :meth:`rfind` and :meth:`rindex`) all accept both integers -in the range 0 to 255 as well as bytes and byte array sequences. +in the range 0 to 255 (inclusive) as well as bytes and byte array sequences. .. versionchanged:: 3.3 - All of the search methods also accept an integer in range 0 to 255 - (a byte) as their first argument. + All of the search methods also accept an integer in the range 0 to 255 + (inclusive) as their first argument. Each bytes and bytearray instance provides a :meth:`decode` convenience -method that is the inverse of "meth:`str.encode`: +method that is the inverse of :meth:`str.encode`: .. method:: bytes.decode(encoding="utf-8", errors="strict") bytearray.decode(encoding="utf-8", errors="strict") @@ -2563,7 +2690,7 @@ Common uses include membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference. -(For other containers see the built in :class:`dict`, :class:`list`, +(For other containers see the built-in :class:`dict`, :class:`list`, and :class:`tuple` classes, and the :mod:`collections` module.) Like other collections, sets support ``x in set``, ``len(set)``, and ``for x in @@ -2763,7 +2890,7 @@ A :dfn:`mapping` object maps :term:`hashable` values to arbitrary objects. Mappings are mutable objects. There is currently only one standard mapping -type, the :dfn:`dictionary`. (For other containers see the built in +type, the :dfn:`dictionary`. (For other containers see the built-in :class:`list`, :class:`set`, and :class:`tuple` classes, and the :mod:`collections` module.) -- Repository URL: http://hg.python.org/cpython From ncoghlan at gmail.com Tue Aug 21 09:47:28 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 21 Aug 2012 17:47:28 +1000 Subject: [Python-checkins] cpython: Close #4966: revamp the sequence docs in order to better explain the state of In-Reply-To: <5032EA7E.70107@gmail.com> References: <3X0mV86gLXzPcJ@mail.python.org> <5032EA7E.70107@gmail.com> Message-ID: On Tue, Aug 21, 2012 at 11:55 AM, Ezio Melotti wrote: >> +Sequence Types --- :class:`list`, :class:`tuple`, :class:`range` >> +================================================================ >> + > > > These 3 links in the section title redirect to the functions.html page. I > think it would be better if they linked to the appropriate subsection > instead, and in the case of the subsections (e.g. "Text Sequence Type --- > str") they shouldn't be links. The same comment can be applied to other > titles as well. I made a start on moving the info out of functions.html and adding appropriate noindex entries. str, bytes and bytearray haven't been consolidated at all yet. >> ++--------------------------+--------------------------------+----------+ >> +| ``s * n, n * s`` | *n* shallow copies of *s* | (2)(7) | > > > I would use '``s * n`` or ``n * s``' here. Done. >> +| ``s.index(x, [i[, j]])`` | index of the first occurence | \(8) | > > > This should be ``s.index(x[, i[, j]])`` Done. >> + >> + * if concatenating :class:`tuple` objects, extend a :class:`list` >> instead. >> + >> + * for other types, investigate the relevant class documentation >> + > > > The trailing punctuation of the elements in this list is inconsistent. Just removed all trailing punctuation from these bullet points for now. > > You missed clear() from this list. The problem was actually index() and count() were missing from the index for the "common sequence operations" table. Added them there, and moved that index above the table. copy() was missing from the index list for the mutable sequence methods, so I added that. > Also in the "Result" column the descriptions in prose are OK, but I find > some of the "same as ..." ones not very readable (or even fairly obscure). > (I think I saw something similar in the doc of list.append() too.) These are all rather old - much of this patch was just moving things around rather than fixing the prose, although there was plenty of the latter, too :) I tried to improve them a bit. > Is it worth mentioning a function call as an example of syntactic ambiguity? > Someone might wonder if foo(a, b, c) is actually passing a 3-elements tuple > or 3 distinct values. Done. > This claim is maybe a bit too strong. I think the main reason to use > namedtuples is being able to access the elements via t.name, rather than > t[pos], and while this can be useful for basically every heterogeneous > tuple, I think that plain tuples are still preferred. Reworded. > On a separate note, should tuple unpacking be mentioned here? (a link to a > separate section of the doc is enough.) Not really - despite the name, tuple unpacking isn't especially closely related to tuples these days. > I would mention explicitly "in :keyword:`for` loops" -- ranges don't loop on > their own (I think people familiar with Ruby and/or JQuery might get > confused here). Done. > I thought that these two paragraphs were talking about positive and negative > start/stop/step until I reached the middle of the second paragraph (the word > "indices" wasn't enough to realize that these paragraphs are about > indexing/slicing, probably because they are rarely used and I wasn't > expecting to find them at this point of the doc). Maybe it's better to move > the paragraphs at the bottom of the section. For the moment, I've just dumped the old range builtin docs into this section. They need a pass to remove the duplication and ensure everything makes sense in context. >> +String literals that are part of a single expression and have only >> whitespace >> +between them will be implicitly converted to a single string literal. >> + > > > Is it a string /literal/ they are converted to? Yup: >>> ast.dump(compile('"hello world"', '', 'eval', flags=ast.PyCF_ONLY_AST)) "Expression(body=Str(s='hello world'))" >>> ast.dump(compile('"hello" " world"', '', 'eval', flags=ast.PyCF_ONLY_AST)) "Expression(body=Str(s='hello world'))" > Anyway a simple ('foo' 'bar') == 'foobar' example might make this sentence > more understandable. Added. >> +There is also no mutable string type, but :meth:`str.join` or >> +:class:`io.StringIO` can be used to efficiently construct strings from >> +multiple fragments. >> + > > str.format() deserves to be mentioned here too. For the kinds of strings where quadratic growth is a problem, str.format is unlikely to be appropriate. > I noticed that here there's this fairly long section about the "old" string > formatting and nothing about the "new" formatting. Maybe this should be > moved together with the new formatting doc, so that all the detailed > formatting docs are in the same place. (This would also help making this > less noticeable) Probably. There are a lot of structural problems in the current docs, because the layout hasn't previously changed to suit the language design changes. >> +While bytes literals and representations are based on ASCII text, bytes >> +objects actually behave like immutable sequences of integers, with each >> +value in the sequence restricted such that ``0 <= x < 256`` (attempts to > > Earlier you used 0 <= x <= 255. The current docs are the result of many merges, much of which I didn't write. This is only the start of improving them by breaking away from the old 1.x structure with a few autocratic decisions on my part to establish a new layout that makes more sense given the evolution of the language, especially the big changes in 2.2 and 3.0 :) > Using ``'abc'.replace('a', 'f')`` and ``b'abc'.replace(b'a', b'f')`` inline > would be better IMHO, given that the current note takes lot of space to > explain a trivial concept. Stylistics edits are always fair game, they don't have to be made by me. While I skipped a lot of your specific suggestions that weren't correcting actual errors, that doesn't mean I'm especially opposed to them, just that I didn't like them enough to implement myself :) Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From python-checkins at python.org Tue Aug 21 10:40:06 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 21 Aug 2012 10:40:06 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1NzUyOiBzL2Fz?= =?utf-8?q?sertRaisesRegexp/assertRaisesRegex/g?= Message-ID: <3X1QLZ0hK3zQMP@mail.python.org> http://hg.python.org/cpython/rev/3a02a1f7d069 changeset: 78695:3a02a1f7d069 branch: 3.2 parent: 78692:dbbf3ccf72e8 user: Ezio Melotti date: Tue Aug 21 11:38:41 2012 +0300 summary: #15752: s/assertRaisesRegexp/assertRaisesRegex/g files: Lib/test/json_tests/test_decode.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/json_tests/test_decode.py b/Lib/test/json_tests/test_decode.py --- a/Lib/test/json_tests/test_decode.py +++ b/Lib/test/json_tests/test_decode.py @@ -57,12 +57,12 @@ def test_extra_data(self): s = '[1, 2, 3]5' msg = 'Extra data' - self.assertRaisesRegexp(ValueError, msg, self.loads, s) + self.assertRaisesRegex(ValueError, msg, self.loads, s) def test_invalid_escape(self): s = '["abc\\y"]' msg = 'escape' - self.assertRaisesRegexp(ValueError, msg, self.loads, s) + self.assertRaisesRegex(ValueError, msg, self.loads, s) class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 10:40:08 2012 From: python-checkins at python.org (ezio.melotti) Date: Tue, 21 Aug 2012 10:40:08 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogIzE1NzUyOiBtZXJnZSB3aXRoIDMuMi4=?= Message-ID: <3X1QLc2j8DzQPC@mail.python.org> http://hg.python.org/cpython/rev/b36ce0a3a844 changeset: 78696:b36ce0a3a844 parent: 78694:28f424022c6e parent: 78695:3a02a1f7d069 user: Ezio Melotti date: Tue Aug 21 11:39:47 2012 +0300 summary: #15752: merge with 3.2. files: Lib/test/json_tests/test_decode.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/json_tests/test_decode.py b/Lib/test/json_tests/test_decode.py --- a/Lib/test/json_tests/test_decode.py +++ b/Lib/test/json_tests/test_decode.py @@ -57,12 +57,12 @@ def test_extra_data(self): s = '[1, 2, 3]5' msg = 'Extra data' - self.assertRaisesRegexp(ValueError, msg, self.loads, s) + self.assertRaisesRegex(ValueError, msg, self.loads, s) def test_invalid_escape(self): s = '["abc\\y"]' msg = 'escape' - self.assertRaisesRegexp(ValueError, msg, self.loads, s) + self.assertRaisesRegex(ValueError, msg, self.loads, s) class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass -- Repository URL: http://hg.python.org/cpython From rdmurray at bitdance.com Tue Aug 21 14:01:15 2012 From: rdmurray at bitdance.com (R. David Murray) Date: Tue, 21 Aug 2012 08:01:15 -0400 Subject: [Python-checkins] [Python-Dev] cpython: Close #4966: revamp the sequence docs in order to better explain the state of In-Reply-To: References: <3X0mV86gLXzPcJ@mail.python.org> <5032EA7E.70107@gmail.com> Message-ID: <20120821120116.2FC6A250085@webabinitio.net> On Tue, 21 Aug 2012 17:47:28 +1000, Nick Coghlan wrote: > On Tue, Aug 21, 2012 at 11:55 AM, Ezio Melotti wrote: > >> +String literals that are part of a single expression and have only > >> whitespace > >> +between them will be implicitly converted to a single string literal. > >> + > > > > > > Is it a string /literal/ they are converted to? > Yup: > > >>> ast.dump(compile('"hello world"', '', 'eval', flags=ast.PyCF_ONLY_AST)) > "Expression(body=Str(s='hello world'))" > >>> ast.dump(compile('"hello" " world"', '', 'eval', flags=ast.PyCF_ONLY_AST)) > "Expression(body=Str(s='hello world'))" > > > Anyway a simple ('foo' 'bar') == 'foobar' example might make this sentence > > more understandable. > > Added. I think it is an important and subtle point that this happens at "compile time" rather than "run time". Subtle in that it is not at all obvious (as this question demonstrates), and important in that it does have performance implications (even if those are trivial in most cases). So I think it would be worth saying "implicitly converted to a single string literal when the source is parsed", or something like that. --David From ncoghlan at gmail.com Tue Aug 21 14:07:57 2012 From: ncoghlan at gmail.com (Nick Coghlan) Date: Tue, 21 Aug 2012 22:07:57 +1000 Subject: [Python-checkins] [Python-Dev] cpython: Close #4966: revamp the sequence docs in order to better explain the state of In-Reply-To: <20120821120116.2FC6A250085@webabinitio.net> References: <3X0mV86gLXzPcJ@mail.python.org> <5032EA7E.70107@gmail.com> <20120821120116.2FC6A250085@webabinitio.net> Message-ID: On Tue, Aug 21, 2012 at 10:01 PM, R. David Murray wrote: > I think it is an important and subtle point that this happens at "compile > time" rather than "run time". Subtle in that it is not at all obvious > (as this question demonstrates), and important in that it does have > performance implications (even if those are trivial in most cases). > So I think it would be worth saying "implicitly converted to a single > string literal when the source is parsed", or something like that. That kind of fine detail is what the language reference is for - the distinction really doesn't matter most of the time. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia From python-checkins at python.org Tue Aug 21 15:56:12 2012 From: python-checkins at python.org (richard.oudkerk) Date: Tue, 21 Aug 2012 15:56:12 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_typo_in_error_handling?= =?utf-8?q?_for_WaitForMultipleObjects=28=29?= Message-ID: <3X1YMJ1P6NzPgt@mail.python.org> http://hg.python.org/cpython/rev/ca54c27a9045 changeset: 78697:ca54c27a9045 user: Richard Oudkerk date: Tue Aug 21 14:54:22 2012 +0100 summary: Fix typo in error handling for WaitForMultipleObjects() files: Modules/_winapi.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Modules/_winapi.c b/Modules/_winapi.c --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -1058,7 +1058,7 @@ if (!PySequence_Check(handle_seq)) { PyErr_Format(PyExc_TypeError, "sequence type expected, got '%s'", - Py_TYPE(handle_seq)->tp_doc); + Py_TYPE(handle_seq)->tp_name); return NULL; } nhandles = PySequence_Length(handle_seq); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 21 19:44:07 2012 From: python-checkins at python.org (georg.brandl) Date: Tue, 21 Aug 2012 19:44:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Remove_patch_a?= =?utf-8?q?rtifacts=2E?= Message-ID: <3X1fQH4KfdzQfR@mail.python.org> http://hg.python.org/cpython/rev/c1c45755397b changeset: 78698:c1c45755397b branch: 2.7 parent: 78682:20985f52b65e user: Georg Brandl date: Tue Aug 21 19:44:00 2012 +0200 summary: Remove patch artifacts. files: Doc/library/datetime.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -25,8 +25,8 @@ is used to represent a specific moment in time that is not open to interpretation [#]_. -+A naive object does not contain enough information to unambiguously locate -+itself relative to other date/time objects. Whether a naive object represents +A naive object does not contain enough information to unambiguously locate +itself relative to other date/time objects. Whether a naive object represents Coordinated Universal Time (UTC), local time, or time in some other timezone is purely up to the program, just like it's up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 22 01:42:13 2012 From: python-checkins at python.org (trent.nelson) Date: Wed, 22 Aug 2012 01:42:13 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NzQ3?= =?utf-8?q?=3A_skip_chflags_UF=5FIMMUTABLE_tests_if_EOPNOTSUPP_is_raised?= =?utf-8?q?=2E?= Message-ID: <3X1pMT68TVzQXY@mail.python.org> http://hg.python.org/cpython/rev/019a2390b014 changeset: 78699:019a2390b014 branch: 3.2 parent: 78695:3a02a1f7d069 user: Trent Nelson date: Tue Aug 21 23:41:43 2012 +0000 summary: Issue #15747: skip chflags UF_IMMUTABLE tests if EOPNOTSUPP is raised. This is necessary for ZFS systems, which don't support UF_IMMUTABLE. 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(support.TESTFN) new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -436,6 +436,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 #15285: Refactor the approach for testing connect timeouts using two external hosts that have been configured specifically for this type of test. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 22 01:49:13 2012 From: python-checkins at python.org (trent.nelson) Date: Wed, 22 Aug 2012 01:49:13 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Block_78699=3A019a2390b014=2C_this_needs_to_be_manually_?= =?utf-8?q?merged=2E?= Message-ID: <3X1pWY3rHwzQW6@mail.python.org> http://hg.python.org/cpython/rev/aa7df57dfe2a changeset: 78700:aa7df57dfe2a parent: 78697:ca54c27a9045 parent: 78699:019a2390b014 user: Trent Nelson date: Tue Aug 21 23:48:55 2012 +0000 summary: Block 78699:019a2390b014, this needs to be manually merged. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 22 01:59:40 2012 From: python-checkins at python.org (trent.nelson) Date: Wed, 22 Aug 2012 01:59:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315747=3A_skip_chf?= =?utf-8?q?lags_UF=5FIMMUTABLE_tests_if_EOPNOTSUPP_is_raised=2E?= Message-ID: <3X1plc6bj4zQXb@mail.python.org> http://hg.python.org/cpython/rev/f986d523e93d changeset: 78701:f986d523e93d user: Trent Nelson date: Tue Aug 21 23:59:31 2012 +0000 summary: Issue #15747: skip chflags UF_IMMUTABLE tests if EOPNOTSUPP is raised. This is necessary for ZFS systems, which don't support UF_IMMUTABLE. (Note: this commit is a manual merge of 78699:019a2390b014 as both _test_chflags_regular_file and test_lchflags_symlink differ between 3.2 and default.) 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 @@ -534,7 +534,17 @@ def _test_chflags_regular_file(self, chflags_func, target_file, **kwargs): st = os.stat(target_file) self.assertTrue(hasattr(st, 'st_flags')) - chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE, **kwargs) + + # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE. + flags = st.st_flags | stat.UF_IMMUTABLE + try: + chflags_func(target_file, flags, **kwargs) + 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) @@ -568,8 +578,15 @@ return posix.chflags(path, flags, follow_symlinks=False) for fn in (posix.lchflags, chflags_nofollow): - fn(_DUMMY_SYMLINK, - dummy_symlink_st.st_flags | stat.UF_IMMUTABLE) + # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE. + flags = dummy_symlink_st.st_flags | stat.UF_IMMUTABLE + try: + fn(_DUMMY_SYMLINK, flags) + 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(support.TESTFN) new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -86,6 +86,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 #15285: Refactor the approach for testing connect timeouts using two external hosts that have been configured specifically for this type of test. -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Aug 22 06:12:24 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 22 Aug 2012 06:12:24 +0200 Subject: [Python-checkins] Daily reference leaks (f986d523e93d): sum=5 Message-ID: results for f986d523e93d on branch "default" -------------------------------------------- test_support leaked [0, 0, -1] references, sum=-1 test_capi leaked [2, 2, 2] references, sum=6 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogoyE7C6', '-x'] From python-checkins at python.org Wed Aug 22 07:38:18 2012 From: python-checkins at python.org (ezio.melotti) Date: Wed, 22 Aug 2012 07:38:18 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Update_suspicious_ignore_f?= =?utf-8?q?ile=2E?= Message-ID: <3X1yGL1QtkzQXB@mail.python.org> http://hg.python.org/cpython/rev/6ce6707743d9 changeset: 78702:6ce6707743d9 user: Ezio Melotti date: Wed Aug 22 08:38:04 2012 +0300 summary: Update suspicious ignore file. files: Doc/tools/sphinxext/susp-ignored.csv | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Doc/tools/sphinxext/susp-ignored.csv b/Doc/tools/sphinxext/susp-ignored.csv --- a/Doc/tools/sphinxext/susp-ignored.csv +++ b/Doc/tools/sphinxext/susp-ignored.csv @@ -129,6 +129,9 @@ library/httplib,,:port,host:port library/imaplib,,:MM,"""DD-Mmm-YYYY HH:MM:SS" library/imaplib,,:SS,"""DD-Mmm-YYYY HH:MM:SS" +library/inspect,,:int,">>> def foo(a, *, b:int, **kwargs):" +library/inspect,,:int,"'(a, *, b:int, **kwargs)'" +library/inspect,,:int,'b:int' library/ipaddress,,:db8,>>> ipaddress.ip_address('2001:db8::') library/ipaddress,,::,>>> ipaddress.ip_address('2001:db8::') library/ipaddress,,:db8,IPv6Address('2001:db8::') -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 22 14:40:55 2012 From: python-checkins at python.org (ronald.oussoren) Date: Wed, 22 Aug 2012 14:40:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_for_issue_?= =?utf-8?q?15716=3A_interpreter_could_crash_when_PYTHONEXECUTABLE_was_set_?= =?utf-8?q?on?= Message-ID: <3X27dz2VVWzQ6Y@mail.python.org> http://hg.python.org/cpython/rev/526c6262d91f changeset: 78703:526c6262d91f branch: 3.2 parent: 78699:019a2390b014 user: Ronald Oussoren date: Wed Aug 22 14:24:14 2012 +0200 summary: Fix for issue 15716: interpreter could crash when PYTHONEXECUTABLE was set on Mac OS X. This is due to an off-by-one error: the allocated buffer didn't have room for a NUL character at the end of the mbstowcs result. files: Misc/NEWS | 2 ++ Modules/main.c | 2 +- 2 files changed, 3 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 #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X. + - Issue #15726: Fix incorrect bounds checking in PyState_FindModule. Patch by Robin Schreiber. diff --git a/Modules/main.c b/Modules/main.c --- a/Modules/main.c +++ b/Modules/main.c @@ -616,7 +616,7 @@ script. */ if ((p = Py_GETENV("PYTHONEXECUTABLE")) && *p != '\0') { wchar_t* buffer; - size_t len = strlen(p); + size_t len = strlen(p) + 1; size_t r; buffer = malloc(len * sizeof(wchar_t)); -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 22 14:40:56 2012 From: python-checkins at python.org (ronald.oussoren) Date: Wed, 22 Aug 2012 14:40:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Fix_for_issue_15716=3A_interpreter_could_crash_when_PYTH?= =?utf-8?q?ONEXECUTABLE_was_set_on?= Message-ID: <3X27f06Kv4zQ6Y@mail.python.org> http://hg.python.org/cpython/rev/ae51329f9893 changeset: 78704:ae51329f9893 parent: 78702:6ce6707743d9 parent: 78703:526c6262d91f user: Ronald Oussoren date: Wed Aug 22 14:40:35 2012 +0200 summary: Fix for issue 15716: interpreter could crash when PYTHONEXECUTABLE was set on Mac OS X. This is due to an off-by-one error: the allocated buffer didn't have room for a NUL character at the end of the mbstowcs result. (merge with 3.2) files: Misc/NEWS | 2 ++ Modules/main.c | 2 +- 2 files changed, 3 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 #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X. + - Issue #15726: Fix incorrect bounds checking in PyState_FindModule. Patch by Robin Schreiber. diff --git a/Modules/main.c b/Modules/main.c --- a/Modules/main.c +++ b/Modules/main.c @@ -604,7 +604,7 @@ script. */ if ((p = Py_GETENV("PYTHONEXECUTABLE")) && *p != '\0') { wchar_t* buffer; - size_t len = strlen(p); + size_t len = strlen(p) + 1; buffer = malloc(len * sizeof(wchar_t)); if (buffer == NULL) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 22 17:46:51 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 22 Aug 2012 17:46:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315766=3A_Fix_a_cr?= =?utf-8?q?ash_in_imp=2Eload=5Fdynamic=28=29_on_PyUnicode=5FFromString=28?= =?utf-8?q?=29?= Message-ID: <3X2CmW1fnvzQMh@mail.python.org> http://hg.python.org/cpython/rev/eaac55703796 changeset: 78705:eaac55703796 user: Victor Stinner date: Wed Aug 22 17:45:52 2012 +0200 summary: Issue #15766: Fix a crash in imp.load_dynamic() on PyUnicode_FromString() failure files: Python/dynload_shlib.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -139,9 +139,9 @@ path = PyUnicode_FromString(pathname); mod_name = PyUnicode_FromString(shortname); PyErr_SetImportError(error_ob, mod_name, path); - Py_DECREF(error_ob); - Py_DECREF(path); - Py_DECREF(mod_name); + Py_XDECREF(error_ob); + Py_XDECREF(path); + Py_XDECREF(mod_name); return NULL; } if (fp != NULL && nhandles < 128) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 22 19:34:45 2012 From: python-checkins at python.org (stefan.krah) Date: Wed, 22 Aug 2012 19:34:45 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Use_zero_bottom_margin=2E?= Message-ID: <3X2G912ZntzQhk@mail.python.org> http://hg.python.org/cpython/rev/1b3f4a1004d3 changeset: 78708:1b3f4a1004d3 user: Stefan Krah date: Wed Aug 22 19:28:12 2012 +0200 summary: Use zero bottom margin. files: Modules/_decimal/tests/bignum.py | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/Modules/_decimal/tests/bignum.py b/Modules/_decimal/tests/bignum.py --- a/Modules/_decimal/tests/bignum.py +++ b/Modules/_decimal/tests/bignum.py @@ -40,6 +40,3 @@ h2 = hash(d) assert h2 == h1 - - - -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 03:34:29 2012 From: python-checkins at python.org (r.david.murray) Date: Thu, 23 Aug 2012 03:34:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=23665194=3A_Update_email?= =?utf-8?q?=2Eutils=2Elocaltime_to_use_astimezone=2C_and_fix_bug=2E?= Message-ID: <3X2SpY2wDYzQMk@mail.python.org> http://hg.python.org/cpython/rev/71b9cca81598 changeset: 78709:71b9cca81598 user: R David Murray date: Wed Aug 22 21:34:00 2012 -0400 summary: #665194: Update email.utils.localtime to use astimezone, and fix bug. The new code correctly handles historic changes in UTC offsets. A test for this should follow. Original patch by Alexander Belopolsky. files: Lib/email/utils.py | 51 ++++++++---------- Lib/test/test_email/test_utils.py | 10 ++- Misc/NEWS | 3 + 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -386,33 +386,26 @@ """ if dt is None: - seconds = time.time() - else: - if dt.tzinfo is None: - # A naive datetime is given. Convert to a (localtime) - # timetuple and pass to system mktime together with - # the isdst hint. System mktime will return seconds - # sysce epoch. - tm = dt.timetuple()[:-1] + (isdst,) - seconds = time.mktime(tm) + dt = datetime.datetime.now(datetime.timezone.utc) + if dt.tzinfo is not None: + return dt.astimezone() + # We have a naive datetime. Convert to a (localtime) timetuple and pass to + # system mktime together with the isdst hint. System mktime will return + # seconds since epoch. + tm = dt.timetuple()[:-1] + (isdst,) + seconds = time.mktime(tm) + localtm = time.localtime(seconds) + try: + delta = datetime.timedelta(seconds=localtm.tm_gmtoff) + tz = datetime.timezone(delta, localtm.tm_zone) + except AttributeError: + # Compute UTC offset and compare with the value implied by tm_isdst. + # If the values match, use the zone name implied by tm_isdst. + delta = dt - datetime.datetime(*time.gmtime(ts)[:6]) + dst = time.daylight and localtm.tm_isdst > 0 + gmtoff = -(time.altzone if dst else time.timezone) + if delta == datetime.timedelta(seconds=gmtoff): + tz = datetime.timezone(delta, time.tzname[dst]) else: - # An aware datetime is given. Use aware datetime - # arithmetics to find seconds since epoch. - delta = dt - datetime.datetime(1970, 1, 1, - tzinfo=datetime.timezone.utc) - seconds = delta.total_seconds() - tm = time.localtime(seconds) - - # XXX: The following logic may not work correctly if UTC - # offset has changed since time provided in dt. This will be - # corrected in C implementation for platforms that support - # tm_gmtoff. - if time.daylight and tm.tm_isdst: - offset = time.altzone - tzname = time.tzname[1] - else: - offset = time.timezone - tzname = time.tzname[0] - - tz = datetime.timezone(datetime.timedelta(seconds=-offset), tzname) - return datetime.datetime.fromtimestamp(seconds, tz) + tz = datetime.timezone(delta) + return dt.replace(tzinfo=tz) diff --git a/Lib/test/test_email/test_utils.py b/Lib/test/test_email/test_utils.py --- a/Lib/test/test_email/test_utils.py +++ b/Lib/test/test_email/test_utils.py @@ -87,17 +87,23 @@ t2 = utils.localtime(t1) self.assertEqual(t1, t2) + @test.support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0') def test_localtime_epoch_utc_daylight_true(self): test.support.patch(self, time, 'daylight', True) t0 = datetime.datetime(1970, 1, 1, tzinfo = datetime.timezone.utc) t1 = utils.localtime(t0) - self.assertEqual(t0, t1) + t2 = t0 - datetime.timedelta(hours=5) + t2 = t2.replace(tzinfo = datetime.timezone(datetime.timedelta(hours=-5))) + self.assertEqual(t1, t2) + @test.support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0') def test_localtime_epoch_utc_daylight_false(self): test.support.patch(self, time, 'daylight', False) t0 = datetime.datetime(1970, 1, 1, tzinfo = datetime.timezone.utc) t1 = utils.localtime(t0) - self.assertEqual(t0, t1) + t2 = t0 - datetime.timedelta(hours=5) + t2 = t2.replace(tzinfo = datetime.timezone(datetime.timedelta(hours=-5))) + self.assertEqual(t1, t2) def test_localtime_epoch_notz_daylight_true(self): test.support.patch(self, time, 'daylight', True) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -24,6 +24,9 @@ Library ------- +- Issue ##665194: Update email.utils.localtime to use datetime.astimezone and + correctly handle historic changes in UTC offsets. + - Issue #15199: Fix JavaScript's default MIME type to application/javascript. Patch by Bohuslav Kabrda. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 03:52:56 2012 From: python-checkins at python.org (r.david.murray) Date: Thu, 23 Aug 2012 03:52:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_=23665194=3A_fix_variable_?= =?utf-8?q?name_in_exception_code_path=2E?= Message-ID: <3X2TCr4JGLzQHf@mail.python.org> http://hg.python.org/cpython/rev/a2d83fba8fd8 changeset: 78710:a2d83fba8fd8 user: R David Murray date: Wed Aug 22 21:52:31 2012 -0400 summary: #665194: fix variable name in exception code path. It was correct in the original patch and I foobared it when I restructured part of the code. files: Lib/email/utils.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -401,7 +401,7 @@ except AttributeError: # Compute UTC offset and compare with the value implied by tm_isdst. # If the values match, use the zone name implied by tm_isdst. - delta = dt - datetime.datetime(*time.gmtime(ts)[:6]) + delta = dt - datetime.datetime(*time.gmtime(seconds)[:6]) dst = time.daylight and localtm.tm_isdst > 0 gmtoff = -(time.altzone if dst else time.timezone) if delta == datetime.timedelta(seconds=gmtoff): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 04:06:07 2012 From: python-checkins at python.org (alexander.belopolsky) Date: Thu, 23 Aug 2012 04:06:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Added_test_for_a_bug_fixed?= =?utf-8?q?_in_issue_=23665194=2E?= Message-ID: <3X2TW36nTNzQQN@mail.python.org> http://hg.python.org/cpython/rev/604222c1f8a0 changeset: 78711:604222c1f8a0 user: Alexander Belopolsky date: Wed Aug 22 22:06:37 2012 -0400 summary: Added test for a bug fixed in issue #665194. files: Lib/test/test_email/test_utils.py | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_email/test_utils.py b/Lib/test/test_email/test_utils.py --- a/Lib/test/test_email/test_utils.py +++ b/Lib/test/test_email/test_utils.py @@ -3,6 +3,7 @@ import test.support import time import unittest +import sys class DateTimeTests(unittest.TestCase): @@ -119,6 +120,17 @@ t2 = utils.localtime(t0.replace(tzinfo=None)) self.assertEqual(t1, t2) + # XXX: Need a more robust test for Olson's tzdata + @unittest.skipIf(sys.platform.startswith('win'), + "Windows does not use Olson's TZ database") + @test.support.run_with_tz('Europe/Kiev') + def test_variable_tzname(self): + t0 = datetime.datetime(1984, 1, 1, tzinfo=datetime.timezone.utc) + t1 = utils.localtime(t0) + self.assertEqual(t1.tzname(), 'MSK') + t0 = datetime.datetime(1994, 1, 1, tzinfo=datetime.timezone.utc) + t1 = utils.localtime(t0) + self.assertEqual(t1.tzname(), 'EET') if __name__ == '__main__': unittest.main() -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 05:01:59 2012 From: python-checkins at python.org (alexander.belopolsky) Date: Thu, 23 Aug 2012 05:01:59 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=23665194=3A_Added_a?= =?utf-8?q?_small_optimization?= Message-ID: <3X2VlW2WwHzQGn@mail.python.org> http://hg.python.org/cpython/rev/4c134e6ba0df changeset: 78712:4c134e6ba0df user: Alexander Belopolsky date: Wed Aug 22 23:02:36 2012 -0400 summary: Issue #665194: Added a small optimization files: Lib/email/utils.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -386,7 +386,7 @@ """ if dt is None: - dt = datetime.datetime.now(datetime.timezone.utc) + return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: return dt.astimezone() # We have a naive datetime. Convert to a (localtime) timetuple and pass to -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 05:14:37 2012 From: python-checkins at python.org (alexander.belopolsky) Date: Thu, 23 Aug 2012 05:14:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Suggested_a_whatsnew_item?= Message-ID: <3X2W254c12zQRJ@mail.python.org> http://hg.python.org/cpython/rev/e7ca9eefa086 changeset: 78713:e7ca9eefa086 user: Alexander Belopolsky date: Wed Aug 22 23:14:29 2012 -0400 summary: Suggested a whatsnew item files: Doc/whatsnew/3.3.rst | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) 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 @@ -1088,7 +1088,9 @@ corresponding to the :class:`~datetime.datetime` instance. * The :meth:`datetime.datetime.strftime` method supports formatting years older than 1000. - + * XXX The :meth:`datetime.datetime.astimezone` method can now be + called without arguments to convert datetime instance to the system + timezone. decimal ------- -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Thu Aug 23 06:10:01 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 23 Aug 2012 06:10:01 +0200 Subject: [Python-checkins] Daily reference leaks (1b3f4a1004d3): sum=6 Message-ID: results for 1b3f4a1004d3 on branch "default" -------------------------------------------- test_capi leaked [2, 2, 2] references, sum=6 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogEEcEvi', '-x'] From python-checkins at python.org Thu Aug 23 08:36:55 2012 From: python-checkins at python.org (ned.deily) Date: Thu, 23 Aug 2012 08:36:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NjQ1?= =?utf-8?q?=3A_Ensure_2to3_grammar_pickles_are_properly_installed=2E?= Message-ID: <3X2bWW6pt4zQLf@mail.python.org> http://hg.python.org/cpython/rev/787ed9b03ef9 changeset: 78714:787ed9b03ef9 branch: 2.7 parent: 78698:c1c45755397b user: Ned Deily date: Wed Aug 22 23:26:06 2012 -0700 summary: Issue #15645: Ensure 2to3 grammar pickles are properly installed. (Patch by Ronald Oussoren) files: Makefile.pre.in | 6 +++--- Misc/NEWS | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -879,6 +879,8 @@ lib-old \ curses pydoc_data $(MACHDEPS) libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c + -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ + ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" @for i in $(SCRIPTDIR) $(LIBDEST); \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -956,8 +958,6 @@ ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST)/site-packages -f \ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages - -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" # Create the PLATDIR source directory, if one wasn't distributed.. $(srcdir)/Lib/$(PLATDIR): @@ -1195,7 +1195,7 @@ find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';' find build -name 'fficonfig.h' -exec rm -f {} ';' || true find build -name 'fficonfig.py' -exec rm -f {} ';' || true - -rm -f Lib/lib2to3/*Grammar*.pickle + -rm -f $(srcdir)/Lib/lib2to3/*Grammar*.pickle profile-removal: find . -name '*.gc??' -exec rm -f {} ';' diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -353,6 +353,8 @@ Build ----- +- Issue #15645: Ensure 2to3 grammar pickles are properly installed. + - Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. - Issue #8847: Disable COMDAT folding in Windows PGO builds. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 08:36:57 2012 From: python-checkins at python.org (ned.deily) Date: Thu, 23 Aug 2012 08:36:57 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NjQ1?= =?utf-8?q?=3A_Ensure_2to3_grammar_pickles_are_properly_installed=2E?= Message-ID: <3X2bWY3WZ3zQLR@mail.python.org> http://hg.python.org/cpython/rev/a377a4298b4e changeset: 78715:a377a4298b4e branch: 3.2 parent: 78703:526c6262d91f user: Ned Deily date: Wed Aug 22 23:27:26 2012 -0700 summary: Issue #15645: Ensure 2to3 grammar pickles are properly installed. (Patch by Ronald Oussoren) files: Makefile.pre.in | 6 +++--- Misc/NEWS | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -937,6 +937,8 @@ unittest unittest/test \ curses pydoc_data $(MACHDEPS) libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c + -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ + ./$(BUILDPYTHON) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" @for i in $(SCRIPTDIR) $(LIBDEST); \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -1014,8 +1016,6 @@ ./$(BUILDPYTHON) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST)/site-packages -f \ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages - -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" # Create the PLATDIR source directory, if one wasn't distributed.. $(srcdir)/Lib/$(PLATDIR): @@ -1256,7 +1256,7 @@ find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';' find build -name 'fficonfig.h' -exec rm -f {} ';' || true find build -name 'fficonfig.py' -exec rm -f {} ';' || true - -rm -f Lib/lib2to3/*Grammar*.pickle + -rm -f $(srcdir)/Lib/lib2to3/*Grammar*.pickle -rm -f Modules/_testembed profile-removal: diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -482,6 +482,8 @@ Build ----- +- Issue #15645: Ensure 2to3 grammar pickles are properly installed. + - Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. - Issue #8847: Disable COMDAT folding in Windows PGO builds. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 08:36:58 2012 From: python-checkins at python.org (ned.deily) Date: Thu, 23 Aug 2012 08:36:58 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_issue_=2315645=3A_null_merge?= Message-ID: <3X2bWZ6hNhzQM4@mail.python.org> http://hg.python.org/cpython/rev/b48cd7045909 changeset: 78716:b48cd7045909 parent: 78713:e7ca9eefa086 parent: 78715:a377a4298b4e user: Ned Deily date: Wed Aug 22 23:32:29 2012 -0700 summary: issue #15645: null merge files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 08:37:00 2012 From: python-checkins at python.org (ned.deily) Date: Thu, 23 Aug 2012 08:37:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315645=3A_Ensure_2?= =?utf-8?q?to3_grammar_pickles_are_properly_installed=2E?= Message-ID: <3X2bWc2gFqzQLl@mail.python.org> http://hg.python.org/cpython/rev/995e58439b59 changeset: 78717:995e58439b59 user: Ned Deily date: Wed Aug 22 23:34:13 2012 -0700 summary: Issue #15645: Ensure 2to3 grammar pickles are properly installed. (Patch by Ronald Oussoren) files: Makefile.pre.in | 6 +++--- Misc/NEWS | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1017,6 +1017,8 @@ venv venv/scripts venv/scripts/posix \ curses pydoc_data $(MACHDEPS) libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c + -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ + $(PYTHON_FOR_BUILD) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" @for i in $(SCRIPTDIR) $(LIBDEST); \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -1094,8 +1096,6 @@ $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST)/site-packages -f \ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages - -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - $(PYTHON_FOR_BUILD) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" # Create the PLATDIR source directory, if one wasn't distributed.. $(srcdir)/Lib/$(PLATDIR): @@ -1340,7 +1340,7 @@ find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';' find build -name 'fficonfig.h' -exec rm -f {} ';' || true find build -name 'fficonfig.py' -exec rm -f {} ';' || true - -rm -f Lib/lib2to3/*Grammar*.pickle + -rm -f $(srcdir)/Lib/lib2to3/*Grammar*.pickle -rm -f $(SYSCONFIGDATA) -rm -f Modules/_testembed Modules/_freeze_importlib diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -105,6 +105,11 @@ - Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. +Build +----- + +- Issue #15645: Ensure 2to3 grammar pickles are properly installed. + What's New in Python 3.3.0 Beta 2? ================================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 08:37:01 2012 From: python-checkins at python.org (ned.deily) Date: Thu, 23 Aug 2012 08:37:01 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2314292=3A_Ensure_t?= =?utf-8?q?hat_the_OS_X_installer_build_configures_the_CXX?= Message-ID: <3X2bWd5RJLzQJ9@mail.python.org> http://hg.python.org/cpython/rev/1f27572a10ce changeset: 78718:1f27572a10ce user: Ned Deily date: Wed Aug 22 23:34:50 2012 -0700 summary: Issue #14292: Ensure that the OS X installer build configures the CXX environment variable to a value comparable to what it sets for CC for the benefit of C++ extension modules. (Patch by Ronald Oussoren) files: Mac/BuildScript/build-installer.py | 28 +++++++++-------- 1 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -149,15 +149,15 @@ DEPTARGET = '10.3' target_cc_map = { - '10.3': 'gcc-4.0', - '10.4': 'gcc-4.0', - '10.5': 'gcc-4.2', - '10.6': 'gcc-4.2', - '10.7': 'clang', - '10.8': 'clang', + '10.3': ('gcc-4.0', 'g++-4.0'), + '10.4': ('gcc-4.0', 'g++-4.0'), + '10.5': ('gcc-4.2', 'g++-4.2'), + '10.6': ('gcc-4.2', 'g++-4.2'), + '10.7': ('clang', 'clang++'), + '10.8': ('clang', 'clang++'), } -CC = target_cc_map[DEPTARGET] +CC, CXX = target_cc_map[DEPTARGET] PYTHON_3 = getVersionTuple() >= (3, 0) @@ -264,8 +264,8 @@ url="http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz", checksum='00b516f4704d4a7cb50a1d97e6e8e15b', configure=None, - install='make install CC=%s PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( - CC, + install='make install CC=%s CXX=%s, PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( + CC, CXX, shellQuote(os.path.join(WORKDIR, 'libraries')), ' -arch '.join(ARCHLIST), SDKPATH, @@ -276,8 +276,8 @@ url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz", checksum='debc62758716a169df9f62e6ab2bc634', configure=None, - install='make install CC=%s prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( - CC, + install='make install CC=%s CXX=%s, prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%( + CC, CXX, shellQuote(os.path.join(WORKDIR, 'libraries')), ' -arch '.join(ARCHLIST), SDKPATH, @@ -550,7 +550,7 @@ Parse arguments and update global settings. """ global WORKDIR, DEPSRC, SDKPATH, SRCDIR, DEPTARGET - global UNIVERSALOPTS, UNIVERSALARCHS, ARCHLIST, CC + global UNIVERSALOPTS, UNIVERSALARCHS, ARCHLIST, CC, CXX if args is None: args = sys.argv[1:] @@ -608,7 +608,7 @@ SDKPATH=os.path.abspath(SDKPATH) DEPSRC=os.path.abspath(DEPSRC) - CC=target_cc_map[DEPTARGET] + CC, CXX=target_cc_map[DEPTARGET] print("Settings:") print(" * Source directory:", SRCDIR) @@ -618,6 +618,7 @@ print(" * Deployment target:", DEPTARGET) print(" * Universal architectures:", ARCHLIST) print(" * C compiler:", CC) + print(" * C++ compiler:", CXX) print("") @@ -1288,6 +1289,7 @@ os.environ['MACOSX_DEPLOYMENT_TARGET'] = DEPTARGET os.environ['CC'] = CC + os.environ['CXX'] = CXX if os.path.exists(WORKDIR): shutil.rmtree(WORKDIR) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 15:10:02 2012 From: python-checkins at python.org (stefan.krah) Date: Thu, 23 Aug 2012 15:10:02 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbjogbXBkX3Fwb3dtb2QoKTogY2Fs?= =?utf-8?q?culate_result_with_zero-exponent_for_compatibility_with?= Message-ID: <3X2mF64hv0zQ7y@mail.python.org> http://hg.python.org/cpython/rev/fcc1e7ca9a48 changeset: 78719:fcc1e7ca9a48 user: Stefan Krah date: Thu Aug 23 15:05:29 2012 +0200 summary: mpd_qpowmod(): calculate result with zero-exponent for compatibility with decimal.py. The hack to remove the ideal exponent is no longer required. files: Modules/_decimal/_decimal.c | 8 --- Modules/_decimal/libmpdec/mpdecimal.c | 34 +++++++------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3872,10 +3872,6 @@ else { mpd_qpowmod(MPD(result), MPD(a), MPD(b), MPD(c), CTX(context), &status); - status = (status == MPD_Clamped) ? 0 : status; - /* remove ideal exponent for compatibility with decimal.py */ - mpd_qquantize(MPD(result), MPD(result), &zero, - CTX(context), &status); Py_DECREF(c); } Py_DECREF(a); @@ -4905,10 +4901,6 @@ else { mpd_qpowmod(MPD(result), MPD(a), MPD(b), MPD(c), CTX(context), &status); - status = (status == MPD_Clamped) ? 0 : status; - /* remove ideal exponent for compatibility with decimal.py */ - mpd_qquantize(MPD(result), MPD(result), &zero, - CTX(context), &status); Py_DECREF(c); } Py_DECREF(a); 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 @@ -6372,7 +6372,7 @@ */ static inline void _mpd_qpowmod_uint(mpd_t *result, mpd_t *base, mpd_uint_t exp, - mpd_t *mod, uint32_t *status) + const mpd_t *mod, uint32_t *status) { mpd_context_t maxcontext; @@ -6383,10 +6383,10 @@ while (exp > 0) { if (exp & 1) { - mpd_qmul(result, result, base, &maxcontext, status); + _mpd_qmul_exact(result, result, base, &maxcontext, status); mpd_qrem(result, result, mod, &maxcontext, status); } - mpd_qmul(base, base, base, &maxcontext, status); + _mpd_qmul_exact(base, base, base, &maxcontext, status); mpd_qrem(base, base, mod, &maxcontext, status); exp >>= 1; } @@ -6452,27 +6452,30 @@ return; } - if (!mpd_qcopy(&tmod, mod, status)) { - goto mpd_errors; - } + mpd_maxcontext(&maxcontext); + + mpd_qrescale(&tmod, mod, 0, &maxcontext, &maxcontext.status); + if (maxcontext.status&MPD_Errors) { + mpd_seterror(result, maxcontext.status&MPD_Errors, status); + goto out; + } + maxcontext.status = 0; mpd_set_positive(&tmod); - mpd_maxcontext(&maxcontext); - mpd_qround_to_int(&tbase, base, &maxcontext, status); - mpd_qround_to_int(&texp, exp, &maxcontext, status); - mpd_qround_to_int(&tmod, &tmod, &maxcontext, status); - + mpd_set_positive(&tbase); tbase_exp = tbase.exp; tbase.exp = 0; + + mpd_qround_to_int(&texp, exp, &maxcontext, status); texp_exp = texp.exp; texp.exp = 0; /* base = (base.int % modulo * pow(10, base.exp, modulo)) % modulo */ mpd_qrem(&tbase, &tbase, &tmod, &maxcontext, status); - _settriple(result, MPD_POS, 1, tbase_exp); + mpd_qshiftl(result, &one, tbase_exp, status); mpd_qrem(result, result, &tmod, &maxcontext, status); - mpd_qmul(&tbase, &tbase, result, &maxcontext, status); + _mpd_qmul_exact(&tbase, &tbase, result, &maxcontext, status); mpd_qrem(&tbase, &tbase, &tmod, &maxcontext, status); if (mpd_isspecial(&tbase) || mpd_isspecial(&texp) || @@ -6494,10 +6497,10 @@ mpd_qcopy(result, &one, status); while (mpd_isfinite(&texp) && !mpd_iszero(&texp)) { if (mpd_isodd(&texp)) { - mpd_qmul(result, result, &tbase, &maxcontext, status); + _mpd_qmul_exact(result, result, &tbase, &maxcontext, status); mpd_qrem(result, result, &tmod, &maxcontext, status); } - mpd_qmul(&tbase, &tbase, &tbase, &maxcontext, status); + _mpd_qmul_exact(&tbase, &tbase, &tbase, &maxcontext, status); mpd_qrem(&tbase, &tbase, &tmod, &maxcontext, status); mpd_qdivint(&texp, &texp, &two, &maxcontext, status); } @@ -6515,7 +6518,6 @@ mpd_del(&texp); mpd_del(&tmod); mpd_del(&tmp); - mpd_qfinalize(result, ctx, status); return; mpd_errors: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 23 15:58:42 2012 From: python-checkins at python.org (stefan.krah) Date: Thu, 23 Aug 2012 15:58:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315770=3A_Check_in?= =?utf-8?q?valid_arguments_in_test_function=2E_Patch_by_Victor_Stinner=2E?= Message-ID: <3X2nKG6Z4mzQJJ@mail.python.org> http://hg.python.org/cpython/rev/fa745ed89b7a changeset: 78720:fa745ed89b7a user: Stefan Krah date: Thu Aug 23 15:53:45 2012 +0200 summary: Issue #15770: Check invalid arguments in test function. Patch by Victor Stinner. files: Lib/test/test_buffer.py | 2 ++ Modules/_testbuffer.c | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -1212,6 +1212,8 @@ self.assertRaises(TypeError, get_contiguous, nd, PyBUF_READ, 961) self.assertRaises(UnicodeEncodeError, get_contiguous, nd, PyBUF_READ, '\u2007') + self.assertRaises(ValueError, get_contiguous, nd, PyBUF_READ, 'Z') + self.assertRaises(ValueError, get_contiguous, nd, 255, 'A') # cmp_contig() nd = ndarray([1], shape=[1]) diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c --- a/Modules/_testbuffer.c +++ b/Modules/_testbuffer.c @@ -2362,6 +2362,13 @@ ord = PyBytes_AS_STRING(ascii_order)[0]; Py_DECREF(ascii_order); + + if (ord != 'C' && ord != 'F' && ord != 'A') { + PyErr_SetString(PyExc_ValueError, + "invalid order, must be C, F or A"); + return CHAR_MAX; + } + return ord; } @@ -2384,16 +2391,21 @@ "buffertype must be PyBUF_READ or PyBUF_WRITE"); return NULL; } + type = PyLong_AsLong(buffertype); if (type == -1 && PyErr_Occurred()) { return NULL; } - - ord = get_ascii_order(order); - if (ord == CHAR_MAX) { + if (type != PyBUF_READ && type != PyBUF_WRITE) { + PyErr_SetString(PyExc_ValueError, + "invalid buffer type"); return NULL; } + ord = get_ascii_order(order); + if (ord == CHAR_MAX) + return NULL; + return PyMemoryView_GetContiguous(obj, (int)type, ord); } -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Fri Aug 24 06:09:54 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 24 Aug 2012 06:09:54 +0200 Subject: [Python-checkins] Daily reference leaks (fa745ed89b7a): sum=6 Message-ID: results for fa745ed89b7a on branch "default" -------------------------------------------- test_capi leaked [2, 2, 2] references, sum=6 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogEr4Oyp', '-x'] From python-checkins at python.org Fri Aug 24 09:44:55 2012 From: python-checkins at python.org (ned.deily) Date: Fri, 24 Aug 2012 09:44:55 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315037=3A_Use_corr?= =?utf-8?q?ect_path_to_system_terminfo_database=2E?= Message-ID: <3X3DzW0G0RzQ8m@mail.python.org> http://hg.python.org/cpython/rev/e587426d719f changeset: 78721:e587426d719f user: Ned Deily date: Fri Aug 24 00:44:01 2012 -0700 summary: Issue #15037: Use correct path to system terminfo database. files: Mac/BuildScript/build-installer.py | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -215,8 +215,6 @@ "--with-shared", "--without-debug", "--without-normal", - "--without-termlib", - "--without-ticlib", "--without-tests", "--without-manpages", "--datadir=/usr/share", -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 10:33:05 2012 From: python-checkins at python.org (nick.coghlan) Date: Fri, 24 Aug 2012 10:33:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=232501=3A_Permissio?= =?utf-8?q?n_bits_are_once_again_correctly_copied_from_the_source?= Message-ID: <3X3G355vF5zPxL@mail.python.org> http://hg.python.org/cpython/rev/3a831a0a29c4 changeset: 78722:3a831a0a29c4 user: Nick Coghlan date: Fri Aug 24 18:32:40 2012 +1000 summary: Close #2501: Permission bits are once again correctly copied from the source file to the cached bytecode file. Test by Eric Snow. files: Lib/importlib/_bootstrap.py | 31 +- Lib/test/test_import.py | 25 +- Misc/NEWS | 5 + Python/importlib.h | 8517 +++++++++++----------- 4 files changed, 4345 insertions(+), 4233 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -118,13 +118,14 @@ return _path_is_mode_type(path, 0o040000) -def _write_atomic(path, data): +def _write_atomic(path, data, mode=0o666): """Best-effort function to write data to a path atomically. Be prepared to handle a FileExistsError if concurrent writing of the temporary file is attempted.""" # id() is used to generate a pseudo-random filename. path_tmp = '{}.{}'.format(path, id(path)) - fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY, 0o666) + fd = _os.open(path_tmp, + _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY, mode & 0o666) try: # We first write data to a temporary file, and then use os.replace() to # perform an atomic rename. @@ -887,6 +888,16 @@ """ return {'mtime': self.path_mtime(path)} + def _cache_bytecode(self, source_path, cache_path, data): + """Optional method which writes data (bytes) to a file path (a str). + + Implementing this method allows for the writing of bytecode files. + + The source path is needed in order to correctly transfer permissions + """ + # For backwards compatibility, we delegate to set_data() + return self.set_data(cache_path, data) + def set_data(self, path, data): """Optional method which writes data (bytes) to a file path (a str). @@ -974,7 +985,7 @@ data.extend(_w_long(len(source_bytes))) data.extend(marshal.dumps(code_object)) try: - self.set_data(bytecode_path, data) + self._cache_bytecode(source_path, bytecode_path, data) _verbose_message('wrote {!r}', bytecode_path) except NotImplementedError: pass @@ -1029,7 +1040,11 @@ st = _os.stat(path) return {'mtime': st.st_mtime, 'size': st.st_size} - def set_data(self, path, data): + def _cache_bytecode(self, source_path, bytecode_path, data): + # Adapt between the two APIs + return self.set_data(bytecode_path, data, source_path=source_path) + + def set_data(self, path, data, *, source_path=None): """Write bytes data to a file.""" parent, filename = _path_split(path) path_parts = [] @@ -1049,8 +1064,14 @@ # If can't get proper access, then just forget about writing # the data. return + mode = 0o666 + if source_path is not None: + try: + mode = _os.stat(source_path).st_mode + except OSError: + pass try: - _write_atomic(path, data) + _write_atomic(path, data, mode) _verbose_message('created {!r}', path) except (PermissionError, FileExistsError): # Don't worry if you can't write bytecode or someone is writing 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 @@ -120,12 +120,35 @@ s = os.stat(fn) # Check that the umask is respected, and the executable bits # aren't set. - self.assertEqual(stat.S_IMODE(s.st_mode), 0o666 & ~mask) + self.assertEqual(oct(stat.S_IMODE(s.st_mode)), oct(0o666 & ~mask)) finally: del sys.path[0] remove_files(TESTFN) unload(TESTFN) + @unittest.skipUnless(os.name == 'posix', + "test meaningful only on posix systems") + def test_cached_mode_issue_2051(self): + mode = 0o600 + source = TESTFN + ".py" + with script_helper.temp_dir() as tempdir: + path = script_helper.make_script(tempdir, TESTFN, + "key='top secret'") + os.chmod(path, mode) + compiled = imp.cache_from_source(path) + sys.path.insert(0, tempdir) + try: + __import__(TESTFN) + finally: + sys.path.remove(tempdir) + + if not os.path.exists(compiled): + self.fail("__import__ did not result in creation of " + "either a .pyc or .pyo file") + stat_info = os.stat(compiled) + + self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(mode)) + def test_imp_module(self): # Verify that the imp module can correctly load and find .py files # XXX (ncoghlan): It would be nice to use support.CleanImport diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,11 @@ Core and Builtins ----------------- +- Issue #2501: Source file permission bits are once again correctly + copied to the cached bytecode file. (The migration to importlib + reintroduced this problem because these was no regression test. A test + has been added as part of this patch) + - Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X. - Issue #15726: Fix incorrect bounds checking in PyState_FindModule. 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 Fri Aug 24 10:36:47 2012 From: python-checkins at python.org (nick.coghlan) Date: Fri, 24 Aug 2012 10:36:47 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=232051=3A_Oops=2C_t?= =?utf-8?q?ransposed_the_digits_in_the_issue_number_in_the_previous?= Message-ID: <3X3G7M2dt6zQ8G@mail.python.org> http://hg.python.org/cpython/rev/cfb11045fc8a changeset: 78723:cfb11045fc8a user: Nick Coghlan date: Fri Aug 24 18:36:31 2012 +1000 summary: Close #2051: Oops, transposed the digits in the issue number in the previous commit 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 #2501: Source file permission bits are once again correctly +- Issue #2051: Source file permission bits are once again correctly copied to the cached bytecode file. (The migration to importlib reintroduced this problem because these was no regression test. A test has been added as part of this patch) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 13:37:28 2012 From: python-checkins at python.org (ross.lagerwall) Date: Fri, 24 Aug 2012 13:37:28 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgMTU3Nzc6?= =?utf-8?q?_Fix_a_refleak_in_=5Fposixsubprocess=2E?= Message-ID: <3X3L7r51RYzQ85@mail.python.org> http://hg.python.org/cpython/rev/081507b4ae40 changeset: 78724:081507b4ae40 branch: 3.2 parent: 78715:a377a4298b4e user: Ross Lagerwall date: Fri Aug 24 13:25:59 2012 +0200 summary: Issue 15777: Fix a refleak in _posixsubprocess. It was exposed by 03c98d05b140 and dbbf3ccf72e8. files: Misc/NEWS | 2 ++ Modules/_posixsubprocess.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -109,6 +109,8 @@ Library ------- +- Issue #15777: Fix a refleak in _posixsubprocess. + - Issue #15199: Fix JavaScript's default MIME type to application/javascript. Patch by Bohuslav Kabrda. diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -566,8 +566,10 @@ } exec_array = _PySequence_BytesToCharpArray(executable_list); - if (!exec_array) + if (!exec_array) { + Py_XDECREF(gc_module); return NULL; + } /* Convert args and env into appropriate arguments for exec() */ /* These conversions are done in the parent process to avoid allocating -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 13:37:30 2012 From: python-checkins at python.org (ross.lagerwall) Date: Fri, 24 Aug 2012 13:37:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_with_3=2E2?= Message-ID: <3X3L7t2cNgzQCG@mail.python.org> http://hg.python.org/cpython/rev/c2df6d55f4d2 changeset: 78725:c2df6d55f4d2 parent: 78723:cfb11045fc8a parent: 78724:081507b4ae40 user: Ross Lagerwall date: Fri Aug 24 13:32:14 2012 +0200 summary: Merge with 3.2 files: Misc/NEWS | 2 ++ Modules/_posixsubprocess.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,8 @@ Library ------- +- Issue #15777: Fix a refleak in _posixsubprocess. + - Issue ##665194: Update email.utils.localtime to use datetime.astimezone and correctly handle historic changes in UTC offsets. diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -568,8 +568,10 @@ } exec_array = _PySequence_BytesToCharpArray(executable_list); - if (!exec_array) + if (!exec_array) { + Py_XDECREF(gc_module); return NULL; + } /* Convert args and env into appropriate arguments for exec() */ /* These conversions are done in the parent process to avoid allocating -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 15:07:20 2012 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 24 Aug 2012 15:07:20 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Add_missing_PGI/PGO_config?= =?utf-8?q?urations_for_pywlauncher=2E?= Message-ID: <3X3N7X2ccXzQ7q@mail.python.org> http://hg.python.org/cpython/rev/39dfb6e22588 changeset: 78726:39dfb6e22588 user: Martin v. L?wis date: Fri Aug 24 15:06:50 2012 +0200 summary: Add missing PGI/PGO configurations for pywlauncher. files: Misc/NEWS | 2 + PCbuild/pcbuild.sln | 1 + PCbuild/pywlauncher.vcxproj | 46 ++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -115,6 +115,8 @@ Build ----- +- Add missing PGI/PGO configurations for pywlauncher. + - Issue #15645: Ensure 2to3 grammar pickles are properly installed. diff --git a/PCbuild/pcbuild.sln b/PCbuild/pcbuild.sln --- a/PCbuild/pcbuild.sln +++ b/PCbuild/pcbuild.sln @@ -582,6 +582,7 @@ {7B2727B5-5A3F-40EE-A866-43A13CD31446}.PGUpdate|Win32.ActiveCfg = PGUpdate|Win32 {7B2727B5-5A3F-40EE-A866-43A13CD31446}.PGUpdate|Win32.Build.0 = PGUpdate|Win32 {7B2727B5-5A3F-40EE-A866-43A13CD31446}.PGUpdate|x64.ActiveCfg = PGUpdate|Win32 + {7B2727B5-5A3F-40EE-A866-43A13CD31446}.PGUpdate|x64.Build.0 = PGUpdate|Win32 {7B2727B5-5A3F-40EE-A866-43A13CD31446}.Release|Win32.ActiveCfg = Release|Win32 {7B2727B5-5A3F-40EE-A866-43A13CD31446}.Release|Win32.Build.0 = Release|Win32 {7B2727B5-5A3F-40EE-A866-43A13CD31446}.Release|x64.ActiveCfg = Release|Win32 diff --git a/PCbuild/pywlauncher.vcxproj b/PCbuild/pywlauncher.vcxproj --- a/PCbuild/pywlauncher.vcxproj +++ b/PCbuild/pywlauncher.vcxproj @@ -61,6 +61,12 @@ true Unicode + + Unicode + + + Unicode + @@ -86,6 +92,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + pyw_d @@ -171,21 +203,33 @@ version.lib;%(AdditionalDependencies) + + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + version.lib;%(AdditionalDependencies) + + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + version.lib;%(AdditionalDependencies) + + _WINDOWS;NDEBUG;_WIN64;_M_X64;%(PreprocessorDefinitions) + version.lib;%(AdditionalDependencies) + + _WINDOWS;NDEBUG;_WIN64;_M_X64;%(PreprocessorDefinitions) + @@ -199,4 +243,4 @@ - + \ No newline at end of file -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 15:22:04 2012 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 24 Aug 2012 15:22:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315511=3A_Drop_exp?= =?utf-8?q?licit_dependency_on_pythonxy=2Elib_from_amd64_configuration=2E?= Message-ID: <3X3NSX6TpVzQGR@mail.python.org> http://hg.python.org/cpython/rev/cbd4fbb90e95 changeset: 78727:cbd4fbb90e95 user: Martin v. L?wis date: Fri Aug 24 15:21:24 2012 +0200 summary: Issue #15511: Drop explicit dependency on pythonxy.lib from amd64 configuration. files: Misc/NEWS | 3 +++ PCbuild/_decimal.vcxproj | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -115,6 +115,9 @@ Build ----- +- Issue #15511: Drop explicit dependency on pythonxy.lib from _decimal + amd64 configuration. + - Add missing PGI/PGO configurations for pywlauncher. - Issue #15645: Ensure 2to3 grammar pickles are properly installed. diff --git a/PCbuild/_decimal.vcxproj b/PCbuild/_decimal.vcxproj --- a/PCbuild/_decimal.vcxproj +++ b/PCbuild/_decimal.vcxproj @@ -168,7 +168,6 @@ 0x1D1A0000 - $(OutDir)python33_d.lib;%(AdditionalDependencies) @@ -192,7 +191,6 @@ NotSet 0x1D1A0000 - $(OutDir)python33.lib;%(AdditionalDependencies) @@ -217,7 +215,6 @@ NotSet 0x1D1A0000 MachineX64 - $(OutDir)python33.lib;%(AdditionalDependencies) @@ -242,7 +239,6 @@ NotSet 0x1D1A0000 MachineX64 - $(SolutionDir)\$(PlatformShortName)\python33.lib;%(AdditionalDependencies) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 15:48:21 2012 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 24 Aug 2012 15:48:21 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A__Drop_PC=5Cpython=5Fnt=2Eh?= =?utf-8?q?_as_it=27s_not_used=2E?= Message-ID: <3X3P2s5cQTzQ2T@mail.python.org> http://hg.python.org/cpython/rev/fc8fe630c5dd changeset: 78728:fc8fe630c5dd user: Martin v. L?wis date: Fri Aug 24 15:47:53 2012 +0200 summary: Drop PC\python_nt.h as it's not used. Add input dependency on custom build step. files: Misc/NEWS | 3 +++ PCbuild/make_versioninfo.vcxproj | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -115,6 +115,9 @@ Build ----- +- Drop PC\python_nt.h as it's not used. Add input dependency on custom + build step. + - Issue #15511: Drop explicit dependency on pythonxy.lib from _decimal amd64 configuration. diff --git a/PCbuild/make_versioninfo.vcxproj b/PCbuild/make_versioninfo.vcxproj --- a/PCbuild/make_versioninfo.vcxproj +++ b/PCbuild/make_versioninfo.vcxproj @@ -87,6 +87,7 @@ make_versioninfo.exe > ..\PC\pythonnt_rc.h $(SolutionDir)..\PC\pythonnt_rc.h;%(Outputs) + $(SolutionDir)make_versioninfo.exe MaxSpeed @@ -104,10 +105,10 @@ Console 0x1d000000 + - cd $(SolutionDir) -make_versioninfo.exe > ..\PC\python_nt.h - + + @@ -140,6 +141,7 @@ make_versioninfo_d.exe > ..\PC\pythonnt_rc_d.h $(SolutionDir)..\PC\pythonnt_rc_d.h;%(Outputs) + $(SolutionDir)make_versioninfo_d.exe Disabled @@ -158,9 +160,8 @@ 0x1d000000 - cd $(SolutionDir) -make_versioninfo_d.exe > ..\PC\python_nt_d.h - + + -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 16:06:32 2012 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 24 Aug 2012 16:06:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Pick_up_32-bit_launcher_fr?= =?utf-8?q?om_PGO_directory_on_64-bit_PGO_build=2E?= Message-ID: <3X3PRr3fbpzQ7s@mail.python.org> http://hg.python.org/cpython/rev/a56c4178f65c changeset: 78729:a56c4178f65c user: Martin v. L?wis date: Fri Aug 24 16:06:10 2012 +0200 summary: Pick up 32-bit launcher from PGO directory on 64-bit PGO build. files: Misc/NEWS | 2 ++ Tools/msi/msi.py | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -115,6 +115,8 @@ Build ----- +- Pick up 32-bit launcher from PGO directory on 64-bit PGO build. + - Drop PC\python_nt.h as it's not used. Add input dependency on custom build step. diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -974,14 +974,17 @@ # 32-bit installer. # XXX does this still allow to install the component on a 32-bit system? # Pick up 32-bit binary always - launcher = os.path.join(srcdir, "PCBuild", "py.exe") + launchersrc = PCBUILD + if launchersrc.lower() == 'pcbuild\\x64-pgo': + launchersrc = 'PCBuild\\win32-pgo' + launcher = os.path.join(srcdir, launchersrc, "py.exe") launcherdir.start_component("launcher", flags = 8+256, keyfile="py.exe") - launcherdir.add_file("%s/py.exe" % PCBUILD, + launcherdir.add_file(launcher, version=installer.FileVersion(launcher, 0), language=installer.FileVersion(launcher, 1)) - launcherw = os.path.join(srcdir, "PCBuild", "pyw.exe") + launcherw = os.path.join(srcdir, launchersrc, "pyw.exe") launcherdir.start_component("launcherw", flags = 8+256, keyfile="pyw.exe") - launcherdir.add_file("%s/pyw.exe" % PCBUILD, + launcherdir.add_file(launcherw, version=installer.FileVersion(launcherw, 0), language=installer.FileVersion(launcherw, 1)) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 16:13:03 2012 From: python-checkins at python.org (martin.v.loewis) Date: Fri, 24 Aug 2012 16:13:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Output_lib_files_for_PGO_b?= =?utf-8?q?uild_into_PGO_directory=2E?= Message-ID: <3X3PbM0XhXzQ7K@mail.python.org> http://hg.python.org/cpython/rev/46e83012c413 changeset: 78730:46e83012c413 user: Martin v. L?wis date: Fri Aug 24 16:12:28 2012 +0200 summary: Output lib files for PGO build into PGO directory. files: Misc/NEWS | 2 ++ PCbuild/pgupdate.props | 1 + 2 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -115,6 +115,8 @@ Build ----- +- Output lib files for PGO build into PGO directory. + - Pick up 32-bit launcher from PGO directory on 64-bit PGO build. - Drop PC\python_nt.h as it's not used. Add input dependency on custom diff --git a/PCbuild/pgupdate.props b/PCbuild/pgupdate.props --- a/PCbuild/pgupdate.props +++ b/PCbuild/pgupdate.props @@ -11,6 +11,7 @@ %(AdditionalManifestDependencies) PGUpdate + $(OutDir)$(TargetName).lib \ No newline at end of file -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 17:31:41 2012 From: python-checkins at python.org (r.david.murray) Date: Fri, 24 Aug 2012 17:31:41 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1MjQ5OiBNYW5n?= =?utf-8?q?le_From_lines_correctly_when_body_contains_invalid_bytes=2E?= Message-ID: <3X3RL542ztzQBy@mail.python.org> http://hg.python.org/cpython/rev/119c645f310e changeset: 78731:119c645f310e branch: 3.2 parent: 78724:081507b4ae40 user: R David Murray date: Fri Aug 24 11:14:13 2012 -0400 summary: #15249: Mangle From lines correctly when body contains invalid bytes. Fix by Colin Su. Test by me, based on a test written by Petri Lehtinen. files: Lib/email/generator.py | 2 ++ Lib/email/test/test_email.py | 16 +++++++++++++++- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 21 insertions(+), 1 deletions(-) diff --git a/Lib/email/generator.py b/Lib/email/generator.py --- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -391,6 +391,8 @@ if msg._payload is None: return if _has_surrogates(msg._payload): + if self._mangle_from_: + msg._payload = fcre.sub(">From ", msg._payload) self.write(msg._payload) else: super(BytesGenerator,self)._handle_text(msg) diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -20,7 +20,7 @@ from email.charset import Charset from email.header import Header, decode_header, make_header from email.parser import Parser, HeaderParser -from email.generator import Generator, DecodedGenerator +from email.generator import Generator, DecodedGenerator, BytesGenerator from email.message import Message from email.mime.application import MIMEApplication from email.mime.audio import MIMEAudio @@ -1298,6 +1298,20 @@ self.assertEqual(len([1 for x in s.getvalue().split('\n') if x.startswith('>From ')]), 2) + def test_mangled_from_with_bad_bytes(self): + source = textwrap.dedent("""\ + Content-Type: text/plain; charset="utf-8" + MIME-Version: 1.0 + Content-Transfer-Encoding: 8bit + From: aaa at bbb.org + + """).encode('utf-8') + msg = email.message_from_bytes(source + b'From R\xc3\xb6lli\n') + b = BytesIO() + g = BytesGenerator(b, mangle_from_=True) + g.flatten(msg) + self.assertEqual(b.getvalue(), source + b'>From R\xc3\xb6lli\n') + # Test the basic MIMEAudio class class TestMIMEAudio(unittest.TestCase): diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -915,6 +915,7 @@ Dan Stromberg Daniel Stutzbach Andreas St?hrk +Colin Su Pal Subbiah Nathan Sullivan Mark Summerfield diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -109,6 +109,9 @@ Library ------- +- Issue #15249: BytesGenerator now correctly mangles From lines (when + requested) even if the body contains undecodable bytes. + - Issue #15777: Fix a refleak in _posixsubprocess. - Issue #15199: Fix JavaScript's default MIME type to application/javascript. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 17:31:43 2012 From: python-checkins at python.org (r.david.murray) Date: Fri, 24 Aug 2012 17:31:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_=2315249=3A_Mangle_From_lines_correctly_when_body_?= =?utf-8?q?contains_invalid_bytes=2E?= Message-ID: <3X3RL70pmzzQK0@mail.python.org> http://hg.python.org/cpython/rev/b6ee4e8c7a77 changeset: 78732:b6ee4e8c7a77 parent: 78730:46e83012c413 parent: 78731:119c645f310e user: R David Murray date: Fri Aug 24 11:23:50 2012 -0400 summary: Merge #15249: Mangle From lines correctly when body contains invalid bytes. Fix by Colin Su. Test by me, based on a test written by Petri Lehtinen. files: Lib/email/generator.py | 2 ++ Lib/test/test_email/test_email.py | 16 +++++++++++++++- Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 21 insertions(+), 1 deletions(-) diff --git a/Lib/email/generator.py b/Lib/email/generator.py --- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -400,6 +400,8 @@ if msg._payload is None: return if _has_surrogates(msg._payload) and not self.policy.cte_type=='7bit': + if self._mangle_from_: + msg._payload = fcre.sub(">From ", msg._payload) self.write(msg._payload) else: super(BytesGenerator,self)._handle_text(msg) diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -21,7 +21,7 @@ from email.charset import Charset from email.header import Header, decode_header, make_header from email.parser import Parser, HeaderParser -from email.generator import Generator, DecodedGenerator +from email.generator import Generator, DecodedGenerator, BytesGenerator from email.message import Message from email.mime.application import MIMEApplication from email.mime.audio import MIMEAudio @@ -1306,6 +1306,20 @@ self.assertEqual(len([1 for x in s.getvalue().split('\n') if x.startswith('>From ')]), 2) + def test_mangled_from_with_bad_bytes(self): + source = textwrap.dedent("""\ + Content-Type: text/plain; charset="utf-8" + MIME-Version: 1.0 + Content-Transfer-Encoding: 8bit + From: aaa at bbb.org + + """).encode('utf-8') + msg = email.message_from_bytes(source + b'From R\xc3\xb6lli\n') + b = BytesIO() + g = BytesGenerator(b, mangle_from_=True) + g.flatten(msg) + self.assertEqual(b.getvalue(), source + b'>From R\xc3\xb6lli\n') + # Test the basic MIMEAudio class class TestMIMEAudio(unittest.TestCase): diff --git a/Misc/ACKS b/Misc/ACKS --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1020,6 +1020,7 @@ Dan Stromberg Daniel Stutzbach Andreas St?hrk +Colin Su Pal Subbiah Nathan Sullivan Mark Summerfield diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,9 @@ Library ------- +- Issue #15249: BytesGenerator now correctly mangles From lines (when + requested) even if the body contains undecodable bytes. + - Issue #15777: Fix a refleak in _posixsubprocess. - Issue ##665194: Update email.utils.localtime to use datetime.astimezone and -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 18:00:29 2012 From: python-checkins at python.org (andrew.svetlov) Date: Fri, 24 Aug 2012 18:00:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315776=3A_Allow_py?= =?utf-8?q?venv_to_work_in_existing_directory_with_--clean=2E?= Message-ID: <3X3RzK0nC2zQ8G@mail.python.org> http://hg.python.org/cpython/rev/0668fc196ce5 changeset: 78733:0668fc196ce5 user: Andrew Svetlov date: Fri Aug 24 19:00:15 2012 +0300 summary: Issue #15776: Allow pyvenv to work in existing directory with --clean. Patch by Vinay Sajip. files: Lib/venv/__init__.py | 10 +++++++++- Misc/NEWS | 2 ++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -105,7 +105,15 @@ if os.path.exists(env_dir) and not (self.clear or self.upgrade): raise ValueError('Directory exists: %s' % env_dir) if os.path.exists(env_dir) and self.clear: - shutil.rmtree(env_dir) + # Issue 15776: To support running pyvenv on '.', the venv + # directory contents are emptied and recreated, instead of + # the venv directory being deleted and recreated. + for f in os.listdir(env_dir): + f = os.path.join(env_dir, f) + if os.path.isdir(f): + shutil.rmtree(f) + else: + os.remove(f) context = Context() context.env_dir = env_dir context.env_name = os.path.split(env_dir)[1] diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,8 @@ Library ------- +- Issue #15776: Allow pyvenv to work in existing directory with --clean. + - Issue #15249: BytesGenerator now correctly mangles From lines (when requested) even if the body contains undecodable bytes. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 18:17:37 2012 From: python-checkins at python.org (georg.brandl) Date: Fri, 24 Aug 2012 18:17:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogQ2xvc2VzICM5Mzc0?= =?utf-8?q?=3A_add_back_now-unused_module_attributes=3B_removing_them_is_a?= Message-ID: <3X3SM56tQszQCN@mail.python.org> http://hg.python.org/cpython/rev/a0b3cb52816e changeset: 78734:a0b3cb52816e branch: 3.2 parent: 78731:119c645f310e user: Georg Brandl date: Fri Aug 24 18:15:29 2012 +0200 summary: Closes #9374: add back now-unused module attributes; removing them is a backward compatibility issue, since they have a public-seeming name. files: Lib/urllib/parse.py | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -48,6 +48,16 @@ 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', 'mms', '', 'sftp'] +# These are not actually used anymore, but should stay for backwards +# compatibility. (They are undocumented, but have a public-looking name.) +non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', + 'telnet', 'wais', 'imap', 'snews', 'sip', 'sips'] +uses_query = ['http', 'wais', 'imap', 'https', 'shttp', 'mms', + 'gopher', 'rtsp', 'rtspu', 'sip', 'sips', ''] +uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news', + 'nntp', 'wais', 'https', 'shttp', 'snews', + 'file', 'prospero', ''] + # Characters valid in scheme names scheme_chars = ('abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 18:17:40 2012 From: python-checkins at python.org (georg.brandl) Date: Fri, 24 Aug 2012 18:17:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Closes_=239374=3A_merge_with_3=2E2?= Message-ID: <3X3SM80LCSzQLq@mail.python.org> http://hg.python.org/cpython/rev/c93fbc2caba5 changeset: 78735:c93fbc2caba5 parent: 78733:0668fc196ce5 parent: 78734:a0b3cb52816e user: Georg Brandl date: Fri Aug 24 18:15:46 2012 +0200 summary: Closes #9374: merge with 3.2 files: Lib/urllib/parse.py | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -48,6 +48,16 @@ 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', 'mms', '', 'sftp'] +# These are not actually used anymore, but should stay for backwards +# compatibility. (They are undocumented, but have a public-looking name.) +non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', + 'telnet', 'wais', 'imap', 'snews', 'sip', 'sips'] +uses_query = ['http', 'wais', 'imap', 'https', 'shttp', 'mms', + 'gopher', 'rtsp', 'rtspu', 'sip', 'sips', ''] +uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news', + 'nntp', 'wais', 'https', 'shttp', 'snews', + 'file', 'prospero', ''] + # Characters valid in scheme names scheme_chars = ('abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 18:17:41 2012 From: python-checkins at python.org (georg.brandl) Date: Fri, 24 Aug 2012 18:17:41 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICM5Mzc0?= =?utf-8?q?=3A_add_back_now-unused_module_attributes=3B_removing_them_is_a?= Message-ID: <3X3SM93T5pzQLv@mail.python.org> http://hg.python.org/cpython/rev/a43481210964 changeset: 78736:a43481210964 branch: 2.7 parent: 78714:787ed9b03ef9 user: Georg Brandl date: Fri Aug 24 18:17:28 2012 +0200 summary: Closes #9374: add back now-unused module attributes; removing them is a backward compatibility issue, since they have a public-seeming name. files: Lib/urlparse.py | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/Lib/urlparse.py b/Lib/urlparse.py --- a/Lib/urlparse.py +++ b/Lib/urlparse.py @@ -44,6 +44,16 @@ 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', 'mms', '', 'sftp'] +# These are not actually used anymore, but should stay for backwards +# compatibility. (They are undocumented, but have a public-looking name.) +non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', + 'telnet', 'wais', 'imap', 'snews', 'sip', 'sips'] +uses_query = ['http', 'wais', 'imap', 'https', 'shttp', 'mms', + 'gopher', 'rtsp', 'rtspu', 'sip', 'sips', ''] +uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news', + 'nntp', 'wais', 'https', 'shttp', 'snews', + 'file', 'prospero', ''] + # Characters valid in scheme names scheme_chars = ('abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:08:35 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 24 Aug 2012 19:08:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315778=3A_Coerce_I?= =?utf-8?q?mportError=2Eargs_to_a_string_when_it_isn=27t?= Message-ID: <3X3TTv4H9xzQMl@mail.python.org> http://hg.python.org/cpython/rev/91909962d7f5 changeset: 78737:91909962d7f5 parent: 78735:c93fbc2caba5 user: Brett Cannon date: Fri Aug 24 13:05:09 2012 -0400 summary: Issue #15778: Coerce ImportError.args to a string when it isn't already one. Patch by Dave Malcolm. files: Lib/test/test_exceptions.py | 5 +++++ Misc/NEWS | 3 +++ Objects/exceptions.c | 2 +- 3 files changed, 9 insertions(+), 1 deletions(-) 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 @@ -937,6 +937,11 @@ self.assertEqual(exc.name, 'somename') self.assertEqual(exc.path, 'somepath') + def test_non_str_argument(self): + # Issue #15778 + arg = b'abc' + exc = ImportError(arg) + self.assertEqual(str(arg), str(exc)) def test_main(): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15778: ensure that str(ImportError(msg)) returns a str + even when msg isn't a str. + - Issue #2051: Source file permission bits are once again correctly copied to the cached bytecode file. (The migration to importlib reintroduced this problem because these was no regression test. A test diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -679,7 +679,7 @@ static PyObject * ImportError_str(PyImportErrorObject *self) { - if (self->msg) { + if (self->msg && PyUnicode_CheckExact(self->msg)) { Py_INCREF(self->msg); return self->msg; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:48:47 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 24 Aug 2012 19:48:47 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=232051=3A_Tweak_las?= =?utf-8?q?t_commit_for_this_issue_to_pass_in_mode_instead?= Message-ID: <3X3VNH4Y9XzQBV@mail.python.org> http://hg.python.org/cpython/rev/0c661c5632e0 changeset: 78738:0c661c5632e0 user: Brett Cannon date: Fri Aug 24 13:48:39 2012 -0400 summary: Issue #2051: Tweak last commit for this issue to pass in mode instead of source path to set_data() and make the new argument private until possible API changes can be discussed more thoroughly in Python 3.4. files: Lib/importlib/_bootstrap.py | 16 +- Python/importlib.h | 3757 +++++++++++----------- 2 files changed, 1884 insertions(+), 1889 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1042,9 +1042,13 @@ def _cache_bytecode(self, source_path, bytecode_path, data): # Adapt between the two APIs - return self.set_data(bytecode_path, data, source_path=source_path) + try: + mode = _os.stat(source_path).st_mode + except OSError: + mode = 0o666 + return self.set_data(bytecode_path, data, _mode=mode) - def set_data(self, path, data, *, source_path=None): + def set_data(self, path, data, *, _mode=0o666): """Write bytes data to a file.""" parent, filename = _path_split(path) path_parts = [] @@ -1064,14 +1068,8 @@ # If can't get proper access, then just forget about writing # the data. return - mode = 0o666 - if source_path is not None: - try: - mode = _os.stat(source_path).st_mode - except OSError: - pass try: - _write_atomic(path, data, mode) + _write_atomic(path, data, _mode) _verbose_message('created {!r}', path) except (PermissionError, FileExistsError): # Don't worry if you can't write bytecode or someone is writing 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 Fri Aug 24 19:50:34 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:50:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE0Njc0?= =?utf-8?q?=3A_Add_a_discussion_of_the_json_module=27s_standard_compliance?= =?utf-8?q?=2E?= Message-ID: <3X3VQL3xsBzQK0@mail.python.org> http://hg.python.org/cpython/rev/132886ef135d changeset: 78739:132886ef135d branch: 3.2 parent: 78734:a0b3cb52816e user: Antoine Pitrou date: Fri Aug 24 19:37:23 2012 +0200 summary: Issue #14674: Add a discussion of the json module's standard compliance. Patch by Chris Rebert. files: Doc/library/json.rst | 117 +++++++++++++++++++++++++++++- Misc/NEWS | 3 + 2 files changed, 114 insertions(+), 6 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -6,8 +6,10 @@ .. moduleauthor:: Bob Ippolito .. sectionauthor:: Bob Ippolito -`JSON (JavaScript Object Notation) `_ is a subset of JavaScript -syntax (ECMA-262 3rd edition) used as a lightweight data interchange format. +`JSON (JavaScript Object Notation) `_, specified by +:rfc:`4627`, is a lightweight data interchange format based on a subset of +`JavaScript `_ syntax (`ECMA-262 3rd +edition `_). :mod:`json` exposes an API familiar to users of the standard library :mod:`marshal` and :mod:`pickle` modules. @@ -105,8 +107,10 @@ .. note:: - The JSON produced by this module's default settings is a subset of - YAML, so it may be used as a serializer for that as well. + JSON is a subset of `YAML `_ 1.2. The JSON produced by + this module's default settings (in particular, the default *separators* + value) is also a subset of YAML 1.0 and 1.1. This module can thus also be + used as a YAML serializer. Basic Usage @@ -185,7 +189,8 @@ *object_hook* is an optional function that will be called with the result of any object literal decoded (a :class:`dict`). The return value of *object_hook* will be used instead of the :class:`dict`. This feature can be used - to implement custom decoders (e.g. JSON-RPC class hinting). + to implement custom decoders (e.g. `JSON-RPC `_ + class hinting). *object_pairs_hook* is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The @@ -230,7 +235,7 @@ *encoding* which is ignored and deprecated. -Encoders and decoders +Encoders and Decoders --------------------- .. class:: JSONDecoder(object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None) @@ -415,3 +420,103 @@ for chunk in json.JSONEncoder().iterencode(bigobject): mysocket.write(chunk) + + +Standard Compliance +------------------- + +The JSON format is specified by :rfc:`4627`. This section details this +module's level of compliance with the RFC. For simplicity, +:class:`JSONEncoder` and :class:`JSONDecoder` subclasses, and parameters other +than those explicitly mentioned, are not considered. + +This module does not comply with the RFC in a strict fashion, implementing some +extensions that are valid JavaScript but not valid JSON. In particular: + +- Top-level non-object, non-array values are accepted and output; +- Infinite and NaN number values are accepted and output; +- Repeated names within an object are accepted, and only the value of the last + name-value pair is used. + +Since the RFC permits RFC-compliant parsers to accept input texts that are not +RFC-compliant, this module's deserializer is technically RFC-compliant under +default settings. + +Character Encodings +^^^^^^^^^^^^^^^^^^^ + +The RFC recommends that JSON be represented using either UTF-8, UTF-16, or +UTF-32, with UTF-8 being the default. + +As permitted, though not required, by the RFC, this module's serializer sets +*ensure_ascii=True* by default, thus escaping the output so that the resulting +strings only contain ASCII characters. + +Other than the *ensure_ascii* parameter, this module is defined strictly in +terms of conversion between Python objects and +:class:`Unicode strings `, and thus does not otherwise address the issue +of character encodings. + + +Top-level Non-Object, Non-Array Values +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC specifies that the top-level value of a JSON text must be either a +JSON object or array (Python :class:`dict` or :class:`list`). This module's +deserializer also accepts input texts consisting solely of a +JSON null, boolean, number, or string value:: + + >>> just_a_json_string = '"spam and eggs"' # Not by itself a valid JSON text + >>> json.loads(just_a_json_string) + 'spam and eggs' + +This module itself does not include a way to request that such input texts be +regarded as illegal. Likewise, this module's serializer also accepts single +Python :data:`None`, :class:`bool`, numeric, and :class:`str` +values as input and will generate output texts consisting solely of a top-level +JSON null, boolean, number, or string value without raising an exception:: + + >>> neither_a_list_nor_a_dict = "spam and eggs" + >>> json.dumps(neither_a_list_nor_a_dict) # The result is not a valid JSON text + '"spam and eggs"' + +This module's serializer does not itself include a way to enforce the +aforementioned constraint. + + +Infinite and NaN Number Values +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC does not permit the representation of infinite or NaN number values. +Despite that, by default, this module accepts and outputs ``Infinity``, +``-Infinity``, and ``NaN`` as if they were valid JSON number literal values:: + + >>> # Neither of these calls raises an exception, but the results are not valid JSON + >>> json.dumps(float('-inf')) + '-Infinity' + >>> json.dumps(float('nan')) + 'NaN' + >>> # Same when deserializing + >>> json.loads('-Infinity') + -inf + >>> json.loads('NaN') + nan + +In the serializer, the *allow_nan* parameter can be used to alter this +behavior. In the deserializer, the *parse_constant* parameter can be used to +alter this behavior. + + +Repeated Names Within an Object +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC specifies that the names within a JSON object should be unique, but +does not specify how repeated names in JSON objects should be handled. By +default, this module does not raise an exception; instead, it ignores all but +the last name-value pair for a given name:: + + >>> weird_json = '{"x": 1, "x": 2, "x": 3}' + >>> json.loads(weird_json) + {'x': 3} + +The *object_pairs_hook* parameter can be used to alter this behavior. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -514,6 +514,9 @@ Documentation ------------- +- Issue #14674: Add a discussion of the json module's standard compliance. + Patch by Chris Rebert. + - Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by Daniel Ellis. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:50:36 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:50:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2314674=3A_Add_a_discussion_of_the_json_module=27?= =?utf-8?q?s_standard_compliance=2E?= Message-ID: <3X3VQN1DnXzQLF@mail.python.org> http://hg.python.org/cpython/rev/16c0e26fc9cd changeset: 78740:16c0e26fc9cd parent: 78737:91909962d7f5 parent: 78739:132886ef135d user: Antoine Pitrou date: Fri Aug 24 19:39:47 2012 +0200 summary: Issue #14674: Add a discussion of the json module's standard compliance. Patch by Chris Rebert. files: Doc/library/json.rst | 117 +++++++++++++++++++++++++++++- Misc/NEWS | 3 + 2 files changed, 114 insertions(+), 6 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -6,8 +6,10 @@ .. moduleauthor:: Bob Ippolito .. sectionauthor:: Bob Ippolito -`JSON (JavaScript Object Notation) `_ is a subset of JavaScript -syntax (ECMA-262 3rd edition) used as a lightweight data interchange format. +`JSON (JavaScript Object Notation) `_, specified by +:rfc:`4627`, is a lightweight data interchange format based on a subset of +`JavaScript `_ syntax (`ECMA-262 3rd +edition `_). :mod:`json` exposes an API familiar to users of the standard library :mod:`marshal` and :mod:`pickle` modules. @@ -105,8 +107,10 @@ .. note:: - The JSON produced by this module's default settings is a subset of - YAML, so it may be used as a serializer for that as well. + JSON is a subset of `YAML `_ 1.2. The JSON produced by + this module's default settings (in particular, the default *separators* + value) is also a subset of YAML 1.0 and 1.1. This module can thus also be + used as a YAML serializer. Basic Usage @@ -185,7 +189,8 @@ *object_hook* is an optional function that will be called with the result of any object literal decoded (a :class:`dict`). The return value of *object_hook* will be used instead of the :class:`dict`. This feature can be used - to implement custom decoders (e.g. JSON-RPC class hinting). + to implement custom decoders (e.g. `JSON-RPC `_ + class hinting). *object_pairs_hook* is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The @@ -230,7 +235,7 @@ *encoding* which is ignored and deprecated. -Encoders and decoders +Encoders and Decoders --------------------- .. class:: JSONDecoder(object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None) @@ -415,3 +420,103 @@ for chunk in json.JSONEncoder().iterencode(bigobject): mysocket.write(chunk) + + +Standard Compliance +------------------- + +The JSON format is specified by :rfc:`4627`. This section details this +module's level of compliance with the RFC. For simplicity, +:class:`JSONEncoder` and :class:`JSONDecoder` subclasses, and parameters other +than those explicitly mentioned, are not considered. + +This module does not comply with the RFC in a strict fashion, implementing some +extensions that are valid JavaScript but not valid JSON. In particular: + +- Top-level non-object, non-array values are accepted and output; +- Infinite and NaN number values are accepted and output; +- Repeated names within an object are accepted, and only the value of the last + name-value pair is used. + +Since the RFC permits RFC-compliant parsers to accept input texts that are not +RFC-compliant, this module's deserializer is technically RFC-compliant under +default settings. + +Character Encodings +^^^^^^^^^^^^^^^^^^^ + +The RFC recommends that JSON be represented using either UTF-8, UTF-16, or +UTF-32, with UTF-8 being the default. + +As permitted, though not required, by the RFC, this module's serializer sets +*ensure_ascii=True* by default, thus escaping the output so that the resulting +strings only contain ASCII characters. + +Other than the *ensure_ascii* parameter, this module is defined strictly in +terms of conversion between Python objects and +:class:`Unicode strings `, and thus does not otherwise address the issue +of character encodings. + + +Top-level Non-Object, Non-Array Values +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC specifies that the top-level value of a JSON text must be either a +JSON object or array (Python :class:`dict` or :class:`list`). This module's +deserializer also accepts input texts consisting solely of a +JSON null, boolean, number, or string value:: + + >>> just_a_json_string = '"spam and eggs"' # Not by itself a valid JSON text + >>> json.loads(just_a_json_string) + 'spam and eggs' + +This module itself does not include a way to request that such input texts be +regarded as illegal. Likewise, this module's serializer also accepts single +Python :data:`None`, :class:`bool`, numeric, and :class:`str` +values as input and will generate output texts consisting solely of a top-level +JSON null, boolean, number, or string value without raising an exception:: + + >>> neither_a_list_nor_a_dict = "spam and eggs" + >>> json.dumps(neither_a_list_nor_a_dict) # The result is not a valid JSON text + '"spam and eggs"' + +This module's serializer does not itself include a way to enforce the +aforementioned constraint. + + +Infinite and NaN Number Values +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC does not permit the representation of infinite or NaN number values. +Despite that, by default, this module accepts and outputs ``Infinity``, +``-Infinity``, and ``NaN`` as if they were valid JSON number literal values:: + + >>> # Neither of these calls raises an exception, but the results are not valid JSON + >>> json.dumps(float('-inf')) + '-Infinity' + >>> json.dumps(float('nan')) + 'NaN' + >>> # Same when deserializing + >>> json.loads('-Infinity') + -inf + >>> json.loads('NaN') + nan + +In the serializer, the *allow_nan* parameter can be used to alter this +behavior. In the deserializer, the *parse_constant* parameter can be used to +alter this behavior. + + +Repeated Names Within an Object +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC specifies that the names within a JSON object should be unique, but +does not specify how repeated names in JSON objects should be handled. By +default, this module does not raise an exception; instead, it ignores all but +the last name-value pair for a given name:: + + >>> weird_json = '{"x": 1, "x": 2, "x": 3}' + >>> json.loads(weird_json) + {'x': 3} + +The *object_pairs_hook* parameter can be used to alter this behavior. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -84,6 +84,9 @@ Documentation ------------- +- Issue #14674: Add a discussion of the json module's standard compliance. + Patch by Chris Rebert. + - Create a 'Concurrent Execution' section in the docs, and split up the 'Optional Operating System Services' section to use a more user-centric classification scheme (splitting them across the new CE section, IPC and -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:50:37 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:50:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE0Njc0?= =?utf-8?q?=3A_Add_a_discussion_of_the_json_module=27s_standard_compliance?= =?utf-8?q?=2E?= Message-ID: <3X3VQP5NH1zQLX@mail.python.org> http://hg.python.org/cpython/rev/d413b36dbee5 changeset: 78741:d413b36dbee5 branch: 2.7 parent: 78736:a43481210964 user: Antoine Pitrou date: Fri Aug 24 19:46:17 2012 +0200 summary: Issue #14674: Add a discussion of the json module's standard compliance. Patch by Chris Rebert. files: Doc/library/json.rst | 122 +++++++++++++++++++++++++++++- Misc/NEWS | 3 + 2 files changed, 119 insertions(+), 6 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -7,8 +7,10 @@ .. sectionauthor:: Bob Ippolito .. versionadded:: 2.6 -`JSON (JavaScript Object Notation) `_ is a subset of JavaScript -syntax (ECMA-262 3rd edition) used as a lightweight data interchange format. +`JSON (JavaScript Object Notation) `_, specified by +:rfc:`4627`, is a lightweight data interchange format based on a subset of +`JavaScript `_ syntax (`ECMA-262 3rd +edition `_). :mod:`json` exposes an API familiar to users of the standard library :mod:`marshal` and :mod:`pickle` modules. @@ -106,8 +108,10 @@ .. note:: - The JSON produced by this module's default settings is a subset of - YAML, so it may be used as a serializer for that as well. + JSON is a subset of `YAML `_ 1.2. The JSON produced by + this module's default settings (in particular, the default *separators* + value) is also a subset of YAML 1.0 and 1.1. This module can thus also be + used as a YAML serializer. Basic Usage @@ -193,7 +197,8 @@ *object_hook* is an optional function that will be called with the result of any object literal decoded (a :class:`dict`). The return value of *object_hook* will be used instead of the :class:`dict`. This feature can be used - to implement custom decoders (e.g. JSON-RPC class hinting). + to implement custom decoders (e.g. `JSON-RPC `_ + class hinting). *object_pairs_hook* is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The @@ -242,7 +247,7 @@ The other arguments have the same meaning as in :func:`load`. -Encoders and decoders +Encoders and Decoders --------------------- .. class:: JSONDecoder([encoding[, object_hook[, parse_float[, parse_int[, parse_constant[, strict[, object_pairs_hook]]]]]]]) @@ -438,3 +443,108 @@ for chunk in JSONEncoder().iterencode(bigobject): mysocket.write(chunk) + + +Standard Compliance +------------------- + +The JSON format is specified by :rfc:`4627`. This section details this +module's level of compliance with the RFC. For simplicity, +:class:`JSONEncoder` and :class:`JSONDecoder` subclasses, and parameters other +than those explicitly mentioned, are not considered. + +This module does not comply with the RFC in a strict fashion, implementing some +extensions that are valid JavaScript but not valid JSON. In particular: + +- Top-level non-object, non-array values are accepted and output; +- Infinite and NaN number values are accepted and output; +- Repeated names within an object are accepted, and only the value of the last + name-value pair is used. + +Since the RFC permits RFC-compliant parsers to accept input texts that are not +RFC-compliant, this module's deserializer is technically RFC-compliant under +default settings. + +Character Encodings +^^^^^^^^^^^^^^^^^^^ + +The RFC recommends that JSON be represented using either UTF-8, UTF-16, or +UTF-32, with UTF-8 being the default. Accordingly, this module uses UTF-8 as +the default for its *encoding* parameter. + +This module's deserializer only directly works with ASCII-compatible encodings; +UTF-16, UTF-32, and other ASCII-incompatible encodings require the use of +workarounds described in the documentation for the deserializer's *encoding* +parameter. + +The RFC also non-normatively describes a limited encoding detection technique +for JSON texts; this module's deserializer does not implement this or any other +kind of encoding detection. + +As permitted, though not required, by the RFC, this module's serializer sets +*ensure_ascii=True* by default, thus escaping the output so that the resulting +strings only contain ASCII characters. + + +Top-level Non-Object, Non-Array Values +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC specifies that the top-level value of a JSON text must be either a +JSON object or array (Python :class:`dict` or :class:`list`). This module's +deserializer also accepts input texts consisting solely of a +JSON null, boolean, number, or string value:: + + >>> just_a_json_string = '"spam and eggs"' # Not by itself a valid JSON text + >>> json.loads(just_a_json_string) + u'spam and eggs' + +This module itself does not include a way to request that such input texts be +regarded as illegal. Likewise, this module's serializer also accepts single +Python :data:`None`, :class:`bool`, numeric, and :class:`str` +values as input and will generate output texts consisting solely of a top-level +JSON null, boolean, number, or string value without raising an exception:: + + >>> neither_a_list_nor_a_dict = u"spam and eggs" + >>> json.dumps(neither_a_list_nor_a_dict) # The result is not a valid JSON text + '"spam and eggs"' + +This module's serializer does not itself include a way to enforce the +aforementioned constraint. + + +Infinite and NaN Number Values +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC does not permit the representation of infinite or NaN number values. +Despite that, by default, this module accepts and outputs ``Infinity``, +``-Infinity``, and ``NaN`` as if they were valid JSON number literal values:: + + >>> # Neither of these calls raises an exception, but the results are not valid JSON + >>> json.dumps(float('-inf')) + '-Infinity' + >>> json.dumps(float('nan')) + 'NaN' + >>> # Same when deserializing + >>> json.loads('-Infinity') + -inf + >>> json.loads('NaN') + nan + +In the serializer, the *allow_nan* parameter can be used to alter this +behavior. In the deserializer, the *parse_constant* parameter can be used to +alter this behavior. + + +Repeated Names Within an Object +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The RFC specifies that the names within a JSON object should be unique, but +does not specify how repeated names in JSON objects should be handled. By +default, this module does not raise an exception; instead, it ignores all but +the last name-value pair for a given name:: + + >>> weird_json = '{"x": 1, "x": 2, "x": 3}' + >>> json.loads(weird_json) + {u'x': 3} + +The *object_pairs_hook* parameter can be used to alter this behavior. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -373,6 +373,9 @@ Documentation ------------- +- Issue #14674: Add a discussion of the json module's standard compliance. + Patch by Chris Rebert. + - Issue #15630: Add an example for "continue" stmt in the tutorial. Patch by Daniel Ellis. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:50:39 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:50:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge?= Message-ID: <3X3VQR1RRNzQM3@mail.python.org> http://hg.python.org/cpython/rev/150c58d98a5d changeset: 78742:150c58d98a5d parent: 78740:16c0e26fc9cd parent: 78738:0c661c5632e0 user: Antoine Pitrou date: Fri Aug 24 19:47:02 2012 +0200 summary: Merge files: Lib/importlib/_bootstrap.py | 16 +- Python/importlib.h | 3757 +++++++++++----------- 2 files changed, 1884 insertions(+), 1889 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1042,9 +1042,13 @@ def _cache_bytecode(self, source_path, bytecode_path, data): # Adapt between the two APIs - return self.set_data(bytecode_path, data, source_path=source_path) + try: + mode = _os.stat(source_path).st_mode + except OSError: + mode = 0o666 + return self.set_data(bytecode_path, data, _mode=mode) - def set_data(self, path, data, *, source_path=None): + def set_data(self, path, data, *, _mode=0o666): """Write bytes data to a file.""" parent, filename = _path_split(path) path_parts = [] @@ -1064,14 +1068,8 @@ # If can't get proper access, then just forget about writing # the data. return - mode = 0o666 - if source_path is not None: - try: - mode = _os.stat(source_path).st_mode - except OSError: - pass try: - _write_atomic(path, data, mode) + _write_atomic(path, data, _mode) _verbose_message('created {!r}', path) except (PermissionError, FileExistsError): # Don't worry if you can't write bytecode or someone is writing 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 Fri Aug 24 19:52:37 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:52:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Add_glossary_r?= =?utf-8?q?eferences?= Message-ID: <3X3VSj3zKpzQNM@mail.python.org> http://hg.python.org/cpython/rev/b60875fec9b7 changeset: 78743:b60875fec9b7 branch: 2.7 parent: 78741:d413b36dbee5 user: Antoine Pitrou date: Fri Aug 24 19:49:08 2012 +0200 summary: Add glossary references files: Doc/library/json.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -120,7 +120,7 @@ .. function:: dump(obj, fp[, skipkeys[, ensure_ascii[, check_circular[, allow_nan[, cls[, indent[, separators[, encoding[, default[, **kw]]]]]]]]]]) Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting - file-like object). + :term:`file-like object`). If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not of a basic type (:class:`str`, :class:`unicode`, :class:`int`, :class:`long`, @@ -185,8 +185,8 @@ .. function:: load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]]) - Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON - document) to a Python object. + Deserialize *fp* (a ``.read()``-supporting :term:`file-like object` + containing a JSON document) to a Python object. If the contents of *fp* are encoded with an ASCII based encoding other than UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be specified. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:53:25 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 19:53:25 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315544=3A_Fix_Deci?= =?utf-8?q?mal=2E=5F=5Ffloat=5F=5F_to_work_with_payload-carrying_NaNs=2E?= Message-ID: <3X3VTd5hmTzQJp@mail.python.org> http://hg.python.org/cpython/rev/49014c59b31f changeset: 78744:49014c59b31f parent: 78742:150c58d98a5d user: Mark Dickinson date: Fri Aug 24 18:53:10 2012 +0100 summary: Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. files: Lib/decimal.py | 8 +++++++- Lib/test/test_decimal.py | 16 ++++++++++++++++ Misc/NEWS | 2 ++ Modules/_decimal/_decimal.c | 18 +++++++++++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Lib/decimal.py b/Lib/decimal.py --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1601,7 +1601,13 @@ def __float__(self): """Float representation.""" - return float(str(self)) + if self._isnan(): + if self.is_snan(): + raise ValueError("Cannot convert signaling NaN to float") + s = "-nan" if self._sign else "nan" + else: + s = str(self) + return float(s) def __int__(self): """Converts self to an int, truncating if necessary.""" 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 @@ -1942,6 +1942,22 @@ for d, n, r in test_triples: self.assertEqual(str(round(Decimal(d), n)), r) + def test_nan_to_float(self): + # Test conversions of decimal NANs to float. + # See http://bugs.python.org/issue15544 + Decimal = self.decimal.Decimal + for s in ('nan', 'nan1234', '-nan', '-nan2468'): + f = float(Decimal(s)) + self.assertTrue(math.isnan(f)) + sign = math.copysign(1.0, f) + self.assertEqual(sign, -1.0 if s.startswith('-') else 1.0) + + def test_snan_to_float(self): + Decimal = self.decimal.Decimal + for s in ('snan', '-snan', 'snan1357', '-snan1234'): + d = Decimal(s) + self.assertRaises(ValueError, float, d) + def test_eval_round_trip(self): Decimal = self.decimal.Decimal diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -32,6 +32,8 @@ Library ------- +- Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. + - Issue #15776: Allow pyvenv to work in existing directory with --clean. - Issue #15249: BytesGenerator now correctly mangles From lines (when diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3357,7 +3357,23 @@ { PyObject *f, *s; - s = dec_str(dec); + if (mpd_isnan(MPD(dec))) { + if (mpd_issnan(MPD(dec))) { + PyErr_SetString(PyExc_ValueError, + "cannot convert signaling NaN to float"); + return NULL; + } + if (mpd_isnegative(MPD(dec))) { + s = PyUnicode_FromString("-nan"); + } + else { + s = PyUnicode_FromString("nan"); + } + } + else { + s = dec_str(dec); + } + if (s == NULL) { return NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:54:39 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:54:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Add_glossary_r?= =?utf-8?q?eferences?= Message-ID: <3X3VW36ddDzQGf@mail.python.org> http://hg.python.org/cpython/rev/eeb44f8245b2 changeset: 78745:eeb44f8245b2 branch: 3.2 parent: 78739:132886ef135d user: Antoine Pitrou date: Fri Aug 24 19:49:08 2012 +0200 summary: Add glossary references files: Doc/library/json.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -119,7 +119,7 @@ .. function:: dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, **kw) Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting - file-like object). + :term:`file-like object`). If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not of a basic type (:class:`str`, :class:`int`, :class:`float`, :class:`bool`, @@ -183,8 +183,8 @@ .. function:: load(fp, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) - Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON - document) to a Python object. + Deserialize *fp* (a ``.read()``-supporting :term:`file-like object` + containing a JSON document) to a Python object. *object_hook* is an optional function that will be called with the result of any object literal decoded (a :class:`dict`). The return value of -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:54:41 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:54:41 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Add_glossary_references?= Message-ID: <3X3VW52nXnzQL2@mail.python.org> http://hg.python.org/cpython/rev/343ef00d1dbe changeset: 78746:343ef00d1dbe parent: 78742:150c58d98a5d parent: 78745:eeb44f8245b2 user: Antoine Pitrou date: Fri Aug 24 19:50:43 2012 +0200 summary: Add glossary references files: Doc/library/json.rst | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -119,7 +119,7 @@ .. function:: dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, **kw) Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting - file-like object). + :term:`file-like object`). If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not of a basic type (:class:`str`, :class:`int`, :class:`float`, :class:`bool`, @@ -183,8 +183,8 @@ .. function:: load(fp, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw) - Deserialize *fp* (a ``.read()``-supporting file-like object containing a JSON - document) to a Python object. + Deserialize *fp* (a ``.read()``-supporting :term:`file-like object` + containing a JSON document) to a Python object. *object_hook* is an optional function that will be called with the result of any object literal decoded (a :class:`dict`). The return value of -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 19:54:42 2012 From: python-checkins at python.org (antoine.pitrou) Date: Fri, 24 Aug 2012 19:54:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge?= Message-ID: <3X3VW66TtnzQPX@mail.python.org> http://hg.python.org/cpython/rev/88e041f69fc7 changeset: 78747:88e041f69fc7 parent: 78746:343ef00d1dbe parent: 78744:49014c59b31f user: Antoine Pitrou date: Fri Aug 24 19:51:09 2012 +0200 summary: Merge files: Lib/decimal.py | 8 +++++++- Lib/test/test_decimal.py | 16 ++++++++++++++++ Misc/NEWS | 2 ++ Modules/_decimal/_decimal.c | 18 +++++++++++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Lib/decimal.py b/Lib/decimal.py --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1601,7 +1601,13 @@ def __float__(self): """Float representation.""" - return float(str(self)) + if self._isnan(): + if self.is_snan(): + raise ValueError("Cannot convert signaling NaN to float") + s = "-nan" if self._sign else "nan" + else: + s = str(self) + return float(s) def __int__(self): """Converts self to an int, truncating if necessary.""" 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 @@ -1942,6 +1942,22 @@ for d, n, r in test_triples: self.assertEqual(str(round(Decimal(d), n)), r) + def test_nan_to_float(self): + # Test conversions of decimal NANs to float. + # See http://bugs.python.org/issue15544 + Decimal = self.decimal.Decimal + for s in ('nan', 'nan1234', '-nan', '-nan2468'): + f = float(Decimal(s)) + self.assertTrue(math.isnan(f)) + sign = math.copysign(1.0, f) + self.assertEqual(sign, -1.0 if s.startswith('-') else 1.0) + + def test_snan_to_float(self): + Decimal = self.decimal.Decimal + for s in ('snan', '-snan', 'snan1357', '-snan1234'): + d = Decimal(s) + self.assertRaises(ValueError, float, d) + def test_eval_round_trip(self): Decimal = self.decimal.Decimal diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -32,6 +32,8 @@ Library ------- +- Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. + - Issue #15776: Allow pyvenv to work in existing directory with --clean. - Issue #15249: BytesGenerator now correctly mangles From lines (when diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3357,7 +3357,23 @@ { PyObject *f, *s; - s = dec_str(dec); + if (mpd_isnan(MPD(dec))) { + if (mpd_issnan(MPD(dec))) { + PyErr_SetString(PyExc_ValueError, + "cannot convert signaling NaN to float"); + return NULL; + } + if (mpd_isnegative(MPD(dec))) { + s = PyUnicode_FromString("-nan"); + } + else { + s = PyUnicode_FromString("nan"); + } + } + else { + s = dec_str(dec); + } + if (s == NULL) { return NULL; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 20:18:35 2012 From: python-checkins at python.org (stefan.krah) Date: Fri, 24 Aug 2012 20:18:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2313072=3A_The_arra?= =?utf-8?q?y_module=27s_=27u=27_format_code_is_now_deprecated_and?= Message-ID: <3X3W2g6CJVzQ0h@mail.python.org> http://hg.python.org/cpython/rev/9c7515e29219 changeset: 78748:9c7515e29219 user: Stefan Krah date: Fri Aug 24 20:14:12 2012 +0200 summary: Issue #13072: The array module's 'u' format code is now deprecated and will be removed in Python 4.0. files: Doc/library/array.rst | 7 ++++++- Doc/whatsnew/3.3.rst | 7 +++++++ Misc/NEWS | 3 +++ 3 files changed, 16 insertions(+), 1 deletions(-) diff --git a/Doc/library/array.rst b/Doc/library/array.rst --- a/Doc/library/array.rst +++ b/Doc/library/array.rst @@ -47,10 +47,15 @@ Notes: (1) - The ``'u'`` type code corresponds to Python's unicode character + The ``'u'`` type code corresponds to Python's obsolete unicode character (:c:type:`Py_UNICODE` which is :c:type:`wchar_t`). Depending on the platform, it can be 16 bits or 32 bits. + ``'u'`` will be removed together with the rest of the :c:type:`Py_UNICODE` + API. + + .. deprecated-removed:: 3.3 4.0 + (2) The ``'q'`` and ``'Q'`` type codes are available only if the platform C compiler used to build Python supports C :c:type:`long long`, 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 @@ -1841,6 +1841,13 @@ :c:func:`PyUnicode_TransformDecimalToASCII` +Deprecated features +------------------- + +The :mod:`array` module's ``'u'`` format code is now deprecated and will be +removed in Python 4 together with the rest of the (:c:type:`Py_UNICODE`) API. + + Porting to Python 3.3 ===================== diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -32,6 +32,9 @@ Library ------- +- Issue #13072: The array module's 'u' format code is now deprecated and + will be removed in Python 4.0. + - Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. - Issue #15776: Allow pyvenv to work in existing directory with --clean. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 20:40:52 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 20:40:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1NTQ0?= =?utf-8?q?=3A_Fix_Decimal=2E=5F=5Ffloat=5F=5F_to_work_with_payload-carryi?= =?utf-8?q?ng_NaNs=2E?= Message-ID: <3X3WXN6nzlzQ9G@mail.python.org> http://hg.python.org/cpython/rev/a931e44ffbe1 changeset: 78749:a931e44ffbe1 branch: 3.2 parent: 78745:eeb44f8245b2 user: Mark Dickinson date: Fri Aug 24 19:32:13 2012 +0100 summary: Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. files: Lib/decimal.py | 8 +++++++- Lib/test/test_decimal.py | 16 ++++++++++++++++ Misc/NEWS | 2 ++ 3 files changed, 25 insertions(+), 1 deletions(-) diff --git a/Lib/decimal.py b/Lib/decimal.py --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1555,7 +1555,13 @@ def __float__(self): """Float representation.""" - return float(str(self)) + if self._isnan(): + if self.is_snan(): + raise ValueError("Cannot convert signaling NaN to float") + s = "-nan" if self._sign else "nan" + else: + s = str(self) + return float(s) def __int__(self): """Converts self to an int, truncating if necessary.""" 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 @@ -1518,6 +1518,22 @@ + def test_nan_to_float(self): + # Test conversions of decimal NANs to float. + # See http://bugs.python.org/issue15544 + Decimal = self.decimal.Decimal + for s in ('nan', 'nan1234', '-nan', '-nan2468'): + f = float(Decimal(s)) + self.assertTrue(math.isnan(f)) + sign = math.copysign(1.0, f) + self.assertEqual(sign, -1.0 if s.startswith('-') else 1.0) + + def test_snan_to_float(self): + Decimal = self.decimal.Decimal + for s in ('snan', '-snan', 'snan1357', '-snan1234'): + d = Decimal(s) + self.assertRaises(ValueError, float, d) + def test_eval_round_trip(self): #with zero diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -109,6 +109,8 @@ Library ------- +- Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. + - Issue #15249: BytesGenerator now correctly mangles From lines (when requested) even if the body contains undecodable bytes. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 20:40:54 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 20:40:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Null_merge_from_3=2E2=2E?= Message-ID: <3X3WXQ3kMPzQ6k@mail.python.org> http://hg.python.org/cpython/rev/52aaa9295cc4 changeset: 78750:52aaa9295cc4 parent: 78748:9c7515e29219 parent: 78749:a931e44ffbe1 user: Mark Dickinson date: Fri Aug 24 19:40:25 2012 +0100 summary: Null merge from 3.2. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 20:51:49 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 20:51:49 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Remove_incorre?= =?utf-8?q?ct_lines_=28meant_for_cdecimal=29_from_recently_added_Decimal_t?= =?utf-8?q?ests=2E?= Message-ID: <3X3Wn14lF8zNg5@mail.python.org> http://hg.python.org/cpython/rev/ffbda5a1d588 changeset: 78751:ffbda5a1d588 branch: 3.2 parent: 78749:a931e44ffbe1 user: Mark Dickinson date: Fri Aug 24 19:51:00 2012 +0100 summary: Remove incorrect lines (meant for cdecimal) from recently added Decimal tests. files: Lib/test/test_decimal.py | 2 -- 1 files changed, 0 insertions(+), 2 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 @@ -1521,7 +1521,6 @@ def test_nan_to_float(self): # Test conversions of decimal NANs to float. # See http://bugs.python.org/issue15544 - Decimal = self.decimal.Decimal for s in ('nan', 'nan1234', '-nan', '-nan2468'): f = float(Decimal(s)) self.assertTrue(math.isnan(f)) @@ -1529,7 +1528,6 @@ self.assertEqual(sign, -1.0 if s.startswith('-') else 1.0) def test_snan_to_float(self): - Decimal = self.decimal.Decimal for s in ('snan', '-snan', 'snan1357', '-snan1234'): d = Decimal(s) self.assertRaises(ValueError, float, d) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 20:51:51 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 20:51:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Null_merge?= Message-ID: <3X3Wn31zcczPqy@mail.python.org> http://hg.python.org/cpython/rev/ed0f88224bbc changeset: 78752:ed0f88224bbc parent: 78750:52aaa9295cc4 parent: 78751:ffbda5a1d588 user: Mark Dickinson date: Fri Aug 24 19:51:32 2012 +0100 summary: Null merge files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 21:01:14 2012 From: python-checkins at python.org (vinay.sajip) Date: Fri, 24 Aug 2012 21:01:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Reverted_change_to_venv_in?= =?utf-8?q?itialisation=2E?= Message-ID: <3X3Wzt3ZyPzQBQ@mail.python.org> http://hg.python.org/cpython/rev/c8ff866591f7 changeset: 78753:c8ff866591f7 user: Vinay Sajip date: Fri Aug 24 20:01:02 2012 +0100 summary: Reverted change to venv initialisation. files: Lib/venv/__init__.py | 10 +--------- 1 files changed, 1 insertions(+), 9 deletions(-) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -105,15 +105,7 @@ if os.path.exists(env_dir) and not (self.clear or self.upgrade): raise ValueError('Directory exists: %s' % env_dir) if os.path.exists(env_dir) and self.clear: - # Issue 15776: To support running pyvenv on '.', the venv - # directory contents are emptied and recreated, instead of - # the venv directory being deleted and recreated. - for f in os.listdir(env_dir): - f = os.path.join(env_dir, f) - if os.path.isdir(f): - shutil.rmtree(f) - else: - os.remove(f) + shutil.rmtree(env_dir) context = Context() context.env_dir = env_dir context.env_name = os.path.split(env_dir)[1] -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 21:06:51 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 21:06:51 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NTQ0?= =?utf-8?q?=3A_Fix_Decimal=2E=5F=5Ffloat=5F=5F_to_work_with_payload-carryi?= =?utf-8?q?ng_NaNs=2E?= Message-ID: <3X3X6M3ZWqzQHg@mail.python.org> http://hg.python.org/cpython/rev/5dd5f824428c changeset: 78754:5dd5f824428c branch: 2.7 parent: 78743:b60875fec9b7 user: Mark Dickinson date: Fri Aug 24 20:06:30 2012 +0100 summary: Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. files: Lib/decimal.py | 8 +++++++- Lib/test/test_decimal.py | 14 ++++++++++++++ Misc/NEWS | 2 ++ 3 files changed, 23 insertions(+), 1 deletions(-) diff --git a/Lib/decimal.py b/Lib/decimal.py --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1581,7 +1581,13 @@ def __float__(self): """Float representation.""" - return float(str(self)) + if self._isnan(): + if self.is_snan(): + raise ValueError("Cannot convert signaling NaN to float") + s = "-nan" if self._sign else "nan" + else: + s = str(self) + return float(s) def __int__(self): """Converts self to an int, truncating if necessary.""" 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 @@ -1448,6 +1448,20 @@ self.assertEqual(float(d1), 66) self.assertEqual(float(d2), 15.32) + def test_nan_to_float(self): + # Test conversions of decimal NANs to float. + # See http://bugs.python.org/issue15544 + for s in ('nan', 'nan1234', '-nan', '-nan2468'): + f = float(Decimal(s)) + self.assertTrue(math.isnan(f)) + sign = math.copysign(1.0, f) + self.assertEqual(sign, -1.0 if s.startswith('-') else 1.0) + + def test_snan_to_float(self): + for s in ('snan', '-snan', 'snan1357', '-snan1234'): + d = Decimal(s) + self.assertRaises(ValueError, float, d) + def test_eval_round_trip(self): #with zero diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -95,6 +95,8 @@ Library ------- +- Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. + - Issue #15199: Fix JavaScript's default MIME type to application/javascript. Patch by Bohuslav Kabrda. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 21:26:39 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 21:26:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Remove_overeag?= =?utf-8?q?er_test_=28don=27t_depend_on_the_sign_of_a_nan=3B__cf=2E_issue_?= =?utf-8?q?=2314521=29?= Message-ID: <3X3XYC3Ck4zQJ6@mail.python.org> http://hg.python.org/cpython/rev/31a7ff299698 changeset: 78755:31a7ff299698 branch: 2.7 user: Mark Dickinson date: Fri Aug 24 20:26:23 2012 +0100 summary: Remove overeager test (don't depend on the sign of a nan; cf. issue #14521) files: Lib/test/test_decimal.py | 2 -- 1 files changed, 0 insertions(+), 2 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 @@ -1454,8 +1454,6 @@ for s in ('nan', 'nan1234', '-nan', '-nan2468'): f = float(Decimal(s)) self.assertTrue(math.isnan(f)) - sign = math.copysign(1.0, f) - self.assertEqual(sign, -1.0 if s.startswith('-') else 1.0) def test_snan_to_float(self): for s in ('snan', '-snan', 'snan1357', '-snan1234'): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 21:32:44 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 21:32:44 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Remove_overeag?= =?utf-8?q?er_test_=28don=27t_depend_on_the_sign_of_a_nan=3B__cf=2E_issue_?= =?utf-8?q?=2314521=29?= Message-ID: <3X3XhD4HDjzQNW@mail.python.org> http://hg.python.org/cpython/rev/121cb9596e7d changeset: 78756:121cb9596e7d branch: 3.2 parent: 78751:ffbda5a1d588 user: Mark Dickinson date: Fri Aug 24 20:31:33 2012 +0100 summary: Remove overeager test (don't depend on the sign of a nan; cf. issue #14521) files: Lib/test/test_decimal.py | 4 ---- 1 files changed, 0 insertions(+), 4 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 @@ -1516,16 +1516,12 @@ for d, n, r in test_triples: self.assertEqual(str(round(Decimal(d), n)), r) - - def test_nan_to_float(self): # Test conversions of decimal NANs to float. # See http://bugs.python.org/issue15544 for s in ('nan', 'nan1234', '-nan', '-nan2468'): f = float(Decimal(s)) self.assertTrue(math.isnan(f)) - sign = math.copysign(1.0, f) - self.assertEqual(sign, -1.0 if s.startswith('-') else 1.0) def test_snan_to_float(self): for s in ('snan', '-snan', 'snan1357', '-snan1234'): -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 24 21:32:46 2012 From: python-checkins at python.org (mark.dickinson) Date: Fri, 24 Aug 2012 21:32:46 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Null_merge_from_3=2E2?= Message-ID: <3X3XhG29QzzQPk@mail.python.org> http://hg.python.org/cpython/rev/249f8c232a30 changeset: 78757:249f8c232a30 parent: 78753:c8ff866591f7 parent: 78756:121cb9596e7d user: Mark Dickinson date: Fri Aug 24 20:32:24 2012 +0100 summary: Null merge from 3.2 files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 00:26:07 2012 From: python-checkins at python.org (brett.cannon) Date: Sat, 25 Aug 2012 00:26:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315316=3A_Let_exce?= =?utf-8?q?ptions_raised_during_imports_triggered_by_the?= Message-ID: <3X3cXH1FbfzQ3j@mail.python.org> http://hg.python.org/cpython/rev/ca4bf8e10bc0 changeset: 78758:ca4bf8e10bc0 user: Brett Cannon date: Fri Aug 24 18:25:59 2012 -0400 summary: Issue #15316: Let exceptions raised during imports triggered by the fromlist of __import__ propagate. The problem previously was that if something listed in fromlist didn't exist then that's okay. The fix for that was too broad in terms of catching ImportError. The trick with the solution to this issue is that the proper refactoring of import thanks to importlib doesn't allow for a way to distinguish (portably) between an ImportError because finders couldn't find a loader, or a loader raised the exception. In Python 3.4 the hope is to introduce a new exception (e.g. ModuleNotFound) to make it clean to differentiate why ImportError was raised. files: Lib/importlib/_bootstrap.py | 18 +- Lib/test/test_importlib/import_/test_api.py | 38 + Misc/NEWS | 4 + Python/importlib.h | 387 +++++---- 4 files changed, 254 insertions(+), 193 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1513,7 +1513,11 @@ raise ImportError(msg, name=name) loader = _find_module(name, path) if loader is None: - raise ImportError(_ERR_MSG.format(name), name=name) + exc = ImportError(_ERR_MSG.format(name), name=name) + # TODO(brett): switch to a proper ModuleNotFound exception in Python + # 3.4. + exc._not_found = True + raise exc elif name not in sys.modules: # The parent import may have already imported this module. loader.load_module(name) @@ -1599,10 +1603,16 @@ try: _call_with_frames_removed(import_, '{}.{}'.format(module.__name__, x)) - except ImportError: + except ImportError as exc: # Backwards-compatibility dictates we ignore failed - # imports triggered by fromlist. - pass + # imports triggered by fromlist for modules that don't + # exist. + # TODO(brett): In Python 3.4, have import raise + # ModuleNotFound and catch that. + if hasattr(exc, '_not_found') and exc._not_found: + pass + else: + raise return module diff --git a/Lib/test/test_importlib/import_/test_api.py b/Lib/test/test_importlib/import_/test_api.py --- a/Lib/test/test_importlib/import_/test_api.py +++ b/Lib/test/test_importlib/import_/test_api.py @@ -1,7 +1,22 @@ +from .. import util as importlib_test_util from . import util +import imp +import sys import unittest +class BadLoaderFinder: + bad = 'fine.bogus' + @classmethod + def find_module(cls, fullname, path): + if fullname == cls.bad: + return cls + @classmethod + def load_module(cls, fullname): + if fullname == cls.bad: + raise ImportError('I cannot be loaded!') + + class APITest(unittest.TestCase): """Test API-specific details for __import__ (e.g. raising the right @@ -19,6 +34,29 @@ with self.assertRaises(ValueError): util.import_('os', globals(), level=-1) + def test_nonexistent_fromlist_entry(self): + # If something in fromlist doesn't exist, that's okay. + # issue15715 + mod = imp.new_module('fine') + mod.__path__ = ['XXX'] + with importlib_test_util.import_state(meta_path=[BadLoaderFinder]): + with importlib_test_util.uncache('fine'): + sys.modules['fine'] = mod + util.import_('fine', fromlist=['not here']) + + def test_fromlist_load_error_propagates(self): + # If something in fromlist triggers an exception not related to not + # existing, let that exception propagate. + # issue15316 + mod = imp.new_module('fine') + mod.__path__ = ['XXX'] + with importlib_test_util.import_state(meta_path=[BadLoaderFinder]): + with importlib_test_util.uncache('fine'): + sys.modules['fine'] = mod + with self.assertRaises(ImportError): + util.import_('fine', fromlist=['bogus']) + + def test_main(): from test.support import run_unittest diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #15316: When an item in the fromlist for __import__ doesn't exist, + don't raise an error, but if an exception is raised as part of an import do + let that propagate. + - Issue #15778: ensure that str(ImportError(msg)) returns a str even when msg isn't a str. 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 Sat Aug 25 04:58:46 2012 From: python-checkins at python.org (ned.deily) Date: Sat, 25 Aug 2012 04:58:46 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Update_various_OS_X_README?= =?utf-8?q?_files_for_3=2E3=2E0=2E?= Message-ID: <3X3kZt6mNvzQLX@mail.python.org> http://hg.python.org/cpython/rev/6c898f297925 changeset: 78759:6c898f297925 user: Ned Deily date: Fri Aug 24 19:57:33 2012 -0700 summary: Update various OS X README files for 3.3.0. files: Mac/BuildScript/README.txt | 161 +++++++++---- Mac/BuildScript/resources/ReadMe.txt | 28 +- Mac/BuildScript/resources/Welcome.rtf | 8 +- Mac/README | 35 ++- 4 files changed, 168 insertions(+), 64 deletions(-) diff --git a/Mac/BuildScript/README.txt b/Mac/BuildScript/README.txt --- a/Mac/BuildScript/README.txt +++ b/Mac/BuildScript/README.txt @@ -8,70 +8,125 @@ an Installer package from the installation plus other files in ``resources`` and ``scripts`` and placed that on a ``.dmg`` disk image. -As of Python 2.7.x and 3.2, PSF practice is to build two installer variants -for each release: +As of Python 3.3.0, PSF practice is to build two installer variants +for each release. 1. 32-bit-only, i386 and PPC universal, capable on running on all machines - supported by Mac OS X 10.3.9 through (at least) 10.6:: + supported by Mac OS X 10.5 through (at least) 10.8:: - python build-installer.py \ + /usr/bin/python build-installer.py \ + --sdk-path=/Developer/SDKs/MacOSX10.5.sdk \ + --universal-archs=32-bit \ + --dep-target=10.5 + + - builds the following third-party libraries + + * NCurses 5.9 (http://bugs.python.org/issue15037) + * SQLite 3.7.13 + * XZ 5.0.3 + + - uses system-supplied versions of third-party libraries + + * readline module links with Apple BSD editline (libedit) + + - requires ActiveState ``Tcl/Tk 8.4`` (currently 8.4.19) to be installed for building + + - recommended build environment: + + * Mac OS X 10.5.8 Intel or PPC + * Xcode 3.1.4 + * ``MacOSX10.5`` SDK + * ``MACOSX_DEPLOYMENT_TARGET=10.5`` + * Apple ``gcc-4.2`` + * system Python 2.5 for documentation build with Sphinx + + - alternate build environments: + + * Mac OS X 10.6.8 with Xcode 3.2.6 + - need to change ``/System/Library/Frameworks/{Tcl,Tk}.framework/Version/Current`` to ``8.4`` + * Note Xcode 4.* does not support building for PPC so cannot be used for this build + +2. 64-bit / 32-bit, x86_64 and i386 universal, for OS X 10.6 (and later):: + + /usr/bin/python build-installer.py \ + --sdk-path=/Developer/SDKs/MacOSX10.6.sdk \ + --universal-archs=intel \ + --dep-target=10.6 + + - builds the following third-party libraries + + * NCurses 5.9 (http://bugs.python.org/issue15037) + * SQLite 3.7.13 + * XZ 5.0.3 + + - uses system-supplied versions of third-party libraries + + * readline module links with Apple BSD editline (libedit) + + - requires ActiveState Tcl/Tk 8.5.9 (or later) to be installed for building + + - recommended build environment: + + * Mac OS X 10.6.8 (or later) + * Xcode 3.2.6 + * ``MacOSX10.6`` SDK + * ``MACOSX_DEPLOYMENT_TARGET=10.6`` + * Apple ``gcc-4.2`` + * system Python 2.6 for documentation build with Sphinx + + - alternate build environments: + + * none. Xcode 4.x currently supplies two C compilers. + ``llvm-gcc-4.2.1`` has been found to miscompile Python 3.3.x and + produce a non-functional Python executable. As it appears to be + considered a migration aid by Apple and is not likely to be fixed, + its use should be avoided. The other compiler, ``clang``, has been + undergoing rapid development. While it appears to have become + production-ready in the most recent Xcode 4 releases (Xcode 4.4.1 + as of this writing), there are still some open issues when + building Python and there has not yet been the level of exposure in + production environments that the Xcode 3 gcc-4.2 compiler has had. + + +* For Python 2.7.x and 3.2.x, the 32-bit-only installer was configured to + support Mac OS X 10.3.9 through (at least) 10.6. Because it is + believed that there are few systems still running OS X 10.3 or 10.4 + and because it has become increasingly difficult to test and + support the differences in these earlier systems, as of Python 3.3.0 the PSF + 32-bit installer no longer supports them. For reference in building such + an installer yourself, the details are:: + + /usr/bin/python build-installer.py \ --sdk-path=/Developer/SDKs/MacOSX10.4u.sdk \ --universal-archs=32-bit \ --dep-target=10.3 - # These are the current default options - builds the following third-party libraries * Bzip2 - * Zlib 1.2.3 + * NCurses * GNU Readline (GPL) * SQLite 3 - * NCurses + * XZ + * Zlib 1.2.3 * Oracle Sleepycat DB 4.8 (Python 2.x only) - requires ActiveState ``Tcl/Tk 8.4`` (currently 8.4.19) to be installed for building - - current target build environment: + - recommended build environment: * Mac OS X 10.5.8 PPC or Intel * Xcode 3.1.4 (or later) * ``MacOSX10.4u`` SDK (later SDKs do not support PPC G3 processors) * ``MACOSX_DEPLOYMENT_TARGET=10.3`` * Apple ``gcc-4.0`` - * Python 2.n (n >= 4) for documentation build with Sphinx + * system Python 2.5 for documentation build with Sphinx - alternate build environments: - * Mac OS X 10.4.11 with Xcode 2.5 - * Mac OS X 10.6.6 with Xcode 3.2.5 + * Mac OS X 10.6.8 with Xcode 3.2.6 - need to change ``/System/Library/Frameworks/{Tcl,Tk}.framework/Version/Current`` to ``8.4`` -2. 64-bit / 32-bit, x86_64 and i386 universal, for OS X 10.6 (and later):: - - python build-installer.py \ - --sdk-path=/Developer/SDKs/MacOSX10.6.sdk \ - --universal-archs=intel \ - --dep-target=10.6 - - - uses system-supplied versions of third-party libraries - - * readline module links with Apple BSD editline (libedit) - * builds Oracle Sleepycat DB 4.8 (Python 2.x only) - - - requires ActiveState Tcl/Tk 8.5.9 (or later) to be installed for building - - - current target build environment: - - * Mac OS X 10.6.6 (or later) - * Xcode 3.2.5 (or later) - * ``MacOSX10.6`` SDK - * ``MACOSX_DEPLOYMENT_TARGET=10.6`` - * Apple ``gcc-4.2`` - * Python 2.n (n >= 4) for documentation build with Sphinx - - - alternate build environments: - - * none General Prerequisites @@ -87,6 +142,11 @@ * It is safest to start each variant build with an empty source directory populated with a fresh copy of the untarred source. +* It is recommended that you remove any existing installed version of the + Python being built:: + + sudo rm -rf /Library/Frameworks/Python.framework/Versions/n.n + The Recipe ---------- @@ -107,9 +167,9 @@ ................................... It is also possible to build a 4-way universal installer that runs on -OS X Leopard or later:: +OS X 10.5 Leopard or later:: - python 2.6 /build-installer.py \ + /usr/bin/python /build-installer.py \ --dep-target=10.5 --universal-archs=all --sdk-path=/Developer/SDKs/MacOSX10.5.sdk @@ -120,7 +180,8 @@ variants can only be run on G5 machines running 10.5. Note that, while OS X 10.6 is only supported on Intel-based machines, it is possible to run ``ppc`` (32-bit) executables unmodified thanks to the Rosetta ppc -emulation in OS X 10.5 and 10.6. +emulation in OS X 10.5 and 10.6. The 4-way installer variant must be +built with Xcode 3. It is not regularly built or tested. Other ``--universal-archs`` options are ``64-bit`` (``x86_64``, ``ppc64``), and ``3-way`` (``ppc``, ``i386``, ``x86_64``). None of these options @@ -133,15 +194,21 @@ Ideally, the resulting binaries should be installed and the test suite run on all supported OS X releases and architectures. As a practical matter, that is generally not possible. At a minimum, variant 1 should be run on -at least one Intel, one PPC G4, and one PPC G3 system and one each of -OS X 10.6, 10.5, 10.4, and 10.3.9. Not all tests run on 10.3.9. -Variant 2 should be run on 10.6 in both 32-bit and 64-bit modes.:: +a PPC G4 system with OS X 10.5 and at least one Intel system running OS X +10.8, 10.7, 10.6, or 10.5. Variant 2 should be run on 10.8, 10.7, and 10.6 +systems in both 32-bit and 64-bit modes.:: - arch -i386 /usr/local/bin/pythonn.n -m test.regrtest -w -u all - arch -X86_64 /usr/local/bin/pythonn.n -m test.regrtest -w -u all + /usr/local/bin/pythonn.n -m test -w -u all,-largefile + /usr/local/bin/pythonn.n-32 -m test -w -u all Certain tests will be skipped and some cause the interpreter to fail which will likely generate ``Python quit unexpectedly`` alert messages -to be generated at several points during a test run. These can -be ignored. +to be generated at several points during a test run. These are normal +during testing and can be ignored. +It is also recommend to launch IDLE and verify that it is at least +functional. Double-click on the IDLE app icon in ``/Applications/Pythonn.n``. +It should also be tested from the command line:: + + /usr/local/bin/idlen.n + diff --git a/Mac/BuildScript/resources/ReadMe.txt b/Mac/BuildScript/resources/ReadMe.txt --- a/Mac/BuildScript/resources/ReadMe.txt +++ b/Mac/BuildScript/resources/ReadMe.txt @@ -5,8 +5,15 @@ Installation requires approximately $INSTALL_SIZE MB of disk space, ignore the message that it will take zero bytes. -You must install onto your current boot disk, even though the -installer does not enforce this, otherwise things will not work. +If you are attempting to install on an OS X 10.8 system, you may +see a message that Python can't be installed because it is from an +unidentified developer. This is because this Python installer +package is not yet compatible with the Gatekeeper security feature +introduced in OS X 10.8. To allow Python to be installed, you +can override the Gatekeeper policy for this install. In the Finder, +instead of double-clicking, control-click or right click the "Python" +installer package icon. Then select "Open using ... Installer" from +the contextual menu that appears. Python consists of the Python programming language interpreter, plus a set of programs to allow easy access to it for Mac users including @@ -16,10 +23,11 @@ **** IMPORTANT **** -Before using IDLE or other programs using the tkinter graphical user -interface toolkit, visit http://www.python.org/download/mac/tcltk/ -for current information about supported and recommended versions -of Tcl/Tk for this version of Python and Mac OS X. +To use IDLE or other programs that use the tkinter graphical user +interface toolkit, you may need to install a third-party version of +the Tcl/Tk frameworks. Visit http://www.python.org/download/mac/tcltk/ +for current information about supported and recommended versions of +Tcl/Tk for this version of Python and of Mac OS X. ******************* @@ -32,5 +40,13 @@ well. Double-click on the "Update Shell Profile" command to add the "bin" directory inside the framework to your shell's search path. +You must install onto your current boot disk, even though the +installer does not enforce this, otherwise things will not work. + +You can verify the integrity of the disk image file containing the +installer package and this ReadMe file by comparing its md5 checksum +and size with the values published on the release page linked at +http://www.python.org/download/ + More information on Python in general can be found at http://www.python.org. diff --git a/Mac/BuildScript/resources/Welcome.rtf b/Mac/BuildScript/resources/Welcome.rtf --- a/Mac/BuildScript/resources/Welcome.rtf +++ b/Mac/BuildScript/resources/Welcome.rtf @@ -1,8 +1,8 @@ -{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350 +{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf470 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw11904\paperh16836\margl1440\margr1440\vieww9640\viewh10620\viewkind0 -\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640 \f0\fs24 \cf0 This package will install \b Python $FULL_VERSION @@ -20,9 +20,9 @@ \ \b NOTE: -\b0 This package will by default not update your shell profile and will also not install files in /usr/local. Double-click +\b0 This package will not update your shell profile by default. Double-click \b Update Shell Profile -\b0 at any time to make $FULL_VERSION the default Python.\ +\b0 at any time to make $FULL_VERSION the default Python 3 version. This version can co-exist with other installed versions of Python 3 and Python 2.\ \ \b IMPORTANT: diff --git a/Mac/README b/Mac/README --- a/Mac/README +++ b/Mac/README @@ -129,8 +129,8 @@ binaries when the universal architecture includes at least one 32-bit architecture (that is, for all flavors but ``64-bit``). -Running a specific archicture -............................. +Running a specific architecture +............................... You can run code using a specific architecture using the ``arch`` command:: @@ -145,6 +145,14 @@ wrapper tools that execute the real interpreter without ensuring that the real interpreter runs with the same architecture. +Using ``arch`` is not a perfect solution as the selected architecture will +not automatically carry through to subprocesses launched by programs and tests +under that Python. If you want to ensure that Python interpreters launched in +subprocesses also run in 32-bit-mode if the main interpreter does, use +a ``python3.3-32`` binary and use the value of ``sys.executable`` as the +``subprocess`` ``Popen`` executable value. + + Building and using a framework-based Python on Mac OS X. ======================================================== @@ -180,9 +188,16 @@ ---------------------------- Yes, probably. If you want Tkinter support you need to get the OSX AquaTk -distribution, this is installed by default on Mac OS X 10.4 or later. If -you want wxPython you need to get that. If you want Cocoa you need to get -PyObjC. +distribution, this is installed by default on Mac OS X 10.4 or later. Be +aware, though, that the Cocoa-based AquaTk's supplied starting with OS X +10.6 have proven to be unstable. If possible, you should consider +installing a newer version before building on OS X 10.6 or later, such as +the ActiveTcl 8.5. See http://www.python.org/download/mac/tcltk/. If you +are building with an SDK, ensure that the newer Tcl and Tk frameworks are +seen in the SDK's ``Library/Frameworks`` directory; you may need to +manually create symlinks to their installed location, ``/Library/Frameworks``. +If you want wxPython you need to get that. +If you want Cocoa you need to get PyObjC. 4. How do I build a framework Python? ------------------------------------- @@ -260,7 +275,13 @@ available out of the box with OS X 10.4 so you may have to install additional software beyond what is provided with Xcode 2. OS X 10.5 provides a recent enough system Python (in ``/usr/bin``) to build -the Python documentation set. +the Python documentation set. It should be possible to use SDKs and/or older +versions of Xcode to build installers that are compatible with older systems +on a newer system but this may not be completely foolproof so the resulting +executables, shared libraries, and ``.so`` bundles should be carefully +examined and tested on all supported systems for proper dynamic linking +dependencies. It is safest to build the distribution on a system running the +minimum OS X version supported. All of this is normally done completely isolated in /tmp/_py, so it does not use your normal build directory nor does it install into /. @@ -285,7 +306,7 @@ configure: WARNING: ## -------------------------------------- ## This almost always means you are trying to build a universal binary for -Python and have libaries in ``/usr/local`` that don't contain the required +Python and have libraries in ``/usr/local`` that don't contain the required architectures. Temporarily move ``/usr/local`` aside to finish the build. -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sat Aug 25 06:10:31 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sat, 25 Aug 2012 06:10:31 +0200 Subject: [Python-checkins] Daily reference leaks (ca4bf8e10bc0): sum=0 Message-ID: results for ca4bf8e10bc0 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogcdjjxS', '-x'] From python-checkins at python.org Sat Aug 25 10:00:03 2012 From: python-checkins at python.org (nick.coghlan) Date: Sat, 25 Aug 2012 10:00:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Close_=2315573=3A_use_valu?= =?utf-8?q?e-based_memoryview_comparisons_=28patch_by_Stefan_Krah=29?= Message-ID: <3X3sGW0fjYzQQZ@mail.python.org> http://hg.python.org/cpython/rev/afa3dedfee18 changeset: 78760:afa3dedfee18 user: Nick Coghlan date: Sat Aug 25 17:59:50 2012 +1000 summary: Close #15573: use value-based memoryview comparisons (patch by Stefan Krah) files: Doc/library/stdtypes.rst | 78 ++- Doc/whatsnew/3.3.rst | 7 +- Lib/test/test_buffer.py | 522 ++++++++++++++++++++++---- Misc/NEWS | 3 + Objects/memoryobject.c | 348 +++++++++++++++-- 5 files changed, 802 insertions(+), 156 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2405,6 +2405,52 @@ :class:`memoryview` has several methods: + .. method:: __eq__(exporter) + + A memoryview and a :pep:`3118` exporter are equal if their shapes are + equivalent and if all corresponding values are equal when the operands' + respective format codes are interpreted using :mod:`struct` syntax. + + For the subset of :mod:`struct` format strings currently supported by + :meth:`tolist`, ``v`` and ``w`` are equal if ``v.tolist() == w.tolist()``:: + + >>> import array + >>> a = array.array('I', [1, 2, 3, 4, 5]) + >>> b = array.array('d', [1.0, 2.0, 3.0, 4.0, 5.0]) + >>> c = array.array('b', [5, 3, 1]) + >>> x = memoryview(a) + >>> y = memoryview(b) + >>> x == a == y == b + True + >>> x.tolist() == a.tolist() == y.tolist() == b.tolist() + True + >>> z = y[::-2] + >>> z == c + True + >>> z.tolist() == c.tolist() + True + + If either format string is not supported by the :mod:`struct` module, + then the objects will always compare as unequal (even if the format + strings and buffer contents are identical):: + + >>> from ctypes import BigEndianStructure, c_long + >>> class BEPoint(BigEndianStructure): + ... _fields_ = [("x", c_long), ("y", c_long)] + ... + >>> point = BEPoint(100, 200) + >>> a = memoryview(point) + >>> b = memoryview(point) + >>> a == point + False + >>> a == b + False + + Note that, as with floating point numbers, ``v is w`` does *not* imply + ``v == w`` for memoryview objects. + + .. versionchanged:: 3.3 + .. method:: tobytes() Return the data in the buffer as a bytestring. This is equivalent to @@ -2417,7 +2463,9 @@ b'abc' For non-contiguous arrays the result is equal to the flattened list - representation with all elements converted to bytes. + representation with all elements converted to bytes. :meth:`tobytes` + supports all format strings, including those that are not in + :mod:`struct` module syntax. .. method:: tolist() @@ -2431,6 +2479,9 @@ >>> m.tolist() [1.1, 2.2, 3.3] + :meth:`tolist` is currently restricted to single character native formats + in :mod:`struct` module syntax. + .. method:: release() Release the underlying buffer exposed by the memoryview object. Many @@ -2470,7 +2521,10 @@ ``[byte_length//new_itemsize]``, which means that the result view will be one-dimensional. The return value is a new memoryview, but the buffer itself is not copied. Supported casts are 1D -> C-contiguous - and C-contiguous -> 1D. One of the formats must be a byte format + and C-contiguous -> 1D. + + Both formats are restricted to single element native formats in + :mod:`struct` syntax. One of the formats must be a byte format ('B', 'b' or 'c'). The byte length of the result must be the same as the original length. @@ -2608,25 +2662,7 @@ A string containing the format (in :mod:`struct` module style) for each element in the view. A memoryview can be created from exporters with arbitrary format strings, but some methods (e.g. :meth:`tolist`) are - restricted to native single element formats. Special care must be taken - when comparing memoryviews. Since comparisons are required to return a - value for ``==`` and ``!=``, two memoryviews referencing the same - exporter can compare as not-equal if the exporter's format is not - understood:: - - >>> from ctypes import BigEndianStructure, c_long - >>> class BEPoint(BigEndianStructure): - ... _fields_ = [("x", c_long), ("y", c_long)] - ... - >>> point = BEPoint(100, 200) - >>> a = memoryview(point) - >>> b = memoryview(point) - >>> a == b - False - >>> a.tolist() - Traceback (most recent call last): - File "", line 1, in - NotImplementedError: memoryview: unsupported format T{>l:x:>l:y:} + restricted to native single element formats. .. attribute:: itemsize 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 @@ -162,7 +162,6 @@ and the view is read-only. (Contributed by Antoine Pitrou in :issue:`13411`) - * Arbitrary slicing of any 1-D arrays type is supported. For example, it is now possible to reverse a memoryview in O(1) by using a negative step. @@ -178,6 +177,12 @@ now returns an integer (in accordance with the struct module syntax). For returning a bytes object the view must be cast to 'c' first. +* memoryview comparisons now use the logical structure of the operands + and compare all array elements by value. All format strings in struct + module syntax are supported. Views with unrecognised format strings + are still permitted, but will always compare as unequal, regardless + of view contents. + * For further changes see `Build and C API Changes`_ and `Porting C code`_ . .. _pep-393: diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -32,6 +32,11 @@ struct = None try: + import ctypes +except ImportError: + ctypes = None + +try: with warnings.catch_warnings(): from numpy import ndarray as numpy_array except ImportError: @@ -835,8 +840,6 @@ # test tobytes() self.assertEqual(result.tobytes(), b) - if not buf_err and is_memoryview_format(fmt): - # lst := expected multi-dimensional logical representation # flatten(lst) := elements in C-order ff = fmt if fmt else 'B' @@ -877,8 +880,10 @@ # To 'C' contig = py_buffer_to_contiguous(result, 'C', PyBUF_FULL_RO) self.assertEqual(len(contig), nmemb * itemsize) - initlst = [struct.unpack_from(fmt, contig, n*itemsize)[0] + initlst = [struct.unpack_from(fmt, contig, n*itemsize) for n in range(nmemb)] + if len(initlst[0]) == 1: + initlst = [v[0] for v in initlst] y = ndarray(initlst, shape=shape, flags=ro, format=fmt) self.assertEqual(memoryview(y), memoryview(result)) @@ -886,8 +891,10 @@ # To 'F' contig = py_buffer_to_contiguous(result, 'F', PyBUF_FULL_RO) self.assertEqual(len(contig), nmemb * itemsize) - initlst = [struct.unpack_from(fmt, contig, n*itemsize)[0] + initlst = [struct.unpack_from(fmt, contig, n*itemsize) for n in range(nmemb)] + if len(initlst[0]) == 1: + initlst = [v[0] for v in initlst] y = ndarray(initlst, shape=shape, flags=ro|ND_FORTRAN, format=fmt) @@ -896,8 +903,10 @@ # To 'A' contig = py_buffer_to_contiguous(result, 'A', PyBUF_FULL_RO) self.assertEqual(len(contig), nmemb * itemsize) - initlst = [struct.unpack_from(fmt, contig, n*itemsize)[0] + initlst = [struct.unpack_from(fmt, contig, n*itemsize) for n in range(nmemb)] + if len(initlst[0]) == 1: + initlst = [v[0] for v in initlst] f = ND_FORTRAN if is_contiguous(result, 'F') else 0 y = ndarray(initlst, shape=shape, flags=f|ro, format=fmt) @@ -3025,7 +3034,7 @@ self.assertEqual(m.tobytes(), a.tobytes()) cmptest(self, a, b, m, singleitem) - def test_memoryview_compare(self): + def test_memoryview_compare_special_cases(self): a = array.array('L', [1, 2, 3]) b = array.array('L', [1, 2, 7]) @@ -3054,43 +3063,32 @@ v = memoryview(a) self.assertNotEqual(v, [1, 2, 3]) - # Different formats: - c = array.array('l', [1, 2, 3]) + # NaNs + nd = ndarray([(0, 0)], shape=[1], format='l x d x', flags=ND_WRITABLE) + nd[0] = (-1, float('nan')) + self.assertNotEqual(memoryview(nd), nd) + + # Depends on issue #15625: the struct module does not understand 'u'. + a = array.array('u', 'xyz') v = memoryview(a) - self.assertNotEqual(v, c) - self.assertNotEqual(c, v) - - # Not implemented formats. Ugly, but inevitable. This is the same as - # issue #2531: equality is also used for membership testing and must - # return a result. - a = ndarray([(1, 1.5), (2, 2.7)], shape=[2], format='ld') - v = memoryview(a) + self.assertNotEqual(a, v) self.assertNotEqual(v, a) - self.assertNotEqual(a, v) - - a = ndarray([b'12345'], shape=[1], format="s") - v = memoryview(a) - self.assertNotEqual(v, a) - self.assertNotEqual(a, v) - - nd = ndarray([(1,1,1), (2,2,2), (3,3,3)], shape=[3], format='iii') - v = memoryview(nd) - self.assertNotEqual(v, nd) - self.assertNotEqual(nd, v) - - # '@' prefix can be dropped: - nd1 = ndarray([1,2,3], shape=[3], format='@i') - nd2 = ndarray([1,2,3], shape=[3], format='i') - v = memoryview(nd1) - w = memoryview(nd2) - self.assertEqual(v, w) - self.assertEqual(w, v) - self.assertEqual(v, nd2) - self.assertEqual(nd2, v) - self.assertEqual(w, nd1) - self.assertEqual(nd1, w) - - # ndim = 0 + + # Some ctypes format strings are unknown to the struct module. + if ctypes: + # format: "T{>l:x:>l:y:}" + class BEPoint(ctypes.BigEndianStructure): + _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)] + point = BEPoint(100, 200) + a = memoryview(point) + b = memoryview(point) + self.assertNotEqual(a, b) + self.assertNotEqual(a, point) + self.assertNotEqual(point, a) + self.assertRaises(NotImplementedError, a.tolist) + + def test_memoryview_compare_ndim_zero(self): + nd1 = ndarray(1729, shape=[], format='@L') nd2 = ndarray(1729, shape=[], format='L', flags=ND_WRITABLE) v = memoryview(nd1) @@ -3124,7 +3122,37 @@ m[9] = 100 self.assertNotEqual(m, nd) - # ndim = 1: contiguous + # struct module: equal + nd1 = ndarray((1729, 1.2, b'12345'), shape=[], format='Lf5s') + nd2 = ndarray((1729, 1.2, b'12345'), shape=[], format='hf5s', + flags=ND_WRITABLE) + v = memoryview(nd1) + w = memoryview(nd2) + self.assertEqual(v, w) + self.assertEqual(w, v) + self.assertEqual(v, nd2) + self.assertEqual(nd2, v) + self.assertEqual(w, nd1) + self.assertEqual(nd1, w) + + # struct module: not equal + nd1 = ndarray((1729, 1.2, b'12345'), shape=[], format='Lf5s') + nd2 = ndarray((-1729, 1.2, b'12345'), shape=[], format='hf5s', + flags=ND_WRITABLE) + v = memoryview(nd1) + w = memoryview(nd2) + self.assertNotEqual(v, w) + self.assertNotEqual(w, v) + self.assertNotEqual(v, nd2) + self.assertNotEqual(nd2, v) + self.assertNotEqual(w, nd1) + self.assertNotEqual(nd1, w) + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + + def test_memoryview_compare_ndim_one(self): + + # contiguous nd1 = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h') nd2 = ndarray([-529, 576, -625, 676, 729], shape=[5], format='@h') v = memoryview(nd1) @@ -3136,7 +3164,19 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - # ndim = 1: non-contiguous + # contiguous, struct module + nd1 = ndarray([-529, 576, -625, 676, -729], shape=[5], format=' 1: C-contiguous - # different values + # random formats + n = 10 + for _ in range(100): + fmt, items, singleitem = randitems(n) + for flags in (0, ND_PIL): + nd = ndarray(items, shape=[n], format=fmt, flags=flags) + m = memoryview(nd) + self.assertEqual(m, nd) + + nd = nd[::-3] + m = memoryview(nd) + self.assertEqual(m, nd) + + def test_memoryview_compare_multidim_c(self): + + # C-contiguous, different values nd1 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='@h') nd2 = ndarray(list(range(0, 30)), shape=[3, 2, 5], format='@h') v = memoryview(nd1) @@ -3208,9 +3316,9 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - # different shape - nd1 = ndarray(list(range(30)), shape=[2, 3, 5], format='L') - nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='L') + # C-contiguous, different values, struct module + nd1 = ndarray([(0, 1, 2)]*30, shape=[3, 2, 5], format='=f q xxL') + nd2 = ndarray([(-1.2, 1, 2)]*30, shape=[3, 2, 5], format='< f 2Q') v = memoryview(nd1) w = memoryview(nd2) @@ -3220,9 +3328,9 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - # different format + # C-contiguous, different shape nd1 = ndarray(list(range(30)), shape=[2, 3, 5], format='L') - nd2 = ndarray(list(range(30)), shape=[2, 3, 5], format='l') + nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='L') v = memoryview(nd1) w = memoryview(nd2) @@ -3232,8 +3340,33 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - ##### ndim > 1: Fortran contiguous - # different values + # C-contiguous, different shape, struct module + nd1 = ndarray([(0, 1, 2)]*21, shape=[3, 7], format='! b B xL') + nd2 = ndarray([(0, 1, 2)]*21, shape=[7, 3], format='= Qx l xxL') + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertNotEqual(v, nd2) + self.assertNotEqual(w, nd1) + self.assertNotEqual(v, w) + + # C-contiguous, different format, struct module + nd1 = ndarray(list(range(30)), shape=[2, 3, 5], format='L') + nd2 = ndarray(list(range(30)), shape=[2, 3, 5], format='l') + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertEqual(v, nd2) + self.assertEqual(w, nd1) + self.assertEqual(v, w) + + def test_memoryview_compare_multidim_fortran(self): + + # Fortran-contiguous, different values nd1 = ndarray(list(range(-15, 15)), shape=[5, 2, 3], format='@h', flags=ND_FORTRAN) nd2 = ndarray(list(range(0, 30)), shape=[5, 2, 3], format='@h', @@ -3247,7 +3380,21 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - # different shape + # Fortran-contiguous, different values, struct module + nd1 = ndarray([(2**64-1, -1)]*6, shape=[2, 3], format='=Qq', + flags=ND_FORTRAN) + nd2 = ndarray([(-1, 2**64-1)]*6, shape=[2, 3], format='=qQ', + flags=ND_FORTRAN) + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertNotEqual(v, nd2) + self.assertNotEqual(w, nd1) + self.assertNotEqual(v, w) + + # Fortran-contiguous, different shape nd1 = ndarray(list(range(-15, 15)), shape=[2, 3, 5], format='l', flags=ND_FORTRAN) nd2 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='l', @@ -3261,7 +3408,21 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - # different format + # Fortran-contiguous, different shape, struct module + nd1 = ndarray(list(range(-15, 15)), shape=[2, 3, 5], format='0ll', + flags=ND_FORTRAN) + nd2 = ndarray(list(range(-15, 15)), shape=[3, 2, 5], format='l', + flags=ND_FORTRAN) + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertNotEqual(v, nd2) + self.assertNotEqual(w, nd1) + self.assertNotEqual(v, w) + + # Fortran-contiguous, different format, struct module nd1 = ndarray(list(range(30)), shape=[5, 2, 3], format='@h', flags=ND_FORTRAN) nd2 = ndarray(list(range(30)), shape=[5, 2, 3], format='@b', @@ -3271,11 +3432,13 @@ self.assertEqual(v, nd1) self.assertEqual(w, nd2) - self.assertNotEqual(v, nd2) - self.assertNotEqual(w, nd1) - self.assertNotEqual(v, w) - - ##### ndim > 1: mixed C/Fortran contiguous + self.assertEqual(v, nd2) + self.assertEqual(w, nd1) + self.assertEqual(v, w) + + def test_memoryview_compare_multidim_mixed(self): + + # mixed C/Fortran contiguous lst1 = list(range(-15, 15)) lst2 = transpose(lst1, [3, 2, 5]) nd1 = ndarray(lst1, shape=[3, 2, 5], format='@l') @@ -3287,8 +3450,20 @@ self.assertEqual(w, nd2) self.assertEqual(v, w) - ##### ndim > 1: non-contiguous - # different values + # mixed C/Fortran contiguous, struct module + lst1 = [(-3.3, -22, b'x')]*30 + lst1[5] = (-2.2, -22, b'x') + lst2 = transpose(lst1, [3, 2, 5]) + nd1 = ndarray(lst1, shape=[3, 2, 5], format='d b c') + nd2 = ndarray(lst2, shape=[3, 2, 5], format='d h c', flags=ND_FORTRAN) + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertEqual(v, w) + + # different values, non-contiguous ex1 = ndarray(list(range(40)), shape=[5, 8], format='@I') nd1 = ex1[3:1:-1, ::-2] ex2 = ndarray(list(range(40)), shape=[5, 8], format='I') @@ -3302,6 +3477,20 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) + # same values, non-contiguous, struct module + ex1 = ndarray([(2**31-1, -2**31)]*22, shape=[11, 2], format='=ii') + nd1 = ex1[3:1:-1, ::-2] + ex2 = ndarray([(2**31-1, -2**31)]*22, shape=[11, 2], format='>ii') + nd2 = ex2[1:3:1, ::-2] + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertEqual(v, nd2) + self.assertEqual(w, nd1) + self.assertEqual(v, w) + # different shape ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='b') nd1 = ex1[1:3:, ::-2] @@ -3316,10 +3505,10 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - # different format - ex1 = ndarray(list(range(30)), shape=[5, 3, 2], format='i') + # different shape, struct module + ex1 = ndarray(list(range(30)), shape=[2, 3, 5], format='B') nd1 = ex1[1:3:, ::-2] - nd2 = ndarray(list(range(30)), shape=[5, 3, 2], format='@I') + nd2 = ndarray(list(range(30)), shape=[3, 2, 5], format='b') nd2 = ex2[1:3:, ::-2] v = memoryview(nd1) w = memoryview(nd2) @@ -3330,9 +3519,11 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - ##### ndim > 1: zeros in shape - nd1 = ndarray(list(range(30)), shape=[0, 3, 2], format='i') - nd2 = ndarray(list(range(30)), shape=[5, 0, 2], format='@i') + # different format, struct module + ex1 = ndarray([(2, b'123')]*30, shape=[5, 3, 2], format='b3s') + nd1 = ex1[1:3:, ::-2] + nd2 = ndarray([(2, b'123')]*30, shape=[5, 3, 2], format='i3s') + nd2 = ex2[1:3:, ::-2] v = memoryview(nd1) w = memoryview(nd2) @@ -3342,7 +3533,35 @@ self.assertNotEqual(w, nd1) self.assertNotEqual(v, w) - # ndim > 1: zero strides + def test_memoryview_compare_multidim_zero_shape(self): + + # zeros in shape + nd1 = ndarray(list(range(30)), shape=[0, 3, 2], format='i') + nd2 = ndarray(list(range(30)), shape=[5, 0, 2], format='@i') + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertNotEqual(v, nd2) + self.assertNotEqual(w, nd1) + self.assertNotEqual(v, w) + + # zeros in shape, struct module + nd1 = ndarray(list(range(30)), shape=[0, 3, 2], format='i') + nd2 = ndarray(list(range(30)), shape=[5, 0, 2], format='@i') + v = memoryview(nd1) + w = memoryview(nd2) + + self.assertEqual(v, nd1) + self.assertEqual(w, nd2) + self.assertNotEqual(v, nd2) + self.assertNotEqual(w, nd1) + self.assertNotEqual(v, w) + + def test_memoryview_compare_multidim_zero_strides(self): + + # zero strides nd1 = ndarray([900]*80, shape=[4, 5, 4], format='@L') nd2 = ndarray([900], shape=[4, 5, 4], strides=[0, 0, 0], format='L') v = memoryview(nd1) @@ -3355,7 +3574,21 @@ self.assertEqual(v, w) self.assertEqual(v.tolist(), w.tolist()) - ##### ndim > 1: suboffsets + # zero strides, struct module + nd1 = ndarray([(1, 2)]*10, shape=[2, 5], format='=lQ') + nd2 = ndarray([(1, 2)], shape=[2, 5], strides=[0, 0], format='', '!']: + x = ndarray([2**63]*120, shape=[3,5,2,2,2], format=byteorder+'Q') + y = ndarray([2**63]*120, shape=[3,5,2,2,2], format=byteorder+'Q', + flags=ND_WRITABLE|ND_FORTRAN) + y[2][3][1][1][1] = 1 + a = memoryview(x) + b = memoryview(y) + self.assertEqual(a, x) + self.assertEqual(b, y) + self.assertNotEqual(a, b) + self.assertNotEqual(a, y) + self.assertNotEqual(b, x) + + x = ndarray([(2**63, 2**31, 2**15)]*120, shape=[3,5,2,2,2], + format=byteorder+'QLH') + y = ndarray([(2**63, 2**31, 2**15)]*120, shape=[3,5,2,2,2], + format=byteorder+'QLH', flags=ND_WRITABLE|ND_FORTRAN) + y[2][3][1][1][1] = (1, 1, 1) + a = memoryview(x) + b = memoryview(y) + self.assertEqual(a, x) + self.assertEqual(b, y) + self.assertNotEqual(a, b) + self.assertNotEqual(a, y) + self.assertNotEqual(b, x) + def test_memoryview_check_released(self): a = array.array('d', [1.1, 2.2, 3.3]) @@ -3452,11 +3787,38 @@ def test_memoryview_tobytes(self): # Many implicit tests are already in self.verify(). - nd = ndarray([-529, 576, -625, 676, -729], shape=[5], format='@h') - + t = (-529, 576, -625, 676, -729) + + nd = ndarray(t, shape=[5], format='@h') m = memoryview(nd) + self.assertEqual(m, nd) self.assertEqual(m.tobytes(), nd.tobytes()) + nd = ndarray([t], shape=[1], format='>hQiLl') + m = memoryview(nd) + self.assertEqual(m, nd) + self.assertEqual(m.tobytes(), nd.tobytes()) + + nd = ndarray([t for _ in range(12)], shape=[2,2,3], format='=hQiLl') + m = memoryview(nd) + self.assertEqual(m, nd) + self.assertEqual(m.tobytes(), nd.tobytes()) + + nd = ndarray([t for _ in range(120)], shape=[5,2,2,3,2], + format='l:x:>l:y:}" + class BEPoint(ctypes.BigEndianStructure): + _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)] + point = BEPoint(100, 200) + a = memoryview(point) + self.assertEqual(a.tobytes(), bytes(point)) + def test_memoryview_get_contiguous(self): # Many implicit tests are already in self.verify(). diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15573: memoryview comparisons are now performed by value with full + support for any valid struct module format definition. + - Issue #15316: When an item in the fromlist for __import__ doesn't exist, don't raise an error, but if an exception is raised as part of an import do let that propagate. diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -246,7 +246,7 @@ (view->suboffsets && view->suboffsets[dest->ndim-1] >= 0) Py_LOCAL_INLINE(int) -last_dim_is_contiguous(Py_buffer *dest, Py_buffer *src) +last_dim_is_contiguous(const Py_buffer *dest, const Py_buffer *src) { assert(dest->ndim > 0 && src->ndim > 0); return (!HAVE_SUBOFFSETS_IN_LAST_DIM(dest) && @@ -255,37 +255,63 @@ src->strides[src->ndim-1] == src->itemsize); } +/* This is not a general function for determining format equivalence. + It is used in copy_single() and copy_buffer() to weed out non-matching + formats. Skipping the '@' character is specifically used in slice + assignments, where the lvalue is already known to have a single character + format. This is a performance hack that could be rewritten (if properly + benchmarked). */ +Py_LOCAL_INLINE(int) +equiv_format(const Py_buffer *dest, const Py_buffer *src) +{ + const char *dfmt, *sfmt; + + assert(dest->format && src->format); + dfmt = dest->format[0] == '@' ? dest->format+1 : dest->format; + sfmt = src->format[0] == '@' ? src->format+1 : src->format; + + if (strcmp(dfmt, sfmt) != 0 || + dest->itemsize != src->itemsize) { + return 0; + } + + return 1; +} + +/* Two shapes are equivalent if they are either equal or identical up + to a zero element at the same position. For example, in NumPy arrays + the shapes [1, 0, 5] and [1, 0, 7] are equivalent. */ +Py_LOCAL_INLINE(int) +equiv_shape(const Py_buffer *dest, const Py_buffer *src) +{ + int i; + + if (dest->ndim != src->ndim) + return 0; + + for (i = 0; i < dest->ndim; i++) { + if (dest->shape[i] != src->shape[i]) + return 0; + if (dest->shape[i] == 0) + break; + } + + return 1; +} + /* Check that the logical structure of the destination and source buffers is identical. */ static int -cmp_structure(Py_buffer *dest, Py_buffer *src) +equiv_structure(const Py_buffer *dest, const Py_buffer *src) { - const char *dfmt, *sfmt; - int i; - - assert(dest->format && src->format); - dfmt = dest->format[0] == '@' ? dest->format+1 : dest->format; - sfmt = src->format[0] == '@' ? src->format+1 : src->format; - - if (strcmp(dfmt, sfmt) != 0 || - dest->itemsize != src->itemsize || - dest->ndim != src->ndim) { - goto value_error; + if (!equiv_format(dest, src) || + !equiv_shape(dest, src)) { + PyErr_SetString(PyExc_ValueError, + "ndarray assignment: lvalue and rvalue have different structures"); + return 0; } - for (i = 0; i < dest->ndim; i++) { - if (dest->shape[i] != src->shape[i]) - goto value_error; - if (dest->shape[i] == 0) - break; - } - - return 0; - -value_error: - PyErr_SetString(PyExc_ValueError, - "ndarray assignment: lvalue and rvalue have different structures"); - return -1; + return 1; } /* Base case for recursive multi-dimensional copying. Contiguous arrays are @@ -358,7 +384,7 @@ assert(dest->ndim == 1); - if (cmp_structure(dest, src) < 0) + if (!equiv_structure(dest, src)) return -1; if (!last_dim_is_contiguous(dest, src)) { @@ -390,7 +416,7 @@ assert(dest->ndim > 0); - if (cmp_structure(dest, src) < 0) + if (!equiv_structure(dest, src)) return -1; if (!last_dim_is_contiguous(dest, src)) { @@ -1828,6 +1854,131 @@ /****************************************************************************/ +/* unpack using the struct module */ +/****************************************************************************/ + +/* For reasonable performance it is necessary to cache all objects required + for unpacking. An unpacker can handle the format passed to unpack_from(). + Invariant: All pointer fields of the struct should either be NULL or valid + pointers. */ +struct unpacker { + PyObject *unpack_from; /* Struct.unpack_from(format) */ + PyObject *mview; /* cached memoryview */ + char *item; /* buffer for mview */ + Py_ssize_t itemsize; /* len(item) */ +}; + +static struct unpacker * +unpacker_new(void) +{ + struct unpacker *x = PyMem_Malloc(sizeof *x); + + if (x == NULL) { + PyErr_NoMemory(); + return NULL; + } + + x->unpack_from = NULL; + x->mview = NULL; + x->item = NULL; + x->itemsize = 0; + + return x; +} + +static void +unpacker_free(struct unpacker *x) +{ + if (x) { + Py_XDECREF(x->unpack_from); + Py_XDECREF(x->mview); + PyMem_Free(x->item); + PyMem_Free(x); + } +} + +/* Return a new unpacker for the given format. */ +static struct unpacker * +struct_get_unpacker(const char *fmt, Py_ssize_t itemsize) +{ + PyObject *structmodule; /* XXX cache these two */ + PyObject *Struct = NULL; /* XXX in globals? */ + PyObject *structobj = NULL; + PyObject *format = NULL; + struct unpacker *x = NULL; + + structmodule = PyImport_ImportModule("struct"); + if (structmodule == NULL) + return NULL; + + Struct = PyObject_GetAttrString(structmodule, "Struct"); + Py_DECREF(structmodule); + if (Struct == NULL) + return NULL; + + x = unpacker_new(); + if (x == NULL) + goto error; + + format = PyBytes_FromString(fmt); + if (format == NULL) + goto error; + + structobj = PyObject_CallFunctionObjArgs(Struct, format, NULL); + if (structobj == NULL) + goto error; + + x->unpack_from = PyObject_GetAttrString(structobj, "unpack_from"); + if (x->unpack_from == NULL) + goto error; + + x->item = PyMem_Malloc(itemsize); + if (x->item == NULL) { + PyErr_NoMemory(); + goto error; + } + x->itemsize = itemsize; + + x->mview = PyMemoryView_FromMemory(x->item, itemsize, PyBUF_WRITE); + if (x->mview == NULL) + goto error; + + +out: + Py_XDECREF(Struct); + Py_XDECREF(format); + Py_XDECREF(structobj); + return x; + +error: + unpacker_free(x); + x = NULL; + goto out; +} + +/* unpack a single item */ +static PyObject * +struct_unpack_single(const char *ptr, struct unpacker *x) +{ + PyObject *v; + + memcpy(x->item, ptr, x->itemsize); + v = PyObject_CallFunctionObjArgs(x->unpack_from, x->mview, NULL); + if (v == NULL) + return NULL; + + if (PyTuple_GET_SIZE(v) == 1) { + PyObject *tmp = PyTuple_GET_ITEM(v, 0); + Py_INCREF(tmp); + Py_DECREF(v); + return tmp; + } + + return v; +} + + +/****************************************************************************/ /* Representations */ /****************************************************************************/ @@ -2261,6 +2412,58 @@ /* Comparisons */ /**************************************************************************/ +#define MV_COMPARE_EX -1 /* exception */ +#define MV_COMPARE_NOT_IMPL -2 /* not implemented */ + +/* Translate a StructError to "not equal". Preserve other exceptions. */ +static int +fix_struct_error_int(void) +{ + assert(PyErr_Occurred()); + /* XXX Cannot get at StructError directly? */ + if (PyErr_ExceptionMatches(PyExc_ImportError) || + PyErr_ExceptionMatches(PyExc_MemoryError)) { + return MV_COMPARE_EX; + } + /* StructError: invalid or unknown format -> not equal */ + PyErr_Clear(); + return 0; +} + +/* Unpack and compare single items of p and q using the struct module. */ +static int +struct_unpack_cmp(const char *p, const char *q, + struct unpacker *unpack_p, struct unpacker *unpack_q) +{ + PyObject *v, *w; + int ret; + + /* At this point any exception from the struct module should not be + StructError, since both formats have been accepted already. */ + v = struct_unpack_single(p, unpack_p); + if (v == NULL) + return MV_COMPARE_EX; + + w = struct_unpack_single(q, unpack_q); + if (w == NULL) { + Py_DECREF(v); + return MV_COMPARE_EX; + } + + /* MV_COMPARE_EX == -1: exceptions are preserved */ + ret = PyObject_RichCompareBool(v, w, Py_EQ); + Py_DECREF(v); + Py_DECREF(w); + + return ret; +} + +/* Unpack and compare single items of p and q. If both p and q have the same + single element native format, the comparison uses a fast path (gcc creates + a jump table and converts memcpy into simple assignments on x86/x64). + + Otherwise, the comparison is delegated to the struct module, which is + 30-60x slower. */ #define CMP_SINGLE(p, q, type) \ do { \ type x; \ @@ -2271,11 +2474,12 @@ } while (0) Py_LOCAL_INLINE(int) -unpack_cmp(const char *p, const char *q, const char *fmt) +unpack_cmp(const char *p, const char *q, char fmt, + struct unpacker *unpack_p, struct unpacker *unpack_q) { int equal; - switch (fmt[0]) { + switch (fmt) { /* signed integers and fast path for 'B' */ case 'B': return *((unsigned char *)p) == *((unsigned char *)q); @@ -2317,9 +2521,17 @@ /* pointer */ case 'P': CMP_SINGLE(p, q, void *); return equal; - /* Py_NotImplemented */ - default: return -1; + /* use the struct module */ + case '_': + assert(unpack_p); + assert(unpack_q); + return struct_unpack_cmp(p, q, unpack_p, unpack_q); } + + /* NOT REACHED */ + PyErr_SetString(PyExc_RuntimeError, + "memoryview: internal error in richcompare"); + return MV_COMPARE_EX; } /* Base case for recursive array comparisons. Assumption: ndim == 1. */ @@ -2327,7 +2539,7 @@ cmp_base(const char *p, const char *q, const Py_ssize_t *shape, const Py_ssize_t *pstrides, const Py_ssize_t *psuboffsets, const Py_ssize_t *qstrides, const Py_ssize_t *qsuboffsets, - const char *fmt) + char fmt, struct unpacker *unpack_p, struct unpacker *unpack_q) { Py_ssize_t i; int equal; @@ -2335,7 +2547,7 @@ for (i = 0; i < shape[0]; p+=pstrides[0], q+=qstrides[0], i++) { const char *xp = ADJUST_PTR(p, psuboffsets); const char *xq = ADJUST_PTR(q, qsuboffsets); - equal = unpack_cmp(xp, xq, fmt); + equal = unpack_cmp(xp, xq, fmt, unpack_p, unpack_q); if (equal <= 0) return equal; } @@ -2350,7 +2562,7 @@ Py_ssize_t ndim, const Py_ssize_t *shape, const Py_ssize_t *pstrides, const Py_ssize_t *psuboffsets, const Py_ssize_t *qstrides, const Py_ssize_t *qsuboffsets, - const char *fmt) + char fmt, struct unpacker *unpack_p, struct unpacker *unpack_q) { Py_ssize_t i; int equal; @@ -2364,7 +2576,7 @@ return cmp_base(p, q, shape, pstrides, psuboffsets, qstrides, qsuboffsets, - fmt); + fmt, unpack_p, unpack_q); } for (i = 0; i < shape[0]; p+=pstrides[0], q+=qstrides[0], i++) { @@ -2373,7 +2585,7 @@ equal = cmp_rec(xp, xq, ndim-1, shape+1, pstrides+1, psuboffsets ? psuboffsets+1 : NULL, qstrides+1, qsuboffsets ? qsuboffsets+1 : NULL, - fmt); + fmt, unpack_p, unpack_q); if (equal <= 0) return equal; } @@ -2385,9 +2597,12 @@ memory_richcompare(PyObject *v, PyObject *w, int op) { PyObject *res; - Py_buffer wbuf, *vv, *ww = NULL; - const char *vfmt, *wfmt; - int equal = -1; /* Py_NotImplemented */ + Py_buffer wbuf, *vv; + Py_buffer *ww = NULL; + struct unpacker *unpack_v = NULL; + struct unpacker *unpack_w = NULL; + char vfmt, wfmt; + int equal = MV_COMPARE_NOT_IMPL; if (op != Py_EQ && op != Py_NE) goto result; /* Py_NotImplemented */ @@ -2414,38 +2629,59 @@ ww = &wbuf; } - vfmt = adjust_fmt(vv); - wfmt = adjust_fmt(ww); - if (vfmt == NULL || wfmt == NULL) { - PyErr_Clear(); - goto result; /* Py_NotImplemented */ - } - - if (cmp_structure(vv, ww) < 0) { + if (!equiv_shape(vv, ww)) { PyErr_Clear(); equal = 0; goto result; } + /* Use fast unpacking for identical primitive C type formats. */ + if (get_native_fmtchar(&vfmt, vv->format) < 0) + vfmt = '_'; + if (get_native_fmtchar(&wfmt, ww->format) < 0) + wfmt = '_'; + if (vfmt == '_' || wfmt == '_' || vfmt != wfmt) { + /* Use struct module unpacking. NOTE: Even for equal format strings, + memcmp() cannot be used for item comparison since it would give + incorrect results in the case of NaNs or uninitialized padding + bytes. */ + vfmt = '_'; + unpack_v = struct_get_unpacker(vv->format, vv->itemsize); + if (unpack_v == NULL) { + equal = fix_struct_error_int(); + goto result; + } + unpack_w = struct_get_unpacker(ww->format, ww->itemsize); + if (unpack_w == NULL) { + equal = fix_struct_error_int(); + goto result; + } + } + if (vv->ndim == 0) { - equal = unpack_cmp(vv->buf, ww->buf, vfmt); + equal = unpack_cmp(vv->buf, ww->buf, + vfmt, unpack_v, unpack_w); } else if (vv->ndim == 1) { equal = cmp_base(vv->buf, ww->buf, vv->shape, vv->strides, vv->suboffsets, ww->strides, ww->suboffsets, - vfmt); + vfmt, unpack_v, unpack_w); } else { equal = cmp_rec(vv->buf, ww->buf, vv->ndim, vv->shape, vv->strides, vv->suboffsets, ww->strides, ww->suboffsets, - vfmt); + vfmt, unpack_v, unpack_w); } result: - if (equal < 0) - res = Py_NotImplemented; + if (equal < 0) { + if (equal == MV_COMPARE_NOT_IMPL) + res = Py_NotImplemented; + else /* exception */ + res = NULL; + } else if ((equal && op == Py_EQ) || (!equal && op == Py_NE)) res = Py_True; else @@ -2453,7 +2689,11 @@ if (ww == &wbuf) PyBuffer_Release(ww); - Py_INCREF(res); + + unpacker_free(unpack_v); + unpacker_free(unpack_w); + + Py_XINCREF(res); return res; } -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 10:12:54 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 10:12:54 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_wrong_way_?= =?utf-8?q?of_adding_Error_information_in_shutil=2Ecopytree=2E?= Message-ID: <3X3sYL5sStzQNK@mail.python.org> http://hg.python.org/cpython/rev/a2bf95458eed changeset: 78761:a2bf95458eed branch: 3.2 parent: 78756:121cb9596e7d user: Georg Brandl date: Sat Aug 25 10:11:57 2012 +0200 summary: Fix wrong way of adding Error information in shutil.copytree. files: Lib/shutil.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -236,7 +236,7 @@ # Copying file access times may fail on Windows pass else: - errors.extend((src, dst, str(why))) + errors.append((src, dst, str(why))) if errors: raise Error(errors) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 10:12:56 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 10:12:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_merge_with_3=2E2?= Message-ID: <3X3sYN4c4zzQNT@mail.python.org> http://hg.python.org/cpython/rev/016087c46600 changeset: 78762:016087c46600 parent: 78760:afa3dedfee18 parent: 78761:a2bf95458eed user: Georg Brandl date: Sat Aug 25 10:12:47 2012 +0200 summary: merge with 3.2 files: Lib/shutil.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -332,7 +332,7 @@ # Copying file access times may fail on Windows pass else: - errors.extend((src, dst, str(why))) + errors.append((src, dst, str(why))) if errors: raise Error(errors) return dst -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 10:14:08 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 10:14:08 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_wrong_way_?= =?utf-8?q?of_adding_Error_information_in_shutil=2Ecopytree=2E?= Message-ID: <3X3sZm22T4zQPF@mail.python.org> http://hg.python.org/cpython/rev/fe3d113e139d changeset: 78763:fe3d113e139d branch: 2.7 parent: 78755:31a7ff299698 user: Georg Brandl date: Sat Aug 25 10:11:57 2012 +0200 summary: Fix wrong way of adding Error information in shutil.copytree. files: Lib/shutil.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/shutil.py b/Lib/shutil.py --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -203,7 +203,7 @@ # Copying file access times may fail on Windows pass else: - errors.extend((src, dst, str(why))) + errors.append((src, dst, str(why))) if errors: raise Error, errors -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 11:24:33 2012 From: python-checkins at python.org (ronald.oussoren) Date: Sat, 25 Aug 2012 11:24:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Fix_issue_1337?= =?utf-8?q?0=3A_Ensure_that_ctypes_works_on_Mac_OS_X_when_Python_is_compil?= =?utf-8?q?ed?= Message-ID: <3X3v811DxbzQKH@mail.python.org> http://hg.python.org/cpython/rev/58a87c02692c changeset: 78764:58a87c02692c branch: 2.7 user: Ronald Oussoren date: Sat Aug 25 11:18:48 2012 +0200 summary: Fix issue 13370: Ensure that ctypes works on Mac OS X when Python is compiled using the clang compiler files: Misc/NEWS | 3 + Modules/_ctypes/libffi_osx/x86/darwin64.S | 6 +- Modules/_ctypes/libffi_osx/x86/x86-darwin.S | 4 + Modules/_ctypes/libffi_osx/x86/x86-ffi64.c | 118 +++++++++- Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c | 4 +- 5 files changed, 128 insertions(+), 7 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -95,6 +95,9 @@ Library ------- +- Issue #13370: Ensure that ctypes works on Mac OS X when Python is + compiled using the clang compiler + - Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. - Issue #15199: Fix JavaScript's default MIME type to application/javascript. diff --git a/Modules/_ctypes/libffi_osx/x86/darwin64.S b/Modules/_ctypes/libffi_osx/x86/darwin64.S --- a/Modules/_ctypes/libffi_osx/x86/darwin64.S +++ b/Modules/_ctypes/libffi_osx/x86/darwin64.S @@ -45,6 +45,7 @@ _ffi_call_unix64: LUW0: movq (%rsp), %r10 /* Load return address. */ + movq %rdi, %r12 /* Save a copy of the register area. */ leaq (%rdi, %rsi), %rax /* Find local stack base. */ movq %rdx, (%rax) /* Save flags. */ movq %rcx, 8(%rax) /* Save raddr. */ @@ -52,7 +53,8 @@ movq %r10, 24(%rax) /* Relocate return address. */ movq %rax, %rbp /* Finalize local stack frame. */ LUW1: - movq %rdi, %r10 /* Save a copy of the register area. */ + /* movq %rdi, %r10 // Save a copy of the register area. */ + movq %r12, %r10 movq %r8, %r11 /* Save a copy of the target fn. */ movl %r9d, %eax /* Set number of SSE registers. */ @@ -255,7 +257,7 @@ ret .align 3 Lld_int8: - movzbl -24(%rsp), %eax + movzbl -24(%rsp), %eax ret .align 3 Lld_int16: diff --git a/Modules/_ctypes/libffi_osx/x86/x86-darwin.S b/Modules/_ctypes/libffi_osx/x86/x86-darwin.S --- a/Modules/_ctypes/libffi_osx/x86/x86-darwin.S +++ b/Modules/_ctypes/libffi_osx/x86/x86-darwin.S @@ -198,8 +198,12 @@ je Lcls_retldouble cmpl $FFI_TYPE_SINT64, %eax je Lcls_retllong + cmpl $FFI_TYPE_UINT8, %eax + je Lcls_retstruct1 cmpl $FFI_TYPE_SINT8, %eax je Lcls_retstruct1 + cmpl $FFI_TYPE_UINT16, %eax + je Lcls_retstruct2 cmpl $FFI_TYPE_SINT16, %eax je Lcls_retstruct2 cmpl $FFI_TYPE_STRUCT, %eax diff --git a/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c b/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c --- a/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c +++ b/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c @@ -152,12 +152,42 @@ case FFI_TYPE_UINT64: case FFI_TYPE_SINT64: case FFI_TYPE_POINTER: +#if 0 if (byte_offset + type->size <= 4) classes[0] = X86_64_INTEGERSI_CLASS; else classes[0] = X86_64_INTEGER_CLASS; return 1; +#else + { + int size = byte_offset + type->size; + + if (size <= 4) + { + classes[0] = X86_64_INTEGERSI_CLASS; + return 1; + } + else if (size <= 8) + { + classes[0] = X86_64_INTEGER_CLASS; + return 1; + } + else if (size <= 12) + { + classes[0] = X86_64_INTEGER_CLASS; + classes[1] = X86_64_INTEGERSI_CLASS; + return 2; + } + else if (size <= 16) + { + classes[0] = classes[1] = X86_64_INTEGERSI_CLASS; + return 2; + } + else + FFI_ASSERT (0); + } +#endif case FFI_TYPE_FLOAT: if (byte_offset == 0) @@ -213,6 +243,21 @@ byte_offset += (*ptr)->size; } + if (words > 2) + { + /* When size > 16 bytes, if the first one isn't + X86_64_SSE_CLASS or any other ones aren't + X86_64_SSEUP_CLASS, everything should be passed in + memory. */ + if (classes[0] != X86_64_SSE_CLASS) + return 0; + + for (i = 1; i < words; i++) + if (classes[i] != X86_64_SSEUP_CLASS) + return 0; + } + + /* Final merger cleanup. */ for (i = 0; i < words; i++) { @@ -224,13 +269,20 @@ /* The X86_64_SSEUP_CLASS should be always preceded by X86_64_SSE_CLASS. */ if (classes[i] == X86_64_SSEUP_CLASS - && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS)) + && classes[i - 1] != X86_64_SSE_CLASS + && classes[i - 1] != X86_64_SSEUP_CLASS) + { + FFI_ASSERT(i != 0); classes[i] = X86_64_SSE_CLASS; + } /* X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS. */ if (classes[i] == X86_64_X87UP_CLASS - && (i == 0 || classes[i - 1] != X86_64_X87_CLASS)) + && classes[i - 1] != X86_64_X87_CLASS) + { + FFI_ASSERT(i != 0); classes[i] = X86_64_SSE_CLASS; + } } return words; @@ -369,6 +421,7 @@ cif->flags = flags; cif->bytes = bytes; + cif->bytes = ALIGN(bytes,8); return FFI_OK; } @@ -449,7 +502,61 @@ case X86_64_INTEGER_CLASS: case X86_64_INTEGERSI_CLASS: reg_args->gpr[gprcount] = 0; - memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); + switch (arg_types[i]->type) { + case FFI_TYPE_SINT8: + { + int8_t shortval = *(int8_t*)a; + int64_t actval = (int64_t)shortval; + reg_args->gpr[gprcount] = actval; + /*memcpy (®_args->gpr[gprcount], &actval, 8);*/ + break; + } + + case FFI_TYPE_SINT16: + { + int16_t shortval = *(int16_t*)a; + int64_t actval = (int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_SINT32: + { + int32_t shortval = *(int32_t*)a; + int64_t actval = (int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_UINT8: + { + u_int8_t shortval = *(u_int8_t*)a; + u_int64_t actval = (u_int64_t)shortval; + /*memcpy (®_args->gpr[gprcount], &actval, 8);*/ + reg_args->gpr[gprcount] = actval; + break; + } + + case FFI_TYPE_UINT16: + { + u_int16_t shortval = *(u_int16_t*)a; + u_int64_t actval = (u_int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_UINT32: + { + u_int32_t shortval = *(u_int32_t*)a; + u_int64_t actval = (u_int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + default: + //memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); + reg_args->gpr[gprcount] = *(int64_t*)a; + } gprcount++; break; @@ -505,12 +612,15 @@ return FFI_OK; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" int ffi_closure_unix64_inner( ffi_closure* closure, void* rvalue, RegisterArgs* reg_args, char* argp) +#pragma clang diagnostic pop { ffi_cif* cif = closure->cif; void** avalue = alloca(cif->nargs * sizeof(void *)); @@ -621,4 +731,4 @@ return ret; } -#endif /* __x86_64__ */ \ No newline at end of file +#endif /* __x86_64__ */ diff --git a/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c b/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c --- a/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c +++ b/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c @@ -35,6 +35,8 @@ /* ffi_prep_args is called by the assembly routine once stack space has been allocated for the function's arguments */ +void ffi_prep_args(char *stack, extended_cif *ecif); + void ffi_prep_args(char *stack, extended_cif *ecif) { register unsigned int i; @@ -433,4 +435,4 @@ } #endif -#endif // __i386__ \ No newline at end of file +#endif // __i386__ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 11:24:34 2012 From: python-checkins at python.org (ronald.oussoren) Date: Sat, 25 Aug 2012 11:24:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_issue_1337?= =?utf-8?q?0=3A_Ensure_that_ctypes_works_on_Mac_OS_X_when_Python_is_compil?= =?utf-8?q?ed?= Message-ID: <3X3v826JWFzQLv@mail.python.org> http://hg.python.org/cpython/rev/a425f2697273 changeset: 78765:a425f2697273 branch: 3.2 parent: 78761:a2bf95458eed user: Ronald Oussoren date: Sat Aug 25 11:19:14 2012 +0200 summary: Fix issue 13370: Ensure that ctypes works on Mac OS X when Python is compiled using the clang compiler files: Misc/NEWS | 3 + Modules/_ctypes/libffi_osx/x86/darwin64.S | 6 +- Modules/_ctypes/libffi_osx/x86/x86-darwin.S | 4 + Modules/_ctypes/libffi_osx/x86/x86-ffi64.c | 118 +++++++++- Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c | 4 +- 5 files changed, 128 insertions(+), 7 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -109,6 +109,9 @@ Library ------- +- Issue #13370: Ensure that ctypes works on Mac OS X when Python is + compiled using the clang compiler + - Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. - Issue #15249: BytesGenerator now correctly mangles From lines (when diff --git a/Modules/_ctypes/libffi_osx/x86/darwin64.S b/Modules/_ctypes/libffi_osx/x86/darwin64.S --- a/Modules/_ctypes/libffi_osx/x86/darwin64.S +++ b/Modules/_ctypes/libffi_osx/x86/darwin64.S @@ -45,6 +45,7 @@ _ffi_call_unix64: LUW0: movq (%rsp), %r10 /* Load return address. */ + movq %rdi, %r12 /* Save a copy of the register area. */ leaq (%rdi, %rsi), %rax /* Find local stack base. */ movq %rdx, (%rax) /* Save flags. */ movq %rcx, 8(%rax) /* Save raddr. */ @@ -52,7 +53,8 @@ movq %r10, 24(%rax) /* Relocate return address. */ movq %rax, %rbp /* Finalize local stack frame. */ LUW1: - movq %rdi, %r10 /* Save a copy of the register area. */ + /* movq %rdi, %r10 // Save a copy of the register area. */ + movq %r12, %r10 movq %r8, %r11 /* Save a copy of the target fn. */ movl %r9d, %eax /* Set number of SSE registers. */ @@ -255,7 +257,7 @@ ret .align 3 Lld_int8: - movzbl -24(%rsp), %eax + movzbl -24(%rsp), %eax ret .align 3 Lld_int16: diff --git a/Modules/_ctypes/libffi_osx/x86/x86-darwin.S b/Modules/_ctypes/libffi_osx/x86/x86-darwin.S --- a/Modules/_ctypes/libffi_osx/x86/x86-darwin.S +++ b/Modules/_ctypes/libffi_osx/x86/x86-darwin.S @@ -198,8 +198,12 @@ je Lcls_retldouble cmpl $FFI_TYPE_SINT64, %eax je Lcls_retllong + cmpl $FFI_TYPE_UINT8, %eax + je Lcls_retstruct1 cmpl $FFI_TYPE_SINT8, %eax je Lcls_retstruct1 + cmpl $FFI_TYPE_UINT16, %eax + je Lcls_retstruct2 cmpl $FFI_TYPE_SINT16, %eax je Lcls_retstruct2 cmpl $FFI_TYPE_STRUCT, %eax diff --git a/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c b/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c --- a/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c +++ b/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c @@ -152,12 +152,42 @@ case FFI_TYPE_UINT64: case FFI_TYPE_SINT64: case FFI_TYPE_POINTER: +#if 0 if (byte_offset + type->size <= 4) classes[0] = X86_64_INTEGERSI_CLASS; else classes[0] = X86_64_INTEGER_CLASS; return 1; +#else + { + int size = byte_offset + type->size; + + if (size <= 4) + { + classes[0] = X86_64_INTEGERSI_CLASS; + return 1; + } + else if (size <= 8) + { + classes[0] = X86_64_INTEGER_CLASS; + return 1; + } + else if (size <= 12) + { + classes[0] = X86_64_INTEGER_CLASS; + classes[1] = X86_64_INTEGERSI_CLASS; + return 2; + } + else if (size <= 16) + { + classes[0] = classes[1] = X86_64_INTEGERSI_CLASS; + return 2; + } + else + FFI_ASSERT (0); + } +#endif case FFI_TYPE_FLOAT: if (byte_offset == 0) @@ -213,6 +243,21 @@ byte_offset += (*ptr)->size; } + if (words > 2) + { + /* When size > 16 bytes, if the first one isn't + X86_64_SSE_CLASS or any other ones aren't + X86_64_SSEUP_CLASS, everything should be passed in + memory. */ + if (classes[0] != X86_64_SSE_CLASS) + return 0; + + for (i = 1; i < words; i++) + if (classes[i] != X86_64_SSEUP_CLASS) + return 0; + } + + /* Final merger cleanup. */ for (i = 0; i < words; i++) { @@ -224,13 +269,20 @@ /* The X86_64_SSEUP_CLASS should be always preceded by X86_64_SSE_CLASS. */ if (classes[i] == X86_64_SSEUP_CLASS - && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS)) + && classes[i - 1] != X86_64_SSE_CLASS + && classes[i - 1] != X86_64_SSEUP_CLASS) + { + FFI_ASSERT(i != 0); classes[i] = X86_64_SSE_CLASS; + } /* X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS. */ if (classes[i] == X86_64_X87UP_CLASS - && (i == 0 || classes[i - 1] != X86_64_X87_CLASS)) + && classes[i - 1] != X86_64_X87_CLASS) + { + FFI_ASSERT(i != 0); classes[i] = X86_64_SSE_CLASS; + } } return words; @@ -369,6 +421,7 @@ cif->flags = flags; cif->bytes = bytes; + cif->bytes = ALIGN(bytes,8); return FFI_OK; } @@ -449,7 +502,61 @@ case X86_64_INTEGER_CLASS: case X86_64_INTEGERSI_CLASS: reg_args->gpr[gprcount] = 0; - memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); + switch (arg_types[i]->type) { + case FFI_TYPE_SINT8: + { + int8_t shortval = *(int8_t*)a; + int64_t actval = (int64_t)shortval; + reg_args->gpr[gprcount] = actval; + /*memcpy (®_args->gpr[gprcount], &actval, 8);*/ + break; + } + + case FFI_TYPE_SINT16: + { + int16_t shortval = *(int16_t*)a; + int64_t actval = (int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_SINT32: + { + int32_t shortval = *(int32_t*)a; + int64_t actval = (int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_UINT8: + { + u_int8_t shortval = *(u_int8_t*)a; + u_int64_t actval = (u_int64_t)shortval; + /*memcpy (®_args->gpr[gprcount], &actval, 8);*/ + reg_args->gpr[gprcount] = actval; + break; + } + + case FFI_TYPE_UINT16: + { + u_int16_t shortval = *(u_int16_t*)a; + u_int64_t actval = (u_int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_UINT32: + { + u_int32_t shortval = *(u_int32_t*)a; + u_int64_t actval = (u_int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + default: + //memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); + reg_args->gpr[gprcount] = *(int64_t*)a; + } gprcount++; break; @@ -505,12 +612,15 @@ return FFI_OK; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" int ffi_closure_unix64_inner( ffi_closure* closure, void* rvalue, RegisterArgs* reg_args, char* argp) +#pragma clang diagnostic pop { ffi_cif* cif = closure->cif; void** avalue = alloca(cif->nargs * sizeof(void *)); @@ -621,4 +731,4 @@ return ret; } -#endif /* __x86_64__ */ \ No newline at end of file +#endif /* __x86_64__ */ diff --git a/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c b/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c --- a/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c +++ b/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c @@ -35,6 +35,8 @@ /* ffi_prep_args is called by the assembly routine once stack space has been allocated for the function's arguments */ +void ffi_prep_args(char *stack, extended_cif *ecif); + void ffi_prep_args(char *stack, extended_cif *ecif) { register unsigned int i; @@ -433,4 +435,4 @@ } #endif -#endif // __i386__ \ No newline at end of file +#endif // __i386__ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 11:24:36 2012 From: python-checkins at python.org (ronald.oussoren) Date: Sat, 25 Aug 2012 11:24:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Fix_issue_13370=3A_Ensure_that_ctypes_works_on_Mac_OS_X_?= =?utf-8?q?when_Python_is?= Message-ID: <3X3v843LcHzQQh@mail.python.org> http://hg.python.org/cpython/rev/bed8dd30309d changeset: 78766:bed8dd30309d parent: 78762:016087c46600 parent: 78765:a425f2697273 user: Ronald Oussoren date: Sat Aug 25 11:24:00 2012 +0200 summary: Fix issue 13370: Ensure that ctypes works on Mac OS X when Python is compiled using the clang compiler (merge from 3.2) files: Misc/NEWS | 3 + Modules/_ctypes/libffi_osx/x86/darwin64.S | 6 +- Modules/_ctypes/libffi_osx/x86/x86-darwin.S | 4 + Modules/_ctypes/libffi_osx/x86/x86-ffi64.c | 118 +++++++++- Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c | 4 +- 5 files changed, 128 insertions(+), 7 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -39,6 +39,9 @@ Library ------- +- Issue #13370: Ensure that ctypes works on Mac OS X when Python is + compiled using the clang compiler + - Issue #13072: The array module's 'u' format code is now deprecated and will be removed in Python 4.0. diff --git a/Modules/_ctypes/libffi_osx/x86/darwin64.S b/Modules/_ctypes/libffi_osx/x86/darwin64.S --- a/Modules/_ctypes/libffi_osx/x86/darwin64.S +++ b/Modules/_ctypes/libffi_osx/x86/darwin64.S @@ -45,6 +45,7 @@ _ffi_call_unix64: LUW0: movq (%rsp), %r10 /* Load return address. */ + movq %rdi, %r12 /* Save a copy of the register area. */ leaq (%rdi, %rsi), %rax /* Find local stack base. */ movq %rdx, (%rax) /* Save flags. */ movq %rcx, 8(%rax) /* Save raddr. */ @@ -52,7 +53,8 @@ movq %r10, 24(%rax) /* Relocate return address. */ movq %rax, %rbp /* Finalize local stack frame. */ LUW1: - movq %rdi, %r10 /* Save a copy of the register area. */ + /* movq %rdi, %r10 // Save a copy of the register area. */ + movq %r12, %r10 movq %r8, %r11 /* Save a copy of the target fn. */ movl %r9d, %eax /* Set number of SSE registers. */ @@ -255,7 +257,7 @@ ret .align 3 Lld_int8: - movzbl -24(%rsp), %eax + movzbl -24(%rsp), %eax ret .align 3 Lld_int16: diff --git a/Modules/_ctypes/libffi_osx/x86/x86-darwin.S b/Modules/_ctypes/libffi_osx/x86/x86-darwin.S --- a/Modules/_ctypes/libffi_osx/x86/x86-darwin.S +++ b/Modules/_ctypes/libffi_osx/x86/x86-darwin.S @@ -198,8 +198,12 @@ je Lcls_retldouble cmpl $FFI_TYPE_SINT64, %eax je Lcls_retllong + cmpl $FFI_TYPE_UINT8, %eax + je Lcls_retstruct1 cmpl $FFI_TYPE_SINT8, %eax je Lcls_retstruct1 + cmpl $FFI_TYPE_UINT16, %eax + je Lcls_retstruct2 cmpl $FFI_TYPE_SINT16, %eax je Lcls_retstruct2 cmpl $FFI_TYPE_STRUCT, %eax diff --git a/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c b/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c --- a/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c +++ b/Modules/_ctypes/libffi_osx/x86/x86-ffi64.c @@ -152,12 +152,42 @@ case FFI_TYPE_UINT64: case FFI_TYPE_SINT64: case FFI_TYPE_POINTER: +#if 0 if (byte_offset + type->size <= 4) classes[0] = X86_64_INTEGERSI_CLASS; else classes[0] = X86_64_INTEGER_CLASS; return 1; +#else + { + int size = byte_offset + type->size; + + if (size <= 4) + { + classes[0] = X86_64_INTEGERSI_CLASS; + return 1; + } + else if (size <= 8) + { + classes[0] = X86_64_INTEGER_CLASS; + return 1; + } + else if (size <= 12) + { + classes[0] = X86_64_INTEGER_CLASS; + classes[1] = X86_64_INTEGERSI_CLASS; + return 2; + } + else if (size <= 16) + { + classes[0] = classes[1] = X86_64_INTEGERSI_CLASS; + return 2; + } + else + FFI_ASSERT (0); + } +#endif case FFI_TYPE_FLOAT: if (byte_offset == 0) @@ -213,6 +243,21 @@ byte_offset += (*ptr)->size; } + if (words > 2) + { + /* When size > 16 bytes, if the first one isn't + X86_64_SSE_CLASS or any other ones aren't + X86_64_SSEUP_CLASS, everything should be passed in + memory. */ + if (classes[0] != X86_64_SSE_CLASS) + return 0; + + for (i = 1; i < words; i++) + if (classes[i] != X86_64_SSEUP_CLASS) + return 0; + } + + /* Final merger cleanup. */ for (i = 0; i < words; i++) { @@ -224,13 +269,20 @@ /* The X86_64_SSEUP_CLASS should be always preceded by X86_64_SSE_CLASS. */ if (classes[i] == X86_64_SSEUP_CLASS - && (i == 0 || classes[i - 1] != X86_64_SSE_CLASS)) + && classes[i - 1] != X86_64_SSE_CLASS + && classes[i - 1] != X86_64_SSEUP_CLASS) + { + FFI_ASSERT(i != 0); classes[i] = X86_64_SSE_CLASS; + } /* X86_64_X87UP_CLASS should be preceded by X86_64_X87_CLASS. */ if (classes[i] == X86_64_X87UP_CLASS - && (i == 0 || classes[i - 1] != X86_64_X87_CLASS)) + && classes[i - 1] != X86_64_X87_CLASS) + { + FFI_ASSERT(i != 0); classes[i] = X86_64_SSE_CLASS; + } } return words; @@ -369,6 +421,7 @@ cif->flags = flags; cif->bytes = bytes; + cif->bytes = ALIGN(bytes,8); return FFI_OK; } @@ -449,7 +502,61 @@ case X86_64_INTEGER_CLASS: case X86_64_INTEGERSI_CLASS: reg_args->gpr[gprcount] = 0; - memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); + switch (arg_types[i]->type) { + case FFI_TYPE_SINT8: + { + int8_t shortval = *(int8_t*)a; + int64_t actval = (int64_t)shortval; + reg_args->gpr[gprcount] = actval; + /*memcpy (®_args->gpr[gprcount], &actval, 8);*/ + break; + } + + case FFI_TYPE_SINT16: + { + int16_t shortval = *(int16_t*)a; + int64_t actval = (int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_SINT32: + { + int32_t shortval = *(int32_t*)a; + int64_t actval = (int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_UINT8: + { + u_int8_t shortval = *(u_int8_t*)a; + u_int64_t actval = (u_int64_t)shortval; + /*memcpy (®_args->gpr[gprcount], &actval, 8);*/ + reg_args->gpr[gprcount] = actval; + break; + } + + case FFI_TYPE_UINT16: + { + u_int16_t shortval = *(u_int16_t*)a; + u_int64_t actval = (u_int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + case FFI_TYPE_UINT32: + { + u_int32_t shortval = *(u_int32_t*)a; + u_int64_t actval = (u_int64_t)shortval; + memcpy (®_args->gpr[gprcount], &actval, 8); + break; + } + + default: + //memcpy (®_args->gpr[gprcount], a, size < 8 ? size : 8); + reg_args->gpr[gprcount] = *(int64_t*)a; + } gprcount++; break; @@ -505,12 +612,15 @@ return FFI_OK; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-prototypes" int ffi_closure_unix64_inner( ffi_closure* closure, void* rvalue, RegisterArgs* reg_args, char* argp) +#pragma clang diagnostic pop { ffi_cif* cif = closure->cif; void** avalue = alloca(cif->nargs * sizeof(void *)); @@ -621,4 +731,4 @@ return ret; } -#endif /* __x86_64__ */ \ No newline at end of file +#endif /* __x86_64__ */ diff --git a/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c b/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c --- a/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c +++ b/Modules/_ctypes/libffi_osx/x86/x86-ffi_darwin.c @@ -35,6 +35,8 @@ /* ffi_prep_args is called by the assembly routine once stack space has been allocated for the function's arguments */ +void ffi_prep_args(char *stack, extended_cif *ecif); + void ffi_prep_args(char *stack, extended_cif *ecif) { register unsigned int i; @@ -433,4 +435,4 @@ } #endif -#endif // __i386__ \ No newline at end of file +#endif // __i386__ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 13:22:22 2012 From: python-checkins at python.org (andrew.svetlov) Date: Sat, 25 Aug 2012 13:22:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Delete_Misc/NEWS_record_fo?= =?utf-8?q?r_reverted_=2315776=2E?= Message-ID: <3X3xly6twrzQCZ@mail.python.org> http://hg.python.org/cpython/rev/b200acb6bed4 changeset: 78767:b200acb6bed4 user: Andrew Svetlov date: Sat Aug 25 14:22:07 2012 +0300 summary: Delete Misc/NEWS record for reverted #15776. files: Misc/NEWS | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -47,8 +47,6 @@ - Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs. -- Issue #15776: Allow pyvenv to work in existing directory with --clean. - - Issue #15249: BytesGenerator now correctly mangles From lines (when requested) even if the body contains undecodable bytes. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 21:34:04 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 21:34:04 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Update_pydoc_topics_and_su?= =?utf-8?q?spicious_markup_file=2E?= Message-ID: <3X48gJ1ptPzQJv@mail.python.org> http://hg.python.org/cpython/rev/b89d0019b833 changeset: 78768:b89d0019b833 parent: 78766:bed8dd30309d user: Georg Brandl date: Sat Aug 25 12:14:59 2012 +0200 summary: Update pydoc topics and suspicious markup file. files: Doc/tools/sphinxext/susp-ignored.csv | 1 + Lib/pydoc_data/topics.py | 18 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Doc/tools/sphinxext/susp-ignored.csv b/Doc/tools/sphinxext/susp-ignored.csv --- a/Doc/tools/sphinxext/susp-ignored.csv +++ b/Doc/tools/sphinxext/susp-ignored.csv @@ -262,6 +262,7 @@ library/stdtypes,,::,>>> hash(v[::-2]) == hash(b'abcefg'[::-2]) library/stdtypes,,:len,s[len(s):len(s)] library/stdtypes,,::,>>> y = m[::2] +library/stdtypes,,::,>>> z = y[::-2] library/string,,:end,s[start:end] library/subprocess,,`,"output=`dmesg | grep hda`" library/subprocess,,`,"output=`mycmd myarg`" diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py --- a/Lib/pydoc_data/topics.py +++ b/Lib/pydoc_data/topics.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Autogenerated by Sphinx on Sat Aug 11 08:41:05 2012 +# Autogenerated by Sphinx on Sat Aug 25 12:12:45 2012 topics = {'assert': '\nThe ``assert`` statement\n************************\n\nAssert statements are a convenient way to insert debugging assertions\ninto a program:\n\n assert_stmt ::= "assert" expression ["," expression]\n\nThe simple form, ``assert expression``, is equivalent to\n\n if __debug__:\n if not expression: raise AssertionError\n\nThe extended form, ``assert expression1, expression2``, is equivalent\nto\n\n if __debug__:\n if not expression1: raise AssertionError(expression2)\n\nThese equivalences assume that ``__debug__`` and ``AssertionError``\nrefer to the built-in variables with those names. In the current\nimplementation, the built-in variable ``__debug__`` is ``True`` under\nnormal circumstances, ``False`` when optimization is requested\n(command line option -O). The current code generator emits no code\nfor an assert statement when optimization is requested at compile\ntime. Note that it is unnecessary to include the source code for the\nexpression that failed in the error message; it will be displayed as\npart of the stack trace.\n\nAssignments to ``__debug__`` are illegal. The value for the built-in\nvariable is determined when the interpreter starts.\n', 'assignment': '\nAssignment statements\n*********************\n\nAssignment statements are used to (re)bind names to values and to\nmodify attributes or items of mutable objects:\n\n assignment_stmt ::= (target_list "=")+ (expression_list | yield_expression)\n target_list ::= target ("," target)* [","]\n target ::= identifier\n | "(" target_list ")"\n | "[" target_list "]"\n | attributeref\n | subscription\n | slicing\n | "*" target\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn assignment statement evaluates the expression list (remember that\nthis can be a single expression or a comma-separated list, the latter\nyielding a tuple) and assigns the single resulting object to each of\nthe target lists, from left to right.\n\nAssignment is defined recursively depending on the form of the target\n(list). When a target is part of a mutable object (an attribute\nreference, subscription or slicing), the mutable object must\nultimately perform the assignment and decide about its validity, and\nmay raise an exception if the assignment is unacceptable. The rules\nobserved by various types and the exceptions raised are given with the\ndefinition of the object types (see section *The standard type\nhierarchy*).\n\nAssignment of an object to a target list, optionally enclosed in\nparentheses or square brackets, is recursively defined as follows.\n\n* If the target list is a single target: The object is assigned to\n that target.\n\n* If the target list is a comma-separated list of targets: The object\n must be an iterable with the same number of items as there are\n targets in the target list, and the items are assigned, from left to\n right, to the corresponding targets.\n\n * If the target list contains one target prefixed with an asterisk,\n called a "starred" target: The object must be a sequence with at\n least as many items as there are targets in the target list, minus\n one. The first items of the sequence are assigned, from left to\n right, to the targets before the starred target. The final items\n of the sequence are assigned to the targets after the starred\n target. A list of the remaining items in the sequence is then\n assigned to the starred target (the list can be empty).\n\n * Else: The object must be a sequence with the same number of items\n as there are targets in the target list, and the items are\n assigned, from left to right, to the corresponding targets.\n\nAssignment of an object to a single target is recursively defined as\nfollows.\n\n* If the target is an identifier (name):\n\n * If the name does not occur in a ``global`` or ``nonlocal``\n statement in the current code block: the name is bound to the\n object in the current local namespace.\n\n * Otherwise: the name is bound to the object in the global namespace\n or the outer namespace determined by ``nonlocal``, respectively.\n\n The name is rebound if it was already bound. This may cause the\n reference count for the object previously bound to the name to reach\n zero, causing the object to be deallocated and its destructor (if it\n has one) to be called.\n\n* If the target is a target list enclosed in parentheses or in square\n brackets: The object must be an iterable with the same number of\n items as there are targets in the target list, and its items are\n assigned, from left to right, to the corresponding targets.\n\n* If the target is an attribute reference: The primary expression in\n the reference is evaluated. It should yield an object with\n assignable attributes; if this is not the case, ``TypeError`` is\n raised. That object is then asked to assign the assigned object to\n the given attribute; if it cannot perform the assignment, it raises\n an exception (usually but not necessarily ``AttributeError``).\n\n Note: If the object is a class instance and the attribute reference\n occurs on both sides of the assignment operator, the RHS expression,\n ``a.x`` can access either an instance attribute or (if no instance\n attribute exists) a class attribute. The LHS target ``a.x`` is\n always set as an instance attribute, creating it if necessary.\n Thus, the two occurrences of ``a.x`` do not necessarily refer to the\n same attribute: if the RHS expression refers to a class attribute,\n the LHS creates a new instance attribute as the target of the\n assignment:\n\n class Cls:\n x = 3 # class variable\n inst = Cls()\n inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x as 3\n\n This description does not necessarily apply to descriptor\n attributes, such as properties created with ``property()``.\n\n* If the target is a subscription: The primary expression in the\n reference is evaluated. It should yield either a mutable sequence\n object (such as a list) or a mapping object (such as a dictionary).\n Next, the subscript expression is evaluated.\n\n If the primary is a mutable sequence object (such as a list), the\n subscript must yield an integer. If it is negative, the sequence\'s\n length is added to it. The resulting value must be a nonnegative\n integer less than the sequence\'s length, and the sequence is asked\n to assign the assigned object to its item with that index. If the\n index is out of range, ``IndexError`` is raised (assignment to a\n subscripted sequence cannot add new items to a list).\n\n If the primary is a mapping object (such as a dictionary), the\n subscript must have a type compatible with the mapping\'s key type,\n and the mapping is then asked to create a key/datum pair which maps\n the subscript to the assigned object. This can either replace an\n existing key/value pair with the same key value, or insert a new\n key/value pair (if no key with the same value existed).\n\n For user-defined objects, the ``__setitem__()`` method is called\n with appropriate arguments.\n\n* If the target is a slicing: The primary expression in the reference\n is evaluated. It should yield a mutable sequence object (such as a\n list). The assigned object should be a sequence object of the same\n type. Next, the lower and upper bound expressions are evaluated,\n insofar they are present; defaults are zero and the sequence\'s\n length. The bounds should evaluate to integers. If either bound is\n negative, the sequence\'s length is added to it. The resulting\n bounds are clipped to lie between zero and the sequence\'s length,\n inclusive. Finally, the sequence object is asked to replace the\n slice with the items of the assigned sequence. The length of the\n slice may be different from the length of the assigned sequence,\n thus changing the length of the target sequence, if the object\n allows it.\n\n**CPython implementation detail:** In the current implementation, the\nsyntax for targets is taken to be the same as for expressions, and\ninvalid syntax is rejected during the code generation phase, causing\nless detailed error messages.\n\nWARNING: Although the definition of assignment implies that overlaps\nbetween the left-hand side and the right-hand side are \'safe\' (for\nexample ``a, b = b, a`` swaps two variables), overlaps *within* the\ncollection of assigned-to variables are not safe! For instance, the\nfollowing program prints ``[0, 2]``:\n\n x = [0, 1]\n i = 0\n i, x[i] = 1, 2\n print(x)\n\nSee also:\n\n **PEP 3132** - Extended Iterable Unpacking\n The specification for the ``*target`` feature.\n\n\nAugmented assignment statements\n===============================\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like ``x += 1`` can be rewritten as\n``x = x + 1`` to achieve a similar, but not exactly equal effect. In\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n', 'atom-identifiers': '\nIdentifiers (Names)\n*******************\n\nAn identifier occurring as an atom is a name. See section\n*Identifiers and keywords* for lexical definition and section *Naming\nand binding* for documentation of naming and binding.\n\nWhen the name is bound to an object, evaluation of the atom yields\nthat object. When a name is not bound, an attempt to evaluate it\nraises a ``NameError`` exception.\n\n**Private name mangling:** When an identifier that textually occurs in\na class definition begins with two or more underscore characters and\ndoes not end in two or more underscores, it is considered a *private\nname* of that class. Private names are transformed to a longer form\nbefore code is generated for them. The transformation inserts the\nclass name in front of the name, with leading underscores removed, and\na single underscore inserted in front of the class name. For example,\nthe identifier ``__spam`` occurring in a class named ``Ham`` will be\ntransformed to ``_Ham__spam``. This transformation is independent of\nthe syntactical context in which the identifier is used. If the\ntransformed name is extremely long (longer than 255 characters),\nimplementation defined truncation may happen. If the class name\nconsists only of underscores, no transformation is done.\n', @@ -7,7 +7,7 @@ 'attribute-access': '\nCustomizing attribute access\n****************************\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n========================\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n====================\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n=========\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n--------------------------\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n', 'attribute-references': '\nAttribute references\n********************\n\nAn attribute reference is a primary followed by a period and a name:\n\n attributeref ::= primary "." identifier\n\nThe primary must evaluate to an object of a type that supports\nattribute references, which most objects do. This object is then\nasked to produce the attribute whose name is the identifier (which can\nbe customized by overriding the ``__getattr__()`` method). If this\nattribute is not available, the exception ``AttributeError`` is\nraised. Otherwise, the type and value of the object produced is\ndetermined by the object. Multiple evaluations of the same attribute\nreference may yield different objects.\n', 'augassign': '\nAugmented assignment statements\n*******************************\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like ``x += 1`` can be rewritten as\n``x = x + 1`` to achieve a similar, but not exactly equal effect. In\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n', - 'binary': '\nBinary arithmetic operations\n****************************\n\nThe binary arithmetic operations have the conventional priority\nlevels. Note that some of these operations also apply to certain non-\nnumeric types. Apart from the power operator, there are only two\nlevels, one for multiplicative operators and one for additive\noperators:\n\n m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr\n | m_expr "%" u_expr\n a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n\nThe ``*`` (multiplication) operator yields the product of its\narguments. The arguments must either both be numbers, or one argument\nmust be an integer and the other must be a sequence. In the former\ncase, the numbers are converted to a common type and then multiplied\ntogether. In the latter case, sequence repetition is performed; a\nnegative repetition factor yields an empty sequence.\n\nThe ``/`` (division) and ``//`` (floor division) operators yield the\nquotient of their arguments. The numeric arguments are first\nconverted to a common type. Integer division yields a float, while\nfloor division of integers results in an integer; the result is that\nof mathematical division with the \'floor\' function applied to the\nresult. Division by zero raises the ``ZeroDivisionError`` exception.\n\nThe ``%`` (modulo) operator yields the remainder from the division of\nthe first argument by the second. The numeric arguments are first\nconverted to a common type. A zero right argument raises the\n``ZeroDivisionError`` exception. The arguments may be floating point\nnumbers, e.g., ``3.14%0.7`` equals ``0.34`` (since ``3.14`` equals\n``4*0.7 + 0.34``.) The modulo operator always yields a result with\nthe same sign as its second operand (or zero); the absolute value of\nthe result is strictly smaller than the absolute value of the second\noperand [1].\n\nThe floor division and modulo operators are connected by the following\nidentity: ``x == (x//y)*y + (x%y)``. Floor division and modulo are\nalso connected with the built-in function ``divmod()``: ``divmod(x, y)\n== (x//y, x%y)``. [2].\n\nIn addition to performing the modulo operation on numbers, the ``%``\noperator is also overloaded by string objects to perform old-style\nstring formatting (also known as interpolation). The syntax for\nstring formatting is described in the Python Library Reference,\nsection *Old String Formatting Operations*.\n\nThe floor division operator, the modulo operator, and the ``divmod()``\nfunction are not defined for complex numbers. Instead, convert to a\nfloating point number using the ``abs()`` function if appropriate.\n\nThe ``+`` (addition) operator yields the sum of its arguments. The\narguments must either both be numbers or both sequences of the same\ntype. In the former case, the numbers are converted to a common type\nand then added together. In the latter case, the sequences are\nconcatenated.\n\nThe ``-`` (subtraction) operator yields the difference of its\narguments. The numeric arguments are first converted to a common\ntype.\n', + 'binary': '\nBinary arithmetic operations\n****************************\n\nThe binary arithmetic operations have the conventional priority\nlevels. Note that some of these operations also apply to certain non-\nnumeric types. Apart from the power operator, there are only two\nlevels, one for multiplicative operators and one for additive\noperators:\n\n m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr\n | m_expr "%" u_expr\n a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n\nThe ``*`` (multiplication) operator yields the product of its\narguments. The arguments must either both be numbers, or one argument\nmust be an integer and the other must be a sequence. In the former\ncase, the numbers are converted to a common type and then multiplied\ntogether. In the latter case, sequence repetition is performed; a\nnegative repetition factor yields an empty sequence.\n\nThe ``/`` (division) and ``//`` (floor division) operators yield the\nquotient of their arguments. The numeric arguments are first\nconverted to a common type. Integer division yields a float, while\nfloor division of integers results in an integer; the result is that\nof mathematical division with the \'floor\' function applied to the\nresult. Division by zero raises the ``ZeroDivisionError`` exception.\n\nThe ``%`` (modulo) operator yields the remainder from the division of\nthe first argument by the second. The numeric arguments are first\nconverted to a common type. A zero right argument raises the\n``ZeroDivisionError`` exception. The arguments may be floating point\nnumbers, e.g., ``3.14%0.7`` equals ``0.34`` (since ``3.14`` equals\n``4*0.7 + 0.34``.) The modulo operator always yields a result with\nthe same sign as its second operand (or zero); the absolute value of\nthe result is strictly smaller than the absolute value of the second\noperand [1].\n\nThe floor division and modulo operators are connected by the following\nidentity: ``x == (x//y)*y + (x%y)``. Floor division and modulo are\nalso connected with the built-in function ``divmod()``: ``divmod(x, y)\n== (x//y, x%y)``. [2].\n\nIn addition to performing the modulo operation on numbers, the ``%``\noperator is also overloaded by string objects to perform old-style\nstring formatting (also known as interpolation). The syntax for\nstring formatting is described in the Python Library Reference,\nsection *printf-style String Formatting*.\n\nThe floor division operator, the modulo operator, and the ``divmod()``\nfunction are not defined for complex numbers. Instead, convert to a\nfloating point number using the ``abs()`` function if appropriate.\n\nThe ``+`` (addition) operator yields the sum of its arguments. The\narguments must either both be numbers or both sequences of the same\ntype. In the former case, the numbers are converted to a common type\nand then added together. In the latter case, the sequences are\nconcatenated.\n\nThe ``-`` (subtraction) operator yields the difference of its\narguments. The numeric arguments are first converted to a common\ntype.\n', 'bitwise': '\nBinary bitwise operations\n*************************\n\nEach of the three bitwise operations has a different priority level:\n\n and_expr ::= shift_expr | and_expr "&" shift_expr\n xor_expr ::= and_expr | xor_expr "^" and_expr\n or_expr ::= xor_expr | or_expr "|" xor_expr\n\nThe ``&`` operator yields the bitwise AND of its arguments, which must\nbe integers.\n\nThe ``^`` operator yields the bitwise XOR (exclusive OR) of its\narguments, which must be integers.\n\nThe ``|`` operator yields the bitwise (inclusive) OR of its arguments,\nwhich must be integers.\n', 'bltin-code-objects': '\nCode Objects\n************\n\nCode objects are used by the implementation to represent "pseudo-\ncompiled" executable Python code such as a function body. They differ\nfrom function objects because they don\'t contain a reference to their\nglobal execution environment. Code objects are returned by the built-\nin ``compile()`` function and can be extracted from function objects\nthrough their ``__code__`` attribute. See also the ``code`` module.\n\nA code object can be executed or evaluated by passing it (instead of a\nsource string) to the ``exec()`` or ``eval()`` built-in functions.\n\nSee *The standard type hierarchy* for more information.\n', 'bltin-ellipsis-object': '\nThe Ellipsis Object\n*******************\n\nThis object is commonly used by slicing (see *Slicings*). It supports\nno special operations. There is exactly one ellipsis object, named\n``Ellipsis`` (a built-in name). ``type(Ellipsis)()`` produces the\n``Ellipsis`` singleton.\n\nIt is written as ``Ellipsis`` or ``...``.\n', @@ -19,7 +19,7 @@ 'calls': '\nCalls\n*****\n\nA call calls a callable object (e.g., a function) with a possibly\nempty series of arguments:\n\n call ::= primary "(" [argument_list [","] | comprehension] ")"\n argument_list ::= positional_arguments ["," keyword_arguments]\n ["," "*" expression] ["," keyword_arguments]\n ["," "**" expression]\n | keyword_arguments ["," "*" expression]\n ["," keyword_arguments] ["," "**" expression]\n | "*" expression ["," keyword_arguments] ["," "**" expression]\n | "**" expression\n positional_arguments ::= expression ("," expression)*\n keyword_arguments ::= keyword_item ("," keyword_item)*\n keyword_item ::= identifier "=" expression\n\nA trailing comma may be present after the positional and keyword\narguments but does not affect the semantics.\n\nThe primary must evaluate to a callable object (user-defined\nfunctions, built-in functions, methods of built-in objects, class\nobjects, methods of class instances, and all objects having a\n``__call__()`` method are callable). All argument expressions are\nevaluated before the call is attempted. Please refer to section\n*Function definitions* for the syntax of formal parameter lists.\n\nIf keyword arguments are present, they are first converted to\npositional arguments, as follows. First, a list of unfilled slots is\ncreated for the formal parameters. If there are N positional\narguments, they are placed in the first N slots. Next, for each\nkeyword argument, the identifier is used to determine the\ncorresponding slot (if the identifier is the same as the first formal\nparameter name, the first slot is used, and so on). If the slot is\nalready filled, a ``TypeError`` exception is raised. Otherwise, the\nvalue of the argument is placed in the slot, filling it (even if the\nexpression is ``None``, it fills the slot). When all arguments have\nbeen processed, the slots that are still unfilled are filled with the\ncorresponding default value from the function definition. (Default\nvalues are calculated, once, when the function is defined; thus, a\nmutable object such as a list or dictionary used as default value will\nbe shared by all calls that don\'t specify an argument value for the\ncorresponding slot; this should usually be avoided.) If there are any\nunfilled slots for which no default value is specified, a\n``TypeError`` exception is raised. Otherwise, the list of filled\nslots is used as the argument list for the call.\n\n**CPython implementation detail:** An implementation may provide\nbuilt-in functions whose positional parameters do not have names, even\nif they are \'named\' for the purpose of documentation, and which\ntherefore cannot be supplied by keyword. In CPython, this is the case\nfor functions implemented in C that use ``PyArg_ParseTuple()`` to\nparse their arguments.\n\nIf there are more positional arguments than there are formal parameter\nslots, a ``TypeError`` exception is raised, unless a formal parameter\nusing the syntax ``*identifier`` is present; in this case, that formal\nparameter receives a tuple containing the excess positional arguments\n(or an empty tuple if there were no excess positional arguments).\n\nIf any keyword argument does not correspond to a formal parameter\nname, a ``TypeError`` exception is raised, unless a formal parameter\nusing the syntax ``**identifier`` is present; in this case, that\nformal parameter receives a dictionary containing the excess keyword\narguments (using the keywords as keys and the argument values as\ncorresponding values), or a (new) empty dictionary if there were no\nexcess keyword arguments.\n\nIf the syntax ``*expression`` appears in the function call,\n``expression`` must evaluate to an iterable. Elements from this\niterable are treated as if they were additional positional arguments;\nif there are positional arguments *x1*, ..., *xN*, and ``expression``\nevaluates to a sequence *y1*, ..., *yM*, this is equivalent to a call\nwith M+N positional arguments *x1*, ..., *xN*, *y1*, ..., *yM*.\n\nA consequence of this is that although the ``*expression`` syntax may\nappear *after* some keyword arguments, it is processed *before* the\nkeyword arguments (and the ``**expression`` argument, if any -- see\nbelow). So:\n\n >>> def f(a, b):\n ... print(a, b)\n ...\n >>> f(b=1, *(2,))\n 2 1\n >>> f(a=1, *(2,))\n Traceback (most recent call last):\n File "", line 1, in ?\n TypeError: f() got multiple values for keyword argument \'a\'\n >>> f(1, *(2,))\n 1 2\n\nIt is unusual for both keyword arguments and the ``*expression``\nsyntax to be used in the same call, so in practice this confusion does\nnot arise.\n\nIf the syntax ``**expression`` appears in the function call,\n``expression`` must evaluate to a mapping, the contents of which are\ntreated as additional keyword arguments. In the case of a keyword\nappearing in both ``expression`` and as an explicit keyword argument,\na ``TypeError`` exception is raised.\n\nFormal parameters using the syntax ``*identifier`` or ``**identifier``\ncannot be used as positional argument slots or as keyword argument\nnames.\n\nA call always returns some value, possibly ``None``, unless it raises\nan exception. How this value is computed depends on the type of the\ncallable object.\n\nIf it is---\n\na user-defined function:\n The code block for the function is executed, passing it the\n argument list. The first thing the code block will do is bind the\n formal parameters to the arguments; this is described in section\n *Function definitions*. When the code block executes a ``return``\n statement, this specifies the return value of the function call.\n\na built-in function or method:\n The result is up to the interpreter; see *Built-in Functions* for\n the descriptions of built-in functions and methods.\n\na class object:\n A new instance of that class is returned.\n\na class instance method:\n The corresponding user-defined function is called, with an argument\n list that is one longer than the argument list of the call: the\n instance becomes the first argument.\n\na class instance:\n The class must define a ``__call__()`` method; the effect is then\n the same as if that method was called.\n', 'class': '\nClass definitions\n*****************\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n exception or the execution of a ``return``, ``continue``, or\n ``break`` statement.\n\n[3] A string literal appearing as the first statement in the function\n body is transformed into the function\'s ``__doc__`` attribute and\n therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s ``__doc__`` item and\n therefore the class\'s *docstring*.\n', 'comparisons': '\nComparisons\n***********\n\nUnlike C, all comparison operations in Python have the same priority,\nwhich is lower than that of any arithmetic, shifting or bitwise\noperation. Also unlike C, expressions like ``a < b < c`` have the\ninterpretation that is conventional in mathematics:\n\n comparison ::= or_expr ( comp_operator or_expr )*\n comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!="\n | "is" ["not"] | ["not"] "in"\n\nComparisons yield boolean values: ``True`` or ``False``.\n\nComparisons can be chained arbitrarily, e.g., ``x < y <= z`` is\nequivalent to ``x < y and y <= z``, except that ``y`` is evaluated\nonly once (but in both cases ``z`` is not evaluated at all when ``x <\ny`` is found to be false).\n\nFormally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*,\n*op2*, ..., *opN* are comparison operators, then ``a op1 b op2 c ... y\nopN z`` is equivalent to ``a op1 b and b op2 c and ... y opN z``,\nexcept that each expression is evaluated at most once.\n\nNote that ``a op1 b op2 c`` doesn\'t imply any kind of comparison\nbetween *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal\n(though perhaps not pretty).\n\nThe operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare\nthe values of two objects. The objects need not have the same type.\nIf both are numbers, they are converted to a common type. Otherwise,\nthe ``==`` and ``!=`` operators *always* consider objects of different\ntypes to be unequal, while the ``<``, ``>``, ``>=`` and ``<=``\noperators raise a ``TypeError`` when comparing objects of different\ntypes that do not implement these operators for the given pair of\ntypes. You can control comparison behavior of objects of non-built-in\ntypes by defining rich comparison methods like ``__gt__()``, described\nin section *Basic customization*.\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* The values ``float(\'NaN\')`` and ``Decimal(\'NaN\')`` are special. The\n are identical to themselves, ``x is x`` but are not equal to\n themselves, ``x != x``. Additionally, comparing any value to a\n not-a-number value will return ``False``. For example, both ``3 <\n float(\'NaN\')`` and ``float(\'NaN\') < 3`` will return ``False``.\n\n* Bytes objects are compared lexicographically using the numeric\n values of their elements.\n\n* Strings are compared lexicographically using the numeric equivalents\n (the result of the built-in function ``ord()``) of their characters.\n [3] String and bytes object can\'t be compared!\n\n* Tuples and lists are compared lexicographically using comparison of\n corresponding elements. This means that to compare equal, each\n element must compare equal and the two sequences must be of the same\n type and have the same length.\n\n If not equal, the sequences are ordered the same as their first\n differing elements. For example, ``[1,2,x] <= [1,2,y]`` has the\n same value as ``x <= y``. If the corresponding element does not\n exist, the shorter sequence is ordered first (for example, ``[1,2] <\n [1,2,3]``).\n\n* Mappings (dictionaries) compare equal if and only if they have the\n same ``(key, value)`` pairs. Order comparisons ``(\'<\', \'<=\', \'>=\',\n \'>\')`` raise ``TypeError``.\n\n* Sets and frozensets define comparison operators to mean subset and\n superset tests. Those relations do not define total orderings (the\n two sets ``{1,2}`` and {2,3} are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering.\n For example, ``min()``, ``max()``, and ``sorted()`` produce\n undefined results given a list of sets as inputs.\n\n* Most other objects of built-in types compare unequal unless they are\n the same object; the choice whether one object is considered smaller\n or larger than another one is made arbitrarily but consistently\n within one execution of a program.\n\nComparison of objects of the differing types depends on whether either\nof the types provide explicit support for the comparison. Most\nnumeric types can be compared with one another, but comparisons of\n``float`` and ``Decimal`` are not supported to avoid the inevitable\nconfusion arising from representation issues such as ``float(\'1.1\')``\nbeing inexactly represented and therefore not exactly equal to\n``Decimal(\'1.1\')`` which is. When cross-type comparison is not\nsupported, the comparison method returns ``NotImplemented``. This can\ncreate the illusion of non-transitivity between supported cross-type\ncomparisons and unsupported comparisons. For example, ``Decimal(2) ==\n2`` and ``2 == float(2)`` but ``Decimal(2) != float(2)``.\n\nThe operators ``in`` and ``not in`` test for membership. ``x in s``\nevaluates to true if *x* is a member of *s*, and false otherwise. ``x\nnot in s`` returns the negation of ``x in s``. All built-in sequences\nand set types support this as well as dictionary, for which ``in``\ntests whether a the dictionary has a given key. For container types\nsuch as list, tuple, set, frozenset, dict, or collections.deque, the\nexpression ``x in y`` is equivalent to ``any(x is e or x == e for e in\ny)``.\n\nFor the string and bytes types, ``x in y`` is true if and only if *x*\nis a substring of *y*. An equivalent test is ``y.find(x) != -1``.\nEmpty strings are always considered to be a substring of any other\nstring, so ``"" in "abc"`` will return ``True``.\n\nFor user-defined classes which define the ``__contains__()`` method,\n``x in y`` is true if and only if ``y.__contains__(x)`` is true.\n\nFor user-defined classes which do not define ``__contains__()`` but do\ndefine ``__iter__()``, ``x in y`` is true if some value ``z`` with ``x\n== z`` is produced while iterating over ``y``. If an exception is\nraised during the iteration, it is as if ``in`` raised that exception.\n\nLastly, the old-style iteration protocol is tried: if a class defines\n``__getitem__()``, ``x in y`` is true if and only if there is a non-\nnegative integer index *i* such that ``x == y[i]``, and all lower\ninteger indices do not raise ``IndexError`` exception. (If any other\nexception is raised, it is as if ``in`` raised that exception).\n\nThe operator ``not in`` is defined to have the inverse true value of\n``in``.\n\nThe operators ``is`` and ``is not`` test for object identity: ``x is\ny`` is true if and only if *x* and *y* are the same object. ``x is\nnot y`` yields the inverse truth value. [4]\n', - 'compound': '\nCompound statements\n*******************\n\nCompound statements contain (groups of) other statements; they affect\nor control the execution of those other statements in some way. In\ngeneral, compound statements span multiple lines, although in simple\nincarnations a whole compound statement may be contained in one line.\n\nThe ``if``, ``while`` and ``for`` statements implement traditional\ncontrol flow constructs. ``try`` specifies exception handlers and/or\ncleanup code for a group of statements, while the ``with`` statement\nallows the execution of initialization and finalization code around a\nblock of code. Function and class definitions are also syntactically\ncompound statements.\n\nCompound statements consist of one or more \'clauses.\' A clause\nconsists of a header and a \'suite.\' The clause headers of a\nparticular compound statement are all at the same indentation level.\nEach clause header begins with a uniquely identifying keyword and ends\nwith a colon. A suite is a group of statements controlled by a\nclause. A suite can be one or more semicolon-separated simple\nstatements on the same line as the header, following the header\'s\ncolon, or it can be one or more indented statements on subsequent\nlines. Only the latter form of suite can contain nested compound\nstatements; the following is illegal, mostly because it wouldn\'t be\nclear to which ``if`` clause a following ``else`` clause would belong:\n\n if test1: if test2: print(x)\n\nAlso note that the semicolon binds tighter than the colon in this\ncontext, so that in the following example, either all or none of the\n``print()`` calls are executed:\n\n if x < y < z: print(x); print(y); print(z)\n\nSummarizing:\n\n compound_stmt ::= if_stmt\n | while_stmt\n | for_stmt\n | try_stmt\n | with_stmt\n | funcdef\n | classdef\n suite ::= stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\n statement ::= stmt_list NEWLINE | compound_stmt\n stmt_list ::= simple_stmt (";" simple_stmt)* [";"]\n\nNote that statements always end in a ``NEWLINE`` possibly followed by\na ``DEDENT``. Also note that optional continuation clauses always\nbegin with a keyword that cannot start a statement, thus there are no\nambiguities (the \'dangling ``else``\' problem is solved in Python by\nrequiring nested ``if`` statements to be indented).\n\nThe formatting of the grammar rules in the following sections places\neach clause on a separate line for clarity.\n\n\nThe ``if`` statement\n====================\n\nThe ``if`` statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section *Boolean operations*\nfor the definition of true and false); then that suite is executed\n(and no other part of the ``if`` statement is executed or evaluated).\nIf all expressions are false, the suite of the ``else`` clause, if\npresent, is executed.\n\n\nThe ``while`` statement\n=======================\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n\n\nThe ``for`` statement\n=====================\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n``expression_list``. The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in the ``else`` clause, if present, is executed,\nand the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n\n\nThe ``try`` statement\n=====================\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception, it is re-raised at the end\nof the ``finally`` clause. If the ``finally`` clause raises another\nexception or executes a ``return`` or ``break`` statement, the saved\nexception is set as the context of the new exception. The exception\ninformation is not available to the program during execution of the\n``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n\n\nThe ``with`` statement\n======================\n\nThe ``with`` statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section *With Statement\nContext Managers*). This allows common\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the ``with`` statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the ``with_item``)\n is evaluated to obtain a context manager.\n\n2. The context manager\'s ``__exit__()`` is loaded for later use.\n\n3. The context manager\'s ``__enter__()`` method is invoked.\n\n4. If a target was included in the ``with`` statement, the return\n value from ``__enter__()`` is assigned to it.\n\n Note: The ``with`` statement guarantees that if the ``__enter__()``\n method returns without an error, then ``__exit__()`` will always\n be called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s ``__exit__()`` method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to ``__exit__()``. Otherwise,\n three ``None`` arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the ``__exit__()`` method was false, the exception is\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from ``__exit__()`` is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple ``with`` statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nFunction definitions\n====================\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more parameters have the form *parameter* ``=``\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding argument may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters up until the "``*``" must also have a default value ---\nthis is a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use ``None`` as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A "``def``"\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n exception or the execution of a ``return``, ``continue``, or\n ``break`` statement.\n\n[3] A string literal appearing as the first statement in the function\n body is transformed into the function\'s ``__doc__`` attribute and\n therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s ``__doc__`` item and\n therefore the class\'s *docstring*.\n', + 'compound': '\nCompound statements\n*******************\n\nCompound statements contain (groups of) other statements; they affect\nor control the execution of those other statements in some way. In\ngeneral, compound statements span multiple lines, although in simple\nincarnations a whole compound statement may be contained in one line.\n\nThe ``if``, ``while`` and ``for`` statements implement traditional\ncontrol flow constructs. ``try`` specifies exception handlers and/or\ncleanup code for a group of statements, while the ``with`` statement\nallows the execution of initialization and finalization code around a\nblock of code. Function and class definitions are also syntactically\ncompound statements.\n\nCompound statements consist of one or more \'clauses.\' A clause\nconsists of a header and a \'suite.\' The clause headers of a\nparticular compound statement are all at the same indentation level.\nEach clause header begins with a uniquely identifying keyword and ends\nwith a colon. A suite is a group of statements controlled by a\nclause. A suite can be one or more semicolon-separated simple\nstatements on the same line as the header, following the header\'s\ncolon, or it can be one or more indented statements on subsequent\nlines. Only the latter form of suite can contain nested compound\nstatements; the following is illegal, mostly because it wouldn\'t be\nclear to which ``if`` clause a following ``else`` clause would belong:\n\n if test1: if test2: print(x)\n\nAlso note that the semicolon binds tighter than the colon in this\ncontext, so that in the following example, either all or none of the\n``print()`` calls are executed:\n\n if x < y < z: print(x); print(y); print(z)\n\nSummarizing:\n\n compound_stmt ::= if_stmt\n | while_stmt\n | for_stmt\n | try_stmt\n | with_stmt\n | funcdef\n | classdef\n suite ::= stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\n statement ::= stmt_list NEWLINE | compound_stmt\n stmt_list ::= simple_stmt (";" simple_stmt)* [";"]\n\nNote that statements always end in a ``NEWLINE`` possibly followed by\na ``DEDENT``. Also note that optional continuation clauses always\nbegin with a keyword that cannot start a statement, thus there are no\nambiguities (the \'dangling ``else``\' problem is solved in Python by\nrequiring nested ``if`` statements to be indented).\n\nThe formatting of the grammar rules in the following sections places\neach clause on a separate line for clarity.\n\n\nThe ``if`` statement\n====================\n\nThe ``if`` statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section *Boolean operations*\nfor the definition of true and false); then that suite is executed\n(and no other part of the ``if`` statement is executed or evaluated).\nIf all expressions are false, the suite of the ``else`` clause, if\npresent, is executed.\n\n\nThe ``while`` statement\n=======================\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n\n\nThe ``for`` statement\n=====================\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n``expression_list``. The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in the ``else`` clause, if present, is executed,\nand the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n\n\nThe ``try`` statement\n=====================\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception or ``break`` statement, it is\nre-raised at the end of the ``finally`` clause. If the ``finally``\nclause raises another exception the saved exception is set as the\ncontext of the new exception; if the ``finally`` clause executes a\n``return`` statement, the saved exception is discarded:\n\n def f():\n try:\n 1/0\n finally:\n return 42\n\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the ``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n\n\nThe ``with`` statement\n======================\n\nThe ``with`` statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section *With Statement\nContext Managers*). This allows common\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the ``with`` statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the ``with_item``)\n is evaluated to obtain a context manager.\n\n2. The context manager\'s ``__exit__()`` is loaded for later use.\n\n3. The context manager\'s ``__enter__()`` method is invoked.\n\n4. If a target was included in the ``with`` statement, the return\n value from ``__enter__()`` is assigned to it.\n\n Note: The ``with`` statement guarantees that if the ``__enter__()``\n method returns without an error, then ``__exit__()`` will always\n be called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s ``__exit__()`` method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to ``__exit__()``. Otherwise,\n three ``None`` arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the ``__exit__()`` method was false, the exception is\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from ``__exit__()`` is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple ``with`` statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nFunction definitions\n====================\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more parameters have the form *parameter* ``=``\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding argument may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters up until the "``*``" must also have a default value ---\nthis is a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use ``None`` as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A "``def``"\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n exception or the execution of a ``return``, ``continue``, or\n ``break`` statement.\n\n[3] A string literal appearing as the first statement in the function\n body is transformed into the function\'s ``__doc__`` attribute and\n therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s ``__doc__`` item and\n therefore the class\'s *docstring*.\n', 'context-managers': '\nWith Statement Context Managers\n*******************************\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n', 'continue': '\nThe ``continue`` statement\n**************************\n\n continue_stmt ::= "continue"\n\n``continue`` may only occur syntactically nested in a ``for`` or\n``while`` loop, but not nested in a function or class definition or\n``finally`` clause within that loop. It continues with the next cycle\nof the nearest enclosing loop.\n\nWhen ``continue`` passes control out of a ``try`` statement with a\n``finally`` clause, that ``finally`` clause is executed before really\nstarting the next loop cycle.\n', 'conversions': '\nArithmetic conversions\n**********************\n\nWhen a description of an arithmetic operator below uses the phrase\n"the numeric arguments are converted to a common type," this means\nthat the operator implementation for built-in types works that way:\n\n* If either argument is a complex number, the other is converted to\n complex;\n\n* otherwise, if either argument is a floating point number, the other\n is converted to floating point;\n\n* otherwise, both must be integers and no conversion is necessary.\n\nSome additional rules apply for certain operators (e.g., a string left\nargument to the \'%\' operator). Extensions must define their own\nconversion behavior.\n', @@ -34,7 +34,7 @@ 'exprlists': '\nExpression lists\n****************\n\n expression_list ::= expression ( "," expression )* [","]\n\nAn expression list containing at least one comma yields a tuple. The\nlength of the tuple is the number of expressions in the list. The\nexpressions are evaluated from left to right.\n\nThe trailing comma is required only to create a single tuple (a.k.a. a\n*singleton*); it is optional in all other cases. A single expression\nwithout a trailing comma doesn\'t create a tuple, but rather yields the\nvalue of that expression. (To create an empty tuple, use an empty pair\nof parentheses: ``()``.)\n', 'floating': '\nFloating point literals\n***********************\n\nFloating point literals are described by the following lexical\ndefinitions:\n\n floatnumber ::= pointfloat | exponentfloat\n pointfloat ::= [intpart] fraction | intpart "."\n exponentfloat ::= (intpart | pointfloat) exponent\n intpart ::= digit+\n fraction ::= "." digit+\n exponent ::= ("e" | "E") ["+" | "-"] digit+\n\nNote that the integer and exponent parts are always interpreted using\nradix 10. For example, ``077e010`` is legal, and denotes the same\nnumber as ``77e10``. The allowed range of floating point literals is\nimplementation-dependent. Some examples of floating point literals:\n\n 3.14 10. .001 1e100 3.14e-10 0e0\n\nNote that numeric literals do not include a sign; a phrase like ``-1``\nis actually an expression composed of the unary operator ``-`` and the\nliteral ``1``.\n', 'for': '\nThe ``for`` statement\n*********************\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n``expression_list``. The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in the ``else`` clause, if present, is executed,\nand the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n', - 'formatstrings': '\nFormat String Syntax\n********************\n\nThe ``str.format()`` method and the ``Formatter`` class share the same\nsyntax for format strings (although in the case of ``Formatter``,\nsubclasses can define their own format string syntax).\n\nFormat strings contain "replacement fields" surrounded by curly braces\n``{}``. Anything that is not contained in braces is considered literal\ntext, which is copied unchanged to the output. If you need to include\na brace character in the literal text, it can be escaped by doubling:\n``{{`` and ``}}``.\n\nThe grammar for a replacement field is as follows:\n\n replacement_field ::= "{" [field_name] ["!" conversion] [":" format_spec] "}"\n field_name ::= arg_name ("." attribute_name | "[" element_index "]")*\n arg_name ::= [identifier | integer]\n attribute_name ::= identifier\n element_index ::= integer | index_string\n index_string ::= +\n conversion ::= "r" | "s" | "a"\n format_spec ::= \n\nIn less formal terms, the replacement field can start with a\n*field_name* that specifies the object whose value is to be formatted\nand inserted into the output instead of the replacement field. The\n*field_name* is optionally followed by a *conversion* field, which is\npreceded by an exclamation point ``\'!\'``, and a *format_spec*, which\nis preceded by a colon ``\':\'``. These specify a non-default format\nfor the replacement value.\n\nSee also the *Format Specification Mini-Language* section.\n\nThe *field_name* itself begins with an *arg_name* that is either a\nnumber or a keyword. If it\'s a number, it refers to a positional\nargument, and if it\'s a keyword, it refers to a named keyword\nargument. If the numerical arg_names in a format string are 0, 1, 2,\n... in sequence, they can all be omitted (not just some) and the\nnumbers 0, 1, 2, ... will be automatically inserted in that order.\nBecause *arg_name* is not quote-delimited, it is not possible to\nspecify arbitrary dictionary keys (e.g., the strings ``\'10\'`` or\n``\':-]\'``) within a format string. The *arg_name* can be followed by\nany number of index or attribute expressions. An expression of the\nform ``\'.name\'`` selects the named attribute using ``getattr()``,\nwhile an expression of the form ``\'[index]\'`` does an index lookup\nusing ``__getitem__()``.\n\nChanged in version 3.1: The positional argument specifiers can be\nomitted, so ``\'{} {}\'`` is equivalent to ``\'{0} {1}\'``.\n\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\n "Bring me a {}" # Implicitly references the first positional argument\n "From {} to {}" # Same as "From {0} to {1}"\n "My quest is {name}" # References keyword argument \'name\'\n "Weight in tons {0.weight}" # \'weight\' attribute of first positional arg\n "Units destroyed: {players[0]}" # First element of keyword argument \'players\'.\n\nThe *conversion* field causes a type coercion before formatting.\nNormally, the job of formatting a value is done by the\n``__format__()`` method of the value itself. However, in some cases\nit is desirable to force a type to be formatted as a string,\noverriding its own definition of formatting. By converting the value\nto a string before calling ``__format__()``, the normal formatting\nlogic is bypassed.\n\nThree conversion flags are currently supported: ``\'!s\'`` which calls\n``str()`` on the value, ``\'!r\'`` which calls ``repr()`` and ``\'!a\'``\nwhich calls ``ascii()``.\n\nSome examples:\n\n "Harold\'s a clever {0!s}" # Calls str() on the argument first\n "Bring out the holy {name!r}" # Calls repr() on the argument first\n "More {!a}" # Calls ascii() on the argument first\n\nThe *format_spec* field contains a specification of how the value\nshould be presented, including such details as field width, alignment,\npadding, decimal precision and so on. Each value type can define its\nown "formatting mini-language" or interpretation of the *format_spec*.\n\nMost built-in types support a common formatting mini-language, which\nis described in the next section.\n\nA *format_spec* field can also include nested replacement fields\nwithin it. These nested replacement fields can contain only a field\nname; conversion flags and format specifications are not allowed. The\nreplacement fields within the format_spec are substituted before the\n*format_spec* string is interpreted. This allows the formatting of a\nvalue to be dynamically specified.\n\nSee the *Format examples* section for some examples.\n\n\nFormat Specification Mini-Language\n==================================\n\n"Format specifications" are used within replacement fields contained\nwithin a format string to define how individual values are presented\n(see *Format String Syntax*). They can also be passed directly to the\nbuilt-in ``format()`` function. Each formattable type may define how\nthe format specification is to be interpreted.\n\nMost built-in types implement the following options for format\nspecifications, although some of the formatting options are only\nsupported by the numeric types.\n\nA general convention is that an empty format string (``""``) produces\nthe same result as if you had called ``str()`` on the value. A non-\nempty format string typically modifies the result.\n\nThe general form of a *standard format specifier* is:\n\n format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]\n fill ::= \n align ::= "<" | ">" | "=" | "^"\n sign ::= "+" | "-" | " "\n width ::= integer\n precision ::= integer\n type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n\nThe *fill* character can be any character other than \'{\' or \'}\'. The\npresence of a fill character is signaled by the character following\nit, which must be one of the alignment options. If the second\ncharacter of *format_spec* is not a valid alignment option, then it is\nassumed that both the fill character and the alignment option are\nabsent.\n\nThe meaning of the various alignment options is as follows:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'<\'`` | Forces the field to be left-aligned within the available |\n | | space (this is the default for most objects). |\n +-----------+------------------------------------------------------------+\n | ``\'>\'`` | Forces the field to be right-aligned within the available |\n | | space (this is the default for numbers). |\n +-----------+------------------------------------------------------------+\n | ``\'=\'`` | Forces the padding to be placed after the sign (if any) |\n | | but before the digits. This is used for printing fields |\n | | in the form \'+000000120\'. This alignment option is only |\n | | valid for numeric types. |\n +-----------+------------------------------------------------------------+\n | ``\'^\'`` | Forces the field to be centered within the available |\n | | space. |\n +-----------+------------------------------------------------------------+\n\nNote that unless a minimum field width is defined, the field width\nwill always be the same size as the data to fill it, so that the\nalignment option has no meaning in this case.\n\nThe *sign* option is only valid for number types, and can be one of\nthe following:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'+\'`` | indicates that a sign should be used for both positive as |\n | | well as negative numbers. |\n +-----------+------------------------------------------------------------+\n | ``\'-\'`` | indicates that a sign should be used only for negative |\n | | numbers (this is the default behavior). |\n +-----------+------------------------------------------------------------+\n | space | indicates that a leading space should be used on positive |\n | | numbers, and a minus sign on negative numbers. |\n +-----------+------------------------------------------------------------+\n\nThe ``\'#\'`` option causes the "alternate form" to be used for the\nconversion. The alternate form is defined differently for different\ntypes. This option is only valid for integer, float, complex and\nDecimal types. For integers, when binary, octal, or hexadecimal output\nis used, this option adds the prefix respective ``\'0b\'``, ``\'0o\'``, or\n``\'0x\'`` to the output value. For floats, complex and Decimal the\nalternate form causes the result of the conversion to always contain a\ndecimal-point character, even if no digits follow it. Normally, a\ndecimal-point character appears in the result of these conversions\nonly if a digit follows it. In addition, for ``\'g\'`` and ``\'G\'``\nconversions, trailing zeros are not removed from the result.\n\nThe ``\',\'`` option signals the use of a comma for a thousands\nseparator. For a locale aware separator, use the ``\'n\'`` integer\npresentation type instead.\n\nChanged in version 3.1: Added the ``\',\'`` option (see also **PEP\n378**).\n\n*width* is a decimal integer defining the minimum field width. If not\nspecified, then the field width will be determined by the content.\n\nIf the *width* field is preceded by a zero (``\'0\'``) character, this\nenables zero-padding. This is equivalent to an *alignment* type of\n``\'=\'`` and a *fill* character of ``\'0\'``.\n\nThe *precision* is a decimal number indicating how many digits should\nbe displayed after the decimal point for a floating point value\nformatted with ``\'f\'`` and ``\'F\'``, or before and after the decimal\npoint for a floating point value formatted with ``\'g\'`` or ``\'G\'``.\nFor non-number types the field indicates the maximum field size - in\nother words, how many characters will be used from the field content.\nThe *precision* is not allowed for integer values.\n\nFinally, the *type* determines how the data should be presented.\n\nThe available string presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'s\'`` | String format. This is the default type for strings and |\n | | may be omitted. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'s\'``. |\n +-----------+------------------------------------------------------------+\n\nThe available integer presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'b\'`` | Binary format. Outputs the number in base 2. |\n +-----------+------------------------------------------------------------+\n | ``\'c\'`` | Character. Converts the integer to the corresponding |\n | | unicode character before printing. |\n +-----------+------------------------------------------------------------+\n | ``\'d\'`` | Decimal Integer. Outputs the number in base 10. |\n +-----------+------------------------------------------------------------+\n | ``\'o\'`` | Octal format. Outputs the number in base 8. |\n +-----------+------------------------------------------------------------+\n | ``\'x\'`` | Hex format. Outputs the number in base 16, using lower- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'X\'`` | Hex format. Outputs the number in base 16, using upper- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'d\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'d\'``. |\n +-----------+------------------------------------------------------------+\n\nIn addition to the above presentation types, integers can be formatted\nwith the floating point presentation types listed below (except\n``\'n\'`` and None). When doing so, ``float()`` is used to convert the\ninteger to a floating point number before formatting.\n\nThe available presentation types for floating point and decimal values\nare:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'e\'`` | Exponent notation. Prints the number in scientific |\n | | notation using the letter \'e\' to indicate the exponent. |\n +-----------+------------------------------------------------------------+\n | ``\'E\'`` | Exponent notation. Same as ``\'e\'`` except it uses an upper |\n | | case \'E\' as the separator character. |\n +-----------+------------------------------------------------------------+\n | ``\'f\'`` | Fixed point. Displays the number as a fixed-point number. |\n +-----------+------------------------------------------------------------+\n | ``\'F\'`` | Fixed point. Same as ``\'f\'``, but converts ``nan`` to |\n | | ``NAN`` and ``inf`` to ``INF``. |\n +-----------+------------------------------------------------------------+\n | ``\'g\'`` | General format. For a given precision ``p >= 1``, this |\n | | rounds the number to ``p`` significant digits and then |\n | | formats the result in either fixed-point format or in |\n | | scientific notation, depending on its magnitude. The |\n | | precise rules are as follows: suppose that the result |\n | | formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1`` would have exponent ``exp``. Then if ``-4 <= exp |\n | | < p``, the number is formatted with presentation type |\n | | ``\'f\'`` and precision ``p-1-exp``. Otherwise, the number |\n | | is formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1``. In both cases insignificant trailing zeros are |\n | | removed from the significand, and the decimal point is |\n | | also removed if there are no remaining digits following |\n | | it. Positive and negative infinity, positive and negative |\n | | zero, and nans, are formatted as ``inf``, ``-inf``, ``0``, |\n | | ``-0`` and ``nan`` respectively, regardless of the |\n | | precision. A precision of ``0`` is treated as equivalent |\n | | to a precision of ``1``. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets too large. The representations of |\n | | infinity and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'g\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | ``\'%\'`` | Percentage. Multiplies the number by 100 and displays in |\n | | fixed (``\'f\'``) format, followed by a percent sign. |\n +-----------+------------------------------------------------------------+\n | None | Similar to ``\'g\'``, except with at least one digit past |\n | | the decimal point and a default precision of 12. This is |\n | | intended to match ``str()``, except you can add the other |\n | | format modifiers. |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the new format syntax and comparison\nwith the old ``%``-formatting.\n\nIn most of the cases the syntax is similar to the old\n``%``-formatting, with the addition of the ``{}`` and with ``:`` used\ninstead of ``%``. For example, ``\'%03.2f\'`` can be translated to\n``\'{:03.2f}\'``.\n\nThe new format syntax also supports new and different options, shown\nin the follow examples.\n\nAccessing arguments by position:\n\n >>> \'{0}, {1}, {2}\'.format(\'a\', \'b\', \'c\')\n \'a, b, c\'\n >>> \'{}, {}, {}\'.format(\'a\', \'b\', \'c\') # 3.1+ only\n \'a, b, c\'\n >>> \'{2}, {1}, {0}\'.format(\'a\', \'b\', \'c\')\n \'c, b, a\'\n >>> \'{2}, {1}, {0}\'.format(*\'abc\') # unpacking argument sequence\n \'c, b, a\'\n >>> \'{0}{1}{0}\'.format(\'abra\', \'cad\') # arguments\' indices can be repeated\n \'abracadabra\'\n\nAccessing arguments by name:\n\n >>> \'Coordinates: {latitude}, {longitude}\'.format(latitude=\'37.24N\', longitude=\'-115.81W\')\n \'Coordinates: 37.24N, -115.81W\'\n >>> coord = {\'latitude\': \'37.24N\', \'longitude\': \'-115.81W\'}\n >>> \'Coordinates: {latitude}, {longitude}\'.format(**coord)\n \'Coordinates: 37.24N, -115.81W\'\n\nAccessing arguments\' attributes:\n\n >>> c = 3-5j\n >>> (\'The complex number {0} is formed from the real part {0.real} \'\n ... \'and the imaginary part {0.imag}.\').format(c)\n \'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.\'\n >>> class Point:\n ... def __init__(self, x, y):\n ... self.x, self.y = x, y\n ... def __str__(self):\n ... return \'Point({self.x}, {self.y})\'.format(self=self)\n ...\n >>> str(Point(4, 2))\n \'Point(4, 2)\'\n\nAccessing arguments\' items:\n\n >>> coord = (3, 5)\n >>> \'X: {0[0]}; Y: {0[1]}\'.format(coord)\n \'X: 3; Y: 5\'\n\nReplacing ``%s`` and ``%r``:\n\n >>> "repr() shows quotes: {!r}; str() doesn\'t: {!s}".format(\'test1\', \'test2\')\n "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n\nAligning the text and specifying a width:\n\n >>> \'{:<30}\'.format(\'left aligned\')\n \'left aligned \'\n >>> \'{:>30}\'.format(\'right aligned\')\n \' right aligned\'\n >>> \'{:^30}\'.format(\'centered\')\n \' centered \'\n >>> \'{:*^30}\'.format(\'centered\') # use \'*\' as a fill char\n \'***********centered***********\'\n\nReplacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign:\n\n >>> \'{:+f}; {:+f}\'.format(3.14, -3.14) # show it always\n \'+3.140000; -3.140000\'\n >>> \'{: f}; {: f}\'.format(3.14, -3.14) # show a space for positive numbers\n \' 3.140000; -3.140000\'\n >>> \'{:-f}; {:-f}\'.format(3.14, -3.14) # show only the minus -- same as \'{:f}; {:f}\'\n \'3.140000; -3.140000\'\n\nReplacing ``%x`` and ``%o`` and converting the value to different\nbases:\n\n >>> # format also supports binary numbers\n >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)\n \'int: 42; hex: 2a; oct: 52; bin: 101010\'\n >>> # with 0x, 0o, or 0b as prefix:\n >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)\n \'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010\'\n\nUsing the comma as a thousands separator:\n\n >>> \'{:,}\'.format(1234567890)\n \'1,234,567,890\'\n\nExpressing a percentage:\n\n >>> points = 19\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 86.36%\'\n\nUsing type-specific formatting:\n\n >>> import datetime\n >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n >>> \'{:%Y-%m-%d %H:%M:%S}\'.format(d)\n \'2010-07-04 12:15:58\'\n\nNesting arguments and more complex examples:\n\n >>> for align, text in zip(\'<^>\', [\'left\', \'center\', \'right\']):\n ... \'{0:{fill}{align}16}\'.format(text, fill=align, align=align)\n ...\n \'left<<<<<<<<<<<<\'\n \'^^^^^center^^^^^\'\n \'>>>>>>>>>>>right\'\n >>>\n >>> octets = [192, 168, 0, 1]\n >>> \'{:02X}{:02X}{:02X}{:02X}\'.format(*octets)\n \'C0A80001\'\n >>> int(_, 16)\n 3232235521\n >>>\n >>> width = 5\n >>> for num in range(5,12):\n ... for base in \'dXob\':\n ... print(\'{0:{width}{base}}\'.format(num, base=base, width=width), end=\' \')\n ... print()\n ...\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 8 10 1000\n 9 9 11 1001\n 10 A 12 1010\n 11 B 13 1011\n', + 'formatstrings': '\nFormat String Syntax\n********************\n\nThe ``str.format()`` method and the ``Formatter`` class share the same\nsyntax for format strings (although in the case of ``Formatter``,\nsubclasses can define their own format string syntax).\n\nFormat strings contain "replacement fields" surrounded by curly braces\n``{}``. Anything that is not contained in braces is considered literal\ntext, which is copied unchanged to the output. If you need to include\na brace character in the literal text, it can be escaped by doubling:\n``{{`` and ``}}``.\n\nThe grammar for a replacement field is as follows:\n\n replacement_field ::= "{" [field_name] ["!" conversion] [":" format_spec] "}"\n field_name ::= arg_name ("." attribute_name | "[" element_index "]")*\n arg_name ::= [identifier | integer]\n attribute_name ::= identifier\n element_index ::= integer | index_string\n index_string ::= +\n conversion ::= "r" | "s" | "a"\n format_spec ::= \n\nIn less formal terms, the replacement field can start with a\n*field_name* that specifies the object whose value is to be formatted\nand inserted into the output instead of the replacement field. The\n*field_name* is optionally followed by a *conversion* field, which is\npreceded by an exclamation point ``\'!\'``, and a *format_spec*, which\nis preceded by a colon ``\':\'``. These specify a non-default format\nfor the replacement value.\n\nSee also the *Format Specification Mini-Language* section.\n\nThe *field_name* itself begins with an *arg_name* that is either a\nnumber or a keyword. If it\'s a number, it refers to a positional\nargument, and if it\'s a keyword, it refers to a named keyword\nargument. If the numerical arg_names in a format string are 0, 1, 2,\n... in sequence, they can all be omitted (not just some) and the\nnumbers 0, 1, 2, ... will be automatically inserted in that order.\nBecause *arg_name* is not quote-delimited, it is not possible to\nspecify arbitrary dictionary keys (e.g., the strings ``\'10\'`` or\n``\':-]\'``) within a format string. The *arg_name* can be followed by\nany number of index or attribute expressions. An expression of the\nform ``\'.name\'`` selects the named attribute using ``getattr()``,\nwhile an expression of the form ``\'[index]\'`` does an index lookup\nusing ``__getitem__()``.\n\nChanged in version 3.1: The positional argument specifiers can be\nomitted, so ``\'{} {}\'`` is equivalent to ``\'{0} {1}\'``.\n\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\n "Bring me a {}" # Implicitly references the first positional argument\n "From {} to {}" # Same as "From {0} to {1}"\n "My quest is {name}" # References keyword argument \'name\'\n "Weight in tons {0.weight}" # \'weight\' attribute of first positional arg\n "Units destroyed: {players[0]}" # First element of keyword argument \'players\'.\n\nThe *conversion* field causes a type coercion before formatting.\nNormally, the job of formatting a value is done by the\n``__format__()`` method of the value itself. However, in some cases\nit is desirable to force a type to be formatted as a string,\noverriding its own definition of formatting. By converting the value\nto a string before calling ``__format__()``, the normal formatting\nlogic is bypassed.\n\nThree conversion flags are currently supported: ``\'!s\'`` which calls\n``str()`` on the value, ``\'!r\'`` which calls ``repr()`` and ``\'!a\'``\nwhich calls ``ascii()``.\n\nSome examples:\n\n "Harold\'s a clever {0!s}" # Calls str() on the argument first\n "Bring out the holy {name!r}" # Calls repr() on the argument first\n "More {!a}" # Calls ascii() on the argument first\n\nThe *format_spec* field contains a specification of how the value\nshould be presented, including such details as field width, alignment,\npadding, decimal precision and so on. Each value type can define its\nown "formatting mini-language" or interpretation of the *format_spec*.\n\nMost built-in types support a common formatting mini-language, which\nis described in the next section.\n\nA *format_spec* field can also include nested replacement fields\nwithin it. These nested replacement fields can contain only a field\nname; conversion flags and format specifications are not allowed. The\nreplacement fields within the format_spec are substituted before the\n*format_spec* string is interpreted. This allows the formatting of a\nvalue to be dynamically specified.\n\nSee the *Format examples* section for some examples.\n\n\nFormat Specification Mini-Language\n==================================\n\n"Format specifications" are used within replacement fields contained\nwithin a format string to define how individual values are presented\n(see *Format String Syntax*). They can also be passed directly to the\nbuilt-in ``format()`` function. Each formattable type may define how\nthe format specification is to be interpreted.\n\nMost built-in types implement the following options for format\nspecifications, although some of the formatting options are only\nsupported by the numeric types.\n\nA general convention is that an empty format string (``""``) produces\nthe same result as if you had called ``str()`` on the value. A non-\nempty format string typically modifies the result.\n\nThe general form of a *standard format specifier* is:\n\n format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]\n fill ::= \n align ::= "<" | ">" | "=" | "^"\n sign ::= "+" | "-" | " "\n width ::= integer\n precision ::= integer\n type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n\nThe *fill* character can be any character other than \'{\' or \'}\'. The\npresence of a fill character is signaled by the character following\nit, which must be one of the alignment options. If the second\ncharacter of *format_spec* is not a valid alignment option, then it is\nassumed that both the fill character and the alignment option are\nabsent.\n\nThe meaning of the various alignment options is as follows:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'<\'`` | Forces the field to be left-aligned within the available |\n | | space (this is the default for most objects). |\n +-----------+------------------------------------------------------------+\n | ``\'>\'`` | Forces the field to be right-aligned within the available |\n | | space (this is the default for numbers). |\n +-----------+------------------------------------------------------------+\n | ``\'=\'`` | Forces the padding to be placed after the sign (if any) |\n | | but before the digits. This is used for printing fields |\n | | in the form \'+000000120\'. This alignment option is only |\n | | valid for numeric types. |\n +-----------+------------------------------------------------------------+\n | ``\'^\'`` | Forces the field to be centered within the available |\n | | space. |\n +-----------+------------------------------------------------------------+\n\nNote that unless a minimum field width is defined, the field width\nwill always be the same size as the data to fill it, so that the\nalignment option has no meaning in this case.\n\nThe *sign* option is only valid for number types, and can be one of\nthe following:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'+\'`` | indicates that a sign should be used for both positive as |\n | | well as negative numbers. |\n +-----------+------------------------------------------------------------+\n | ``\'-\'`` | indicates that a sign should be used only for negative |\n | | numbers (this is the default behavior). |\n +-----------+------------------------------------------------------------+\n | space | indicates that a leading space should be used on positive |\n | | numbers, and a minus sign on negative numbers. |\n +-----------+------------------------------------------------------------+\n\nThe ``\'#\'`` option causes the "alternate form" to be used for the\nconversion. The alternate form is defined differently for different\ntypes. This option is only valid for integer, float, complex and\nDecimal types. For integers, when binary, octal, or hexadecimal output\nis used, this option adds the prefix respective ``\'0b\'``, ``\'0o\'``, or\n``\'0x\'`` to the output value. For floats, complex and Decimal the\nalternate form causes the result of the conversion to always contain a\ndecimal-point character, even if no digits follow it. Normally, a\ndecimal-point character appears in the result of these conversions\nonly if a digit follows it. In addition, for ``\'g\'`` and ``\'G\'``\nconversions, trailing zeros are not removed from the result.\n\nThe ``\',\'`` option signals the use of a comma for a thousands\nseparator. For a locale aware separator, use the ``\'n\'`` integer\npresentation type instead.\n\nChanged in version 3.1: Added the ``\',\'`` option (see also **PEP\n378**).\n\n*width* is a decimal integer defining the minimum field width. If not\nspecified, then the field width will be determined by the content.\n\nPreceding the *width* field by a zero (``\'0\'``) character enables\nsign-aware zero-padding for numeric types. This is equivalent to a\n*fill* character of ``\'0\'`` with an *alignment* type of ``\'=\'``.\n\nThe *precision* is a decimal number indicating how many digits should\nbe displayed after the decimal point for a floating point value\nformatted with ``\'f\'`` and ``\'F\'``, or before and after the decimal\npoint for a floating point value formatted with ``\'g\'`` or ``\'G\'``.\nFor non-number types the field indicates the maximum field size - in\nother words, how many characters will be used from the field content.\nThe *precision* is not allowed for integer values.\n\nFinally, the *type* determines how the data should be presented.\n\nThe available string presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'s\'`` | String format. This is the default type for strings and |\n | | may be omitted. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'s\'``. |\n +-----------+------------------------------------------------------------+\n\nThe available integer presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'b\'`` | Binary format. Outputs the number in base 2. |\n +-----------+------------------------------------------------------------+\n | ``\'c\'`` | Character. Converts the integer to the corresponding |\n | | unicode character before printing. |\n +-----------+------------------------------------------------------------+\n | ``\'d\'`` | Decimal Integer. Outputs the number in base 10. |\n +-----------+------------------------------------------------------------+\n | ``\'o\'`` | Octal format. Outputs the number in base 8. |\n +-----------+------------------------------------------------------------+\n | ``\'x\'`` | Hex format. Outputs the number in base 16, using lower- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'X\'`` | Hex format. Outputs the number in base 16, using upper- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'d\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'d\'``. |\n +-----------+------------------------------------------------------------+\n\nIn addition to the above presentation types, integers can be formatted\nwith the floating point presentation types listed below (except\n``\'n\'`` and None). When doing so, ``float()`` is used to convert the\ninteger to a floating point number before formatting.\n\nThe available presentation types for floating point and decimal values\nare:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'e\'`` | Exponent notation. Prints the number in scientific |\n | | notation using the letter \'e\' to indicate the exponent. |\n +-----------+------------------------------------------------------------+\n | ``\'E\'`` | Exponent notation. Same as ``\'e\'`` except it uses an upper |\n | | case \'E\' as the separator character. |\n +-----------+------------------------------------------------------------+\n | ``\'f\'`` | Fixed point. Displays the number as a fixed-point number. |\n +-----------+------------------------------------------------------------+\n | ``\'F\'`` | Fixed point. Same as ``\'f\'``, but converts ``nan`` to |\n | | ``NAN`` and ``inf`` to ``INF``. |\n +-----------+------------------------------------------------------------+\n | ``\'g\'`` | General format. For a given precision ``p >= 1``, this |\n | | rounds the number to ``p`` significant digits and then |\n | | formats the result in either fixed-point format or in |\n | | scientific notation, depending on its magnitude. The |\n | | precise rules are as follows: suppose that the result |\n | | formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1`` would have exponent ``exp``. Then if ``-4 <= exp |\n | | < p``, the number is formatted with presentation type |\n | | ``\'f\'`` and precision ``p-1-exp``. Otherwise, the number |\n | | is formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1``. In both cases insignificant trailing zeros are |\n | | removed from the significand, and the decimal point is |\n | | also removed if there are no remaining digits following |\n | | it. Positive and negative infinity, positive and negative |\n | | zero, and nans, are formatted as ``inf``, ``-inf``, ``0``, |\n | | ``-0`` and ``nan`` respectively, regardless of the |\n | | precision. A precision of ``0`` is treated as equivalent |\n | | to a precision of ``1``. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets too large. The representations of |\n | | infinity and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'g\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | ``\'%\'`` | Percentage. Multiplies the number by 100 and displays in |\n | | fixed (``\'f\'``) format, followed by a percent sign. |\n +-----------+------------------------------------------------------------+\n | None | Similar to ``\'g\'``, except with at least one digit past |\n | | the decimal point and a default precision of 12. This is |\n | | intended to match ``str()``, except you can add the other |\n | | format modifiers. |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the new format syntax and comparison\nwith the old ``%``-formatting.\n\nIn most of the cases the syntax is similar to the old\n``%``-formatting, with the addition of the ``{}`` and with ``:`` used\ninstead of ``%``. For example, ``\'%03.2f\'`` can be translated to\n``\'{:03.2f}\'``.\n\nThe new format syntax also supports new and different options, shown\nin the follow examples.\n\nAccessing arguments by position:\n\n >>> \'{0}, {1}, {2}\'.format(\'a\', \'b\', \'c\')\n \'a, b, c\'\n >>> \'{}, {}, {}\'.format(\'a\', \'b\', \'c\') # 3.1+ only\n \'a, b, c\'\n >>> \'{2}, {1}, {0}\'.format(\'a\', \'b\', \'c\')\n \'c, b, a\'\n >>> \'{2}, {1}, {0}\'.format(*\'abc\') # unpacking argument sequence\n \'c, b, a\'\n >>> \'{0}{1}{0}\'.format(\'abra\', \'cad\') # arguments\' indices can be repeated\n \'abracadabra\'\n\nAccessing arguments by name:\n\n >>> \'Coordinates: {latitude}, {longitude}\'.format(latitude=\'37.24N\', longitude=\'-115.81W\')\n \'Coordinates: 37.24N, -115.81W\'\n >>> coord = {\'latitude\': \'37.24N\', \'longitude\': \'-115.81W\'}\n >>> \'Coordinates: {latitude}, {longitude}\'.format(**coord)\n \'Coordinates: 37.24N, -115.81W\'\n\nAccessing arguments\' attributes:\n\n >>> c = 3-5j\n >>> (\'The complex number {0} is formed from the real part {0.real} \'\n ... \'and the imaginary part {0.imag}.\').format(c)\n \'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.\'\n >>> class Point:\n ... def __init__(self, x, y):\n ... self.x, self.y = x, y\n ... def __str__(self):\n ... return \'Point({self.x}, {self.y})\'.format(self=self)\n ...\n >>> str(Point(4, 2))\n \'Point(4, 2)\'\n\nAccessing arguments\' items:\n\n >>> coord = (3, 5)\n >>> \'X: {0[0]}; Y: {0[1]}\'.format(coord)\n \'X: 3; Y: 5\'\n\nReplacing ``%s`` and ``%r``:\n\n >>> "repr() shows quotes: {!r}; str() doesn\'t: {!s}".format(\'test1\', \'test2\')\n "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n\nAligning the text and specifying a width:\n\n >>> \'{:<30}\'.format(\'left aligned\')\n \'left aligned \'\n >>> \'{:>30}\'.format(\'right aligned\')\n \' right aligned\'\n >>> \'{:^30}\'.format(\'centered\')\n \' centered \'\n >>> \'{:*^30}\'.format(\'centered\') # use \'*\' as a fill char\n \'***********centered***********\'\n\nReplacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign:\n\n >>> \'{:+f}; {:+f}\'.format(3.14, -3.14) # show it always\n \'+3.140000; -3.140000\'\n >>> \'{: f}; {: f}\'.format(3.14, -3.14) # show a space for positive numbers\n \' 3.140000; -3.140000\'\n >>> \'{:-f}; {:-f}\'.format(3.14, -3.14) # show only the minus -- same as \'{:f}; {:f}\'\n \'3.140000; -3.140000\'\n\nReplacing ``%x`` and ``%o`` and converting the value to different\nbases:\n\n >>> # format also supports binary numbers\n >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)\n \'int: 42; hex: 2a; oct: 52; bin: 101010\'\n >>> # with 0x, 0o, or 0b as prefix:\n >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)\n \'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010\'\n\nUsing the comma as a thousands separator:\n\n >>> \'{:,}\'.format(1234567890)\n \'1,234,567,890\'\n\nExpressing a percentage:\n\n >>> points = 19\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 86.36%\'\n\nUsing type-specific formatting:\n\n >>> import datetime\n >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n >>> \'{:%Y-%m-%d %H:%M:%S}\'.format(d)\n \'2010-07-04 12:15:58\'\n\nNesting arguments and more complex examples:\n\n >>> for align, text in zip(\'<^>\', [\'left\', \'center\', \'right\']):\n ... \'{0:{fill}{align}16}\'.format(text, fill=align, align=align)\n ...\n \'left<<<<<<<<<<<<\'\n \'^^^^^center^^^^^\'\n \'>>>>>>>>>>>right\'\n >>>\n >>> octets = [192, 168, 0, 1]\n >>> \'{:02X}{:02X}{:02X}{:02X}\'.format(*octets)\n \'C0A80001\'\n >>> int(_, 16)\n 3232235521\n >>>\n >>> width = 5\n >>> for num in range(5,12):\n ... for base in \'dXob\':\n ... print(\'{0:{width}{base}}\'.format(num, base=base, width=width), end=\' \')\n ... print()\n ...\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 8 10 1000\n 9 9 11 1001\n 10 A 12 1010\n 11 B 13 1011\n', 'function': '\nFunction definitions\n********************\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more parameters have the form *parameter* ``=``\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding argument may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters up until the "``*``" must also have a default value ---\nthis is a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use ``None`` as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A "``def``"\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n', 'global': '\nThe ``global`` statement\n************************\n\n global_stmt ::= "global" identifier ("," identifier)*\n\nThe ``global`` statement is a declaration which holds for the entire\ncurrent code block. It means that the listed identifiers are to be\ninterpreted as globals. It would be impossible to assign to a global\nvariable without ``global``, although free variables may refer to\nglobals without being declared global.\n\nNames listed in a ``global`` statement must not be used in the same\ncode block textually preceding that ``global`` statement.\n\nNames listed in a ``global`` statement must not be defined as formal\nparameters or in a ``for`` loop control target, ``class`` definition,\nfunction definition, or ``import`` statement.\n\n**CPython implementation detail:** The current implementation does not\nenforce the latter two restrictions, but programs should not abuse\nthis freedom, as future implementations may enforce them or silently\nchange the meaning of the program.\n\n**Programmer\'s note:** the ``global`` is a directive to the parser.\nIt applies only to code parsed at the same time as the ``global``\nstatement. In particular, a ``global`` statement contained in a string\nor code object supplied to the built-in ``exec()`` function does not\naffect the code block *containing* the function call, and code\ncontained in such a string is unaffected by ``global`` statements in\nthe code containing the function call. The same applies to the\n``eval()`` and ``compile()`` functions.\n', 'id-classes': '\nReserved classes of identifiers\n*******************************\n\nCertain classes of identifiers (besides keywords) have special\nmeanings. These classes are identified by the patterns of leading and\ntrailing underscore characters:\n\n``_*``\n Not imported by ``from module import *``. The special identifier\n ``_`` is used in the interactive interpreter to store the result of\n the last evaluation; it is stored in the ``builtins`` module. When\n not in interactive mode, ``_`` has no special meaning and is not\n defined. See section *The import statement*.\n\n Note: The name ``_`` is often used in conjunction with\n internationalization; refer to the documentation for the\n ``gettext`` module for more information on this convention.\n\n``__*__``\n System-defined names. These names are defined by the interpreter\n and its implementation (including the standard library). Current\n system names are discussed in the *Special method names* section\n and elsewhere. More will likely be defined in future versions of\n Python. *Any* use of ``__*__`` names, in any context, that does\n not follow explicitly documented use, is subject to breakage\n without warning.\n\n``__*``\n Class-private names. Names in this category, when used within the\n context of a class definition, are re-written to use a mangled form\n to help avoid name clashes between "private" attributes of base and\n derived classes. See section *Identifiers (Names)*.\n', @@ -61,18 +61,18 @@ 'slicings': '\nSlicings\n********\n\nA slicing selects a range of items in a sequence object (e.g., a\nstring, tuple or list). Slicings may be used as expressions or as\ntargets in assignment or ``del`` statements. The syntax for a\nslicing:\n\n slicing ::= primary "[" slice_list "]"\n slice_list ::= slice_item ("," slice_item)* [","]\n slice_item ::= expression | proper_slice\n proper_slice ::= [lower_bound] ":" [upper_bound] [ ":" [stride] ]\n lower_bound ::= expression\n upper_bound ::= expression\n stride ::= expression\n\nThere is ambiguity in the formal syntax here: anything that looks like\nan expression list also looks like a slice list, so any subscription\ncan be interpreted as a slicing. Rather than further complicating the\nsyntax, this is disambiguated by defining that in this case the\ninterpretation as a subscription takes priority over the\ninterpretation as a slicing (this is the case if the slice list\ncontains no proper slice).\n\nThe semantics for a slicing are as follows. The primary must evaluate\nto a mapping object, and it is indexed (using the same\n``__getitem__()`` method as normal subscription) with a key that is\nconstructed from the slice list, as follows. If the slice list\ncontains at least one comma, the key is a tuple containing the\nconversion of the slice items; otherwise, the conversion of the lone\nslice item is the key. The conversion of a slice item that is an\nexpression is that expression. The conversion of a proper slice is a\nslice object (see section *The standard type hierarchy*) whose\n``start``, ``stop`` and ``step`` attributes are the values of the\nexpressions given as lower bound, upper bound and stride,\nrespectively, substituting ``None`` for missing expressions.\n', 'specialattrs': '\nSpecial Attributes\n******************\n\nThe implementation adds a few special read-only attributes to several\nobject types, where they are relevant. Some of these are not reported\nby the ``dir()`` built-in function.\n\nobject.__dict__\n\n A dictionary or other mapping object used to store an object\'s\n (writable) attributes.\n\ninstance.__class__\n\n The class to which a class instance belongs.\n\nclass.__bases__\n\n The tuple of base classes of a class object.\n\nclass.__name__\n\n The name of the class or type.\n\nclass.__qualname__\n\n The *qualified name* of the class or type.\n\n New in version 3.3.\n\nclass.__mro__\n\n This attribute is a tuple of classes that are considered when\n looking for base classes during method resolution.\n\nclass.mro()\n\n This method can be overridden by a metaclass to customize the\n method resolution order for its instances. It is called at class\n instantiation, and its result is stored in ``__mro__``.\n\nclass.__subclasses__()\n\n Each class keeps a list of weak references to its immediate\n subclasses. This method returns a list of all those references\n still alive. Example:\n\n >>> int.__subclasses__()\n []\n\n-[ Footnotes ]-\n\n[1] Additional information on these special methods may be found in\n the Python Reference Manual (*Basic customization*).\n\n[2] As a consequence, the list ``[1, 2]`` is considered equal to\n ``[1.0, 2.0]``, and similarly for tuples.\n\n[3] They must have since the parser can\'t tell the type of the\n operands.\n\n[4] Cased characters are those with general category property being\n one of "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt"\n (Letter, titlecase).\n\n[5] To format only a tuple you should therefore provide a singleton\n tuple whose only element is the tuple to be formatted.\n', 'specialnames': '\nSpecial method names\n********************\n\nA class can implement certain operations that are invoked by special\nsyntax (such as arithmetic operations or subscripting and slicing) by\ndefining methods with special names. This is Python\'s approach to\n*operator overloading*, allowing classes to define their own behavior\nwith respect to language operators. For instance, if a class defines\na method named ``__getitem__()``, and ``x`` is an instance of this\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``TypeError``).\n\nWhen implementing a class that emulates any built-in type, it is\nimportant that the emulation only be implemented to the degree that it\nmakes sense for the object being modelled. For example, some\nsequences may work well with retrieval of individual elements, but\nextracting a slice may not make sense. (One example of this is the\n``NodeList`` interface in the W3C\'s Document Object Model.)\n\n\nBasic customization\n===================\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n for the ``gc`` module for more information about how\n ``__del__()`` methods are handled by the cycle detector,\n particularly the description of the ``garbage`` value.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the ``str()`` built-in function and by the ``print()``\n function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n\n\nCustomizing attribute access\n============================\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n--------------------\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n---------\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\n\nThe following methods are used to override the default behavior of the\n``isinstance()`` and ``issubclass()`` built-in functions.\n\nIn particular, the metaclass ``abc.ABCMeta`` implements these methods\nin order to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n ``isinstance(instance, class)``.\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n ``issubclass(subclass, class)``.\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also:\n\n **PEP 3119** - Introducing Abstract Base Classes\n Includes the specification for customizing ``isinstance()`` and\n ``issubclass()`` behavior through ``__instancecheck__()`` and\n ``__subclasscheck__()``, with motivation for this functionality\n in the context of adding Abstract Base Classes (see the ``abc``\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, ``x(arg1, arg2, ...)`` is a shorthand for\n ``x.__call__(arg1, arg2, ...)``.\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which ``0 <= k < N``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function ``len()``. Should return\n the length of the object, an integer ``>=`` 0. Also, an object\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\nNote: Slicing is done exclusively with the following three methods. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n should be raised.\n\n Note: ``for`` loops expect that an ``IndexError`` will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the ``__getitem__()`` method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the ``__getitem__()``\n method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method ``keys()``.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the ``reversed()`` built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the ``__reversed__()`` method is not provided, the\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\n\nThe membership test operators (``in`` and ``not in``) are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define ``__contains__()``, the membership\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__truediv__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return ``NotImplemented``.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\n ``**=``, ``<<=``, ``>>=``, ``&=``, ``^=``, ``|=``). These methods\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n considered, as with the evaluation of ``x + y``.\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations (``-``, ``+``,\n ``abs()`` and ``~``).\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: object of type \'C\' has no len()\n\nThe rationale behind this behaviour lies with a number of special\nmethods such as ``__hash__()`` and ``__repr__()`` that are implemented\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen invoked on the type object itself:\n\n >>> 1 .__hash__() == hash(1)\n True\n >>> int.__hash__() == hash(int)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe ``__getattribute__()`` method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print("Metaclass getattribute invoked")\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object, metaclass=Meta):\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print("Class getattribute invoked")\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the ``__getattribute__()`` machinery in this fashion\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n handled incorrectly.\n\n[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', - 'string-methods': '\nString Methods\n**************\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the universal newlines approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', + 'string-methods': '\nString Methods\n**************\n\nStrings implement all of the *common* sequence operations, along with\nthe additional methods described below.\n\nStrings also support two styles of string formatting, one providing a\nlarge degree of flexibility and customization (see ``str.format()``,\n*Format String Syntax* and *String Formatting*) and the other based on\nC ``printf`` style formatting that handles a narrower range of types\nand is slightly harder to use correctly, but is often faster for the\ncases it can handle (*printf-style String Formatting*).\n\nThe *Text Processing Services* section of the standard library covers\na number of other modules that provide various text related utilities\n(including regular expression support in the ``re`` module).\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the *universal newlines* approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n\', \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', 'strings': '\nString and Bytes literals\n*************************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "R" | "U"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'" | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | stringescapeseq\n longstringitem ::= longstringchar | stringescapeseq\n shortstringchar ::= \n longstringchar ::= \n stringescapeseq ::= "\\" \n\n bytesliteral ::= bytesprefix(shortbytes | longbytes)\n bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"\n shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' shortbytesitem* \'"\'\n longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' longbytesitem* \'"""\'\n shortbytesitem ::= shortbyteschar | bytesescapeseq\n longbytesitem ::= longbyteschar | bytesescapeseq\n shortbyteschar ::= \n longbyteschar ::= \n bytesescapeseq ::= "\\" \n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the ``stringprefix`` or\n``bytesprefix`` and the rest of the literal. The source character set\nis defined by the encoding declaration; it is UTF-8 if no encoding\ndeclaration is given in the source file; see section *Encoding\ndeclarations*.\n\nIn plain English: Both types of literals can be enclosed in matching\nsingle quotes (``\'``) or double quotes (``"``). They can also be\nenclosed in matching groups of three single or double quotes (these\nare generally referred to as *triple-quoted strings*). The backslash\n(``\\``) character is used to escape characters that otherwise have a\nspecial meaning, such as newline, backslash itself, or the quote\ncharacter.\n\nBytes literals are always prefixed with ``\'b\'`` or ``\'B\'``; they\nproduce an instance of the ``bytes`` type instead of the ``str`` type.\nThey may only contain ASCII characters; bytes with a numeric value of\n128 or greater must be expressed with escapes.\n\nAs of Python 3.3 it is possible again to prefix unicode strings with a\n``u`` prefix to simplify maintenance of dual 2.x and 3.x codebases.\n\nBoth string and bytes literals may optionally be prefixed with a\nletter ``\'r\'`` or ``\'R\'``; such strings are called *raw strings* and\ntreat backslashes as literal characters. As a result, in string\nliterals, ``\'\\U\'`` and ``\'\\u\'`` escapes in raw strings are not treated\nspecially. Given that Python 2.x\'s raw unicode literals behave\ndifferently than Python 3.x\'s the ``\'ur\'`` syntax is not supported.\n\n New in version 3.3: The ``\'rb\'`` prefix of raw bytes literals has\n been added as a synonym of ``\'br\'``.\n\n New in version 3.3: Support for the unicode legacy literal\n (``u\'value\'``) was reintroduced to simplify the maintenance of dual\n Python 2.x and 3.x codebases. See **PEP 414** for more information.\n\nIn triple-quoted strings, unescaped newlines and quotes are allowed\n(and are retained), except that three unescaped quotes in a row\nterminate the string. (A "quote" is the character used to open the\nstring, i.e. either ``\'`` or ``"``.)\n\nUnless an ``\'r\'`` or ``\'R\'`` prefix is present, escape sequences in\nstrings are interpreted according to rules similar to those used by\nStandard C. The recognized escape sequences are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\newline`` | Backslash and newline ignored | |\n+-------------------+-----------------------------------+---------+\n| ``\\\\`` | Backslash (``\\``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\\'`` | Single quote (``\'``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\"`` | Double quote (``"``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\a`` | ASCII Bell (BEL) | |\n+-------------------+-----------------------------------+---------+\n| ``\\b`` | ASCII Backspace (BS) | |\n+-------------------+-----------------------------------+---------+\n| ``\\f`` | ASCII Formfeed (FF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\n`` | ASCII Linefeed (LF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\r`` | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| ``\\t`` | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| ``\\v`` | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| ``\\ooo`` | Character with octal value *ooo* | (1,3) |\n+-------------------+-----------------------------------+---------+\n| ``\\xhh`` | Character with hex value *hh* | (2,3) |\n+-------------------+-----------------------------------+---------+\n\nEscape sequences only recognized in string literals are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\N{name}`` | Character named *name* in the | (4) |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (5) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (6) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, exactly two hex digits are required.\n\n3. In a bytes literal, hexadecimal and octal escapes denote the byte\n with the given value. In a string literal, these escapes denote a\n Unicode character with the given value.\n\n4. Changed in version 3.3: Support for name aliases [1] has been\n added.\n\n5. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Exactly four hex digits are\n required.\n\n6. Any Unicode character can be encoded this way, but characters\n outside the Basic Multilingual Plane (BMP) will be encoded using a\n surrogate pair if Python is compiled to use 16-bit code units (the\n default). Exactly eight hex digits are required.\n\nUnlike Standard C, all unrecognized escape sequences are left in the\nstring unchanged, i.e., *the backslash is left in the string*. (This\nbehavior is useful when debugging: if an escape sequence is mistyped,\nthe resulting output is more easily recognized as broken.) It is also\nimportant to note that the escape sequences only recognized in string\nliterals fall into the category of unrecognized escapes for bytes\nliterals.\n\nEven in a raw string, string quotes can be escaped with a backslash,\nbut the backslash remains in the string; for example, ``r"\\""`` is a\nvalid string literal consisting of two characters: a backslash and a\ndouble quote; ``r"\\"`` is not a valid string literal (even a raw\nstring cannot end in an odd number of backslashes). Specifically, *a\nraw string cannot end in a single backslash* (since the backslash\nwould escape the following quote character). Note also that a single\nbackslash followed by a newline is interpreted as those two characters\nas part of the string, *not* as a line continuation.\n', 'subscriptions': '\nSubscriptions\n*************\n\nA subscription selects an item of a sequence (string, tuple or list)\nor mapping (dictionary) object:\n\n subscription ::= primary "[" expression_list "]"\n\nThe primary must evaluate to an object that supports subscription,\ne.g. a list or dictionary. User-defined objects can support\nsubscription by defining a ``__getitem__()`` method.\n\nFor built-in objects, there are two types of objects that support\nsubscription:\n\nIf the primary is a mapping, the expression list must evaluate to an\nobject whose value is one of the keys of the mapping, and the\nsubscription selects the value in the mapping that corresponds to that\nkey. (The expression list is a tuple except if it has exactly one\nitem.)\n\nIf the primary is a sequence, the expression (list) must evaluate to\nan integer or a slice (as discussed in the following section).\n\nThe formal syntax makes no special provision for negative indices in\nsequences; however, built-in sequences all provide a ``__getitem__()``\nmethod that interprets negative indices by adding the length of the\nsequence to the index (so that ``x[-1]`` selects the last item of\n``x``). The resulting value must be a nonnegative integer less than\nthe number of items in the sequence, and the subscription selects the\nitem whose index is that value (counting from zero). Since the support\nfor negative indices and slicing occurs in the object\'s\n``__getitem__()`` method, subclasses overriding this method will need\nto explicitly add that support.\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n', 'truth': "\nTruth Value Testing\n*******************\n\nAny object can be tested for truth value, for use in an ``if`` or\n``while`` condition or as operand of the Boolean operations below. The\nfollowing values are considered false:\n\n* ``None``\n\n* ``False``\n\n* zero of any numeric type, for example, ``0``, ``0.0``, ``0j``.\n\n* any empty sequence, for example, ``''``, ``()``, ``[]``.\n\n* any empty mapping, for example, ``{}``.\n\n* instances of user-defined classes, if the class defines a\n ``__bool__()`` or ``__len__()`` method, when that method returns the\n integer zero or ``bool`` value ``False``. [1]\n\nAll other values are considered true --- so objects of many types are\nalways true.\n\nOperations and built-in functions that have a Boolean result always\nreturn ``0`` or ``False`` for false and ``1`` or ``True`` for true,\nunless otherwise stated. (Important exception: the Boolean operations\n``or`` and ``and`` always return one of their operands.)\n", - 'try': '\nThe ``try`` statement\n*********************\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception, it is re-raised at the end\nof the ``finally`` clause. If the ``finally`` clause raises another\nexception or executes a ``return`` or ``break`` statement, the saved\nexception is set as the context of the new exception. The exception\ninformation is not available to the program during execution of the\n``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', + 'try': '\nThe ``try`` statement\n*********************\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception or ``break`` statement, it is\nre-raised at the end of the ``finally`` clause. If the ``finally``\nclause raises another exception the saved exception is set as the\ncontext of the new exception; if the ``finally`` clause executes a\n``return`` statement, the saved exception is discarded:\n\n def f():\n try:\n 1/0\n finally:\n return 42\n\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the ``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', 'types': '\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.), although such additions\nwill often be provided via the standard library instead.\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name ``None``.\n It is used to signify the absence of a value in many situations,\n e.g., it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n ``NotImplemented``. Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the literal ``...`` or the\n built-in name ``Ellipsis``. Its truth value is true.\n\n``numbers.Number``\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n ``numbers.Integral``\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are two types of integers:\n\n Integers (``int``)\n\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, and Boolean values behave like the values 0 and 1,\n respectively, in almost all contexts, the exception being\n that when converted to a string, the strings ``"False"`` or\n ``"True"`` are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers.\n\n ``numbers.Real`` (``float``)\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these is\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n ``numbers.Complex`` (``complex``)\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number ``z`` can be retrieved through the read-only\n attributes ``z.real`` and ``z.imag``.\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function ``len()`` returns the number of\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is selected by ``a[i]``.\n\n Sequences also support slicing: ``a[i:j]`` selects all items with\n index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: ``a[i:j:k]`` selects all items of *a* with index *x*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'`` and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and ``del`` (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in ``bytearray()`` constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module ``array`` provides an additional example of\n a mutable sequence type, as does the ``collections`` module.\n\nSet types\n These represent unordered, finite sets of unique, immutable\n objects. As such, they cannot be indexed by any subscript. However,\n they can be iterated over, and the built-in function ``len()``\n returns the number of items in a set. Common uses for sets are fast\n membership testing, removing duplicates from a sequence, and\n computing mathematical operations such as intersection, union,\n difference, and symmetric difference.\n\n For set elements, the same immutability rules apply as for\n dictionary keys. Note that numeric types obey the normal rules for\n numeric comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``), only one of them can be contained in a set.\n\n There are currently two intrinsic set types:\n\n Sets\n These represent a mutable set. They are created by the built-in\n ``set()`` constructor and can be modified afterwards by several\n methods, such as ``add()``.\n\n Frozen sets\n These represent an immutable set. They are created by the\n built-in ``frozenset()`` constructor. As a frozenset is\n immutable and *hashable*, it can be used again as an element of\n another set, or as a dictionary key.\n\nMappings\n These represent finite sets of objects indexed by arbitrary index\n sets. The subscript notation ``a[k]`` selects the item indexed by\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``len()`` returns the number of items in a mapping.\n\n There is currently a single intrinsic mapping type:\n\n Dictionaries\n These represent finite sets of objects indexed by nearly\n arbitrary values. The only types of values not acceptable as\n keys are values containing lists or dictionaries or other\n mutable types that are compared by value rather than by object\n identity, the reason being that the efficient implementation of\n dictionaries requires a key\'s hash value to remain constant.\n Numeric types used for keys obey the normal rules for numeric\n comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``) then they can be used interchangeably to index the same\n dictionary entry.\n\n Dictionaries are mutable; they can be created by the ``{...}``\n notation (see section *Dictionary displays*).\n\n The extension modules ``dbm.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\n\nCallable types\n These are the types to which the function call operation (see\n section *Calls*) can be applied:\n\n User-defined functions\n A user-defined function object is created by a function\n definition (see section *Function definitions*). It should be\n called with an argument list containing the same number of items\n as the function\'s formal parameter list.\n\n Special attributes:\n\n +---------------------------+---------------------------------+-------------+\n | Attribute | Meaning | |\n +===========================+=================================+=============+\n | ``__doc__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\n +---------------------------+---------------------------------+-------------+\n | ``__module__`` | The name of the module the | Writable |\n | | function was defined in, or | |\n | | ``None`` if unavailable. | |\n +---------------------------+---------------------------------+-------------+\n | ``__defaults__`` | A tuple containing default | Writable |\n | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | that holds the function\'s | |\n | | global variables --- the global | |\n | | namespace of the module in | |\n | | which the function was defined. | |\n +---------------------------+---------------------------------+-------------+\n | ``__dict__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | or ``\'return\'`` for the return | |\n | | annotation, if provided. | |\n +---------------------------+---------------------------------+-------------+\n | ``__kwdefaults__`` | A dict containing defaults for | Writable |\n | | keyword-only parameters. | |\n +---------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\n\n Function objects also support getting and setting arbitrary\n attributes, which can be used, for example, to attach metadata\n to functions. Regular attribute dot-notation is used to get and\n set such attributes. *Note that the current implementation only\n supports function attributes on user-defined functions. Function\n attributes on built-in functions may be supported in the\n future.*\n\n Additional information about a function\'s definition can be\n retrieved from its code object; see the description of internal\n types below.\n\n Instance methods\n An instance method object combines a class, a class instance and\n any callable object (normally a user-defined function).\n\n Special read-only attributes: ``__self__`` is the class instance\n object, ``__func__`` is the function object; ``__doc__`` is the\n method\'s documentation (same as ``__func__.__doc__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\n\n Methods also support accessing (but not setting) the arbitrary\n function attributes on the underlying function object.\n\n User-defined method objects may be created when getting an\n attribute of a class (perhaps via an instance of that class), if\n that attribute is a user-defined function object or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__func__``\n attribute is the original function object.\n\n When a user-defined method object is created by retrieving\n another method object from a class or instance, the behaviour is\n the same as for a function object, except that the ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n of the class.\n\n Generator functions\n A function or method which uses the ``yield`` statement (see\n section *The yield statement*) is called a *generator function*.\n Such a function, when called, always returns an iterator object\n which can be used to execute the body of the function: calling\n the iterator\'s ``__next__()`` method will cause the function to\n execute until it provides a value using the ``yield`` statement.\n When the function executes a ``return`` statement or falls off\n the end, a ``StopIteration`` exception is raised and the\n iterator will have reached the end of the set of values to be\n returned.\n\n Built-in functions\n A built-in function object is a wrapper around a C function.\n Examples of built-in functions are ``len()`` and ``math.sin()``\n (``math`` is a standard built-in module). The number and type of\n the arguments are determined by the C function. Special read-\n only attributes: ``__doc__`` is the function\'s documentation\n string, or ``None`` if unavailable; ``__name__`` is the\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined in or ``None`` if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n ``alist.append()``, assuming *alist* is a list object. In this\n case, the special read-only attribute ``__self__`` is set to the\n object denoted by *alist*.\n\n Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the ``import``\n statement (see ``import``), or by calling functions such as\n ``importlib.import_module()`` and built-in ``__import__()``. A\n module object has a namespace implemented by a dictionary object\n (this is the dictionary referenced by the ``__globals__`` attribute\n of functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., ``m.x`` is\n equivalent to ``m.__dict__["x"]``. A module object does not contain\n the code object used to initialize the module (since it isn\'t\n needed once the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., ``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.\n\n Special read-only attribute: ``__dict__`` is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: ``__name__`` is the module\'s\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute may be missing for certain types of modules,\n such as C modules that are statically linked into the interpreter;\n for extension modules loaded dynamically from a shared library, it\n is the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\n\n Class attribute assignments update the class\'s dictionary, never\n the dictionary of a base class.\n\n A class object can be called (see above) to yield a class instance\n (see below).\n\n Special attributes: ``__name__`` is the class name; ``__module__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n undefined.\n\nClass instances\n A class instance is created by calling a class object (see above).\n A class instance has a namespace implemented as a dictionary which\n is the first place in which attribute references are searched.\n When an attribute is not found there, and the instance\'s class has\n an attribute by that name, the search continues with the class\n attributes. If a class attribute is found that is a user-defined\n function object, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n lookup.\n\n Attribute assignments and deletions update the instance\'s\n dictionary, never a class\'s dictionary. If the class has a\n ``__setattr__()`` or ``__delattr__()`` method, this is called\n instead of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n *Special method names*.\n\n Special attributes: ``__dict__`` is the attribute dictionary;\n ``__class__`` is the instance\'s class.\n\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: ``co_name`` gives the function\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n the filename from which the code was compiled;\n ``co_firstlineno`` is the first line number of the function;\n ``co_lnotab`` is a string encoding the mapping from bytecode\n offsets to line numbers (for details see the source code of the\n interpreter); ``co_stacksize`` is the required stack size\n (including local variables); ``co_flags`` is an integer encoding\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of Python.\n\n Other bits in ``co_flags`` are reserved for internal use.\n\n If a code object represents a function, the first item in\n ``co_consts`` is the documentation string of the function, or\n ``None`` if undefined.\n\n Frame objects\n Frame objects represent execution frames. They may occur in\n traceback objects (see below).\n\n Special read-only attributes: ``f_back`` is to the previous\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string of the code object).\n\n Special writable attributes: ``f_trace``, if not ``None``, is a\n function called at the start of each source code line (this is\n used by the debugger); ``f_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n by writing to f_lineno.\n\n Traceback objects\n Traceback objects represent a stack trace of an exception. A\n traceback object is created when an exception occurs. When the\n search for an exception handler unwinds the execution stack, at\n each unwound level a traceback object is inserted in front of\n the current traceback. When an exception handler is entered,\n the stack trace is made available to the program. (See section\n *The try statement*.) It is accessible as the third item of the\n tuple returned by ``sys.exc_info()``. When the program contains\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n ``staticmethod()`` constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in ``classmethod()`` constructor.\n', 'typesfunctions': '\nFunctions\n*********\n\nFunction objects are created by function definitions. The only\noperation on a function object is to call it: ``func(argument-list)``.\n\nThere are really two flavors of function objects: built-in functions\nand user-defined functions. Both support the same operation (to call\nthe function), but the implementation is different, hence the\ndifferent object types.\n\nSee *Function definitions* for more information.\n', - 'typesmapping': '\nMapping Types --- ``dict``\n**************************\n\nA *mapping* object maps *hashable* values to arbitrary objects.\nMappings are mutable objects. There is currently only one standard\nmapping type, the *dictionary*. (For other containers see the built\nin ``list``, ``set``, and ``tuple`` classes, and the ``collections``\nmodule.)\n\nA dictionary\'s keys are *almost* arbitrary values. Values that are\nnot *hashable*, that is, values containing lists, dictionaries or\nother mutable types (that are compared by value rather than by object\nidentity) may not be used as keys. Numeric types used for keys obey\nthe normal rules for numeric comparison: if two numbers compare equal\n(such as ``1`` and ``1.0``) then they can be used interchangeably to\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict([arg])\n\n Return a new dictionary initialized from an optional positional\n argument or from a set of keyword arguments. If no arguments are\n given, return a new empty dictionary. If the positional argument\n *arg* is a mapping object, return a dictionary mapping the same\n keys to the same values as does the mapping object. Otherwise the\n positional argument must be a sequence, a container that supports\n iteration, or an iterator object. The elements of the argument\n must each also be of one of those kinds, and each must in turn\n contain exactly two objects. The first is used as a key in the new\n dictionary, and the second as the key\'s value. If a given key is\n seen more than once, the last value associated with it is retained\n in the new dictionary.\n\n If keyword arguments are given, the keywords themselves with their\n associated values are added as items to the dictionary. If a key\n is specified both in the positional argument and as a keyword\n argument, the value associated with the keyword is retained in the\n dictionary. For example, these all return a dictionary equal to\n ``{"one": 1, "two": 2}``:\n\n * ``dict(one=1, two=2)``\n\n * ``dict({\'one\': 1, \'two\': 2})``\n\n * ``dict(zip((\'one\', \'two\'), (1, 2)))``\n\n * ``dict([[\'two\', 2], [\'one\', 1]])``\n\n The first example only works for keys that are valid Python\n identifiers; the others work with any valid keys.\n\n These are the operations that dictionaries support (and therefore,\n custom mapping types should support too):\n\n len(d)\n\n Return the number of items in the dictionary *d*.\n\n d[key]\n\n Return the item of *d* with key *key*. Raises a ``KeyError`` if\n *key* is not in the map.\n\n If a subclass of dict defines a method ``__missing__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\n\n d[key] = value\n\n Set ``d[key]`` to *value*.\n\n del d[key]\n\n Remove ``d[key]`` from *d*. Raises a ``KeyError`` if *key* is\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n classmethod fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n ``fromkeys()`` is a class method that returns a new dictionary.\n *value* defaults to ``None``.\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to ``None``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a ``KeyError`` is raised.\n\n popitem()\n\n Remove and return an arbitrary ``(key, value)`` pair from the\n dictionary.\n\n ``popitem()`` is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling ``popitem()`` raises a ``KeyError``.\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to ``None``.\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return ``None``.\n\n ``update()`` accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: ``d.update(red=1,\n blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` are *view objects*. They provide a dynamic view on\nthe dictionary\'s entries, which means that when the dictionary\nchanges, the view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of ``(key, value)``) in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of ``(value, key)`` pairs\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n d.items()]``.\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a ``RuntimeError`` or fail to iterate over all entries.\n\nx in dictview\n\n Return ``True`` if *x* is in the underlying dictionary\'s keys,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that ``(key, value)`` pairs are unique\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', + 'typesmapping': '\nMapping Types --- ``dict``\n**************************\n\nA *mapping* object maps *hashable* values to arbitrary objects.\nMappings are mutable objects. There is currently only one standard\nmapping type, the *dictionary*. (For other containers see the built-\nin ``list``, ``set``, and ``tuple`` classes, and the ``collections``\nmodule.)\n\nA dictionary\'s keys are *almost* arbitrary values. Values that are\nnot *hashable*, that is, values containing lists, dictionaries or\nother mutable types (that are compared by value rather than by object\nidentity) may not be used as keys. Numeric types used for keys obey\nthe normal rules for numeric comparison: if two numbers compare equal\n(such as ``1`` and ``1.0``) then they can be used interchangeably to\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict([arg])\n\n Return a new dictionary initialized from an optional positional\n argument or from a set of keyword arguments. If no arguments are\n given, return a new empty dictionary. If the positional argument\n *arg* is a mapping object, return a dictionary mapping the same\n keys to the same values as does the mapping object. Otherwise the\n positional argument must be a sequence, a container that supports\n iteration, or an iterator object. The elements of the argument\n must each also be of one of those kinds, and each must in turn\n contain exactly two objects. The first is used as a key in the new\n dictionary, and the second as the key\'s value. If a given key is\n seen more than once, the last value associated with it is retained\n in the new dictionary.\n\n If keyword arguments are given, the keywords themselves with their\n associated values are added as items to the dictionary. If a key\n is specified both in the positional argument and as a keyword\n argument, the value associated with the keyword is retained in the\n dictionary. For example, these all return a dictionary equal to\n ``{"one": 1, "two": 2}``:\n\n * ``dict(one=1, two=2)``\n\n * ``dict({\'one\': 1, \'two\': 2})``\n\n * ``dict(zip((\'one\', \'two\'), (1, 2)))``\n\n * ``dict([[\'two\', 2], [\'one\', 1]])``\n\n The first example only works for keys that are valid Python\n identifiers; the others work with any valid keys.\n\n These are the operations that dictionaries support (and therefore,\n custom mapping types should support too):\n\n len(d)\n\n Return the number of items in the dictionary *d*.\n\n d[key]\n\n Return the item of *d* with key *key*. Raises a ``KeyError`` if\n *key* is not in the map.\n\n If a subclass of dict defines a method ``__missing__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\n\n d[key] = value\n\n Set ``d[key]`` to *value*.\n\n del d[key]\n\n Remove ``d[key]`` from *d*. Raises a ``KeyError`` if *key* is\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n classmethod fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n ``fromkeys()`` is a class method that returns a new dictionary.\n *value* defaults to ``None``.\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to ``None``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a ``KeyError`` is raised.\n\n popitem()\n\n Remove and return an arbitrary ``(key, value)`` pair from the\n dictionary.\n\n ``popitem()`` is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling ``popitem()`` raises a ``KeyError``.\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to ``None``.\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return ``None``.\n\n ``update()`` accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: ``d.update(red=1,\n blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` are *view objects*. They provide a dynamic view on\nthe dictionary\'s entries, which means that when the dictionary\nchanges, the view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of ``(key, value)``) in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of ``(value, key)`` pairs\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n d.items()]``.\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a ``RuntimeError`` or fail to iterate over all entries.\n\nx in dictview\n\n Return ``True`` if *x* is in the underlying dictionary\'s keys,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that ``(key, value)`` pairs are unique\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.abc.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', 'typesmethods': "\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as ``append()`` on\nlists) and class instance methods. Built-in methods are described\nwith the types that support them.\n\nIf you access a method (a function defined in a class namespace)\nthrough an instance, you get a special object: a *bound method* (also\ncalled *instance method*) object. When called, it will add the\n``self`` argument to the argument list. Bound methods have two\nspecial read-only attributes: ``m.__self__`` is the object on which\nthe method operates, and ``m.__func__`` is the function implementing\nthe method. Calling ``m(arg-1, arg-2, ..., arg-n)`` is completely\nequivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,\narg-n)``.\n\nLike function objects, bound method objects support getting arbitrary\nattributes. However, since method attributes are actually stored on\nthe underlying function object (``meth.__func__``), setting method\nattributes on bound methods is disallowed. Attempting to set a method\nattribute results in a ``TypeError`` being raised. In order to set a\nmethod attribute, you need to explicitly set it on the underlying\nfunction object:\n\n class C:\n def method(self):\n pass\n\n c = C()\n c.method.__func__.whoami = 'my name is c'\n\nSee *The standard type hierarchy* for more information.\n", 'typesmodules': "\nModules\n*******\n\nThe only special operation on a module is attribute access:\n``m.name``, where *m* is a module and *name* accesses a name defined\nin *m*'s symbol table. Module attributes can be assigned to. (Note\nthat the ``import`` statement is not, strictly speaking, an operation\non a module object; ``import foo`` does not require a module object\nnamed *foo* to exist, rather it requires an (external) *definition*\nfor a module named *foo* somewhere.)\n\nA special attribute of every module is ``__dict__``. This is the\ndictionary containing the module's symbol table. Modifying this\ndictionary will actually change the module's symbol table, but direct\nassignment to the ``__dict__`` attribute is not possible (you can\nwrite ``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but\nyou can't write ``m.__dict__ = {}``). Modifying ``__dict__`` directly\nis not recommended.\n\nModules built into the interpreter are written like this: ````. If loaded from a file, they are written as\n````.\n", - 'typesseq': '\nSequence Types --- ``str``, ``bytes``, ``bytearray``, ``list``, ``tuple``, ``range``\n************************************************************************************\n\nThere are six sequence types: strings, byte sequences (``bytes``\nobjects), byte arrays (``bytearray`` objects), lists, tuples, and\nrange objects. For other containers see the built in ``dict`` and\n``set`` classes, and the ``collections`` module.\n\nStrings contain Unicode characters. Their literals are written in\nsingle or double quotes: ``\'xyzzy\'``, ``"frobozz"``. See *String and\nBytes literals* for more about string literals. In addition to the\nfunctionality described here, there are also string-specific methods\ndescribed in the *String Methods* section.\n\nBytes and bytearray objects contain single bytes -- the former is\nimmutable while the latter is a mutable sequence. Bytes objects can be\nconstructed by using the constructor, ``bytes()``, and from literals;\nuse a ``b`` prefix with normal string syntax: ``b\'xyzzy\'``. To\nconstruct byte arrays, use the ``bytearray()`` function.\n\nWhile string objects are sequences of characters (represented by\nstrings of length 1), bytes and bytearray objects are sequences of\n*integers* (between 0 and 255), representing the ASCII value of single\nbytes. That means that for a bytes or bytearray object *b*, ``b[0]``\nwill be an integer, while ``b[0:1]`` will be a bytes or bytearray\nobject of length 1. The representation of bytes objects uses the\nliteral format (``b\'...\'``) since it is generally more useful than\ne.g. ``bytes([50, 19, 100])``. You can always convert a bytes object\ninto a list of integers using ``list(b)``.\n\nAlso, while in previous Python versions, byte strings and Unicode\nstrings could be exchanged for each other rather freely (barring\nencoding issues), strings and bytes are now completely separate\nconcepts. There\'s no implicit en-/decoding if you pass an object of\nthe wrong type. A string always compares unequal to a bytes or\nbytearray object.\n\nLists are constructed with square brackets, separating items with\ncommas: ``[a, b, c]``. Tuples are constructed by the comma operator\n(not within square brackets), with or without enclosing parentheses,\nbut an empty tuple must have the enclosing parentheses, such as ``a,\nb, c`` or ``()``. A single item tuple must have a trailing comma,\nsuch as ``(d,)``.\n\nObjects of type range are created using the ``range()`` function.\nThey don\'t support concatenation or repetition, and using ``min()`` or\n``max()`` on them is inefficient.\n\nMost sequence types support the following operations. The ``in`` and\n``not in`` operations have the same priorities as the comparison\noperations. The ``+`` and ``*`` operations have the same priority as\nthe corresponding numeric operations. [3] Additional methods are\nprovided for *Mutable Sequence Types*.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type; *n*, *i*, *j* and *k* are\nintegers.\n\n+--------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+====================+==================================+============+\n| ``x in s`` | ``True`` if an item of *s* is | (1) |\n| | equal to *x*, else ``False`` | |\n+--------------------+----------------------------------+------------+\n| ``x not in s`` | ``False`` if an item of *s* is | (1) |\n| | equal to *x*, else ``True`` | |\n+--------------------+----------------------------------+------------+\n| ``s + t`` | the concatenation of *s* and *t* | (6) |\n+--------------------+----------------------------------+------------+\n| ``s * n, n * s`` | *n* shallow copies of *s* | (2) |\n| | concatenated | |\n+--------------------+----------------------------------+------------+\n| ``s[i]`` | *i*th item of *s*, origin 0 | (3) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+--------------------+----------------------------------+------------+\n| ``len(s)`` | length of *s* | |\n+--------------------+----------------------------------+------------+\n| ``min(s)`` | smallest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``max(s)`` | largest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.index(i)`` | index of the first occurence of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.count(i)`` | total number of occurences of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n\nSequence types also support comparisons. In particular, tuples and\nlists are compared lexicographically by comparing corresponding\nelements. This means that to compare equal, every element must\ncompare equal and the two sequences must be of the same type and have\nthe same length. (For full details see *Comparisons* in the language\nreference.)\n\nNotes:\n\n1. When *s* is a string object, the ``in`` and ``not in`` operations\n act like a substring test.\n\n2. Values of *n* less than ``0`` are treated as ``0`` (which yields an\n empty sequence of the same type as *s*). Note also that the copies\n are shallow; nested structures are not copied. This often haunts\n new Python programmers; consider:\n\n >>> lists = [[]] * 3\n >>> lists\n [[], [], []]\n >>> lists[0].append(3)\n >>> lists\n [[3], [3], [3]]\n\n What has happened is that ``[[]]`` is a one-element list containing\n an empty list, so all three elements of ``[[]] * 3`` are (pointers\n to) this single empty list. Modifying any of the elements of\n ``lists`` modifies this single list. You can create a list of\n different lists this way:\n\n >>> lists = [[] for i in range(3)]\n >>> lists[0].append(3)\n >>> lists[1].append(5)\n >>> lists[2].append(7)\n >>> lists\n [[3], [5], [7]]\n\n3. If *i* or *j* is negative, the index is relative to the end of the\n string: ``len(s) + i`` or ``len(s) + j`` is substituted. But note\n that ``-0`` is still ``0``.\n\n4. The slice of *s* from *i* to *j* is defined as the sequence of\n items with index *k* such that ``i <= k < j``. If *i* or *j* is\n greater than ``len(s)``, use ``len(s)``. If *i* is omitted or\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n empty.\n\n5. The slice of *s* from *i* to *j* with step *k* is defined as the\n sequence of items with index ``x = i + n*k`` such that ``0 <= n <\n (j-i)/k``. In other words, the indices are ``i``, ``i+k``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable strings always results in a new object.\n This means that building up a string by repeated concatenation will\n have a quadratic runtime cost in the total string length. To get a\n linear runtime cost, you must switch to one of the alternatives\n below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end;\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()``, or you can do in-place concatenation with a\n ``bytearray`` object. ``bytearray`` objects are mutable and have\n an efficient overallocation mechanism.\n\n\nString Methods\n==============\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the universal newlines approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n\n\nOld String Formatting Operations\n================================\n\nNote: The formatting operations described here are modelled on C\'s\n printf() syntax. They only support formatting of certain builtin\n types. The use of a binary operator means that care may be needed\n in order to format tuples and dictionaries correctly. As the new\n *String Formatting* syntax is more flexible and handles tuples and\n dictionaries naturally, it is recommended for new code. However,\n there are no current plans to deprecate printf-style formatting.\n\nString objects have one unique built-in operation: the ``%`` operator\n(modulo). This is also known as the string *formatting* or\n*interpolation* operator. Given ``format % values`` (where *format* is\na string), ``%`` conversion specifications in *format* are replaced\nwith zero or more elements of *values*. The effect is similar to the\nusing ``sprintf()`` in the C language.\n\nIf *format* requires a single argument, *values* may be a single non-\ntuple object. [5] Otherwise, *values* must be a tuple with exactly\nthe number of items specified by the format string, or a single\nmapping object (for example, a dictionary).\n\nA conversion specifier contains two or more characters and has the\nfollowing components, which must occur in this order:\n\n1. The ``\'%\'`` character, which marks the start of the specifier.\n\n2. Mapping key (optional), consisting of a parenthesised sequence of\n characters (for example, ``(somename)``).\n\n3. Conversion flags (optional), which affect the result of some\n conversion types.\n\n4. Minimum field width (optional). If specified as an ``\'*\'``\n (asterisk), the actual width is read from the next element of the\n tuple in *values*, and the object to convert comes after the\n minimum field width and optional precision.\n\n5. Precision (optional), given as a ``\'.\'`` (dot) followed by the\n precision. If specified as ``\'*\'`` (an asterisk), the actual\n precision is read from the next element of the tuple in *values*,\n and the value to convert comes after the precision.\n\n6. Length modifier (optional).\n\n7. Conversion type.\n\nWhen the right argument is a dictionary (or other mapping type), then\nthe formats in the string *must* include a parenthesised mapping key\ninto that dictionary inserted immediately after the ``\'%\'`` character.\nThe mapping key selects the value to be formatted from the mapping.\nFor example:\n\n>>> print(\'%(language)s has %(number)03d quote types.\' %\n... {\'language\': "Python", "number": 2})\nPython has 002 quote types.\n\nIn this case no ``*`` specifiers may occur in a format (since they\nrequire a sequential parameter list).\n\nThe conversion flag characters are:\n\n+-----------+-----------------------------------------------------------------------+\n| Flag | Meaning |\n+===========+=======================================================================+\n| ``\'#\'`` | The value conversion will use the "alternate form" (where defined |\n| | below). |\n+-----------+-----------------------------------------------------------------------+\n| ``\'0\'`` | The conversion will be zero padded for numeric values. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'-\'`` | The converted value is left adjusted (overrides the ``\'0\'`` |\n| | conversion if both are given). |\n+-----------+-----------------------------------------------------------------------+\n| ``\' \'`` | (a space) A blank should be left before a positive number (or empty |\n| | string) produced by a signed conversion. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'+\'`` | A sign character (``\'+\'`` or ``\'-\'``) will precede the conversion |\n| | (overrides a "space" flag). |\n+-----------+-----------------------------------------------------------------------+\n\nA length modifier (``h``, ``l``, or ``L``) may be present, but is\nignored as it is not necessary for Python -- so e.g. ``%ld`` is\nidentical to ``%d``.\n\nThe conversion types are:\n\n+--------------+-------------------------------------------------------+---------+\n| Conversion | Meaning | Notes |\n+==============+=======================================================+=========+\n| ``\'d\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'i\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'o\'`` | Signed octal value. | (1) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'u\'`` | Obsolete type -- it is identical to ``\'d\'``. | (7) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'x\'`` | Signed hexadecimal (lowercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'X\'`` | Signed hexadecimal (uppercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'e\'`` | Floating point exponential format (lowercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'E\'`` | Floating point exponential format (uppercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'f\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'F\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'g\'`` | Floating point format. Uses lowercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'G\'`` | Floating point format. Uses uppercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'c\'`` | Single character (accepts integer or single character | |\n| | string). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'r\'`` | String (converts any Python object using ``repr()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'s\'`` | String (converts any Python object using ``str()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'a\'`` | String (converts any Python object using | (5) |\n| | ``ascii()``). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'%\'`` | No argument is converted, results in a ``\'%\'`` | |\n| | character in the result. | |\n+--------------+-------------------------------------------------------+---------+\n\nNotes:\n\n1. The alternate form causes a leading zero (``\'0\'``) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n2. The alternate form causes a leading ``\'0x\'`` or ``\'0X\'`` (depending\n on whether the ``\'x\'`` or ``\'X\'`` format was used) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n3. The alternate form causes the result to always contain a decimal\n point, even if no digits follow it.\n\n The precision determines the number of digits after the decimal\n point and defaults to 6.\n\n4. The alternate form causes the result to always contain a decimal\n point, and trailing zeroes are not removed as they would otherwise\n be.\n\n The precision determines the number of significant digits before\n and after the decimal point and defaults to 6.\n\n5. If precision is ``N``, the output is truncated to ``N`` characters.\n\n1. See **PEP 237**.\n\nSince Python strings have an explicit length, ``%s`` conversions do\nnot assume that ``\'\\0\'`` is the end of the string.\n\nChanged in version 3.1: ``%f`` conversions for numbers whose absolute\nvalue is over 1e50 are no longer replaced by ``%g`` conversions.\n\nAdditional string operations are defined in standard modules\n``string`` and ``re``.\n\n\nRange Type\n==========\n\nThe ``range`` type is an immutable sequence which is commonly used for\nlooping. The advantage of the ``range`` type is that an ``range``\nobject will always take the same amount of memory, no matter the size\nof the range it represents.\n\nRange objects have relatively little behavior: they support indexing,\ncontains, iteration, the ``len()`` function, and the following\nmethods:\n\nrange.count(x)\n\n Return the number of *i*\'s for which ``s[i] == x``.\n\n New in version 3.2.\n\nrange.index(x)\n\n Return the smallest *i* such that ``s[i] == x``. Raises\n ``ValueError`` when *x* is not in the range.\n\n New in version 3.2.\n\n\nMutable Sequence Types\n======================\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | remove all items from ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | return a shallow copy of ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.count(x)`` | return number of *i*\'s for which | |\n| | ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.index(x[, i[, j]])`` | return smallest *k* such that | (3) |\n| | ``s[k] == x`` and ``i <= k < j`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | (5) |\n| | return x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | (3) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (6) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. *x* can be any iterable object.\n\n3. Raises ``ValueError`` when *x* is not found in *s*. When a negative\n index is passed as the second or third parameter to the ``index()``\n method, the sequence length is added, as for slice indices. If it\n is still negative, it is truncated to zero, as for slice indices.\n\n4. When a negative index is passed as the first parameter to the\n ``insert()`` method, the sequence length is added, as for slice\n indices. If it is still negative, it is truncated to zero, as for\n slice indices.\n\n5. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n6. The ``sort()`` and ``reverse()`` methods modify the sequence in\n place for economy of space when sorting or reversing a large\n sequence. To remind you that they operate by side effect, they\n don\'t return the sorted or reversed sequence.\n\n7. The ``sort()`` method takes optional arguments for controlling the\n comparisons. Each must be specified as a keyword argument.\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: ``key=str.lower``. The\n default value is ``None``. Use ``functools.cmp_to_key()`` to\n convert an old-style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n The ``sort()`` method is guaranteed to be stable. A sort is stable\n if it guarantees not to change the relative order of elements that\n compare equal --- this is helpful for sorting in multiple passes\n (for example, sort by department, then by salary grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can detect\n that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nBytes and Byte Array Methods\n============================\n\nBytes and bytearray objects, being "strings of bytes", have all\nmethods found on strings, with the exception of ``encode()``,\n``format()`` and ``isidentifier()``, which do not make sense with\nthese types. For converting the objects to strings, they have a\n``decode()`` method.\n\nWherever one of these methods needs to interpret the bytes as\ncharacters (e.g. the ``is...()`` methods), the ASCII character set is\nassumed.\n\nNew in version 3.3: The functions ``count()``, ``find()``,\n``index()``, ``rfind()`` and ``rindex()`` have additional semantics\ncompared to the corresponding string functions: They also accept an\ninteger in range 0 to 255 (a byte) as their first argument.\n\nNote: The methods on bytes and bytearray objects don\'t accept strings as\n their arguments, just as the methods on strings don\'t accept bytes\n as their arguments. For example, you have to write\n\n a = "abc"\n b = a.replace("a", "f")\n\n and\n\n a = b"abc"\n b = a.replace(b"a", b"f")\n\nbytes.decode(encoding="utf-8", errors="strict")\nbytearray.decode(encoding="utf-8", errors="strict")\n\n Return a string decoded from the given bytes. Default encoding is\n ``\'utf-8\'``. *errors* may be given to set a different error\n handling scheme. The default for *errors* is ``\'strict\'``, meaning\n that encoding errors raise a ``UnicodeError``. Other possible\n values are ``\'ignore\'``, ``\'replace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Added support for keyword arguments.\n\nThe bytes and bytearray types have an additional class method:\n\nclassmethod bytes.fromhex(string)\nclassmethod bytearray.fromhex(string)\n\n This ``bytes`` class method returns a bytes or bytearray object,\n decoding the given string object. The string must contain two\n hexadecimal digits per byte, spaces are ignored.\n\n >>> bytes.fromhex(\'f0 f1f2 \')\n b\'\\xf0\\xf1\\xf2\'\n\nThe maketrans and translate methods differ in semantics from the\nversions available on strings:\n\nbytes.translate(table[, delete])\nbytearray.translate(table[, delete])\n\n Return a copy of the bytes or bytearray object where all bytes\n occurring in the optional argument *delete* are removed, and the\n remaining bytes have been mapped through the given translation\n table, which must be a bytes object of length 256.\n\n You can use the ``bytes.maketrans()`` method to create a\n translation table.\n\n Set the *table* argument to ``None`` for translations that only\n delete characters:\n\n >>> b\'read this short text\'.translate(None, b\'aeiou\')\n b\'rd ths shrt txt\'\n\nstatic bytes.maketrans(from, to)\nstatic bytearray.maketrans(from, to)\n\n This static method returns a translation table usable for\n ``bytes.translate()`` that will map each character in *from* into\n the character at the same position in *to*; *from* and *to* must be\n bytes objects and have the same length.\n\n New in version 3.1.\n', - 'typesseq-mutable': '\nMutable Sequence Types\n**********************\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | remove all items from ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | return a shallow copy of ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.count(x)`` | return number of *i*\'s for which | |\n| | ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.index(x[, i[, j]])`` | return smallest *k* such that | (3) |\n| | ``s[k] == x`` and ``i <= k < j`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | (5) |\n| | return x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | (3) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (6) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. *x* can be any iterable object.\n\n3. Raises ``ValueError`` when *x* is not found in *s*. When a negative\n index is passed as the second or third parameter to the ``index()``\n method, the sequence length is added, as for slice indices. If it\n is still negative, it is truncated to zero, as for slice indices.\n\n4. When a negative index is passed as the first parameter to the\n ``insert()`` method, the sequence length is added, as for slice\n indices. If it is still negative, it is truncated to zero, as for\n slice indices.\n\n5. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n6. The ``sort()`` and ``reverse()`` methods modify the sequence in\n place for economy of space when sorting or reversing a large\n sequence. To remind you that they operate by side effect, they\n don\'t return the sorted or reversed sequence.\n\n7. The ``sort()`` method takes optional arguments for controlling the\n comparisons. Each must be specified as a keyword argument.\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: ``key=str.lower``. The\n default value is ``None``. Use ``functools.cmp_to_key()`` to\n convert an old-style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n The ``sort()`` method is guaranteed to be stable. A sort is stable\n if it guarantees not to change the relative order of elements that\n compare equal --- this is helpful for sorting in multiple passes\n (for example, sort by department, then by salary grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can detect\n that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n', + 'typesseq': '\nSequence Types --- ``list``, ``tuple``, ``range``\n*************************************************\n\nThere are three basic sequence types: lists, tuples, and range\nobjects. Additional sequence types tailored for processing of *binary\ndata* and *text strings* are described in dedicated sections.\n\n\nCommon Sequence Operations\n==========================\n\nThe operations in the following table are supported by most sequence\ntypes, both mutable and immutable. The ``collections.abc.Sequence``\nABC is provided to make it easier to correctly implement these\noperations on custom sequence types.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type, *n*, *i*, *j* and *k* are\nintegers and *x* is an arbitrary object that meets any type and value\nrestrictions imposed by *s*.\n\nThe ``in`` and ``not in`` operations have the same priorities as the\ncomparison operations. The ``+`` (concatenation) and ``*``\n(repetition) operations have the same priority as the corresponding\nnumeric operations.\n\n+----------------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+============================+==================================+============+\n| ``x in s`` | ``True`` if an item of *s* is | (1) |\n| | equal to *x*, else ``False`` | |\n+----------------------------+----------------------------------+------------+\n| ``x not in s`` | ``False`` if an item of *s* is | (1) |\n| | equal to *x*, else ``True`` | |\n+----------------------------+----------------------------------+------------+\n| ``s + t`` | the concatenation of *s* and *t* | (6)(7) |\n+----------------------------+----------------------------------+------------+\n| ``s * n`` or ``n * s`` | *n* shallow copies of *s* | (2)(7) |\n| | concatenated | |\n+----------------------------+----------------------------------+------------+\n| ``s[i]`` | *i*th item of *s*, origin 0 | (3) |\n+----------------------------+----------------------------------+------------+\n| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |\n+----------------------------+----------------------------------+------------+\n| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+----------------------------+----------------------------------+------------+\n| ``len(s)`` | length of *s* | |\n+----------------------------+----------------------------------+------------+\n| ``min(s)`` | smallest item of *s* | |\n+----------------------------+----------------------------------+------------+\n| ``max(s)`` | largest item of *s* | |\n+----------------------------+----------------------------------+------------+\n| ``s.index(x[, i[, j]])`` | index of the first occurence of | (8) |\n| | *x* in *s* (at or after index | |\n| | *i* and before index *j*) | |\n+----------------------------+----------------------------------+------------+\n| ``s.count(x)`` | total number of occurences of | |\n| | *x* in *s* | |\n+----------------------------+----------------------------------+------------+\n\nSequences of the same type also support comparisons. In particular,\ntuples and lists are compared lexicographically by comparing\ncorresponding elements. This means that to compare equal, every\nelement must compare equal and the two sequences must be of the same\ntype and have the same length. (For full details see *Comparisons* in\nthe language reference.)\n\nNotes:\n\n1. While the ``in`` and ``not in`` operations are used only for simple\n containment testing in the general case, some specialised sequences\n (such as ``str``, ``bytes`` and ``bytearray``) also use them for\n subsequence testing:\n\n >>> "gg" in "eggs"\n True\n\n2. Values of *n* less than ``0`` are treated as ``0`` (which yields an\n empty sequence of the same type as *s*). Note also that the copies\n are shallow; nested structures are not copied. This often haunts\n new Python programmers; consider:\n\n >>> lists = [[]] * 3\n >>> lists\n [[], [], []]\n >>> lists[0].append(3)\n >>> lists\n [[3], [3], [3]]\n\n What has happened is that ``[[]]`` is a one-element list containing\n an empty list, so all three elements of ``[[]] * 3`` are (pointers\n to) this single empty list. Modifying any of the elements of\n ``lists`` modifies this single list. You can create a list of\n different lists this way:\n\n >>> lists = [[] for i in range(3)]\n >>> lists[0].append(3)\n >>> lists[1].append(5)\n >>> lists[2].append(7)\n >>> lists\n [[3], [5], [7]]\n\n3. If *i* or *j* is negative, the index is relative to the end of the\n string: ``len(s) + i`` or ``len(s) + j`` is substituted. But note\n that ``-0`` is still ``0``.\n\n4. The slice of *s* from *i* to *j* is defined as the sequence of\n items with index *k* such that ``i <= k < j``. If *i* or *j* is\n greater than ``len(s)``, use ``len(s)``. If *i* is omitted or\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n empty.\n\n5. The slice of *s* from *i* to *j* with step *k* is defined as the\n sequence of items with index ``x = i + n*k`` such that ``0 <= n <\n (j-i)/k``. In other words, the indices are ``i``, ``i+k``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable sequences always results in a new object.\n This means that building up a sequence by repeated concatenation\n will have a quadratic runtime cost in the total sequence length.\n To get a linear runtime cost, you must switch to one of the\n alternatives below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end or else write to a ``io.StringIO``\n instance and retrieve its value when complete\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()`` or ``io.BytesIO``, or you can do in-place\n concatenation with a ``bytearray`` object. ``bytearray`` objects\n are mutable and have an efficient overallocation mechanism\n\n * if concatenating ``tuple`` objects, extend a ``list`` instead\n\n * for other types, investigate the relevant class documentation\n\n7. Some sequence types (such as ``range``) only support item sequences\n that follow specific patterns, and hence don\'t support sequence\n concatenation or repetition.\n\n8. ``index`` raises ``ValueError`` when *x* is not found in *s*. When\n supported, the additional arguments to the index method allow\n efficient searching of subsections of the sequence. Passing the\n extra arguments is roughly equivalent to using ``s[i:j].index(x)``,\n only without copying any data and with the returned index being\n relative to the start of the sequence rather than the start of the\n slice.\n\n\nImmutable Sequence Types\n========================\n\nThe only operation that immutable sequence types generally implement\nthat is not also implemented by mutable sequence types is support for\nthe ``hash()`` built-in.\n\nThis support allows immutable sequences, such as ``tuple`` instances,\nto be used as ``dict`` keys and stored in ``set`` and ``frozenset``\ninstances.\n\nAttempting to hash an immutable sequence that contains unhashable\nvalues will result in ``TypeError``.\n\n\nMutable Sequence Types\n======================\n\nThe operations in the following table are defined on mutable sequence\ntypes. The ``collections.abc.MutableSequence`` ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, ``bytearray`` only\naccepts integers that meet the value restriction ``0 <= x <= 255``).\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | appends *x* to the end of the | |\n| | sequence (same as | |\n| | ``s[len(s):len(s)] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | removes all items from ``s`` | (5) |\n| | (same as ``del s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | creates a shallow copy of ``s`` | (5) |\n| | (same as ``s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(t)`` | extends *s* with the contents of | |\n| | *t* (same as ``s[len(s):len(s)] | |\n| | = t``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | ``s[i:i] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | remove the first item from *s* | (3) |\n| | where ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n3. ``remove`` raises ``ValueError`` when *x* is not found in *s*.\n\n4. The ``reverse()`` method modifies the sequence in place for economy\n of space when reversing a large sequence. To remind users that it\n operates by side effect, it does not return the reversed sequence.\n\n5. ``clear()`` and ``copy()`` are included for consistency with the\n interfaces of mutable containers that don\'t support slicing\n operations (such as ``dict`` and ``set``)\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nLists\n=====\n\nLists are mutable sequences, typically used to store collections of\nhomogeneous items (where the precise degree of similarity will vary by\napplication).\n\nclass class list([iterable])\n\n Lists may be constructed in several ways:\n\n * Using a pair of square brackets to denote the empty list: ``[]``\n\n * Using square brackets, separating items with commas: ``[a]``,\n ``[a, b, c]``\n\n * Using a list comprehension: ``[x for x in iterable]``\n\n * Using the type constructor: ``list()`` or ``list(iterable)``\n\n The constructor builds a list whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a list, a copy is made and\n returned, similar to ``iterable[:]``. For example, ``list(\'abc\')``\n returns ``[\'a\', \'b\', \'c\']`` and ``list( (1, 2, 3) )`` returns ``[1,\n 2, 3]``. If no argument is given, the constructor creates a new\n empty list, ``[]``.\n\n Many other operations also produce lists, including the\n ``sorted()`` built-in.\n\n Lists implement all of the *common* and *mutable* sequence\n operations. Lists also provide the following additional method:\n\n sort(*, key=None, reverse=None)\n\n This method sorts the list in place, using only ``<``\n comparisons between items. Exceptions are not suppressed - if\n any comparison operations fail, the entire sort operation will\n fail (and the list will likely be left in a partially modified\n state).\n\n *key* specifies a function of one argument that is used to\n extract a comparison key from each list element (for example,\n ``key=str.lower``). The key corresponding to each item in the\n list is calculated once and then used for the entire sorting\n process. The default value of ``None`` means that list items are\n sorted directly without calculating a separate key value.\n\n The ``functools.cmp_to_key()`` utility is available to convert a\n 2.x style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n This method modifies the sequence in place for economy of space\n when sorting a large sequence. To remind users that it operates\n by side effect, it does not return the sorted sequence (use\n ``sorted()`` to explicitly request a new sorted list instance).\n\n The ``sort()`` method is guaranteed to be stable. A sort is\n stable if it guarantees not to change the relative order of\n elements that compare equal --- this is helpful for sorting in\n multiple passes (for example, sort by department, then by salary\n grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can\n detect that the list has been mutated during a sort.\n\n\nTuples\n======\n\nTuples are immutable sequences, typically used to store collections of\nheterogeneous data (such as the 2-tuples produced by the\n``enumerate()`` built-in). Tuples are also used for cases where an\nimmutable sequence of homogeneous data is needed (such as allowing\nstorage in a ``set`` or ``dict`` instance).\n\nclass class tuple([iterable])\n\n Tuples may be constructed in a number of ways:\n\n * Using a pair of parentheses to denote the empty tuple: ``()``\n\n * Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)``\n\n * Separating items with commas: ``a, b, c`` or ``(a, b, c)``\n\n * Using the ``tuple()`` built-in: ``tuple()`` or\n ``tuple(iterable)``\n\n The constructor builds a tuple whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a tuple, it is returned\n unchanged. For example, ``tuple(\'abc\')`` returns ``(\'a\', \'b\',\n \'c\')`` and ``tuple( [1, 2, 3] )`` returns ``(1, 2, 3)``. If no\n argument is given, the constructor creates a new empty tuple,\n ``()``.\n\n Note that it is actually the comma which makes a tuple, not the\n parentheses. The parentheses are optional, except in the empty\n tuple case, or when they are needed to avoid syntactic ambiguity.\n For example, ``f(a, b, c)`` is a function call with three\n arguments, while ``f((a, b, c))`` is a function call with a 3-tuple\n as the sole argument.\n\n Tuples implement all of the *common* sequence operations.\n\nFor heterogeneous collections of data where access by name is clearer\nthan access by index, ``collections.namedtuple()`` may be a more\nappropriate choice than a simple tuple object.\n\n\nRanges\n======\n\nThe ``range`` type represents an immutable sequence of numbers and is\ncommonly used for looping a specific number of times in ``for`` loops.\n\nclass class range([start], stop[, step])\n\n The arguments to the range constructor must be integers (either\n built-in ``int`` or any object that implements the ``__index__``\n special method). If the *step* argument is omitted, it defaults to\n ``1``. If the *start* argument is omitted, it defaults to ``0``. If\n *step* is zero, ``ValueError`` is raised.\n\n For a positive *step*, the contents of a range ``r`` are determined\n by the formula ``r[i] = start + step*i`` where ``i >= 0`` and\n ``r[i] < stop``.\n\n For a negative *step*, the contents of the range are still\n determined by the formula ``r[i] = start + step*i``, but the\n constraints are ``i >= 0`` and ``r[i] > stop``.\n\n A range object will be empty if ``r[0]`` does not meant the value\n constraint. Ranges do support negative indices, but these are\n interpreted as indexing from the end of the sequence determined by\n the positive indices.\n\n Ranges containing absolute values larger than ``sys.maxsize`` are\n permitted but some features (such as ``len()``) may raise\n ``OverflowError``.\n\n Range examples:\n\n >>> list(range(10))\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n >>> list(range(1, 11))\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n >>> list(range(0, 30, 5))\n [0, 5, 10, 15, 20, 25]\n >>> list(range(0, 10, 3))\n [0, 3, 6, 9]\n >>> list(range(0, -10, -1))\n [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n >>> list(range(0))\n []\n >>> list(range(1, 0))\n []\n\n Ranges implement all of the *common* sequence operations except\n concatenation and repetition (due to the fact that range objects\n can only represent sequences that follow a strict pattern and\n repetition and concatenation will usually violate that pattern).\n\nThe advantage of the ``range`` type over a regular ``list`` or\n``tuple`` is that a ``range`` object will always take the same (small)\namount of memory, no matter the size of the range it represents (as it\nonly stores the ``start``, ``stop`` and ``step`` values, calculating\nindividual items and subranges as needed).\n\nRange objects implement the ``collections.Sequence`` ABC, and provide\nfeatures such as containment tests, element index lookup, slicing and\nsupport for negative indices (see *Sequence Types --- list, tuple,\nrange*):\n\n>>> r = range(0, 20, 2)\n>>> r\nrange(0, 20, 2)\n>>> 11 in r\nFalse\n>>> 10 in r\nTrue\n>>> r.index(10)\n5\n>>> r[5]\n10\n>>> r[:5]\nrange(0, 10, 2)\n>>> r[-1]\n18\n\nTesting range objects for equality with ``==`` and ``!=`` compares\nthem as sequences. That is, two range objects are considered equal if\nthey represent the same sequence of values. (Note that two range\nobjects that compare equal might have different ``start``, ``stop``\nand ``step`` attributes, for example ``range(0) == range(2, 1, 3)`` or\n``range(0, 3, 2) == range(0, 4, 2)``.)\n\nChanged in version 3.2: Implement the Sequence ABC. Support slicing\nand negative indices. Test ``int`` objects for membership in constant\ntime instead of iterating through all items.\n\nChanged in version 3.3: Define \'==\' and \'!=\' to compare range objects\nbased on the sequence of values they define (instead of comparing\nbased on object identity).\n\nNew in version 3.3: The ``start``, ``stop`` and ``step`` attributes.\n', + 'typesseq-mutable': "\nMutable Sequence Types\n**********************\n\nThe operations in the following table are defined on mutable sequence\ntypes. The ``collections.abc.MutableSequence`` ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, ``bytearray`` only\naccepts integers that meet the value restriction ``0 <= x <= 255``).\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | appends *x* to the end of the | |\n| | sequence (same as | |\n| | ``s[len(s):len(s)] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | removes all items from ``s`` | (5) |\n| | (same as ``del s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | creates a shallow copy of ``s`` | (5) |\n| | (same as ``s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(t)`` | extends *s* with the contents of | |\n| | *t* (same as ``s[len(s):len(s)] | |\n| | = t``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | ``s[i:i] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | remove the first item from *s* | (3) |\n| | where ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n3. ``remove`` raises ``ValueError`` when *x* is not found in *s*.\n\n4. The ``reverse()`` method modifies the sequence in place for economy\n of space when reversing a large sequence. To remind users that it\n operates by side effect, it does not return the reversed sequence.\n\n5. ``clear()`` and ``copy()`` are included for consistency with the\n interfaces of mutable containers that don't support slicing\n operations (such as ``dict`` and ``set``)\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n", 'unary': '\nUnary arithmetic and bitwise operations\n***************************************\n\nAll unary arithmetic and bitwise operations have the same priority:\n\n u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n\nThe unary ``-`` (minus) operator yields the negation of its numeric\nargument.\n\nThe unary ``+`` (plus) operator yields its numeric argument unchanged.\n\nThe unary ``~`` (invert) operator yields the bitwise inversion of its\ninteger argument. The bitwise inversion of ``x`` is defined as\n``-(x+1)``. It only applies to integral numbers.\n\nIn all three cases, if the argument does not have the proper type, a\n``TypeError`` exception is raised.\n', 'while': '\nThe ``while`` statement\n***********************\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n', 'with': '\nThe ``with`` statement\n**********************\n\nThe ``with`` statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section *With Statement\nContext Managers*). This allows common\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the ``with`` statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the ``with_item``)\n is evaluated to obtain a context manager.\n\n2. The context manager\'s ``__exit__()`` is loaded for later use.\n\n3. The context manager\'s ``__enter__()`` method is invoked.\n\n4. If a target was included in the ``with`` statement, the return\n value from ``__enter__()`` is assigned to it.\n\n Note: The ``with`` statement guarantees that if the ``__enter__()``\n method returns without an error, then ``__exit__()`` will always\n be called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s ``__exit__()`` method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to ``__exit__()``. Otherwise,\n three ``None`` arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the ``__exit__()`` method was false, the exception is\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from ``__exit__()`` is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple ``with`` statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n', -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 21:34:05 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 21:34:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Bump_to_3=2E3=2E0rc1=2E?= Message-ID: <3X48gK6rCFzQJv@mail.python.org> http://hg.python.org/cpython/rev/8bb5c7bc46ba changeset: 78769:8bb5c7bc46ba tag: v3.3.0rc1 user: Georg Brandl date: Sat Aug 25 12:16:37 2012 +0200 summary: Bump to 3.3.0rc1. files: Include/patchlevel.h | 6 +++--- Lib/distutils/__init__.py | 2 +- Lib/idlelib/idlever.py | 2 +- Misc/NEWS | 2 +- Misc/RPM/python-3.3.spec | 2 +- README | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Include/patchlevel.h b/Include/patchlevel.h --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -19,11 +19,11 @@ #define PY_MAJOR_VERSION 3 #define PY_MINOR_VERSION 3 #define PY_MICRO_VERSION 0 -#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_BETA -#define PY_RELEASE_SERIAL 2 +#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_GAMMA +#define PY_RELEASE_SERIAL 1 /* Version as a string */ -#define PY_VERSION "3.3.0b2+" +#define PY_VERSION "3.3.0rc1" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Lib/distutils/__init__.py b/Lib/distutils/__init__.py --- a/Lib/distutils/__init__.py +++ b/Lib/distutils/__init__.py @@ -13,5 +13,5 @@ # Updated automatically by the Python release process. # #--start constants-- -__version__ = "3.3.0b2" +__version__ = "3.3.0rc1" #--end constants-- diff --git a/Lib/idlelib/idlever.py b/Lib/idlelib/idlever.py --- a/Lib/idlelib/idlever.py +++ b/Lib/idlelib/idlever.py @@ -1,1 +1,1 @@ -IDLE_VERSION = "3.3.0b2" +IDLE_VERSION = "3.3.0rc1" diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -5,7 +5,7 @@ What's New in Python 3.3.0 Release Candidate 1? =============================================== -*Release date: XX-Aug-2012* +*Release date: 25-Aug-2012* Core and Builtins ----------------- diff --git a/Misc/RPM/python-3.3.spec b/Misc/RPM/python-3.3.spec --- a/Misc/RPM/python-3.3.spec +++ b/Misc/RPM/python-3.3.spec @@ -39,7 +39,7 @@ %define name python #--start constants-- -%define version 3.3.0b2 +%define version 3.3.0rc1 %define libvers 3.3 #--end constants-- %define release 1pydotorg diff --git a/README b/README --- a/README +++ b/README @@ -1,5 +1,5 @@ -This is Python version 3.3.0 beta 2 -=================================== +This is Python version 3.3.0 release candidate 1 +================================================ Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Python Software Foundation. All rights reserved. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 21:34:07 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 21:34:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Added_tag_v3=2E3=2E0rc1_fo?= =?utf-8?q?r_changeset_8bb5c7bc46ba?= Message-ID: <3X48gM32MrzQTh@mail.python.org> http://hg.python.org/cpython/rev/041dbd43f701 changeset: 78770:041dbd43f701 user: Georg Brandl date: Sat Aug 25 12:16:59 2012 +0200 summary: Added tag v3.3.0rc1 for changeset 8bb5c7bc46ba files: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -105,3 +105,4 @@ 7c51388a3aa7ce76a8541bbbdfc05d2d259a162c v3.3.0a4 e15c554cd43eb23bc0a528a4e8741da9bbec9607 v3.3.0b1 4972a8f1b2aa3d7cdd64dc96aa7fa112fe1ea343 v3.3.0b2 +8bb5c7bc46ba43804480f3e328e1fa956672c885 v3.3.0rc1 -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 21:34:08 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 21:34:08 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Post-release_updates=2E?= Message-ID: <3X48gN6RLFzQVt@mail.python.org> http://hg.python.org/cpython/rev/290a07e57797 changeset: 78771:290a07e57797 user: Georg Brandl date: Sat Aug 25 21:33:08 2012 +0200 summary: Post-release updates. files: Include/patchlevel.h | 2 +- Misc/NEWS | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/Include/patchlevel.h b/Include/patchlevel.h --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 1 /* Version as a string */ -#define PY_VERSION "3.3.0rc1" +#define PY_VERSION "3.3.0rc1+" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2,6 +2,18 @@ Python News +++++++++++ +What's New in Python 3.3.0 Release Candidate 2? +=============================================== + +*Release date: XX-Sep-2012* + +Core and Builtins +----------------- + +Library +------- + + What's New in Python 3.3.0 Release Candidate 1? =============================================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Sat Aug 25 21:34:12 2012 From: python-checkins at python.org (georg.brandl) Date: Sat, 25 Aug 2012 21:34:12 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_Merge_in_changes_from_3=2E3=2E0_release_clone=2E?= Message-ID: <3X48gS1npSzQWj@mail.python.org> http://hg.python.org/cpython/rev/aa0e6eab6136 changeset: 78772:aa0e6eab6136 parent: 78767:b200acb6bed4 parent: 78771:290a07e57797 user: Georg Brandl date: Sat Aug 25 21:33:56 2012 +0200 summary: Merge in changes from 3.3.0 release clone. files: .hgtags | 1 + Doc/tools/sphinxext/susp-ignored.csv | 1 + Include/patchlevel.h | 6 ++-- Lib/distutils/__init__.py | 2 +- Lib/idlelib/idlever.py | 2 +- Lib/pydoc_data/topics.py | 18 ++++++++-------- Misc/NEWS | 14 +++++++++++- Misc/RPM/python-3.3.spec | 2 +- README | 4 +- 9 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -105,3 +105,4 @@ 7c51388a3aa7ce76a8541bbbdfc05d2d259a162c v3.3.0a4 e15c554cd43eb23bc0a528a4e8741da9bbec9607 v3.3.0b1 4972a8f1b2aa3d7cdd64dc96aa7fa112fe1ea343 v3.3.0b2 +8bb5c7bc46ba43804480f3e328e1fa956672c885 v3.3.0rc1 diff --git a/Doc/tools/sphinxext/susp-ignored.csv b/Doc/tools/sphinxext/susp-ignored.csv --- a/Doc/tools/sphinxext/susp-ignored.csv +++ b/Doc/tools/sphinxext/susp-ignored.csv @@ -262,6 +262,7 @@ library/stdtypes,,::,>>> hash(v[::-2]) == hash(b'abcefg'[::-2]) library/stdtypes,,:len,s[len(s):len(s)] library/stdtypes,,::,>>> y = m[::2] +library/stdtypes,,::,>>> z = y[::-2] library/string,,:end,s[start:end] library/subprocess,,`,"output=`dmesg | grep hda`" library/subprocess,,`,"output=`mycmd myarg`" diff --git a/Include/patchlevel.h b/Include/patchlevel.h --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -19,11 +19,11 @@ #define PY_MAJOR_VERSION 3 #define PY_MINOR_VERSION 3 #define PY_MICRO_VERSION 0 -#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_BETA -#define PY_RELEASE_SERIAL 2 +#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_GAMMA +#define PY_RELEASE_SERIAL 1 /* Version as a string */ -#define PY_VERSION "3.3.0b2+" +#define PY_VERSION "3.3.0rc1+" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff --git a/Lib/distutils/__init__.py b/Lib/distutils/__init__.py --- a/Lib/distutils/__init__.py +++ b/Lib/distutils/__init__.py @@ -13,5 +13,5 @@ # Updated automatically by the Python release process. # #--start constants-- -__version__ = "3.3.0b2" +__version__ = "3.3.0rc1" #--end constants-- diff --git a/Lib/idlelib/idlever.py b/Lib/idlelib/idlever.py --- a/Lib/idlelib/idlever.py +++ b/Lib/idlelib/idlever.py @@ -1,1 +1,1 @@ -IDLE_VERSION = "3.3.0b2" +IDLE_VERSION = "3.3.0rc1" diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py --- a/Lib/pydoc_data/topics.py +++ b/Lib/pydoc_data/topics.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Autogenerated by Sphinx on Sat Aug 11 08:41:05 2012 +# Autogenerated by Sphinx on Sat Aug 25 12:12:45 2012 topics = {'assert': '\nThe ``assert`` statement\n************************\n\nAssert statements are a convenient way to insert debugging assertions\ninto a program:\n\n assert_stmt ::= "assert" expression ["," expression]\n\nThe simple form, ``assert expression``, is equivalent to\n\n if __debug__:\n if not expression: raise AssertionError\n\nThe extended form, ``assert expression1, expression2``, is equivalent\nto\n\n if __debug__:\n if not expression1: raise AssertionError(expression2)\n\nThese equivalences assume that ``__debug__`` and ``AssertionError``\nrefer to the built-in variables with those names. In the current\nimplementation, the built-in variable ``__debug__`` is ``True`` under\nnormal circumstances, ``False`` when optimization is requested\n(command line option -O). The current code generator emits no code\nfor an assert statement when optimization is requested at compile\ntime. Note that it is unnecessary to include the source code for the\nexpression that failed in the error message; it will be displayed as\npart of the stack trace.\n\nAssignments to ``__debug__`` are illegal. The value for the built-in\nvariable is determined when the interpreter starts.\n', 'assignment': '\nAssignment statements\n*********************\n\nAssignment statements are used to (re)bind names to values and to\nmodify attributes or items of mutable objects:\n\n assignment_stmt ::= (target_list "=")+ (expression_list | yield_expression)\n target_list ::= target ("," target)* [","]\n target ::= identifier\n | "(" target_list ")"\n | "[" target_list "]"\n | attributeref\n | subscription\n | slicing\n | "*" target\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn assignment statement evaluates the expression list (remember that\nthis can be a single expression or a comma-separated list, the latter\nyielding a tuple) and assigns the single resulting object to each of\nthe target lists, from left to right.\n\nAssignment is defined recursively depending on the form of the target\n(list). When a target is part of a mutable object (an attribute\nreference, subscription or slicing), the mutable object must\nultimately perform the assignment and decide about its validity, and\nmay raise an exception if the assignment is unacceptable. The rules\nobserved by various types and the exceptions raised are given with the\ndefinition of the object types (see section *The standard type\nhierarchy*).\n\nAssignment of an object to a target list, optionally enclosed in\nparentheses or square brackets, is recursively defined as follows.\n\n* If the target list is a single target: The object is assigned to\n that target.\n\n* If the target list is a comma-separated list of targets: The object\n must be an iterable with the same number of items as there are\n targets in the target list, and the items are assigned, from left to\n right, to the corresponding targets.\n\n * If the target list contains one target prefixed with an asterisk,\n called a "starred" target: The object must be a sequence with at\n least as many items as there are targets in the target list, minus\n one. The first items of the sequence are assigned, from left to\n right, to the targets before the starred target. The final items\n of the sequence are assigned to the targets after the starred\n target. A list of the remaining items in the sequence is then\n assigned to the starred target (the list can be empty).\n\n * Else: The object must be a sequence with the same number of items\n as there are targets in the target list, and the items are\n assigned, from left to right, to the corresponding targets.\n\nAssignment of an object to a single target is recursively defined as\nfollows.\n\n* If the target is an identifier (name):\n\n * If the name does not occur in a ``global`` or ``nonlocal``\n statement in the current code block: the name is bound to the\n object in the current local namespace.\n\n * Otherwise: the name is bound to the object in the global namespace\n or the outer namespace determined by ``nonlocal``, respectively.\n\n The name is rebound if it was already bound. This may cause the\n reference count for the object previously bound to the name to reach\n zero, causing the object to be deallocated and its destructor (if it\n has one) to be called.\n\n* If the target is a target list enclosed in parentheses or in square\n brackets: The object must be an iterable with the same number of\n items as there are targets in the target list, and its items are\n assigned, from left to right, to the corresponding targets.\n\n* If the target is an attribute reference: The primary expression in\n the reference is evaluated. It should yield an object with\n assignable attributes; if this is not the case, ``TypeError`` is\n raised. That object is then asked to assign the assigned object to\n the given attribute; if it cannot perform the assignment, it raises\n an exception (usually but not necessarily ``AttributeError``).\n\n Note: If the object is a class instance and the attribute reference\n occurs on both sides of the assignment operator, the RHS expression,\n ``a.x`` can access either an instance attribute or (if no instance\n attribute exists) a class attribute. The LHS target ``a.x`` is\n always set as an instance attribute, creating it if necessary.\n Thus, the two occurrences of ``a.x`` do not necessarily refer to the\n same attribute: if the RHS expression refers to a class attribute,\n the LHS creates a new instance attribute as the target of the\n assignment:\n\n class Cls:\n x = 3 # class variable\n inst = Cls()\n inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x as 3\n\n This description does not necessarily apply to descriptor\n attributes, such as properties created with ``property()``.\n\n* If the target is a subscription: The primary expression in the\n reference is evaluated. It should yield either a mutable sequence\n object (such as a list) or a mapping object (such as a dictionary).\n Next, the subscript expression is evaluated.\n\n If the primary is a mutable sequence object (such as a list), the\n subscript must yield an integer. If it is negative, the sequence\'s\n length is added to it. The resulting value must be a nonnegative\n integer less than the sequence\'s length, and the sequence is asked\n to assign the assigned object to its item with that index. If the\n index is out of range, ``IndexError`` is raised (assignment to a\n subscripted sequence cannot add new items to a list).\n\n If the primary is a mapping object (such as a dictionary), the\n subscript must have a type compatible with the mapping\'s key type,\n and the mapping is then asked to create a key/datum pair which maps\n the subscript to the assigned object. This can either replace an\n existing key/value pair with the same key value, or insert a new\n key/value pair (if no key with the same value existed).\n\n For user-defined objects, the ``__setitem__()`` method is called\n with appropriate arguments.\n\n* If the target is a slicing: The primary expression in the reference\n is evaluated. It should yield a mutable sequence object (such as a\n list). The assigned object should be a sequence object of the same\n type. Next, the lower and upper bound expressions are evaluated,\n insofar they are present; defaults are zero and the sequence\'s\n length. The bounds should evaluate to integers. If either bound is\n negative, the sequence\'s length is added to it. The resulting\n bounds are clipped to lie between zero and the sequence\'s length,\n inclusive. Finally, the sequence object is asked to replace the\n slice with the items of the assigned sequence. The length of the\n slice may be different from the length of the assigned sequence,\n thus changing the length of the target sequence, if the object\n allows it.\n\n**CPython implementation detail:** In the current implementation, the\nsyntax for targets is taken to be the same as for expressions, and\ninvalid syntax is rejected during the code generation phase, causing\nless detailed error messages.\n\nWARNING: Although the definition of assignment implies that overlaps\nbetween the left-hand side and the right-hand side are \'safe\' (for\nexample ``a, b = b, a`` swaps two variables), overlaps *within* the\ncollection of assigned-to variables are not safe! For instance, the\nfollowing program prints ``[0, 2]``:\n\n x = [0, 1]\n i = 0\n i, x[i] = 1, 2\n print(x)\n\nSee also:\n\n **PEP 3132** - Extended Iterable Unpacking\n The specification for the ``*target`` feature.\n\n\nAugmented assignment statements\n===============================\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like ``x += 1`` can be rewritten as\n``x = x + 1`` to achieve a similar, but not exactly equal effect. In\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n', 'atom-identifiers': '\nIdentifiers (Names)\n*******************\n\nAn identifier occurring as an atom is a name. See section\n*Identifiers and keywords* for lexical definition and section *Naming\nand binding* for documentation of naming and binding.\n\nWhen the name is bound to an object, evaluation of the atom yields\nthat object. When a name is not bound, an attempt to evaluate it\nraises a ``NameError`` exception.\n\n**Private name mangling:** When an identifier that textually occurs in\na class definition begins with two or more underscore characters and\ndoes not end in two or more underscores, it is considered a *private\nname* of that class. Private names are transformed to a longer form\nbefore code is generated for them. The transformation inserts the\nclass name in front of the name, with leading underscores removed, and\na single underscore inserted in front of the class name. For example,\nthe identifier ``__spam`` occurring in a class named ``Ham`` will be\ntransformed to ``_Ham__spam``. This transformation is independent of\nthe syntactical context in which the identifier is used. If the\ntransformed name is extremely long (longer than 255 characters),\nimplementation defined truncation may happen. If the class name\nconsists only of underscores, no transformation is done.\n', @@ -7,7 +7,7 @@ 'attribute-access': '\nCustomizing attribute access\n****************************\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n========================\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n====================\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n=========\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n--------------------------\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n', 'attribute-references': '\nAttribute references\n********************\n\nAn attribute reference is a primary followed by a period and a name:\n\n attributeref ::= primary "." identifier\n\nThe primary must evaluate to an object of a type that supports\nattribute references, which most objects do. This object is then\nasked to produce the attribute whose name is the identifier (which can\nbe customized by overriding the ``__getattr__()`` method). If this\nattribute is not available, the exception ``AttributeError`` is\nraised. Otherwise, the type and value of the object produced is\ndetermined by the object. Multiple evaluations of the same attribute\nreference may yield different objects.\n', 'augassign': '\nAugmented assignment statements\n*******************************\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section *Primaries* for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like ``x += 1`` can be rewritten as\n``x = x + 1`` to achieve a similar, but not exactly equal effect. In\nthe augmented version, ``x`` is only evaluated once. Also, when\npossible, the actual operation is performed *in-place*, meaning that\nrather than creating a new object and assigning that to the target,\nthe old object is modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same *caveat about\nclass and instance attributes* applies as for regular assignments.\n', - 'binary': '\nBinary arithmetic operations\n****************************\n\nThe binary arithmetic operations have the conventional priority\nlevels. Note that some of these operations also apply to certain non-\nnumeric types. Apart from the power operator, there are only two\nlevels, one for multiplicative operators and one for additive\noperators:\n\n m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr\n | m_expr "%" u_expr\n a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n\nThe ``*`` (multiplication) operator yields the product of its\narguments. The arguments must either both be numbers, or one argument\nmust be an integer and the other must be a sequence. In the former\ncase, the numbers are converted to a common type and then multiplied\ntogether. In the latter case, sequence repetition is performed; a\nnegative repetition factor yields an empty sequence.\n\nThe ``/`` (division) and ``//`` (floor division) operators yield the\nquotient of their arguments. The numeric arguments are first\nconverted to a common type. Integer division yields a float, while\nfloor division of integers results in an integer; the result is that\nof mathematical division with the \'floor\' function applied to the\nresult. Division by zero raises the ``ZeroDivisionError`` exception.\n\nThe ``%`` (modulo) operator yields the remainder from the division of\nthe first argument by the second. The numeric arguments are first\nconverted to a common type. A zero right argument raises the\n``ZeroDivisionError`` exception. The arguments may be floating point\nnumbers, e.g., ``3.14%0.7`` equals ``0.34`` (since ``3.14`` equals\n``4*0.7 + 0.34``.) The modulo operator always yields a result with\nthe same sign as its second operand (or zero); the absolute value of\nthe result is strictly smaller than the absolute value of the second\noperand [1].\n\nThe floor division and modulo operators are connected by the following\nidentity: ``x == (x//y)*y + (x%y)``. Floor division and modulo are\nalso connected with the built-in function ``divmod()``: ``divmod(x, y)\n== (x//y, x%y)``. [2].\n\nIn addition to performing the modulo operation on numbers, the ``%``\noperator is also overloaded by string objects to perform old-style\nstring formatting (also known as interpolation). The syntax for\nstring formatting is described in the Python Library Reference,\nsection *Old String Formatting Operations*.\n\nThe floor division operator, the modulo operator, and the ``divmod()``\nfunction are not defined for complex numbers. Instead, convert to a\nfloating point number using the ``abs()`` function if appropriate.\n\nThe ``+`` (addition) operator yields the sum of its arguments. The\narguments must either both be numbers or both sequences of the same\ntype. In the former case, the numbers are converted to a common type\nand then added together. In the latter case, the sequences are\nconcatenated.\n\nThe ``-`` (subtraction) operator yields the difference of its\narguments. The numeric arguments are first converted to a common\ntype.\n', + 'binary': '\nBinary arithmetic operations\n****************************\n\nThe binary arithmetic operations have the conventional priority\nlevels. Note that some of these operations also apply to certain non-\nnumeric types. Apart from the power operator, there are only two\nlevels, one for multiplicative operators and one for additive\noperators:\n\n m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr\n | m_expr "%" u_expr\n a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n\nThe ``*`` (multiplication) operator yields the product of its\narguments. The arguments must either both be numbers, or one argument\nmust be an integer and the other must be a sequence. In the former\ncase, the numbers are converted to a common type and then multiplied\ntogether. In the latter case, sequence repetition is performed; a\nnegative repetition factor yields an empty sequence.\n\nThe ``/`` (division) and ``//`` (floor division) operators yield the\nquotient of their arguments. The numeric arguments are first\nconverted to a common type. Integer division yields a float, while\nfloor division of integers results in an integer; the result is that\nof mathematical division with the \'floor\' function applied to the\nresult. Division by zero raises the ``ZeroDivisionError`` exception.\n\nThe ``%`` (modulo) operator yields the remainder from the division of\nthe first argument by the second. The numeric arguments are first\nconverted to a common type. A zero right argument raises the\n``ZeroDivisionError`` exception. The arguments may be floating point\nnumbers, e.g., ``3.14%0.7`` equals ``0.34`` (since ``3.14`` equals\n``4*0.7 + 0.34``.) The modulo operator always yields a result with\nthe same sign as its second operand (or zero); the absolute value of\nthe result is strictly smaller than the absolute value of the second\noperand [1].\n\nThe floor division and modulo operators are connected by the following\nidentity: ``x == (x//y)*y + (x%y)``. Floor division and modulo are\nalso connected with the built-in function ``divmod()``: ``divmod(x, y)\n== (x//y, x%y)``. [2].\n\nIn addition to performing the modulo operation on numbers, the ``%``\noperator is also overloaded by string objects to perform old-style\nstring formatting (also known as interpolation). The syntax for\nstring formatting is described in the Python Library Reference,\nsection *printf-style String Formatting*.\n\nThe floor division operator, the modulo operator, and the ``divmod()``\nfunction are not defined for complex numbers. Instead, convert to a\nfloating point number using the ``abs()`` function if appropriate.\n\nThe ``+`` (addition) operator yields the sum of its arguments. The\narguments must either both be numbers or both sequences of the same\ntype. In the former case, the numbers are converted to a common type\nand then added together. In the latter case, the sequences are\nconcatenated.\n\nThe ``-`` (subtraction) operator yields the difference of its\narguments. The numeric arguments are first converted to a common\ntype.\n', 'bitwise': '\nBinary bitwise operations\n*************************\n\nEach of the three bitwise operations has a different priority level:\n\n and_expr ::= shift_expr | and_expr "&" shift_expr\n xor_expr ::= and_expr | xor_expr "^" and_expr\n or_expr ::= xor_expr | or_expr "|" xor_expr\n\nThe ``&`` operator yields the bitwise AND of its arguments, which must\nbe integers.\n\nThe ``^`` operator yields the bitwise XOR (exclusive OR) of its\narguments, which must be integers.\n\nThe ``|`` operator yields the bitwise (inclusive) OR of its arguments,\nwhich must be integers.\n', 'bltin-code-objects': '\nCode Objects\n************\n\nCode objects are used by the implementation to represent "pseudo-\ncompiled" executable Python code such as a function body. They differ\nfrom function objects because they don\'t contain a reference to their\nglobal execution environment. Code objects are returned by the built-\nin ``compile()`` function and can be extracted from function objects\nthrough their ``__code__`` attribute. See also the ``code`` module.\n\nA code object can be executed or evaluated by passing it (instead of a\nsource string) to the ``exec()`` or ``eval()`` built-in functions.\n\nSee *The standard type hierarchy* for more information.\n', 'bltin-ellipsis-object': '\nThe Ellipsis Object\n*******************\n\nThis object is commonly used by slicing (see *Slicings*). It supports\nno special operations. There is exactly one ellipsis object, named\n``Ellipsis`` (a built-in name). ``type(Ellipsis)()`` produces the\n``Ellipsis`` singleton.\n\nIt is written as ``Ellipsis`` or ``...``.\n', @@ -19,7 +19,7 @@ 'calls': '\nCalls\n*****\n\nA call calls a callable object (e.g., a function) with a possibly\nempty series of arguments:\n\n call ::= primary "(" [argument_list [","] | comprehension] ")"\n argument_list ::= positional_arguments ["," keyword_arguments]\n ["," "*" expression] ["," keyword_arguments]\n ["," "**" expression]\n | keyword_arguments ["," "*" expression]\n ["," keyword_arguments] ["," "**" expression]\n | "*" expression ["," keyword_arguments] ["," "**" expression]\n | "**" expression\n positional_arguments ::= expression ("," expression)*\n keyword_arguments ::= keyword_item ("," keyword_item)*\n keyword_item ::= identifier "=" expression\n\nA trailing comma may be present after the positional and keyword\narguments but does not affect the semantics.\n\nThe primary must evaluate to a callable object (user-defined\nfunctions, built-in functions, methods of built-in objects, class\nobjects, methods of class instances, and all objects having a\n``__call__()`` method are callable). All argument expressions are\nevaluated before the call is attempted. Please refer to section\n*Function definitions* for the syntax of formal parameter lists.\n\nIf keyword arguments are present, they are first converted to\npositional arguments, as follows. First, a list of unfilled slots is\ncreated for the formal parameters. If there are N positional\narguments, they are placed in the first N slots. Next, for each\nkeyword argument, the identifier is used to determine the\ncorresponding slot (if the identifier is the same as the first formal\nparameter name, the first slot is used, and so on). If the slot is\nalready filled, a ``TypeError`` exception is raised. Otherwise, the\nvalue of the argument is placed in the slot, filling it (even if the\nexpression is ``None``, it fills the slot). When all arguments have\nbeen processed, the slots that are still unfilled are filled with the\ncorresponding default value from the function definition. (Default\nvalues are calculated, once, when the function is defined; thus, a\nmutable object such as a list or dictionary used as default value will\nbe shared by all calls that don\'t specify an argument value for the\ncorresponding slot; this should usually be avoided.) If there are any\nunfilled slots for which no default value is specified, a\n``TypeError`` exception is raised. Otherwise, the list of filled\nslots is used as the argument list for the call.\n\n**CPython implementation detail:** An implementation may provide\nbuilt-in functions whose positional parameters do not have names, even\nif they are \'named\' for the purpose of documentation, and which\ntherefore cannot be supplied by keyword. In CPython, this is the case\nfor functions implemented in C that use ``PyArg_ParseTuple()`` to\nparse their arguments.\n\nIf there are more positional arguments than there are formal parameter\nslots, a ``TypeError`` exception is raised, unless a formal parameter\nusing the syntax ``*identifier`` is present; in this case, that formal\nparameter receives a tuple containing the excess positional arguments\n(or an empty tuple if there were no excess positional arguments).\n\nIf any keyword argument does not correspond to a formal parameter\nname, a ``TypeError`` exception is raised, unless a formal parameter\nusing the syntax ``**identifier`` is present; in this case, that\nformal parameter receives a dictionary containing the excess keyword\narguments (using the keywords as keys and the argument values as\ncorresponding values), or a (new) empty dictionary if there were no\nexcess keyword arguments.\n\nIf the syntax ``*expression`` appears in the function call,\n``expression`` must evaluate to an iterable. Elements from this\niterable are treated as if they were additional positional arguments;\nif there are positional arguments *x1*, ..., *xN*, and ``expression``\nevaluates to a sequence *y1*, ..., *yM*, this is equivalent to a call\nwith M+N positional arguments *x1*, ..., *xN*, *y1*, ..., *yM*.\n\nA consequence of this is that although the ``*expression`` syntax may\nappear *after* some keyword arguments, it is processed *before* the\nkeyword arguments (and the ``**expression`` argument, if any -- see\nbelow). So:\n\n >>> def f(a, b):\n ... print(a, b)\n ...\n >>> f(b=1, *(2,))\n 2 1\n >>> f(a=1, *(2,))\n Traceback (most recent call last):\n File "", line 1, in ?\n TypeError: f() got multiple values for keyword argument \'a\'\n >>> f(1, *(2,))\n 1 2\n\nIt is unusual for both keyword arguments and the ``*expression``\nsyntax to be used in the same call, so in practice this confusion does\nnot arise.\n\nIf the syntax ``**expression`` appears in the function call,\n``expression`` must evaluate to a mapping, the contents of which are\ntreated as additional keyword arguments. In the case of a keyword\nappearing in both ``expression`` and as an explicit keyword argument,\na ``TypeError`` exception is raised.\n\nFormal parameters using the syntax ``*identifier`` or ``**identifier``\ncannot be used as positional argument slots or as keyword argument\nnames.\n\nA call always returns some value, possibly ``None``, unless it raises\nan exception. How this value is computed depends on the type of the\ncallable object.\n\nIf it is---\n\na user-defined function:\n The code block for the function is executed, passing it the\n argument list. The first thing the code block will do is bind the\n formal parameters to the arguments; this is described in section\n *Function definitions*. When the code block executes a ``return``\n statement, this specifies the return value of the function call.\n\na built-in function or method:\n The result is up to the interpreter; see *Built-in Functions* for\n the descriptions of built-in functions and methods.\n\na class object:\n A new instance of that class is returned.\n\na class instance method:\n The corresponding user-defined function is called, with an argument\n list that is one longer than the argument list of the call: the\n instance becomes the first argument.\n\na class instance:\n The class must define a ``__call__()`` method; the effect is then\n the same as if that method was called.\n', 'class': '\nClass definitions\n*****************\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n exception or the execution of a ``return``, ``continue``, or\n ``break`` statement.\n\n[3] A string literal appearing as the first statement in the function\n body is transformed into the function\'s ``__doc__`` attribute and\n therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s ``__doc__`` item and\n therefore the class\'s *docstring*.\n', 'comparisons': '\nComparisons\n***********\n\nUnlike C, all comparison operations in Python have the same priority,\nwhich is lower than that of any arithmetic, shifting or bitwise\noperation. Also unlike C, expressions like ``a < b < c`` have the\ninterpretation that is conventional in mathematics:\n\n comparison ::= or_expr ( comp_operator or_expr )*\n comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!="\n | "is" ["not"] | ["not"] "in"\n\nComparisons yield boolean values: ``True`` or ``False``.\n\nComparisons can be chained arbitrarily, e.g., ``x < y <= z`` is\nequivalent to ``x < y and y <= z``, except that ``y`` is evaluated\nonly once (but in both cases ``z`` is not evaluated at all when ``x <\ny`` is found to be false).\n\nFormally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*,\n*op2*, ..., *opN* are comparison operators, then ``a op1 b op2 c ... y\nopN z`` is equivalent to ``a op1 b and b op2 c and ... y opN z``,\nexcept that each expression is evaluated at most once.\n\nNote that ``a op1 b op2 c`` doesn\'t imply any kind of comparison\nbetween *a* and *c*, so that, e.g., ``x < y > z`` is perfectly legal\n(though perhaps not pretty).\n\nThe operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare\nthe values of two objects. The objects need not have the same type.\nIf both are numbers, they are converted to a common type. Otherwise,\nthe ``==`` and ``!=`` operators *always* consider objects of different\ntypes to be unequal, while the ``<``, ``>``, ``>=`` and ``<=``\noperators raise a ``TypeError`` when comparing objects of different\ntypes that do not implement these operators for the given pair of\ntypes. You can control comparison behavior of objects of non-built-in\ntypes by defining rich comparison methods like ``__gt__()``, described\nin section *Basic customization*.\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* The values ``float(\'NaN\')`` and ``Decimal(\'NaN\')`` are special. The\n are identical to themselves, ``x is x`` but are not equal to\n themselves, ``x != x``. Additionally, comparing any value to a\n not-a-number value will return ``False``. For example, both ``3 <\n float(\'NaN\')`` and ``float(\'NaN\') < 3`` will return ``False``.\n\n* Bytes objects are compared lexicographically using the numeric\n values of their elements.\n\n* Strings are compared lexicographically using the numeric equivalents\n (the result of the built-in function ``ord()``) of their characters.\n [3] String and bytes object can\'t be compared!\n\n* Tuples and lists are compared lexicographically using comparison of\n corresponding elements. This means that to compare equal, each\n element must compare equal and the two sequences must be of the same\n type and have the same length.\n\n If not equal, the sequences are ordered the same as their first\n differing elements. For example, ``[1,2,x] <= [1,2,y]`` has the\n same value as ``x <= y``. If the corresponding element does not\n exist, the shorter sequence is ordered first (for example, ``[1,2] <\n [1,2,3]``).\n\n* Mappings (dictionaries) compare equal if and only if they have the\n same ``(key, value)`` pairs. Order comparisons ``(\'<\', \'<=\', \'>=\',\n \'>\')`` raise ``TypeError``.\n\n* Sets and frozensets define comparison operators to mean subset and\n superset tests. Those relations do not define total orderings (the\n two sets ``{1,2}`` and {2,3} are not equal, nor subsets of one\n another, nor supersets of one another). Accordingly, sets are not\n appropriate arguments for functions which depend on total ordering.\n For example, ``min()``, ``max()``, and ``sorted()`` produce\n undefined results given a list of sets as inputs.\n\n* Most other objects of built-in types compare unequal unless they are\n the same object; the choice whether one object is considered smaller\n or larger than another one is made arbitrarily but consistently\n within one execution of a program.\n\nComparison of objects of the differing types depends on whether either\nof the types provide explicit support for the comparison. Most\nnumeric types can be compared with one another, but comparisons of\n``float`` and ``Decimal`` are not supported to avoid the inevitable\nconfusion arising from representation issues such as ``float(\'1.1\')``\nbeing inexactly represented and therefore not exactly equal to\n``Decimal(\'1.1\')`` which is. When cross-type comparison is not\nsupported, the comparison method returns ``NotImplemented``. This can\ncreate the illusion of non-transitivity between supported cross-type\ncomparisons and unsupported comparisons. For example, ``Decimal(2) ==\n2`` and ``2 == float(2)`` but ``Decimal(2) != float(2)``.\n\nThe operators ``in`` and ``not in`` test for membership. ``x in s``\nevaluates to true if *x* is a member of *s*, and false otherwise. ``x\nnot in s`` returns the negation of ``x in s``. All built-in sequences\nand set types support this as well as dictionary, for which ``in``\ntests whether a the dictionary has a given key. For container types\nsuch as list, tuple, set, frozenset, dict, or collections.deque, the\nexpression ``x in y`` is equivalent to ``any(x is e or x == e for e in\ny)``.\n\nFor the string and bytes types, ``x in y`` is true if and only if *x*\nis a substring of *y*. An equivalent test is ``y.find(x) != -1``.\nEmpty strings are always considered to be a substring of any other\nstring, so ``"" in "abc"`` will return ``True``.\n\nFor user-defined classes which define the ``__contains__()`` method,\n``x in y`` is true if and only if ``y.__contains__(x)`` is true.\n\nFor user-defined classes which do not define ``__contains__()`` but do\ndefine ``__iter__()``, ``x in y`` is true if some value ``z`` with ``x\n== z`` is produced while iterating over ``y``. If an exception is\nraised during the iteration, it is as if ``in`` raised that exception.\n\nLastly, the old-style iteration protocol is tried: if a class defines\n``__getitem__()``, ``x in y`` is true if and only if there is a non-\nnegative integer index *i* such that ``x == y[i]``, and all lower\ninteger indices do not raise ``IndexError`` exception. (If any other\nexception is raised, it is as if ``in`` raised that exception).\n\nThe operator ``not in`` is defined to have the inverse true value of\n``in``.\n\nThe operators ``is`` and ``is not`` test for object identity: ``x is\ny`` is true if and only if *x* and *y* are the same object. ``x is\nnot y`` yields the inverse truth value. [4]\n', - 'compound': '\nCompound statements\n*******************\n\nCompound statements contain (groups of) other statements; they affect\nor control the execution of those other statements in some way. In\ngeneral, compound statements span multiple lines, although in simple\nincarnations a whole compound statement may be contained in one line.\n\nThe ``if``, ``while`` and ``for`` statements implement traditional\ncontrol flow constructs. ``try`` specifies exception handlers and/or\ncleanup code for a group of statements, while the ``with`` statement\nallows the execution of initialization and finalization code around a\nblock of code. Function and class definitions are also syntactically\ncompound statements.\n\nCompound statements consist of one or more \'clauses.\' A clause\nconsists of a header and a \'suite.\' The clause headers of a\nparticular compound statement are all at the same indentation level.\nEach clause header begins with a uniquely identifying keyword and ends\nwith a colon. A suite is a group of statements controlled by a\nclause. A suite can be one or more semicolon-separated simple\nstatements on the same line as the header, following the header\'s\ncolon, or it can be one or more indented statements on subsequent\nlines. Only the latter form of suite can contain nested compound\nstatements; the following is illegal, mostly because it wouldn\'t be\nclear to which ``if`` clause a following ``else`` clause would belong:\n\n if test1: if test2: print(x)\n\nAlso note that the semicolon binds tighter than the colon in this\ncontext, so that in the following example, either all or none of the\n``print()`` calls are executed:\n\n if x < y < z: print(x); print(y); print(z)\n\nSummarizing:\n\n compound_stmt ::= if_stmt\n | while_stmt\n | for_stmt\n | try_stmt\n | with_stmt\n | funcdef\n | classdef\n suite ::= stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\n statement ::= stmt_list NEWLINE | compound_stmt\n stmt_list ::= simple_stmt (";" simple_stmt)* [";"]\n\nNote that statements always end in a ``NEWLINE`` possibly followed by\na ``DEDENT``. Also note that optional continuation clauses always\nbegin with a keyword that cannot start a statement, thus there are no\nambiguities (the \'dangling ``else``\' problem is solved in Python by\nrequiring nested ``if`` statements to be indented).\n\nThe formatting of the grammar rules in the following sections places\neach clause on a separate line for clarity.\n\n\nThe ``if`` statement\n====================\n\nThe ``if`` statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section *Boolean operations*\nfor the definition of true and false); then that suite is executed\n(and no other part of the ``if`` statement is executed or evaluated).\nIf all expressions are false, the suite of the ``else`` clause, if\npresent, is executed.\n\n\nThe ``while`` statement\n=======================\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n\n\nThe ``for`` statement\n=====================\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n``expression_list``. The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in the ``else`` clause, if present, is executed,\nand the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n\n\nThe ``try`` statement\n=====================\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception, it is re-raised at the end\nof the ``finally`` clause. If the ``finally`` clause raises another\nexception or executes a ``return`` or ``break`` statement, the saved\nexception is set as the context of the new exception. The exception\ninformation is not available to the program during execution of the\n``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n\n\nThe ``with`` statement\n======================\n\nThe ``with`` statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section *With Statement\nContext Managers*). This allows common\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the ``with`` statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the ``with_item``)\n is evaluated to obtain a context manager.\n\n2. The context manager\'s ``__exit__()`` is loaded for later use.\n\n3. The context manager\'s ``__enter__()`` method is invoked.\n\n4. If a target was included in the ``with`` statement, the return\n value from ``__enter__()`` is assigned to it.\n\n Note: The ``with`` statement guarantees that if the ``__enter__()``\n method returns without an error, then ``__exit__()`` will always\n be called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s ``__exit__()`` method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to ``__exit__()``. Otherwise,\n three ``None`` arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the ``__exit__()`` method was false, the exception is\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from ``__exit__()`` is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple ``with`` statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nFunction definitions\n====================\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more parameters have the form *parameter* ``=``\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding argument may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters up until the "``*``" must also have a default value ---\nthis is a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use ``None`` as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A "``def``"\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n exception or the execution of a ``return``, ``continue``, or\n ``break`` statement.\n\n[3] A string literal appearing as the first statement in the function\n body is transformed into the function\'s ``__doc__`` attribute and\n therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s ``__doc__`` item and\n therefore the class\'s *docstring*.\n', + 'compound': '\nCompound statements\n*******************\n\nCompound statements contain (groups of) other statements; they affect\nor control the execution of those other statements in some way. In\ngeneral, compound statements span multiple lines, although in simple\nincarnations a whole compound statement may be contained in one line.\n\nThe ``if``, ``while`` and ``for`` statements implement traditional\ncontrol flow constructs. ``try`` specifies exception handlers and/or\ncleanup code for a group of statements, while the ``with`` statement\nallows the execution of initialization and finalization code around a\nblock of code. Function and class definitions are also syntactically\ncompound statements.\n\nCompound statements consist of one or more \'clauses.\' A clause\nconsists of a header and a \'suite.\' The clause headers of a\nparticular compound statement are all at the same indentation level.\nEach clause header begins with a uniquely identifying keyword and ends\nwith a colon. A suite is a group of statements controlled by a\nclause. A suite can be one or more semicolon-separated simple\nstatements on the same line as the header, following the header\'s\ncolon, or it can be one or more indented statements on subsequent\nlines. Only the latter form of suite can contain nested compound\nstatements; the following is illegal, mostly because it wouldn\'t be\nclear to which ``if`` clause a following ``else`` clause would belong:\n\n if test1: if test2: print(x)\n\nAlso note that the semicolon binds tighter than the colon in this\ncontext, so that in the following example, either all or none of the\n``print()`` calls are executed:\n\n if x < y < z: print(x); print(y); print(z)\n\nSummarizing:\n\n compound_stmt ::= if_stmt\n | while_stmt\n | for_stmt\n | try_stmt\n | with_stmt\n | funcdef\n | classdef\n suite ::= stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\n statement ::= stmt_list NEWLINE | compound_stmt\n stmt_list ::= simple_stmt (";" simple_stmt)* [";"]\n\nNote that statements always end in a ``NEWLINE`` possibly followed by\na ``DEDENT``. Also note that optional continuation clauses always\nbegin with a keyword that cannot start a statement, thus there are no\nambiguities (the \'dangling ``else``\' problem is solved in Python by\nrequiring nested ``if`` statements to be indented).\n\nThe formatting of the grammar rules in the following sections places\neach clause on a separate line for clarity.\n\n\nThe ``if`` statement\n====================\n\nThe ``if`` statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section *Boolean operations*\nfor the definition of true and false); then that suite is executed\n(and no other part of the ``if`` statement is executed or evaluated).\nIf all expressions are false, the suite of the ``else`` clause, if\npresent, is executed.\n\n\nThe ``while`` statement\n=======================\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n\n\nThe ``for`` statement\n=====================\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n``expression_list``. The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in the ``else`` clause, if present, is executed,\nand the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n\n\nThe ``try`` statement\n=====================\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception or ``break`` statement, it is\nre-raised at the end of the ``finally`` clause. If the ``finally``\nclause raises another exception the saved exception is set as the\ncontext of the new exception; if the ``finally`` clause executes a\n``return`` statement, the saved exception is discarded:\n\n def f():\n try:\n 1/0\n finally:\n return 42\n\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the ``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n\n\nThe ``with`` statement\n======================\n\nThe ``with`` statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section *With Statement\nContext Managers*). This allows common\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the ``with`` statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the ``with_item``)\n is evaluated to obtain a context manager.\n\n2. The context manager\'s ``__exit__()`` is loaded for later use.\n\n3. The context manager\'s ``__enter__()`` method is invoked.\n\n4. If a target was included in the ``with`` statement, the return\n value from ``__enter__()`` is assigned to it.\n\n Note: The ``with`` statement guarantees that if the ``__enter__()``\n method returns without an error, then ``__exit__()`` will always\n be called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s ``__exit__()`` method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to ``__exit__()``. Otherwise,\n three ``None`` arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the ``__exit__()`` method was false, the exception is\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from ``__exit__()`` is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple ``with`` statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nFunction definitions\n====================\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more parameters have the form *parameter* ``=``\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding argument may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters up until the "``*``" must also have a default value ---\nthis is a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use ``None`` as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A "``def``"\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section *The standard\ntype hierarchy*):\n\n classdef ::= [decorators] "class" classname [inheritance] ":" suite\n inheritance ::= "(" [parameter_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. The inheritance list\nusually gives a list of base classes (see *Customizing class creation*\nfor more advanced uses), so each item in the list should evaluate to a\nclass object which allows subclassing. Classes without an inheritance\nlist inherit, by default, from the base class ``object``; hence,\n\n class Foo:\n pass\n\nis equivalent to\n\n class Foo(object):\n pass\n\nThe class\'s suite is then executed in a new execution frame (see\n*Naming and binding*), using a newly created local namespace and the\noriginal global namespace. (Usually, the suite contains mostly\nfunction definitions.) When the class\'s suite finishes execution, its\nexecution frame is discarded but its local namespace is saved. [4] A\nclass object is then created using the inheritance list for the base\nclasses and the saved local namespace for the attribute dictionary.\nThe class name is bound to this class object in the original local\nnamespace.\n\nClass creation can be customized heavily using *metaclasses*.\n\nClasses can also be decorated: just like when decorating functions,\n\n @f1(arg)\n @f2\n class Foo: pass\n\nis equivalent to\n\n class Foo: pass\n Foo = f1(arg)(f2(Foo))\n\nThe evaluation rules for the decorator expressions are the same as for\nfunction decorators. The result must be a class object, which is then\nbound to the class name.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass attributes; they are shared by instances. Instance attributes\ncan be set in a method with ``self.name = value``. Both class and\ninstance attributes are accessible through the notation\n"``self.name``", and an instance attribute hides a class attribute\nwith the same name when accessed in this way. Class attributes can be\nused as defaults for instance attributes, but using mutable values\nthere can lead to unexpected results. *Descriptors* can be used to\ncreate instance variables with different implementation details.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3 **PEP 3129** - Class\n Decorators\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless there\n is a ``finally`` clause which happens to raise another exception.\n That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of an\n exception or the execution of a ``return``, ``continue``, or\n ``break`` statement.\n\n[3] A string literal appearing as the first statement in the function\n body is transformed into the function\'s ``__doc__`` attribute and\n therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s ``__doc__`` item and\n therefore the class\'s *docstring*.\n', 'context-managers': '\nWith Statement Context Managers\n*******************************\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n', 'continue': '\nThe ``continue`` statement\n**************************\n\n continue_stmt ::= "continue"\n\n``continue`` may only occur syntactically nested in a ``for`` or\n``while`` loop, but not nested in a function or class definition or\n``finally`` clause within that loop. It continues with the next cycle\nof the nearest enclosing loop.\n\nWhen ``continue`` passes control out of a ``try`` statement with a\n``finally`` clause, that ``finally`` clause is executed before really\nstarting the next loop cycle.\n', 'conversions': '\nArithmetic conversions\n**********************\n\nWhen a description of an arithmetic operator below uses the phrase\n"the numeric arguments are converted to a common type," this means\nthat the operator implementation for built-in types works that way:\n\n* If either argument is a complex number, the other is converted to\n complex;\n\n* otherwise, if either argument is a floating point number, the other\n is converted to floating point;\n\n* otherwise, both must be integers and no conversion is necessary.\n\nSome additional rules apply for certain operators (e.g., a string left\nargument to the \'%\' operator). Extensions must define their own\nconversion behavior.\n', @@ -34,7 +34,7 @@ 'exprlists': '\nExpression lists\n****************\n\n expression_list ::= expression ( "," expression )* [","]\n\nAn expression list containing at least one comma yields a tuple. The\nlength of the tuple is the number of expressions in the list. The\nexpressions are evaluated from left to right.\n\nThe trailing comma is required only to create a single tuple (a.k.a. a\n*singleton*); it is optional in all other cases. A single expression\nwithout a trailing comma doesn\'t create a tuple, but rather yields the\nvalue of that expression. (To create an empty tuple, use an empty pair\nof parentheses: ``()``.)\n', 'floating': '\nFloating point literals\n***********************\n\nFloating point literals are described by the following lexical\ndefinitions:\n\n floatnumber ::= pointfloat | exponentfloat\n pointfloat ::= [intpart] fraction | intpart "."\n exponentfloat ::= (intpart | pointfloat) exponent\n intpart ::= digit+\n fraction ::= "." digit+\n exponent ::= ("e" | "E") ["+" | "-"] digit+\n\nNote that the integer and exponent parts are always interpreted using\nradix 10. For example, ``077e010`` is legal, and denotes the same\nnumber as ``77e10``. The allowed range of floating point literals is\nimplementation-dependent. Some examples of floating point literals:\n\n 3.14 10. .001 1e100 3.14e-10 0e0\n\nNote that numeric literals do not include a sign; a phrase like ``-1``\nis actually an expression composed of the unary operator ``-`` and the\nliteral ``1``.\n', 'for': '\nThe ``for`` statement\n*********************\n\nThe ``for`` statement is used to iterate over the elements of a\nsequence (such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n``expression_list``. The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments (see *Assignment statements*), and then the suite is\nexecuted. When the items are exhausted (which is immediately when the\nsequence is empty or an iterator raises a ``StopIteration``\nexception), the suite in the ``else`` clause, if present, is executed,\nand the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ncontinues with the next item, or with the ``else`` clause if there was\nno next item.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nNames in the target list are not deleted when the loop is finished,\nbut if the sequence is empty, it will not have been assigned to at all\nby the loop. Hint: the built-in function ``range()`` returns an\niterator of integers suitable to emulate the effect of Pascal\'s ``for\ni := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1,\n2]``.\n\nNote: There is a subtlety when the sequence is being modified by the loop\n (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n', - 'formatstrings': '\nFormat String Syntax\n********************\n\nThe ``str.format()`` method and the ``Formatter`` class share the same\nsyntax for format strings (although in the case of ``Formatter``,\nsubclasses can define their own format string syntax).\n\nFormat strings contain "replacement fields" surrounded by curly braces\n``{}``. Anything that is not contained in braces is considered literal\ntext, which is copied unchanged to the output. If you need to include\na brace character in the literal text, it can be escaped by doubling:\n``{{`` and ``}}``.\n\nThe grammar for a replacement field is as follows:\n\n replacement_field ::= "{" [field_name] ["!" conversion] [":" format_spec] "}"\n field_name ::= arg_name ("." attribute_name | "[" element_index "]")*\n arg_name ::= [identifier | integer]\n attribute_name ::= identifier\n element_index ::= integer | index_string\n index_string ::= +\n conversion ::= "r" | "s" | "a"\n format_spec ::= \n\nIn less formal terms, the replacement field can start with a\n*field_name* that specifies the object whose value is to be formatted\nand inserted into the output instead of the replacement field. The\n*field_name* is optionally followed by a *conversion* field, which is\npreceded by an exclamation point ``\'!\'``, and a *format_spec*, which\nis preceded by a colon ``\':\'``. These specify a non-default format\nfor the replacement value.\n\nSee also the *Format Specification Mini-Language* section.\n\nThe *field_name* itself begins with an *arg_name* that is either a\nnumber or a keyword. If it\'s a number, it refers to a positional\nargument, and if it\'s a keyword, it refers to a named keyword\nargument. If the numerical arg_names in a format string are 0, 1, 2,\n... in sequence, they can all be omitted (not just some) and the\nnumbers 0, 1, 2, ... will be automatically inserted in that order.\nBecause *arg_name* is not quote-delimited, it is not possible to\nspecify arbitrary dictionary keys (e.g., the strings ``\'10\'`` or\n``\':-]\'``) within a format string. The *arg_name* can be followed by\nany number of index or attribute expressions. An expression of the\nform ``\'.name\'`` selects the named attribute using ``getattr()``,\nwhile an expression of the form ``\'[index]\'`` does an index lookup\nusing ``__getitem__()``.\n\nChanged in version 3.1: The positional argument specifiers can be\nomitted, so ``\'{} {}\'`` is equivalent to ``\'{0} {1}\'``.\n\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\n "Bring me a {}" # Implicitly references the first positional argument\n "From {} to {}" # Same as "From {0} to {1}"\n "My quest is {name}" # References keyword argument \'name\'\n "Weight in tons {0.weight}" # \'weight\' attribute of first positional arg\n "Units destroyed: {players[0]}" # First element of keyword argument \'players\'.\n\nThe *conversion* field causes a type coercion before formatting.\nNormally, the job of formatting a value is done by the\n``__format__()`` method of the value itself. However, in some cases\nit is desirable to force a type to be formatted as a string,\noverriding its own definition of formatting. By converting the value\nto a string before calling ``__format__()``, the normal formatting\nlogic is bypassed.\n\nThree conversion flags are currently supported: ``\'!s\'`` which calls\n``str()`` on the value, ``\'!r\'`` which calls ``repr()`` and ``\'!a\'``\nwhich calls ``ascii()``.\n\nSome examples:\n\n "Harold\'s a clever {0!s}" # Calls str() on the argument first\n "Bring out the holy {name!r}" # Calls repr() on the argument first\n "More {!a}" # Calls ascii() on the argument first\n\nThe *format_spec* field contains a specification of how the value\nshould be presented, including such details as field width, alignment,\npadding, decimal precision and so on. Each value type can define its\nown "formatting mini-language" or interpretation of the *format_spec*.\n\nMost built-in types support a common formatting mini-language, which\nis described in the next section.\n\nA *format_spec* field can also include nested replacement fields\nwithin it. These nested replacement fields can contain only a field\nname; conversion flags and format specifications are not allowed. The\nreplacement fields within the format_spec are substituted before the\n*format_spec* string is interpreted. This allows the formatting of a\nvalue to be dynamically specified.\n\nSee the *Format examples* section for some examples.\n\n\nFormat Specification Mini-Language\n==================================\n\n"Format specifications" are used within replacement fields contained\nwithin a format string to define how individual values are presented\n(see *Format String Syntax*). They can also be passed directly to the\nbuilt-in ``format()`` function. Each formattable type may define how\nthe format specification is to be interpreted.\n\nMost built-in types implement the following options for format\nspecifications, although some of the formatting options are only\nsupported by the numeric types.\n\nA general convention is that an empty format string (``""``) produces\nthe same result as if you had called ``str()`` on the value. A non-\nempty format string typically modifies the result.\n\nThe general form of a *standard format specifier* is:\n\n format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]\n fill ::= \n align ::= "<" | ">" | "=" | "^"\n sign ::= "+" | "-" | " "\n width ::= integer\n precision ::= integer\n type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n\nThe *fill* character can be any character other than \'{\' or \'}\'. The\npresence of a fill character is signaled by the character following\nit, which must be one of the alignment options. If the second\ncharacter of *format_spec* is not a valid alignment option, then it is\nassumed that both the fill character and the alignment option are\nabsent.\n\nThe meaning of the various alignment options is as follows:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'<\'`` | Forces the field to be left-aligned within the available |\n | | space (this is the default for most objects). |\n +-----------+------------------------------------------------------------+\n | ``\'>\'`` | Forces the field to be right-aligned within the available |\n | | space (this is the default for numbers). |\n +-----------+------------------------------------------------------------+\n | ``\'=\'`` | Forces the padding to be placed after the sign (if any) |\n | | but before the digits. This is used for printing fields |\n | | in the form \'+000000120\'. This alignment option is only |\n | | valid for numeric types. |\n +-----------+------------------------------------------------------------+\n | ``\'^\'`` | Forces the field to be centered within the available |\n | | space. |\n +-----------+------------------------------------------------------------+\n\nNote that unless a minimum field width is defined, the field width\nwill always be the same size as the data to fill it, so that the\nalignment option has no meaning in this case.\n\nThe *sign* option is only valid for number types, and can be one of\nthe following:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'+\'`` | indicates that a sign should be used for both positive as |\n | | well as negative numbers. |\n +-----------+------------------------------------------------------------+\n | ``\'-\'`` | indicates that a sign should be used only for negative |\n | | numbers (this is the default behavior). |\n +-----------+------------------------------------------------------------+\n | space | indicates that a leading space should be used on positive |\n | | numbers, and a minus sign on negative numbers. |\n +-----------+------------------------------------------------------------+\n\nThe ``\'#\'`` option causes the "alternate form" to be used for the\nconversion. The alternate form is defined differently for different\ntypes. This option is only valid for integer, float, complex and\nDecimal types. For integers, when binary, octal, or hexadecimal output\nis used, this option adds the prefix respective ``\'0b\'``, ``\'0o\'``, or\n``\'0x\'`` to the output value. For floats, complex and Decimal the\nalternate form causes the result of the conversion to always contain a\ndecimal-point character, even if no digits follow it. Normally, a\ndecimal-point character appears in the result of these conversions\nonly if a digit follows it. In addition, for ``\'g\'`` and ``\'G\'``\nconversions, trailing zeros are not removed from the result.\n\nThe ``\',\'`` option signals the use of a comma for a thousands\nseparator. For a locale aware separator, use the ``\'n\'`` integer\npresentation type instead.\n\nChanged in version 3.1: Added the ``\',\'`` option (see also **PEP\n378**).\n\n*width* is a decimal integer defining the minimum field width. If not\nspecified, then the field width will be determined by the content.\n\nIf the *width* field is preceded by a zero (``\'0\'``) character, this\nenables zero-padding. This is equivalent to an *alignment* type of\n``\'=\'`` and a *fill* character of ``\'0\'``.\n\nThe *precision* is a decimal number indicating how many digits should\nbe displayed after the decimal point for a floating point value\nformatted with ``\'f\'`` and ``\'F\'``, or before and after the decimal\npoint for a floating point value formatted with ``\'g\'`` or ``\'G\'``.\nFor non-number types the field indicates the maximum field size - in\nother words, how many characters will be used from the field content.\nThe *precision* is not allowed for integer values.\n\nFinally, the *type* determines how the data should be presented.\n\nThe available string presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'s\'`` | String format. This is the default type for strings and |\n | | may be omitted. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'s\'``. |\n +-----------+------------------------------------------------------------+\n\nThe available integer presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'b\'`` | Binary format. Outputs the number in base 2. |\n +-----------+------------------------------------------------------------+\n | ``\'c\'`` | Character. Converts the integer to the corresponding |\n | | unicode character before printing. |\n +-----------+------------------------------------------------------------+\n | ``\'d\'`` | Decimal Integer. Outputs the number in base 10. |\n +-----------+------------------------------------------------------------+\n | ``\'o\'`` | Octal format. Outputs the number in base 8. |\n +-----------+------------------------------------------------------------+\n | ``\'x\'`` | Hex format. Outputs the number in base 16, using lower- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'X\'`` | Hex format. Outputs the number in base 16, using upper- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'d\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'d\'``. |\n +-----------+------------------------------------------------------------+\n\nIn addition to the above presentation types, integers can be formatted\nwith the floating point presentation types listed below (except\n``\'n\'`` and None). When doing so, ``float()`` is used to convert the\ninteger to a floating point number before formatting.\n\nThe available presentation types for floating point and decimal values\nare:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'e\'`` | Exponent notation. Prints the number in scientific |\n | | notation using the letter \'e\' to indicate the exponent. |\n +-----------+------------------------------------------------------------+\n | ``\'E\'`` | Exponent notation. Same as ``\'e\'`` except it uses an upper |\n | | case \'E\' as the separator character. |\n +-----------+------------------------------------------------------------+\n | ``\'f\'`` | Fixed point. Displays the number as a fixed-point number. |\n +-----------+------------------------------------------------------------+\n | ``\'F\'`` | Fixed point. Same as ``\'f\'``, but converts ``nan`` to |\n | | ``NAN`` and ``inf`` to ``INF``. |\n +-----------+------------------------------------------------------------+\n | ``\'g\'`` | General format. For a given precision ``p >= 1``, this |\n | | rounds the number to ``p`` significant digits and then |\n | | formats the result in either fixed-point format or in |\n | | scientific notation, depending on its magnitude. The |\n | | precise rules are as follows: suppose that the result |\n | | formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1`` would have exponent ``exp``. Then if ``-4 <= exp |\n | | < p``, the number is formatted with presentation type |\n | | ``\'f\'`` and precision ``p-1-exp``. Otherwise, the number |\n | | is formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1``. In both cases insignificant trailing zeros are |\n | | removed from the significand, and the decimal point is |\n | | also removed if there are no remaining digits following |\n | | it. Positive and negative infinity, positive and negative |\n | | zero, and nans, are formatted as ``inf``, ``-inf``, ``0``, |\n | | ``-0`` and ``nan`` respectively, regardless of the |\n | | precision. A precision of ``0`` is treated as equivalent |\n | | to a precision of ``1``. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets too large. The representations of |\n | | infinity and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'g\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | ``\'%\'`` | Percentage. Multiplies the number by 100 and displays in |\n | | fixed (``\'f\'``) format, followed by a percent sign. |\n +-----------+------------------------------------------------------------+\n | None | Similar to ``\'g\'``, except with at least one digit past |\n | | the decimal point and a default precision of 12. This is |\n | | intended to match ``str()``, except you can add the other |\n | | format modifiers. |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the new format syntax and comparison\nwith the old ``%``-formatting.\n\nIn most of the cases the syntax is similar to the old\n``%``-formatting, with the addition of the ``{}`` and with ``:`` used\ninstead of ``%``. For example, ``\'%03.2f\'`` can be translated to\n``\'{:03.2f}\'``.\n\nThe new format syntax also supports new and different options, shown\nin the follow examples.\n\nAccessing arguments by position:\n\n >>> \'{0}, {1}, {2}\'.format(\'a\', \'b\', \'c\')\n \'a, b, c\'\n >>> \'{}, {}, {}\'.format(\'a\', \'b\', \'c\') # 3.1+ only\n \'a, b, c\'\n >>> \'{2}, {1}, {0}\'.format(\'a\', \'b\', \'c\')\n \'c, b, a\'\n >>> \'{2}, {1}, {0}\'.format(*\'abc\') # unpacking argument sequence\n \'c, b, a\'\n >>> \'{0}{1}{0}\'.format(\'abra\', \'cad\') # arguments\' indices can be repeated\n \'abracadabra\'\n\nAccessing arguments by name:\n\n >>> \'Coordinates: {latitude}, {longitude}\'.format(latitude=\'37.24N\', longitude=\'-115.81W\')\n \'Coordinates: 37.24N, -115.81W\'\n >>> coord = {\'latitude\': \'37.24N\', \'longitude\': \'-115.81W\'}\n >>> \'Coordinates: {latitude}, {longitude}\'.format(**coord)\n \'Coordinates: 37.24N, -115.81W\'\n\nAccessing arguments\' attributes:\n\n >>> c = 3-5j\n >>> (\'The complex number {0} is formed from the real part {0.real} \'\n ... \'and the imaginary part {0.imag}.\').format(c)\n \'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.\'\n >>> class Point:\n ... def __init__(self, x, y):\n ... self.x, self.y = x, y\n ... def __str__(self):\n ... return \'Point({self.x}, {self.y})\'.format(self=self)\n ...\n >>> str(Point(4, 2))\n \'Point(4, 2)\'\n\nAccessing arguments\' items:\n\n >>> coord = (3, 5)\n >>> \'X: {0[0]}; Y: {0[1]}\'.format(coord)\n \'X: 3; Y: 5\'\n\nReplacing ``%s`` and ``%r``:\n\n >>> "repr() shows quotes: {!r}; str() doesn\'t: {!s}".format(\'test1\', \'test2\')\n "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n\nAligning the text and specifying a width:\n\n >>> \'{:<30}\'.format(\'left aligned\')\n \'left aligned \'\n >>> \'{:>30}\'.format(\'right aligned\')\n \' right aligned\'\n >>> \'{:^30}\'.format(\'centered\')\n \' centered \'\n >>> \'{:*^30}\'.format(\'centered\') # use \'*\' as a fill char\n \'***********centered***********\'\n\nReplacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign:\n\n >>> \'{:+f}; {:+f}\'.format(3.14, -3.14) # show it always\n \'+3.140000; -3.140000\'\n >>> \'{: f}; {: f}\'.format(3.14, -3.14) # show a space for positive numbers\n \' 3.140000; -3.140000\'\n >>> \'{:-f}; {:-f}\'.format(3.14, -3.14) # show only the minus -- same as \'{:f}; {:f}\'\n \'3.140000; -3.140000\'\n\nReplacing ``%x`` and ``%o`` and converting the value to different\nbases:\n\n >>> # format also supports binary numbers\n >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)\n \'int: 42; hex: 2a; oct: 52; bin: 101010\'\n >>> # with 0x, 0o, or 0b as prefix:\n >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)\n \'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010\'\n\nUsing the comma as a thousands separator:\n\n >>> \'{:,}\'.format(1234567890)\n \'1,234,567,890\'\n\nExpressing a percentage:\n\n >>> points = 19\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 86.36%\'\n\nUsing type-specific formatting:\n\n >>> import datetime\n >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n >>> \'{:%Y-%m-%d %H:%M:%S}\'.format(d)\n \'2010-07-04 12:15:58\'\n\nNesting arguments and more complex examples:\n\n >>> for align, text in zip(\'<^>\', [\'left\', \'center\', \'right\']):\n ... \'{0:{fill}{align}16}\'.format(text, fill=align, align=align)\n ...\n \'left<<<<<<<<<<<<\'\n \'^^^^^center^^^^^\'\n \'>>>>>>>>>>>right\'\n >>>\n >>> octets = [192, 168, 0, 1]\n >>> \'{:02X}{:02X}{:02X}{:02X}\'.format(*octets)\n \'C0A80001\'\n >>> int(_, 16)\n 3232235521\n >>>\n >>> width = 5\n >>> for num in range(5,12):\n ... for base in \'dXob\':\n ... print(\'{0:{width}{base}}\'.format(num, base=base, width=width), end=\' \')\n ... print()\n ...\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 8 10 1000\n 9 9 11 1001\n 10 A 12 1010\n 11 B 13 1011\n', + 'formatstrings': '\nFormat String Syntax\n********************\n\nThe ``str.format()`` method and the ``Formatter`` class share the same\nsyntax for format strings (although in the case of ``Formatter``,\nsubclasses can define their own format string syntax).\n\nFormat strings contain "replacement fields" surrounded by curly braces\n``{}``. Anything that is not contained in braces is considered literal\ntext, which is copied unchanged to the output. If you need to include\na brace character in the literal text, it can be escaped by doubling:\n``{{`` and ``}}``.\n\nThe grammar for a replacement field is as follows:\n\n replacement_field ::= "{" [field_name] ["!" conversion] [":" format_spec] "}"\n field_name ::= arg_name ("." attribute_name | "[" element_index "]")*\n arg_name ::= [identifier | integer]\n attribute_name ::= identifier\n element_index ::= integer | index_string\n index_string ::= +\n conversion ::= "r" | "s" | "a"\n format_spec ::= \n\nIn less formal terms, the replacement field can start with a\n*field_name* that specifies the object whose value is to be formatted\nand inserted into the output instead of the replacement field. The\n*field_name* is optionally followed by a *conversion* field, which is\npreceded by an exclamation point ``\'!\'``, and a *format_spec*, which\nis preceded by a colon ``\':\'``. These specify a non-default format\nfor the replacement value.\n\nSee also the *Format Specification Mini-Language* section.\n\nThe *field_name* itself begins with an *arg_name* that is either a\nnumber or a keyword. If it\'s a number, it refers to a positional\nargument, and if it\'s a keyword, it refers to a named keyword\nargument. If the numerical arg_names in a format string are 0, 1, 2,\n... in sequence, they can all be omitted (not just some) and the\nnumbers 0, 1, 2, ... will be automatically inserted in that order.\nBecause *arg_name* is not quote-delimited, it is not possible to\nspecify arbitrary dictionary keys (e.g., the strings ``\'10\'`` or\n``\':-]\'``) within a format string. The *arg_name* can be followed by\nany number of index or attribute expressions. An expression of the\nform ``\'.name\'`` selects the named attribute using ``getattr()``,\nwhile an expression of the form ``\'[index]\'`` does an index lookup\nusing ``__getitem__()``.\n\nChanged in version 3.1: The positional argument specifiers can be\nomitted, so ``\'{} {}\'`` is equivalent to ``\'{0} {1}\'``.\n\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\n "Bring me a {}" # Implicitly references the first positional argument\n "From {} to {}" # Same as "From {0} to {1}"\n "My quest is {name}" # References keyword argument \'name\'\n "Weight in tons {0.weight}" # \'weight\' attribute of first positional arg\n "Units destroyed: {players[0]}" # First element of keyword argument \'players\'.\n\nThe *conversion* field causes a type coercion before formatting.\nNormally, the job of formatting a value is done by the\n``__format__()`` method of the value itself. However, in some cases\nit is desirable to force a type to be formatted as a string,\noverriding its own definition of formatting. By converting the value\nto a string before calling ``__format__()``, the normal formatting\nlogic is bypassed.\n\nThree conversion flags are currently supported: ``\'!s\'`` which calls\n``str()`` on the value, ``\'!r\'`` which calls ``repr()`` and ``\'!a\'``\nwhich calls ``ascii()``.\n\nSome examples:\n\n "Harold\'s a clever {0!s}" # Calls str() on the argument first\n "Bring out the holy {name!r}" # Calls repr() on the argument first\n "More {!a}" # Calls ascii() on the argument first\n\nThe *format_spec* field contains a specification of how the value\nshould be presented, including such details as field width, alignment,\npadding, decimal precision and so on. Each value type can define its\nown "formatting mini-language" or interpretation of the *format_spec*.\n\nMost built-in types support a common formatting mini-language, which\nis described in the next section.\n\nA *format_spec* field can also include nested replacement fields\nwithin it. These nested replacement fields can contain only a field\nname; conversion flags and format specifications are not allowed. The\nreplacement fields within the format_spec are substituted before the\n*format_spec* string is interpreted. This allows the formatting of a\nvalue to be dynamically specified.\n\nSee the *Format examples* section for some examples.\n\n\nFormat Specification Mini-Language\n==================================\n\n"Format specifications" are used within replacement fields contained\nwithin a format string to define how individual values are presented\n(see *Format String Syntax*). They can also be passed directly to the\nbuilt-in ``format()`` function. Each formattable type may define how\nthe format specification is to be interpreted.\n\nMost built-in types implement the following options for format\nspecifications, although some of the formatting options are only\nsupported by the numeric types.\n\nA general convention is that an empty format string (``""``) produces\nthe same result as if you had called ``str()`` on the value. A non-\nempty format string typically modifies the result.\n\nThe general form of a *standard format specifier* is:\n\n format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]\n fill ::= \n align ::= "<" | ">" | "=" | "^"\n sign ::= "+" | "-" | " "\n width ::= integer\n precision ::= integer\n type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n\nThe *fill* character can be any character other than \'{\' or \'}\'. The\npresence of a fill character is signaled by the character following\nit, which must be one of the alignment options. If the second\ncharacter of *format_spec* is not a valid alignment option, then it is\nassumed that both the fill character and the alignment option are\nabsent.\n\nThe meaning of the various alignment options is as follows:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'<\'`` | Forces the field to be left-aligned within the available |\n | | space (this is the default for most objects). |\n +-----------+------------------------------------------------------------+\n | ``\'>\'`` | Forces the field to be right-aligned within the available |\n | | space (this is the default for numbers). |\n +-----------+------------------------------------------------------------+\n | ``\'=\'`` | Forces the padding to be placed after the sign (if any) |\n | | but before the digits. This is used for printing fields |\n | | in the form \'+000000120\'. This alignment option is only |\n | | valid for numeric types. |\n +-----------+------------------------------------------------------------+\n | ``\'^\'`` | Forces the field to be centered within the available |\n | | space. |\n +-----------+------------------------------------------------------------+\n\nNote that unless a minimum field width is defined, the field width\nwill always be the same size as the data to fill it, so that the\nalignment option has no meaning in this case.\n\nThe *sign* option is only valid for number types, and can be one of\nthe following:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | ``\'+\'`` | indicates that a sign should be used for both positive as |\n | | well as negative numbers. |\n +-----------+------------------------------------------------------------+\n | ``\'-\'`` | indicates that a sign should be used only for negative |\n | | numbers (this is the default behavior). |\n +-----------+------------------------------------------------------------+\n | space | indicates that a leading space should be used on positive |\n | | numbers, and a minus sign on negative numbers. |\n +-----------+------------------------------------------------------------+\n\nThe ``\'#\'`` option causes the "alternate form" to be used for the\nconversion. The alternate form is defined differently for different\ntypes. This option is only valid for integer, float, complex and\nDecimal types. For integers, when binary, octal, or hexadecimal output\nis used, this option adds the prefix respective ``\'0b\'``, ``\'0o\'``, or\n``\'0x\'`` to the output value. For floats, complex and Decimal the\nalternate form causes the result of the conversion to always contain a\ndecimal-point character, even if no digits follow it. Normally, a\ndecimal-point character appears in the result of these conversions\nonly if a digit follows it. In addition, for ``\'g\'`` and ``\'G\'``\nconversions, trailing zeros are not removed from the result.\n\nThe ``\',\'`` option signals the use of a comma for a thousands\nseparator. For a locale aware separator, use the ``\'n\'`` integer\npresentation type instead.\n\nChanged in version 3.1: Added the ``\',\'`` option (see also **PEP\n378**).\n\n*width* is a decimal integer defining the minimum field width. If not\nspecified, then the field width will be determined by the content.\n\nPreceding the *width* field by a zero (``\'0\'``) character enables\nsign-aware zero-padding for numeric types. This is equivalent to a\n*fill* character of ``\'0\'`` with an *alignment* type of ``\'=\'``.\n\nThe *precision* is a decimal number indicating how many digits should\nbe displayed after the decimal point for a floating point value\nformatted with ``\'f\'`` and ``\'F\'``, or before and after the decimal\npoint for a floating point value formatted with ``\'g\'`` or ``\'G\'``.\nFor non-number types the field indicates the maximum field size - in\nother words, how many characters will be used from the field content.\nThe *precision* is not allowed for integer values.\n\nFinally, the *type* determines how the data should be presented.\n\nThe available string presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'s\'`` | String format. This is the default type for strings and |\n | | may be omitted. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'s\'``. |\n +-----------+------------------------------------------------------------+\n\nThe available integer presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'b\'`` | Binary format. Outputs the number in base 2. |\n +-----------+------------------------------------------------------------+\n | ``\'c\'`` | Character. Converts the integer to the corresponding |\n | | unicode character before printing. |\n +-----------+------------------------------------------------------------+\n | ``\'d\'`` | Decimal Integer. Outputs the number in base 10. |\n +-----------+------------------------------------------------------------+\n | ``\'o\'`` | Octal format. Outputs the number in base 8. |\n +-----------+------------------------------------------------------------+\n | ``\'x\'`` | Hex format. Outputs the number in base 16, using lower- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'X\'`` | Hex format. Outputs the number in base 16, using upper- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'d\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | None | The same as ``\'d\'``. |\n +-----------+------------------------------------------------------------+\n\nIn addition to the above presentation types, integers can be formatted\nwith the floating point presentation types listed below (except\n``\'n\'`` and None). When doing so, ``float()`` is used to convert the\ninteger to a floating point number before formatting.\n\nThe available presentation types for floating point and decimal values\nare:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | ``\'e\'`` | Exponent notation. Prints the number in scientific |\n | | notation using the letter \'e\' to indicate the exponent. |\n +-----------+------------------------------------------------------------+\n | ``\'E\'`` | Exponent notation. Same as ``\'e\'`` except it uses an upper |\n | | case \'E\' as the separator character. |\n +-----------+------------------------------------------------------------+\n | ``\'f\'`` | Fixed point. Displays the number as a fixed-point number. |\n +-----------+------------------------------------------------------------+\n | ``\'F\'`` | Fixed point. Same as ``\'f\'``, but converts ``nan`` to |\n | | ``NAN`` and ``inf`` to ``INF``. |\n +-----------+------------------------------------------------------------+\n | ``\'g\'`` | General format. For a given precision ``p >= 1``, this |\n | | rounds the number to ``p`` significant digits and then |\n | | formats the result in either fixed-point format or in |\n | | scientific notation, depending on its magnitude. The |\n | | precise rules are as follows: suppose that the result |\n | | formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1`` would have exponent ``exp``. Then if ``-4 <= exp |\n | | < p``, the number is formatted with presentation type |\n | | ``\'f\'`` and precision ``p-1-exp``. Otherwise, the number |\n | | is formatted with presentation type ``\'e\'`` and precision |\n | | ``p-1``. In both cases insignificant trailing zeros are |\n | | removed from the significand, and the decimal point is |\n | | also removed if there are no remaining digits following |\n | | it. Positive and negative infinity, positive and negative |\n | | zero, and nans, are formatted as ``inf``, ``-inf``, ``0``, |\n | | ``-0`` and ``nan`` respectively, regardless of the |\n | | precision. A precision of ``0`` is treated as equivalent |\n | | to a precision of ``1``. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets too large. The representations of |\n | | infinity and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | ``\'n\'`` | Number. This is the same as ``\'g\'``, except that it uses |\n | | the current locale setting to insert the appropriate |\n | | number separator characters. |\n +-----------+------------------------------------------------------------+\n | ``\'%\'`` | Percentage. Multiplies the number by 100 and displays in |\n | | fixed (``\'f\'``) format, followed by a percent sign. |\n +-----------+------------------------------------------------------------+\n | None | Similar to ``\'g\'``, except with at least one digit past |\n | | the decimal point and a default precision of 12. This is |\n | | intended to match ``str()``, except you can add the other |\n | | format modifiers. |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the new format syntax and comparison\nwith the old ``%``-formatting.\n\nIn most of the cases the syntax is similar to the old\n``%``-formatting, with the addition of the ``{}`` and with ``:`` used\ninstead of ``%``. For example, ``\'%03.2f\'`` can be translated to\n``\'{:03.2f}\'``.\n\nThe new format syntax also supports new and different options, shown\nin the follow examples.\n\nAccessing arguments by position:\n\n >>> \'{0}, {1}, {2}\'.format(\'a\', \'b\', \'c\')\n \'a, b, c\'\n >>> \'{}, {}, {}\'.format(\'a\', \'b\', \'c\') # 3.1+ only\n \'a, b, c\'\n >>> \'{2}, {1}, {0}\'.format(\'a\', \'b\', \'c\')\n \'c, b, a\'\n >>> \'{2}, {1}, {0}\'.format(*\'abc\') # unpacking argument sequence\n \'c, b, a\'\n >>> \'{0}{1}{0}\'.format(\'abra\', \'cad\') # arguments\' indices can be repeated\n \'abracadabra\'\n\nAccessing arguments by name:\n\n >>> \'Coordinates: {latitude}, {longitude}\'.format(latitude=\'37.24N\', longitude=\'-115.81W\')\n \'Coordinates: 37.24N, -115.81W\'\n >>> coord = {\'latitude\': \'37.24N\', \'longitude\': \'-115.81W\'}\n >>> \'Coordinates: {latitude}, {longitude}\'.format(**coord)\n \'Coordinates: 37.24N, -115.81W\'\n\nAccessing arguments\' attributes:\n\n >>> c = 3-5j\n >>> (\'The complex number {0} is formed from the real part {0.real} \'\n ... \'and the imaginary part {0.imag}.\').format(c)\n \'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.\'\n >>> class Point:\n ... def __init__(self, x, y):\n ... self.x, self.y = x, y\n ... def __str__(self):\n ... return \'Point({self.x}, {self.y})\'.format(self=self)\n ...\n >>> str(Point(4, 2))\n \'Point(4, 2)\'\n\nAccessing arguments\' items:\n\n >>> coord = (3, 5)\n >>> \'X: {0[0]}; Y: {0[1]}\'.format(coord)\n \'X: 3; Y: 5\'\n\nReplacing ``%s`` and ``%r``:\n\n >>> "repr() shows quotes: {!r}; str() doesn\'t: {!s}".format(\'test1\', \'test2\')\n "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n\nAligning the text and specifying a width:\n\n >>> \'{:<30}\'.format(\'left aligned\')\n \'left aligned \'\n >>> \'{:>30}\'.format(\'right aligned\')\n \' right aligned\'\n >>> \'{:^30}\'.format(\'centered\')\n \' centered \'\n >>> \'{:*^30}\'.format(\'centered\') # use \'*\' as a fill char\n \'***********centered***********\'\n\nReplacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign:\n\n >>> \'{:+f}; {:+f}\'.format(3.14, -3.14) # show it always\n \'+3.140000; -3.140000\'\n >>> \'{: f}; {: f}\'.format(3.14, -3.14) # show a space for positive numbers\n \' 3.140000; -3.140000\'\n >>> \'{:-f}; {:-f}\'.format(3.14, -3.14) # show only the minus -- same as \'{:f}; {:f}\'\n \'3.140000; -3.140000\'\n\nReplacing ``%x`` and ``%o`` and converting the value to different\nbases:\n\n >>> # format also supports binary numbers\n >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)\n \'int: 42; hex: 2a; oct: 52; bin: 101010\'\n >>> # with 0x, 0o, or 0b as prefix:\n >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)\n \'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010\'\n\nUsing the comma as a thousands separator:\n\n >>> \'{:,}\'.format(1234567890)\n \'1,234,567,890\'\n\nExpressing a percentage:\n\n >>> points = 19\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 86.36%\'\n\nUsing type-specific formatting:\n\n >>> import datetime\n >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n >>> \'{:%Y-%m-%d %H:%M:%S}\'.format(d)\n \'2010-07-04 12:15:58\'\n\nNesting arguments and more complex examples:\n\n >>> for align, text in zip(\'<^>\', [\'left\', \'center\', \'right\']):\n ... \'{0:{fill}{align}16}\'.format(text, fill=align, align=align)\n ...\n \'left<<<<<<<<<<<<\'\n \'^^^^^center^^^^^\'\n \'>>>>>>>>>>>right\'\n >>>\n >>> octets = [192, 168, 0, 1]\n >>> \'{:02X}{:02X}{:02X}{:02X}\'.format(*octets)\n \'C0A80001\'\n >>> int(_, 16)\n 3232235521\n >>>\n >>> width = 5\n >>> for num in range(5,12):\n ... for base in \'dXob\':\n ... print(\'{0:{width}{base}}\'.format(num, base=base, width=width), end=\' \')\n ... print()\n ...\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 8 10 1000\n 9 9 11 1001\n 10 A 12 1010\n 11 B 13 1011\n', 'function': '\nFunction definitions\n********************\n\nA function definition defines a user-defined function object (see\nsection *The standard type hierarchy*):\n\n funcdef ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" [parameter] ("," defparameter)*\n [, "**" parameter]\n | "**" parameter\n | defparameter [","] )\n parameter ::= identifier [":" expression]\n defparameter ::= parameter ["=" expression]\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more parameters have the form *parameter* ``=``\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding argument may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters up until the "``*``" must also have a default value ---\nthis is a syntactic restriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use ``None`` as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section\n*Calls*. A function call always assigns values to all parameters\nmentioned in the parameter list, either from position arguments, from\nkeyword arguments, or from default values. If the form\n"``*identifier``" is present, it is initialized to a tuple receiving\nany excess positional parameters, defaulting to the empty tuple. If\nthe form "``**identifier``" is present, it is initialized to a new\ndictionary receiving any excess keyword arguments, defaulting to a new\nempty dictionary. Parameters after "``*``" or "``*identifier``" are\nkeyword-only parameters and may only be passed used keyword arguments.\n\nParameters may have annotations of the form "``: expression``"\nfollowing the parameter name. Any parameter may have an annotation\neven those of the form ``*identifier`` or ``**identifier``. Functions\nmay have "return" annotation of the form "``-> expression``" after the\nparameter list. These annotations can be any valid Python expression\nand are evaluated when the function definition is executed.\nAnnotations may be evaluated in a different order than they appear in\nthe source code. The presence of annotations does not change the\nsemantics of a function. The annotation values are available as\nvalues of a dictionary keyed by the parameters\' names in the\n``__annotations__`` attribute of the function object.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda forms,\ndescribed in section *Lambdas*. Note that the lambda form is merely a\nshorthand for a simplified function definition; a function defined in\na "``def``" statement can be passed around or assigned to another name\njust like a function defined by a lambda form. The "``def``" form is\nactually more powerful since it allows the execution of multiple\nstatements and annotations.\n\n**Programmer\'s note:** Functions are first-class objects. A "``def``"\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section *Naming and binding* for details.\n\nSee also:\n\n **PEP 3107** - Function Annotations\n The original specification for function annotations.\n', 'global': '\nThe ``global`` statement\n************************\n\n global_stmt ::= "global" identifier ("," identifier)*\n\nThe ``global`` statement is a declaration which holds for the entire\ncurrent code block. It means that the listed identifiers are to be\ninterpreted as globals. It would be impossible to assign to a global\nvariable without ``global``, although free variables may refer to\nglobals without being declared global.\n\nNames listed in a ``global`` statement must not be used in the same\ncode block textually preceding that ``global`` statement.\n\nNames listed in a ``global`` statement must not be defined as formal\nparameters or in a ``for`` loop control target, ``class`` definition,\nfunction definition, or ``import`` statement.\n\n**CPython implementation detail:** The current implementation does not\nenforce the latter two restrictions, but programs should not abuse\nthis freedom, as future implementations may enforce them or silently\nchange the meaning of the program.\n\n**Programmer\'s note:** the ``global`` is a directive to the parser.\nIt applies only to code parsed at the same time as the ``global``\nstatement. In particular, a ``global`` statement contained in a string\nor code object supplied to the built-in ``exec()`` function does not\naffect the code block *containing* the function call, and code\ncontained in such a string is unaffected by ``global`` statements in\nthe code containing the function call. The same applies to the\n``eval()`` and ``compile()`` functions.\n', 'id-classes': '\nReserved classes of identifiers\n*******************************\n\nCertain classes of identifiers (besides keywords) have special\nmeanings. These classes are identified by the patterns of leading and\ntrailing underscore characters:\n\n``_*``\n Not imported by ``from module import *``. The special identifier\n ``_`` is used in the interactive interpreter to store the result of\n the last evaluation; it is stored in the ``builtins`` module. When\n not in interactive mode, ``_`` has no special meaning and is not\n defined. See section *The import statement*.\n\n Note: The name ``_`` is often used in conjunction with\n internationalization; refer to the documentation for the\n ``gettext`` module for more information on this convention.\n\n``__*__``\n System-defined names. These names are defined by the interpreter\n and its implementation (including the standard library). Current\n system names are discussed in the *Special method names* section\n and elsewhere. More will likely be defined in future versions of\n Python. *Any* use of ``__*__`` names, in any context, that does\n not follow explicitly documented use, is subject to breakage\n without warning.\n\n``__*``\n Class-private names. Names in this category, when used within the\n context of a class definition, are re-written to use a mangled form\n to help avoid name clashes between "private" attributes of base and\n derived classes. See section *Identifiers (Names)*.\n', @@ -61,18 +61,18 @@ 'slicings': '\nSlicings\n********\n\nA slicing selects a range of items in a sequence object (e.g., a\nstring, tuple or list). Slicings may be used as expressions or as\ntargets in assignment or ``del`` statements. The syntax for a\nslicing:\n\n slicing ::= primary "[" slice_list "]"\n slice_list ::= slice_item ("," slice_item)* [","]\n slice_item ::= expression | proper_slice\n proper_slice ::= [lower_bound] ":" [upper_bound] [ ":" [stride] ]\n lower_bound ::= expression\n upper_bound ::= expression\n stride ::= expression\n\nThere is ambiguity in the formal syntax here: anything that looks like\nan expression list also looks like a slice list, so any subscription\ncan be interpreted as a slicing. Rather than further complicating the\nsyntax, this is disambiguated by defining that in this case the\ninterpretation as a subscription takes priority over the\ninterpretation as a slicing (this is the case if the slice list\ncontains no proper slice).\n\nThe semantics for a slicing are as follows. The primary must evaluate\nto a mapping object, and it is indexed (using the same\n``__getitem__()`` method as normal subscription) with a key that is\nconstructed from the slice list, as follows. If the slice list\ncontains at least one comma, the key is a tuple containing the\nconversion of the slice items; otherwise, the conversion of the lone\nslice item is the key. The conversion of a slice item that is an\nexpression is that expression. The conversion of a proper slice is a\nslice object (see section *The standard type hierarchy*) whose\n``start``, ``stop`` and ``step`` attributes are the values of the\nexpressions given as lower bound, upper bound and stride,\nrespectively, substituting ``None`` for missing expressions.\n', 'specialattrs': '\nSpecial Attributes\n******************\n\nThe implementation adds a few special read-only attributes to several\nobject types, where they are relevant. Some of these are not reported\nby the ``dir()`` built-in function.\n\nobject.__dict__\n\n A dictionary or other mapping object used to store an object\'s\n (writable) attributes.\n\ninstance.__class__\n\n The class to which a class instance belongs.\n\nclass.__bases__\n\n The tuple of base classes of a class object.\n\nclass.__name__\n\n The name of the class or type.\n\nclass.__qualname__\n\n The *qualified name* of the class or type.\n\n New in version 3.3.\n\nclass.__mro__\n\n This attribute is a tuple of classes that are considered when\n looking for base classes during method resolution.\n\nclass.mro()\n\n This method can be overridden by a metaclass to customize the\n method resolution order for its instances. It is called at class\n instantiation, and its result is stored in ``__mro__``.\n\nclass.__subclasses__()\n\n Each class keeps a list of weak references to its immediate\n subclasses. This method returns a list of all those references\n still alive. Example:\n\n >>> int.__subclasses__()\n []\n\n-[ Footnotes ]-\n\n[1] Additional information on these special methods may be found in\n the Python Reference Manual (*Basic customization*).\n\n[2] As a consequence, the list ``[1, 2]`` is considered equal to\n ``[1.0, 2.0]``, and similarly for tuples.\n\n[3] They must have since the parser can\'t tell the type of the\n operands.\n\n[4] Cased characters are those with general category property being\n one of "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt"\n (Letter, titlecase).\n\n[5] To format only a tuple you should therefore provide a singleton\n tuple whose only element is the tuple to be formatted.\n', 'specialnames': '\nSpecial method names\n********************\n\nA class can implement certain operations that are invoked by special\nsyntax (such as arithmetic operations or subscripting and slicing) by\ndefining methods with special names. This is Python\'s approach to\n*operator overloading*, allowing classes to define their own behavior\nwith respect to language operators. For instance, if a class defines\na method named ``__getitem__()``, and ``x`` is an instance of this\nclass, then ``x[i]`` is roughly equivalent to ``type(x).__getitem__(x,\ni)``. Except where mentioned, attempts to execute an operation raise\nan exception when no appropriate method is defined (typically\n``AttributeError`` or ``TypeError``).\n\nWhen implementing a class that emulates any built-in type, it is\nimportant that the emulation only be implemented to the degree that it\nmakes sense for the object being modelled. For example, some\nsequences may work well with retrieval of individual elements, but\nextracting a slice may not make sense. (One example of this is the\n``NodeList`` interface in the W3C\'s Document Object Model.)\n\n\nBasic customization\n===================\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. ``__new__()`` is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of ``__new__()`` should be the new object instance (usually\n an instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s ``__new__()`` method using\n ``super(currentclass, cls).__new__(cls[, ...])`` with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If ``__new__()`` returns an instance of *cls*, then the new\n instance\'s ``__init__()`` method will be invoked like\n ``__init__(self[, ...])``, where *self* is the new instance and the\n remaining arguments are the same as were passed to ``__new__()``.\n\n If ``__new__()`` does not return an instance of *cls*, then the new\n instance\'s ``__init__()`` method will not be invoked.\n\n ``__new__()`` is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called when the instance is created. The arguments are those\n passed to the class constructor expression. If a base class has an\n ``__init__()`` method, the derived class\'s ``__init__()`` method,\n if any, must explicitly call it to ensure proper initialization of\n the base class part of the instance; for example:\n ``BaseClass.__init__(self, [args...])``. As a special constraint\n on constructors, no value may be returned; doing so will cause a\n ``TypeError`` to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a ``__del__()`` method,\n the derived class\'s ``__del__()`` method, if any, must explicitly\n call it to ensure proper deletion of the base class part of the\n instance. Note that it is possible (though not recommended!) for\n the ``__del__()`` method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n ``__del__()`` methods are called for objects that still exist when\n the interpreter exits.\n\n Note: ``del x`` doesn\'t directly call ``x.__del__()`` --- the former\n decrements the reference count for ``x`` by one, and the latter\n is only called when ``x``\'s reference count reaches zero. Some\n common situations that may prevent the reference count of an\n object from going to zero include: circular references between\n objects (e.g., a doubly-linked list or a tree data structure with\n parent and child pointers); a reference to the object on the\n stack frame of a function that caught an exception (the traceback\n stored in ``sys.exc_info()[2]`` keeps the stack frame alive); or\n a reference to the object on the stack frame that raised an\n unhandled exception in interactive mode (the traceback stored in\n ``sys.last_traceback`` keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing ``None`` in\n ``sys.last_traceback``. Circular references which are garbage are\n detected when the option cycle detector is enabled (it\'s on by\n default), but can only be cleaned up if there are no Python-\n level ``__del__()`` methods involved. Refer to the documentation\n for the ``gc`` module for more information about how\n ``__del__()`` methods are handled by the cycle detector,\n particularly the description of the ``garbage`` value.\n\n Warning: Due to the precarious circumstances under which ``__del__()``\n methods are invoked, exceptions that occur during their execution\n are ignored, and a warning is printed to ``sys.stderr`` instead.\n Also, when ``__del__()`` is invoked in response to a module being\n deleted (e.g., when execution of the program is done), other\n globals referenced by the ``__del__()`` method may already have\n been deleted or in the process of being torn down (e.g. the\n import machinery shutting down). For this reason, ``__del__()``\n methods should do the absolute minimum needed to maintain\n external invariants. Starting with version 1.5, Python\n guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the ``__del__()`` method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function to compute the\n "official" string representation of an object. If at all possible,\n this should look like a valid Python expression that could be used\n to recreate an object with the same value (given an appropriate\n environment). If this is not possible, a string of the form\n ``<...some useful description...>`` should be returned. The return\n value must be a string object. If a class defines ``__repr__()``\n but not ``__str__()``, then ``__repr__()`` is also used when an\n "informal" string representation of instances of that class is\n required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the ``str()`` built-in function and by the ``print()``\n function to compute the "informal" string representation of an\n object. This differs from ``__repr__()`` in that it does not have\n to be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__bytes__(self)\n\n Called by ``bytes()`` to compute a byte-string representation of an\n object. This should return a ``bytes`` object.\n\nobject.__format__(self, format_spec)\n\n Called by the ``format()`` built-in function (and by extension, the\n ``format()`` method of class ``str``) to produce a "formatted"\n string representation of an object. The ``format_spec`` argument is\n a string that contains a description of the formatting options\n desired. The interpretation of the ``format_spec`` argument is up\n to the type implementing ``__format__()``, however most classes\n will either delegate formatting to one of the built-in types, or\n use a similar formatting option syntax.\n\n See *Format Specification Mini-Language* for a description of the\n standard formatting syntax.\n\n The return value must be a string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n These are the so-called "rich comparison" methods. The\n correspondence between operator symbols and method names is as\n follows: ``xy`` calls ``x.__gt__(y)``, and ``x>=y`` calls\n ``x.__ge__(y)``.\n\n A rich comparison method may return the singleton\n ``NotImplemented`` if it does not implement the operation for a\n given pair of arguments. By convention, ``False`` and ``True`` are\n returned for a successful comparison. However, these methods can\n return any value, so if the comparison operator is used in a\n Boolean context (e.g., in the condition of an ``if`` statement),\n Python will call ``bool()`` on the value to determine if the result\n is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of ``x==y`` does not imply that ``x!=y`` is false.\n Accordingly, when defining ``__eq__()``, one should also define\n ``__ne__()`` so that the operators will behave as expected. See\n the paragraph on ``__hash__()`` for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, ``__lt__()`` and ``__gt__()`` are each\n other\'s reflection, ``__le__()`` and ``__ge__()`` are each other\'s\n reflection, and ``__eq__()`` and ``__ne__()`` are their own\n reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see ``functools.total_ordering()``.\n\nobject.__hash__(self)\n\n Called by built-in function ``hash()`` and for operations on\n members of hashed collections including ``set``, ``frozenset``, and\n ``dict``. ``__hash__()`` should return an integer. The only\n required property is that objects which compare equal have the same\n hash value; it is advised to somehow mix together (e.g. using\n exclusive or) the hash values for the components of the object that\n also play a part in comparison of objects.\n\n If a class does not define an ``__eq__()`` method it should not\n define a ``__hash__()`` operation either; if it defines\n ``__eq__()`` but not ``__hash__()``, its instances will not be\n usable as items in hashable collections. If a class defines\n mutable objects and implements an ``__eq__()`` method, it should\n not implement ``__hash__()``, since the implementation of hashable\n collections requires that a key\'s hash value is immutable (if the\n object\'s hash value changes, it will be in the wrong hash bucket).\n\n User-defined classes have ``__eq__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal (except with\n themselves) and ``x.__hash__()`` returns an appropriate value such\n that ``x == y`` implies both that ``x is y`` and ``hash(x) ==\n hash(y)``.\n\n Classes which inherit a ``__hash__()`` method from a parent class\n but change the meaning of ``__eq__()`` such that the hash value\n returned is no longer appropriate (e.g. by switching to a value-\n based concept of equality instead of the default identity based\n equality) can explicitly flag themselves as being unhashable by\n setting ``__hash__ = None`` in the class definition. Doing so means\n that not only will instances of the class raise an appropriate\n ``TypeError`` when a program attempts to retrieve their hash value,\n but they will also be correctly identified as unhashable when\n checking ``isinstance(obj, collections.Hashable)`` (unlike classes\n which define their own ``__hash__()`` to explicitly raise\n ``TypeError``).\n\n If a class that overrides ``__eq__()`` needs to retain the\n implementation of ``__hash__()`` from a parent class, the\n interpreter must be told this explicitly by setting ``__hash__ =\n .__hash__``. Otherwise the inheritance of\n ``__hash__()`` will be blocked, just as if ``__hash__`` had been\n explicitly set to ``None``.\n\n Note: By default, the ``__hash__()`` values of str, bytes and datetime\n objects are "salted" with an unpredictable random value.\n Although they remain constant within an individual Python\n process, they are not predictable between repeated invocations of\n Python.This is intended to provide protection against a denial-\n of-service caused by carefully-chosen inputs that exploit the\n worst case performance of a dict insertion, O(n^2) complexity.\n See http://www.ocert.org/advisories/ocert-2011-003.html for\n details.Changing hash values affects the iteration order of\n dicts, sets and other mappings. Python has never made guarantees\n about this ordering (and it typically varies between 32-bit and\n 64-bit builds).See also ``PYTHONHASHSEED``.\n\n Changed in version 3.3: Hash randomization is enabled by default.\n\nobject.__bool__(self)\n\n Called to implement truth value testing and the built-in operation\n ``bool()``; should return ``False`` or ``True``. When this method\n is not defined, ``__len__()`` is called, if it is defined, and the\n object is considered true if its result is nonzero. If a class\n defines neither ``__len__()`` nor ``__bool__()``, all its instances\n are considered true.\n\n\nCustomizing attribute access\n============================\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of ``x.name``)\nfor class instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for ``self``). ``name`` is the attribute name.\n This method should return the (computed) attribute value or raise\n an ``AttributeError`` exception.\n\n Note that if the attribute is found through the normal mechanism,\n ``__getattr__()`` is not called. (This is an intentional asymmetry\n between ``__getattr__()`` and ``__setattr__()``.) This is done both\n for efficiency reasons and because otherwise ``__getattr__()``\n would have no way to access other attributes of the instance. Note\n that at least for instance variables, you can fake total control by\n not inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n ``__getattribute__()`` method below for a way to actually get total\n control over attribute access.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines\n ``__getattr__()``, the latter will not be called unless\n ``__getattribute__()`` either calls it explicitly or raises an\n ``AttributeError``. This method should return the (computed)\n attribute value or raise an ``AttributeError`` exception. In order\n to avoid infinite recursion in this method, its implementation\n should always call the base class method with the same name to\n access any attributes it needs, for example,\n ``object.__getattribute__(self, name)``.\n\n Note: This method may still be bypassed when looking up special methods\n as the result of implicit invocation via language syntax or\n built-in functions. See *Special method lookup*.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If ``__setattr__()`` wants to assign to an instance attribute, it\n should call the base class method with the same name, for example,\n ``object.__setattr__(self, name, value)``.\n\nobject.__delattr__(self, name)\n\n Like ``__setattr__()`` but for attribute deletion instead of\n assignment. This should only be implemented if ``del obj.name`` is\n meaningful for the object.\n\nobject.__dir__(self)\n\n Called when ``dir()`` is called on the object. A sequence must be\n returned. ``dir()`` converts the returned sequence to a list and\n sorts it.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' ``__dict__``.\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or ``None`` when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an\n ``AttributeError`` exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n--------------------\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: ``__get__()``, ``__set__()``, and\n``__delete__()``. If any of those methods are defined for an object,\nit is said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, ``a.x`` has a\nlookup chain starting with ``a.__dict__[\'x\']``, then\n``type(a).__dict__[\'x\']``, and continuing through the base classes of\n``type(a)`` excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called.\n\nThe starting point for descriptor invocation is a binding, ``a.x``.\nHow the arguments are assembled depends on ``a``:\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: ``x.__get__(a)``.\n\nInstance Binding\n If binding to an object instance, ``a.x`` is transformed into the\n call: ``type(a).__dict__[\'x\'].__get__(a, type(a))``.\n\nClass Binding\n If binding to a class, ``A.x`` is transformed into the call:\n ``A.__dict__[\'x\'].__get__(None, A)``.\n\nSuper Binding\n If ``a`` is an instance of ``super``, then the binding ``super(B,\n obj).m()`` searches ``obj.__class__.__mro__`` for the base class\n ``A`` immediately preceding ``B`` and then invokes the descriptor\n with the call: ``A.__dict__[\'m\'].__get__(obj, obj.__class__)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of ``__get__()``, ``__set__()`` and ``__delete__()``.\nIf it does not define ``__get__()``, then accessing the attribute will\nreturn the descriptor object itself unless there is a value in the\nobject\'s instance dictionary. If the descriptor defines ``__set__()``\nand/or ``__delete__()``, it is a data descriptor; if it defines\nneither, it is a non-data descriptor. Normally, data descriptors\ndefine both ``__get__()`` and ``__set__()``, while non-data\ndescriptors have just the ``__get__()`` method. Data descriptors with\n``__set__()`` and ``__get__()`` defined always override a redefinition\nin an instance dictionary. In contrast, non-data descriptors can be\noverridden by instances.\n\nPython methods (including ``staticmethod()`` and ``classmethod()``)\nare implemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe ``property()`` function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n---------\n\nBy default, instances of classes have a dictionary for attribute\nstorage. This wastes space for objects having very few instance\nvariables. The space consumption can become acute when creating large\nnumbers of instances.\n\nThe default can be overridden by defining *__slots__* in a class\ndefinition. The *__slots__* declaration takes a sequence of instance\nvariables and reserves just enough space in each instance to hold a\nvalue for each variable. Space is saved because *__dict__* is not\ncreated for each instance.\n\nobject.__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n class, *__slots__* reserves space for the declared variables and\n prevents the automatic creation of *__dict__* and *__weakref__* for\n each instance.\n\n\nNotes on using *__slots__*\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises ``AttributeError``. If\n dynamic assignment of new variables is desired, then add\n ``\'__dict__\'`` to the sequence of strings in the *__slots__*\n declaration.\n\n* Without a *__weakref__* variable for each instance, classes defining\n *__slots__* do not support weak references to its instances. If weak\n reference support is needed, then add ``\'__weakref__\'`` to the\n sequence of strings in the *__slots__* declaration.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (*Implementing Descriptors*) for each variable name. As\n a result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the instance\n variable defined by the base class slot is inaccessible (except by\n retrieving its descriptor directly from the base class). This\n renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as ``int``, ``str`` and\n ``tuple``.\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings may\n also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, classes are constructed using ``type()``. The class body\nis executed in a new namespace and the class name is bound locally to\nthe result of ``type(name, bases, namespace)``.\n\nThe class creation process can be customised by passing the\n``metaclass`` keyword argument in the class definition line, or by\ninheriting from an existing class that included such an argument. In\nthe following example, both ``MyClass`` and ``MySubclass`` are\ninstances of ``Meta``:\n\n class Meta(type):\n pass\n\n class MyClass(metaclass=Meta):\n pass\n\n class MySubclass(MyClass):\n pass\n\nAny other keyword arguments that are specified in the class definition\nare passed through to all metaclass operations described below.\n\nWhen a class definition is executed, the following steps occur:\n\n* the appropriate metaclass is determined\n\n* the class namespace is prepared\n\n* the class body is executed\n\n* the class object is created\n\n\nDetermining the appropriate metaclass\n-------------------------------------\n\nThe appropriate metaclass for a class definition is determined as\nfollows:\n\n* if no bases and no explicit metaclass are given, then ``type()`` is\n used\n\n* if an explicit metaclass is given and it is *not* an instance of\n ``type()``, then it is used directly as the metaclass\n\n* if an instance of ``type()`` is given as the explicit metaclass, or\n bases are defined, then the most derived metaclass is used\n\nThe most derived metaclass is selected from the explicitly specified\nmetaclass (if any) and the metaclasses (i.e. ``type(cls)``) of all\nspecified base classes. The most derived metaclass is one which is a\nsubtype of *all* of these candidate metaclasses. If none of the\ncandidate metaclasses meets that criterion, then the class definition\nwill fail with ``TypeError``.\n\n\nPreparing the class namespace\n-----------------------------\n\nOnce the appropriate metaclass has been identified, then the class\nnamespace is prepared. If the metaclass has a ``__prepare__``\nattribute, it is called as ``namespace = metaclass.__prepare__(name,\nbases, **kwds)`` (where the additional keyword arguments, if any, come\nfrom the class definition).\n\nIf the metaclass has no ``__prepare__`` attribute, then the class\nnamespace is initialised as an empty ``dict()`` instance.\n\nSee also:\n\n **PEP 3115** - Metaclasses in Python 3000\n Introduced the ``__prepare__`` namespace hook\n\n\nExecuting the class body\n------------------------\n\nThe class body is executed (approximately) as ``exec(body, globals(),\nnamespace)``. The key difference from a normal call to ``exec()`` is\nthat lexical scoping allows the class body (including any methods) to\nreference names from the current and outer scopes when the class\ndefinition occurs inside a function.\n\nHowever, even when the class definition occurs inside the function,\nmethods defined inside the class still cannot see names defined at the\nclass scope. Class variables must be accessed through the first\nparameter of instance or class methods, and cannot be accessed at all\nfrom static methods.\n\n\nCreating the class object\n-------------------------\n\nOnce the class namespace has been populated by executing the class\nbody, the class object is created by calling ``metaclass(name, bases,\nnamespace, **kwds)`` (the additional keywords passed here are the same\nas those passed to ``__prepare__``).\n\nThis class object is the one that will be referenced by the zero-\nargument form of ``super()``. ``__class__`` is an implicit closure\nreference created by the compiler if any methods in a class body refer\nto either ``__class__`` or ``super``. This allows the zero argument\nform of ``super()`` to correctly identify the class being defined\nbased on lexical scoping, while the class or instance that was used to\nmake the current call is identified based on the first argument passed\nto the method.\n\nAfter the class object is created, it is passed to the class\ndecorators included in the class definition (if any) and the resulting\nobject is bound in the local namespace as the defined class.\n\nSee also:\n\n **PEP 3135** - New super\n Describes the implicit ``__class__`` closure reference\n\n\nMetaclass example\n-----------------\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored include logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\nHere is an example of a metaclass that uses an\n``collections.OrderedDict`` to remember the order that class members\nwere defined:\n\n class OrderedClass(type):\n\n @classmethod\n def __prepare__(metacls, name, bases, **kwds):\n return collections.OrderedDict()\n\n def __new__(cls, name, bases, namespace, **kwds):\n result = type.__new__(cls, name, bases, dict(namespace))\n result.members = tuple(namespace)\n return result\n\n class A(metaclass=OrderedClass):\n def one(self): pass\n def two(self): pass\n def three(self): pass\n def four(self): pass\n\n >>> A.members\n (\'__module__\', \'one\', \'two\', \'three\', \'four\')\n\nWhen the class definition for *A* gets executed, the process begins\nwith calling the metaclass\'s ``__prepare__()`` method which returns an\nempty ``collections.OrderedDict``. That mapping records the methods\nand attributes of *A* as they are defined within the body of the class\nstatement. Once those definitions are executed, the ordered dictionary\nis fully populated and the metaclass\'s ``__new__()`` method gets\ninvoked. That method builds the new type and it saves the ordered\ndictionary keys in an attribute called ``members``.\n\n\nCustomizing instance and subclass checks\n========================================\n\nThe following methods are used to override the default behavior of the\n``isinstance()`` and ``issubclass()`` built-in functions.\n\nIn particular, the metaclass ``abc.ABCMeta`` implements these methods\nin order to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n ``isinstance(instance, class)``.\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n ``issubclass(subclass, class)``.\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also:\n\n **PEP 3119** - Introducing Abstract Base Classes\n Includes the specification for customizing ``isinstance()`` and\n ``issubclass()`` behavior through ``__instancecheck__()`` and\n ``__subclasscheck__()``, with motivation for this functionality\n in the context of adding Abstract Base Classes (see the ``abc``\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, ``x(arg1, arg2, ...)`` is a shorthand for\n ``x.__call__(arg1, arg2, ...)``.\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which ``0 <= k < N``\nwhere *N* is the length of the sequence, or slice objects, which\ndefine a range of items. It is also recommended that mappings provide\nthe methods ``keys()``, ``values()``, ``items()``, ``get()``,\n``clear()``, ``setdefault()``, ``pop()``, ``popitem()``, ``copy()``,\nand ``update()`` behaving similar to those for Python\'s standard\ndictionary objects. The ``collections`` module provides a\n``MutableMapping`` abstract base class to help create those methods\nfrom a base set of ``__getitem__()``, ``__setitem__()``,\n``__delitem__()``, and ``keys()``. Mutable sequences should provide\nmethods ``append()``, ``count()``, ``index()``, ``extend()``,\n``insert()``, ``pop()``, ``remove()``, ``reverse()`` and ``sort()``,\nlike Python standard list objects. Finally, sequence types should\nimplement addition (meaning concatenation) and multiplication (meaning\nrepetition) by defining the methods ``__add__()``, ``__radd__()``,\n``__iadd__()``, ``__mul__()``, ``__rmul__()`` and ``__imul__()``\ndescribed below; they should not define other numerical operators. It\nis recommended that both mappings and sequences implement the\n``__contains__()`` method to allow efficient use of the ``in``\noperator; for mappings, ``in`` should search the mapping\'s keys; for\nsequences, it should search through the values. It is further\nrecommended that both mappings and sequences implement the\n``__iter__()`` method to allow efficient iteration through the\ncontainer; for mappings, ``__iter__()`` should be the same as\n``keys()``; for sequences, it should iterate through the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function ``len()``. Should return\n the length of the object, an integer ``>=`` 0. Also, an object\n that doesn\'t define a ``__bool__()`` method and whose ``__len__()``\n method returns zero is considered to be false in a Boolean context.\n\nNote: Slicing is done exclusively with the following three methods. A\n call like\n\n a[1:2] = b\n\n is translated to\n\n a[slice(1, 2, None)] = b\n\n and so forth. Missing slice items are always filled in with\n ``None``.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of ``self[key]``. For sequence\n types, the accepted keys should be integers and slice objects.\n Note that the special interpretation of negative indexes (if the\n class wishes to emulate a sequence type) is up to the\n ``__getitem__()`` method. If *key* is of an inappropriate type,\n ``TypeError`` may be raised; if of a value outside the set of\n indexes for the sequence (after any special interpretation of\n negative values), ``IndexError`` should be raised. For mapping\n types, if *key* is missing (not in the container), ``KeyError``\n should be raised.\n\n Note: ``for`` loops expect that an ``IndexError`` will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the ``__getitem__()`` method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of ``self[key]``. Same note as for\n ``__getitem__()``. This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the ``__getitem__()``\n method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method ``keys()``.\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see *Iterator Types*.\n\nobject.__reversed__(self)\n\n Called (if present) by the ``reversed()`` built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the ``__reversed__()`` method is not provided, the\n ``reversed()`` built-in will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects that\n support the sequence protocol should only provide\n ``__reversed__()`` if they can provide an implementation that is\n more efficient than the one provided by ``reversed()``.\n\nThe membership test operators (``in`` and ``not in``) are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define ``__contains__()``, the membership\n test first tries iteration via ``__iter__()``, then the old\n sequence iteration protocol via ``__getitem__()``, see *this\n section in the language reference*.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__truediv__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``). For instance, to evaluate the expression ``x + y``, where\n *x* is an instance of a class that has an ``__add__()`` method,\n ``x.__add__(y)`` is called. The ``__divmod__()`` method should be\n the equivalent to using ``__floordiv__()`` and ``__mod__()``; it\n should not be related to ``__truediv__()``. Note that\n ``__pow__()`` should be defined to accept an optional third\n argument if the ternary version of the built-in ``pow()`` function\n is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return ``NotImplemented``.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations (``+``, ``-``, ``*``, ``/``, ``//``, ``%``,\n ``divmod()``, ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``,\n ``|``) with reflected (swapped) operands. These functions are only\n called if the left operand does not support the corresponding\n operation and the operands are of different types. [2] For\n instance, to evaluate the expression ``x - y``, where *y* is an\n instance of a class that has an ``__rsub__()`` method,\n ``y.__rsub__(x)`` is called if ``x.__sub__(y)`` returns\n *NotImplemented*.\n\n Note that ternary ``pow()`` will not try calling ``__rpow__()``\n (the coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left operand\'s\n type and that subclass provides the reflected method for the\n operation, this method will be called before the left operand\'s\n non-reflected method. This behavior allows subclasses to\n override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\n ``**=``, ``<<=``, ``>>=``, ``&=``, ``^=``, ``|=``). These methods\n should attempt to do the operation in-place (modifying *self*) and\n return the result (which could be, but does not have to be,\n *self*). If a specific method is not defined, the augmented\n assignment falls back to the normal methods. For instance, to\n execute the statement ``x += y``, where *x* is an instance of a\n class that has an ``__iadd__()`` method, ``x.__iadd__(y)`` is\n called. If *x* is an instance of a class that does not define a\n ``__iadd__()`` method, ``x.__add__(y)`` and ``y.__radd__(x)`` are\n considered, as with the evaluation of ``x + y``.\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations (``-``, ``+``,\n ``abs()`` and ``~``).\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__float__(self)\nobject.__round__(self[, n])\n\n Called to implement the built-in functions ``complex()``,\n ``int()``, ``float()`` and ``round()``. Should return a value of\n the appropriate type.\n\nobject.__index__(self)\n\n Called to implement ``operator.index()``. Also called whenever\n Python needs an integer object (such as in slicing, or in the\n built-in ``bin()``, ``hex()`` and ``oct()`` functions). Must return\n an integer.\n\n\nWith Statement Context Managers\n===============================\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a ``with`` statement. The context\nmanager handles the entry into, and the exit from, the desired runtime\ncontext for the execution of the block of code. Context managers are\nnormally invoked using the ``with`` statement (described in section\n*The with statement*), but can also be used by directly invoking their\nmethods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see *Context Manager Types*.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The ``with``\n statement will bind this method\'s return value to the target(s)\n specified in the ``as`` clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be ``None``.\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that ``__exit__()`` methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n\n\nSpecial method lookup\n=====================\n\nFor custom classes, implicit invocations of special methods are only\nguaranteed to work correctly if defined on an object\'s type, not in\nthe object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: object of type \'C\' has no len()\n\nThe rationale behind this behaviour lies with a number of special\nmethods such as ``__hash__()`` and ``__repr__()`` that are implemented\nby all objects, including type objects. If the implicit lookup of\nthese methods used the conventional lookup process, they would fail\nwhen invoked on the type object itself:\n\n >>> 1 .__hash__() == hash(1)\n True\n >>> int.__hash__() == hash(int)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe ``__getattribute__()`` method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print("Metaclass getattribute invoked")\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object, metaclass=Meta):\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print("Class getattribute invoked")\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the ``__getattribute__()`` machinery in this fashion\nprovides significant scope for speed optimisations within the\ninterpreter, at the cost of some flexibility in the handling of\nspecial methods (the special method *must* be set on the class object\nitself in order to be consistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type, under\n certain controlled conditions. It generally isn\'t a good idea\n though, since it can lead to some very strange behaviour if it is\n handled incorrectly.\n\n[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', - 'string-methods': '\nString Methods\n**************\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the universal newlines approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', + 'string-methods': '\nString Methods\n**************\n\nStrings implement all of the *common* sequence operations, along with\nthe additional methods described below.\n\nStrings also support two styles of string formatting, one providing a\nlarge degree of flexibility and customization (see ``str.format()``,\n*Format String Syntax* and *String Formatting*) and the other based on\nC ``printf`` style formatting that handles a narrower range of types\nand is slightly harder to use correctly, but is often faster for the\ncases it can handle (*printf-style String Formatting*).\n\nThe *Text Processing Services* section of the standard library covers\na number of other modules that provide various text related utilities\n(including regular expression support in the ``re`` module).\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the *universal newlines* approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n\', \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n', 'strings': '\nString and Bytes literals\n*************************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "R" | "U"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'" | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | stringescapeseq\n longstringitem ::= longstringchar | stringescapeseq\n shortstringchar ::= \n longstringchar ::= \n stringescapeseq ::= "\\" \n\n bytesliteral ::= bytesprefix(shortbytes | longbytes)\n bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB"\n shortbytes ::= "\'" shortbytesitem* "\'" | \'"\' shortbytesitem* \'"\'\n longbytes ::= "\'\'\'" longbytesitem* "\'\'\'" | \'"""\' longbytesitem* \'"""\'\n shortbytesitem ::= shortbyteschar | bytesescapeseq\n longbytesitem ::= longbyteschar | bytesescapeseq\n shortbyteschar ::= \n longbyteschar ::= \n bytesescapeseq ::= "\\" \n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the ``stringprefix`` or\n``bytesprefix`` and the rest of the literal. The source character set\nis defined by the encoding declaration; it is UTF-8 if no encoding\ndeclaration is given in the source file; see section *Encoding\ndeclarations*.\n\nIn plain English: Both types of literals can be enclosed in matching\nsingle quotes (``\'``) or double quotes (``"``). They can also be\nenclosed in matching groups of three single or double quotes (these\nare generally referred to as *triple-quoted strings*). The backslash\n(``\\``) character is used to escape characters that otherwise have a\nspecial meaning, such as newline, backslash itself, or the quote\ncharacter.\n\nBytes literals are always prefixed with ``\'b\'`` or ``\'B\'``; they\nproduce an instance of the ``bytes`` type instead of the ``str`` type.\nThey may only contain ASCII characters; bytes with a numeric value of\n128 or greater must be expressed with escapes.\n\nAs of Python 3.3 it is possible again to prefix unicode strings with a\n``u`` prefix to simplify maintenance of dual 2.x and 3.x codebases.\n\nBoth string and bytes literals may optionally be prefixed with a\nletter ``\'r\'`` or ``\'R\'``; such strings are called *raw strings* and\ntreat backslashes as literal characters. As a result, in string\nliterals, ``\'\\U\'`` and ``\'\\u\'`` escapes in raw strings are not treated\nspecially. Given that Python 2.x\'s raw unicode literals behave\ndifferently than Python 3.x\'s the ``\'ur\'`` syntax is not supported.\n\n New in version 3.3: The ``\'rb\'`` prefix of raw bytes literals has\n been added as a synonym of ``\'br\'``.\n\n New in version 3.3: Support for the unicode legacy literal\n (``u\'value\'``) was reintroduced to simplify the maintenance of dual\n Python 2.x and 3.x codebases. See **PEP 414** for more information.\n\nIn triple-quoted strings, unescaped newlines and quotes are allowed\n(and are retained), except that three unescaped quotes in a row\nterminate the string. (A "quote" is the character used to open the\nstring, i.e. either ``\'`` or ``"``.)\n\nUnless an ``\'r\'`` or ``\'R\'`` prefix is present, escape sequences in\nstrings are interpreted according to rules similar to those used by\nStandard C. The recognized escape sequences are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\newline`` | Backslash and newline ignored | |\n+-------------------+-----------------------------------+---------+\n| ``\\\\`` | Backslash (``\\``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\\'`` | Single quote (``\'``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\"`` | Double quote (``"``) | |\n+-------------------+-----------------------------------+---------+\n| ``\\a`` | ASCII Bell (BEL) | |\n+-------------------+-----------------------------------+---------+\n| ``\\b`` | ASCII Backspace (BS) | |\n+-------------------+-----------------------------------+---------+\n| ``\\f`` | ASCII Formfeed (FF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\n`` | ASCII Linefeed (LF) | |\n+-------------------+-----------------------------------+---------+\n| ``\\r`` | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| ``\\t`` | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| ``\\v`` | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| ``\\ooo`` | Character with octal value *ooo* | (1,3) |\n+-------------------+-----------------------------------+---------+\n| ``\\xhh`` | Character with hex value *hh* | (2,3) |\n+-------------------+-----------------------------------+---------+\n\nEscape sequences only recognized in string literals are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| ``\\N{name}`` | Character named *name* in the | (4) |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (5) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (6) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, exactly two hex digits are required.\n\n3. In a bytes literal, hexadecimal and octal escapes denote the byte\n with the given value. In a string literal, these escapes denote a\n Unicode character with the given value.\n\n4. Changed in version 3.3: Support for name aliases [1] has been\n added.\n\n5. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Exactly four hex digits are\n required.\n\n6. Any Unicode character can be encoded this way, but characters\n outside the Basic Multilingual Plane (BMP) will be encoded using a\n surrogate pair if Python is compiled to use 16-bit code units (the\n default). Exactly eight hex digits are required.\n\nUnlike Standard C, all unrecognized escape sequences are left in the\nstring unchanged, i.e., *the backslash is left in the string*. (This\nbehavior is useful when debugging: if an escape sequence is mistyped,\nthe resulting output is more easily recognized as broken.) It is also\nimportant to note that the escape sequences only recognized in string\nliterals fall into the category of unrecognized escapes for bytes\nliterals.\n\nEven in a raw string, string quotes can be escaped with a backslash,\nbut the backslash remains in the string; for example, ``r"\\""`` is a\nvalid string literal consisting of two characters: a backslash and a\ndouble quote; ``r"\\"`` is not a valid string literal (even a raw\nstring cannot end in an odd number of backslashes). Specifically, *a\nraw string cannot end in a single backslash* (since the backslash\nwould escape the following quote character). Note also that a single\nbackslash followed by a newline is interpreted as those two characters\nas part of the string, *not* as a line continuation.\n', 'subscriptions': '\nSubscriptions\n*************\n\nA subscription selects an item of a sequence (string, tuple or list)\nor mapping (dictionary) object:\n\n subscription ::= primary "[" expression_list "]"\n\nThe primary must evaluate to an object that supports subscription,\ne.g. a list or dictionary. User-defined objects can support\nsubscription by defining a ``__getitem__()`` method.\n\nFor built-in objects, there are two types of objects that support\nsubscription:\n\nIf the primary is a mapping, the expression list must evaluate to an\nobject whose value is one of the keys of the mapping, and the\nsubscription selects the value in the mapping that corresponds to that\nkey. (The expression list is a tuple except if it has exactly one\nitem.)\n\nIf the primary is a sequence, the expression (list) must evaluate to\nan integer or a slice (as discussed in the following section).\n\nThe formal syntax makes no special provision for negative indices in\nsequences; however, built-in sequences all provide a ``__getitem__()``\nmethod that interprets negative indices by adding the length of the\nsequence to the index (so that ``x[-1]`` selects the last item of\n``x``). The resulting value must be a nonnegative integer less than\nthe number of items in the sequence, and the subscription selects the\nitem whose index is that value (counting from zero). Since the support\nfor negative indices and slicing occurs in the object\'s\n``__getitem__()`` method, subclasses overriding this method will need\nto explicitly add that support.\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n', 'truth': "\nTruth Value Testing\n*******************\n\nAny object can be tested for truth value, for use in an ``if`` or\n``while`` condition or as operand of the Boolean operations below. The\nfollowing values are considered false:\n\n* ``None``\n\n* ``False``\n\n* zero of any numeric type, for example, ``0``, ``0.0``, ``0j``.\n\n* any empty sequence, for example, ``''``, ``()``, ``[]``.\n\n* any empty mapping, for example, ``{}``.\n\n* instances of user-defined classes, if the class defines a\n ``__bool__()`` or ``__len__()`` method, when that method returns the\n integer zero or ``bool`` value ``False``. [1]\n\nAll other values are considered true --- so objects of many types are\nalways true.\n\nOperations and built-in functions that have a Boolean result always\nreturn ``0`` or ``False`` for false and ``1`` or ``True`` for true,\nunless otherwise stated. (Important exception: the Boolean operations\n``or`` and ``and`` always return one of their operands.)\n", - 'try': '\nThe ``try`` statement\n*********************\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception, it is re-raised at the end\nof the ``finally`` clause. If the ``finally`` clause raises another\nexception or executes a ``return`` or ``break`` statement, the saved\nexception is set as the context of the new exception. The exception\ninformation is not available to the program during execution of the\n``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', + 'try': '\nThe ``try`` statement\n*********************\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n del N\n\nThis means the exception must be assigned to a different name to be\nable to refer to it after the except clause. Exceptions are cleared\nbecause with the traceback attached to them, they form a reference\ncycle with the stack frame, keeping all locals in that frame alive\nuntil the next garbage collection occurs.\n\nBefore an except clause\'s suite is executed, details about the\nexception are stored in the ``sys`` module and can be access via\n``sys.exc_info()``. ``sys.exc_info()`` returns a 3-tuple consisting of\nthe exception class, the exception instance and a traceback object\n(see section *The standard type hierarchy*) identifying the point in\nthe program where the exception occurred. ``sys.exc_info()`` values\nare restored to their previous values (before the call) when returning\nfrom a function that handled an exception.\n\nThe optional ``else`` clause is executed if and when control flows off\nthe end of the ``try`` clause. [2] Exceptions in the ``else`` clause\nare not handled by the preceding ``except`` clauses.\n\nIf ``finally`` is present, it specifies a \'cleanup\' handler. The\n``try`` clause is executed, including any ``except`` and ``else``\nclauses. If an exception occurs in any of the clauses and is not\nhandled, the exception is temporarily saved. The ``finally`` clause is\nexecuted. If there is a saved exception or ``break`` statement, it is\nre-raised at the end of the ``finally`` clause. If the ``finally``\nclause raises another exception the saved exception is set as the\ncontext of the new exception; if the ``finally`` clause executes a\n``return`` statement, the saved exception is discarded:\n\n def f():\n try:\n 1/0\n finally:\n return 42\n\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the ``finally`` clause.\n\nWhen a ``return``, ``break`` or ``continue`` statement is executed in\nthe ``try`` suite of a ``try``...``finally`` statement, the\n``finally`` clause is also executed \'on the way out.\' A ``continue``\nstatement is illegal in the ``finally`` clause. (The reason is a\nproblem with the current implementation --- this restriction may be\nlifted in the future).\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information on using the ``raise`` statement to\ngenerate exceptions may be found in section *The raise statement*.\n', 'types': '\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.), although such additions\nwill often be provided via the standard library instead.\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name ``None``.\n It is used to signify the absence of a value in many situations,\n e.g., it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n ``NotImplemented``. Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the literal ``...`` or the\n built-in name ``Ellipsis``. Its truth value is true.\n\n``numbers.Number``\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n ``numbers.Integral``\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are two types of integers:\n\n Integers (``int``)\n\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, and Boolean values behave like the values 0 and 1,\n respectively, in almost all contexts, the exception being\n that when converted to a string, the strings ``"False"`` or\n ``"True"`` are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers.\n\n ``numbers.Real`` (``float``)\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these is\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n ``numbers.Complex`` (``complex``)\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number ``z`` can be retrieved through the read-only\n attributes ``z.real`` and ``z.imag``.\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function ``len()`` returns the number of\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is selected by ``a[i]``.\n\n Sequences also support slicing: ``a[i:j]`` selects all items with\n index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: ``a[i:j:k]`` selects all items of *a* with index *x*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n A string is a sequence of values that represent Unicode\n codepoints. All the codepoints in range ``U+0000 - U+10FFFF``\n can be represented in a string. Python doesn\'t have a\n ``chr`` type, and every character in the string is\n represented as a string object with length ``1``. The built-\n in function ``ord()`` converts a character to its codepoint\n (as an integer); ``chr()`` converts an integer in range ``0 -\n 10FFFF`` to the corresponding character. ``str.encode()`` can\n be used to convert a ``str`` to ``bytes`` using the given\n encoding, and ``bytes.decode()`` can be used to achieve the\n opposite.\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Bytes\n A bytes object is an immutable array. The items are 8-bit\n bytes, represented by integers in the range 0 <= x < 256.\n Bytes literals (like ``b\'abc\'`` and the built-in function\n ``bytes()`` can be used to construct bytes objects. Also,\n bytes objects can be decoded to strings via the ``decode()``\n method.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and ``del`` (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in ``bytearray()`` constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module ``array`` provides an additional example of\n a mutable sequence type, as does the ``collections`` module.\n\nSet types\n These represent unordered, finite sets of unique, immutable\n objects. As such, they cannot be indexed by any subscript. However,\n they can be iterated over, and the built-in function ``len()``\n returns the number of items in a set. Common uses for sets are fast\n membership testing, removing duplicates from a sequence, and\n computing mathematical operations such as intersection, union,\n difference, and symmetric difference.\n\n For set elements, the same immutability rules apply as for\n dictionary keys. Note that numeric types obey the normal rules for\n numeric comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``), only one of them can be contained in a set.\n\n There are currently two intrinsic set types:\n\n Sets\n These represent a mutable set. They are created by the built-in\n ``set()`` constructor and can be modified afterwards by several\n methods, such as ``add()``.\n\n Frozen sets\n These represent an immutable set. They are created by the\n built-in ``frozenset()`` constructor. As a frozenset is\n immutable and *hashable*, it can be used again as an element of\n another set, or as a dictionary key.\n\nMappings\n These represent finite sets of objects indexed by arbitrary index\n sets. The subscript notation ``a[k]`` selects the item indexed by\n ``k`` from the mapping ``a``; this can be used in expressions and\n as the target of assignments or ``del`` statements. The built-in\n function ``len()`` returns the number of items in a mapping.\n\n There is currently a single intrinsic mapping type:\n\n Dictionaries\n These represent finite sets of objects indexed by nearly\n arbitrary values. The only types of values not acceptable as\n keys are values containing lists or dictionaries or other\n mutable types that are compared by value rather than by object\n identity, the reason being that the efficient implementation of\n dictionaries requires a key\'s hash value to remain constant.\n Numeric types used for keys obey the normal rules for numeric\n comparison: if two numbers compare equal (e.g., ``1`` and\n ``1.0``) then they can be used interchangeably to index the same\n dictionary entry.\n\n Dictionaries are mutable; they can be created by the ``{...}``\n notation (see section *Dictionary displays*).\n\n The extension modules ``dbm.ndbm`` and ``dbm.gnu`` provide\n additional examples of mapping types, as does the\n ``collections`` module.\n\nCallable types\n These are the types to which the function call operation (see\n section *Calls*) can be applied:\n\n User-defined functions\n A user-defined function object is created by a function\n definition (see section *Function definitions*). It should be\n called with an argument list containing the same number of items\n as the function\'s formal parameter list.\n\n Special attributes:\n\n +---------------------------+---------------------------------+-------------+\n | Attribute | Meaning | |\n +===========================+=================================+=============+\n | ``__doc__`` | The function\'s documentation | Writable |\n | | string, or ``None`` if | |\n | | unavailable | |\n +---------------------------+---------------------------------+-------------+\n | ``__name__`` | The function\'s name | Writable |\n +---------------------------+---------------------------------+-------------+\n | ``__qualname__`` | The function\'s *qualified name* | Writable |\n | | New in version 3.3. | |\n +---------------------------+---------------------------------+-------------+\n | ``__module__`` | The name of the module the | Writable |\n | | function was defined in, or | |\n | | ``None`` if unavailable. | |\n +---------------------------+---------------------------------+-------------+\n | ``__defaults__`` | A tuple containing default | Writable |\n | | argument values for those | |\n | | arguments that have defaults, | |\n | | or ``None`` if no arguments | |\n | | have a default value | |\n +---------------------------+---------------------------------+-------------+\n | ``__code__`` | The code object representing | Writable |\n | | the compiled function body. | |\n +---------------------------+---------------------------------+-------------+\n | ``__globals__`` | A reference to the dictionary | Read-only |\n | | that holds the function\'s | |\n | | global variables --- the global | |\n | | namespace of the module in | |\n | | which the function was defined. | |\n +---------------------------+---------------------------------+-------------+\n | ``__dict__`` | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +---------------------------+---------------------------------+-------------+\n | ``__closure__`` | ``None`` or a tuple of cells | Read-only |\n | | that contain bindings for the | |\n | | function\'s free variables. | |\n +---------------------------+---------------------------------+-------------+\n | ``__annotations__`` | A dict containing annotations | Writable |\n | | of parameters. The keys of the | |\n | | dict are the parameter names, | |\n | | or ``\'return\'`` for the return | |\n | | annotation, if provided. | |\n +---------------------------+---------------------------------+-------------+\n | ``__kwdefaults__`` | A dict containing defaults for | Writable |\n | | keyword-only parameters. | |\n +---------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\n\n Function objects also support getting and setting arbitrary\n attributes, which can be used, for example, to attach metadata\n to functions. Regular attribute dot-notation is used to get and\n set such attributes. *Note that the current implementation only\n supports function attributes on user-defined functions. Function\n attributes on built-in functions may be supported in the\n future.*\n\n Additional information about a function\'s definition can be\n retrieved from its code object; see the description of internal\n types below.\n\n Instance methods\n An instance method object combines a class, a class instance and\n any callable object (normally a user-defined function).\n\n Special read-only attributes: ``__self__`` is the class instance\n object, ``__func__`` is the function object; ``__doc__`` is the\n method\'s documentation (same as ``__func__.__doc__``);\n ``__name__`` is the method name (same as ``__func__.__name__``);\n ``__module__`` is the name of the module the method was defined\n in, or ``None`` if unavailable.\n\n Methods also support accessing (but not setting) the arbitrary\n function attributes on the underlying function object.\n\n User-defined method objects may be created when getting an\n attribute of a class (perhaps via an instance of that class), if\n that attribute is a user-defined function object or a class\n method object.\n\n When an instance method object is created by retrieving a user-\n defined function object from a class via one of its instances,\n its ``__self__`` attribute is the instance, and the method\n object is said to be bound. The new method\'s ``__func__``\n attribute is the original function object.\n\n When a user-defined method object is created by retrieving\n another method object from a class or instance, the behaviour is\n the same as for a function object, except that the ``__func__``\n attribute of the new instance is not the original method object\n but its ``__func__`` attribute.\n\n When an instance method object is created by retrieving a class\n method object from a class or instance, its ``__self__``\n attribute is the class itself, and its ``__func__`` attribute is\n the function object underlying the class method.\n\n When an instance method object is called, the underlying\n function (``__func__``) is called, inserting the class instance\n (``__self__``) in front of the argument list. For instance,\n when ``C`` is a class which contains a definition for a function\n ``f()``, and ``x`` is an instance of ``C``, calling ``x.f(1)``\n is equivalent to calling ``C.f(x, 1)``.\n\n When an instance method object is derived from a class method\n object, the "class instance" stored in ``__self__`` will\n actually be the class itself, so that calling either ``x.f(1)``\n or ``C.f(1)`` is equivalent to calling ``f(C,1)`` where ``f`` is\n the underlying function.\n\n Note that the transformation from function object to instance\n method object happens each time the attribute is retrieved from\n the instance. In some cases, a fruitful optimization is to\n assign the attribute to a local variable and call that local\n variable. Also notice that this transformation only happens for\n user-defined functions; other callable objects (and all non-\n callable objects) are retrieved without transformation. It is\n also important to note that user-defined functions which are\n attributes of a class instance are not converted to bound\n methods; this *only* happens when the function is an attribute\n of the class.\n\n Generator functions\n A function or method which uses the ``yield`` statement (see\n section *The yield statement*) is called a *generator function*.\n Such a function, when called, always returns an iterator object\n which can be used to execute the body of the function: calling\n the iterator\'s ``__next__()`` method will cause the function to\n execute until it provides a value using the ``yield`` statement.\n When the function executes a ``return`` statement or falls off\n the end, a ``StopIteration`` exception is raised and the\n iterator will have reached the end of the set of values to be\n returned.\n\n Built-in functions\n A built-in function object is a wrapper around a C function.\n Examples of built-in functions are ``len()`` and ``math.sin()``\n (``math`` is a standard built-in module). The number and type of\n the arguments are determined by the C function. Special read-\n only attributes: ``__doc__`` is the function\'s documentation\n string, or ``None`` if unavailable; ``__name__`` is the\n function\'s name; ``__self__`` is set to ``None`` (but see the\n next item); ``__module__`` is the name of the module the\n function was defined in or ``None`` if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n ``alist.append()``, assuming *alist* is a list object. In this\n case, the special read-only attribute ``__self__`` is set to the\n object denoted by *alist*.\n\n Classes\n Classes are callable. These objects normally act as factories\n for new instances of themselves, but variations are possible for\n class types that override ``__new__()``. The arguments of the\n call are passed to ``__new__()`` and, in the typical case, to\n ``__init__()`` to initialize the new instance.\n\n Class Instances\n Instances of arbitrary classes can be made callable by defining\n a ``__call__()`` method in their class.\n\nModules\n Modules are a basic organizational unit of Python code, and are\n created by the *import system* as invoked either by the ``import``\n statement (see ``import``), or by calling functions such as\n ``importlib.import_module()`` and built-in ``__import__()``. A\n module object has a namespace implemented by a dictionary object\n (this is the dictionary referenced by the ``__globals__`` attribute\n of functions defined in the module). Attribute references are\n translated to lookups in this dictionary, e.g., ``m.x`` is\n equivalent to ``m.__dict__["x"]``. A module object does not contain\n the code object used to initialize the module (since it isn\'t\n needed once the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., ``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.\n\n Special read-only attribute: ``__dict__`` is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: ``__name__`` is the module\'s\n name; ``__doc__`` is the module\'s documentation string, or ``None``\n if unavailable; ``__file__`` is the pathname of the file from which\n the module was loaded, if it was loaded from a file. The\n ``__file__`` attribute may be missing for certain types of modules,\n such as C modules that are statically linked into the interpreter;\n for extension modules loaded dynamically from a shared library, it\n is the pathname of the shared library file.\n\nCustom classes\n Custom class types are typically created by class definitions (see\n section *Class definitions*). A class has a namespace implemented\n by a dictionary object. Class attribute references are translated\n to lookups in this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]`` (although there are a number of hooks which\n allow for other means of locating attributes). When the attribute\n name is not found there, the attribute search continues in the base\n classes. This search of the base classes uses the C3 method\n resolution order which behaves correctly even in the presence of\n \'diamond\' inheritance structures where there are multiple\n inheritance paths leading back to a common ancestor. Additional\n details on the C3 MRO used by Python can be found in the\n documentation accompanying the 2.3 release at\n http://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class ``C``, say) would yield\n a class method object, it is transformed into an instance method\n object whose ``__self__`` attributes is ``C``. When it would yield\n a static method object, it is transformed into the object wrapped\n by the static method object. See section *Implementing Descriptors*\n for another way in which attributes retrieved from a class may\n differ from those actually contained in its ``__dict__``.\n\n Class attribute assignments update the class\'s dictionary, never\n the dictionary of a base class.\n\n A class object can be called (see above) to yield a class instance\n (see below).\n\n Special attributes: ``__name__`` is the class name; ``__module__``\n is the module name in which the class was defined; ``__dict__`` is\n the dictionary containing the class\'s namespace; ``__bases__`` is a\n tuple (possibly empty or a singleton) containing the base classes,\n in the order of their occurrence in the base class list;\n ``__doc__`` is the class\'s documentation string, or None if\n undefined.\n\nClass instances\n A class instance is created by calling a class object (see above).\n A class instance has a namespace implemented as a dictionary which\n is the first place in which attribute references are searched.\n When an attribute is not found there, and the instance\'s class has\n an attribute by that name, the search continues with the class\n attributes. If a class attribute is found that is a user-defined\n function object, it is transformed into an instance method object\n whose ``__self__`` attribute is the instance. Static method and\n class method objects are also transformed; see above under\n "Classes". See section *Implementing Descriptors* for another way\n in which attributes of a class retrieved via its instances may\n differ from the objects actually stored in the class\'s\n ``__dict__``. If no class attribute is found, and the object\'s\n class has a ``__getattr__()`` method, that is called to satisfy the\n lookup.\n\n Attribute assignments and deletions update the instance\'s\n dictionary, never a class\'s dictionary. If the class has a\n ``__setattr__()`` or ``__delattr__()`` method, this is called\n instead of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n *Special method names*.\n\n Special attributes: ``__dict__`` is the attribute dictionary;\n ``__class__`` is the instance\'s class.\n\nI/O objects (also known as file objects)\n A *file object* represents an open file. Various shortcuts are\n available to create file objects: the ``open()`` built-in function,\n and also ``os.popen()``, ``os.fdopen()``, and the ``makefile()``\n method of socket objects (and perhaps by other functions or methods\n provided by extension modules).\n\n The objects ``sys.stdin``, ``sys.stdout`` and ``sys.stderr`` are\n initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams; they are all open in text\n mode and therefore follow the interface defined by the\n ``io.TextIOBase`` abstract class.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: ``co_name`` gives the function\n name; ``co_argcount`` is the number of positional arguments\n (including arguments with default values); ``co_nlocals`` is the\n number of local variables used by the function (including\n arguments); ``co_varnames`` is a tuple containing the names of\n the local variables (starting with the argument names);\n ``co_cellvars`` is a tuple containing the names of local\n variables that are referenced by nested functions;\n ``co_freevars`` is a tuple containing the names of free\n variables; ``co_code`` is a string representing the sequence of\n bytecode instructions; ``co_consts`` is a tuple containing the\n literals used by the bytecode; ``co_names`` is a tuple\n containing the names used by the bytecode; ``co_filename`` is\n the filename from which the code was compiled;\n ``co_firstlineno`` is the first line number of the function;\n ``co_lnotab`` is a string encoding the mapping from bytecode\n offsets to line numbers (for details see the source code of the\n interpreter); ``co_stacksize`` is the required stack size\n (including local variables); ``co_flags`` is an integer encoding\n a number of flags for the interpreter.\n\n The following flag bits are defined for ``co_flags``: bit\n ``0x04`` is set if the function uses the ``*arguments`` syntax\n to accept an arbitrary number of positional arguments; bit\n ``0x08`` is set if the function uses the ``**keywords`` syntax\n to accept arbitrary keyword arguments; bit ``0x20`` is set if\n the function is a generator.\n\n Future feature declarations (``from __future__ import\n division``) also use bits in ``co_flags`` to indicate whether a\n code object was compiled with a particular feature enabled: bit\n ``0x2000`` is set if the function was compiled with future\n division enabled; bits ``0x10`` and ``0x1000`` were used in\n earlier versions of Python.\n\n Other bits in ``co_flags`` are reserved for internal use.\n\n If a code object represents a function, the first item in\n ``co_consts`` is the documentation string of the function, or\n ``None`` if undefined.\n\n Frame objects\n Frame objects represent execution frames. They may occur in\n traceback objects (see below).\n\n Special read-only attributes: ``f_back`` is to the previous\n stack frame (towards the caller), or ``None`` if this is the\n bottom stack frame; ``f_code`` is the code object being executed\n in this frame; ``f_locals`` is the dictionary used to look up\n local variables; ``f_globals`` is used for global variables;\n ``f_builtins`` is used for built-in (intrinsic) names;\n ``f_lasti`` gives the precise instruction (this is an index into\n the bytecode string of the code object).\n\n Special writable attributes: ``f_trace``, if not ``None``, is a\n function called at the start of each source code line (this is\n used by the debugger); ``f_lineno`` is the current line number\n of the frame --- writing to this from within a trace function\n jumps to the given line (only for the bottom-most frame). A\n debugger can implement a Jump command (aka Set Next Statement)\n by writing to f_lineno.\n\n Traceback objects\n Traceback objects represent a stack trace of an exception. A\n traceback object is created when an exception occurs. When the\n search for an exception handler unwinds the execution stack, at\n each unwound level a traceback object is inserted in front of\n the current traceback. When an exception handler is entered,\n the stack trace is made available to the program. (See section\n *The try statement*.) It is accessible as the third item of the\n tuple returned by ``sys.exc_info()``. When the program contains\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n ``staticmethod()`` constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in ``classmethod()`` constructor.\n', 'typesfunctions': '\nFunctions\n*********\n\nFunction objects are created by function definitions. The only\noperation on a function object is to call it: ``func(argument-list)``.\n\nThere are really two flavors of function objects: built-in functions\nand user-defined functions. Both support the same operation (to call\nthe function), but the implementation is different, hence the\ndifferent object types.\n\nSee *Function definitions* for more information.\n', - 'typesmapping': '\nMapping Types --- ``dict``\n**************************\n\nA *mapping* object maps *hashable* values to arbitrary objects.\nMappings are mutable objects. There is currently only one standard\nmapping type, the *dictionary*. (For other containers see the built\nin ``list``, ``set``, and ``tuple`` classes, and the ``collections``\nmodule.)\n\nA dictionary\'s keys are *almost* arbitrary values. Values that are\nnot *hashable*, that is, values containing lists, dictionaries or\nother mutable types (that are compared by value rather than by object\nidentity) may not be used as keys. Numeric types used for keys obey\nthe normal rules for numeric comparison: if two numbers compare equal\n(such as ``1`` and ``1.0``) then they can be used interchangeably to\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict([arg])\n\n Return a new dictionary initialized from an optional positional\n argument or from a set of keyword arguments. If no arguments are\n given, return a new empty dictionary. If the positional argument\n *arg* is a mapping object, return a dictionary mapping the same\n keys to the same values as does the mapping object. Otherwise the\n positional argument must be a sequence, a container that supports\n iteration, or an iterator object. The elements of the argument\n must each also be of one of those kinds, and each must in turn\n contain exactly two objects. The first is used as a key in the new\n dictionary, and the second as the key\'s value. If a given key is\n seen more than once, the last value associated with it is retained\n in the new dictionary.\n\n If keyword arguments are given, the keywords themselves with their\n associated values are added as items to the dictionary. If a key\n is specified both in the positional argument and as a keyword\n argument, the value associated with the keyword is retained in the\n dictionary. For example, these all return a dictionary equal to\n ``{"one": 1, "two": 2}``:\n\n * ``dict(one=1, two=2)``\n\n * ``dict({\'one\': 1, \'two\': 2})``\n\n * ``dict(zip((\'one\', \'two\'), (1, 2)))``\n\n * ``dict([[\'two\', 2], [\'one\', 1]])``\n\n The first example only works for keys that are valid Python\n identifiers; the others work with any valid keys.\n\n These are the operations that dictionaries support (and therefore,\n custom mapping types should support too):\n\n len(d)\n\n Return the number of items in the dictionary *d*.\n\n d[key]\n\n Return the item of *d* with key *key*. Raises a ``KeyError`` if\n *key* is not in the map.\n\n If a subclass of dict defines a method ``__missing__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\n\n d[key] = value\n\n Set ``d[key]`` to *value*.\n\n del d[key]\n\n Remove ``d[key]`` from *d*. Raises a ``KeyError`` if *key* is\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n classmethod fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n ``fromkeys()`` is a class method that returns a new dictionary.\n *value* defaults to ``None``.\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to ``None``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a ``KeyError`` is raised.\n\n popitem()\n\n Remove and return an arbitrary ``(key, value)`` pair from the\n dictionary.\n\n ``popitem()`` is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling ``popitem()`` raises a ``KeyError``.\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to ``None``.\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return ``None``.\n\n ``update()`` accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: ``d.update(red=1,\n blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` are *view objects*. They provide a dynamic view on\nthe dictionary\'s entries, which means that when the dictionary\nchanges, the view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of ``(key, value)``) in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of ``(value, key)`` pairs\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n d.items()]``.\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a ``RuntimeError`` or fail to iterate over all entries.\n\nx in dictview\n\n Return ``True`` if *x* is in the underlying dictionary\'s keys,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that ``(key, value)`` pairs are unique\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', + 'typesmapping': '\nMapping Types --- ``dict``\n**************************\n\nA *mapping* object maps *hashable* values to arbitrary objects.\nMappings are mutable objects. There is currently only one standard\nmapping type, the *dictionary*. (For other containers see the built-\nin ``list``, ``set``, and ``tuple`` classes, and the ``collections``\nmodule.)\n\nA dictionary\'s keys are *almost* arbitrary values. Values that are\nnot *hashable*, that is, values containing lists, dictionaries or\nother mutable types (that are compared by value rather than by object\nidentity) may not be used as keys. Numeric types used for keys obey\nthe normal rules for numeric comparison: if two numbers compare equal\n(such as ``1`` and ``1.0``) then they can be used interchangeably to\nindex the same dictionary entry. (Note however, that since computers\nstore floating-point numbers as approximations it is usually unwise to\nuse them as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of\n``key: value`` pairs within braces, for example: ``{\'jack\': 4098,\n\'sjoerd\': 4127}`` or ``{4098: \'jack\', 4127: \'sjoerd\'}``, or by the\n``dict`` constructor.\n\nclass class dict([arg])\n\n Return a new dictionary initialized from an optional positional\n argument or from a set of keyword arguments. If no arguments are\n given, return a new empty dictionary. If the positional argument\n *arg* is a mapping object, return a dictionary mapping the same\n keys to the same values as does the mapping object. Otherwise the\n positional argument must be a sequence, a container that supports\n iteration, or an iterator object. The elements of the argument\n must each also be of one of those kinds, and each must in turn\n contain exactly two objects. The first is used as a key in the new\n dictionary, and the second as the key\'s value. If a given key is\n seen more than once, the last value associated with it is retained\n in the new dictionary.\n\n If keyword arguments are given, the keywords themselves with their\n associated values are added as items to the dictionary. If a key\n is specified both in the positional argument and as a keyword\n argument, the value associated with the keyword is retained in the\n dictionary. For example, these all return a dictionary equal to\n ``{"one": 1, "two": 2}``:\n\n * ``dict(one=1, two=2)``\n\n * ``dict({\'one\': 1, \'two\': 2})``\n\n * ``dict(zip((\'one\', \'two\'), (1, 2)))``\n\n * ``dict([[\'two\', 2], [\'one\', 1]])``\n\n The first example only works for keys that are valid Python\n identifiers; the others work with any valid keys.\n\n These are the operations that dictionaries support (and therefore,\n custom mapping types should support too):\n\n len(d)\n\n Return the number of items in the dictionary *d*.\n\n d[key]\n\n Return the item of *d* with key *key*. Raises a ``KeyError`` if\n *key* is not in the map.\n\n If a subclass of dict defines a method ``__missing__()``, if the\n key *key* is not present, the ``d[key]`` operation calls that\n method with the key *key* as argument. The ``d[key]`` operation\n then returns or raises whatever is returned or raised by the\n ``__missing__(key)`` call if the key is not present. No other\n operations or methods invoke ``__missing__()``. If\n ``__missing__()`` is not defined, ``KeyError`` is raised.\n ``__missing__()`` must be a method; it cannot be an instance\n variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n See ``collections.Counter`` for a complete implementation\n including other methods helpful for accumulating and managing\n tallies.\n\n d[key] = value\n\n Set ``d[key]`` to *value*.\n\n del d[key]\n\n Remove ``d[key]`` from *d*. Raises a ``KeyError`` if *key* is\n not in the map.\n\n key in d\n\n Return ``True`` if *d* has a key *key*, else ``False``.\n\n key not in d\n\n Equivalent to ``not key in d``.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for ``iter(d.keys())``.\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n classmethod fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n ``fromkeys()`` is a class method that returns a new dictionary.\n *value* defaults to ``None``.\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to ``None``,\n so that this method never raises a ``KeyError``.\n\n items()\n\n Return a new view of the dictionary\'s items (``(key, value)``\n pairs). See the *documentation of view objects*.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See the\n *documentation of view objects*.\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a ``KeyError`` is raised.\n\n popitem()\n\n Remove and return an arbitrary ``(key, value)`` pair from the\n dictionary.\n\n ``popitem()`` is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling ``popitem()`` raises a ``KeyError``.\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to ``None``.\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return ``None``.\n\n ``update()`` accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: ``d.update(red=1,\n blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See the\n *documentation of view objects*.\n\nSee also:\n\n ``types.MappingProxyType`` can be used to create a read-only view\n of a ``dict``.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by ``dict.keys()``, ``dict.values()`` and\n``dict.items()`` are *view objects*. They provide a dynamic view on\nthe dictionary\'s entries, which means that when the dictionary\nchanges, the view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of ``(key, value)``) in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of ``(value, key)`` pairs\n using ``zip()``: ``pairs = zip(d.values(), d.keys())``. Another\n way to create the same list is ``pairs = [(v, k) for (k, v) in\n d.items()]``.\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a ``RuntimeError`` or fail to iterate over all entries.\n\nx in dictview\n\n Return ``True`` if *x* is in the underlying dictionary\'s keys,\n values or items (in the latter case, *x* should be a ``(key,\n value)`` tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that ``(key, value)`` pairs are unique\nand hashable, then the items view is also set-like. (Values views are\nnot treated as set-like since the entries are generally not unique.)\nFor set-like views, all of the operations defined for the abstract\nbase class ``collections.abc.Set`` are available (for example, ``==``,\n``<``, or ``^``).\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.keys()\n >>> values = dishes.values()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n >>> keys ^ {\'sausage\', \'juice\'}\n {\'juice\', \'sausage\', \'bacon\', \'spam\'}\n', 'typesmethods': "\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as ``append()`` on\nlists) and class instance methods. Built-in methods are described\nwith the types that support them.\n\nIf you access a method (a function defined in a class namespace)\nthrough an instance, you get a special object: a *bound method* (also\ncalled *instance method*) object. When called, it will add the\n``self`` argument to the argument list. Bound methods have two\nspecial read-only attributes: ``m.__self__`` is the object on which\nthe method operates, and ``m.__func__`` is the function implementing\nthe method. Calling ``m(arg-1, arg-2, ..., arg-n)`` is completely\nequivalent to calling ``m.__func__(m.__self__, arg-1, arg-2, ...,\narg-n)``.\n\nLike function objects, bound method objects support getting arbitrary\nattributes. However, since method attributes are actually stored on\nthe underlying function object (``meth.__func__``), setting method\nattributes on bound methods is disallowed. Attempting to set a method\nattribute results in a ``TypeError`` being raised. In order to set a\nmethod attribute, you need to explicitly set it on the underlying\nfunction object:\n\n class C:\n def method(self):\n pass\n\n c = C()\n c.method.__func__.whoami = 'my name is c'\n\nSee *The standard type hierarchy* for more information.\n", 'typesmodules': "\nModules\n*******\n\nThe only special operation on a module is attribute access:\n``m.name``, where *m* is a module and *name* accesses a name defined\nin *m*'s symbol table. Module attributes can be assigned to. (Note\nthat the ``import`` statement is not, strictly speaking, an operation\non a module object; ``import foo`` does not require a module object\nnamed *foo* to exist, rather it requires an (external) *definition*\nfor a module named *foo* somewhere.)\n\nA special attribute of every module is ``__dict__``. This is the\ndictionary containing the module's symbol table. Modifying this\ndictionary will actually change the module's symbol table, but direct\nassignment to the ``__dict__`` attribute is not possible (you can\nwrite ``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but\nyou can't write ``m.__dict__ = {}``). Modifying ``__dict__`` directly\nis not recommended.\n\nModules built into the interpreter are written like this: ````. If loaded from a file, they are written as\n````.\n", - 'typesseq': '\nSequence Types --- ``str``, ``bytes``, ``bytearray``, ``list``, ``tuple``, ``range``\n************************************************************************************\n\nThere are six sequence types: strings, byte sequences (``bytes``\nobjects), byte arrays (``bytearray`` objects), lists, tuples, and\nrange objects. For other containers see the built in ``dict`` and\n``set`` classes, and the ``collections`` module.\n\nStrings contain Unicode characters. Their literals are written in\nsingle or double quotes: ``\'xyzzy\'``, ``"frobozz"``. See *String and\nBytes literals* for more about string literals. In addition to the\nfunctionality described here, there are also string-specific methods\ndescribed in the *String Methods* section.\n\nBytes and bytearray objects contain single bytes -- the former is\nimmutable while the latter is a mutable sequence. Bytes objects can be\nconstructed by using the constructor, ``bytes()``, and from literals;\nuse a ``b`` prefix with normal string syntax: ``b\'xyzzy\'``. To\nconstruct byte arrays, use the ``bytearray()`` function.\n\nWhile string objects are sequences of characters (represented by\nstrings of length 1), bytes and bytearray objects are sequences of\n*integers* (between 0 and 255), representing the ASCII value of single\nbytes. That means that for a bytes or bytearray object *b*, ``b[0]``\nwill be an integer, while ``b[0:1]`` will be a bytes or bytearray\nobject of length 1. The representation of bytes objects uses the\nliteral format (``b\'...\'``) since it is generally more useful than\ne.g. ``bytes([50, 19, 100])``. You can always convert a bytes object\ninto a list of integers using ``list(b)``.\n\nAlso, while in previous Python versions, byte strings and Unicode\nstrings could be exchanged for each other rather freely (barring\nencoding issues), strings and bytes are now completely separate\nconcepts. There\'s no implicit en-/decoding if you pass an object of\nthe wrong type. A string always compares unequal to a bytes or\nbytearray object.\n\nLists are constructed with square brackets, separating items with\ncommas: ``[a, b, c]``. Tuples are constructed by the comma operator\n(not within square brackets), with or without enclosing parentheses,\nbut an empty tuple must have the enclosing parentheses, such as ``a,\nb, c`` or ``()``. A single item tuple must have a trailing comma,\nsuch as ``(d,)``.\n\nObjects of type range are created using the ``range()`` function.\nThey don\'t support concatenation or repetition, and using ``min()`` or\n``max()`` on them is inefficient.\n\nMost sequence types support the following operations. The ``in`` and\n``not in`` operations have the same priorities as the comparison\noperations. The ``+`` and ``*`` operations have the same priority as\nthe corresponding numeric operations. [3] Additional methods are\nprovided for *Mutable Sequence Types*.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type; *n*, *i*, *j* and *k* are\nintegers.\n\n+--------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+====================+==================================+============+\n| ``x in s`` | ``True`` if an item of *s* is | (1) |\n| | equal to *x*, else ``False`` | |\n+--------------------+----------------------------------+------------+\n| ``x not in s`` | ``False`` if an item of *s* is | (1) |\n| | equal to *x*, else ``True`` | |\n+--------------------+----------------------------------+------------+\n| ``s + t`` | the concatenation of *s* and *t* | (6) |\n+--------------------+----------------------------------+------------+\n| ``s * n, n * s`` | *n* shallow copies of *s* | (2) |\n| | concatenated | |\n+--------------------+----------------------------------+------------+\n| ``s[i]`` | *i*th item of *s*, origin 0 | (3) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |\n+--------------------+----------------------------------+------------+\n| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+--------------------+----------------------------------+------------+\n| ``len(s)`` | length of *s* | |\n+--------------------+----------------------------------+------------+\n| ``min(s)`` | smallest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``max(s)`` | largest item of *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.index(i)`` | index of the first occurence of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n| ``s.count(i)`` | total number of occurences of | |\n| | *i* in *s* | |\n+--------------------+----------------------------------+------------+\n\nSequence types also support comparisons. In particular, tuples and\nlists are compared lexicographically by comparing corresponding\nelements. This means that to compare equal, every element must\ncompare equal and the two sequences must be of the same type and have\nthe same length. (For full details see *Comparisons* in the language\nreference.)\n\nNotes:\n\n1. When *s* is a string object, the ``in`` and ``not in`` operations\n act like a substring test.\n\n2. Values of *n* less than ``0`` are treated as ``0`` (which yields an\n empty sequence of the same type as *s*). Note also that the copies\n are shallow; nested structures are not copied. This often haunts\n new Python programmers; consider:\n\n >>> lists = [[]] * 3\n >>> lists\n [[], [], []]\n >>> lists[0].append(3)\n >>> lists\n [[3], [3], [3]]\n\n What has happened is that ``[[]]`` is a one-element list containing\n an empty list, so all three elements of ``[[]] * 3`` are (pointers\n to) this single empty list. Modifying any of the elements of\n ``lists`` modifies this single list. You can create a list of\n different lists this way:\n\n >>> lists = [[] for i in range(3)]\n >>> lists[0].append(3)\n >>> lists[1].append(5)\n >>> lists[2].append(7)\n >>> lists\n [[3], [5], [7]]\n\n3. If *i* or *j* is negative, the index is relative to the end of the\n string: ``len(s) + i`` or ``len(s) + j`` is substituted. But note\n that ``-0`` is still ``0``.\n\n4. The slice of *s* from *i* to *j* is defined as the sequence of\n items with index *k* such that ``i <= k < j``. If *i* or *j* is\n greater than ``len(s)``, use ``len(s)``. If *i* is omitted or\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n empty.\n\n5. The slice of *s* from *i* to *j* with step *k* is defined as the\n sequence of items with index ``x = i + n*k`` such that ``0 <= n <\n (j-i)/k``. In other words, the indices are ``i``, ``i+k``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable strings always results in a new object.\n This means that building up a string by repeated concatenation will\n have a quadratic runtime cost in the total string length. To get a\n linear runtime cost, you must switch to one of the alternatives\n below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end;\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()``, or you can do in-place concatenation with a\n ``bytearray`` object. ``bytearray`` objects are mutable and have\n an efficient overallocation mechanism.\n\n\nString Methods\n==============\n\nString objects support the methods listed below.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the *Sequence Types --- str, bytes, bytearray, list,\ntuple, range* section. To output formatted strings, see the *String\nFormatting* section. Also, see the ``re`` module for string functions\nbased on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\nstr.casefold()\n\n Return a casefolded copy of the string. Casefolded strings may be\n used for caseless matching.\n\n Casefolding is similar to lowercasing but more aggressive because\n it is intended to remove all case distinctions in a string. For\n example, the German lowercase letter ``\'\xc3\x9f\'`` is equivalent to\n ``"ss"``. Since it is already lowercase, ``lower()`` would do\n nothing to ``\'\xc3\x9f\'``; ``casefold()`` converts it to ``"ss"``.\n\n The casefolding algorithm is described in section 3.13 of the\n Unicode Standard.\n\n New in version 3.3.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.encode(encoding="utf-8", errors="strict")\n\n Return an encoded version of the string as a bytes object. Default\n encoding is ``\'utf-8\'``. *errors* may be given to set a different\n error handling scheme. The default for *errors* is ``\'strict\'``,\n meaning that encoding errors raise a ``UnicodeError``. Other\n possible values are ``\'ignore\'``, ``\'replace\'``,\n ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return ``True`` if the string ends with the specified *suffix*,\n otherwise return ``False``. *suffix* can also be a tuple of\n suffixes to look for. With optional *start*, test beginning at\n that position. With optional *end*, stop comparing at that\n position.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by zero or more spaces, depending on the current column and the\n given tab size. The column number is reset to zero after each\n newline occurring in the string. If *tabsize* is not given, a tab\n size of ``8`` characters is assumed. This doesn\'t understand other\n non-printing characters or escape sequences.\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found, such that *sub* is contained in the slice ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\n Note: The ``find()`` method should be used only if you need to know the\n position of *sub*. To check if *sub* is a substring or not, use\n the ``in`` operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces ``{}``. Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See *Format String Syntax* for a description of the various\n formatting options that can be specified in format strings.\n\nstr.format_map(mapping)\n\n Similar to ``str.format(**mapping)``, except that ``mapping`` is\n used directly and not copied to a ``dict`` . This is useful if for\n example ``mapping`` is a dict subclass:\n\n >>> class Default(dict):\n ... def __missing__(self, key):\n ... return key\n ...\n >>> \'{name} was born in {country}\'.format_map(Default(name=\'Guido\'))\n \'Guido was born in country\'\n\n New in version 3.2.\n\nstr.index(sub[, start[, end]])\n\n Like ``find()``, but raise ``ValueError`` when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise. A character\n ``c`` is alphanumeric if one of the following returns ``True``:\n ``c.isalpha()``, ``c.isdecimal()``, ``c.isdigit()``, or\n ``c.isnumeric()``.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise. Alphabetic\n characters are those characters defined in the Unicode character\n database as "Letter", i.e., those with general category property\n being one of "Lm", "Lt", "Lu", "Ll", or "Lo". Note that this is\n different from the "Alphabetic" property defined in the Unicode\n Standard.\n\nstr.isdecimal()\n\n Return true if all characters in the string are decimal characters\n and there is at least one character, false otherwise. Decimal\n characters are those from general category "Nd". This category\n includes digit characters, and all characters that can be used to\n form decimal-radix numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise. Digits include decimal\n characters and digits that need special handling, such as the\n compatibility superscript digits. Formally, a digit is a character\n that has the property value Numeric_Type=Digit or\n Numeric_Type=Decimal.\n\nstr.isidentifier()\n\n Return true if the string is a valid identifier according to the\n language definition, section *Identifiers and keywords*.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\nstr.isnumeric()\n\n Return true if all characters in the string are numeric characters,\n and there is at least one character, false otherwise. Numeric\n characters include digit characters, and all characters that have\n the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION\n ONE FIFTH. Formally, numeric characters are those with the\n property value Numeric_Type=Digit, Numeric_Type=Decimal or\n Numeric_Type=Numeric.\n\nstr.isprintable()\n\n Return true if all characters in the string are printable or the\n string is empty, false otherwise. Nonprintable characters are\n those characters defined in the Unicode character database as\n "Other" or "Separator", excepting the ASCII space (0x20) which is\n considered printable. (Note that printable characters in this\n context are those which should not be escaped when ``repr()`` is\n invoked on a string. It has no bearing on the handling of strings\n written to ``sys.stdout`` or ``sys.stderr``.)\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise. Whitespace\n characters are those characters defined in the Unicode character\n database as "Other" or "Separator" and those with bidirectional\n property being one of "WS", "B", or "S".\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. A ``TypeError`` will be raised if there are\n any non-string values in *iterable*, including ``bytes`` objects.\n The separator between elements is the string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n The lowercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\nstatic str.maketrans(x[, y[, z]])\n\n This static method returns a translation table usable for\n ``str.translate()``.\n\n If there is only one argument, it must be a dictionary mapping\n Unicode ordinals (integers) or characters (strings of length 1) to\n Unicode ordinals, strings (of arbitrary lengths) or None.\n Character keys will then be converted to ordinals.\n\n If there are two arguments, they must be strings of equal length,\n and in the resulting dictionary, each character in x will be mapped\n to the character at the same position in y. If there is a third\n argument, it must be a string, whose characters will be mapped to\n None in the result.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within ``s[start:end]``.\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like ``rfind()`` but raises ``ValueError`` when the substring *sub*\n is not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to ``len(s)``.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\nstr.rsplit(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n ``None``, any whitespace string is a separator. Except for\n splitting from the right, ``rsplit()`` behaves like ``split()``\n which is described in detail below.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or ``None``, the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\nstr.split(sep=None, maxsplit=-1)\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most ``maxsplit+1``\n elements). If *maxsplit* is not specified or ``-1``, then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n ``\'1,,2\'.split(\',\')`` returns ``[\'1\', \'\', \'2\']``). The *sep*\n argument may consist of multiple characters (for example,\n ``\'1<>2<>3\'.split(\'<>\')`` returns ``[\'1\', \'2\', \'3\']``). Splitting\n an empty string with a specified separator returns ``[\'\']``.\n\n If *sep* is not specified or is ``None``, a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a ``None`` separator returns\n ``[]``.\n\n For example, ``\' 1 2 3 \'.split()`` returns ``[\'1\', \'2\', \'3\']``,\n and ``\' 1 2 3 \'.split(None, 1)`` returns ``[\'1\', \'2 3 \']``.\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the universal newlines approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n For example, ``\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()`` returns\n ``[\'ab c\', \'\', \'de fg\', \'kl\']``, while the same call with\n ``splitlines(True)`` returns ``[\'ab c\\n\', \'\\n, \'de fg\\r\',\n \'kl\\r\\n\']``.\n\n Unlike ``split()`` when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line.\n\nstr.startswith(prefix[, start[, end]])\n\n Return ``True`` if string starts with the *prefix*, otherwise\n return ``False``. *prefix* can also be a tuple of prefixes to look\n for. With optional *start*, test string beginning at that\n position. With optional *end*, stop comparing string at that\n position.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or ``None``, the\n *chars* argument defaults to removing whitespace. The *chars*\n argument is not a prefix or suffix; rather, all combinations of its\n values are stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa. Note that it is not necessarily true that\n ``s.swapcase().swapcase() == s``.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n lambda mo: mo.group(0)[0].upper() +\n mo.group(0)[1:].lower(),\n s)\n\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\nstr.translate(map)\n\n Return a copy of the *s* where all characters have been mapped\n through the *map* which must be a dictionary of Unicode ordinals\n (integers) to Unicode ordinals, strings or ``None``. Unmapped\n characters are left untouched. Characters mapped to ``None`` are\n deleted.\n\n You can use ``str.maketrans()`` to create a translation map from\n character-to-character mappings in different formats.\n\n Note: An even more flexible approach is to create a custom character\n mapping codec using the ``codecs`` module (see\n ``encodings.cp1251`` for an example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that ``str.upper().isupper()`` might\n be ``False`` if ``s`` contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n The uppercasing algorithm used is described in section 3.13 of the\n Unicode Standard.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to ``len(s)``.\n\n\nOld String Formatting Operations\n================================\n\nNote: The formatting operations described here are modelled on C\'s\n printf() syntax. They only support formatting of certain builtin\n types. The use of a binary operator means that care may be needed\n in order to format tuples and dictionaries correctly. As the new\n *String Formatting* syntax is more flexible and handles tuples and\n dictionaries naturally, it is recommended for new code. However,\n there are no current plans to deprecate printf-style formatting.\n\nString objects have one unique built-in operation: the ``%`` operator\n(modulo). This is also known as the string *formatting* or\n*interpolation* operator. Given ``format % values`` (where *format* is\na string), ``%`` conversion specifications in *format* are replaced\nwith zero or more elements of *values*. The effect is similar to the\nusing ``sprintf()`` in the C language.\n\nIf *format* requires a single argument, *values* may be a single non-\ntuple object. [5] Otherwise, *values* must be a tuple with exactly\nthe number of items specified by the format string, or a single\nmapping object (for example, a dictionary).\n\nA conversion specifier contains two or more characters and has the\nfollowing components, which must occur in this order:\n\n1. The ``\'%\'`` character, which marks the start of the specifier.\n\n2. Mapping key (optional), consisting of a parenthesised sequence of\n characters (for example, ``(somename)``).\n\n3. Conversion flags (optional), which affect the result of some\n conversion types.\n\n4. Minimum field width (optional). If specified as an ``\'*\'``\n (asterisk), the actual width is read from the next element of the\n tuple in *values*, and the object to convert comes after the\n minimum field width and optional precision.\n\n5. Precision (optional), given as a ``\'.\'`` (dot) followed by the\n precision. If specified as ``\'*\'`` (an asterisk), the actual\n precision is read from the next element of the tuple in *values*,\n and the value to convert comes after the precision.\n\n6. Length modifier (optional).\n\n7. Conversion type.\n\nWhen the right argument is a dictionary (or other mapping type), then\nthe formats in the string *must* include a parenthesised mapping key\ninto that dictionary inserted immediately after the ``\'%\'`` character.\nThe mapping key selects the value to be formatted from the mapping.\nFor example:\n\n>>> print(\'%(language)s has %(number)03d quote types.\' %\n... {\'language\': "Python", "number": 2})\nPython has 002 quote types.\n\nIn this case no ``*`` specifiers may occur in a format (since they\nrequire a sequential parameter list).\n\nThe conversion flag characters are:\n\n+-----------+-----------------------------------------------------------------------+\n| Flag | Meaning |\n+===========+=======================================================================+\n| ``\'#\'`` | The value conversion will use the "alternate form" (where defined |\n| | below). |\n+-----------+-----------------------------------------------------------------------+\n| ``\'0\'`` | The conversion will be zero padded for numeric values. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'-\'`` | The converted value is left adjusted (overrides the ``\'0\'`` |\n| | conversion if both are given). |\n+-----------+-----------------------------------------------------------------------+\n| ``\' \'`` | (a space) A blank should be left before a positive number (or empty |\n| | string) produced by a signed conversion. |\n+-----------+-----------------------------------------------------------------------+\n| ``\'+\'`` | A sign character (``\'+\'`` or ``\'-\'``) will precede the conversion |\n| | (overrides a "space" flag). |\n+-----------+-----------------------------------------------------------------------+\n\nA length modifier (``h``, ``l``, or ``L``) may be present, but is\nignored as it is not necessary for Python -- so e.g. ``%ld`` is\nidentical to ``%d``.\n\nThe conversion types are:\n\n+--------------+-------------------------------------------------------+---------+\n| Conversion | Meaning | Notes |\n+==============+=======================================================+=========+\n| ``\'d\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'i\'`` | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'o\'`` | Signed octal value. | (1) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'u\'`` | Obsolete type -- it is identical to ``\'d\'``. | (7) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'x\'`` | Signed hexadecimal (lowercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'X\'`` | Signed hexadecimal (uppercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'e\'`` | Floating point exponential format (lowercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'E\'`` | Floating point exponential format (uppercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'f\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'F\'`` | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'g\'`` | Floating point format. Uses lowercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'G\'`` | Floating point format. Uses uppercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'c\'`` | Single character (accepts integer or single character | |\n| | string). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'r\'`` | String (converts any Python object using ``repr()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'s\'`` | String (converts any Python object using ``str()``). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| ``\'a\'`` | String (converts any Python object using | (5) |\n| | ``ascii()``). | |\n+--------------+-------------------------------------------------------+---------+\n| ``\'%\'`` | No argument is converted, results in a ``\'%\'`` | |\n| | character in the result. | |\n+--------------+-------------------------------------------------------+---------+\n\nNotes:\n\n1. The alternate form causes a leading zero (``\'0\'``) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n2. The alternate form causes a leading ``\'0x\'`` or ``\'0X\'`` (depending\n on whether the ``\'x\'`` or ``\'X\'`` format was used) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n3. The alternate form causes the result to always contain a decimal\n point, even if no digits follow it.\n\n The precision determines the number of digits after the decimal\n point and defaults to 6.\n\n4. The alternate form causes the result to always contain a decimal\n point, and trailing zeroes are not removed as they would otherwise\n be.\n\n The precision determines the number of significant digits before\n and after the decimal point and defaults to 6.\n\n5. If precision is ``N``, the output is truncated to ``N`` characters.\n\n1. See **PEP 237**.\n\nSince Python strings have an explicit length, ``%s`` conversions do\nnot assume that ``\'\\0\'`` is the end of the string.\n\nChanged in version 3.1: ``%f`` conversions for numbers whose absolute\nvalue is over 1e50 are no longer replaced by ``%g`` conversions.\n\nAdditional string operations are defined in standard modules\n``string`` and ``re``.\n\n\nRange Type\n==========\n\nThe ``range`` type is an immutable sequence which is commonly used for\nlooping. The advantage of the ``range`` type is that an ``range``\nobject will always take the same amount of memory, no matter the size\nof the range it represents.\n\nRange objects have relatively little behavior: they support indexing,\ncontains, iteration, the ``len()`` function, and the following\nmethods:\n\nrange.count(x)\n\n Return the number of *i*\'s for which ``s[i] == x``.\n\n New in version 3.2.\n\nrange.index(x)\n\n Return the smallest *i* such that ``s[i] == x``. Raises\n ``ValueError`` when *x* is not in the range.\n\n New in version 3.2.\n\n\nMutable Sequence Types\n======================\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | remove all items from ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | return a shallow copy of ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.count(x)`` | return number of *i*\'s for which | |\n| | ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.index(x[, i[, j]])`` | return smallest *k* such that | (3) |\n| | ``s[k] == x`` and ``i <= k < j`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | (5) |\n| | return x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | (3) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (6) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. *x* can be any iterable object.\n\n3. Raises ``ValueError`` when *x* is not found in *s*. When a negative\n index is passed as the second or third parameter to the ``index()``\n method, the sequence length is added, as for slice indices. If it\n is still negative, it is truncated to zero, as for slice indices.\n\n4. When a negative index is passed as the first parameter to the\n ``insert()`` method, the sequence length is added, as for slice\n indices. If it is still negative, it is truncated to zero, as for\n slice indices.\n\n5. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n6. The ``sort()`` and ``reverse()`` methods modify the sequence in\n place for economy of space when sorting or reversing a large\n sequence. To remind you that they operate by side effect, they\n don\'t return the sorted or reversed sequence.\n\n7. The ``sort()`` method takes optional arguments for controlling the\n comparisons. Each must be specified as a keyword argument.\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: ``key=str.lower``. The\n default value is ``None``. Use ``functools.cmp_to_key()`` to\n convert an old-style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n The ``sort()`` method is guaranteed to be stable. A sort is stable\n if it guarantees not to change the relative order of elements that\n compare equal --- this is helpful for sorting in multiple passes\n (for example, sort by department, then by salary grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can detect\n that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nBytes and Byte Array Methods\n============================\n\nBytes and bytearray objects, being "strings of bytes", have all\nmethods found on strings, with the exception of ``encode()``,\n``format()`` and ``isidentifier()``, which do not make sense with\nthese types. For converting the objects to strings, they have a\n``decode()`` method.\n\nWherever one of these methods needs to interpret the bytes as\ncharacters (e.g. the ``is...()`` methods), the ASCII character set is\nassumed.\n\nNew in version 3.3: The functions ``count()``, ``find()``,\n``index()``, ``rfind()`` and ``rindex()`` have additional semantics\ncompared to the corresponding string functions: They also accept an\ninteger in range 0 to 255 (a byte) as their first argument.\n\nNote: The methods on bytes and bytearray objects don\'t accept strings as\n their arguments, just as the methods on strings don\'t accept bytes\n as their arguments. For example, you have to write\n\n a = "abc"\n b = a.replace("a", "f")\n\n and\n\n a = b"abc"\n b = a.replace(b"a", b"f")\n\nbytes.decode(encoding="utf-8", errors="strict")\nbytearray.decode(encoding="utf-8", errors="strict")\n\n Return a string decoded from the given bytes. Default encoding is\n ``\'utf-8\'``. *errors* may be given to set a different error\n handling scheme. The default for *errors* is ``\'strict\'``, meaning\n that encoding errors raise a ``UnicodeError``. Other possible\n values are ``\'ignore\'``, ``\'replace\'`` and any other name\n registered via ``codecs.register_error()``, see section *Codec Base\n Classes*. For a list of possible encodings, see section *Standard\n Encodings*.\n\n Changed in version 3.1: Added support for keyword arguments.\n\nThe bytes and bytearray types have an additional class method:\n\nclassmethod bytes.fromhex(string)\nclassmethod bytearray.fromhex(string)\n\n This ``bytes`` class method returns a bytes or bytearray object,\n decoding the given string object. The string must contain two\n hexadecimal digits per byte, spaces are ignored.\n\n >>> bytes.fromhex(\'f0 f1f2 \')\n b\'\\xf0\\xf1\\xf2\'\n\nThe maketrans and translate methods differ in semantics from the\nversions available on strings:\n\nbytes.translate(table[, delete])\nbytearray.translate(table[, delete])\n\n Return a copy of the bytes or bytearray object where all bytes\n occurring in the optional argument *delete* are removed, and the\n remaining bytes have been mapped through the given translation\n table, which must be a bytes object of length 256.\n\n You can use the ``bytes.maketrans()`` method to create a\n translation table.\n\n Set the *table* argument to ``None`` for translations that only\n delete characters:\n\n >>> b\'read this short text\'.translate(None, b\'aeiou\')\n b\'rd ths shrt txt\'\n\nstatic bytes.maketrans(from, to)\nstatic bytearray.maketrans(from, to)\n\n This static method returns a translation table usable for\n ``bytes.translate()`` that will map each character in *from* into\n the character at the same position in *to*; *from* and *to* must be\n bytes objects and have the same length.\n\n New in version 3.1.\n', - 'typesseq-mutable': '\nMutable Sequence Types\n**********************\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | remove all items from ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | return a shallow copy of ``s`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.count(x)`` | return number of *i*\'s for which | |\n| | ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.index(x[, i[, j]])`` | return smallest *k* such that | (3) |\n| | ``s[k] == x`` and ``i <= k < j`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | same as ``s[i:i] = [x]`` | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | same as ``x = s[i]; del s[i]; | (5) |\n| | return x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | same as ``del s[s.index(x)]`` | (3) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (6) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.sort([key[, reverse]])`` | sort the items of *s* in place | (6), (7), (8) |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. *x* can be any iterable object.\n\n3. Raises ``ValueError`` when *x* is not found in *s*. When a negative\n index is passed as the second or third parameter to the ``index()``\n method, the sequence length is added, as for slice indices. If it\n is still negative, it is truncated to zero, as for slice indices.\n\n4. When a negative index is passed as the first parameter to the\n ``insert()`` method, the sequence length is added, as for slice\n indices. If it is still negative, it is truncated to zero, as for\n slice indices.\n\n5. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n6. The ``sort()`` and ``reverse()`` methods modify the sequence in\n place for economy of space when sorting or reversing a large\n sequence. To remind you that they operate by side effect, they\n don\'t return the sorted or reversed sequence.\n\n7. The ``sort()`` method takes optional arguments for controlling the\n comparisons. Each must be specified as a keyword argument.\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: ``key=str.lower``. The\n default value is ``None``. Use ``functools.cmp_to_key()`` to\n convert an old-style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n The ``sort()`` method is guaranteed to be stable. A sort is stable\n if it guarantees not to change the relative order of elements that\n compare equal --- this is helpful for sorting in multiple passes\n (for example, sort by department, then by salary grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can detect\n that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n', + 'typesseq': '\nSequence Types --- ``list``, ``tuple``, ``range``\n*************************************************\n\nThere are three basic sequence types: lists, tuples, and range\nobjects. Additional sequence types tailored for processing of *binary\ndata* and *text strings* are described in dedicated sections.\n\n\nCommon Sequence Operations\n==========================\n\nThe operations in the following table are supported by most sequence\ntypes, both mutable and immutable. The ``collections.abc.Sequence``\nABC is provided to make it easier to correctly implement these\noperations on custom sequence types.\n\nThis table lists the sequence operations sorted in ascending priority\n(operations in the same box have the same priority). In the table,\n*s* and *t* are sequences of the same type, *n*, *i*, *j* and *k* are\nintegers and *x* is an arbitrary object that meets any type and value\nrestrictions imposed by *s*.\n\nThe ``in`` and ``not in`` operations have the same priorities as the\ncomparison operations. The ``+`` (concatenation) and ``*``\n(repetition) operations have the same priority as the corresponding\nnumeric operations.\n\n+----------------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+============================+==================================+============+\n| ``x in s`` | ``True`` if an item of *s* is | (1) |\n| | equal to *x*, else ``False`` | |\n+----------------------------+----------------------------------+------------+\n| ``x not in s`` | ``False`` if an item of *s* is | (1) |\n| | equal to *x*, else ``True`` | |\n+----------------------------+----------------------------------+------------+\n| ``s + t`` | the concatenation of *s* and *t* | (6)(7) |\n+----------------------------+----------------------------------+------------+\n| ``s * n`` or ``n * s`` | *n* shallow copies of *s* | (2)(7) |\n| | concatenated | |\n+----------------------------+----------------------------------+------------+\n| ``s[i]`` | *i*th item of *s*, origin 0 | (3) |\n+----------------------------+----------------------------------+------------+\n| ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) |\n+----------------------------+----------------------------------+------------+\n| ``s[i:j:k]`` | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+----------------------------+----------------------------------+------------+\n| ``len(s)`` | length of *s* | |\n+----------------------------+----------------------------------+------------+\n| ``min(s)`` | smallest item of *s* | |\n+----------------------------+----------------------------------+------------+\n| ``max(s)`` | largest item of *s* | |\n+----------------------------+----------------------------------+------------+\n| ``s.index(x[, i[, j]])`` | index of the first occurence of | (8) |\n| | *x* in *s* (at or after index | |\n| | *i* and before index *j*) | |\n+----------------------------+----------------------------------+------------+\n| ``s.count(x)`` | total number of occurences of | |\n| | *x* in *s* | |\n+----------------------------+----------------------------------+------------+\n\nSequences of the same type also support comparisons. In particular,\ntuples and lists are compared lexicographically by comparing\ncorresponding elements. This means that to compare equal, every\nelement must compare equal and the two sequences must be of the same\ntype and have the same length. (For full details see *Comparisons* in\nthe language reference.)\n\nNotes:\n\n1. While the ``in`` and ``not in`` operations are used only for simple\n containment testing in the general case, some specialised sequences\n (such as ``str``, ``bytes`` and ``bytearray``) also use them for\n subsequence testing:\n\n >>> "gg" in "eggs"\n True\n\n2. Values of *n* less than ``0`` are treated as ``0`` (which yields an\n empty sequence of the same type as *s*). Note also that the copies\n are shallow; nested structures are not copied. This often haunts\n new Python programmers; consider:\n\n >>> lists = [[]] * 3\n >>> lists\n [[], [], []]\n >>> lists[0].append(3)\n >>> lists\n [[3], [3], [3]]\n\n What has happened is that ``[[]]`` is a one-element list containing\n an empty list, so all three elements of ``[[]] * 3`` are (pointers\n to) this single empty list. Modifying any of the elements of\n ``lists`` modifies this single list. You can create a list of\n different lists this way:\n\n >>> lists = [[] for i in range(3)]\n >>> lists[0].append(3)\n >>> lists[1].append(5)\n >>> lists[2].append(7)\n >>> lists\n [[3], [5], [7]]\n\n3. If *i* or *j* is negative, the index is relative to the end of the\n string: ``len(s) + i`` or ``len(s) + j`` is substituted. But note\n that ``-0`` is still ``0``.\n\n4. The slice of *s* from *i* to *j* is defined as the sequence of\n items with index *k* such that ``i <= k < j``. If *i* or *j* is\n greater than ``len(s)``, use ``len(s)``. If *i* is omitted or\n ``None``, use ``0``. If *j* is omitted or ``None``, use\n ``len(s)``. If *i* is greater than or equal to *j*, the slice is\n empty.\n\n5. The slice of *s* from *i* to *j* with step *k* is defined as the\n sequence of items with index ``x = i + n*k`` such that ``0 <= n <\n (j-i)/k``. In other words, the indices are ``i``, ``i+k``,\n ``i+2*k``, ``i+3*k`` and so on, stopping when *j* is reached (but\n never including *j*). If *i* or *j* is greater than ``len(s)``,\n use ``len(s)``. If *i* or *j* are omitted or ``None``, they become\n "end" values (which end depends on the sign of *k*). Note, *k*\n cannot be zero. If *k* is ``None``, it is treated like ``1``.\n\n6. Concatenating immutable sequences always results in a new object.\n This means that building up a sequence by repeated concatenation\n will have a quadratic runtime cost in the total sequence length.\n To get a linear runtime cost, you must switch to one of the\n alternatives below:\n\n * if concatenating ``str`` objects, you can build a list and use\n ``str.join()`` at the end or else write to a ``io.StringIO``\n instance and retrieve its value when complete\n\n * if concatenating ``bytes`` objects, you can similarly use\n ``bytes.join()`` or ``io.BytesIO``, or you can do in-place\n concatenation with a ``bytearray`` object. ``bytearray`` objects\n are mutable and have an efficient overallocation mechanism\n\n * if concatenating ``tuple`` objects, extend a ``list`` instead\n\n * for other types, investigate the relevant class documentation\n\n7. Some sequence types (such as ``range``) only support item sequences\n that follow specific patterns, and hence don\'t support sequence\n concatenation or repetition.\n\n8. ``index`` raises ``ValueError`` when *x* is not found in *s*. When\n supported, the additional arguments to the index method allow\n efficient searching of subsections of the sequence. Passing the\n extra arguments is roughly equivalent to using ``s[i:j].index(x)``,\n only without copying any data and with the returned index being\n relative to the start of the sequence rather than the start of the\n slice.\n\n\nImmutable Sequence Types\n========================\n\nThe only operation that immutable sequence types generally implement\nthat is not also implemented by mutable sequence types is support for\nthe ``hash()`` built-in.\n\nThis support allows immutable sequences, such as ``tuple`` instances,\nto be used as ``dict`` keys and stored in ``set`` and ``frozenset``\ninstances.\n\nAttempting to hash an immutable sequence that contains unhashable\nvalues will result in ``TypeError``.\n\n\nMutable Sequence Types\n======================\n\nThe operations in the following table are defined on mutable sequence\ntypes. The ``collections.abc.MutableSequence`` ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, ``bytearray`` only\naccepts integers that meet the value restriction ``0 <= x <= 255``).\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | appends *x* to the end of the | |\n| | sequence (same as | |\n| | ``s[len(s):len(s)] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | removes all items from ``s`` | (5) |\n| | (same as ``del s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | creates a shallow copy of ``s`` | (5) |\n| | (same as ``s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(t)`` | extends *s* with the contents of | |\n| | *t* (same as ``s[len(s):len(s)] | |\n| | = t``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | ``s[i:i] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | remove the first item from *s* | (3) |\n| | where ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n3. ``remove`` raises ``ValueError`` when *x* is not found in *s*.\n\n4. The ``reverse()`` method modifies the sequence in place for economy\n of space when reversing a large sequence. To remind users that it\n operates by side effect, it does not return the reversed sequence.\n\n5. ``clear()`` and ``copy()`` are included for consistency with the\n interfaces of mutable containers that don\'t support slicing\n operations (such as ``dict`` and ``set``)\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n\n\nLists\n=====\n\nLists are mutable sequences, typically used to store collections of\nhomogeneous items (where the precise degree of similarity will vary by\napplication).\n\nclass class list([iterable])\n\n Lists may be constructed in several ways:\n\n * Using a pair of square brackets to denote the empty list: ``[]``\n\n * Using square brackets, separating items with commas: ``[a]``,\n ``[a, b, c]``\n\n * Using a list comprehension: ``[x for x in iterable]``\n\n * Using the type constructor: ``list()`` or ``list(iterable)``\n\n The constructor builds a list whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a list, a copy is made and\n returned, similar to ``iterable[:]``. For example, ``list(\'abc\')``\n returns ``[\'a\', \'b\', \'c\']`` and ``list( (1, 2, 3) )`` returns ``[1,\n 2, 3]``. If no argument is given, the constructor creates a new\n empty list, ``[]``.\n\n Many other operations also produce lists, including the\n ``sorted()`` built-in.\n\n Lists implement all of the *common* and *mutable* sequence\n operations. Lists also provide the following additional method:\n\n sort(*, key=None, reverse=None)\n\n This method sorts the list in place, using only ``<``\n comparisons between items. Exceptions are not suppressed - if\n any comparison operations fail, the entire sort operation will\n fail (and the list will likely be left in a partially modified\n state).\n\n *key* specifies a function of one argument that is used to\n extract a comparison key from each list element (for example,\n ``key=str.lower``). The key corresponding to each item in the\n list is calculated once and then used for the entire sorting\n process. The default value of ``None`` means that list items are\n sorted directly without calculating a separate key value.\n\n The ``functools.cmp_to_key()`` utility is available to convert a\n 2.x style *cmp* function to a *key* function.\n\n *reverse* is a boolean value. If set to ``True``, then the list\n elements are sorted as if each comparison were reversed.\n\n This method modifies the sequence in place for economy of space\n when sorting a large sequence. To remind users that it operates\n by side effect, it does not return the sorted sequence (use\n ``sorted()`` to explicitly request a new sorted list instance).\n\n The ``sort()`` method is guaranteed to be stable. A sort is\n stable if it guarantees not to change the relative order of\n elements that compare equal --- this is helpful for sorting in\n multiple passes (for example, sort by department, then by salary\n grade).\n\n **CPython implementation detail:** While a list is being sorted,\n the effect of attempting to mutate, or even inspect, the list is\n undefined. The C implementation of Python makes the list appear\n empty for the duration, and raises ``ValueError`` if it can\n detect that the list has been mutated during a sort.\n\n\nTuples\n======\n\nTuples are immutable sequences, typically used to store collections of\nheterogeneous data (such as the 2-tuples produced by the\n``enumerate()`` built-in). Tuples are also used for cases where an\nimmutable sequence of homogeneous data is needed (such as allowing\nstorage in a ``set`` or ``dict`` instance).\n\nclass class tuple([iterable])\n\n Tuples may be constructed in a number of ways:\n\n * Using a pair of parentheses to denote the empty tuple: ``()``\n\n * Using a trailing comma for a singleton tuple: ``a,`` or ``(a,)``\n\n * Separating items with commas: ``a, b, c`` or ``(a, b, c)``\n\n * Using the ``tuple()`` built-in: ``tuple()`` or\n ``tuple(iterable)``\n\n The constructor builds a tuple whose items are the same and in the\n same order as *iterable*\'s items. *iterable* may be either a\n sequence, a container that supports iteration, or an iterator\n object. If *iterable* is already a tuple, it is returned\n unchanged. For example, ``tuple(\'abc\')`` returns ``(\'a\', \'b\',\n \'c\')`` and ``tuple( [1, 2, 3] )`` returns ``(1, 2, 3)``. If no\n argument is given, the constructor creates a new empty tuple,\n ``()``.\n\n Note that it is actually the comma which makes a tuple, not the\n parentheses. The parentheses are optional, except in the empty\n tuple case, or when they are needed to avoid syntactic ambiguity.\n For example, ``f(a, b, c)`` is a function call with three\n arguments, while ``f((a, b, c))`` is a function call with a 3-tuple\n as the sole argument.\n\n Tuples implement all of the *common* sequence operations.\n\nFor heterogeneous collections of data where access by name is clearer\nthan access by index, ``collections.namedtuple()`` may be a more\nappropriate choice than a simple tuple object.\n\n\nRanges\n======\n\nThe ``range`` type represents an immutable sequence of numbers and is\ncommonly used for looping a specific number of times in ``for`` loops.\n\nclass class range([start], stop[, step])\n\n The arguments to the range constructor must be integers (either\n built-in ``int`` or any object that implements the ``__index__``\n special method). If the *step* argument is omitted, it defaults to\n ``1``. If the *start* argument is omitted, it defaults to ``0``. If\n *step* is zero, ``ValueError`` is raised.\n\n For a positive *step*, the contents of a range ``r`` are determined\n by the formula ``r[i] = start + step*i`` where ``i >= 0`` and\n ``r[i] < stop``.\n\n For a negative *step*, the contents of the range are still\n determined by the formula ``r[i] = start + step*i``, but the\n constraints are ``i >= 0`` and ``r[i] > stop``.\n\n A range object will be empty if ``r[0]`` does not meant the value\n constraint. Ranges do support negative indices, but these are\n interpreted as indexing from the end of the sequence determined by\n the positive indices.\n\n Ranges containing absolute values larger than ``sys.maxsize`` are\n permitted but some features (such as ``len()``) may raise\n ``OverflowError``.\n\n Range examples:\n\n >>> list(range(10))\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n >>> list(range(1, 11))\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n >>> list(range(0, 30, 5))\n [0, 5, 10, 15, 20, 25]\n >>> list(range(0, 10, 3))\n [0, 3, 6, 9]\n >>> list(range(0, -10, -1))\n [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n >>> list(range(0))\n []\n >>> list(range(1, 0))\n []\n\n Ranges implement all of the *common* sequence operations except\n concatenation and repetition (due to the fact that range objects\n can only represent sequences that follow a strict pattern and\n repetition and concatenation will usually violate that pattern).\n\nThe advantage of the ``range`` type over a regular ``list`` or\n``tuple`` is that a ``range`` object will always take the same (small)\namount of memory, no matter the size of the range it represents (as it\nonly stores the ``start``, ``stop`` and ``step`` values, calculating\nindividual items and subranges as needed).\n\nRange objects implement the ``collections.Sequence`` ABC, and provide\nfeatures such as containment tests, element index lookup, slicing and\nsupport for negative indices (see *Sequence Types --- list, tuple,\nrange*):\n\n>>> r = range(0, 20, 2)\n>>> r\nrange(0, 20, 2)\n>>> 11 in r\nFalse\n>>> 10 in r\nTrue\n>>> r.index(10)\n5\n>>> r[5]\n10\n>>> r[:5]\nrange(0, 10, 2)\n>>> r[-1]\n18\n\nTesting range objects for equality with ``==`` and ``!=`` compares\nthem as sequences. That is, two range objects are considered equal if\nthey represent the same sequence of values. (Note that two range\nobjects that compare equal might have different ``start``, ``stop``\nand ``step`` attributes, for example ``range(0) == range(2, 1, 3)`` or\n``range(0, 3, 2) == range(0, 4, 2)``.)\n\nChanged in version 3.2: Implement the Sequence ABC. Support slicing\nand negative indices. Test ``int`` objects for membership in constant\ntime instead of iterating through all items.\n\nChanged in version 3.3: Define \'==\' and \'!=\' to compare range objects\nbased on the sequence of values they define (instead of comparing\nbased on object identity).\n\nNew in version 3.3: The ``start``, ``stop`` and ``step`` attributes.\n', + 'typesseq-mutable': "\nMutable Sequence Types\n**********************\n\nThe operations in the following table are defined on mutable sequence\ntypes. The ``collections.abc.MutableSequence`` ABC is provided to make\nit easier to correctly implement these operations on custom sequence\ntypes.\n\nIn the table *s* is an instance of a mutable sequence type, *t* is any\niterable object and *x* is an arbitrary object that meets any type and\nvalue restrictions imposed by *s* (for example, ``bytearray`` only\naccepts integers that meet the value restriction ``0 <= x <= 255``).\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | appends *x* to the end of the | |\n| | sequence (same as | |\n| | ``s[len(s):len(s)] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.clear()`` | removes all items from ``s`` | (5) |\n| | (same as ``del s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.copy()`` | creates a shallow copy of ``s`` | (5) |\n| | (same as ``s[:]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(t)`` | extends *s* with the contents of | |\n| | *t* (same as ``s[len(s):len(s)] | |\n| | = t``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.insert(i, x)`` | inserts *x* into *s* at the | |\n| | index given by *i* (same as | |\n| | ``s[i:i] = [x]``) | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.pop([i])`` | retrieves the item at *i* and | (2) |\n| | also removes it from *s* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.remove(x)`` | remove the first item from *s* | (3) |\n| | where ``s[i] == x`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.reverse()`` | reverses the items of *s* in | (4) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The optional argument *i* defaults to ``-1``, so that by default\n the last item is removed and returned.\n\n3. ``remove`` raises ``ValueError`` when *x* is not found in *s*.\n\n4. The ``reverse()`` method modifies the sequence in place for economy\n of space when reversing a large sequence. To remind users that it\n operates by side effect, it does not return the reversed sequence.\n\n5. ``clear()`` and ``copy()`` are included for consistency with the\n interfaces of mutable containers that don't support slicing\n operations (such as ``dict`` and ``set``)\n\n New in version 3.3: ``clear()`` and ``copy()`` methods.\n", 'unary': '\nUnary arithmetic and bitwise operations\n***************************************\n\nAll unary arithmetic and bitwise operations have the same priority:\n\n u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n\nThe unary ``-`` (minus) operator yields the negation of its numeric\nargument.\n\nThe unary ``+`` (plus) operator yields its numeric argument unchanged.\n\nThe unary ``~`` (invert) operator yields the bitwise inversion of its\ninteger argument. The bitwise inversion of ``x`` is defined as\n``-(x+1)``. It only applies to integral numbers.\n\nIn all three cases, if the argument does not have the proper type, a\n``TypeError`` exception is raised.\n', 'while': '\nThe ``while`` statement\n***********************\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n', 'with': '\nThe ``with`` statement\n**********************\n\nThe ``with`` statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section *With Statement\nContext Managers*). This allows common\n``try``...``except``...``finally`` usage patterns to be encapsulated\nfor convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the ``with`` statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the ``with_item``)\n is evaluated to obtain a context manager.\n\n2. The context manager\'s ``__exit__()`` is loaded for later use.\n\n3. The context manager\'s ``__enter__()`` method is invoked.\n\n4. If a target was included in the ``with`` statement, the return\n value from ``__enter__()`` is assigned to it.\n\n Note: The ``with`` statement guarantees that if the ``__enter__()``\n method returns without an error, then ``__exit__()`` will always\n be called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s ``__exit__()`` method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to ``__exit__()``. Otherwise,\n three ``None`` arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the ``__exit__()`` method was false, the exception is\n reraised. If the return value was true, the exception is\n suppressed, and execution continues with the statement following\n the ``with`` statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from ``__exit__()`` is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple ``with`` statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nChanged in version 3.1: Support for multiple context expressions.\n\nSee also:\n\n **PEP 0343** - The "with" statement\n The specification, background, and examples for the Python\n ``with`` statement.\n', diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2,10 +2,22 @@ Python News +++++++++++ +What's New in Python 3.3.0 Release Candidate 2? +=============================================== + +*Release date: XX-Sep-2012* + +Core and Builtins +----------------- + +Library +------- + + What's New in Python 3.3.0 Release Candidate 1? =============================================== -*Release date: XX-Aug-2012* +*Release date: 25-Aug-2012* Core and Builtins ----------------- diff --git a/Misc/RPM/python-3.3.spec b/Misc/RPM/python-3.3.spec --- a/Misc/RPM/python-3.3.spec +++ b/Misc/RPM/python-3.3.spec @@ -39,7 +39,7 @@ %define name python #--start constants-- -%define version 3.3.0b2 +%define version 3.3.0rc1 %define libvers 3.3 #--end constants-- %define release 1pydotorg diff --git a/README b/README --- a/README +++ b/README @@ -1,5 +1,5 @@ -This is Python version 3.3.0 beta 2 -=================================== +This is Python version 3.3.0 release candidate 1 +================================================ Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Python Software Foundation. All rights reserved. -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Sun Aug 26 06:11:48 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Sun, 26 Aug 2012 06:11:48 +0200 Subject: [Python-checkins] Daily reference leaks (aa0e6eab6136): sum=2 Message-ID: results for aa0e6eab6136 on branch "default" -------------------------------------------- test_dbm leaked [0, 2, 0] references, sum=2 Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogmFScmA', '-x'] From python-checkins at python.org Sun Aug 26 06:33:35 2012 From: python-checkins at python.org (ezio.melotti) Date: Sun, 26 Aug 2012 06:33:35 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Fix_typo=2E?= Message-ID: <3X4Ndq6W2mzQWZ@mail.python.org> http://hg.python.org/cpython/rev/5b0595339c9d changeset: 78773:5b0595339c9d user: Ezio Melotti date: Sun Aug 26 07:33:10 2012 +0300 summary: Fix typo. files: Doc/library/types.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/types.rst b/Doc/library/types.rst --- a/Doc/library/types.rst +++ b/Doc/library/types.rst @@ -69,7 +69,7 @@ the types that arise only incidentally during processing such as the ``listiterator`` type. -Typical use is of these names is for :func:`isinstance` or +Typical use of these names is for :func:`isinstance` or :func:`issubclass` checks. Standard names are defined for the following types: -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Mon Aug 27 06:11:01 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Mon, 27 Aug 2012 06:11:01 +0200 Subject: [Python-checkins] Daily reference leaks (5b0595339c9d): sum=0 Message-ID: results for 5b0595339c9d on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogW9OOhY', '-x'] From python-checkins at python.org Mon Aug 27 09:07:00 2012 From: python-checkins at python.org (ezio.melotti) Date: Mon, 27 Aug 2012 09:07:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE1Nzg4OiBmaXgg?= =?utf-8?q?broken_links_in_subprocess_doc=2E__Patch_by_Chris_Rebert=2E?= Message-ID: <3X540N5NRDzQCQ@mail.python.org> http://hg.python.org/cpython/rev/92aa438a5c4b changeset: 78774:92aa438a5c4b branch: 2.7 parent: 78764:58a87c02692c user: Ezio Melotti date: Mon Aug 27 10:00:05 2012 +0300 summary: #15788: fix broken links in subprocess doc. Patch by Chris Rebert. files: Doc/library/subprocess.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -513,8 +513,8 @@ .. warning:: - Use :meth:`communicate` rather than :attr:`.stdin.write `, - :attr:`.stdout.read ` or :attr:`.stderr.read ` to avoid + Use :meth:`~Popen.communicate` rather than :attr:`.stdin.write `, + :attr:`.stdout.read ` or :attr:`.stderr.read ` to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 27 09:07:02 2012 From: python-checkins at python.org (ezio.melotti) Date: Mon, 27 Aug 2012 09:07:02 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzE1Nzg4OiBmaXgg?= =?utf-8?q?broken_links_in_subprocess_doc=2E__Patch_by_Chris_Rebert=2E?= Message-ID: <3X540Q3Y29zQ49@mail.python.org> http://hg.python.org/cpython/rev/1676e423054a changeset: 78775:1676e423054a branch: 3.2 parent: 78765:a425f2697273 user: Ezio Melotti date: Mon Aug 27 10:00:05 2012 +0300 summary: #15788: fix broken links in subprocess doc. Patch by Chris Rebert. files: Doc/library/subprocess.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -565,8 +565,8 @@ .. warning:: - Use :meth:`communicate` rather than :attr:`.stdin.write `, - :attr:`.stdout.read ` or :attr:`.stderr.read ` to avoid + Use :meth:`~Popen.communicate` rather than :attr:`.stdin.write `, + :attr:`.stdout.read ` or :attr:`.stderr.read ` to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 27 09:07:03 2012 From: python-checkins at python.org (ezio.melotti) Date: Mon, 27 Aug 2012 09:07:03 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogIzE1Nzg4OiBtZXJnZSB3aXRoIDMuMi4=?= Message-ID: <3X540R6PrYzQDl@mail.python.org> http://hg.python.org/cpython/rev/64640a02b0ca changeset: 78776:64640a02b0ca parent: 78773:5b0595339c9d parent: 78775:1676e423054a user: Ezio Melotti date: Mon Aug 27 10:03:23 2012 +0300 summary: #15788: merge with 3.2. files: Doc/library/subprocess.rst | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -669,8 +669,8 @@ .. warning:: - Use :meth:`communicate` rather than :attr:`.stdin.write `, - :attr:`.stdout.read ` or :attr:`.stderr.read ` to avoid + Use :meth:`~Popen.communicate` rather than :attr:`.stdin.write `, + :attr:`.stdout.read ` or :attr:`.stderr.read ` to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 27 19:33:59 2012 From: python-checkins at python.org (petri.lehtinen) Date: Mon, 27 Aug 2012 19:33:59 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Fix_a_JSON_doc?= =?utf-8?q?_typo?= Message-ID: <3X5Kvq5qrxzQ4s@mail.python.org> http://hg.python.org/cpython/rev/3e50d6dada09 changeset: 78777:3e50d6dada09 branch: 3.2 parent: 78775:1676e423054a user: Petri Lehtinen date: Mon Aug 27 20:27:30 2012 +0300 summary: Fix a JSON doc typo files: Doc/library/json.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -146,7 +146,7 @@ object members will be pretty-printed with that indent level. An indent level of 0, negative, or ``""`` will only insert newlines. ``None`` (the default) selects the most compact representation. Using a positive integer indent - indents that many spaces per level. If *indent* is a string (such at '\t'), + indents that many spaces per level. If *indent* is a string (such as ``"\t"``), that string is used to indent each level. If *separators* is an ``(item_separator, dict_separator)`` tuple, then it -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Mon Aug 27 19:34:01 2012 From: python-checkins at python.org (petri.lehtinen) Date: Mon, 27 Aug 2012 19:34:01 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge=3A_Fix_a_JSON_doc_typo?= Message-ID: <3X5Kvs42SbzQ5f@mail.python.org> http://hg.python.org/cpython/rev/52159aa5d401 changeset: 78778:52159aa5d401 parent: 78776:64640a02b0ca parent: 78777:3e50d6dada09 user: Petri Lehtinen date: Mon Aug 27 20:27:51 2012 +0300 summary: Merge: Fix a JSON doc typo files: Doc/library/json.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -146,7 +146,7 @@ object members will be pretty-printed with that indent level. An indent level of 0, negative, or ``""`` will only insert newlines. ``None`` (the default) selects the most compact representation. Using a positive integer indent - indents that many spaces per level. If *indent* is a string (such at '\t'), + indents that many spaces per level. If *indent* is a string (such as ``"\t"``), that string is used to indent each level. If *separators* is an ``(item_separator, dict_separator)`` tuple, then it -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 00:29:39 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 28 Aug 2012 00:29:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315781=3A_Fix_two_?= =?utf-8?q?small_race_conditions_in_import=27s_module_locking=2E?= Message-ID: <3X5SSz5KbZzQ55@mail.python.org> http://hg.python.org/cpython/rev/7fa6336e9864 changeset: 78779:7fa6336e9864 user: Antoine Pitrou date: Tue Aug 28 00:24:52 2012 +0200 summary: Issue #15781: Fix two small race conditions in import's module locking. files: Lib/importlib/_bootstrap.py | 10 +- Lib/test/test_threaded_import.py | 12 +- Misc/NEWS | 2 + Python/import.c | 6 +- Python/importlib.h | 7302 +++++++++-------- 5 files changed, 3678 insertions(+), 3654 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -268,8 +268,10 @@ Should only be called with the import lock taken.""" lock = None - if name in _module_locks: + try: lock = _module_locks[name]() + except KeyError: + pass if lock is None: if _thread is None: lock = _DummyModuleLock(name) @@ -543,6 +545,9 @@ # implicitly imports 'locale' and would otherwise trigger an # infinite loop. module = new_module(fullname) + # This must be done before putting the module in sys.modules + # (otherwise an optimization shortcut in import.c becomes wrong) + module.__initializing__ = True sys.modules[fullname] = module module.__loader__ = self try: @@ -554,8 +559,9 @@ module.__package__ = fullname else: module.__package__ = fullname.rpartition('.')[0] + else: + module.__initializing__ = True try: - module.__initializing__ = True # If __package__ was not set above, __import__() will do it later. return fxn(self, module, *args, **kwargs) except: 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 @@ -224,7 +224,17 @@ @reap_threads def test_main(): - run_unittest(ThreadedImportTests) + old_switchinterval = None + try: + old_switchinterval = sys.getswitchinterval() + sys.setswitchinterval(0.00000001) + except AttributeError: + pass + try: + run_unittest(ThreadedImportTests) + finally: + if old_switchinterval is not None: + sys.setswitchinterval(old_switchinterval) if __name__ == "__main__": test_main() diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #15781: Fix two small race conditions in import's module locking. + Library ------- diff --git a/Python/import.c b/Python/import.c --- a/Python/import.c +++ b/Python/import.c @@ -1408,7 +1408,11 @@ int initializing = 0; Py_INCREF(mod); - /* Only call _bootstrap._lock_unlock_module() if __initializing__ is true. */ + /* Optimization: only call _bootstrap._lock_unlock_module() if + __initializing__ is true. + NOTE: because of this, __initializing__ must be set *before* + stuffing the new module in sys.modules. + */ value = _PyObject_GetAttrId(mod, &PyId___initializing__); if (value == NULL) PyErr_Clear(); 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 solipsis at pitrou.net Tue Aug 28 06:10:50 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Tue, 28 Aug 2012 06:10:50 +0200 Subject: [Python-checkins] Daily reference leaks (7fa6336e9864): sum=0 Message-ID: results for 7fa6336e9864 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflognwJ4KS', '-x'] From python-checkins at python.org Tue Aug 28 11:36:43 2012 From: python-checkins at python.org (petri.lehtinen) Date: Tue, 28 Aug 2012 11:36:43 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogIzExOTY0OiBEb2N1?= =?utf-8?q?ment_a_change_in_v3=2E2_to_the_json_indent_parameter?= Message-ID: <3X5lGg2vnPzPx2@mail.python.org> http://hg.python.org/cpython/rev/5bff555168ab changeset: 78780:5bff555168ab branch: 3.2 parent: 78777:3e50d6dada09 user: Petri Lehtinen date: Tue Aug 28 07:08:44 2012 +0300 summary: #11964: Document a change in v3.2 to the json indent parameter files: Doc/library/json.rst | 16 ++++++++++++---- Misc/NEWS | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -149,6 +149,9 @@ indents that many spaces per level. If *indent* is a string (such as ``"\t"``), that string is used to indent each level. + .. versionchanged:: 3.2 + Allow strings for *indent* in addition to integers. + If *separators* is an ``(item_separator, dict_separator)`` tuple, then it will be used instead of the default ``(', ', ': ')`` separators. ``(',', ':')`` is the most compact JSON representation. @@ -371,10 +374,15 @@ will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis. - If *indent* is a non-negative integer (it is ``None`` by default), then JSON - array elements and object members will be pretty-printed with that indent - level. An indent level of 0 will only insert newlines. ``None`` is the most - compact representation. + If *indent* is a non-negative integer or string, then JSON array elements and + object members will be pretty-printed with that indent level. An indent level + of 0, negative, or ``""`` will only insert newlines. ``None`` (the default) + selects the most compact representation. Using a positive integer indent + indents that many spaces per level. If *indent* is a string (such as ``"\t"``), + that string is used to indent each level. + + .. versionchanged:: 3.2 + Allow strings for *indent* in addition to integers. If specified, *separators* should be an ``(item_separator, key_separator)`` tuple. The default is ``(', ', ': ')``. To get the most compact JSON diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -519,6 +519,9 @@ Documentation ------------- +- Issue #11964: Document a change in v3.2 to the behavior of the indent + parameter of json encoding operations. + - Issue #14674: Add a discussion of the json module's standard compliance. Patch by Chris Rebert. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 11:36:45 2012 From: python-checkins at python.org (petri.lehtinen) Date: Tue, 28 Aug 2012 11:36:45 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_=2311964=3A_Document_a_change_in_v3=2E2_to_the_json_inde?= =?utf-8?q?nt_parameter?= Message-ID: <3X5lGj0hCWzPxW@mail.python.org> http://hg.python.org/cpython/rev/0fb511659ef4 changeset: 78781:0fb511659ef4 parent: 78779:7fa6336e9864 parent: 78780:5bff555168ab user: Petri Lehtinen date: Tue Aug 28 12:34:09 2012 +0300 summary: #11964: Document a change in v3.2 to the json indent parameter files: Doc/library/json.rst | 16 ++++++++++++---- Misc/NEWS | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Doc/library/json.rst b/Doc/library/json.rst --- a/Doc/library/json.rst +++ b/Doc/library/json.rst @@ -149,6 +149,9 @@ indents that many spaces per level. If *indent* is a string (such as ``"\t"``), that string is used to indent each level. + .. versionchanged:: 3.2 + Allow strings for *indent* in addition to integers. + If *separators* is an ``(item_separator, dict_separator)`` tuple, then it will be used instead of the default ``(', ', ': ')`` separators. ``(',', ':')`` is the most compact JSON representation. @@ -371,10 +374,15 @@ will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis. - If *indent* is a non-negative integer (it is ``None`` by default), then JSON - array elements and object members will be pretty-printed with that indent - level. An indent level of 0 will only insert newlines. ``None`` is the most - compact representation. + If *indent* is a non-negative integer or string, then JSON array elements and + object members will be pretty-printed with that indent level. An indent level + of 0, negative, or ``""`` will only insert newlines. ``None`` (the default) + selects the most compact representation. Using a positive integer indent + indents that many spaces per level. If *indent* is a string (such as ``"\t"``), + that string is used to indent each level. + + .. versionchanged:: 3.2 + Allow strings for *indent* in addition to integers. If specified, *separators* should be an ``(item_separator, key_separator)`` tuple. The default is ``(', ', ': ')``. To get the most compact JSON diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -2,6 +2,36 @@ Python News +++++++++++ +What's New in Python 3.3.1 +========================== + +*Release date: XX-XX-XXXX* + +Core and Builtins +----------------- + +Library +------- + +Extension Modules +----------------- + +Tests +----- + +Build +----- + +Documentation +------------- + +- Issue #11964: Document a change in v3.2 to the behavior of the indent + parameter of json encoding operations. + +Tools/Demos +----------- + + What's New in Python 3.3.0 Release Candidate 2? =============================================== -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 12:35:29 2012 From: python-checkins at python.org (hynek.schlawack) Date: Tue, 28 Aug 2012 12:35:29 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogIzE0ODgwOiBGaXgg?= =?utf-8?q?kwargs_notation_in_csv=2Ereader=2C_=2Ewriter_=26_=2Eregister=5F?= =?utf-8?q?dialect?= Message-ID: <3X5mZT4bF8zQ1H@mail.python.org> http://hg.python.org/cpython/rev/dc080e19f7aa changeset: 78782:dc080e19f7aa branch: 2.7 parent: 78774:92aa438a5c4b user: Hynek Schlawack date: Tue Aug 28 12:33:46 2012 +0200 summary: #14880: Fix kwargs notation in csv.reader, .writer & .register_dialect Patch by Chris Rebert. files: Doc/library/csv.rst | 12 ++++++------ Misc/NEWS | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -57,7 +57,7 @@ The :mod:`csv` module defines the following functions: -.. function:: reader(csvfile[, dialect='excel'][, fmtparam]) +.. function:: reader(csvfile, dialect='excel', **fmtparams) Return a reader object which will iterate over lines in the given *csvfile*. *csvfile* can be any object which supports the :term:`iterator` protocol and returns a @@ -67,7 +67,7 @@ *dialect* parameter can be given which is used to define a set of parameters specific to a particular CSV dialect. It may be an instance of a subclass of the :class:`Dialect` class or one of the strings returned by the - :func:`list_dialects` function. The other optional *fmtparam* keyword arguments + :func:`list_dialects` function. The other optional *fmtparams* keyword arguments can be given to override individual formatting parameters in the current dialect. For full details about the dialect and formatting parameters, see section :ref:`csv-fmt-params`. @@ -94,7 +94,7 @@ be split into lines in a manner which preserves the newline characters. -.. function:: writer(csvfile[, dialect='excel'][, fmtparam]) +.. function:: writer(csvfile, dialect='excel', **fmtparams) Return a writer object responsible for converting the user's data into delimited strings on the given file-like object. *csvfile* can be any object with a @@ -103,7 +103,7 @@ parameter can be given which is used to define a set of parameters specific to a particular CSV dialect. It may be an instance of a subclass of the :class:`Dialect` class or one of the strings returned by the - :func:`list_dialects` function. The other optional *fmtparam* keyword arguments + :func:`list_dialects` function. The other optional *fmtparams* keyword arguments can be given to override individual formatting parameters in the current dialect. For full details about the dialect and formatting parameters, see section :ref:`csv-fmt-params`. To make it @@ -122,11 +122,11 @@ >>> spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam']) -.. function:: register_dialect(name[, dialect][, fmtparam]) +.. function:: register_dialect(name[, dialect], **fmtparams) Associate *dialect* with *name*. *name* must be a string or Unicode object. The dialect can be specified either by passing a sub-class of :class:`Dialect`, or - by *fmtparam* keyword arguments, or both, with keyword arguments overriding + by *fmtparams* keyword arguments, or both, with keyword arguments overriding parameters of the dialect. For full details about the dialect and formatting parameters, see section :ref:`csv-fmt-params`. diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -378,6 +378,9 @@ Documentation ------------- +- Issue #14880: Fix kwargs notation in csv.reader, .writer & .register_dialect. + Patch by Chris Rebert. + - Issue #14674: Add a discussion of the json module's standard compliance. Patch by Chris Rebert. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 19:03:05 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 28 Aug 2012 19:03:05 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogLSBJc3N1ZSAjMTU1?= =?utf-8?q?91=3A_Fix_parsing_MAKEFLAGS_in_the_sharedmods_target=2E?= Message-ID: <3X5x9j47d0zPvw@mail.python.org> http://hg.python.org/cpython/rev/1a1d097b17e2 changeset: 78783:1a1d097b17e2 branch: 2.7 user: Matthias Klose date: Tue Aug 28 18:52:28 2012 +0200 summary: - Issue #15591: Fix parsing MAKEFLAGS in the sharedmods target. files: Makefile.pre.in | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -407,10 +407,14 @@ # Build the shared modules sharedmods: $(BUILDPYTHON) - @case $$MAKEFLAGS in \ - *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \ - *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ - esac + if which getopt >/dev/null 2>&1; then \ + mflags=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ + else \ + mflags=" $$MAKEFLAGS "; \ + fi; \ + case $$mflags in "* -s *") quiet=-q; esac; \ + $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ + ./$(BUILDPYTHON) -E $(srcdir)/setup.py $$quiet build # Build static library # avoid long command lines, same as LIBRARY_OBJS -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 19:03:07 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 28 Aug 2012 19:03:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogLSBJc3N1ZSAjMTU1?= =?utf-8?q?91=3A_Fix_parsing_MAKEFLAGS_in_the_sharedmods_target=2E?= Message-ID: <3X5x9l1xvMzPyW@mail.python.org> http://hg.python.org/cpython/rev/763d188a96bb changeset: 78784:763d188a96bb branch: 3.2 parent: 78780:5bff555168ab user: Matthias Klose date: Tue Aug 28 18:55:07 2012 +0200 summary: - Issue #15591: Fix parsing MAKEFLAGS in the sharedmods target. files: Makefile.pre.in | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -436,10 +436,14 @@ # Build the shared modules sharedmods: $(BUILDPYTHON) - @case $$MAKEFLAGS in \ - *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \ - *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ - esac + if which getopt >/dev/null; then \ + mflags=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ + else \ + mflags=" $$MAKEFLAGS "; \ + fi; \ + case $$mflags in "* -s *") quiet=-q; esac; \ + $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ + ./$(BUILDPYTHON) -E $(srcdir)/setup.py $$quiet build # Build static library # avoid long command lines, same as LIBRARY_OBJS -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 19:03:08 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 28 Aug 2012 19:03:08 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_-_Issue_=2315591=3A_Fix_parsing_MAKEFLAGS_in_the_sharedm?= =?utf-8?q?ods_target=2E?= Message-ID: <3X5x9m5QmHzQ38@mail.python.org> http://hg.python.org/cpython/rev/3a3fd48a6ef7 changeset: 78785:3a3fd48a6ef7 parent: 78781:0fb511659ef4 parent: 78784:763d188a96bb user: Matthias Klose date: Tue Aug 28 19:00:01 2012 +0200 summary: - Issue #15591: Fix parsing MAKEFLAGS in the sharedmods target. files: Makefile.pre.in | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -475,7 +475,12 @@ # Build the shared modules sharedmods: $(BUILDPYTHON) $(SYSCONFIGDATA) - case $$MAKEFLAGS in *s*) quiet=-q; esac; \ + if which getopt >/dev/null; then \ + mflags=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ + else \ + mflags=" $$MAKEFLAGS "; \ + fi; \ + case $$mflags in "* -s *") quiet=-q; esac; \ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 19:11:45 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 28 Aug 2012 19:11:45 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_-_fix_paste_er?= =?utf-8?q?ror_=28whitespace=29_from_previous_commit?= Message-ID: <3X5xMj1ZJZzNY5@mail.python.org> http://hg.python.org/cpython/rev/f918d4a06c64 changeset: 78786:f918d4a06c64 branch: 2.7 parent: 78783:1a1d097b17e2 user: Matthias Klose date: Tue Aug 28 19:07:08 2012 +0200 summary: - fix paste error (whitespace) from previous commit files: Makefile.pre.in | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -407,8 +407,8 @@ # Build the shared modules sharedmods: $(BUILDPYTHON) - if which getopt >/dev/null 2>&1; then \ - mflags=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ + if which getopt >/dev/null 2>&1; then \ + s=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ else \ mflags=" $$MAKEFLAGS "; \ fi; \ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 19:11:47 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 28 Aug 2012 19:11:47 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_-_fix_paste_er?= =?utf-8?q?ror_=28whitespace=29_from_previous_commit?= Message-ID: <3X5xMl0XnMzPyr@mail.python.org> http://hg.python.org/cpython/rev/5c13bd7f6256 changeset: 78787:5c13bd7f6256 branch: 3.2 parent: 78784:763d188a96bb user: Matthias Klose date: Tue Aug 28 19:07:38 2012 +0200 summary: - fix paste error (whitespace) from previous commit files: Makefile.pre.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -436,7 +436,7 @@ # Build the shared modules sharedmods: $(BUILDPYTHON) - if which getopt >/dev/null; then \ + if which getopt >/dev/null; then \ mflags=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ else \ mflags=" $$MAKEFLAGS "; \ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 19:11:48 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 28 Aug 2012 19:11:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_-_fix_paste_error_=28whitespace=29_from_previous_commit?= Message-ID: <3X5xMm45WHzQ2s@mail.python.org> http://hg.python.org/cpython/rev/06497bbdf4fe changeset: 78788:06497bbdf4fe parent: 78785:3a3fd48a6ef7 parent: 78787:5c13bd7f6256 user: Matthias Klose date: Tue Aug 28 19:08:42 2012 +0200 summary: - fix paste error (whitespace) from previous commit files: Makefile.pre.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -475,7 +475,7 @@ # Build the shared modules sharedmods: $(BUILDPYTHON) $(SYSCONFIGDATA) - if which getopt >/dev/null; then \ + if which getopt >/dev/null; then \ mflags=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ else \ mflags=" $$MAKEFLAGS "; \ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 19:26:52 2012 From: python-checkins at python.org (matthias.klose) Date: Tue, 28 Aug 2012 19:26:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A__-_fix_typo_in?= =?utf-8?q?troduced_in_http=3A//hg=2Epython=2Eorg/cpython/rev/f918d4a06c64?= Message-ID: <3X5xj82sjczQ4J@mail.python.org> http://hg.python.org/cpython/rev/ec4ea40be2f6 changeset: 78789:ec4ea40be2f6 branch: 2.7 parent: 78786:f918d4a06c64 user: Matthias Klose date: Tue Aug 28 19:23:56 2012 +0200 summary: - fix typo introduced in http://hg.python.org/cpython/rev/f918d4a06c64 files: Makefile.pre.in | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -408,7 +408,7 @@ # Build the shared modules sharedmods: $(BUILDPYTHON) if which getopt >/dev/null 2>&1; then \ - s=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ + mflags=`getopt s $$MAKEFLAGS 2>/dev/null | sed 's/ --.*/ /'`; \ else \ mflags=" $$MAKEFLAGS "; \ fi; \ -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Tue Aug 28 20:13:56 2012 From: python-checkins at python.org (antoine.pitrou) Date: Tue, 28 Aug 2012 20:13:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315794=3A_Relax_a_?= =?utf-8?q?test_case_due_to_the_deadlock_detection=27s?= Message-ID: <3X5ylS3RfgzPyR@mail.python.org> http://hg.python.org/cpython/rev/454dceb5fd56 changeset: 78790:454dceb5fd56 parent: 78788:06497bbdf4fe user: Antoine Pitrou date: Tue Aug 28 20:10:18 2012 +0200 summary: Issue #15794: Relax a test case due to the deadlock detection's conservativeness. files: Lib/test/test_importlib/test_locks.py | 22 ++++++++++++-- 1 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_importlib/test_locks.py b/Lib/test/test_importlib/test_locks.py --- a/Lib/test/test_importlib/test_locks.py +++ b/Lib/test/test_importlib/test_locks.py @@ -1,4 +1,5 @@ from importlib import _bootstrap +import sys import time import unittest import weakref @@ -41,6 +42,17 @@ @unittest.skipUnless(threading, "threads needed for this test") class DeadlockAvoidanceTests(unittest.TestCase): + def setUp(self): + try: + self.old_switchinterval = sys.getswitchinterval() + sys.setswitchinterval(0.000001) + except AttributeError: + self.old_switchinterval = None + + def tearDown(self): + if self.old_switchinterval is not None: + sys.setswitchinterval(self.old_switchinterval) + def run_deadlock_avoidance_test(self, create_deadlock): NLOCKS = 10 locks = [LockType(str(i)) for i in range(NLOCKS)] @@ -75,10 +87,12 @@ def test_deadlock(self): results = self.run_deadlock_avoidance_test(True) - # One of the threads detected a potential deadlock on its second - # acquire() call. - self.assertEqual(results.count((True, False)), 1) - self.assertEqual(results.count((True, True)), len(results) - 1) + # At least one of the threads detected a potential deadlock on its + # second acquire() call. It may be several of them, because the + # deadlock avoidance mechanism is conservative. + nb_deadlocks = results.count((True, False)) + self.assertGreaterEqual(nb_deadlocks, 1) + self.assertEqual(results.count((True, True)), len(results) - nb_deadlocks) def test_no_deadlock(self): results = self.run_deadlock_avoidance_test(False) -- Repository URL: http://hg.python.org/cpython From brett at python.org Tue Aug 28 21:00:57 2012 From: brett at python.org (Brett Cannon) Date: Tue, 28 Aug 2012 15:00:57 -0400 Subject: [Python-checkins] cpython: Issue #15794: Relax a test case due to the deadlock detection's In-Reply-To: <3X5ylS3RfgzPyR@mail.python.org> References: <3X5ylS3RfgzPyR@mail.python.org> Message-ID: Should there be a Misc/NEWS entry since we are in rc mode? On Tue, Aug 28, 2012 at 2:13 PM, antoine.pitrou wrote: > http://hg.python.org/cpython/rev/454dceb5fd56 > changeset: 78790:454dceb5fd56 > parent: 78788:06497bbdf4fe > user: Antoine Pitrou > date: Tue Aug 28 20:10:18 2012 +0200 > summary: > Issue #15794: Relax a test case due to the deadlock detection's > conservativeness. > > files: > Lib/test/test_importlib/test_locks.py | 22 ++++++++++++-- > 1 files changed, 18 insertions(+), 4 deletions(-) > > > diff --git a/Lib/test/test_importlib/test_locks.py > b/Lib/test/test_importlib/test_locks.py > --- a/Lib/test/test_importlib/test_locks.py > +++ b/Lib/test/test_importlib/test_locks.py > @@ -1,4 +1,5 @@ > from importlib import _bootstrap > +import sys > import time > import unittest > import weakref > @@ -41,6 +42,17 @@ > @unittest.skipUnless(threading, "threads needed for this test") > class DeadlockAvoidanceTests(unittest.TestCase): > > + def setUp(self): > + try: > + self.old_switchinterval = sys.getswitchinterval() > + sys.setswitchinterval(0.000001) > + except AttributeError: > + self.old_switchinterval = None > + > + def tearDown(self): > + if self.old_switchinterval is not None: > + sys.setswitchinterval(self.old_switchinterval) > + > def run_deadlock_avoidance_test(self, create_deadlock): > NLOCKS = 10 > locks = [LockType(str(i)) for i in range(NLOCKS)] > @@ -75,10 +87,12 @@ > > def test_deadlock(self): > results = self.run_deadlock_avoidance_test(True) > - # One of the threads detected a potential deadlock on its second > - # acquire() call. > - self.assertEqual(results.count((True, False)), 1) > - self.assertEqual(results.count((True, True)), len(results) - 1) > + # At least one of the threads detected a potential deadlock on its > + # second acquire() call. It may be several of them, because the > + # deadlock avoidance mechanism is conservative. > + nb_deadlocks = results.count((True, False)) > + self.assertGreaterEqual(nb_deadlocks, 1) > + self.assertEqual(results.count((True, True)), len(results) - > nb_deadlocks) > > def test_no_deadlock(self): > results = self.run_deadlock_avoidance_test(False) > > -- > Repository URL: http://hg.python.org/cpython > > _______________________________________________ > Python-checkins mailing list > Python-checkins at python.org > http://mail.python.org/mailman/listinfo/python-checkins > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-checkins at python.org Tue Aug 28 21:22:48 2012 From: python-checkins at python.org (richard.oudkerk) Date: Tue, 28 Aug 2012 21:22:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315784=3A_Modify_O?= =?utf-8?q?SError=2E=5F=5Fstr=5F=5F=28=29_to_better_distinguish_between?= Message-ID: <3X60Gw2R6ZzPvm@mail.python.org> http://hg.python.org/cpython/rev/2e587b9bae35 changeset: 78791:2e587b9bae35 user: Richard Oudkerk date: Tue Aug 28 19:33:26 2012 +0100 summary: Issue #15784: Modify OSError.__str__() to better distinguish between errno error numbers and Windows error numbers. files: Lib/test/test_exceptions.py | 4 ++-- Misc/NEWS | 3 +++ Objects/exceptions.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) 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 @@ -216,14 +216,14 @@ self.assertEqual(w.winerror, 3) self.assertEqual(w.strerror, 'foo') self.assertEqual(w.filename, 'bar') - self.assertEqual(str(w), "[Error 3] foo: 'bar'") + self.assertEqual(str(w), "[WinError 3] foo: 'bar'") # Unknown win error becomes EINVAL (22) w = OSError(0, 'foo', None, 1001) self.assertEqual(w.errno, 22) self.assertEqual(w.winerror, 1001) self.assertEqual(w.strerror, 'foo') self.assertEqual(w.filename, None) - self.assertEqual(str(w), "[Error 1001] foo") + self.assertEqual(str(w), "[WinError 1001] foo") # Non-numeric "errno" w = OSError('bar', 'foo') self.assertEqual(w.errno, 'bar') diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,9 @@ Core and Builtins ----------------- +- Issue #15784: Modify OSError.__str__() to better distinguish between + errno error numbers and Windows error numbers. + - Issue #15781: Fix two small race conditions in import's module locking. Library diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1016,12 +1016,12 @@ #ifdef MS_WINDOWS /* If available, winerror has the priority over myerrno */ if (self->winerror && self->filename) - return PyUnicode_FromFormat("[Error %S] %S: %R", + return PyUnicode_FromFormat("[WinError %S] %S: %R", self->winerror ? self->winerror: Py_None, self->strerror ? self->strerror: Py_None, self->filename); if (self->winerror && self->strerror) - return PyUnicode_FromFormat("[Error %S] %S", + return PyUnicode_FromFormat("[WinError %S] %S", self->winerror ? self->winerror: Py_None, self->strerror ? self->strerror: Py_None); #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 00:02:26 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 29 Aug 2012 00:02:26 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_use_the_strict?= =?utf-8?q?er_PyMapping=5FCheck_=28closes_=2315801=29?= Message-ID: <3X63q65V25zQ2j@mail.python.org> http://hg.python.org/cpython/rev/2801bf875a24 changeset: 78792:2801bf875a24 branch: 2.7 parent: 78789:ec4ea40be2f6 user: Benjamin Peterson date: Tue Aug 28 17:55:35 2012 -0400 summary: use the stricter PyMapping_Check (closes #15801) files: Lib/test/string_tests.py | 3 +++ Misc/NEWS | 3 +++ Objects/stringobject.c | 2 +- Objects/unicodeobject.c | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1113,6 +1113,9 @@ self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) self.checkraises(ValueError, '%10', '__mod__', (42,)) + class X(object): pass + self.checkraises(TypeError, 'abc', '__mod__', X()) + def test_floatformatting(self): # float formatting for prec in xrange(100): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ Core and Builtins ----------------- +- Issue #15801: Make sure mappings passed to '%' formatting are actually + subscriptable. + - Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly. Patch by Serhiy Storchaka. diff --git a/Objects/stringobject.c b/Objects/stringobject.c --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -4254,7 +4254,7 @@ arglen = -1; argidx = -2; } - if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) && + if (PyMapping_Check(args) && !PyTuple_Check(args) && !PyObject_TypeCheck(args, &PyBaseString_Type)) dict = args; while (--fmtcnt >= 0) { diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8275,7 +8275,7 @@ arglen = -1; argidx = -2; } - if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) && + if (PyMapping_Check(args) && !PyTuple_Check(args) && !PyObject_TypeCheck(args, &PyBaseString_Type)) dict = args; -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 00:02:28 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 29 Aug 2012 00:02:28 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_use_the_strict?= =?utf-8?q?er_PyMapping=5FCheck_=28closes_=2315801=29?= Message-ID: <3X63q82xZ6zQ3m@mail.python.org> http://hg.python.org/cpython/rev/4d431e719646 changeset: 78793:4d431e719646 branch: 3.2 parent: 78787:5c13bd7f6256 user: Benjamin Peterson date: Tue Aug 28 17:55:35 2012 -0400 summary: use the stricter PyMapping_Check (closes #15801) files: Lib/test/string_tests.py | 3 +++ Misc/NEWS | 3 +++ Objects/unicodeobject.c | 3 +-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1142,6 +1142,9 @@ self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.)) self.checkraises(ValueError, '%10', '__mod__', (42,)) + class X(object): pass + self.checkraises(TypeError, 'abc', '__mod__', X()) + def test_floatformatting(self): # float formatting for prec in range(100): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ - Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X. +- Issue #15801: Make sure mappings passed to '%' formatting are actually + subscriptable. + - Issue #15726: Fix incorrect bounds checking in PyState_FindModule. Patch by Robin Schreiber. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9504,8 +9504,7 @@ arglen = -1; argidx = -2; } - if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) && - !PyUnicode_Check(args)) + if (PyMapping_Check(args) && !PyTuple_Check(args) && !PyUnicode_Check(args)) dict = args; while (--fmtcnt >= 0) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 00:02:30 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 29 Aug 2012 00:02:30 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?b?KTogbWVyZ2UgMy4yICgjMTU4MDEp?= Message-ID: <3X63qB3VCzzQ4K@mail.python.org> http://hg.python.org/cpython/rev/263d09ce3e9e changeset: 78794:263d09ce3e9e parent: 78790:454dceb5fd56 parent: 78793:4d431e719646 user: Benjamin Peterson date: Tue Aug 28 18:01:45 2012 -0400 summary: merge 3.2 (#15801) files: Lib/test/string_tests.py | 3 +++ Misc/NEWS | 3 +++ Objects/unicodeobject.c | 3 +-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1206,6 +1206,9 @@ self.checkraises(ValueError, '%%%df' % (2**64), '__mod__', (3.2)) self.checkraises(ValueError, '%%.%df' % (2**64), '__mod__', (3.2)) + class X(object): pass + self.checkraises(TypeError, 'abc', '__mod__', X()) + def test_floatformatting(self): # float formatting for prec in range(100): diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -71,6 +71,9 @@ - Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X. +- Issue #15801: Make sure mappings passed to '%' formatting are actually + subscriptable. + - Issue #15726: Fix incorrect bounds checking in PyState_FindModule. Patch by Robin Schreiber. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13461,8 +13461,7 @@ arglen = -1; argidx = -2; } - if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) && - !PyUnicode_Check(args)) + if (PyMapping_Check(args) && !PyTuple_Check(args) && !PyUnicode_Check(args)) dict = args; while (--fmtcnt >= 0) { -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 00:02:32 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 29 Aug 2012 00:02:32 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_default_-=3E_default?= =?utf-8?q?=29=3A_merge_heads?= Message-ID: <3X63qD1tD9zQ11@mail.python.org> http://hg.python.org/cpython/rev/786d9516663e changeset: 78795:786d9516663e parent: 78794:263d09ce3e9e parent: 78791:2e587b9bae35 user: Benjamin Peterson date: Tue Aug 28 18:02:18 2012 -0400 summary: merge heads files: Lib/test/test_exceptions.py | 4 ++-- Misc/NEWS | 3 +++ Objects/exceptions.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) 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 @@ -216,14 +216,14 @@ self.assertEqual(w.winerror, 3) self.assertEqual(w.strerror, 'foo') self.assertEqual(w.filename, 'bar') - self.assertEqual(str(w), "[Error 3] foo: 'bar'") + self.assertEqual(str(w), "[WinError 3] foo: 'bar'") # Unknown win error becomes EINVAL (22) w = OSError(0, 'foo', None, 1001) self.assertEqual(w.errno, 22) self.assertEqual(w.winerror, 1001) self.assertEqual(w.strerror, 'foo') self.assertEqual(w.filename, None) - self.assertEqual(str(w), "[Error 1001] foo") + self.assertEqual(str(w), "[WinError 1001] foo") # Non-numeric "errno" w = OSError('bar', 'foo') self.assertEqual(w.errno, 'bar') diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -40,6 +40,9 @@ Core and Builtins ----------------- +- Issue #15784: Modify OSError.__str__() to better distinguish between + errno error numbers and Windows error numbers. + - Issue #15781: Fix two small race conditions in import's module locking. Library diff --git a/Objects/exceptions.c b/Objects/exceptions.c --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1016,12 +1016,12 @@ #ifdef MS_WINDOWS /* If available, winerror has the priority over myerrno */ if (self->winerror && self->filename) - return PyUnicode_FromFormat("[Error %S] %S: %R", + return PyUnicode_FromFormat("[WinError %S] %S: %R", self->winerror ? self->winerror: Py_None, self->strerror ? self->strerror: Py_None, self->filename); if (self->winerror && self->strerror) - return PyUnicode_FromFormat("[Error %S] %S", + return PyUnicode_FromFormat("[WinError %S] %S", self->winerror ? self->winerror: Py_None, self->strerror ? self->strerror: Py_None); #endif -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 01:41:48 2012 From: python-checkins at python.org (victor.stinner) Date: Wed, 29 Aug 2012 01:41:48 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315785=3A_Modify_w?= =?utf-8?q?indow=2Eget=5Fwch=28=29_API_of_the_curses_module=3A_return_a?= Message-ID: <3X661m67YWzPvm@mail.python.org> http://hg.python.org/cpython/rev/c58789634d22 changeset: 78796:c58789634d22 user: Victor Stinner date: Wed Aug 29 01:40:57 2012 +0200 summary: Issue #15785: Modify window.get_wch() API of the curses module: return a character for most keys, and an integer for special keys, instead of always returning an integer. So it is now possible to distinguish special keys like keypad keys. files: Doc/library/curses.rst | 9 +++++---- Lib/test/test_curses.py | 12 +++++------- Misc/NEWS | 7 ++++++- Modules/_cursesmodule.c | 5 ++++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst --- a/Doc/library/curses.rst +++ b/Doc/library/curses.rst @@ -869,8 +869,8 @@ .. method:: window.get_wch([y, x]) - Get a wide character. Like :meth:`getch`, but the integer returned is the - Unicode code point for the key pressed, so it can be passed to :func:`chr`. + Get a wide character. Return a character for most keys, or an integer for + function keys, keypad keys, and other special keys. .. versionadded:: 3.3 @@ -878,8 +878,9 @@ .. method:: window.getkey([y, x]) Get a character, returning a string instead of an integer, as :meth:`getch` - does. Function keys, keypad keys and so on return a multibyte string containing - the key name. In no-delay mode, an exception is raised if there is no input. + does. Function keys, keypad keys and other special keys return a multibyte + string containing the key name. In no-delay mode, an exception is raised if + there is no input. .. method:: window.getmaxyx() diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -267,8 +267,7 @@ def test_unget_wch(stdscr): if not hasattr(curses, 'unget_wch'): return - import locale - encoding = locale.getpreferredencoding() + encoding = stdscr.encoding for ch in ('a', '\xe9', '\u20ac', '\U0010FFFF'): try: ch.encode(encoding) @@ -277,18 +276,17 @@ try: curses.unget_wch(ch) except Exception as err: - raise Exception("unget_wch(%a) failed with locale encoding %s: %s" - % (ch, encoding, err)) + raise Exception("unget_wch(%a) failed with encoding %s: %s" + % (ch, stdscr.encoding, err)) read = stdscr.get_wch() - read = chr(read) if read != ch: raise AssertionError("%r != %r" % (read, ch)) code = ord(ch) curses.unget_wch(code) read = stdscr.get_wch() - if read != code: - raise AssertionError("%r != %r" % (read, code)) + if read != ch: + raise AssertionError("%r != %r" % (read, ch)) def test_issue10570(): b = curses.tparm(curses.tigetstr("cup"), 5, 3) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -48,6 +48,11 @@ Library ------- +- Issue #15785: Modify window.get_wch() API of the curses module: return + a character for most keys, and an integer for special keys, instead of + always returning an integer. So it is now possible to distinguish special + keys like keypad keys. + What's New in Python 3.3.0 Release Candidate 1? =============================================== @@ -58,7 +63,7 @@ ----------------- - Issue #15573: memoryview comparisons are now performed by value with full - support for any valid struct module format definition. + support for any valid struct module format definition. - Issue #15316: When an item in the fromlist for __import__ doesn't exist, don't raise an error, but if an exception is raised as part of an import do diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -1203,7 +1203,10 @@ PyErr_SetString(PyCursesError, "no input"); return NULL; } - return PyLong_FromLong(rtn); + if (ct == KEY_CODE_YES) + return PyLong_FromLong(rtn); + else + return PyUnicode_FromOrdinal(rtn); } #endif -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Wed Aug 29 05:57:40 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Wed, 29 Aug 2012 05:57:40 +0200 Subject: [Python-checkins] Daily reference leaks (c58789634d22): sum=0 Message-ID: results for c58789634d22 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog6U0h5y', '-x'] From python-checkins at python.org Wed Aug 29 14:04:17 2012 From: python-checkins at python.org (benjamin.peterson) Date: Wed, 29 Aug 2012 14:04:17 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_move_entry_to_the_correct_?= =?utf-8?q?version?= Message-ID: <3X6QVT2BDQzQ6T@mail.python.org> http://hg.python.org/cpython/rev/124fb2b39ed9 changeset: 78797:124fb2b39ed9 user: Benjamin Peterson date: Wed Aug 29 08:04:11 2012 -0400 summary: move entry to the correct version files: Misc/NEWS | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #15801: Make sure mappings passed to '%' formatting are actually + subscriptable. + Library ------- @@ -79,9 +82,6 @@ - Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X. -- Issue #15801: Make sure mappings passed to '%' formatting are actually - subscriptable. - - Issue #15726: Fix incorrect bounds checking in PyState_FindModule. Patch by Robin Schreiber. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 15:21:34 2012 From: python-checkins at python.org (trent.nelson) Date: Wed, 29 Aug 2012 15:21:34 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1NzY1?= =?utf-8?q?=3A_Fix_quirky_NetBSD_getcwd=28=29_behaviour=2E?= Message-ID: <3X6SCf5lbkzQ3V@mail.python.org> http://hg.python.org/cpython/rev/bfa5d0ddfbeb changeset: 78798:bfa5d0ddfbeb branch: 2.7 parent: 78792:2801bf875a24 user: Trent Nelson date: Wed Aug 29 09:20:41 2012 -0400 summary: Issue #15765: Fix quirky NetBSD getcwd() behaviour. This is done by extending a previous fix for issue #9185 that was made for Solaris and OpenBSD to NetBSD as well. files: Lib/test/test_posix.py | 12 ++++++++++-- Misc/NEWS | 3 +++ Modules/posixmodule.c | 4 +++- 3 files changed, 16 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 @@ -405,8 +405,16 @@ _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG - if 'sunos' in sys.platform or 'openbsd' in sys.platform: - expected_errno = errno.ERANGE # Issue 9185 + # The following platforms have quirky getcwd() + # behaviour -- see issue 9185 and 15765 for + # more information. + quirky_platform = ( + 'sunos' in sys.platform or + 'netbsd' in sys.platform or + 'openbsd' in sys.platform + ) + if quirky_platform: + expected_errno = errno.ERANGE self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -346,6 +346,9 @@ Tests ----- +- Issue #15765: Extend a previous fix to Solaris and OpenBSD for quirky + getcwd() behaviour (issue #9185) to NetBSD as well. + - Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1956,7 +1956,9 @@ "getcwd() -> path\n\n\ Return a string representing the current working directory."); -#if (defined(__sun) && defined(__SVR4)) || defined(__OpenBSD__) +#if (defined(__sun) && defined(__SVR4)) || \ + defined(__OpenBSD__) || \ + defined(__NetBSD__) /* Issue 9185: getcwd() returns NULL/ERANGE indefinitely. */ static PyObject * posix_getcwd(PyObject *self, PyObject *noargs) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 15:28:07 2012 From: python-checkins at python.org (vinay.sajip) Date: Wed, 29 Aug 2012 15:28:07 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICMxNTgw?= =?utf-8?q?7=3A_Removed_incorrect_directive_from_help=2E?= Message-ID: <3X6SMC4bQbzQ93@mail.python.org> http://hg.python.org/cpython/rev/48f54b6bf0ef changeset: 78799:48f54b6bf0ef branch: 2.7 parent: 78792:2801bf875a24 user: Vinay Sajip date: Wed Aug 29 14:25:42 2012 +0100 summary: Closes #15807: Removed incorrect directive from help. files: Doc/library/logging.handlers.rst | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) diff --git a/Doc/library/logging.handlers.rst b/Doc/library/logging.handlers.rst --- a/Doc/library/logging.handlers.rst +++ b/Doc/library/logging.handlers.rst @@ -698,9 +698,6 @@ .. method:: setTarget(target) - .. versionchanged:: 2.6 - *credentials* was added. - Sets the target handler for this handler. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 15:28:09 2012 From: python-checkins at python.org (vinay.sajip) Date: Wed, 29 Aug 2012 15:28:09 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAobWVyZ2UgMi43IC0+IDIuNyk6?= =?utf-8?q?_Merged_upstream_changes=2E?= Message-ID: <3X6SMF1JLYzQ88@mail.python.org> http://hg.python.org/cpython/rev/39f045e0a072 changeset: 78800:39f045e0a072 branch: 2.7 parent: 78799:48f54b6bf0ef parent: 78798:bfa5d0ddfbeb user: Vinay Sajip date: Wed Aug 29 14:27:07 2012 +0100 summary: Merged upstream changes. files: Lib/test/test_posix.py | 12 ++++++++++-- Misc/NEWS | 3 +++ Modules/posixmodule.c | 4 +++- 3 files changed, 16 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 @@ -405,8 +405,16 @@ _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) except OSError as e: expected_errno = errno.ENAMETOOLONG - if 'sunos' in sys.platform or 'openbsd' in sys.platform: - expected_errno = errno.ERANGE # Issue 9185 + # The following platforms have quirky getcwd() + # behaviour -- see issue 9185 and 15765 for + # more information. + quirky_platform = ( + 'sunos' in sys.platform or + 'netbsd' in sys.platform or + 'openbsd' in sys.platform + ) + if quirky_platform: + expected_errno = errno.ERANGE self.assertEqual(e.errno, expected_errno) finally: os.chdir('..') diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -346,6 +346,9 @@ Tests ----- +- Issue #15765: Extend a previous fix to Solaris and OpenBSD for quirky + getcwd() behaviour (issue #9185) to NetBSD as well. + - Issue #15615: Add some tests for the json module's handling of invalid input data. Patch by Kushal Das. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1956,7 +1956,9 @@ "getcwd() -> path\n\n\ Return a string representing the current working directory."); -#if (defined(__sun) && defined(__SVR4)) || defined(__OpenBSD__) +#if (defined(__sun) && defined(__SVR4)) || \ + defined(__OpenBSD__) || \ + defined(__NetBSD__) /* Issue 9185: getcwd() returns NULL/ERANGE indefinitely. */ static PyObject * posix_getcwd(PyObject *self, PyObject *noargs) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 15:34:08 2012 From: python-checkins at python.org (vinay.sajip) Date: Wed, 29 Aug 2012 15:34:08 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogQ2xvc2VzICMxNTcx?= =?utf-8?q?0=3A_accept_long_in_=5FcheckLevel=2E?= Message-ID: <3X6SV82S66zPxW@mail.python.org> http://hg.python.org/cpython/rev/8ba6d8fc9740 changeset: 78801:8ba6d8fc9740 branch: 2.7 user: Vinay Sajip date: Wed Aug 29 14:33:14 2012 +0100 summary: Closes #15710: accept long in _checkLevel. files: Lib/logging/__init__.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -180,7 +180,7 @@ _releaseLock() def _checkLevel(level): - if isinstance(level, int): + if isinstance(level, (int, long)): rv = level elif str(level) == level: if level not in _levelNames: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 16:52:19 2012 From: python-checkins at python.org (ezio.melotti) Date: Wed, 29 Aug 2012 16:52:19 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Add_missing_co?= =?utf-8?q?mma=2E?= Message-ID: <3X6VDM3yH6zPww@mail.python.org> http://hg.python.org/cpython/rev/9f6fc62d7a66 changeset: 78802:9f6fc62d7a66 branch: 2.7 user: Ezio Melotti date: Wed Aug 29 17:50:42 2012 +0300 summary: Add missing comma. files: Doc/library/unittest.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1157,7 +1157,7 @@ .. method:: assertListEqual(list1, list2, msg=None) assertTupleEqual(tuple1, tuple2, msg=None) - Tests that two lists or tuples are equal. If not an error message is + Tests that two lists or tuples are equal. If not, an error message is constructed that shows only the differences between the two. An error is also raised if either of the parameters are of the wrong type. These methods are used by default when comparing lists or tuples with -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 16:52:21 2012 From: python-checkins at python.org (ezio.melotti) Date: Wed, 29 Aug 2012 16:52:21 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Add_missing_co?= =?utf-8?q?mma=2E?= Message-ID: <3X6VDP2nGCzPy5@mail.python.org> http://hg.python.org/cpython/rev/900b82193237 changeset: 78803:900b82193237 branch: 3.2 parent: 78793:4d431e719646 user: Ezio Melotti date: Wed Aug 29 17:50:42 2012 +0300 summary: Add missing comma. files: Doc/library/unittest.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1271,7 +1271,7 @@ .. method:: assertListEqual(first, second, msg=None) assertTupleEqual(first, second, msg=None) - Tests that two lists or tuples are equal. If not an error message is + Tests that two lists or tuples are equal. If not, an error message is constructed that shows only the differences between the two. An error is also raised if either of the parameters are of the wrong type. These methods are used by default when comparing lists or tuples with -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Wed Aug 29 16:52:22 2012 From: python-checkins at python.org (ezio.melotti) Date: Wed, 29 Aug 2012 16:52:22 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Add_missing_comma=2E?= Message-ID: <3X6VDQ5cJTzQ4b@mail.python.org> http://hg.python.org/cpython/rev/4a37bed5b96f changeset: 78804:4a37bed5b96f parent: 78797:124fb2b39ed9 parent: 78803:900b82193237 user: Ezio Melotti date: Wed Aug 29 17:52:06 2012 +0300 summary: Add missing comma. files: Doc/library/unittest.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -1265,7 +1265,7 @@ .. method:: assertListEqual(first, second, msg=None) assertTupleEqual(first, second, msg=None) - Tests that two lists or tuples are equal. If not an error message is + Tests that two lists or tuples are equal. If not, an error message is constructed that shows only the differences between the two. An error is also raised if either of the parameters are of the wrong type. These methods are used by default when comparing lists or tuples with -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 30 00:33:56 2012 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 30 Aug 2012 00:33:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1ODAw?= =?utf-8?q?=3A_fix_the_closing_of_input_/_output_files_when_gzip_is_used_a?= =?utf-8?q?s_a?= Message-ID: <3X6hT06Y6mzPpX@mail.python.org> http://hg.python.org/cpython/rev/0b5ba5f610a9 changeset: 78805:0b5ba5f610a9 branch: 3.2 parent: 78803:900b82193237 user: Antoine Pitrou date: Thu Aug 30 00:29:24 2012 +0200 summary: Issue #15800: fix the closing of input / output files when gzip is used as a script. files: Lib/gzip.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -621,9 +621,9 @@ if not chunk: break g.write(chunk) - if g is not sys.stdout: + if g is not sys.stdout.buffer: g.close() - if f is not sys.stdin: + if f is not sys.stdin.buffer: f.close() if __name__ == '__main__': -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 30 00:33:58 2012 From: python-checkins at python.org (antoine.pitrou) Date: Thu, 30 Aug 2012 00:33:58 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315800=3A_fix_the_closing_of_input_/_output_file?= =?utf-8?q?s_when_gzip_is_used_as_a?= Message-ID: <3X6hT242j2zQ79@mail.python.org> http://hg.python.org/cpython/rev/be505d22dde8 changeset: 78806:be505d22dde8 parent: 78804:4a37bed5b96f parent: 78805:0b5ba5f610a9 user: Antoine Pitrou date: Thu Aug 30 00:30:14 2012 +0200 summary: Issue #15800: fix the closing of input / output files when gzip is used as a script. files: Lib/gzip.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -670,9 +670,9 @@ if not chunk: break g.write(chunk) - if g is not sys.stdout: + if g is not sys.stdout.buffer: g.close() - if f is not sys.stdin: + if f is not sys.stdin.buffer: f.close() if __name__ == '__main__': -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Thu Aug 30 06:02:53 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Thu, 30 Aug 2012 06:02:53 +0200 Subject: [Python-checkins] Daily reference leaks (be505d22dde8): sum=0 Message-ID: results for be505d22dde8 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflogEVeEGz', '-x'] From python-checkins at python.org Thu Aug 30 12:14:33 2012 From: python-checkins at python.org (stefan.krah) Date: Thu, 30 Aug 2012 12:14:33 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315724=3A_Add_vers?= =?utf-8?q?ionchanged_tags_to_the_memoryview_documentation=2E?= Message-ID: <3X701P1KPMzPsv@mail.python.org> http://hg.python.org/cpython/rev/34e8c06f7e55 changeset: 78807:34e8c06f7e55 user: Stefan Krah date: Thu Aug 30 12:09:09 2012 +0200 summary: Issue #15724: Add versionchanged tags to the memoryview documentation. files: Doc/library/stdtypes.rst | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2450,6 +2450,8 @@ ``v == w`` for memoryview objects. .. versionchanged:: 3.3 + Previous versions compared the raw memory disregarding the item format + and the logical array structure. .. method:: tobytes() @@ -2479,8 +2481,10 @@ >>> m.tolist() [1.1, 2.2, 3.3] - :meth:`tolist` is currently restricted to single character native formats - in :mod:`struct` module syntax. + .. versionchanged:: 3.3 + :meth:`tolist` now supports all single character native formats in + :mod:`struct` module syntax as well as multi-dimensional + representations. .. method:: release() @@ -2664,6 +2668,10 @@ arbitrary format strings, but some methods (e.g. :meth:`tolist`) are restricted to native single element formats. + .. versionchanged:: 3.3 + format ``'B'`` is now handled according to the struct module syntax. + This means that ``memoryview(b'abc')[0] == b'abc'[0] == 97``. + .. attribute:: itemsize The size in bytes of each element of the memoryview:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 30 12:39:42 2012 From: python-checkins at python.org (stefan.krah) Date: Thu, 30 Aug 2012 12:39:42 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Closes_=2310650=3A_Depreca?= =?utf-8?q?te_the_watchexp_parameter_of_Decimal=2Equantize=28=29=2E?= Message-ID: <3X70ZQ4KHNzQ52@mail.python.org> http://hg.python.org/cpython/rev/7db16ff9f5fd changeset: 78808:7db16ff9f5fd user: Stefan Krah date: Thu Aug 30 12:33:55 2012 +0200 summary: Closes #10650: Deprecate the watchexp parameter of Decimal.quantize(). files: Doc/library/decimal.rst | 5 +++++ Doc/whatsnew/3.3.rst | 4 ++++ Misc/NEWS | 3 +++ 3 files changed, 12 insertions(+), 0 deletions(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -737,6 +737,11 @@ resulting exponent is greater than :attr:`Emax` or less than :attr:`Etiny`. + .. deprecated:: 3.3 + *watchexp* is an implementation detail from the pure Python version + and is not present in the C version. It will be removed in version + 3.4, where it defaults to ``True``. + .. method:: radix() Return ``Decimal(10)``, the radix (base) in which the :class:`Decimal` 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 @@ -1190,6 +1190,10 @@ changed to match the order displayed by :func:`repr`. +* The ``watchexp`` parameter in the :meth:`~decimal.Decimal.quantize` method + is deprecated. + + ftplib ------ diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -51,6 +51,9 @@ Library ------- +- Issue #10650: Deprecate the watchexp parameter of the Decimal.quantize() + method. + - Issue #15785: Modify window.get_wch() API of the curses module: return a character for most keys, and an integer for special keys, instead of always returning an integer. So it is now possible to distinguish special -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 30 16:32:14 2012 From: python-checkins at python.org (trent.nelson) Date: Thu, 30 Aug 2012 16:32:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1ODE5?= =?utf-8?q?=3A_Fix_out-of-tree_builds_from_a_readonly_source=2E?= Message-ID: <3X75kk10jbzQ1H@mail.python.org> http://hg.python.org/cpython/rev/62044cd5b19b changeset: 78809:62044cd5b19b branch: 3.2 parent: 78805:0b5ba5f610a9 user: Trent Nelson date: Thu Aug 30 14:32:02 2012 +0000 summary: Issue #15819: Fix out-of-tree builds from a readonly source. files: Makefile.pre.in | 12 +++++-- Misc/NEWS | 3 ++ configure | 50 +++++++++++++++++++++++++++++++++++++ configure.ac | 1 + 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -59,6 +59,8 @@ # Also, making them read-only seems to be a good idea... INSTALL_SHARED= ${INSTALL} -m 555 +MKDIR_P= @MKDIR_P@ + MAKESETUP= $(srcdir)/Modules/makesetup # Compiler options @@ -223,8 +225,8 @@ ########################################################################## # Grammar -GRAMMAR_H= $(srcdir)/Include/graminit.h -GRAMMAR_C= $(srcdir)/Python/graminit.c +GRAMMAR_H= Include/graminit.h +GRAMMAR_C= Python/graminit.c GRAMMAR_INPUT= $(srcdir)/Grammar/Grammar @@ -266,9 +268,9 @@ ########################################################################## # AST -AST_H_DIR= $(srcdir)/Include +AST_H_DIR= Include AST_H= $(AST_H_DIR)/Python-ast.h -AST_C_DIR= $(srcdir)/Python +AST_C_DIR= Python AST_C= $(AST_C_DIR)/Python-ast.c AST_ASDL= $(srcdir)/Parser/Python.asdl @@ -609,9 +611,11 @@ Parser/pgenmain.o: $(srcdir)/Include/parsetok.h $(AST_H): $(AST_ASDL) $(ASDLGEN_FILES) + $(MKDIR_P) $(AST_H_DIR) $(ASDLGEN) -h $(AST_H_DIR) $(AST_ASDL) $(AST_C): $(AST_ASDL) $(ASDLGEN_FILES) + $(MKDIR_P) $(AST_C_DIR) $(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL) Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -495,6 +495,9 @@ Build ----- +- Issue #15819: Make sure we can build Python out-of-tree from a readonly + source directory. (Somewhat related to Issue #9860.) + - Issue #15645: Ensure 2to3 grammar pickles are properly installed. - Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -641,6 +641,7 @@ OPT ABIFLAGS LN +MKDIR_P INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM @@ -5438,6 +5439,48 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } +if test -z "$MKDIR_P"; then + if ${ac_cv_path_mkdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done + done +IFS=$as_save_IFS + +fi + + test -d ./--version && rmdir ./--version + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + MKDIR_P="$ac_install_sh -d" + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } + # Not every filesystem supports hard links @@ -14567,6 +14610,7 @@ ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' test -n "\$AWK" || AWK=awk _ACEOF @@ -15134,6 +15178,11 @@ [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 @@ -15188,6 +15237,7 @@ s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -869,6 +869,7 @@ fi esac AC_PROG_INSTALL +AC_PROG_MKDIR_P # Not every filesystem supports hard links AC_SUBST(LN) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 30 16:36:38 2012 From: python-checkins at python.org (trent.nelson) Date: Thu, 30 Aug 2012 16:36:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Block_78809=3A62044cd5b19b_=28Issue_=2315819=29_from_3?= =?utf-8?b?LjIu?= Message-ID: <3X75qp0l9VzQ8h@mail.python.org> http://hg.python.org/cpython/rev/af36536988fd changeset: 78810:af36536988fd parent: 78808:7db16ff9f5fd parent: 78809:62044cd5b19b user: Trent Nelson date: Thu Aug 30 14:36:15 2012 +0000 summary: Block 78809:62044cd5b19b (Issue #15819) from 3.2. files: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 30 16:52:52 2012 From: python-checkins at python.org (trent.nelson) Date: Thu, 30 Aug 2012 16:52:52 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315819=3A_Fix_out-?= =?utf-8?q?of-tree_builds_from_a_readonly_source=2E?= Message-ID: <3X76BX3yv4zQBF@mail.python.org> http://hg.python.org/cpython/rev/ab6ab44921b2 changeset: 78811:ab6ab44921b2 user: Trent Nelson date: Thu Aug 30 14:52:38 2012 +0000 summary: Issue #15819: Fix out-of-tree builds from a readonly source. files: Makefile.pre.in | 10 ++++++---- Misc/NEWS | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -229,8 +229,8 @@ ########################################################################## # Grammar -GRAMMAR_H= $(srcdir)/Include/graminit.h -GRAMMAR_C= $(srcdir)/Python/graminit.c +GRAMMAR_H= Include/graminit.h +GRAMMAR_C= Python/graminit.c GRAMMAR_INPUT= $(srcdir)/Grammar/Grammar @@ -296,9 +296,9 @@ ########################################################################## # AST -AST_H_DIR= $(srcdir)/Include +AST_H_DIR= Include AST_H= $(AST_H_DIR)/Python-ast.h -AST_C_DIR= $(srcdir)/Python +AST_C_DIR= Python AST_C= $(AST_C_DIR)/Python-ast.c AST_ASDL= $(srcdir)/Parser/Python.asdl @@ -665,9 +665,11 @@ Parser/pgenmain.o: $(srcdir)/Include/parsetok.h $(AST_H): $(AST_ASDL) $(ASDLGEN_FILES) + $(MKDIR_P) $(AST_H_DIR) $(ASDLGEN) -h $(AST_H_DIR) $(AST_ASDL) $(AST_C): $(AST_H) $(AST_ASDL) $(ASDLGEN_FILES) + $(MKDIR_P) $(AST_C_DIR) $(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL) Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -25,6 +25,9 @@ Build ----- +- Issue #15819: Make sure we can build Python out-of-tree from a readonly + source directory. (Somewhat related to Issue #9860.) + Documentation ------------- -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Thu Aug 30 16:56:23 2012 From: python-checkins at python.org (trent.nelson) Date: Thu, 30 Aug 2012 16:56:23 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1ODE5?= =?utf-8?q?=3A_Fix_out-of-tree_builds_from_a_readonly_source=2E?= Message-ID: <3X76Gb4611zQ1Y@mail.python.org> http://hg.python.org/cpython/rev/2dde5a7439fd changeset: 78812:2dde5a7439fd branch: 2.7 parent: 78802:9f6fc62d7a66 user: Trent Nelson date: Thu Aug 30 14:56:13 2012 +0000 summary: Issue #15819: Fix out-of-tree builds from a readonly source. files: Makefile.pre.in | 12 +++++-- Misc/NEWS | 3 ++ configure | 50 +++++++++++++++++++++++++++++++++++++ configure.ac | 1 + 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -57,6 +57,8 @@ # Also, making them read-only seems to be a good idea... INSTALL_SHARED= ${INSTALL} -m 555 +MKDIR_P= @MKDIR_P@ + MAKESETUP= $(srcdir)/Modules/makesetup # Compiler options @@ -204,8 +206,8 @@ ########################################################################## # Grammar -GRAMMAR_H= $(srcdir)/Include/graminit.h -GRAMMAR_C= $(srcdir)/Python/graminit.c +GRAMMAR_H= Include/graminit.h +GRAMMAR_C= Python/graminit.c GRAMMAR_INPUT= $(srcdir)/Grammar/Grammar @@ -246,9 +248,9 @@ ########################################################################## # AST -AST_H_DIR= $(srcdir)/Include +AST_H_DIR= Include AST_H= $(AST_H_DIR)/Python-ast.h -AST_C_DIR= $(srcdir)/Python +AST_C_DIR= Python AST_C= $(AST_C_DIR)/Python-ast.c AST_ASDL= $(srcdir)/Parser/Python.asdl @@ -563,9 +565,11 @@ Parser/pgenmain.o: $(srcdir)/Include/parsetok.h $(AST_H): $(AST_ASDL) $(ASDLGEN_FILES) + $(MKDIR_P) $(AST_H_DIR) $(ASDLGEN) -h $(AST_H_DIR) $(AST_ASDL) $(AST_C): $(AST_ASDL) $(ASDLGEN_FILES) + $(MKDIR_P) $(AST_C_DIR) $(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL) Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -364,6 +364,9 @@ Build ----- +- Issue #15819: Make sure we can build Python out-of-tree from a readonly + source directory. (Somewhat related to Issue #9860.) + - Issue #15645: Ensure 2to3 grammar pickles are properly installed. - Issue #15560: Fix building _sqlite3 extension on OS X with an SDK. diff --git a/configure b/configure --- a/configure +++ b/configure @@ -640,6 +640,7 @@ BASECFLAGS OPT LN +MKDIR_P INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM @@ -5356,6 +5357,48 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } +if test -z "$MKDIR_P"; then + if ${ac_cv_path_mkdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done + done +IFS=$as_save_IFS + +fi + + test -d ./--version && rmdir ./--version + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + MKDIR_P="$ac_install_sh -d" + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } + # Not every filesystem supports hard links @@ -14479,6 +14522,7 @@ ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' test -n "\$AWK" || AWK=awk _ACEOF @@ -15047,6 +15091,11 @@ [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 @@ -15101,6 +15150,7 @@ s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -878,6 +878,7 @@ fi esac AC_PROG_INSTALL +AC_PROG_MKDIR_P # Not every filesystem supports hard links AC_SUBST(LN) -- Repository URL: http://hg.python.org/cpython From solipsis at pitrou.net Fri Aug 31 06:04:54 2012 From: solipsis at pitrou.net (solipsis at pitrou.net) Date: Fri, 31 Aug 2012 06:04:54 +0200 Subject: [Python-checkins] Daily reference leaks (ab6ab44921b2): sum=0 Message-ID: results for ab6ab44921b2 on branch "default" -------------------------------------------- Command line was: ['./python', '-m', 'test.regrtest', '-uall', '-R', '3:3:/home/antoine/cpython/refleaks/reflog8UCqim', '-x'] From python-checkins at python.org Fri Aug 31 12:55:37 2012 From: python-checkins at python.org (andrew.svetlov) Date: Fri, 31 Aug 2012 12:55:37 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMi43KTogSXNzdWUgIzE1ODI1?= =?utf-8?q?=3A_fix_typo_in_OrderedDict_docs=2E?= Message-ID: <3X7ctK3SyDzQ9q@mail.python.org> http://hg.python.org/cpython/rev/69952b5599b5 changeset: 78813:69952b5599b5 branch: 2.7 user: Andrew Svetlov date: Fri Aug 31 13:53:30 2012 +0300 summary: Issue #15825: fix typo in OrderedDict docs. Patch by Mike Hoy. files: Doc/ACKS.txt | 1 + Doc/library/collections.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Doc/ACKS.txt b/Doc/ACKS.txt --- a/Doc/ACKS.txt +++ b/Doc/ACKS.txt @@ -92,6 +92,7 @@ * Rob Hooft * Brian Hooper * Randall Hopper + * Mike Hoy * Michael Hudson * Eric Huss * Jeremy Hylton diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -852,7 +852,7 @@ to the end and the sort is not maintained. It is also straight-forward to create an ordered dictionary variant -that the remembers the order the keys were *last* inserted. +that remembers the order the keys were *last* inserted. If a new entry overwrites an existing entry, the original insertion position is changed and moved to the end:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 31 12:55:39 2012 From: python-checkins at python.org (andrew.svetlov) Date: Fri, 31 Aug 2012 12:55:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?b?Y3B5dGhvbiAoMy4yKTogSXNzdWUgIzE1ODI1?= =?utf-8?q?=3A_fix_typo_in_OrderedDict_docs=2E?= Message-ID: <3X7ctM33bhzQCV@mail.python.org> http://hg.python.org/cpython/rev/8877d25119ef changeset: 78814:8877d25119ef branch: 3.2 parent: 78809:62044cd5b19b user: Andrew Svetlov date: Fri Aug 31 13:54:54 2012 +0300 summary: Issue #15825: fix typo in OrderedDict docs. Patch by Mike Hoy. files: Doc/ACKS.txt | 1 + Doc/library/collections.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Doc/ACKS.txt b/Doc/ACKS.txt --- a/Doc/ACKS.txt +++ b/Doc/ACKS.txt @@ -95,6 +95,7 @@ * Rob Hooft * Brian Hooper * Randall Hopper + * Mike Hoy * Michael Hudson * Eric Huss * Jeremy Hylton diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -878,7 +878,7 @@ to the end and the sort is not maintained. It is also straight-forward to create an ordered dictionary variant -that the remembers the order the keys were *last* inserted. +that remembers the order the keys were *last* inserted. If a new entry overwrites an existing entry, the original insertion position is changed and moved to the end:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 31 12:55:40 2012 From: python-checkins at python.org (andrew.svetlov) Date: Fri, 31 Aug 2012 12:55:40 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Issue_=2315825=3A_fix_typo_in_OrderedDict_docs=2E?= Message-ID: <3X7ctN6D5lzQLL@mail.python.org> http://hg.python.org/cpython/rev/ef80ce83eab1 changeset: 78815:ef80ce83eab1 parent: 78811:ab6ab44921b2 parent: 78814:8877d25119ef user: Andrew Svetlov date: Fri Aug 31 13:55:11 2012 +0300 summary: Issue #15825: fix typo in OrderedDict docs. Patch by Mike Hoy. files: Doc/ACKS.txt | 1 + Doc/library/collections.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Doc/ACKS.txt b/Doc/ACKS.txt --- a/Doc/ACKS.txt +++ b/Doc/ACKS.txt @@ -96,6 +96,7 @@ * Rob Hooft * Brian Hooper * Randall Hopper + * Mike Hoy * Michael Hudson * Eric Huss * Jeremy Hylton diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -1012,7 +1012,7 @@ to the end and the sort is not maintained. It is also straight-forward to create an ordered dictionary variant -that the remembers the order the keys were *last* inserted. +that remembers the order the keys were *last* inserted. If a new entry overwrites an existing entry, the original insertion position is changed and moved to the end:: -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 31 15:53:38 2012 From: python-checkins at python.org (nick.coghlan) Date: Fri, 31 Aug 2012 15:53:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?peps=3A_Add_first_draft_of_1=2E3_meta?= =?utf-8?q?data_spec_=28includes_some_info_on_metadata_files_that?= Message-ID: <3X7hqk5JfgzPyW@mail.python.org> http://hg.python.org/peps/rev/42ee0afd40ed changeset: 4502:42ee0afd40ed user: Nick Coghlan date: Fri Aug 31 23:53:29 2012 +1000 summary: Add first draft of 1.3 metadata spec (includes some info on metadata files that went missing in the 1.2 spec) files: pep-0426.txt | 643 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 643 insertions(+), 0 deletions(-) diff --git a/pep-0426.txt b/pep-0426.txt new file mode 100644 --- /dev/null +++ b/pep-0426.txt @@ -0,0 +1,643 @@ +PEP: 426 +Title: Metadata for Python Software Packages 1.3 +Version: $Revision$ +Last-Modified: $Date$ +Author: Daniel Holth +Discussions-To: Distutils SIG +Status: Draft +Type: Standards Track +Content-Type: text/x-rst +Created: 30 Aug 2012 + + +Abstract +======== + +This PEP describes a mechanism for adding metadata to Python distributions. +It includes specifics of the field names, and their semantics and +usage. + +This document specifies version 1.3 of the metadata format. +Version 1.0 is specified in PEP 241. +Version 1.1 is specified in PEP 314. +Version 1.2 is specified in PEP 345. + +Version 1.3 of the metadata format adds fields designed to make +third-party packaging of Python Software easier and defines a +formal extension mechanism. The fields are "Setup-Requires-Dist" +"Provides-Extra", and "Extension". This version also adds the `extra` +variable to the `environment markers` specification. + +Metadata Files +============== + +The syntax defined in this PEP is for use with Python distribution metadata +files. This file format is a single set of RFC-822 headers parseable by +the ``rfc822`` or ``email`` modules. The field names listed in the +`Fields`_ section are used as the header names. + +There are two standard locations for these metadata files: + +* the ``PKG-INFO`` file included in the base directory of Python + source distribution archives (as created by the distutils ``sdist`` + command) +* the ``dist-info/METADATA`` files in a Python installation database, as + described in PEP 376. + +Other tools involved in Python distribution may choose to record this +metadata in additional tool-specific locations (e.g. as part of a +binary distribution archive format). + +Encoding +======== + +Keys must be ASCII. Values are expected to be displayed as UTF-8, +but should otherwise be treated as opaque bytes. + +Fields +====== + +This section specifies the names and semantics of each of the +supported metadata fields. + +Fields marked with "(Multiple use)" may be specified multiple +times in a single metadata file. Other fields may only occur +once in a metadata file. Fields marked with "(optional)" are +not required to appear in a valid metadata file; all other +fields must be present. + +Metadata-Version +:::::::::::::::: + +Version of the file format; "1.3" is the only legal value. + +Example:: + + Metadata-Version: 1.3 + + +Name +:::: + +The name of the distribution. + +Example:: + + Name: BeagleVote + + +Version +::::::: + +A string containing the distribution's version number. This +field must be in the format specified in PEP 386. + +Example:: + + Version: 1.0a2 + + +Platform (multiple use) +::::::::::::::::::::::: + +A Platform specification describing an operating system supported by +the distribution which is not listed in the "Operating System" Trove classifiers. +See "Classifier" below. + +Examples:: + + Platform: ObscureUnix + Platform: RareDOS + + +Supported-Platform (multiple use) +::::::::::::::::::::::::::::::::: + +Binary distributions containing a metadata file will use the +Supported-Platform field in their metadata to specify the OS and +CPU for which the binary distribution was compiled. The semantics of +the Supported-Platform field are not specified in this PEP. + +Example:: + + Supported-Platform: RedHat 7.2 + Supported-Platform: i386-win32-2791 + + +Summary +::::::: + +A one-line summary of what the distribution does. + +Example:: + + Summary: A module for collecting votes from beagles. + + +Description (optional) +:::::::::::::::::::::: + +A longer description of the distribution that can run to several +paragraphs. Software that deals with metadata should not assume +any maximum size for this field, though people shouldn't include +their instruction manual as the description. + +The contents of this field can be written using reStructuredText +markup [1]_. For programs that work with the metadata, supporting +markup is optional; programs can also display the contents of the +field as-is. This means that authors should be conservative in +the markup they use. + +To support empty lines and lines with indentation with respect to +the RFC 822 format, any CRLF character has to be suffixed by 7 spaces +followed by a pipe ("|") char. As a result, the Description field is +encoded into a folded field that can be interpreted by RFC822 +parser [2]_. + +Example:: + + Description: This project provides powerful math functions + |For example, you can use `sum()` to sum numbers: + | + |Example:: + | + | >>> sum(1, 2) + | 3 + | + +This encoding implies that any occurences of a CRLF followed by 7 spaces +and a pipe char have to be replaced by a single CRLF when the field is unfolded +using a RFC822 reader. + + +Keywords (optional) +::::::::::::::::::: + +A list of additional keywords to be used to assist searching +for the distribution in a larger catalog. + +Example:: + + Keywords: dog puppy voting election + + +Home-page (optional) +:::::::::::::::::::: + +A string containing the URL for the distribution's home page. + +Example:: + + Home-page: http://www.example.com/~cschultz/bvote/ + + +Download-URL +:::::::::::: + +A string containing the URL from which this version of the distribution +can be downloaded. (This means that the URL can't be something like +".../BeagleVote-latest.tgz", but instead must be ".../BeagleVote-0.45.tgz".) + + +Author (optional) +::::::::::::::::: + +A string containing the author's name at a minimum; additional +contact information may be provided. + +Example:: + + Author: C. Schultz, Universal Features Syndicate, + Los Angeles, CA + + +Author-email (optional) +::::::::::::::::::::::: + +A string containing the author's e-mail address. It can contain +a name and e-mail address in the legal forms for a RFC-822 +``From:`` header. + +Example:: + + Author-email: "C. Schultz" + + +Maintainer (optional) +::::::::::::::::::::: + +A string containing the maintainer's name at a minimum; additional +contact information may be provided. + +Note that this field is intended for use when a project is being +maintained by someone other than the original author: it should be +omitted if it is identical to ``Author``. + +Example:: + + Maintainer: C. Schultz, Universal Features Syndicate, + Los Angeles, CA + + +Maintainer-email (optional) +::::::::::::::::::::::::::: + +A string containing the maintainer's e-mail address. It can contain +a name and e-mail address in the legal forms for a RFC-822 +``From:`` header. + +Note that this field is intended for use when a project is being +maintained by someone other than the original author: it should be +omitted if it is identical to ``Author-email``. + +Example:: + + Maintainer-email: "C. Schultz" + + +License (optional) +:::::::::::::::::: + +Text indicating the license covering the distribution where the license +is not a selection from the "License" Trove classifiers. See +"Classifier" below. This field may also be used to specify a +particular version of a licencse which is named via the ``Classifier`` +field, or to indicate a variation or exception to such a license. + +Examples:: + + License: This software may only be obtained by sending the + author a postcard, and then the user promises not + to redistribute it. + + License: GPL version 3, excluding DRM provisions + + +Classifier (multiple use) +::::::::::::::::::::::::: + +Each entry is a string giving a single classification value +for the distribution. Classifiers are described in PEP 301 [2]. + +Examples:: + + Classifier: Development Status :: 4 - Beta + Classifier: Environment :: Console (Text Based) + + +Requires-Dist (multiple use) +:::::::::::::::::::::::::::: + +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 distutils project names should correspond to names as found +on the `Python Package Index`_. + +Version declarations must follow the rules described in +`Version Specifiers`_ + +Examples:: + + Requires-Dist: pkginfo + Requires-Dist: PasteDeploy + Requires-Dist: zope.interface (>3.5.0) + + +Setup-Requires-Dist (multiple use) +:::::::::::::::::::::::::::::::::: + +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. + +Examples:: + + Setup-Requires-Dist: custom_setup_command + +Dependencies mentioned in `Setup-Requires-Dist` may be installed exclusively +for setup and are not guaranteed to be available at run time. + + +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). + +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``. + +A distribution may also provide a "virtual" project name, which does +not correspond to any separately-distributed project: such a name +might be used to indicate an abstract capability which could be supplied +by one of multiple projects. E.g., multiple projects might supply +RDBMS bindings for use by a given ORM: each project might declare +that it provides ``ORM-bindings``, allowing other projects to depend +only on having at most one of them installed. + +A version declaration may be supplied and must follow the rules described +in `Version Specifiers`_. The distribution's version number will be implied +if none is specified. + +Examples:: + + Provides-Dist: OtherProject + Provides-Dist: AnotherProject (3.4) + Provides-Dist: virtual_package + + +Obsoletes-Dist (multiple use) +::::::::::::::::::::::::::::: + +Each entry contains a string describing a distutils project's distribution +which this distribution renders obsolete, meaning that the two projects +should not be installed at the same time. + +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. + +Examples:: + + Obsoletes-Dist: Gorgon + Obsoletes-Dist: OtherProject (<3.0) + + +Requires-Python +::::::::::::::: + +This field specifies the Python version(s) that the distribution is +guaranteed to be compatible with. + +Version numbers must be in the format specified in `Version Specifiers`_. + +Examples:: + + Requires-Python: 2.5 + Requires-Python: >2.1 + Requires-Python: >=2.3.4 + Requires-Python: >=2.5,<2.7 + + +Requires-External (multiple use) +:::::::::::::::::::::::::::::::: + +Each entry contains a string describing some dependency in the +system that the distribution is to be used. This field is intended to +serve as a hint to downstream project maintainers, and has no +semantics which are meaningful to the ``distutils`` distribution. + +The format of a requirement string is a name of an external +dependency, optionally followed by a version declaration within +parentheses. + +Because they refer to non-Python software releases, version numbers +for this field are **not** required to conform to the format +specified in PEP 386: they should correspond to the +version scheme used by the external dependency. + +Notice that there's is no particular rule on the strings to be used. + +Examples:: + + Requires-External: C + Requires-External: libpng (>=1.5) + + +Project-URL (multiple-use) +:::::::::::::::::::::::::: + +A string containing a browsable URL for the project and a label for it, +separated by a comma. + +Example:: + + Bug Tracker, http://bitbucket.org/tarek/distribute/issues/ + +The label is a free text limited to 32 signs. + + +Provides-Extra (multiple use) +::::::::::::::::::::::::::::: + +A string containing the name of an optional feature. Must be a valid Python +identifier. May be used to make a dependency conditional on whether the +optional feature has been requested. + +Example:: + + Name: beaglevote + Provides-Extra: pdf + Requires-Dist: reportlab; extra == 'pdf' + Requires-Dist: nose; extra == 'test' + Requires-Dist: sphinx; extra == 'doc' + +A second distribution requires an optional dependency by placing it +inside square brackets and can request multiple features by separating +them with a comma (,). + +The full set of requirements is the union of the `Requires-Dist` sets +evaluated with `extra` set to `None` and then to the name of each +requested feature. + +Example:: + + Requires-Dist: beaglevote[pdf] + -> requires beaglevote, reportlab + + Requires-Dist: beaglevote[test, doc] + -> requires beaglevote, sphinx, nose + +Two feature names `test` and `doc` are reserved to mark dependencies that +are needed for running automated tests and generating documentation, +respectively. + +It is legal to specify `Provides-Extra` without referencing it in any +`Requires-Dist`. It is an error to request a feature name that has +not been declared with `Provides-Extra`. + + +Extension (multiple-use) +:::::::::::::::::::::::: + +An ASCII string, not containing whitespace or the - character, that +indicates the presence of extended metadata. Additional tags defined by +the extension should be of the form string-Name:: + + Extension: Chili + Chili-Type: Poblano + Chili-Heat: Mild + + +Version Specifiers +================== + +Version specifiers are a series of conditional operators and +version numbers, separated by commas. Conditional operators +must be one of "<", ">", "<=", ">=", "==" and "!=". + +Any number of conditional operators can be specified, e.g. +the string ">1.0, !=1.3.4, <2.0" is a legal version declaration. +The comma (",") is equivalent to the **and** operator. + +Each version number must be in the format specified in PEP 386. + +When a version is provided, it always includes all versions that +starts with the same value. For example the "2.5" version of Python +will include versions like "2.5.2" or "2.5.3". Pre and post releases +in that case are excluded. So in our example, versions like "2.5a1" are +not included when "2.5" is used. If the first version of the range is +required, it has to be explicitly given. In our example, it will be +"2.5.0". + +Notice that some projects might omit the ".0" prefix for the first release +of the "2.5.x" series: + +- 2.5 +- 2.5.1 +- 2.5.2 +- etc. + +In that case, "2.5.0" will have to be explicitly used to avoid any confusion +between the "2.5" notation that represents the full range. It is a recommended +practice to use schemes of the same length for a series to completely avoid +this problem. + +Some Examples: + +- ``Requires-Dist: zope.interface (3.1)``: any version that starts with 3.1, + excluding post or pre-releases. +- ``Requires-Dist: zope.interface (==3.1)``: equivalent to ``Requires-Dist: + zope.interface (3.1)``. +- ``Requires-Dist: zope.interface (3.1.0)``: any version that starts with + 3.1.0, excluding post or pre-releases. Since that particular project doesn't + use more than 3 digits, it also means "only the 3.1.0 release". +- ``Requires-Python: 3``: Any Python 3 version, no matter wich one, excluding + post or pre-releases. +- ``Requires-Python: >=2.6,<3``: Any version of Python 2.6 or 2.7, including + post releases of 2.6, pre and post releases of 2.7. It excludes pre releases + of Python 3. +- ``Requires-Python: 2.6.2``: Equivalent to ">=2.6.2,<2.6.3". So this includes + only Python 2.6.2. Of course, if Python was numbered with 4 digits, it would + have include all versions of the 2.6.2 series. +- ``Requires-Python: 2.5.0``: Equivalent to ">=2.5.0,<2.5.1". +- ``Requires-Dist: zope.interface (3.1,!=3.1.3)``: any version that starts with + 3.1, excluding post or pre-releases of 3.1 *and* excluding any version that + starts with "3.1.3". For this particular project, this means: "any version + of the 3.1 series but not 3.1.3". This is equivalent to: + ">=3.1,!=3.1.3,<3.2". + +Environment markers +=================== + +An **environment marker** is a marker that can be added at the end of a +field after a semi-colon (";"), to add a condition about the execution +environment. + +Here are some example of fields using such markers:: + + Requires-Dist: pywin32 (>1.0); sys.platform == 'win32' + Obsoletes-Dist: pywin31; sys.platform == 'win32' + Requires-Dist: foo (1,!=1.3); platform.machine == 'i386' + Requires-Dist: bar; python_version == '2.4' or python_version == '2.5' + Requires-External: libxslt; 'linux' in sys.platform + +The micro-language behind this is the simplest possible: it compares only +strings, with the ``==`` and ``in`` operators (and their opposites), and +with the ability to combine expressions. Parethesis are also supported for +grouping. + +The pseudo-grammar is :: + + EXPR [in|==|!=|not in]?EXPR [or|and] ... + +where ``EXPR`` belongs to any of those: + +- python_version = '%s.%s' % (sys.version_info[0], sys.version_info[1]) +- python_full_version = sys.version.split()[0] +- os.name = os.name +- sys.platform = sys.platform +- platform.version = platform.version() +- platform.machine = platform.machine() +- platform.python_implementation = platform.python_implementation() +- a free string, like ``'2.4'``, or ``'win32'`` +- extra = (name of requested feature) or None + +Notice that ``in`` is restricted to strings, meaning that it is not possible +to use other sequences like tuples or lists on the right side. + +The fields that benefit from this marker are: + +- Requires-Python +- Requires-External +- Requires-Dist +- Setup-Requires-Dist +- Provides-Dist +- Obsoletes-Dist +- Classifier + +(The `extra` variable is only meaningful for Requires-Dist.) + +Summary of Differences From PEP 345 +=================================== + +* Values are now expected to be UTF-8 + +* Metadata-Version is now 1.3. + +* Added `extra` to environment markers. + +* Changed fields: + + - Requires-Dist + +* Added fields: + + - Setup-Requires-Dist + - Provides-Extra + - Extension + +References +========== + +This document specifies version 1.3 of the metadata format. +Version 1.0 is specified in PEP 241. +Version 1.1 is specified in PEP 314. +Version 1.2 is specified in PEP 345. + +.. [1] reStructuredText markup: + http://docutils.sourceforge.net/ + +.. _`Python Package Index`: http://pypi.python.org/pypi/ + +.. [2] RFC 822 Long Header Fields: + http://www.freesoft.org/CIE/RFC/822/7.htm + +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 + End: -- Repository URL: http://hg.python.org/peps From python-checkins at python.org Fri Aug 31 16:13:56 2012 From: python-checkins at python.org (nick.coghlan) Date: Fri, 31 Aug 2012 16:13:56 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315828=3A_Restore_?= =?utf-8?q?support_for_C_extension_modules_in_imp=2Eload=5Fmodule=28=29?= Message-ID: <3X7jH81YcWzQKj@mail.python.org> http://hg.python.org/cpython/rev/9ba57938f54d changeset: 78816:9ba57938f54d user: Nick Coghlan date: Sat Sep 01 00:13:45 2012 +1000 summary: Issue #15828: Restore support for C extension modules in imp.load_module() files: Lib/imp.py | 6 ++++-- Lib/test/test_imp.py | 29 +++++++++++++++++++++++++++++ Lib/test/test_import.py | 19 ------------------- Misc/NEWS | 2 ++ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Lib/imp.py b/Lib/imp.py --- a/Lib/imp.py +++ b/Lib/imp.py @@ -153,13 +153,15 @@ warnings.simplefilter('ignore') if mode and (not mode.startswith(('r', 'U')) or '+' in mode): raise ValueError('invalid file open mode {!r}'.format(mode)) - elif file is None and type_ in {PY_SOURCE, PY_COMPILED}: + elif file is None and type_ in {PY_SOURCE, PY_COMPILED, C_EXTENSION}: msg = 'file object required for import (type code {})'.format(type_) raise ValueError(msg) elif type_ == PY_SOURCE: return load_source(name, filename, file) elif type_ == PY_COMPILED: return load_compiled(name, filename, file) + elif type_ == C_EXTENSION: + return load_dynamic(name, filename, file) elif type_ == PKG_DIRECTORY: return load_package(name, filename) elif type_ == C_BUILTIN: @@ -167,7 +169,7 @@ elif type_ == PY_FROZEN: return init_frozen(name) else: - msg = "Don't know how to import {} (type code {}".format(name, type_) + msg = "Don't know how to import {} (type code {})".format(name, type_) raise ImportError(msg, name=name) 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 @@ -186,6 +186,35 @@ self.assertRaises(SyntaxError, imp.find_module, "badsyntax_pep3120", [path]) + def test_load_from_source(self): + # Verify that the imp module can correctly load and find .py files + # XXX (ncoghlan): It would be nice to use support.CleanImport + # here, but that breaks because the os module registers some + # handlers in copy_reg on import. Since CleanImport doesn't + # revert that registration, the module is left in a broken + # state after reversion. Reinitialising the module contents + # and just reverting os.environ to its previous state is an OK + # workaround + orig_path = os.path + orig_getenv = os.getenv + with support.EnvironmentVarGuard(): + x = imp.find_module("os") + self.addCleanup(x[0].close) + new_os = imp.load_module("os", *x) + self.assertIs(os, new_os) + self.assertIs(orig_path, new_os.path) + self.assertIsNot(orig_getenv, new_os.getenv) + + @support.cpython_only + def test_issue15828_load_extensions(self): + # Issue 15828 picked up that the adapter between the old imp API + # and importlib couldn't handle C extensions + example = "_heapq" + x = imp.find_module(example) + self.addCleanup(x[0].close) + mod = imp.load_module(example, *x) + self.assertEqual(mod.__name__, example) + 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/Lib/test/test_import.py b/Lib/test/test_import.py --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -149,25 +149,6 @@ self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(mode)) - def test_imp_module(self): - # Verify that the imp module can correctly load and find .py files - # XXX (ncoghlan): It would be nice to use support.CleanImport - # here, but that breaks because the os module registers some - # handlers in copy_reg on import. Since CleanImport doesn't - # revert that registration, the module is left in a broken - # state after reversion. Reinitialising the module contents - # and just reverting os.environ to its previous state is an OK - # workaround - orig_path = os.path - orig_getenv = os.getenv - with EnvironmentVarGuard(): - x = imp.find_module("os") - self.addCleanup(x[0].close) - new_os = imp.load_module("os", *x) - self.assertIs(os, new_os) - self.assertIs(orig_path, new_os.path) - self.assertIsNot(orig_getenv, new_os.getenv) - def test_bug7732(self): source = TESTFN + '.py' os.mkdir(source) diff --git a/Misc/NEWS b/Misc/NEWS --- a/Misc/NEWS +++ b/Misc/NEWS @@ -54,6 +54,8 @@ Library ------- +- Issue #15828: Restore support for C extensions in imp.load_module() + - Issue #10650: Deprecate the watchexp parameter of the Decimal.quantize() method. -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 31 17:31:31 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 31 Aug 2012 17:31:31 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython=3A_Issue_=2315828=3A_Don=27t_?= =?utf-8?q?try_to_close_a_file_if_imp=2Efind=5Fmodule=28=29_doesn=27t?= Message-ID: <3X7l0g171SzQMc@mail.python.org> http://hg.python.org/cpython/rev/d54f047312a8 changeset: 78817:d54f047312a8 user: Brett Cannon date: Fri Aug 31 11:31:20 2012 -0400 summary: Issue #15828: Don't try to close a file if imp.find_module() doesn't return one. files: Lib/test/test_imp.py | 4 +++- 1 files changed, 3 insertions(+), 1 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 @@ -211,7 +211,9 @@ # and importlib couldn't handle C extensions example = "_heapq" x = imp.find_module(example) - self.addCleanup(x[0].close) + file_ = x[0] + if file_ is not None: + self.addCleanup(file_.close) mod = imp.load_module(example, *x) self.assertEqual(mod.__name__, example) -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 31 17:52:36 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 31 Aug 2012 17:52:36 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?benchmarks=3A_Ignore_more_stuff=2E?= Message-ID: <3X7lT0697tzQLq@mail.python.org> http://hg.python.org/benchmarks/rev/8cc15b202237 changeset: 161:8cc15b202237 user: Brett Cannon date: Fri Aug 31 11:52:10 2012 -0400 summary: Ignore more stuff. files: .hgignore | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -1,7 +1,12 @@ - syntax: glob +*.swp *.pyc *.pyo *.pyd *.o lib/2to3/lib2to3/*.pickle +*.cover +*~ +.coverage +coverage/ +htmlcov/ -- Repository URL: http://hg.python.org/benchmarks From python-checkins at python.org Fri Aug 31 17:52:38 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 31 Aug 2012 17:52:38 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?benchmarks=3A_Pathlib_works_under_Pyt?= =?utf-8?q?hon_3=2E?= Message-ID: <3X7lT21BBTzQMV@mail.python.org> http://hg.python.org/benchmarks/rev/873baf08045e changeset: 162:873baf08045e user: Brett Cannon date: Fri Aug 31 11:52:30 2012 -0400 summary: Pathlib works under Python 3. files: make_perf3.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/make_perf3.sh b/make_perf3.sh --- a/make_perf3.sh +++ b/make_perf3.sh @@ -30,7 +30,7 @@ cp "${srcdir}/perf.py" perf.py ${CONVERT} perf.py -SAFE_LIBS="2to3 mako" +SAFE_LIBS="2to3 mako pathlib" mkdir lib for safe_lib in ${SAFE_LIBS}; do cp -a "${srcdir}/lib/${safe_lib}" lib/${safe_lib} -- Repository URL: http://hg.python.org/benchmarks From python-checkins at python.org Fri Aug 31 21:42:26 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 31 Aug 2012 21:42:26 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Ignore_the_Tools_director?= =?utf-8?q?y_when_generating_coverage_reports=2E?= Message-ID: <3X7rZB10Y6zQFL@mail.python.org> http://hg.python.org/devguide/rev/dba748ac63b4 changeset: 541:dba748ac63b4 user: Brett Cannon date: Fri Aug 31 15:42:20 2012 -0400 summary: Ignore the Tools directory when generating coverage reports. files: coverage.rst | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/coverage.rst b/coverage.rst --- a/coverage.rst +++ b/coverage.rst @@ -128,7 +128,7 @@ But one of the strengths of coverage.py is its HTML-based reports which let you visually see what lines of code were not tested:: - ./python -m coverage html -i --omit="*/test/*,*/tests/*" + ./python -m coverage html -i --omit="*/test/*,*/tests/*,*/Tools/*" This will generate an HTML report in a directory named ``htmlcov`` which ignores any errors that may arise and -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Fri Aug 31 21:58:14 2012 From: python-checkins at python.org (brett.cannon) Date: Fri, 31 Aug 2012 21:58:14 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?devguide=3A_Tweak_the_last_commit=2E?= Message-ID: <3X7rwQ0qfZzQ80@mail.python.org> http://hg.python.org/devguide/rev/aadb78f591c8 changeset: 542:aadb78f591c8 user: Brett Cannon date: Fri Aug 31 15:58:08 2012 -0400 summary: Tweak the last commit. files: coverage.rst | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/coverage.rst b/coverage.rst --- a/coverage.rst +++ b/coverage.rst @@ -128,13 +128,13 @@ But one of the strengths of coverage.py is its HTML-based reports which let you visually see what lines of code were not tested:: - ./python -m coverage html -i --omit="*/test/*,*/tests/*,*/Tools/*" + ./python -m coverage html -i --omit="*/test/*,*/tests/*,Tools/*" This will generate an HTML report in a directory named ``htmlcov`` which -ignores any errors that may arise and -ignores test modules. You can then open the ``htmlcov/index.html`` file -in a web browser to view the coverage results along with pages that visibly -show what lines of code were or were not executed. +ignores any errors that may arise and ignores modules for which test coverage is +unimportant (e.g. tests). You can then open the ``htmlcov/index.html`` file in a +web browser to view the coverage results along with pages that visibly show what +lines of code were or were not executed. .. _branch_coverage: -- Repository URL: http://hg.python.org/devguide From python-checkins at python.org Fri Aug 31 23:11:50 2012 From: python-checkins at python.org (trent.nelson) Date: Fri, 31 Aug 2012 23:11:50 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=283=2E2=29=3A_Remove_trailin?= =?utf-8?q?g_whitespace_in_order_to_silence_warnings_on_HP-UX=2E?= Message-ID: <3X7tYL6WxszQ4N@mail.python.org> http://hg.python.org/cpython/rev/c0c7b1998306 changeset: 78818:c0c7b1998306 branch: 3.2 parent: 78814:8877d25119ef user: Trent Nelson date: Fri Aug 31 17:11:39 2012 -0400 summary: Remove trailing whitespace in order to silence warnings on HP-UX. files: Include/pyfpe.h | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/pyfpe.h b/Include/pyfpe.h --- a/Include/pyfpe.h +++ b/Include/pyfpe.h @@ -4,8 +4,8 @@ extern "C" { #endif /* - --------------------------------------------------------------------- - / Copyright (c) 1996. \ + --------------------------------------------------------------------- + / Copyright (c) 1996. \ | The Regents of the University of California. | | All rights reserved. | | | @@ -37,8 +37,8 @@ | opinions of authors expressed herein do not necessarily state or | | reflect those of the United States Government or the University | | of California, and shall not be used for advertising or product | - \ endorsement purposes. / - --------------------------------------------------------------------- + \ endorsement purposes. / + --------------------------------------------------------------------- */ /* -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 31 23:14:39 2012 From: python-checkins at python.org (trent.nelson) Date: Fri, 31 Aug 2012 23:14:39 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=28merge_3=2E2_-=3E_default?= =?utf-8?q?=29=3A_Merge_whitespace_fix_from_3=2E2=2E?= Message-ID: <3X7tcb3QLJzQLX@mail.python.org> http://hg.python.org/cpython/rev/815b88454e3e changeset: 78819:815b88454e3e parent: 78817:d54f047312a8 parent: 78818:c0c7b1998306 user: Trent Nelson date: Fri Aug 31 17:14:31 2012 -0400 summary: Merge whitespace fix from 3.2. files: Include/pyfpe.h | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/pyfpe.h b/Include/pyfpe.h --- a/Include/pyfpe.h +++ b/Include/pyfpe.h @@ -4,8 +4,8 @@ extern "C" { #endif /* - --------------------------------------------------------------------- - / Copyright (c) 1996. \ + --------------------------------------------------------------------- + / Copyright (c) 1996. \ | The Regents of the University of California. | | All rights reserved. | | | @@ -37,8 +37,8 @@ | opinions of authors expressed herein do not necessarily state or | | reflect those of the United States Government or the University | | of California, and shall not be used for advertising or product | - \ endorsement purposes. / - --------------------------------------------------------------------- + \ endorsement purposes. / + --------------------------------------------------------------------- */ /* -- Repository URL: http://hg.python.org/cpython From python-checkins at python.org Fri Aug 31 23:16:00 2012 From: python-checkins at python.org (trent.nelson) Date: Fri, 31 Aug 2012 23:16:00 +0200 (CEST) Subject: [Python-checkins] =?utf-8?q?cpython_=282=2E7=29=3A_Remove_trailin?= =?utf-8?q?g_whitespace_in_order_to_silence_warnings_on_HP-UX=2E?= Message-ID: <3X7tf873mmzQLq@mail.python.org> http://hg.python.org/cpython/rev/7b076911f5f9 changeset: 78820:7b076911f5f9 branch: 2.7 parent: 78813:69952b5599b5 user: Trent Nelson date: Fri Aug 31 17:15:49 2012 -0400 summary: Remove trailing whitespace in order to silence warnings on HP-UX. files: Include/pyfpe.h | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/pyfpe.h b/Include/pyfpe.h --- a/Include/pyfpe.h +++ b/Include/pyfpe.h @@ -4,8 +4,8 @@ extern "C" { #endif /* - --------------------------------------------------------------------- - / Copyright (c) 1996. \ + --------------------------------------------------------------------- + / Copyright (c) 1996. \ | The Regents of the University of California. | | All rights reserved. | | | @@ -37,8 +37,8 @@ | opinions of authors expressed herein do not necessarily state or | | reflect those of the United States Government or the University | | of California, and shall not be used for advertising or product | - \ endorsement purposes. / - --------------------------------------------------------------------- + \ endorsement purposes. / + --------------------------------------------------------------------- */ /* -- Repository URL: http://hg.python.org/cpython