From python-3000-checkins at python.org Mon Nov 3 21:31:38 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Mon, 3 Nov 2008 21:31:38 +0100 (CET) Subject: [Python-3000-checkins] r67088 - in python/branches/py3k: Doc/ACKS.txt Include/compile.h Lib/modulefinder.py Lib/test/test_descr.py Lib/test/test_io.py Lib/test/test_modulefinder.py Lib/test/test_parser.py Misc/ACKS Modules/_fileio.c Modules/parsermodule.c Python/future.c Tools/scripts/findnocoding.py Message-ID: <20081103203138.E69B31E400C@bag.python.org> Author: benjamin.peterson Date: Mon Nov 3 21:31:38 2008 New Revision: 67088 Log: Merged revisions 67028,67040,67044,67046,67052,67065,67070,67077,67082 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67028 | benjamin.peterson | 2008-10-25 18:27:07 -0500 (Sat, 25 Oct 2008) | 1 line don't use a catch-all ........ r67040 | armin.rigo | 2008-10-28 12:01:21 -0500 (Tue, 28 Oct 2008) | 5 lines Fix one of the tests: it relied on being present in an "output test" in order to actually test what it was supposed to test, i.e. that the code in the __del__ method did not crash. Use instead the new helper test_support.captured_output(). ........ r67044 | amaury.forgeotdarc | 2008-10-29 18:15:57 -0500 (Wed, 29 Oct 2008) | 3 lines Correct error message in io.open(): closefd=True is the only accepted value with a file name. ........ r67046 | thomas.heller | 2008-10-30 15:18:13 -0500 (Thu, 30 Oct 2008) | 2 lines Fixed a modulefinder crash on certain relative imports. ........ r67052 | christian.heimes | 2008-10-30 16:26:15 -0500 (Thu, 30 Oct 2008) | 1 line Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members. ........ r67065 | benjamin.peterson | 2008-10-30 18:59:18 -0500 (Thu, 30 Oct 2008) | 1 line move unprefixed error into .c file ........ r67070 | benjamin.peterson | 2008-10-31 15:41:44 -0500 (Fri, 31 Oct 2008) | 1 line rephrase has_key doc ........ r67077 | benjamin.peterson | 2008-11-03 09:14:51 -0600 (Mon, 03 Nov 2008) | 1 line #4048 make the parser module accept relative imports as valid ........ r67082 | hirokazu.yamamoto | 2008-11-03 12:03:06 -0600 (Mon, 03 Nov 2008) | 2 lines Issue #3774: Fixed an error when create a Tkinter menu item without command and then remove it. Written by Guilherme Polo (gpolo). ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/ACKS.txt python/branches/py3k/Include/compile.h python/branches/py3k/Lib/modulefinder.py python/branches/py3k/Lib/test/test_descr.py python/branches/py3k/Lib/test/test_io.py python/branches/py3k/Lib/test/test_modulefinder.py python/branches/py3k/Lib/test/test_parser.py python/branches/py3k/Misc/ACKS python/branches/py3k/Modules/_fileio.c python/branches/py3k/Modules/parsermodule.c python/branches/py3k/Python/future.c python/branches/py3k/Tools/scripts/findnocoding.py Modified: python/branches/py3k/Doc/ACKS.txt ============================================================================== --- python/branches/py3k/Doc/ACKS.txt (original) +++ python/branches/py3k/Doc/ACKS.txt Mon Nov 3 21:31:38 2008 @@ -16,6 +16,7 @@ * A. Amoroso * Pehr Anderson * Oliver Andrich + * Heidi Annexstad * Jes?s Cea Avi?n * Daniel Barclay * Chris Barker Modified: python/branches/py3k/Include/compile.h ============================================================================== --- python/branches/py3k/Include/compile.h (original) +++ python/branches/py3k/Include/compile.h Mon Nov 3 21:31:38 2008 @@ -32,8 +32,6 @@ PyCompilerFlags *, PyArena *); PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *); -#define ERR_LATE_FUTURE \ -"from __future__ imports must occur at the beginning of the file" #ifdef __cplusplus } Modified: python/branches/py3k/Lib/modulefinder.py ============================================================================== --- python/branches/py3k/Lib/modulefinder.py (original) +++ python/branches/py3k/Lib/modulefinder.py Mon Nov 3 21:31:38 2008 @@ -310,7 +310,10 @@ def _add_badmodule(self, name, caller): if name not in self.badmodules: self.badmodules[name] = {} - self.badmodules[name][caller.__name__] = 1 + if caller: + self.badmodules[name][caller.__name__] = 1 + else: + self.badmodules[name]["-"] = 1 def _safe_import_hook(self, name, caller, fromlist, level=-1): # wrapper for self.import_hook() that won't raise ImportError Modified: python/branches/py3k/Lib/test/test_descr.py ============================================================================== --- python/branches/py3k/Lib/test/test_descr.py (original) +++ python/branches/py3k/Lib/test/test_descr.py Mon Nov 3 21:31:38 2008 @@ -1020,14 +1020,10 @@ def __del__(self_): self.assertEqual(self_.a, 1) self.assertEqual(self_.b, 2) - - save_stderr = sys.stderr - sys.stderr = sys.stdout - h = H() - try: + with test_support.captured_output('stderr') as s: + h = H() del h - finally: - sys.stderr = save_stderr + self.assertEqual(s.getvalue(), '') def test_slots_special(self): # Testing __dict__ and __weakref__ in __slots__... Modified: python/branches/py3k/Lib/test/test_io.py ============================================================================== --- python/branches/py3k/Lib/test/test_io.py (original) +++ python/branches/py3k/Lib/test/test_io.py Mon Nov 3 21:31:38 2008 @@ -1245,6 +1245,7 @@ self.assertRaises(ValueError, io.FileIO, "/some/invalid/name", "rt") self.assertEqual(w.warnings, []) + def test_main(): support.run_unittest(IOTest, BytesIOTest, StringIOTest, BufferedReaderTest, BufferedWriterTest, Modified: python/branches/py3k/Lib/test/test_modulefinder.py ============================================================================== --- python/branches/py3k/Lib/test/test_modulefinder.py (original) +++ python/branches/py3k/Lib/test/test_modulefinder.py Mon Nov 3 21:31:38 2008 @@ -190,6 +190,19 @@ a/b/c/f.py """] +relative_import_test_3 = [ + "a.module", + ["a", "a.module"], + ["a.bar"], + [], + """\ +a/__init__.py + def foo(): pass +a/module.py + from . import foo + from . import bar +"""] + def open_file(path): ##print "#", os.path.abspath(path) dirname = os.path.dirname(path) @@ -256,6 +269,9 @@ def test_relative_imports_2(self): self._do_test(relative_import_test_2) + def test_relative_imports_3(self): + self._do_test(relative_import_test_3) + def test_main(): distutils.log.set_threshold(distutils.log.WARN) support.run_unittest(ModuleFinderTest) Modified: python/branches/py3k/Lib/test/test_parser.py ============================================================================== --- python/branches/py3k/Lib/test/test_parser.py (original) +++ python/branches/py3k/Lib/test/test_parser.py Mon Nov 3 21:31:38 2008 @@ -1,4 +1,5 @@ import parser +import os import unittest import sys from test import support @@ -172,6 +173,7 @@ "from sys.path import (dirname, basename as my_basename)") self.check_suite( "from sys.path import (dirname, basename as my_basename,)") + self.check_suite("from .bogus import x") def test_basic_import_statement(self): self.check_suite("import sys") Modified: python/branches/py3k/Misc/ACKS ============================================================================== --- python/branches/py3k/Misc/ACKS (original) +++ python/branches/py3k/Misc/ACKS Mon Nov 3 21:31:38 2008 @@ -61,6 +61,7 @@ Steven Bethard Stephen Bevan Ron Bickers +David Binger Dominic Binks Philippe Biondi Stuart Bishop Modified: python/branches/py3k/Modules/_fileio.c ============================================================================== --- python/branches/py3k/Modules/_fileio.c (original) +++ python/branches/py3k/Modules/_fileio.c Mon Nov 3 21:31:38 2008 @@ -251,7 +251,7 @@ self->closefd = 1; if (!closefd) { PyErr_SetString(PyExc_ValueError, - "Cannot use closefd=True with file name"); + "Cannot use closefd=False with file name"); goto error; } Modified: python/branches/py3k/Modules/parsermodule.c ============================================================================== --- python/branches/py3k/Modules/parsermodule.c (original) +++ python/branches/py3k/Modules/parsermodule.c Mon Nov 3 21:31:38 2008 @@ -1710,10 +1710,10 @@ count_from_dots(node *tree) { int i; - for (i = 0; i < NCH(tree); i++) + for (i = 1; i < NCH(tree); i++) if (TYPE(CHILD(tree, i)) != DOT) break; - return i; + return i-1; } /* 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' | Modified: python/branches/py3k/Python/future.c ============================================================================== --- python/branches/py3k/Python/future.c (original) +++ python/branches/py3k/Python/future.c Mon Nov 3 21:31:38 2008 @@ -8,6 +8,8 @@ #include "symtable.h" #define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined" +#define ERR_LATE_FUTURE \ +"from __future__ imports must occur at the beginning of the file" static int future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename) Modified: python/branches/py3k/Tools/scripts/findnocoding.py ============================================================================== --- python/branches/py3k/Tools/scripts/findnocoding.py (original) +++ python/branches/py3k/Tools/scripts/findnocoding.py Mon Nov 3 21:31:38 2008 @@ -12,7 +12,7 @@ # our pysource module finds Python source files try: import pysource -except: +except ImportError: # emulate the module with a simple os.walk class pysource: has_python_ext = looks_like_python = can_be_compiled = None From python-3000-checkins at python.org Mon Nov 3 22:29:10 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Mon, 3 Nov 2008 22:29:10 +0100 (CET) Subject: [Python-3000-checkins] r67090 - python/branches/py3k/Lib/test/test_descr.py Message-ID: <20081103212910.3FEEA1E4002@bag.python.org> Author: benjamin.peterson Date: Mon Nov 3 22:29:09 2008 New Revision: 67090 Log: fix test_descr Modified: python/branches/py3k/Lib/test/test_descr.py Modified: python/branches/py3k/Lib/test/test_descr.py ============================================================================== --- python/branches/py3k/Lib/test/test_descr.py (original) +++ python/branches/py3k/Lib/test/test_descr.py Mon Nov 3 22:29:09 2008 @@ -1020,7 +1020,7 @@ def __del__(self_): self.assertEqual(self_.a, 1) self.assertEqual(self_.b, 2) - with test_support.captured_output('stderr') as s: + with support.captured_output('stderr') as s: h = H() del h self.assertEqual(s.getvalue(), '') From python-3000-checkins at python.org Tue Nov 4 01:31:31 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Tue, 4 Nov 2008 01:31:31 +0100 (CET) Subject: [Python-3000-checkins] r67092 - in python/branches/py3k: Lib/pickle.py Modules/_pickle.c Message-ID: <20081104003131.DC3CA1E4002@bag.python.org> Author: hirokazu.yamamoto Date: Tue Nov 4 01:31:31 2008 New Revision: 67092 Log: Blocked revisions 67002 via svnmerge ........ r67002 | hirokazu.yamamoto | 2008-10-23 09:37:33 +0900 | 1 line Issue #4183: Some tests didn't run with pickle.HIGHEST_PROTOCOL. ........ Modified: python/branches/py3k/Lib/pickle.py python/branches/py3k/Modules/_pickle.c Modified: python/branches/py3k/Lib/pickle.py ============================================================================== --- python/branches/py3k/Lib/pickle.py (original) +++ python/branches/py3k/Lib/pickle.py Tue Nov 4 01:31:31 2008 @@ -345,6 +345,9 @@ else: self.write(PERSID + str(pid).encode("ascii") + b'\n') + def _isiter(self, obj): + return hasattr(obj, '__next__') and hasattr(obj, '__iter__') + def save_reduce(self, func, args, state=None, listitems=None, dictitems=None, obj=None): # This API is called by some subclasses @@ -357,6 +360,16 @@ if not hasattr(func, '__call__'): raise PicklingError("func from save_reduce() should be callable") + # Assert that listitems is an iterator + if listitems is not None and not self._isiter(listitems): + raise PicklingError("listitems from save_reduce() should be an " + "iterator") + + # Assert that dictitems is an iterator + if dictitems is not None and not self._isiter(dictitems): + raise PicklingError("dictitems from save_reduce() should be an " + "iterator") + save = self.save write = self.write Modified: python/branches/py3k/Modules/_pickle.c ============================================================================== --- python/branches/py3k/Modules/_pickle.c (original) +++ python/branches/py3k/Modules/_pickle.c Tue Nov 4 01:31:31 2008 @@ -1963,7 +1963,6 @@ PyObject *state = NULL; PyObject *listitems = Py_None; PyObject *dictitems = Py_None; - Py_ssize_t size; int use_newobj = self->proto >= 2; @@ -1971,13 +1970,6 @@ const char build_op = BUILD; const char newobj_op = NEWOBJ; - size = PyTuple_Size(args); - if (size < 2 || size > 5) { - PyErr_SetString(PicklingError, "tuple returned by " - "__reduce__ must contain 2 through 5 elements"); - return -1; - } - if (!PyArg_UnpackTuple(args, "save_reduce", 2, 5, &callable, &argtup, &state, &listitems, &dictitems)) return -1; @@ -2154,6 +2146,7 @@ PyObject *reduce_value = NULL; PyObject *memo_key = NULL; int status = 0; + Py_ssize_t size; if (Py_EnterRecursiveCall(" while pickling an object") < 0) return -1; @@ -2332,6 +2325,13 @@ goto error; } + size = PyTuple_Size(reduce_value); + if (size < 2 || size > 5) { + PyErr_SetString(PicklingError, "tuple returned by " + "__reduce__ must contain 2 through 5 elements"); + goto error; + } + status = save_reduce(self, reduce_value, obj); if (0) { From python-3000-checkins at python.org Tue Nov 4 01:35:10 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Tue, 4 Nov 2008 01:35:10 +0100 (CET) Subject: [Python-3000-checkins] r67093 - in python/branches/py3k: Lib/pickle.py Modules/_pickle.c Message-ID: <20081104003510.CF7F41E4029@bag.python.org> Author: hirokazu.yamamoto Date: Tue Nov 4 01:35:10 2008 New Revision: 67093 Log: Sorry, r67092 is commit miss.... Modified: python/branches/py3k/Lib/pickle.py python/branches/py3k/Modules/_pickle.c Modified: python/branches/py3k/Lib/pickle.py ============================================================================== --- python/branches/py3k/Lib/pickle.py (original) +++ python/branches/py3k/Lib/pickle.py Tue Nov 4 01:35:10 2008 @@ -345,9 +345,6 @@ else: self.write(PERSID + str(pid).encode("ascii") + b'\n') - def _isiter(self, obj): - return hasattr(obj, '__next__') and hasattr(obj, '__iter__') - def save_reduce(self, func, args, state=None, listitems=None, dictitems=None, obj=None): # This API is called by some subclasses @@ -360,16 +357,6 @@ if not hasattr(func, '__call__'): raise PicklingError("func from save_reduce() should be callable") - # Assert that listitems is an iterator - if listitems is not None and not self._isiter(listitems): - raise PicklingError("listitems from save_reduce() should be an " - "iterator") - - # Assert that dictitems is an iterator - if dictitems is not None and not self._isiter(dictitems): - raise PicklingError("dictitems from save_reduce() should be an " - "iterator") - save = self.save write = self.write Modified: python/branches/py3k/Modules/_pickle.c ============================================================================== --- python/branches/py3k/Modules/_pickle.c (original) +++ python/branches/py3k/Modules/_pickle.c Tue Nov 4 01:35:10 2008 @@ -1963,6 +1963,7 @@ PyObject *state = NULL; PyObject *listitems = Py_None; PyObject *dictitems = Py_None; + Py_ssize_t size; int use_newobj = self->proto >= 2; @@ -1970,6 +1971,13 @@ const char build_op = BUILD; const char newobj_op = NEWOBJ; + size = PyTuple_Size(args); + if (size < 2 || size > 5) { + PyErr_SetString(PicklingError, "tuple returned by " + "__reduce__ must contain 2 through 5 elements"); + return -1; + } + if (!PyArg_UnpackTuple(args, "save_reduce", 2, 5, &callable, &argtup, &state, &listitems, &dictitems)) return -1; @@ -2146,7 +2154,6 @@ PyObject *reduce_value = NULL; PyObject *memo_key = NULL; int status = 0; - Py_ssize_t size; if (Py_EnterRecursiveCall(" while pickling an object") < 0) return -1; @@ -2325,13 +2332,6 @@ goto error; } - size = PyTuple_Size(reduce_value); - if (size < 2 || size > 5) { - PyErr_SetString(PicklingError, "tuple returned by " - "__reduce__ must contain 2 through 5 elements"); - goto error; - } - status = save_reduce(self, reduce_value, obj); if (0) { From python-3000-checkins at python.org Tue Nov 4 07:26:28 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Tue, 4 Nov 2008 07:26:28 +0100 (CET) Subject: [Python-3000-checkins] r67095 - python/branches/py3k/Lib/tkinter/__init__.py Message-ID: <20081104062628.06F131E4002@bag.python.org> Author: hirokazu.yamamoto Date: Tue Nov 4 07:26:27 2008 New Revision: 67095 Log: Issue #3774: Fixed an error when create a Tkinter menu item without command and then remove it. Written by Guilherme Polo (gpolo). Ported r67082. Modified: python/branches/py3k/Lib/tkinter/__init__.py Modified: python/branches/py3k/Lib/tkinter/__init__.py ============================================================================== --- python/branches/py3k/Lib/tkinter/__init__.py (original) +++ python/branches/py3k/Lib/tkinter/__init__.py Tue Nov 4 07:26:27 2008 @@ -1913,6 +1913,8 @@ cnf = _cnfmerge((cnf, kw)) self.widgetName = widgetName BaseWidget._setup(self, master, cnf) + if self._tclCommands is None: + self._tclCommands = [] classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)] for k, v in classes: del cnf[k] @@ -2648,21 +2650,20 @@ """Add separator at INDEX.""" self.insert(index, 'separator', cnf or kw) def delete(self, index1, index2=None): - """Delete menu items between INDEX1 and INDEX2 (not included).""" + """Delete menu items between INDEX1 and INDEX2 (included).""" if index2 is None: index2 = index1 - cmds = [] - (num_index1, num_index2) = (self.index(index1), self.index(index2)) - if (num_index1 is not None) and (num_index2 is not None): - for i in range(num_index1, num_index2 + 1): - if 'command' in self.entryconfig(i): - c = str(self.entrycget(i, 'command')) - if c in self._tclCommands: - cmds.append(c) - self.tk.call(self._w, 'delete', index1, index2) - for c in cmds: - self.deletecommand(c) + num_index1, num_index2 = self.index(index1), self.index(index2) + if (num_index1 is None) or (num_index2 is None): + num_index1, num_index2 = 0, -1 + + for i in range(num_index1, num_index2 + 1): + if 'command' in self.entryconfig(i): + c = str(self.entrycget(i, 'command')) + if c: + self.deletecommand(c) + self.tk.call(self._w, 'delete', index1, index2) def entrycget(self, index, option): """Return the resource value of an menu item for OPTION at INDEX.""" return self.tk.call(self._w, 'entrycget', index, '-' + option) From python-3000-checkins at python.org Tue Nov 4 21:45:30 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Tue, 4 Nov 2008 21:45:30 +0100 (CET) Subject: [Python-3000-checkins] r67100 - in python/branches/py3k: Misc/NEWS Modules/_multiprocessing/multiprocessing.h Modules/readline.c configure configure.in setup.py Message-ID: <20081104204530.5AEAA1E4054@bag.python.org> Author: martin.v.loewis Date: Tue Nov 4 21:45:29 2008 New Revision: 67100 Log: Merged revisions 67098 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67098 | martin.v.loewis | 2008-11-04 21:40:09 +0100 (Di, 04 Nov 2008) | 2 lines Issue #4204: Fixed module build errors on FreeBSD 4. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_multiprocessing/multiprocessing.h python/branches/py3k/Modules/readline.c python/branches/py3k/configure python/branches/py3k/configure.in python/branches/py3k/setup.py Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Tue Nov 4 21:45:29 2008 @@ -96,6 +96,8 @@ - Issue #4018: Disable "for me" installations on Vista. +- Issue #4204: Fixed module build errors on FreeBSD 4. + Tools/Demos ----------- Modified: python/branches/py3k/Modules/_multiprocessing/multiprocessing.h ============================================================================== --- python/branches/py3k/Modules/_multiprocessing/multiprocessing.h (original) +++ python/branches/py3k/Modules/_multiprocessing/multiprocessing.h Tue Nov 4 21:45:29 2008 @@ -20,7 +20,9 @@ # define SEM_VALUE_MAX LONG_MAX #else # include /* O_CREAT and O_EXCL */ +# include # include +# include # include /* htonl() and ntohl() */ # if HAVE_SEM_OPEN # include Modified: python/branches/py3k/Modules/readline.c ============================================================================== --- python/branches/py3k/Modules/readline.c (original) +++ python/branches/py3k/Modules/readline.c Tue Nov 4 21:45:29 2008 @@ -35,7 +35,11 @@ #define completion_matches(x, y) \ rl_completion_matches((x), ((rl_compentry_func_t *)(y))) #else +#if defined(_RL_FUNCTION_TYPEDEF) extern char **completion_matches(char *, rl_compentry_func_t *); +#else +extern char **completion_matches(char *, CPFunction *); +#endif #endif static void @@ -213,7 +217,11 @@ default completion display. */ rl_completion_display_matches_hook = completion_display_matches_hook ? +#if defined(_RL_FUNCTION_TYPEDEF) (rl_compdisp_func_t *)on_completion_display_matches_hook : 0; +#else + (VFunction *)on_completion_display_matches_hook : 0; +#endif #endif return result; Modified: python/branches/py3k/configure ============================================================================== --- python/branches/py3k/configure (original) +++ python/branches/py3k/configure Tue Nov 4 21:45:29 2008 @@ -2098,11 +2098,18 @@ # but used in struct sockaddr.sa_family. Reported by Tim Rice. SCO_SV/3.2) define_xopen_source=no;; - # On FreeBSD 4.8 and MacOS X 10.2, a bug in ncurses.h means that - # it craps out if _XOPEN_EXTENDED_SOURCE is defined. Apparently, - # this is fixed in 10.3, which identifies itself as Darwin/7.* - # This should hopefully be fixed in FreeBSD 4.9 - FreeBSD/4.8* | Darwin/6* ) + # On FreeBSD 4, the math functions C89 does not cover are never defined + # with _XOPEN_SOURCE and __BSD_VISIBLE does not re-enable them. + FreeBSD/4.*) + define_xopen_source=no;; + # On MacOS X 10.2, a bug in ncurses.h means that it craps out if + # _XOPEN_EXTENDED_SOURCE is defined. Apparently, this is fixed in 10.3, which + # identifies itself as Darwin/7.* + # On Mac OS X 10.4, defining _POSIX_C_SOURCE or _XOPEN_SOURCE + # disables platform specific features beyond repair. + # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE + # has no effect, don't bother defining them + Darwin/[6789].*) define_xopen_source=no;; # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined @@ -2114,13 +2121,6 @@ define_xopen_source=no fi ;; - # On Mac OS X 10.4, defining _POSIX_C_SOURCE or _XOPEN_SOURCE - # disables platform specific features beyond repair. - # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE - # has no effect, don't bother defining them - Darwin/[789].*) - define_xopen_source=no - ;; # On QNX 6.3.2, defining _XOPEN_SOURCE prevents netdb.h from # defining NI_NUMERICHOST. QNX/6.3.2) Modified: python/branches/py3k/configure.in ============================================================================== --- python/branches/py3k/configure.in (original) +++ python/branches/py3k/configure.in Tue Nov 4 21:45:29 2008 @@ -275,11 +275,18 @@ # but used in struct sockaddr.sa_family. Reported by Tim Rice. SCO_SV/3.2) define_xopen_source=no;; - # On FreeBSD 4.8 and MacOS X 10.2, a bug in ncurses.h means that - # it craps out if _XOPEN_EXTENDED_SOURCE is defined. Apparently, - # this is fixed in 10.3, which identifies itself as Darwin/7.* - # This should hopefully be fixed in FreeBSD 4.9 - FreeBSD/4.8* | Darwin/6* ) + # On FreeBSD 4, the math functions C89 does not cover are never defined + # with _XOPEN_SOURCE and __BSD_VISIBLE does not re-enable them. + FreeBSD/4.*) + define_xopen_source=no;; + # On MacOS X 10.2, a bug in ncurses.h means that it craps out if + # _XOPEN_EXTENDED_SOURCE is defined. Apparently, this is fixed in 10.3, which + # identifies itself as Darwin/7.* + # On Mac OS X 10.4, defining _POSIX_C_SOURCE or _XOPEN_SOURCE + # disables platform specific features beyond repair. + # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE + # has no effect, don't bother defining them + Darwin/@<:@6789@:>@.*) define_xopen_source=no;; # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined @@ -291,13 +298,6 @@ define_xopen_source=no fi ;; - # On Mac OS X 10.4, defining _POSIX_C_SOURCE or _XOPEN_SOURCE - # disables platform specific features beyond repair. - # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE - # has no effect, don't bother defining them - Darwin/@<:@789@:>@.*) - define_xopen_source=no - ;; # On QNX 6.3.2, defining _XOPEN_SOURCE prevents netdb.h from # defining NI_NUMERICHOST. QNX/6.3.2) Modified: python/branches/py3k/setup.py ============================================================================== --- python/branches/py3k/setup.py (original) +++ python/branches/py3k/setup.py Tue Nov 4 21:45:29 2008 @@ -1011,7 +1011,7 @@ ) libraries = [] - elif platform in ('freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'): + elif platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'): # FreeBSD's P1003.1b semaphore support is very experimental # and has many known problems. (as of June 2008) macros = dict( # FreeBSD From python-3000-checkins at python.org Wed Nov 5 20:30:32 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Wed, 5 Nov 2008 20:30:32 +0100 (CET) Subject: [Python-3000-checkins] r67106 - in python/branches/py3k: Doc/library/io.rst Lib/test/test_io.py Misc/NEWS Modules/_fileio.c Message-ID: <20081105193032.C45051E4002@bag.python.org> Author: christian.heimes Date: Wed Nov 5 20:30:32 2008 New Revision: 67106 Log: Fixed issue #4233. Changed semantic of _fileio.FileIO's close() method on file objects with closefd=False. The file descriptor is still kept open but the file object behaves like a closed file. The FileIO object also got a new readonly attribute closefd. Approved by Barry Modified: python/branches/py3k/Doc/library/io.rst python/branches/py3k/Lib/test/test_io.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_fileio.c Modified: python/branches/py3k/Doc/library/io.rst ============================================================================== --- python/branches/py3k/Doc/library/io.rst (original) +++ python/branches/py3k/Doc/library/io.rst Wed Nov 5 20:30:32 2008 @@ -213,8 +213,10 @@ .. method:: close() - Flush and close this stream. This method has no effect if the file is - already closed. + Flush and close this stream. This method has no effect if the file is + already closed. Once the file is closed, any operation on the file + (e.g. reading or writing) will raise an :exc:`IOError`. The internal + file descriptor isn't closed if *closefd* was False. .. attribute:: closed Modified: python/branches/py3k/Lib/test/test_io.py ============================================================================== --- python/branches/py3k/Lib/test/test_io.py (original) +++ python/branches/py3k/Lib/test/test_io.py Wed Nov 5 20:30:32 2008 @@ -272,6 +272,29 @@ self.assertRaises(ValueError, io.open, support.TESTFN, 'w', closefd=False) + def testReadClosed(self): + with io.open(support.TESTFN, "w") as f: + f.write("egg\n") + with io.open(support.TESTFN, "r") as f: + file = io.open(f.fileno(), "r", closefd=False) + self.assertEqual(file.read(), "egg\n") + file.seek(0) + file.close() + self.assertRaises(ValueError, file.read) + + def test_no_closefd_with_filename(self): + # can't use closefd in combination with a file name + self.assertRaises(ValueError, io.open, support.TESTFN, "r", closefd=False) + + def test_closefd_attr(self): + with io.open(support.TESTFN, "wb") as f: + f.write(b"egg\n") + with io.open(support.TESTFN, "r") as f: + self.assertEqual(f.buffer.raw.closefd, True) + file = io.open(f.fileno(), "r", closefd=False) + self.assertEqual(file.buffer.raw.closefd, False) + + class MemorySeekTestMixin: def testInit(self): @@ -1237,15 +1260,6 @@ else: self.assert_(issubclass(obj, io.IOBase)) - def test_fileio_warnings(self): - with support.check_warnings() as w: - self.assertEqual(w.warnings, []) - self.assertRaises(TypeError, io.FileIO, []) - self.assertEqual(w.warnings, []) - self.assertRaises(ValueError, io.FileIO, "/some/invalid/name", "rt") - self.assertEqual(w.warnings, []) - - def test_main(): support.run_unittest(IOTest, BytesIOTest, StringIOTest, BufferedReaderTest, BufferedWriterTest, Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 5 20:30:32 2008 @@ -15,6 +15,11 @@ Core and Builtins ----------------- +- Issue #4233: Changed semantic of ``_fileio.FileIO``'s ``close()`` + method on file objects with closefd=False. The file descriptor is still + kept open but the file object behaves like a closed file. The ``FileIO`` + object also got a new readonly attribute ``closefd``. + - Issue #3626: On cygwin, starting python with a non-existent script name would not display anything if the file name is only 1 character long. Modified: python/branches/py3k/Modules/_fileio.c ============================================================================== --- python/branches/py3k/Modules/_fileio.c (original) +++ python/branches/py3k/Modules/_fileio.c Wed Nov 5 20:30:32 2008 @@ -61,10 +61,7 @@ fileio_close(PyFileIOObject *self) { if (!self->closefd) { - if (PyErr_WarnEx(PyExc_RuntimeWarning, - "Trying to close unclosable fd!", 3) < 0) { - return NULL; - } + self->fd = -1; Py_RETURN_NONE; } errno = internal_close(self); @@ -821,6 +818,12 @@ } static PyObject * +get_closefd(PyFileIOObject *self, void *closure) +{ + return PyBool_FromLong((long)(self->closefd)); +} + +static PyObject * get_mode(PyFileIOObject *self, void *closure) { return PyUnicode_FromString(mode_string(self)); @@ -828,6 +831,8 @@ static PyGetSetDef fileio_getsetlist[] = { {"closed", (getter)get_closed, NULL, "True if the file is closed"}, + {"closefd", (getter)get_closefd, NULL, + "True if the file descriptor will be closed"}, {"mode", (getter)get_mode, NULL, "String giving the file mode"}, {0}, }; From python-3000-checkins at python.org Wed Nov 5 20:39:50 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Wed, 5 Nov 2008 20:39:50 +0100 (CET) Subject: [Python-3000-checkins] r67107 - in python/branches/py3k: Doc/library/imaplib.rst Lib/imaplib.py Misc/NEWS Message-ID: <20081105193950.EB8D11E4002@bag.python.org> Author: christian.heimes Date: Wed Nov 5 20:39:50 2008 New Revision: 67107 Log: Issue #1210: Fixed imaplib Patch by Victor Stinner, reviewed by Barry Warsaw. Modified: python/branches/py3k/Doc/library/imaplib.rst python/branches/py3k/Lib/imaplib.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Doc/library/imaplib.rst ============================================================================== --- python/branches/py3k/Doc/library/imaplib.rst (original) +++ python/branches/py3k/Doc/library/imaplib.rst Wed Nov 5 20:39:50 2008 @@ -75,7 +75,7 @@ This is a subclass derived from :class:`IMAP4` that connects to the ``stdin/stdout`` file descriptors created by passing *command* to - ``os.popen2()``. + ``subprocess.Popen()``. The following utility functions are defined: @@ -468,13 +468,6 @@ Allow simple extension commands notified by server in ``CAPABILITY`` response. -Instances of :class:`IMAP4_SSL` have just one additional method: - - -.. method:: IMAP4_SSL.ssl() - - Returns SSLObject instance used for the secure connection with the server. - The following attributes are defined on instances of :class:`IMAP4`: Modified: python/branches/py3k/Lib/imaplib.py ============================================================================== --- python/branches/py3k/Lib/imaplib.py (original) +++ python/branches/py3k/Lib/imaplib.py Wed Nov 5 20:39:50 2008 @@ -22,14 +22,14 @@ __version__ = "2.58" -import binascii, os, random, re, socket, sys, time +import binascii, random, re, socket, subprocess, sys, time __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate"] # Globals -CRLF = '\r\n' +CRLF = b'\r\n' Debug = 0 IMAP4_PORT = 143 IMAP4_SSL_PORT = 993 @@ -81,19 +81,19 @@ # Patterns to match server responses -Continuation = re.compile(r'\+( (?P.*))?') -Flags = re.compile(r'.*FLAGS \((?P[^\)]*)\)') -InternalDate = re.compile(r'.*INTERNALDATE "' - r'(?P[ 0123][0-9])-(?P[A-Z][a-z][a-z])-(?P[0-9][0-9][0-9][0-9])' - r' (?P[0-9][0-9]):(?P[0-9][0-9]):(?P[0-9][0-9])' - r' (?P[-+])(?P[0-9][0-9])(?P[0-9][0-9])' - r'"') -Literal = re.compile(r'.*{(?P\d+)}$', re.ASCII) -MapCRLF = re.compile(r'\r\n|\r|\n') -Response_code = re.compile(r'\[(?P[A-Z-]+)( (?P[^\]]*))?\]') -Untagged_response = re.compile(r'\* (?P[A-Z-]+)( (?P.*))?') +Continuation = re.compile(br'\+( (?P.*))?') +Flags = re.compile(br'.*FLAGS \((?P[^\)]*)\)') +InternalDate = re.compile(br'.*INTERNALDATE "' + br'(?P[ 0123][0-9])-(?P[A-Z][a-z][a-z])-(?P[0-9][0-9][0-9][0-9])' + br' (?P[0-9][0-9]):(?P[0-9][0-9]):(?P[0-9][0-9])' + br' (?P[-+])(?P[0-9][0-9])(?P[0-9][0-9])' + br'"') +Literal = re.compile(br'.*{(?P\d+)}$', re.ASCII) +MapCRLF = re.compile(br'\r\n|\r|\n') +Response_code = re.compile(br'\[(?P[A-Z-]+)( (?P[^\]]*))?\]') +Untagged_response = re.compile(br'\* (?P[A-Z-]+)( (?P.*))?') Untagged_status = re.compile( - r'\* (?P\d+) (?P[A-Z-]+)( (?P.*))?', re.ASCII) + br'\* (?P\d+) (?P[A-Z-]+)( (?P.*))?', re.ASCII) @@ -147,7 +147,7 @@ class abort(error): pass # Service errors - close and retry class readonly(abort): pass # Mailbox status changed to READ-ONLY - mustquote = re.compile(r"[^\w!#$%&'*+,.:;<=>?^`|~-]", re.ASCII) + mustquote = re.compile(br"[^\w!#$%&'*+,.:;<=>?^`|~-]", re.ASCII) def __init__(self, host = '', port = IMAP4_PORT): self.debug = Debug @@ -167,9 +167,9 @@ # and compile tagged response matcher. self.tagpre = Int2AP(random.randint(4096, 65535)) - self.tagre = re.compile(r'(?P' + self.tagre = re.compile(br'(?P' + self.tagpre - + r'\d+) (?P[A-Z]+) (?P.*)', re.ASCII) + + br'\d+) (?P[A-Z]+) (?P.*)', re.ASCII) # Get server welcome message, # request and store CAPABILITY response. @@ -193,7 +193,9 @@ typ, dat = self.capability() if dat == [None]: raise self.error('no CAPABILITY response from server') - self.capabilities = tuple(dat[-1].upper().split()) + dat = str(dat[-1], "ASCII") + dat = dat.upper() + self.capabilities = tuple(dat.split()) if __debug__: if self.debug >= 3: @@ -219,6 +221,11 @@ # Overridable methods + def _create_socket(self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + return sock + def open(self, host = '', port = IMAP4_PORT): """Setup connection to remote server on "host:port" (default: localhost:standard IMAP4 port). @@ -227,14 +234,21 @@ """ self.host = host self.port = port - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.connect((host, port)) + self.sock = self._create_socket() self.file = self.sock.makefile('rb') def read(self, size): """Read 'size' bytes from remote.""" - return self.file.read(size) + chunks = [] + read = 0 + while read < size: + data = self.file.read(min(size-read, 4096)) + if not data: + break + read += len(data) + chunks.append(data) + return b''.join(chunks) def readline(self): @@ -791,12 +805,12 @@ def _append_untagged(self, typ, dat): - - if dat is None: dat = '' + if dat is None: + dat = b'' ur = self.untagged_responses if __debug__: if self.debug >= 5: - self._mesg('untagged_responses[%s] %s += ["%s"]' % + self._mesg('untagged_responses[%s] %s += ["%r"]' % (typ, len(ur.get(typ,'')), dat)) if typ in ur: ur[typ].append(dat) @@ -828,10 +842,14 @@ raise self.readonly('mailbox status changed to READ-ONLY') tag = self._new_tag() - data = '%s %s' % (tag, name) + name = bytes(name, 'ASCII') + data = tag + b' ' + name for arg in args: if arg is None: continue - data = '%s %s' % (data, self._checkquote(arg)) + if isinstance(arg, str): + arg = bytes(arg, "ASCII") + #data = data + b' ' + self._checkquote(arg) + data = data + b' ' + arg literal = self.literal if literal is not None: @@ -840,16 +858,16 @@ literator = literal else: literator = None - data = '%s {%s}' % (data, len(literal)) + data = data + bytes(' {%s}' % len(literal), 'ASCII') if __debug__: if self.debug >= 4: - self._mesg('> %s' % data) + self._mesg('> %r' % data) else: - self._log('> %s' % data) + self._log('> %r' % data) try: - self.send('%s%s' % (data, CRLF)) + self.send(data + CRLF) except (socket.error, OSError) as val: raise self.abort('socket error: %s' % val) @@ -915,6 +933,7 @@ raise self.abort('unexpected tagged response: %s' % resp) typ = self.mo.group('type') + typ = str(typ, 'ASCII') dat = self.mo.group('data') self.tagged_commands[tag] = (typ, [dat]) else: @@ -936,9 +955,10 @@ raise self.abort("unexpected response: '%s'" % resp) typ = self.mo.group('type') + typ = str(typ, 'ascii') dat = self.mo.group('data') - if dat is None: dat = '' # Null untagged response - if dat2: dat = dat + ' ' + dat2 + if dat is None: dat = b'' # Null untagged response + if dat2: dat = dat + b' ' + dat2 # Is there a literal to come? @@ -965,11 +985,13 @@ # Bracketed response information? if typ in ('OK', 'NO', 'BAD') and self._match(Response_code, dat): - self._append_untagged(self.mo.group('type'), self.mo.group('data')) + typ = self.mo.group('type') + typ = str(typ, "ASCII") + self._append_untagged(typ, self.mo.group('data')) if __debug__: if self.debug >= 1 and typ in ('NO', 'BAD', 'BYE'): - self._mesg('%s response: %s' % (typ, dat)) + self._mesg('%s response: %r' % (typ, dat)) return resp @@ -1007,9 +1029,9 @@ line = line[:-2] if __debug__: if self.debug >= 4: - self._mesg('< %s' % line) + self._mesg('< %r' % line) else: - self._log('< %s' % line) + self._log('< %r' % line) return line @@ -1021,13 +1043,13 @@ self.mo = cre.match(s) if __debug__: if self.mo is not None and self.debug >= 5: - self._mesg("\tmatched r'%s' => %r" % (cre.pattern, self.mo.groups())) + self._mesg("\tmatched r'%r' => %r" % (cre.pattern, self.mo.groups())) return self.mo is not None def _new_tag(self): - tag = '%s%s' % (self.tagpre, self.tagnum) + tag = self.tagpre + bytes(str(self.tagnum), 'ASCII') self.tagnum = self.tagnum + 1 self.tagged_commands[tag] = None return tag @@ -1038,8 +1060,6 @@ # Must quote command args if non-alphanumeric chars present, # and not already quoted. - if type(arg) is not type(''): - return arg if len(arg) >= 2 and (arg[0],arg[-1]) in (('(',')'),('"','"')): return arg if arg and self.mustquote.search(arg) is None: @@ -1049,10 +1069,10 @@ def _quote(self, arg): - arg = arg.replace('\\', '\\\\') - arg = arg.replace('"', '\\"') + arg = arg.replace(b'\\', b'\\\\') + arg = arg.replace(b'"', b'\\"') - return '"%s"' % arg + return b'"' + arg + b'"' def _simple_command(self, name, *args): @@ -1061,7 +1081,6 @@ def _untagged_response(self, typ, dat, name): - if typ == 'NO': return typ, dat if not name in self.untagged_responses: @@ -1137,73 +1156,17 @@ self.certfile = certfile IMAP4.__init__(self, host, port) + def _create_socket(self): + sock = IMAP4._create_socket(self) + return ssl.wrap_socket(sock, self.keyfile, self.certfile) - def open(self, host = '', port = IMAP4_SSL_PORT): + def open(self, host='', port=IMAP4_SSL_PORT): """Setup connection to remote server on "host:port". (default: localhost:standard IMAP4 SSL port). This connection will be used by the routines: read, readline, send, shutdown. """ - self.host = host - self.port = port - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect((host, port)) - self.sock = ssl.wrap_socket(sock, self.keyfile, self.certfile) - self.file = self.sock.makefile('rb') - - - def read(self, size): - """Read 'size' bytes from remote.""" - # sslobj.read() sometimes returns < size bytes - chunks = [] - read = 0 - while read < size: - data = self.sslobj.read(min(size-read, 16384)) - read += len(data) - chunks.append(data) - - return b''.join(chunks) - - - def readline(self): - """Read line from remote.""" - line = [] - while 1: - char = self.sslobj.read(1) - line.append(char) - if char == b"\n": return b''.join(line) - - - def send(self, data): - """Send data to remote.""" - bytes = len(data) - while bytes > 0: - sent = self.sslobj.write(data) - if sent == bytes: - break # avoid copy - data = data[sent:] - bytes = bytes - sent - - - def shutdown(self): - """Close I/O established in "open".""" - self.sock.close() - - - def socket(self): - """Return socket instance used to connect to IMAP4 server. - - socket = .socket() - """ - return self.sock - - - def ssl(self): - """Return SSLObject instance used to communicate with the IMAP4 server. - - ssl = ssl.wrap_socket(.socket) - """ - return self.sock + IMAP4.open(self, host, port) __all__.append("IMAP4_SSL") @@ -1214,7 +1177,7 @@ Instantiate with: IMAP4_stream(command) - where "command" is a string that can be passed to os.popen2() + where "command" is a string that can be passed to subprocess.Popen() for more documentation see the docstring of the parent class IMAP4. """ @@ -1234,8 +1197,11 @@ self.port = None self.sock = None self.file = None - self.writefile, self.readfile = os.popen2(self.command) - + self.process = subprocess.Popen(self.command, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + shell=True, close_fds=True) + self.writefile = self.process.stdin + self.readfile = self.process.stdout def read(self, size): """Read 'size' bytes from remote.""" @@ -1257,6 +1223,7 @@ """Close I/O established in "open".""" self.readfile.close() self.writefile.close() + self.process.wait() @@ -1355,11 +1322,11 @@ """Convert integer to A-P string representation.""" - val = ''; AP = 'ABCDEFGHIJKLMNOP' + val = b''; AP = b'ABCDEFGHIJKLMNOP' num = int(abs(num)) while num: num, mod = divmod(num, 16) - val = AP[mod] + val + val = AP[mod:mod+1] + val return val Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 5 20:39:50 2008 @@ -15,6 +15,8 @@ Core and Builtins ----------------- +- Issue #1210: Fixed imaplib and its documentation. + - Issue #4233: Changed semantic of ``_fileio.FileIO``'s ``close()`` method on file objects with closefd=False. The file descriptor is still kept open but the file object behaves like a closed file. The ``FileIO`` From python-3000-checkins at python.org Wed Nov 5 20:44:22 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Wed, 5 Nov 2008 20:44:22 +0100 (CET) Subject: [Python-3000-checkins] r67108 - in python/branches/py3k: Lib/nntplib.py Misc/NEWS Message-ID: <20081105194422.44FCB1E4002@bag.python.org> Author: christian.heimes Date: Wed Nov 5 20:44:21 2008 New Revision: 67108 Log: Issue #3714: nntplib module broken by str to unicode conversion Patch by Victor, Reviewed by Barry Modified: python/branches/py3k/Lib/nntplib.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/nntplib.py ============================================================================== --- python/branches/py3k/Lib/nntplib.py (original) +++ python/branches/py3k/Lib/nntplib.py Wed Nov 5 20:44:21 2008 @@ -7,7 +7,7 @@ >>> resp, count, first, last, name = s.group('comp.lang.python') >>> print('Group', name, 'has', count, 'articles, range', first, 'to', last) Group comp.lang.python has 51 articles, range 5770 to 5821 ->>> resp, subs = s.xhdr('subject', first + '-' + last) +>>> resp, subs = s.xhdr('subject', '{0}-{1}'.format(first, last)) >>> resp = s.quit() >>> @@ -15,7 +15,7 @@ Error responses are turned into exceptions. To post an article from a file: ->>> f = open(filename, 'r') # file containing article, including header +>>> f = open(filename, 'rb') # file containing article, including header >>> resp = s.post(f) >>> @@ -81,11 +81,11 @@ # Response numbers that are followed by additional text (e.g. article) -LONGRESP = ['100', '215', '220', '221', '222', '224', '230', '231', '282'] +LONGRESP = [b'100', b'215', b'220', b'221', b'222', b'224', b'230', b'231', b'282'] # Line terminators (we always output CRLF, but accept any of CRLF, CR, LF) -CRLF = '\r\n' +CRLF = b'\r\n' @@ -128,7 +128,7 @@ # error 500, probably 'not implemented' pass except NNTPTemporaryError as e: - if user and e.response[:3] == '480': + if user and e.response.startswith(b'480'): # Need authorization before 'mode reader' readermode_afterauth = 1 else: @@ -148,13 +148,13 @@ # Perform NNRP authentication if needed. if user: resp = self.shortcmd('authinfo user '+user) - if resp[:3] == '381': + if resp.startswith(b'381'): if not password: raise NNTPReplyError(resp) else: resp = self.shortcmd( 'authinfo pass '+password) - if resp[:3] != '281': + if not resp.startswith(b'281'): raise NNTPPermanentError(resp) if readermode_afterauth: try: @@ -196,6 +196,7 @@ def putcmd(self, line): """Internal: send one command to the server (through putline()).""" if self.debugging: print('*cmd*', repr(line)) + line = bytes(line, "ASCII") self.putline(line) def getline(self): @@ -205,8 +206,10 @@ if self.debugging > 1: print('*get*', repr(line)) if not line: raise EOFError - if line[-2:] == CRLF: line = line[:-2] - elif line[-1:] in CRLF: line = line[:-1] + if line[-2:] == CRLF: + line = line[:-2] + elif line[-1:] in CRLF: + line = line[:-1] return line def getresp(self): @@ -215,11 +218,11 @@ resp = self.getline() if self.debugging: print('*resp*', repr(resp)) c = resp[:1] - if c == '4': + if c == b'4': raise NNTPTemporaryError(resp) - if c == '5': + if c == b'5': raise NNTPPermanentError(resp) - if c not in '123': + if c not in b'123': raise NNTPProtocolError(resp) return resp @@ -239,12 +242,12 @@ list = [] while 1: line = self.getline() - if line == '.': + if line == b'.': break - if line[:2] == '..': + if line.startswith(b'..'): line = line[1:] if file: - file.write(line + "\n") + file.write(line + b'\n') else: list.append(line) finally: @@ -312,16 +315,16 @@ resp, lines = self.descriptions(group) if len(lines) == 0: - return "" + return b'' else: return lines[0][1] def descriptions(self, group_pattern): """Get descriptions for a range of groups.""" - line_pat = re.compile("^(?P[^ \t]+)[ \t]+(.*)$") + line_pat = re.compile(b'^(?P[^ \t]+)[ \t]+(.*)$') # Try the more std (acc. to RFC2980) LIST NEWSGROUPS first resp, raw_lines = self.longcmd('LIST NEWSGROUPS ' + group_pattern) - if resp[:3] != "215": + if not resp.startswith(b'215'): # Now the deprecated XGTITLE. This either raises an error # or succeeds with the same output structure as LIST # NEWSGROUPS. @@ -344,7 +347,7 @@ - name: the group name""" resp = self.shortcmd('GROUP ' + name) - if resp[:3] != '211': + if not resp.startswith(b'211'): raise NNTPReplyError(resp) words = resp.split() count = first = last = 0 @@ -368,11 +371,11 @@ def statparse(self, resp): """Internal: parse the response of a STAT, NEXT or LAST command.""" - if resp[:2] != '22': + if not resp.startswith(b'22'): raise NNTPReplyError(resp) words = resp.split() nr = 0 - id = '' + id = b'' n = len(words) if n > 1: nr = words[1] @@ -393,7 +396,7 @@ - nr: the article number - id: the message id""" - return self.statcmd('STAT ' + id) + return self.statcmd('STAT {0}'.format(id)) def next(self): """Process a NEXT command. No arguments. Return as for STAT.""" @@ -418,7 +421,7 @@ - id: message id - list: the lines of the article's header""" - return self.artcmd('HEAD ' + id) + return self.artcmd('HEAD {0}'.format(id)) def body(self, id, file=None): """Process a BODY command. Argument: @@ -431,7 +434,7 @@ - list: the lines of the article's body or an empty list if file was used""" - return self.artcmd('BODY ' + id, file) + return self.artcmd('BODY {0}'.format(id), file) def article(self, id): """Process an ARTICLE command. Argument: @@ -442,7 +445,7 @@ - id: message id - list: the lines of the article""" - return self.artcmd('ARTICLE ' + id) + return self.artcmd('ARTICLE {0}'.format(id)) def slave(self): """Process a SLAVE command. Returns: @@ -458,8 +461,8 @@ - resp: server response if successful - list: list of (nr, value) strings""" - pat = re.compile('^([0-9]+) ?(.*)\n?') - resp, lines = self.longcmd('XHDR ' + hdr + ' ' + str, file) + pat = re.compile(b'^([0-9]+) ?(.*)\n?') + resp, lines = self.longcmd('XHDR {0} {1}'.format(hdr, str), file) for i in range(len(lines)): line = lines[i] m = pat.match(line) @@ -476,10 +479,10 @@ - list: list of (art-nr, subject, poster, date, id, references, size, lines)""" - resp, lines = self.longcmd('XOVER ' + start + '-' + end, file) + resp, lines = self.longcmd('XOVER {0}-{1}'.format(start, end), file) xover_lines = [] for line in lines: - elem = line.split("\t") + elem = line.split(b'\t') try: xover_lines.append((elem[0], elem[1], @@ -500,7 +503,7 @@ - resp: server response if successful - list: list of (name,title) strings""" - line_pat = re.compile("^([^ \t]+)[ \t]+(.*)$") + line_pat = re.compile(b'^([^ \t]+)[ \t]+(.*)$') resp, raw_lines = self.longcmd('XGTITLE ' + group, file) lines = [] for raw_line in raw_lines: @@ -516,8 +519,8 @@ resp: server response if successful path: directory path to article""" - resp = self.shortcmd("XPATH " + id) - if resp[:3] != '223': + resp = self.shortcmd('XPATH {0}'.format(id)) + if not resp.startswith(b'223'): raise NNTPReplyError(resp) try: [resp_num, path] = resp.split() @@ -535,7 +538,7 @@ time: Time suitable for newnews/newgroups commands etc.""" resp = self.shortcmd("DATE") - if resp[:3] != '111': + if not resp.startswith(b'111'): raise NNTPReplyError(resp) elem = resp.split() if len(elem) != 2: @@ -546,29 +549,30 @@ raise NNTPDataError(resp) return resp, date, time - - def post(self, f): - """Process a POST command. Arguments: - - f: file containing the article - Returns: - - resp: server response if successful""" - - resp = self.shortcmd('POST') + def _post(self, command, f): + resp = self.shortcmd(command) # Raises error_??? if posting is not allowed - if resp[0] != '3': + if not resp.startswith(b'3'): raise NNTPReplyError(resp) while 1: line = f.readline() if not line: break - if line[-1] == '\n': + if line.endswith(b'\n'): line = line[:-1] - if line[:1] == '.': - line = '.' + line + if line.startswith(b'.'): + line = b'.' + line self.putline(line) - self.putline('.') + self.putline(b'.') return self.getresp() + def post(self, f): + """Process a POST command. Arguments: + - f: file containing the article + Returns: + - resp: server response if successful""" + return self._post('POST', f) + def ihave(self, id, f): """Process an IHAVE command. Arguments: - id: message-id of the article @@ -576,22 +580,7 @@ Returns: - resp: server response if successful Note that if the server refuses the article an exception is raised.""" - - resp = self.shortcmd('IHAVE ' + id) - # Raises error_??? if the server already has it - if resp[0] != '3': - raise NNTPReplyError(resp) - while 1: - line = f.readline() - if not line: - break - if line[-1] == '\n': - line = line[:-1] - if line[:1] == '.': - line = '.' + line - self.putline(line) - self.putline('.') - return self.getresp() + return self._post('IHAVE {0}'.format(id), f) def quit(self): """Process a QUIT command and close the socket. Returns: @@ -620,7 +609,7 @@ resp, count, first, last, name = s.group('comp.lang.python') print(resp) print('Group', name, 'has', count, 'articles, range', first, 'to', last) - resp, subs = s.xhdr('subject', first + '-' + last) + resp, subs = s.xhdr('subject', '{0}-{1}'.format(first, last)) print(resp) for item in subs: print("%7s %s" % item) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 5 20:44:21 2008 @@ -15,6 +15,8 @@ Core and Builtins ----------------- +- Issue #3714: Fixed nntplib by using bytes where appropriate. + - Issue #1210: Fixed imaplib and its documentation. - Issue #4233: Changed semantic of ``_fileio.FileIO``'s ``close()`` From python-3000-checkins at python.org Wed Nov 5 20:48:28 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Wed, 5 Nov 2008 20:48:28 +0100 (CET) Subject: [Python-3000-checkins] r67109 - in python/branches/py3k: Lib/poplib.py Lib/test/test_poplib.py Misc/NEWS Message-ID: <20081105194828.634FF1E4037@bag.python.org> Author: christian.heimes Date: Wed Nov 5 20:48:27 2008 New Revision: 67109 Log: Fixed issue #3727: poplib module broken by str to unicode conversion Victor strikes again! Assisted by Barry Modified: python/branches/py3k/Lib/poplib.py python/branches/py3k/Lib/test/test_poplib.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/poplib.py ============================================================================== --- python/branches/py3k/Lib/poplib.py (original) +++ python/branches/py3k/Lib/poplib.py Wed Nov 5 20:48:27 2008 @@ -75,26 +75,30 @@ above. """ + encoding = 'UTF-8' def __init__(self, host, port=POP3_PORT, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): self.host = host self.port = port - self.sock = socket.create_connection((host, port), timeout) + self.sock = self._create_socket(timeout) self.file = self.sock.makefile('rb') self._debugging = 0 self.welcome = self._getresp() + def _create_socket(self, timeout): + return socket.create_connection((self.host, self.port), timeout) def _putline(self, line): if self._debugging > 1: print('*put*', repr(line)) - self.sock.sendall('%s%s' % (line, CRLF)) + self.sock.sendall(line + CRLF) # Internal: send one command to the server (through _putline()) def _putcmd(self, line): if self._debugging: print('*cmd*', repr(line)) + line = bytes(line, self.encoding) self._putline(line) @@ -123,8 +127,7 @@ def _getresp(self): resp, o = self._getline() if self._debugging > 1: print('*resp*', repr(resp)) - c = resp[:1] - if c != b'+': + if not resp.startswith(b'+'): raise error_proto(resp) return resp @@ -136,7 +139,7 @@ list = []; octets = 0 line, o = self._getline() while line != b'.': - if line[:2] == b'..': + if line.startswith(b'..'): o = o-1 line = line[1:] octets = octets + o @@ -266,25 +269,26 @@ return self._shortcmd('RPOP %s' % user) - timestamp = re.compile(r'\+OK.*(<[^>]+>)') + timestamp = re.compile(br'\+OK.*(<[^>]+>)') - def apop(self, user, secret): + def apop(self, user, password): """Authorisation - only possible if server has supplied a timestamp in initial greeting. Args: - user - mailbox user; - secret - secret shared between client and server. + user - mailbox user; + password - mailbox password. NB: mailbox is locked by server from here to 'quit()' """ + secret = bytes(secret, self.encoding) m = self.timestamp.match(self.welcome) if not m: raise error_proto('-ERR APOP not supported by server') import hashlib - digest = hashlib.md5(m.group(1)+secret).digest() - digest = ''.join(map(lambda x:'%02x'%ord(x), digest)) + digest = m.group(1)+secret + digest = hashlib.md5(digest).hexdigest() return self._shortcmd('APOP %s %s' % (user, digest)) @@ -324,79 +328,19 @@ keyfile - PEM formatted file that countains your private key certfile - PEM formatted certificate chain file - See the methods of the parent class POP3 for more documentation. + See the methods of the parent class POP3 for more documentation. """ - def __init__(self, host, port = POP3_SSL_PORT, keyfile = None, certfile = None): - self.host = host - self.port = port + def __init__(self, host, port=POP3_SSL_PORT, + keyfile=None, certfile=None, + timeout=socket._GLOBAL_DEFAULT_TIMEOUT): self.keyfile = keyfile self.certfile = certfile - self.buffer = "" - msg = "getaddrinfo returns an empty list" - self.sock = None - for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): - af, socktype, proto, canonname, sa = res - try: - self.sock = socket.socket(af, socktype, proto) - self.sock.connect(sa) - except socket.error as msg: - if self.sock: - self.sock.close() - self.sock = None - continue - break - if not self.sock: - raise socket.error(msg) - self.file = self.sock.makefile('rb') - self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) - self._debugging = 0 - self.welcome = self._getresp() - - def _fillBuffer(self): - localbuf = self.sslobj.read() - if len(localbuf) == 0: - raise error_proto('-ERR EOF') - self.buffer += localbuf - - def _getline(self): - line = "" - renewline = re.compile(r'.*?\n') - match = renewline.match(self.buffer) - while not match: - self._fillBuffer() - match = renewline.match(self.buffer) - line = match.group(0) - self.buffer = renewline.sub('' ,self.buffer, 1) - if self._debugging > 1: print('*get*', repr(line)) - - octets = len(line) - if line[-2:] == CRLF: - return line[:-2], octets - if line[0] == CR: - return line[1:-1], octets - return line[:-1], octets - - def _putline(self, line): - if self._debugging > 1: print('*put*', repr(line)) - line += CRLF - bytes = len(line) - while bytes > 0: - sent = self.sslobj.write(line) - if sent == bytes: - break # avoid copy - line = line[sent:] - bytes = bytes - sent - - def quit(self): - """Signoff: commit changes on server, unlock mailbox, close connection.""" - try: - resp = self._shortcmd('QUIT') - except error_proto as val: - resp = val - self.sock.close() - del self.sslobj, self.sock - return resp + POP3.__init__(self, host, port, timeout) + + def _create_socket(self, timeout): + sock = POP3._create_socket(self, timeout) + return ssl.wrap_socket(sock, self.keyfile, self.certfile) __all__.append("POP3_SSL") Modified: python/branches/py3k/Lib/test/test_poplib.py ============================================================================== --- python/branches/py3k/Lib/test/test_poplib.py (original) +++ python/branches/py3k/Lib/test/test_poplib.py Wed Nov 5 20:48:27 2008 @@ -1,43 +1,284 @@ -import socket -import threading +"""Test script for poplib module.""" + +# Modified by Giampaolo Rodola' to give poplib.POP3 and poplib.POP3_SSL +# a real test suite + import poplib +import threading +import asyncore +import asynchat +import socket +import os import time from unittest import TestCase -from test import support +from test import support as test_support -HOST = support.HOST +HOST = test_support.HOST +PORT = 0 -def server(evt, serv): - serv.listen(5) - try: - conn, addr = serv.accept() - except socket.timeout: - pass - else: - conn.send(b"+ Hola mundo\n") - conn.close() - finally: - serv.close() - evt.set() +# the dummy data returned by server when LIST and RETR commands are issued +LIST_RESP = b'1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n.\r\n' +RETR_RESP = b"""From: postmaster at python.org\ +\r\nContent-Type: text/plain\r\n\ +MIME-Version: 1.0\r\n\ +Subject: Dummy\r\n\ +\r\n\ +line1\r\n\ +line2\r\n\ +line3\r\n\ +.\r\n""" + + +class DummyPOP3Handler(asynchat.async_chat): + + def __init__(self, conn): + asynchat.async_chat.__init__(self, conn) + self.set_terminator(b"\r\n") + self.in_buffer = [] + self.push('+OK dummy pop3 server ready.') + + def collect_incoming_data(self, data): + self.in_buffer.append(data) + + def found_terminator(self): + line = b''.join(self.in_buffer) + line = str(line, 'ISO-8859-1') + self.in_buffer = [] + cmd = line.split(' ')[0].lower() + space = line.find(' ') + if space != -1: + arg = line[space + 1:] + else: + arg = "" + if hasattr(self, 'cmd_' + cmd): + method = getattr(self, 'cmd_' + cmd) + method(arg) + else: + self.push('-ERR unrecognized POP3 command "%s".' %cmd) + + def handle_error(self): + raise + + def push(self, data): + asynchat.async_chat.push(self, data.encode("ISO-8859-1") + b'\r\n') + + def cmd_echo(self, arg): + # sends back the received string (used by the test suite) + self.push(arg) + + def cmd_user(self, arg): + if arg != "guido": + self.push("-ERR no such user") + self.push('+OK password required') + + def cmd_pass(self, arg): + if arg != "python": + self.push("-ERR wrong password") + self.push('+OK 10 messages') + + def cmd_stat(self, arg): + self.push('+OK 10 100') + + def cmd_list(self, arg): + if arg: + self.push('+OK %s %s' %(arg, arg)) + else: + self.push('+OK') + asynchat.async_chat.push(self, LIST_RESP) + + cmd_uidl = cmd_list + + def cmd_retr(self, arg): + self.push('+OK %s bytes' %len(RETR_RESP)) + asynchat.async_chat.push(self, RETR_RESP) + + cmd_top = cmd_retr + + def cmd_dele(self, arg): + self.push('+OK message marked for deletion.') + + def cmd_noop(self, arg): + self.push('+OK done nothing.') + + def cmd_rpop(self, arg): + self.push('+OK done nothing.') + + +class DummyPOP3Server(asyncore.dispatcher, threading.Thread): + + handler = DummyPOP3Handler + + def __init__(self, address, af=socket.AF_INET): + threading.Thread.__init__(self) + asyncore.dispatcher.__init__(self) + self.create_socket(af, socket.SOCK_STREAM) + self.bind(address) + self.listen(5) + self.active = False + self.active_lock = threading.Lock() + self.host, self.port = self.socket.getsockname()[:2] + + def start(self): + assert not self.active + self.__flag = threading.Event() + threading.Thread.start(self) + self.__flag.wait() + + def run(self): + self.active = True + self.__flag.set() + while self.active and asyncore.socket_map: + self.active_lock.acquire() + asyncore.loop(timeout=0.1, count=1) + self.active_lock.release() + asyncore.close_all(ignore_all=True) + + def stop(self): + assert self.active + self.active = False + self.join() + + def handle_accept(self): + conn, addr = self.accept() + self.handler = self.handler(conn) + self.close() + + def handle_connect(self): + self.close() + handle_read = handle_connect + + def writable(self): + return 0 + + def handle_error(self): + raise + + +class TestPOP3Class(TestCase): + def assertOK(self, resp): + self.assertTrue(resp.startswith(b"+OK")) + + def setUp(self): + self.server = DummyPOP3Server((HOST, PORT)) + self.server.start() + self.client = poplib.POP3(self.server.host, self.server.port) + + def tearDown(self): + self.client.quit() + self.server.stop() -class GeneralTests(TestCase): + def test_getwelcome(self): + self.assertEqual(self.client.getwelcome(), b'+OK dummy pop3 server ready.') + + def test_exceptions(self): + self.assertRaises(poplib.error_proto, self.client._shortcmd, 'echo -err') + + def test_user(self): + self.assertOK(self.client.user('guido')) + self.assertRaises(poplib.error_proto, self.client.user, 'invalid') + + def test_pass_(self): + self.assertOK(self.client.pass_('python')) + self.assertRaises(poplib.error_proto, self.client.user, 'invalid') + + def test_stat(self): + self.assertEqual(self.client.stat(), (10, 100)) + + def test_list(self): + self.assertEqual(self.client.list()[1:], + ([b'1 1', b'2 2', b'3 3', b'4 4', b'5 5'], + 25)) + self.assertTrue(self.client.list('1').endswith(b"OK 1 1")) + + def test_retr(self): + expected = (b'+OK 116 bytes', + [b'From: postmaster at python.org', b'Content-Type: text/plain', + b'MIME-Version: 1.0', b'Subject: Dummy', + b'', b'line1', b'line2', b'line3'], + 113) + foo = self.client.retr('foo') + self.assertEqual(foo, expected) + + def test_dele(self): + self.assertOK(self.client.dele('foo')) + + def test_noop(self): + self.assertOK(self.client.noop()) + + def test_rpop(self): + self.assertOK(self.client.rpop('foo')) + + def test_top(self): + expected = (b'+OK 116 bytes', + [b'From: postmaster at python.org', b'Content-Type: text/plain', + b'MIME-Version: 1.0', b'Subject: Dummy', b'', + b'line1', b'line2', b'line3'], + 113) + self.assertEqual(self.client.top(1, 1), expected) + + def test_uidl(self): + self.client.uidl() + self.client.uidl('foo') + + +SUPPORTS_SSL = False +if hasattr(poplib, 'POP3_SSL'): + import ssl + + SUPPORTS_SSL = True + CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert.pem") + + class DummyPOP3_SSLHandler(DummyPOP3Handler): + + def __init__(self, conn): + asynchat.async_chat.__init__(self, conn) + ssl_socket = ssl.wrap_socket(self.socket, certfile=CERTFILE, + server_side=True) + self.del_channel() + self.set_socket(ssl_socket) + self.set_terminator(b"\r\n") + self.in_buffer = [] + self.push('+OK dummy pop3 server ready.') + + class TestPOP3_SSLClass(TestPOP3Class): + # repeat previous tests by using poplib.POP3_SSL + + def setUp(self): + self.server = DummyPOP3Server((HOST, PORT)) + self.server.handler = DummyPOP3_SSLHandler + self.server.start() + self.client = poplib.POP3_SSL(self.server.host, self.server.port) + + def test__all__(self): + self.assert_('POP3_SSL' in poplib.__all__) + + +class TestTimeouts(TestCase): def setUp(self): self.evt = threading.Event() self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.settimeout(3) - self.port = support.bind_port(self.sock) - threading.Thread(target=server, args=(self.evt,self.sock)).start() + self.port = test_support.bind_port(self.sock) + threading.Thread(target=self.server, args=(self.evt,self.sock)).start() time.sleep(.1) def tearDown(self): self.evt.wait() - def testBasic(self): - # connects - pop = poplib.POP3(HOST, self.port) - pop.sock.close() + def server(self, evt, serv): + serv.listen(5) + try: + conn, addr = serv.accept() + except socket.timeout: + pass + else: + conn.send(b"+ Hola mundo\n") + conn.close() + finally: + serv.close() + evt.set() def testTimeoutDefault(self): self.assertTrue(socket.getdefaulttimeout() is None) @@ -65,8 +306,16 @@ pop.sock.close() -def test_main(verbose=None): - support.run_unittest(GeneralTests) +def test_main(): + tests = [TestPOP3Class, TestTimeouts] + if SUPPORTS_SSL: + tests.append(TestPOP3_SSLClass) + thread_info = test_support.threading_setup() + try: + test_support.run_unittest(*tests) + finally: + test_support.threading_cleanup(*thread_info) + if __name__ == '__main__': test_main() Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 5 20:48:27 2008 @@ -15,6 +15,8 @@ Core and Builtins ----------------- +- Issue #3727: Fixed poplib + - Issue #3714: Fixed nntplib by using bytes where appropriate. - Issue #1210: Fixed imaplib and its documentation. From python-3000-checkins at python.org Wed Nov 5 22:34:59 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 5 Nov 2008 22:34:59 +0100 (CET) Subject: [Python-3000-checkins] r67110 - python/branches/py3k Message-ID: <20081105213459.C63201E400C@bag.python.org> Author: benjamin.peterson Date: Wed Nov 5 22:34:59 2008 New Revision: 67110 Log: Blocked revisions 66878 via svnmerge ........ r66878 | benjamin.peterson | 2008-10-11 12:25:36 -0500 (Sat, 11 Oct 2008) | 4 lines give poplib a real test suite #4088 from Giampaolo Rodola'x ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Wed Nov 5 22:42:46 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 5 Nov 2008 22:42:46 +0100 (CET) Subject: [Python-3000-checkins] r67111 - in python/branches/py3k: Doc/library/select.rst Doc/library/socket.rst Lib/test/test_fileio.py Lib/test/test_io.py Message-ID: <20081105214246.147581E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 5 22:42:45 2008 New Revision: 67111 Log: Merged revisions 67089,67091,67101 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67089 | benjamin.peterson | 2008-11-03 14:43:20 -0600 (Mon, 03 Nov 2008) | 1 line clarify by splitting into multiple paragraphs ........ r67091 | benjamin.peterson | 2008-11-03 16:34:57 -0600 (Mon, 03 Nov 2008) | 1 line move a FileIO test to test_fileio ........ r67101 | georg.brandl | 2008-11-04 14:49:35 -0600 (Tue, 04 Nov 2008) | 2 lines #4167: fix markup glitches. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/select.rst python/branches/py3k/Doc/library/socket.rst python/branches/py3k/Lib/test/test_fileio.py python/branches/py3k/Lib/test/test_io.py Modified: python/branches/py3k/Doc/library/select.rst ============================================================================== --- python/branches/py3k/Doc/library/select.rst (original) +++ python/branches/py3k/Doc/library/select.rst Wed Nov 5 22:42:45 2008 @@ -355,7 +355,7 @@ Filter specific flags - *:const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags* + :const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags +----------------------------+--------------------------------------------+ | Constant | Meaning | @@ -364,7 +364,7 @@ +----------------------------+--------------------------------------------+ - *:const:`KQ_FILTER_VNODE` filter flags* + :const:`KQ_FILTER_VNODE` filter flags +----------------------------+--------------------------------------------+ | Constant | Meaning | @@ -385,7 +385,7 @@ +----------------------------+--------------------------------------------+ - *:const:`KQ_FILTER_PROC` filter flags* + :const:`KQ_FILTER_PROC` filter flags +----------------------------+--------------------------------------------+ | Constant | Meaning | @@ -408,7 +408,7 @@ | :const:`KQ_NOTE_TRACKERR` | unable to attach to a child | +----------------------------+--------------------------------------------+ - *:const:`KQ_FILTER_NETDEV` filter flags* [not available on Mac OS X] + :const:`KQ_FILTER_NETDEV` filter flags [not available on Mac OS X] +----------------------------+--------------------------------------------+ | Constant | Meaning | Modified: python/branches/py3k/Doc/library/socket.rst ============================================================================== --- python/branches/py3k/Doc/library/socket.rst (original) +++ python/branches/py3k/Doc/library/socket.rst Wed Nov 5 22:42:45 2008 @@ -260,11 +260,15 @@ .. function:: gethostname() Return a string containing the hostname of the machine where the Python - interpreter is currently executing. If you want to know the current machine's IP - address, you may want to use ``gethostbyname(gethostname())``. This operation - assumes that there is a valid address-to-host mapping for the host, and the - assumption does not always hold. Note: :func:`gethostname` doesn't always return - the fully qualified domain name; use ``getfqdn()`` (see above). + interpreter is currently executing. + + If you want to know the current machine's IP address, you may want to use + ``gethostbyname(gethostname())``. This operation assumes that there is a + valid address-to-host mapping for the host, and the assumption does not + always hold. + + Note: :func:`gethostname` doesn't always return the fully qualified domain + name; use ``getfqdn()`` (see above). .. function:: gethostbyaddr(ip_address) Modified: python/branches/py3k/Lib/test/test_fileio.py ============================================================================== --- python/branches/py3k/Lib/test/test_fileio.py (original) +++ python/branches/py3k/Lib/test/test_fileio.py Wed Nov 5 22:42:45 2008 @@ -6,7 +6,7 @@ from array import array from weakref import proxy -from test.support import TESTFN, findfile, run_unittest +from test.support import TESTFN, findfile, check_warnings, run_unittest from collections import UserList import _fileio @@ -240,6 +240,14 @@ def testInvalidInit(self): self.assertRaises(TypeError, _fileio._FileIO, "1", 0, 0) + def testWarnings(self): + with check_warnings() as w: + self.assertEqual(w.warnings, []) + self.assertRaises(TypeError, _fileio._FileIO, []) + self.assertEqual(w.warnings, []) + self.assertRaises(ValueError, _fileio._FileIO, "/some/invalid/name", "rt") + self.assertEqual(w.warnings, []) + def test_main(): # Historically, these tests have been sloppy about removing TESTFN. Modified: python/branches/py3k/Lib/test/test_io.py ============================================================================== --- python/branches/py3k/Lib/test/test_io.py (original) +++ python/branches/py3k/Lib/test/test_io.py Wed Nov 5 22:42:45 2008 @@ -1260,6 +1260,7 @@ else: self.assert_(issubclass(obj, io.IOBase)) + def test_main(): support.run_unittest(IOTest, BytesIOTest, StringIOTest, BufferedReaderTest, BufferedWriterTest, From python-3000-checkins at python.org Wed Nov 5 23:48:34 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 5 Nov 2008 23:48:34 +0100 (CET) Subject: [Python-3000-checkins] r67112 - in python/branches/py3k: Lib/test/test_frozen.py Misc/NEWS Python/import.c Message-ID: <20081105224834.3CC581E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 5 23:48:33 2008 New Revision: 67112 Log: fix #4211: the __path__ of a frozen package should be a list Modified: python/branches/py3k/Lib/test/test_frozen.py python/branches/py3k/Misc/NEWS python/branches/py3k/Python/import.c Modified: python/branches/py3k/Lib/test/test_frozen.py ============================================================================== --- python/branches/py3k/Lib/test/test_frozen.py (original) +++ python/branches/py3k/Lib/test/test_frozen.py Wed Nov 5 23:48:33 2008 @@ -22,6 +22,7 @@ self.assertEqual(len(dir(__phello__)), 7, dir(__phello__)) else: self.assertEqual(len(dir(__phello__)), 8, dir(__phello__)) + self.assertEquals(__phello__.__path__, [__phello__.__name__]) try: import __phello__.spam Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 5 23:48:33 2008 @@ -15,6 +15,9 @@ Core and Builtins ----------------- +- Issue #4211: The __path__ attribute of frozen packages is now a list instead + of a string as required by PEP 302. + - Issue #3727: Fixed poplib - Issue #3714: Fixed nntplib by using bytes where appropriate. Modified: python/branches/py3k/Python/import.c ============================================================================== --- python/branches/py3k/Python/import.c (original) +++ python/branches/py3k/Python/import.c Wed Nov 5 23:48:33 2008 @@ -1293,37 +1293,16 @@ Py_DECREF(meta_path); } - if (path != NULL && PyUnicode_Check(path)) { - /* The only type of submodule allowed inside a "frozen" - package are other frozen modules or packages. */ - char *p = _PyUnicode_AsString(path); - if (strlen(p) + 1 + strlen(name) >= (size_t)buflen) { - PyErr_SetString(PyExc_ImportError, - "full frozen module name too long"); - return NULL; - } - strcpy(buf, p); - strcat(buf, "."); - strcat(buf, name); - strcpy(name, buf); - if (find_frozen(name) != NULL) { - strcpy(buf, name); - return &fd_frozen; - } - PyErr_Format(PyExc_ImportError, - "No frozen submodule named %.200s", name); - return NULL; + if (find_frozen(fullname) != NULL) { + strcpy(buf, fullname); + return &fd_frozen; } + if (path == NULL) { if (is_builtin(name)) { strcpy(buf, name); return &fd_builtin; } - if ((find_frozen(name)) != NULL) { - strcpy(buf, name); - return &fd_frozen; - } - #ifdef MS_COREDLL fp = PyWin_FindRegisteredModule(name, &fdp, buf, buflen); if (fp != NULL) { @@ -1333,6 +1312,7 @@ #endif path = PySys_GetObject("path"); } + if (path == NULL || !PyList_Check(path)) { PyErr_SetString(PyExc_ImportError, "sys.path must be a list of directory names"); @@ -1886,6 +1866,9 @@ { struct _frozen *p; + if (!name) + return NULL; + for (p = PyImport_FrozenModules; ; p++) { if (p->name == NULL) return NULL; @@ -1959,7 +1942,7 @@ } if (ispackage) { /* Set __path__ to the package name */ - PyObject *d, *s; + PyObject *d, *s, *l; int err; m = PyImport_AddModule(name); if (m == NULL) @@ -1968,8 +1951,14 @@ s = PyUnicode_InternFromString(name); if (s == NULL) goto err_return; - err = PyDict_SetItemString(d, "__path__", s); - Py_DECREF(s); + l = PyList_New(1); + if (l == NULL) { + Py_DECREF(s); + goto err_return; + } + PyList_SET_ITEM(l, 0, s); + err = PyDict_SetItemString(d, "__path__", l); + Py_DECREF(l); if (err != 0) goto err_return; } From python-3000-checkins at python.org Wed Nov 5 23:49:10 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 5 Nov 2008 23:49:10 +0100 (CET) Subject: [Python-3000-checkins] r67113 - python/branches/py3k/Misc/NEWS Message-ID: <20081105224910.444571E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 5 23:49:09 2008 New Revision: 67113 Log: period Modified: python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 5 23:49:09 2008 @@ -18,7 +18,7 @@ - Issue #4211: The __path__ attribute of frozen packages is now a list instead of a string as required by PEP 302. -- Issue #3727: Fixed poplib +- Issue #3727: Fixed poplib. - Issue #3714: Fixed nntplib by using bytes where appropriate. From python-3000-checkins at python.org Thu Nov 6 04:29:33 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Thu, 6 Nov 2008 04:29:33 +0100 (CET) Subject: [Python-3000-checkins] r67114 - in python/branches/py3k: Include/patchlevel.h Lib/distutils/__init__.py Lib/idlelib/idlever.py Lib/pydoc_topics.py Misc/NEWS Misc/RPM/python-3.0.spec README Message-ID: <20081106032933.BD3F21E4002@bag.python.org> Author: barry.warsaw Date: Thu Nov 6 04:29:32 2008 New Revision: 67114 Log: Bumping to 3.0rc2. Modified: python/branches/py3k/Include/patchlevel.h python/branches/py3k/Lib/distutils/__init__.py python/branches/py3k/Lib/idlelib/idlever.py python/branches/py3k/Lib/pydoc_topics.py python/branches/py3k/Misc/NEWS python/branches/py3k/Misc/RPM/python-3.0.spec python/branches/py3k/README Modified: python/branches/py3k/Include/patchlevel.h ============================================================================== --- python/branches/py3k/Include/patchlevel.h (original) +++ python/branches/py3k/Include/patchlevel.h Thu Nov 6 04:29:32 2008 @@ -20,10 +20,10 @@ #define PY_MINOR_VERSION 0 #define PY_MICRO_VERSION 0 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_GAMMA -#define PY_RELEASE_SERIAL 1 +#define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.0rc1+" +#define PY_VERSION "3.0rc2" /*--end constants--*/ /* Subversion Revision number of this file (not of the repository) */ Modified: python/branches/py3k/Lib/distutils/__init__.py ============================================================================== --- python/branches/py3k/Lib/distutils/__init__.py (original) +++ python/branches/py3k/Lib/distutils/__init__.py Thu Nov 6 04:29:32 2008 @@ -20,5 +20,5 @@ # #--start constants-- -__version__ = "3.0rc1" +__version__ = "3.0rc2" #--end constants-- Modified: python/branches/py3k/Lib/idlelib/idlever.py ============================================================================== --- python/branches/py3k/Lib/idlelib/idlever.py (original) +++ python/branches/py3k/Lib/idlelib/idlever.py Thu Nov 6 04:29:32 2008 @@ -1 +1 @@ -IDLE_VERSION = "3.0rc1" +IDLE_VERSION = "3.0rc2" Modified: python/branches/py3k/Lib/pydoc_topics.py ============================================================================== --- python/branches/py3k/Lib/pydoc_topics.py (original) +++ python/branches/py3k/Lib/pydoc_topics.py Thu Nov 6 04:29:32 2008 @@ -1,9 +1,9 @@ -# Autogenerated by Sphinx on Thu Oct 2 15:58:57 2008 +# Autogenerated by Sphinx on Wed Nov 5 22:25:20 2008 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:\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 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 a sequence 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* 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(In the current implementation, the syntax for targets is taken to be\nthe same as for expressions, and invalid syntax is rejected during the\ncode generation phase, causing less 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 ::= target augop (expression_list | yield_expression)\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 initial value is\nretrieved with a ``getattr()`` and the result is assigned with a\n``setattr()``. Notice that the two methods do not necessarily refer\nto the same variable. When ``getattr()`` refers to a class variable,\n``setattr()`` still writes to an instance variable. For example:\n\n class A:\n x = 3 # class variable\n a = A()\n a.x += 1 # writes a.x as 4 leaving A.x as 3\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', 'atom-literals': "\nLiterals\n********\n\nPython supports string and bytes literals and various numeric\nliterals:\n\n literal ::= stringliteral | bytesliteral\n | integer | floatnumber | imagnumber\n\nEvaluation of a literal yields an object of the given type (string,\nbytes, integer, floating point number, complex number) with the given\nvalue. The value may be approximated in the case of floating point\nand imaginary (complex) literals. See section *Literals* for details.\n\nWith the exception of bytes literals, these all correspond to\nimmutable data types, and hence the object's identity is less\nimportant than its value. Multiple evaluations of literals with the\nsame value (either the same occurrence in the program text or a\ndifferent occurrence) may obtain the same object or a different object\nwith the same value.\n", - '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 builtin 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 list must be\n returned.\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 the\nclass dictionary of another class, known as the *owner* class. 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, A)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. Normally, data\ndescriptors define both ``__get__()`` and ``__set__()``, while non-\ndata descriptors have just the ``__get__()`` method. Data descriptors\nalways override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances. [2]\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* 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* 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__*.\n\n* *__slots__* do not work for classes derived from "variable-length"\n built-in types such as ``int``, ``str`` and ``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-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 builtin 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 list must be\n returned.\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 the\nclass dictionary of another class, known as the *owner* class. 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, A)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. Normally, data\ndescriptors define both ``__get__()`` and ``__set__()``, while non-\ndata descriptors have just the ``__get__()`` method. Data descriptors\nalways override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances. [2]\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* 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* 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__*.\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 ::= target augop (expression_list | yield_expression)\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 initial value is\nretrieved with a ``getattr()`` and the result is assigned with a\n``setattr()``. Notice that the two methods do not necessarily refer\nto the same variable. When ``getattr()`` refers to a class variable,\n``setattr()`` still writes to an instance variable. For example:\n\n class A:\n x = 3 # class variable\n a = A()\n a.x += 1 # writes a.x as 4 leaving A.x as 3\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', @@ -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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function and by string\n conversions (reverse quotes) to compute the "official" string\n representation of an object. If at all possible, this should look\n like a valid Python expression that could be used to recreate an\n object with the same value (given an appropriate environment). If\n this is not possible, a string of the form ``<...some useful\n description...>`` should be returned. The return value must be a\n string object. If a class defines ``__repr__()`` but not\n ``__str__()``, then ``__repr__()`` is also used when an "informal"\n string representation of instances of that class is 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.__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\nobject.__hash__(self)\n\n Called for the key object for dictionary operations, and by the\n built-in function ``hash()``. Should return an integer usable as a\n hash value for dictionary operations. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g., using exclusive or) the hash\n values for the components of the object that also play a part in\n 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 dictionary keys. If a class defines mutable objects and\n implements an ``__eq__()`` method, it should not implement\n ``__hash__()``, since the dictionary implementation requires that a\n key\'s hash value is immutable (if the object\'s hash value changes,\n 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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n 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.__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\nobject.__hash__(self)\n\n Called for the key object for dictionary operations, and by the\n built-in function ``hash()``. Should return an integer usable as a\n hash value for dictionary operations. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g., using exclusive or) the hash\n values for the components of the object that also play a part in\n 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 dictionary keys. If a class defines mutable objects and\n implements an ``__eq__()`` method, it should not implement\n ``__hash__()``, since the dictionary implementation requires that a\n key\'s hash value is immutable (if the object\'s hash value changes,\n 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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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``\n(undocumented) and ``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\n``pdb.py`` can also be invoked as a script to debug other scripts.\nFor example:\n\n python -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\nTypical 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[, locals]])\n\n Execute the *statement* (given as a string) under debugger control.\n The debugger prompt appears before any code is executed; you can\n set breakpoints and type ``continue``, or you can step through the\n statement using ``step`` or ``next`` (all these commands are\n explained below). The optional *globals* and *locals* arguments\n specify the environment in which the code is executed; by default\n the dictionary of the module ``__main__`` is used. (See the\n explanation of the built-in ``exec()`` or ``eval()`` functions.)\n\npdb.runeval(expression[, globals[, locals]])\n\n Evaluate the *expression* (given as a string) under debugger\n control. When ``runeval()`` returns, it returns the value of the\n expression. Otherwise this function is similar to ``run()``.\n\npdb.runcall(function[, argument, ...])\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])\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', '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 that 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\nIt is illegal to delete a name from the local namespace if it occurs\nas a free variable in a nested block.\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', '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 ::= id_start id_continue*\n id_start ::= \n id_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\nAll identifiers are converted into the normal form NFC while parsing;\ncomparison of identifiers is based on NFC.\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);\n applications should not expect to define additional names using\n this convention. The set of names of this class defined by Python\n may be extended in future versions. See section *Special method\n names*.\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\nfirst form (without ``from``) repeats these steps for each identifier\nin the list. The form with ``from`` performs step (1) once, and then\nperforms step (2) repeatedly.\n\nIn this context, to "initialize" a built-in or extension module means\nto call an initialization function that the module must provide for\nthe purpose (in the reference implementation, the function\'s name is\nobtained by prepending string "init" to the module\'s name); to\n"initialize" a Python-coded module means to execute the module\'s body.\n\nThe system maintains a table of modules that have been or are being\ninitialized, indexed by module name. This table is accessible as\n``sys.modules``. When a module name is found in this table, step (1)\nis finished. If not, a search for a module definition is started.\nWhen a module is found, it is loaded. Details of the module searching\nand loading process are implementation and platform specific. It\ngenerally involves searching for a "built-in" module with the given\nname and then searching a list of locations given as ``sys.path``.\n\nIf a built-in module is found, its built-in initialization code is\nexecuted and step (1) is finished. If no matching file is found,\n``ImportError`` is raised. If a file is found, it is parsed, yielding\nan executable code block. If a syntax error occurs, ``SyntaxError``\nis raised. Otherwise, an empty module of the given name is created\nand inserted in the module table, and then the code block is executed\nin the context of this module. Exceptions during this execution\nterminate step (1).\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. If the\nwild card form of import --- ``import *`` --- is used in a function\nand the function contains or is a nested block with free variables,\nthe compiler will raise a ``SyntaxError``.\n\n**Hierarchical module names:** when the module names contains one or\nmore dots, the module search path is carried out differently. The\nsequence of identifiers up to the last dot is used to find a\n"package"; the final identifier is then searched inside the package.\nA package is generally a subdirectory of a directory on ``sys.path``\nthat has a file ``__init__.py``.\n\nThe built-in function ``__import__()`` is provided to support\napplications that determine which modules need to be loaded\ndynamically; refer to *Built-in Functions* for additional information.\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``, ``nested_scopes`` and\n``with_statement``. They are all redundant because they are always\nenabled, and only kept for backwards 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 builtin 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', + '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\nfirst form (without ``from``) repeats these steps for each identifier\nin the list. The form with ``from`` performs step (1) once, and then\nperforms step (2) repeatedly.\n\nIn this context, to "initialize" a built-in or extension module means\nto call an initialization function that the module must provide for\nthe purpose (in the reference implementation, the function\'s name is\nobtained by prepending string "init" to the module\'s name); to\n"initialize" a Python-coded module means to execute the module\'s body.\n\nThe system maintains a table of modules that have been or are being\ninitialized, indexed by module name. This table is accessible as\n``sys.modules``. When a module name is found in this table, step (1)\nis finished. If not, a search for a module definition is started.\nWhen a module is found, it is loaded. Details of the module searching\nand loading process are implementation and platform specific. It\ngenerally involves searching for a "built-in" module with the given\nname and then searching a list of locations given as ``sys.path``.\n\nIf a built-in module is found, its built-in initialization code is\nexecuted and step (1) is finished. If no matching file is found,\n``ImportError`` is raised. If a file is found, it is parsed, yielding\nan executable code block. If a syntax error occurs, ``SyntaxError``\nis raised. Otherwise, an empty module of the given name is created\nand inserted in the module table, and then the code block is executed\nin the context of this module. Exceptions during this execution\nterminate step (1).\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. If the\nwild card form of import --- ``import *`` --- is used in a function\nand the function contains or is a nested block with free variables,\nthe compiler will raise a ``SyntaxError``.\n\n**Hierarchical module names:** when the module names contains one or\nmore dots, the module search path is carried out differently. The\nsequence of identifiers up to the last dot is used to find a\n"package"; the final identifier is then searched inside the package.\nA package is generally a subdirectory of a directory on ``sys.path``\nthat has a file ``__init__.py``.\n\nThe built-in function ``__import__()`` is provided to support\napplications that determine which modules need to be loaded\ndynamically; refer to *Built-in Functions* for additional information.\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 builtin 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', '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-builtin\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* 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, ``cmp([1,2,x], [1,2,y])`` returns\n the same as ``cmp(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 their sorted\n ``(key, value)`` lists compare equal. [4] Outcomes other than\n equality are resolved consistently, but are not otherwise defined.\n [5]\n\n* Most other objects of builtin 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\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.\n\nFor the list and tuple types, ``x in y`` is true if and only if there\nexists an index *i* such that ``x == y[i]`` is true.\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__()`` and do\ndefine ``__getitem__()``, ``x in y`` is true if and only if there is a\nnon-negative 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. [6]\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': '\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', @@ -59,7 +59,7 @@ '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', '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. If there are no base\n classes, this will be an empty tuple.\n\nclass.__name__\n\n The name of the class or type.\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] To format only a tuple you should therefore provide a singleton\n tuple whose only element is the tuple to be formatted.\n\n[5] These numbers are fairly arbitrary. They are intended to avoid\n printing endless strings of meaningless digits without hampering\n correct use and without having to know the exact precision of\n floating point values on a particular machine.\n\n[6] The advantage of leaving the newline on is that returning an empty\n string is then an unambiguous EOF indication. It is also possible\n (in cases where it might matter, for example, if you want to make\n an exact copy of a file while scanning its lines) to tell whether\n the last line of a file ended in a newline or not (yes this\n happens!).\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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n method is called.\n\nobject.__repr__(self)\n\n Called by the ``repr()`` built-in function and by string\n conversions (reverse quotes) to compute the "official" string\n representation of an object. If at all possible, this should look\n like a valid Python expression that could be used to recreate an\n object with the same value (given an appropriate environment). If\n this is not possible, a string of the form ``<...some useful\n description...>`` should be returned. The return value must be a\n string object. If a class defines ``__repr__()`` but not\n ``__str__()``, then ``__repr__()`` is also used when an "informal"\n string representation of instances of that class is 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.__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\nobject.__hash__(self)\n\n Called for the key object for dictionary operations, and by the\n built-in function ``hash()``. Should return an integer usable as a\n hash value for dictionary operations. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g., using exclusive or) the hash\n values for the components of the object that also play a part in\n 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 dictionary keys. If a class defines mutable objects and\n implements an ``__eq__()`` method, it should not implement\n ``__hash__()``, since the dictionary implementation requires that a\n key\'s hash value is immutable (if the object\'s hash value changes,\n 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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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 builtin 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 list must be\n returned.\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 the\nclass dictionary of another class, known as the *owner* class. 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, A)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. Normally, data\ndescriptors define both ``__get__()`` and ``__set__()``, while non-\ndata descriptors have just the ``__get__()`` method. Data descriptors\nalways override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances. [2]\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* 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* 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__*.\n\n* *__slots__* do not work for classes derived from "variable-length"\n built-in types such as ``int``, ``str`` and ``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()``. A class\ndefinition is read into a separate namespace and the value of class\nname is bound to the result of ``type(name, bases, dict)``.\n\nWhen the class definition is read, if *__metaclass__* is defined then\nthe callable assigned to it will be called instead of ``type()``. This\nallows classes or functions to be written which monitor or alter the\nclass creation process:\n\n* Modifying the class dictionary prior to the class being created.\n\n* Returning an instance of another class -- essentially performing the\n role of a factory function.\n\nThese steps will have to be performed in the metaclass\'s ``__new__()``\nmethod -- ``type.__new__()`` can then be called from this method to\ncreate a class with different properties. This example adds a new\nelement to the class dictionary before creating the class:\n\n class metacls(type):\n def __new__(mcs, name, bases, dict):\n dict[\'foo\'] = \'metacls was here\'\n return type.__new__(mcs, name, bases, dict)\n\nYou can of course also override other class methods (or add new\nmethods); for example defining a custom ``__call__()`` method in the\nmetaclass allows custom behavior when the class is called, e.g. not\nalways creating a new instance.\n\n__metaclass__\n\n This variable can be any callable accepting arguments for ``name``,\n ``bases``, and ``dict``. Upon class creation, the callable is used\n instead of the built-in ``type()``.\n\nThe appropriate metaclass is determined by the following precedence\nrules:\n\n* If ``dict[\'__metaclass__\']`` exists, it is used.\n\n* Otherwise, if there is at least one base class, its metaclass is\n used (this looks for a *__class__* attribute first and if not found,\n uses its type).\n\n* Otherwise, if a global variable named __metaclass__ exists, it is\n used.\n\n* Otherwise, the default metaclass (``type``) is used.\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored including logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\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()`` builtin 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()`` builtin will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects should\n normally only provide ``__reversed__()`` if they do not support the\n sequence protocol and an efficient implementation of reverse\n iteration is possible.\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\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. [3] 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 operations (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\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 operation falls back to the normal methods. For instance, to\n evaluate the expression ``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(object):\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 may also bypass the\n``__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):\n ... __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] A descriptor can define any combination of ``__get__()``,\n ``__set__()`` and ``__delete__()``. If it does not define\n ``__get__()``, then accessing the attribute even on an instance\n will return the descriptor object itself. If the descriptor\n defines ``__set__()`` and/or ``__delete__()``, it is a data\n descriptor; if it defines neither, it is a non-data descriptor.\n\n[3] 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', + '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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n 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.__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\nobject.__hash__(self)\n\n Called for the key object for dictionary operations, and by the\n built-in function ``hash()``. Should return an integer usable as a\n hash value for dictionary operations. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g., using exclusive or) the hash\n values for the components of the object that also play a part in\n 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 dictionary keys. If a class defines mutable objects and\n implements an ``__eq__()`` method, it should not implement\n ``__hash__()``, since the dictionary implementation requires that a\n key\'s hash value is immutable (if the object\'s hash value changes,\n 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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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 builtin 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 list must be\n returned.\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 the\nclass dictionary of another class, known as the *owner* class. 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, A)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. Normally, data\ndescriptors define both ``__get__()`` and ``__set__()``, while non-\ndata descriptors have just the ``__get__()`` method. Data descriptors\nalways override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances. [2]\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* 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* 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__*.\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()``. A class\ndefinition is read into a separate namespace and the value of class\nname is bound to the result of ``type(name, bases, dict)``.\n\nWhen the class definition is read, if a callable ``metaclass`` keyword\nargument is passed after the bases in the class definition, the\ncallable given will be called instead of ``type()``. If other keyword\narguments are passed, they will also be passed to the metaclass. This\nallows classes or functions to be written which monitor or alter the\nclass creation process:\n\n* Modifying the class dictionary prior to the class being created.\n\n* Returning an instance of another class -- essentially performing the\n role of a factory function.\n\nThese steps will have to be performed in the metaclass\'s ``__new__()``\nmethod -- ``type.__new__()`` can then be called from this method to\ncreate a class with different properties. This example adds a new\nelement to the class dictionary before creating the class:\n\n class metacls(type):\n def __new__(mcs, name, bases, dict):\n dict[\'foo\'] = \'metacls was here\'\n return type.__new__(mcs, name, bases, dict)\n\nYou can of course also override other class methods (or add new\nmethods); for example defining a custom ``__call__()`` method in the\nmetaclass allows custom behavior when the class is called, e.g. not\nalways creating a new instance.\n\nIf the metaclass has a ``__prepare__()`` attribute (usually\nimplemented as a class or static method), it is called before the\nclass body is evaluated with the name of the class and a tuple of its\nbases for arguments. It should return an object that supports the\nmapping interface that will be used to store the namespace of the\nclass. The default is a plain dictionary. This could be used, for\nexample, to keep track of the order that class attributes are declared\nin by returning an ordered dictionary.\n\nThe appropriate metaclass is determined by the following precedence\nrules:\n\n* If the ``metaclass`` keyword argument is based with the bases, it is\n used.\n\n* Otherwise, if there is at least one base class, its metaclass is\n used.\n\n* Otherwise, the default metaclass (``type``) is used.\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored including logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\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()`` builtin 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()`` builtin will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects should\n normally only provide ``__reversed__()`` if they do not support the\n sequence protocol and an efficient implementation of reverse\n iteration is possible.\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\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. [3] 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 operations (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\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 operation falls back to the normal methods. For instance, to\n evaluate the expression ``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(object):\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 may also bypass the\n``__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] A descriptor can define any combination of ``__get__()``,\n ``__set__()`` and ``__delete__()``. If it does not define\n ``__get__()``, then accessing the attribute even on an instance\n will return the descriptor object itself. If the descriptor\n defines ``__set__()`` and/or ``__delete__()``, it is a data\n descriptor; if it defines neither, it is a non-data descriptor.\n\n[3] 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. Note that none of\nthese methods take keyword arguments.\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 only its first character\n capitalized.\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 occurrences of substring *sub* in the range\n [*start*, *end*]. Optional arguments *start* and *end* are\n interpreted as in slice notation.\n\nstr.encode([encoding[, errors]])\n\n Return an encoded version of the string. Default encoding is the\n current default string encoding. *errors* may be given to set a\n different error handling scheme. The default for *errors* is\n ``\'strict\'``, meaning that encoding errors raise a\n ``UnicodeError``. Other possible values are ``\'ignore\'``,\n ``\'replace\'``, ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and\n any other name registered via ``codecs.register_error()``, see\n section *Codec Base Classes*. For a list of possible encodings, see\n section *Standard Encodings*.\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 one 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 range [*start*, *end*].\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\nstr.format(format_string, *args, **kwargs)\n\n Perform a string formatting operation. The *format_string*\n argument can contain literal text or replacement fields delimited\n by braces ``{}``. Each replacement field contains either the\n numeric index of a positional argument, or the name of a keyword\n argument. Returns a copy of *format_string* where each replacement\n field is replaced with the string value of the corresponding\n 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.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.\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.\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 include digit characters, and all characters that that\n can be used to form decimal-radix numbers, e.g. U+0660, ARABIC-\n 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.\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 in the string are lowercase and\n 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.\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.\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 in the string are uppercase and\n there is at least one cased character, false otherwise.\n\nstr.join(seq)\n\n Return a string which is the concatenation of the strings in the\n sequence *seq*. A ``TypeError`` will be raised if there are any\n non-string values in *seq*, including ``bytes`` objects. The\n 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\n ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string converted to lowercase.\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\nstr.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]. Optional\n arguments *start* and *end* are interpreted as in slice notation.\n 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\n ``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[, maxsplit]])\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[, maxsplit]])\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, then there is no limit\n 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.\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.\n\nstr.title()\n\n Return a titlecased version of the string: words start with\n uppercase characters, all remaining cased characters are lowercase.\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\n ordinals(integers) to Unicode ordinals, strings or ``None``.\n Unmapped characters are left untouched. Characters mapped to\n ``None`` are deleted.\n\n A *map* for ``translate()`` is usually best created by\n ``str.maketrans()``.\n\n You can use the ``maketrans()`` helper function in the ``string``\n module to create a translation table. For string objects, set the\n *table* argument to ``None`` for translations that only delete\n characters:\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 converted to uppercase.\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 ``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" | "R"\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"\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\nString literals may optionally be prefixed with a letter ``\'r\'`` or\n``\'R\'``; such strings are called *raw strings* and treat backslashes\nas literal characters. As a result, ``\'\\U\'`` and ``\'\\u\'`` escapes in\nraw strings are not treated specially.\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\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 | |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (4) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (5) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, at most two hex digits are accepted.\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. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Unlike in Standard C, exactly\n two hex digits are required.\n\n5. 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). Individual code units which form parts of a surrogate\n pair can be encoded using this escape sequence.\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. If this value is negative, the length of the sequence is\nadded to it (so that, e.g., ``x[-1]`` selects the last item of ``x``.)\nThe resulting value must be a nonnegative integer less than the number\nof items in the sequence, and the subscription selects the item whose\nindex is that value (counting from zero).\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n', Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Nov 6 04:29:32 2008 @@ -4,13 +4,10 @@ (editors: check NEWS.help for information about editing NEWS using ReST.) -What's New in Python 3.0 beta 5 -=============================== - -[Note: due to the number of unresolved issues we're going back to beta - releases for a while.] +What's New in Python 3.0 release candidate 2 +============================================ -*Release date: XX-XXX-2008* +*Release date: 05-Nov-2008* Core and Builtins ----------------- Modified: python/branches/py3k/Misc/RPM/python-3.0.spec ============================================================================== --- python/branches/py3k/Misc/RPM/python-3.0.spec (original) +++ python/branches/py3k/Misc/RPM/python-3.0.spec Thu Nov 6 04:29:32 2008 @@ -34,7 +34,7 @@ %define name python #--start constants-- -%define version 3.0rc1 +%define version 3.0rc2 %define libver 3.0 #--end constants-- %define release 1pydotorg Modified: python/branches/py3k/README ============================================================================== --- python/branches/py3k/README (original) +++ python/branches/py3k/README Thu Nov 6 04:29:32 2008 @@ -1,4 +1,4 @@ -This is Python version 3.0 release candidate 1 +This is Python version 3.0 release candidate 2 ============================================== For notes specific to this release, see RELNOTES in this directory. From nnorwitz at gmail.com Thu Nov 6 14:43:37 2008 From: nnorwitz at gmail.com (Neal Norwitz) Date: Thu, 6 Nov 2008 08:43:37 -0500 Subject: [Python-3000-checkins] Python Regression Test Failures doc (1) Message-ID: <20081106134337.GA5412@python.psfb.org> svn update tools/sphinx U tools/sphinx/__init__.py U tools/sphinx/htmlwriter.py U tools/sphinx/config.py U tools/sphinx/latexwriter.py U tools/sphinx/directives/desc.py U tools/sphinx/directives/other.py U tools/sphinx/texinputs/sphinx.sty U tools/sphinx/textwriter.py U tools/sphinx/builder.py U tools/sphinx/util/texescape.py U tools/sphinx/util/compat.py Updated to revision 67119. svn update tools/docutils At revision 67119. svn update tools/jinja At revision 67119. svn update tools/pygments At revision 67119. mkdir -p build/html build/doctrees python2.5 tools/sphinx-build.py -b html -d build/doctrees -D latex_paper_size= . build/html Sphinx v0.5, building html loading pickled environment... done building [html]: targets for 0 source files that are out of date updating environment: [config changed] 393 added, 0 changed, 0 removed reading sources... about bugs c-api/abstract c-api/allocation c-api/arg c-api/bool c-api/buffer c-api/bytearray c-api/bytes c-api/cell c-api/cobject c-api/complex c-api/concrete c-api/conversion c-api/datetime c-api/descriptor c-api/dict c-api/exceptions c-api/file c-api/float c-api/function c-api/gcsupport c-api/gen c-api/import c-api/index c-api/init c-api/intro c-api/iter c-api/iterator c-api/list c-api/long c-api/mapping c-api/marshal c-api/memory c-api/method c-api/module c-api/none c-api/number c-api/objbuffer c-api/object c-api/objimpl c-api/refcounting c-api/reflection c-api/sequence c-api/set c-api/slice c-api/structures c-api/sys c-api/tuple c-api/type c-api/typeobj c-api/unicode c-api/utilities c-api/veryhigh c-api/weakref contents copyright distutils/apiref distutils/builtdist distutils/commandref distutils/configfile distutils/examples distutils/extending distutils/index distutils/introduction distutils/packageindex distutils/setupscript distutils/sourcedist distutils/uploading documenting/fromlatex documenting/index documenting/intro documenting/markup documenting/rest documenting/sphinx documenting/style extending/building extending/embedding extending/extending extending/index extending/newtypes extending/windows glossary howto/advocacy howto/cporting howto/curses howto/doanddont howto/functional howto/index howto/regex howto/sockets howto/unicode howto/urllib2 howto/webservers install/index library/2to3 library/__future__ library/__main__ library/_dummy_thread library/_thread library/abc library/aifc library/allos library/archiving library/array library/ast library/asynchat library/asyncore library/atexit library/audioop library/base64 library/bdb library/binascii library/binhex library/bisect library/builtins library/bz2 library/calendar library/cgi library/cgitb library/chunk library/cmath library/cmd library/code library/codecs library/codeop library/collections library/colorsys library/compileall library/configparser library/constants library/contextlib library/copy library/copyreg library/crypt library/crypto library/csv library/ctypes library/curses library/curses.ascii library/curses.panel library/custominterp library/datatypes library/datetime library/dbm library/debug library/decimal library/development library/difflib library/dis library/distutils library/doctest library/dummy_threading library/email library/email-examples library/email.charset library/email.encoders library/email.errors library/email.generator library/email.header library/email.iterators library/email.message library/email.mime library/email.parser library/email.util library/errno library/exceptions library/fcntl library/filecmp library/fileformats library/fileinput library/filesys library/fnmatch library/formatter library/fpectl library/fractions library/frameworks library/ftplib library/functions library/functools library/gc library/getopt library/getpass library/gettext library/glob library/grp library/gzip library/hashlib library/heapq library/hmac library/html.entities library/html.parser library/http.client library/http.cookiejar library/http.cookies library/http.server library/i18n library/idle library/imaplib library/imghdr library/imp library/index library/inspect library/internet library/intro library/io library/ipc library/itertools library/json library/keyword library/language library/linecache library/locale library/logging library/macpath library/mailbox library/mailcap library/markup library/marshal library/math library/mimetypes library/misc library/mm library/mmap library/modulefinder library/modules library/msilib library/msvcrt library/multiprocessing library/netdata library/netrc library/nis library/nntplib library/numbers library/numeric library/objects library/operator library/optparse library/os library/os.path library/ossaudiodev library/othergui library/parser library/pdb library/persistence library/pickle library/pickletools library/pipes library/pkgutil library/platform library/plistlib library/poplib library/posix library/pprint library/profile library/pty library/pwd library/py_compile library/pyclbr library/pydoc library/pyexpat library/python library/queue library/quopri library/random library/re library/readline library/reprlib library/resource library/rlcompleter library/runpy library/sched library/select library/shelve library/shlex library/shutil library/signal library/site library/smtpd library/smtplib library/sndhdr library/socket library/socketserver library/someos library/spwd library/sqlite3 library/ssl library/stat library/stdtypes library/string library/stringprep library/strings library/struct library/subprocess library/sunau library/symbol library/symtable library/sys library/syslog library/tabnanny library/tarfile library/telnetlib library/tempfile library/termios library/test library/textwrap library/threading library/time library/timeit library/tk library/tkinter library/tkinter.scrolledtext library/tkinter.tix library/token library/tokenize library/trace library/traceback library/tty library/turtle library/types library/undoc library/unicodedata library/unittest library/unix library/urllib.error library/urllib.parse library/urllib.request library/urllib.robotparser library/uu library/uuid library/warnings library/wave library/weakref library/webbrowser library/windows library/winreg library/winsound library/wsgiref library/xdrlib library/xml.dom library/xml.dom.minidom library/xml.dom.pulldom library/xml.etree.elementtree library/xml.sax library/xml.sax.handler library/xml.sax.reader library/xml.sax.utils library/xmlrpc.client library/xmlrpc.server library/zipfile library/zipimport library/zlib license reference/compound_stmts reference/datamodel reference/executionmodel reference/expressions reference/grammar reference/index reference/introduction reference/lexical_analysis reference/simple_stmts reference/toplevel_components tutorial/appetite tutorial/classes tutorial/controlflow tutorial/datastructures tutorial/errors tutorial/floatingpoint tutorial/index tutorial/inputoutput tutorial/interactive tutorial/interpreter tutorial/introduction tutorial/modules tutorial/stdlib tutorial/stdlib2 tutorial/whatnow using/cmdline Exception occurred: File "/home/neal/python/py3k/Doc/tools/docutils/nodes.py", line 90, in setup_child child.parent = self AttributeError: 'list' object has no attribute 'parent' The full traceback has been saved in /tmp/sphinx-err-DFSQlx.log, if you want to report the issue to the author. Please also report this if it was a user error, so that a better error message can be provided next time. Send reports to sphinx-dev at googlegroups.com. Thanks! make: *** [build] Error 1 From python-3000-checkins at python.org Thu Nov 6 18:30:03 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Thu, 6 Nov 2008 18:30:03 +0100 (CET) Subject: [Python-3000-checkins] r67122 - in python/branches/py3k: Misc/NEWS PCbuild/pyd.vsprops PCbuild/pyd_d.vsprops Message-ID: <20081106173003.F29241E4012@bag.python.org> Author: martin.v.loewis Date: Thu Nov 6 18:30:03 2008 New Revision: 67122 Log: Merged revisions 67120 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67120 | martin.v.loewis | 2008-11-06 17:43:00 +0100 (Do, 06 Nov 2008) | 2 lines Issue #4120: Exclude manifest from extension modules in VS2008. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/PCbuild/pyd.vsprops python/branches/py3k/PCbuild/pyd_d.vsprops Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Nov 6 18:30:03 2008 @@ -103,6 +103,8 @@ Build ----- +- Issue #4120: Exclude manifest from extension modules in VS2008. + - Issue #4091: Install pythonxy.dll in system32 again. - Issue #4018: Disable "for me" installations on Vista. Modified: python/branches/py3k/PCbuild/pyd.vsprops ============================================================================== --- python/branches/py3k/PCbuild/pyd.vsprops (original) +++ python/branches/py3k/PCbuild/pyd.vsprops Thu Nov 6 18:30:03 2008 @@ -1,4 +1,4 @@ - + + + Author: martin.v.loewis Date: Thu Nov 6 20:46:56 2008 New Revision: 67127 Log: Merged revisions 67125 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67125 | martin.v.loewis | 2008-11-06 20:46:03 +0100 (Do, 06 Nov 2008) | 2 lines Stop including fake manifest file in DLLs directory. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Tools/msi/msi.py Modified: python/branches/py3k/Tools/msi/msi.py ============================================================================== --- python/branches/py3k/Tools/msi/msi.py (original) +++ python/branches/py3k/Tools/msi/msi.py Thu Nov 6 20:46:56 2008 @@ -941,10 +941,12 @@ root.add_file(manifest[0], **manifest[1]) root.add_file(crtdll[0], **crtdll[1]) # Copy the manifest - manifest_dlls = manifest[0]+".root" - open(manifest_dlls, "w").write(open(manifest[1]['src']).read().replace("msvcr","../msvcr")) - DLLs.start_component("msvcr90_dlls", feature=private_crt) - DLLs.add_file(manifest[0], src=os.path.abspath(manifest_dlls)) + # Actually, don't do that anymore - no DLL in DLLs should have a manifest + # dependency on msvcr90.dll anymore, so this should not be necessary + #manifest_dlls = manifest[0]+".root" + #open(manifest_dlls, "w").write(open(manifest[1]['src']).read().replace("msvcr","../msvcr")) + #DLLs.start_component("msvcr90_dlls", feature=private_crt) + #DLLs.add_file(manifest[0], src=os.path.abspath(manifest_dlls)) # Now start the main component for the DLLs directory; # no regular files have been added to the directory yet. From python-3000-checkins at python.org Fri Nov 7 02:38:26 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 7 Nov 2008 02:38:26 +0100 (CET) Subject: [Python-3000-checkins] r67132 - python/branches/py3k/Lib/pydoc_topics.py Message-ID: <20081107013826.E797D1E4002@bag.python.org> Author: barry.warsaw Date: Fri Nov 7 02:38:26 2008 New Revision: 67132 Log: update Modified: python/branches/py3k/Lib/pydoc_topics.py Modified: python/branches/py3k/Lib/pydoc_topics.py ============================================================================== --- python/branches/py3k/Lib/pydoc_topics.py (original) +++ python/branches/py3k/Lib/pydoc_topics.py Fri Nov 7 02:38:26 2008 @@ -1,4 +1,4 @@ -# Autogenerated by Sphinx on Wed Nov 5 22:25:20 2008 +# Autogenerated by Sphinx on Thu Nov 6 20:34:10 2008 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:\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 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 a sequence 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* 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(In the current implementation, the syntax for targets is taken to be\nthe same as for expressions, and invalid syntax is rejected during the\ncode generation phase, causing less 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 ::= target augop (expression_list | yield_expression)\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 initial value is\nretrieved with a ``getattr()`` and the result is assigned with a\n``setattr()``. Notice that the two methods do not necessarily refer\nto the same variable. When ``getattr()`` refers to a class variable,\n``setattr()`` still writes to an instance variable. For example:\n\n class A:\n x = 3 # class variable\n a = A()\n a.x += 1 # writes a.x as 4 leaving A.x as 3\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', From nnorwitz at gmail.com Fri Nov 7 02:43:38 2008 From: nnorwitz at gmail.com (Neal Norwitz) Date: Thu, 6 Nov 2008 20:43:38 -0500 Subject: [Python-3000-checkins] Python Regression Test Failures doc (1) Message-ID: <20081107014338.GA19139@python.psfb.org> svn update tools/sphinx At revision 67133. svn update tools/docutils At revision 67133. svn update tools/jinja At revision 67133. svn update tools/pygments At revision 67133. mkdir -p build/html build/doctrees python2.5 tools/sphinx-build.py -b html -d build/doctrees -D latex_paper_size= . build/html Sphinx v0.5, building html loading pickled environment... done building [html]: targets for 0 source files that are out of date updating environment: [config changed] 393 added, 0 changed, 0 removed reading sources... about bugs c-api/abstract c-api/allocation c-api/arg c-api/bool c-api/buffer c-api/bytearray c-api/bytes c-api/cell c-api/cobject c-api/complex c-api/concrete c-api/conversion c-api/datetime c-api/descriptor c-api/dict c-api/exceptions c-api/file c-api/float c-api/function c-api/gcsupport c-api/gen c-api/import c-api/index c-api/init c-api/intro c-api/iter c-api/iterator c-api/list c-api/long c-api/mapping c-api/marshal c-api/memory c-api/method c-api/module c-api/none c-api/number c-api/objbuffer c-api/object c-api/objimpl c-api/refcounting c-api/reflection c-api/sequence c-api/set c-api/slice c-api/structures c-api/sys c-api/tuple c-api/type c-api/typeobj c-api/unicode c-api/utilities c-api/veryhigh c-api/weakref contents copyright distutils/apiref distutils/builtdist distutils/commandref distutils/configfile distutils/examples distutils/extending distutils/index distutils/introduction distutils/packageindex distutils/setupscript distutils/sourcedist distutils/uploading documenting/fromlatex documenting/index documenting/intro documenting/markup documenting/rest documenting/sphinx documenting/style extending/building extending/embedding extending/extending extending/index extending/newtypes extending/windows glossary howto/advocacy howto/cporting howto/curses howto/doanddont howto/functional howto/index howto/regex howto/sockets howto/unicode howto/urllib2 howto/webservers install/index library/2to3 library/__future__ library/__main__ library/_dummy_thread library/_thread library/abc library/aifc library/allos library/archiving library/array library/ast library/asynchat library/asyncore library/atexit library/audioop library/base64 library/bdb library/binascii library/binhex library/bisect library/builtins library/bz2 library/calendar library/cgi library/cgitb library/chunk library/cmath library/cmd library/code library/codecs library/codeop library/collections library/colorsys library/compileall library/configparser library/constants library/contextlib library/copy library/copyreg library/crypt library/crypto library/csv library/ctypes library/curses library/curses.ascii library/curses.panel library/custominterp library/datatypes library/datetime library/dbm library/debug library/decimal library/development library/difflib library/dis library/distutils library/doctest library/dummy_threading library/email library/email-examples library/email.charset library/email.encoders library/email.errors library/email.generator library/email.header library/email.iterators library/email.message library/email.mime library/email.parser library/email.util library/errno library/exceptions library/fcntl library/filecmp library/fileformats library/fileinput library/filesys library/fnmatch library/formatter library/fpectl library/fractions library/frameworks library/ftplib library/functions library/functools library/gc library/getopt library/getpass library/gettext library/glob library/grp library/gzip library/hashlib library/heapq library/hmac library/html.entities library/html.parser library/http.client library/http.cookiejar library/http.cookies library/http.server library/i18n library/idle library/imaplib library/imghdr library/imp library/index library/inspect library/internet library/intro library/io library/ipc library/itertools library/json library/keyword library/language library/linecache library/locale library/logging library/macpath library/mailbox library/mailcap library/markup library/marshal library/math library/mimetypes library/misc library/mm library/mmap library/modulefinder library/modules library/msilib library/msvcrt library/multiprocessing library/netdata library/netrc library/nis library/nntplib library/numbers library/numeric library/objects library/operator library/optparse library/os library/os.path library/ossaudiodev library/othergui library/parser library/pdb library/persistence library/pickle library/pickletools library/pipes library/pkgutil library/platform library/plistlib library/poplib library/posix library/pprint library/profile library/pty library/pwd library/py_compile library/pyclbr library/pydoc library/pyexpat library/python library/queue library/quopri library/random library/re library/readline library/reprlib library/resource library/rlcompleter library/runpy library/sched library/select library/shelve library/shlex library/shutil library/signal library/site library/smtpd library/smtplib library/sndhdr library/socket library/socketserver library/someos library/spwd library/sqlite3 library/ssl library/stat library/stdtypes library/string library/stringprep library/strings library/struct library/subprocess library/sunau library/symbol library/symtable library/sys library/syslog library/tabnanny library/tarfile library/telnetlib library/tempfile library/termios library/test library/textwrap library/threading library/time library/timeit library/tk library/tkinter library/tkinter.scrolledtext library/tkinter.tix library/token library/tokenize library/trace library/traceback library/tty library/turtle library/types library/undoc library/unicodedata library/unittest library/unix library/urllib.error library/urllib.parse library/urllib.request library/urllib.robotparser library/uu library/uuid library/warnings library/wave library/weakref library/webbrowser library/windows library/winreg library/winsound library/wsgiref library/xdrlib library/xml.dom library/xml.dom.minidom library/xml.dom.pulldom library/xml.etree.elementtree library/xml.sax library/xml.sax.handler library/xml.sax.reader library/xml.sax.utils library/xmlrpc.client library/xmlrpc.server library/zipfile library/zipimport library/zlib license reference/compound_stmts reference/datamodel reference/executionmodel reference/expressions reference/grammar reference/index reference/introduction reference/lexical_analysis reference/simple_stmts reference/toplevel_components tutorial/appetite tutorial/classes tutorial/controlflow tutorial/datastructures tutorial/errors tutorial/floatingpoint tutorial/index tutorial/inputoutput tutorial/interactive tutorial/interpreter tutorial/introduction tutorial/modules tutorial/stdlib tutorial/stdlib2 tutorial/whatnow using/cmdline Exception occurred: File "/home/neal/python/py3k/Doc/tools/docutils/nodes.py", line 90, in setup_child child.parent = self AttributeError: 'list' object has no attribute 'parent' The full traceback has been saved in /tmp/sphinx-err-TxU4cI.log, if you want to report the issue to the author. Please also report this if it was a user error, so that a better error message can be provided next time. Send reports to sphinx-dev at googlegroups.com. Thanks! make: *** [build] Error 1 From python-3000-checkins at python.org Fri Nov 7 04:06:24 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 7 Nov 2008 04:06:24 +0100 (CET) Subject: [Python-3000-checkins] r67136 - python/branches/py3k/Doc/using/cmdline.rst Message-ID: <20081107030624.90D0D1E4002@bag.python.org> Author: barry.warsaw Date: Fri Nov 7 04:06:24 2008 New Revision: 67136 Log: A totally crappy workaround for issue 4266, but this allows me to build the release. Modified: python/branches/py3k/Doc/using/cmdline.rst Modified: python/branches/py3k/Doc/using/cmdline.rst ============================================================================== --- python/branches/py3k/Doc/using/cmdline.rst (original) +++ python/branches/py3k/Doc/using/cmdline.rst Fri Nov 7 04:06:24 2008 @@ -135,9 +135,6 @@ an empty string (``""``) and the current directory will be added to the start of :data:`sys.path`. - .. seealso:: - :ref:`tut-invoking` - Generic options ~~~~~~~~~~~~~~~ From python-3000-checkins at python.org Fri Nov 7 04:46:33 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 7 Nov 2008 04:46:33 +0100 (CET) Subject: [Python-3000-checkins] r67139 - in python/branches/py3k: Include/patchlevel.h Misc/NEWS Message-ID: <20081107034633.896DC1E4002@bag.python.org> Author: barry.warsaw Date: Fri Nov 7 04:46:33 2008 New Revision: 67139 Log: post release cleanup Modified: python/branches/py3k/Include/patchlevel.h python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Include/patchlevel.h ============================================================================== --- python/branches/py3k/Include/patchlevel.h (original) +++ python/branches/py3k/Include/patchlevel.h Fri Nov 7 04:46:33 2008 @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "3.0rc2" +#define PY_VERSION "3.0rc2+" /*--end constants--*/ /* Subversion Revision number of this file (not of the repository) */ Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 7 04:46:33 2008 @@ -4,6 +4,18 @@ (editors: check NEWS.help for information about editing NEWS using ReST.) +What's New in Python {XXX PUT NEXT VERSION HERE XXX}? +================================ + +*Release date: XX-XXX-2008* + +Core and Builtins +----------------- + +Library +------- + + What's New in Python 3.0 release candidate 2 ============================================ From python-3000-checkins at python.org Fri Nov 7 04:51:43 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 7 Nov 2008 04:51:43 +0100 (CET) Subject: [Python-3000-checkins] r67141 - python/branches/py3k/Misc/NEWS Message-ID: <20081107035143.518E81E4002@bag.python.org> Author: benjamin.peterson Date: Fri Nov 7 04:51:42 2008 New Revision: 67141 Log: name the release Modified: python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 7 04:51:42 2008 @@ -4,11 +4,12 @@ (editors: check NEWS.help for information about editing NEWS using ReST.) -What's New in Python {XXX PUT NEXT VERSION HERE XXX}? -================================ +What's New in Python 3.0 release candiate 3? +============================================ *Release date: XX-XXX-2008* + Core and Builtins ----------------- From python-3000-checkins at python.org Fri Nov 7 10:39:56 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Fri, 7 Nov 2008 10:39:56 +0100 (CET) Subject: [Python-3000-checkins] r67148 - in python/branches/py3k: Doc/library/email.parser.rst Doc/library/sqlite3.rst Doc/library/threading.rst Doc/tutorial/controlflow.rst Doc/using/cmdline.rst Message-ID: <20081107093956.D00381E4002@bag.python.org> Author: georg.brandl Date: Fri Nov 7 10:39:56 2008 New Revision: 67148 Log: Merged revisions 67117-67119,67123-67124,67143 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67117 | georg.brandl | 2008-11-06 11:17:58 +0100 (Thu, 06 Nov 2008) | 2 lines #4268: Use correct module for two toplevel functions. ........ r67118 | georg.brandl | 2008-11-06 11:19:11 +0100 (Thu, 06 Nov 2008) | 2 lines #4267: small fixes in sqlite3 docs. ........ r67119 | georg.brandl | 2008-11-06 11:20:49 +0100 (Thu, 06 Nov 2008) | 2 lines #4245: move Thread section to the top. ........ r67123 | georg.brandl | 2008-11-06 19:49:15 +0100 (Thu, 06 Nov 2008) | 2 lines #4247: add "pass" examples to tutorial. ........ r67124 | andrew.kuchling | 2008-11-06 20:23:02 +0100 (Thu, 06 Nov 2008) | 1 line Fix grammar error; reword two paragraphs ........ r67143 | georg.brandl | 2008-11-07 09:27:39 +0100 (Fri, 07 Nov 2008) | 2 lines Fix syntax. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/email.parser.rst python/branches/py3k/Doc/library/sqlite3.rst python/branches/py3k/Doc/library/threading.rst python/branches/py3k/Doc/tutorial/controlflow.rst python/branches/py3k/Doc/using/cmdline.rst Modified: python/branches/py3k/Doc/library/email.parser.rst ============================================================================== --- python/branches/py3k/Doc/library/email.parser.rst (original) +++ python/branches/py3k/Doc/library/email.parser.rst Fri Nov 7 10:39:56 2008 @@ -145,6 +145,7 @@ a common task, two functions are provided as a convenience. They are available in the top-level :mod:`email` package namespace. +.. currentmodule:: email .. function:: message_from_string(s[, _class[, strict]]) Modified: python/branches/py3k/Doc/library/sqlite3.rst ============================================================================== --- python/branches/py3k/Doc/library/sqlite3.rst (original) +++ python/branches/py3k/Doc/library/sqlite3.rst Fri Nov 7 10:39:56 2008 @@ -62,10 +62,10 @@ c.execute('select * from stocks where symbol=?', t) # Larger example - for t in (('2006-03-28', 'BUY', 'IBM', 1000, 45.00), + for t in [('2006-03-28', 'BUY', 'IBM', 1000, 45.00), ('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00), ('2006-04-06', 'SELL', 'IBM', 500, 53.00), - ): + ]: c.execute('insert into stocks values (?,?,?,?,?)', t) To retrieve data after executing a SELECT statement, you can either treat the @@ -421,10 +421,9 @@ import sqlite3, os con = sqlite3.connect('existing_db.db') - full_dump = os.linesep.join(con.iterdump()) - f = open('dump.sql', 'w') - f.writelines(full_dump) - f.close() + with open('dump.sql', 'w') as f: + for line in con.iterdump(): + f.write('%s\n' % line) .. _sqlite3-cursor-objects: @@ -800,8 +799,8 @@ If you want **autocommit mode**, then set :attr:`isolation_level` to None. Otherwise leave it at its default, which will result in a plain "BEGIN" -statement, or set it to one of SQLite's supported isolation levels: DEFERRED, -IMMEDIATE or EXCLUSIVE. +statement, or set it to one of SQLite's supported isolation levels: "DEFERRED", +"IMMEDIATE" or "EXCLUSIVE". Modified: python/branches/py3k/Doc/library/threading.rst ============================================================================== --- python/branches/py3k/Doc/library/threading.rst (original) +++ python/branches/py3k/Doc/library/threading.rst Fri Nov 7 10:39:56 2008 @@ -168,6 +168,163 @@ All of the methods described below are executed atomically. +.. _thread-objects: + +Thread Objects +-------------- + +This class represents an activity that is run in a separate thread of control. +There are two ways to specify the activity: by passing a callable object to the +constructor, or by overriding the :meth:`run` method in a subclass. No other +methods (except for the constructor) should be overridden in a subclass. In +other words, *only* override the :meth:`__init__` and :meth:`run` methods of +this class. + +Once a thread object is created, its activity must be started by calling the +thread's :meth:`start` method. This invokes the :meth:`run` method in a +separate thread of control. + +Once the thread's activity is started, the thread is considered 'alive'. It +stops being alive when its :meth:`run` method terminates -- either normally, or +by raising an unhandled exception. The :meth:`is_alive` method tests whether the +thread is alive. + +Other threads can call a thread's :meth:`join` method. This blocks the calling +thread until the thread whose :meth:`join` method is called is terminated. + +A thread has a name. The name can be passed to the constructor, and read or +changed through the :attr:`name` attribute. + +A thread can be flagged as a "daemon thread". The significance of this flag is +that the entire Python program exits when only daemon threads are left. The +initial value is inherited from the creating thread. The flag can be set +through the :attr:`daemon` attribute. + +There is a "main thread" object; this corresponds to the initial thread of +control in the Python program. It is not a daemon thread. + +There is the possibility that "dummy thread objects" are created. These are +thread objects corresponding to "alien threads", which are threads of control +started outside the threading module, such as directly from C code. Dummy +thread objects have limited functionality; they are always considered alive and +daemonic, and cannot be :meth:`join`\ ed. They are never deleted, since it is +impossible to detect the termination of alien threads. + + +.. class:: Thread(group=None, target=None, name=None, args=(), kwargs={}) + + This constructor should always be called with keyword arguments. Arguments are: + + *group* should be ``None``; reserved for future extension when a + :class:`ThreadGroup` class is implemented. + + *target* is the callable object to be invoked by the :meth:`run` method. + Defaults to ``None``, meaning nothing is called. + + *name* is the thread name. By default, a unique name is constructed of the form + "Thread-*N*" where *N* is a small decimal number. + + *args* is the argument tuple for the target invocation. Defaults to ``()``. + + *kwargs* is a dictionary of keyword arguments for the target invocation. + Defaults to ``{}``. + + If the subclass overrides the constructor, it must make sure to invoke the base + class constructor (``Thread.__init__()``) before doing anything else to the + thread. + + +.. method:: Thread.start() + + Start the thread's activity. + + It must be called at most once per thread object. It arranges for the object's + :meth:`run` method to be invoked in a separate thread of control. + + This method will raise a :exc:`RuntimeException` if called more than once on the + same thread object. + + +.. method:: Thread.run() + + Method representing the thread's activity. + + You may override this method in a subclass. The standard :meth:`run` method + invokes the callable object passed to the object's constructor as the *target* + argument, if any, with sequential and keyword arguments taken from the *args* + and *kwargs* arguments, respectively. + + +.. method:: Thread.join([timeout]) + + Wait until the thread terminates. This blocks the calling thread until the + thread whose :meth:`join` method is called terminates -- either normally or + through an unhandled exception -- or until the optional timeout occurs. + + When the *timeout* argument is present and not ``None``, it should be a floating + point number specifying a timeout for the operation in seconds (or fractions + thereof). As :meth:`join` always returns ``None``, you must call :meth:`is_alive` + after :meth:`join` to decide whether a timeout happened -- if the thread is + still alive, the :meth:`join` call timed out. + + When the *timeout* argument is not present or ``None``, the operation will block + until the thread terminates. + + A thread can be :meth:`join`\ ed many times. + + :meth:`join` raises a :exc:`RuntimeError` if an attempt is made to join + the current thread as that would cause a deadlock. It is also an error to + :meth:`join` a thread before it has been started and attempts to do so + raises the same exception. + + +.. method:: Thread.getName() + Thread.setName() + + Old API for :attr:`~Thread.name`. + + +.. attribute:: Thread.name + + A string used for identification purposes only. It has no semantics. + Multiple threads may be given the same name. The initial name is set by the + constructor. + + +.. attribute:: Thread.ident + + The 'thread identifier' of this thread or ``None`` if the thread has not been + started. This is a nonzero integer. See the :func:`thread.get_ident()` + function. Thread identifiers may be recycled when a thread exits and another + thread is created. The identifier is available even after the thread has + exited. + + +.. method:: Thread.is_alive() + + Return whether the thread is alive. + + Roughly, a thread is alive from the moment the :meth:`start` method returns + until its :meth:`run` method terminates. The module function :func:`enumerate` + returns a list of all alive threads. + + +.. method:: Thread.isDaemon() + Thread.setDaemon() + + Old API for :attr:`~Thread.daemon`. + + +.. attribute:: Thread.daemon + + The thread's daemon flag. This must be set before :meth:`start` is called, + otherwise :exc:`RuntimeError` is raised. + + The initial value is inherited from the creating thread. + + The entire Python program exits when no alive non-daemon threads are left. + + .. _lock-objects: Lock Objects @@ -525,163 +682,6 @@ thereof). -.. _thread-objects: - -Thread Objects --------------- - -This class represents an activity that is run in a separate thread of control. -There are two ways to specify the activity: by passing a callable object to the -constructor, or by overriding the :meth:`run` method in a subclass. No other -methods (except for the constructor) should be overridden in a subclass. In -other words, *only* override the :meth:`__init__` and :meth:`run` methods of -this class. - -Once a thread object is created, its activity must be started by calling the -thread's :meth:`start` method. This invokes the :meth:`run` method in a -separate thread of control. - -Once the thread's activity is started, the thread is considered 'alive'. It -stops being alive when its :meth:`run` method terminates -- either normally, or -by raising an unhandled exception. The :meth:`is_alive` method tests whether the -thread is alive. - -Other threads can call a thread's :meth:`join` method. This blocks the calling -thread until the thread whose :meth:`join` method is called is terminated. - -A thread has a name. The name can be passed to the constructor, and read or -changed through the :attr:`name` attribute. - -A thread can be flagged as a "daemon thread". The significance of this flag is -that the entire Python program exits when only daemon threads are left. The -initial value is inherited from the creating thread. The flag can be set -through the :attr:`daemon` attribute. - -There is a "main thread" object; this corresponds to the initial thread of -control in the Python program. It is not a daemon thread. - -There is the possibility that "dummy thread objects" are created. These are -thread objects corresponding to "alien threads", which are threads of control -started outside the threading module, such as directly from C code. Dummy -thread objects have limited functionality; they are always considered alive and -daemonic, and cannot be :meth:`join`\ ed. They are never deleted, since it is -impossible to detect the termination of alien threads. - - -.. class:: Thread(group=None, target=None, name=None, args=(), kwargs={}) - - This constructor should always be called with keyword arguments. Arguments are: - - *group* should be ``None``; reserved for future extension when a - :class:`ThreadGroup` class is implemented. - - *target* is the callable object to be invoked by the :meth:`run` method. - Defaults to ``None``, meaning nothing is called. - - *name* is the thread name. By default, a unique name is constructed of the form - "Thread-*N*" where *N* is a small decimal number. - - *args* is the argument tuple for the target invocation. Defaults to ``()``. - - *kwargs* is a dictionary of keyword arguments for the target invocation. - Defaults to ``{}``. - - If the subclass overrides the constructor, it must make sure to invoke the base - class constructor (``Thread.__init__()``) before doing anything else to the - thread. - - -.. method:: Thread.start() - - Start the thread's activity. - - It must be called at most once per thread object. It arranges for the object's - :meth:`run` method to be invoked in a separate thread of control. - - This method will raise a :exc:`RuntimeException` if called more than once on the - same thread object. - - -.. method:: Thread.run() - - Method representing the thread's activity. - - You may override this method in a subclass. The standard :meth:`run` method - invokes the callable object passed to the object's constructor as the *target* - argument, if any, with sequential and keyword arguments taken from the *args* - and *kwargs* arguments, respectively. - - -.. method:: Thread.join([timeout]) - - Wait until the thread terminates. This blocks the calling thread until the - thread whose :meth:`join` method is called terminates -- either normally or - through an unhandled exception -- or until the optional timeout occurs. - - When the *timeout* argument is present and not ``None``, it should be a floating - point number specifying a timeout for the operation in seconds (or fractions - thereof). As :meth:`join` always returns ``None``, you must call :meth:`is_alive` - after :meth:`join` to decide whether a timeout happened -- if the thread is - still alive, the :meth:`join` call timed out. - - When the *timeout* argument is not present or ``None``, the operation will block - until the thread terminates. - - A thread can be :meth:`join`\ ed many times. - - :meth:`join` raises a :exc:`RuntimeError` if an attempt is made to join - the current thread as that would cause a deadlock. It is also an error to - :meth:`join` a thread before it has been started and attempts to do so - raises the same exception. - - -.. method:: Thread.getName() - Thread.setName() - - Old API for :attr:`~Thread.name`. - - -.. attribute:: Thread.name - - A string used for identification purposes only. It has no semantics. - Multiple threads may be given the same name. The initial name is set by the - constructor. - - -.. attribute:: Thread.ident - - The 'thread identifier' of this thread or ``None`` if the thread has not been - started. This is a nonzero integer. See the :func:`thread.get_ident()` - function. Thread identifiers may be recycled when a thread exits and another - thread is created. The identifier is available even after the thread has - exited. - - -.. method:: Thread.is_alive() - - Return whether the thread is alive. - - Roughly, a thread is alive from the moment the :meth:`start` method returns - until its :meth:`run` method terminates. The module function :func:`enumerate` - returns a list of all alive threads. - - -.. method:: Thread.isDaemon() - Thread.setDaemon() - - Old API for :attr:`~Thread.daemon`. - - -.. attribute:: Thread.daemon - - The thread's daemon flag. This must be set before :meth:`start` is called, - otherwise :exc:`RuntimeError` is raised. - - The initial value is inherited from the creating thread. - - The entire Python program exits when no alive non-daemon threads are left. - - .. _timer-objects: Timer Objects Modified: python/branches/py3k/Doc/tutorial/controlflow.rst ============================================================================== --- python/branches/py3k/Doc/tutorial/controlflow.rst (original) +++ python/branches/py3k/Doc/tutorial/controlflow.rst Fri Nov 7 10:39:56 2008 @@ -196,6 +196,41 @@ ... pass # Busy-wait for keyboard interrupt (Ctrl+C) ... +This is commonly used for creating minimal classes such as exceptions, or +for ignoring unwanted exceptions:: + + >>> class ParserError(Exception): + ... pass + ... + >>> try: + ... import audioop + ... except ImportError: + ... pass + ... + +Another place :keyword:`pass` can be used is as a place-holder for a function or +conditional body when you are working on new code, allowing you to keep +thinking at a more abstract level. However, as :keyword:`pass` is silently +ignored, a better choice may be to raise a :exc:`NotImplementedError` +exception:: + + >>> def initlog(*args): + ... raise NotImplementedError # Open logfile if not already open + ... if not logfp: + ... raise NotImplementedError # Set up dummy log back-end + ... raise NotImplementedError('Call log initialization handler') + ... + +If :keyword:`pass` were used here and you later ran tests, they may fail +without indicating why. Using :exc:`NotImplementedError` causes this code +to raise an exception, telling you exactly where the incomplete code +is. Note the two calling styles of the exceptions above. +The first style, with no message but with an accompanying comment, +lets you easily leave the comment when you remove the exception, +which ideally would be a good description for +the block of code the exception is a placeholder for. However, the +third example, providing a message for the exception, will produce +a more useful traceback. .. _tut-functions: Modified: python/branches/py3k/Doc/using/cmdline.rst ============================================================================== --- python/branches/py3k/Doc/using/cmdline.rst (original) +++ python/branches/py3k/Doc/using/cmdline.rst Fri Nov 7 10:39:56 2008 @@ -135,6 +135,8 @@ an empty string (``""``) and the current directory will be added to the start of :data:`sys.path`. +.. seealso:: :ref:`tut-invoking` + Generic options ~~~~~~~~~~~~~~~ From python-3000-checkins at python.org Fri Nov 7 19:54:51 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Fri, 7 Nov 2008 19:54:51 +0100 (CET) Subject: [Python-3000-checkins] r67151 - in python/branches/py3k: Misc/NEWS Tools/msi/msi.py Message-ID: <20081107185451.7A7271E401E@bag.python.org> Author: martin.v.loewis Date: Fri Nov 7 19:54:51 2008 New Revision: 67151 Log: Merged revisions 67149 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67149 | martin.v.loewis | 2008-11-07 19:51:50 +0100 (Fr, 07 Nov 2008) | 1 line Issue #1656675: Register a drop handler for .py* files on Windows. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/Tools/msi/msi.py Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 7 19:54:51 2008 @@ -16,6 +16,11 @@ Library ------- +Build +----- + +- Issue #1656675: Register a drop handler for .py* files on Windows. + What's New in Python 3.0 release candidate 2 ============================================ Modified: python/branches/py3k/Tools/msi/msi.py ============================================================================== --- python/branches/py3k/Tools/msi/msi.py (original) +++ python/branches/py3k/Tools/msi/msi.py Fri Nov 7 19:54:51 2008 @@ -1183,6 +1183,7 @@ ewi = "Edit with IDLE" pat2 = r"Software\Classes\%sPython.%sFile\DefaultIcon" pat3 = r"Software\Classes\%sPython.%sFile" + pat4 = r"Software\Classes\%sPython.%sFile\shellex\DropHandler" tcl_verbs = [] if have_tcl: tcl_verbs=[ @@ -1230,6 +1231,13 @@ "Python File (no console)", "REGISTRY.def"), ("pyc.txt", -1, pat3 % (testprefix, "Compiled"), "", "Compiled Python File", "REGISTRY.def"), + # Drop Handler + ("py.drop", -1, pat4 % (testprefix, ""), "", + "{60254CA5-953B-11CF-8C96-00AA00B8708C}", "REGISTRY.def"), + ("pyw.drop", -1, pat4 % (testprefix, "NoCon"), "", + "{60254CA5-953B-11CF-8C96-00AA00B8708C}", "REGISTRY.def"), + ("pyc.drop", -1, pat4 % (testprefix, "Compiled"), "", + "{60254CA5-953B-11CF-8C96-00AA00B8708C}", "REGISTRY.def"), ]) # Registry keys From python-3000-checkins at python.org Sat Nov 8 16:15:58 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 8 Nov 2008 16:15:58 +0100 (CET) Subject: [Python-3000-checkins] r67160 - in python/branches/py3k: Lib/distutils/command/install.py Misc/NEWS Message-ID: <20081108151558.4626A1E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 8 16:15:57 2008 New Revision: 67160 Log: #4283: fix left-over iteritems() in distutils. Modified: python/branches/py3k/Lib/distutils/command/install.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/distutils/command/install.py ============================================================================== --- python/branches/py3k/Lib/distutils/command/install.py (original) +++ python/branches/py3k/Lib/distutils/command/install.py Sat Nov 8 16:15:57 2008 @@ -546,7 +546,7 @@ if not self.user: return home = convert_path(os.path.expanduser("~")) - for name, path in self.config_vars.iteritems(): + for name, path in self.config_vars.items(): if path.startswith(home) and not os.path.isdir(path): self.debug_print("os.makedirs('%s', 0o700)" % path) os.makedirs(path, 0o700) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Nov 8 16:15:57 2008 @@ -16,6 +16,8 @@ Library ------- +- Issue #4283: fix a left-over "iteritems" call in distutils. + Build ----- From python-3000-checkins at python.org Sat Nov 8 17:54:05 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 8 Nov 2008 17:54:05 +0100 (CET) Subject: [Python-3000-checkins] r67161 - python/branches/py3k/Doc/library/functions.rst Message-ID: <20081108165405.A9F5A1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 8 17:54:05 2008 New Revision: 67161 Log: compile can also produce AST Modified: python/branches/py3k/Doc/library/functions.rst Modified: python/branches/py3k/Doc/library/functions.rst ============================================================================== --- python/branches/py3k/Doc/library/functions.rst (original) +++ python/branches/py3k/Doc/library/functions.rst Sat Nov 8 17:54:05 2008 @@ -199,11 +199,11 @@ .. function:: compile(source, filename, mode[, flags[, dont_inherit]]) - Compile the *source* into a code object. Code objects can be + Compile the *source* into a code object or AST object. Code objects can be executed by a call to :func:`exec` or evaluated by a call to - :func:`eval`. *source* can either be a string or an AST object. - Refer to the :mod:`_ast` module documentation for information on - how to compile into and from AST objects. + :func:`eval`. *source* can either be a string or an AST object. Refer to the + :mod:`_ast` module documentation for information on how to compile into and + from AST objects. The *filename* argument should give the file from which the code was read; pass some recognizable value if it wasn't From python-3000-checkins at python.org Sat Nov 8 18:05:00 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 8 Nov 2008 18:05:00 +0100 (CET) Subject: [Python-3000-checkins] r67164 - in python/branches/py3k: Doc/library/ast.rst Doc/library/functions.rst Message-ID: <20081108170500.A112F1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 8 18:05:00 2008 New Revision: 67164 Log: Merged revisions 67162 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67162 | benjamin.peterson | 2008-11-08 10:55:33 -0600 (Sat, 08 Nov 2008) | 1 line a few compile() and ast doc improvements ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/ast.rst python/branches/py3k/Doc/library/functions.rst Modified: python/branches/py3k/Doc/library/ast.rst ============================================================================== --- python/branches/py3k/Doc/library/ast.rst (original) +++ python/branches/py3k/Doc/library/ast.rst Sat Nov 8 18:05:00 2008 @@ -15,13 +15,12 @@ Python release; this module helps to find out programmatically what the current grammar looks like. -An abstract syntax tree can be generated by passing :data:`_ast.PyCF_ONLY_AST` -as a flag to the :func:`compile` builtin function, or using the :func:`parse` +An abstract syntax tree can be generated by passing :data:`ast.PyCF_ONLY_AST` as +a flag to the :func:`compile` builtin function, or using the :func:`parse` helper provided in this module. The result will be a tree of objects whose -classes all inherit from :class:`ast.AST`. +classes all inherit from :class:`ast.AST`. An abstract syntax tree can be +compiled into a Python code object using the built-in :func:`compile` function. -A modified abstract syntax tree can be compiled into a Python code object using -the built-in :func:`compile` function. Node classes ------------ @@ -113,7 +112,7 @@ .. function:: parse(expr, filename='', mode='exec') Parse an expression into an AST node. Equivalent to ``compile(expr, - filename, mode, PyCF_ONLY_AST)``. + filename, mode, ast.PyCF_ONLY_AST)``. .. function:: literal_eval(node_or_string) Modified: python/branches/py3k/Doc/library/functions.rst ============================================================================== --- python/branches/py3k/Doc/library/functions.rst (original) +++ python/branches/py3k/Doc/library/functions.rst Sat Nov 8 18:05:00 2008 @@ -199,21 +199,20 @@ .. function:: compile(source, filename, mode[, flags[, dont_inherit]]) - Compile the *source* into a code object or AST object. Code objects can be - executed by a call to :func:`exec` or evaluated by a call to - :func:`eval`. *source* can either be a string or an AST object. Refer to the - :mod:`_ast` module documentation for information on how to compile into and - from AST objects. - - The *filename* argument should give the file from - which the code was read; pass some recognizable value if it wasn't - read from a file (``''`` is commonly used). The *mode* - argument specifies what kind of code must be compiled; it can be - ``'exec'`` if *source* consists of a sequence of statements, - ``'eval'`` if it consists of a single expression, or ``'single'`` - if it consists of a single interactive statement (in the latter - case, expression statements that evaluate to something else than - ``None`` will be printed). + Compile the *source* into a code or AST object. Code objects can be executed + by an :keyword:`exec` statement or evaluated by a call to :func:`eval`. + *source* can either be a string or an AST object. Refer to the :mod:`ast` + module documentation for information on how to work with AST objects. + + The *filename* argument should give the file from which the code was read; + pass some recognizable value if it wasn't read from a file (``''`` is + commonly used). + + The *mode* argument specifies what kind of code must be compiled; it can be + ``'exec'`` if *source* consists of a sequence of statements, ``'eval'`` if it + consists of a single expression, or ``'single'`` if it consists of a single + interactive statement (in the latter case, expression statements that + evaluate to something else than ``None`` will be printed). The optional arguments *flags* and *dont_inherit* control which future statements (see :pep:`236`) affect the compilation of *source*. If neither @@ -233,6 +232,14 @@ This function raises :exc:`SyntaxError` if the compiled source is invalid, and :exc:`TypeError` if the source contains null bytes. + .. note:: + + When compiling a string with multi-line statements, line endings must be + represented by a single newline character (``'\n'``), and the input must + be terminated by at least one newline character. If line endings are + represented by ``'\r\n'``, use :meth:`str.replace` to change them into + ``'\n'``. + .. function:: complex([real[, imag]]) From python-3000-checkins at python.org Sat Nov 8 18:06:19 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 8 Nov 2008 18:06:19 +0100 (CET) Subject: [Python-3000-checkins] r67165 - python/branches/py3k Message-ID: <20081108170619.080CF1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 8 18:06:18 2008 New Revision: 67165 Log: Blocked revisions 67163 via svnmerge ........ r67163 | benjamin.peterson | 2008-11-08 11:04:18 -0600 (Sat, 08 Nov 2008) | 1 line move context clue to versionchanged tag ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Nov 8 18:08:32 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 8 Nov 2008 18:08:32 +0100 (CET) Subject: [Python-3000-checkins] r67167 - python/branches/py3k Message-ID: <20081108170832.99F7A1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 8 18:08:32 2008 New Revision: 67167 Log: Blocked revisions 67166 via svnmerge ........ r67166 | benjamin.peterson | 2008-11-08 11:07:06 -0600 (Sat, 08 Nov 2008) | 1 line clarify what was added ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Nov 8 18:24:34 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 8 Nov 2008 18:24:34 +0100 (CET) Subject: [Python-3000-checkins] r67168 - in python/branches/py3k: Demo/sockets/udpecho.py Demo/sockets/unixclient.py Doc/library/socketserver.rst Misc/ACKS Misc/NEWS Message-ID: <20081108172434.80F2F1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 8 18:24:34 2008 New Revision: 67168 Log: fix the socketserver demo code for py3k #4275 Thanks to Don MacMillen Modified: python/branches/py3k/Demo/sockets/udpecho.py python/branches/py3k/Demo/sockets/unixclient.py python/branches/py3k/Doc/library/socketserver.rst python/branches/py3k/Misc/ACKS python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Demo/sockets/udpecho.py ============================================================================== --- python/branches/py3k/Demo/sockets/udpecho.py (original) +++ python/branches/py3k/Demo/sockets/udpecho.py Sat Nov 8 18:24:34 2008 @@ -56,7 +56,8 @@ line = sys.stdin.readline() if not line: break - s.sendto(line, addr) + print('addr = ', addr) + s.sendto(bytes(line, 'ascii'), addr) data, fromaddr = s.recvfrom(BUFSIZE) print('client received %r from %r' % (data, fromaddr)) Modified: python/branches/py3k/Demo/sockets/unixclient.py ============================================================================== --- python/branches/py3k/Demo/sockets/unixclient.py (original) +++ python/branches/py3k/Demo/sockets/unixclient.py Sat Nov 8 18:24:34 2008 @@ -6,7 +6,7 @@ FILE = 'unix-socket' s = socket(AF_UNIX, SOCK_STREAM) s.connect(FILE) -s.send('Hello, world') +s.send(b'Hello, world') data = s.recv(1024) s.close() print('Received', repr(data)) Modified: python/branches/py3k/Doc/library/socketserver.rst ============================================================================== --- python/branches/py3k/Doc/library/socketserver.rst (original) +++ python/branches/py3k/Doc/library/socketserver.rst Sat Nov 8 18:24:34 2008 @@ -336,8 +336,8 @@ def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() - print "%s wrote:" % self.client_address[0] - print self.data + print("%s wrote:" % self.client_address[0]) + print(self.data) # just send back the same data, but upper-cased self.request.send(self.data.upper()) @@ -360,8 +360,8 @@ # self.rfile is a file-like object created by the handler; # we can now use e.g. readline() instead of raw recv() calls self.data = self.rfile.readline().strip() - print "%s wrote:" % self.client_address[0] - print self.data + print("%s wrote:" % self.client_address[0]) + print(self.data) # Likewise, self.wfile is a file-like object used to write back # to the client self.wfile.write(self.data.upper()) @@ -385,14 +385,14 @@ # Connect to server and send data sock.connect((HOST, PORT)) - sock.send(data + "\n") + sock.send(bytes(data + "\n","utf8")) # Receive data from the server and shut down received = sock.recv(1024) sock.close() - print "Sent: %s" % data - print "Received: %s" % received + print("Sent: %s" % data) + print("Received: %s" % received) The output of the example should look something like this: @@ -401,18 +401,18 @@ $ python TCPServer.py 127.0.0.1 wrote: - hello world with TCP + b'hello world with TCP' 127.0.0.1 wrote: - python is nice + b'python is nice' Client:: $ python TCPClient.py hello world with TCP Sent: hello world with TCP - Received: HELLO WORLD WITH TCP + Received: b'HELLO WORLD WITH TCP' $ python TCPClient.py python is nice Sent: python is nice - Received: PYTHON IS NICE + Received: b'PYTHON IS NICE' :class:`socketserver.UDPServer` Example @@ -433,13 +433,13 @@ def handle(self): data = self.request[0].strip() socket = self.request[1] - print "%s wrote:" % self.client_address[0] - print data + print("%s wrote:" % self.client_address[0]) + print(data) socket.sendto(data.upper(), self.client_address) if __name__ == "__main__": HOST, PORT = "localhost", 9999 - server = socketserver.UDPServer((HOST, PORT), BaseUDPRequestHandler) + server = socketserver.UDPServer((HOST, PORT), MyUDPHandler) server.serve_forever() This is the client side:: @@ -447,7 +447,7 @@ import socket import sys - HOST, PORT = "localhost" + HOST, PORT = "localhost", 9999 data = " ".join(sys.argv[1:]) # SOCK_DGRAM is the socket type to use for UDP sockets @@ -455,11 +455,11 @@ # As you can see, there is no connect() call; UDP has no connections. # Instead, data is directly sent to the recipient via sendto(). - sock.sendto(data + "\n", (HOST, PORT)) + sock.sendto(bytes(data + "\n","utf8"), (HOST, PORT)) received = sock.recv(1024) - print "Sent: %s" % data - print "Received: %s" % received + print("Sent: %s" % data) + print("Received: %s" % received) The output of the example should look exactly like for the TCP server example. @@ -481,7 +481,7 @@ def handle(self): data = self.request.recv(1024) cur_thread = threading.current_thread() - response = "%s: %s" % (cur_thread.get_name(), data) + response = bytes("%s: %s" % (cur_thread.getName(), data),'ascii') self.request.send(response) class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): @@ -492,7 +492,7 @@ sock.connect((ip, port)) sock.send(message) response = sock.recv(1024) - print "Received: %s" % response + print("Received: %s" % response) sock.close() if __name__ == "__main__": @@ -506,23 +506,24 @@ # more thread for each request server_thread = threading.Thread(target=server.serve_forever) # Exit the server thread when the main thread terminates - server_thread.set_daemon(True) + server_thread.setDaemon(True) server_thread.start() - print "Server loop running in thread:", t.get_name() + print("Server loop running in thread:", server_thread.getName()) - client(ip, port, "Hello World 1") - client(ip, port, "Hello World 2") - client(ip, port, "Hello World 3") + client(ip, port, b"Hello World 1") + client(ip, port, b"Hello World 2") + client(ip, port, b"Hello World 3") server.shutdown() + The output of the example should look something like this:: $ python ThreadedTCPServer.py Server loop running in thread: Thread-1 - Received: Thread-2: Hello World 1 - Received: Thread-3: Hello World 2 - Received: Thread-4: Hello World 3 + Received: b"Thread-2: b'Hello World 1'" + Received: b"Thread-3: b'Hello World 2'" + Received: b"Thread-4: b'Hello World 3'" The :class:`ForkingMixIn` class is used in the same way, except that the server Modified: python/branches/py3k/Misc/ACKS ============================================================================== --- python/branches/py3k/Misc/ACKS (original) +++ python/branches/py3k/Misc/ACKS Sat Nov 8 18:24:34 2008 @@ -435,6 +435,7 @@ Andrew I MacIntyre Tim MacKenzie Nick Maclaren +Don MacMillen Steve Majewski Grzegorz Makarewicz Ken Manheimer Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Nov 8 18:24:34 2008 @@ -23,6 +23,11 @@ - Issue #1656675: Register a drop handler for .py* files on Windows. +Tools/Demos +----------- + +- Demos of the socketserver module now work with Python 3. + What's New in Python 3.0 release candidate 2 ============================================ From python-3000-checkins at python.org Sat Nov 8 20:56:21 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 8 Nov 2008 20:56:21 +0100 (CET) Subject: [Python-3000-checkins] r67172 - in python/branches/py3k: Python/ast.c Python/compile.c Message-ID: <20081108195621.E08EC1E400C@bag.python.org> Author: benjamin.peterson Date: Sat Nov 8 20:56:21 2008 New Revision: 67172 Log: Merged revisions 67171 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67171 | benjamin.peterson | 2008-11-08 12:38:54 -0600 (Sat, 08 Nov 2008) | 4 lines check for assignment to __debug__ during AST generation Also, give assignment to None a better error message ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Python/ast.c python/branches/py3k/Python/compile.c Modified: python/branches/py3k/Python/ast.c ============================================================================== --- python/branches/py3k/Python/ast.c (original) +++ python/branches/py3k/Python/ast.c Sat Nov 8 20:56:21 2008 @@ -354,6 +354,7 @@ "None", "True", "False", + "__debug__", NULL, }; Modified: python/branches/py3k/Python/compile.c ============================================================================== --- python/branches/py3k/Python/compile.c (original) +++ python/branches/py3k/Python/compile.c Sat Nov 8 20:56:21 2008 @@ -2498,12 +2498,6 @@ PyObject *mangled; /* XXX AugStore isn't used anywhere! */ - /* First check for assignment to __debug__. Param? */ - if ((ctx == Store || ctx == AugStore || ctx == Del) - && !PyUnicode_CompareWithASCIIString(name, "__debug__")) { - return compiler_error(c, "can not assign to __debug__"); - } - mangled = _Py_Mangle(c->u->u_private, name); if (!mangled) return 0; From python-3000-checkins at python.org Sun Nov 9 02:43:03 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 9 Nov 2008 02:43:03 +0100 (CET) Subject: [Python-3000-checkins] r67174 - python/branches/py3k/Doc/library/string.rst Message-ID: <20081109014303.4A5071E4002@bag.python.org> Author: benjamin.peterson Date: Sun Nov 9 02:43:02 2008 New Revision: 67174 Log: update string formatting grammar Modified: python/branches/py3k/Doc/library/string.rst Modified: python/branches/py3k/Doc/library/string.rst ============================================================================== --- python/branches/py3k/Doc/library/string.rst (original) +++ python/branches/py3k/Doc/library/string.rst Sun Nov 9 02:43:02 2008 @@ -199,7 +199,7 @@ field_name: (`identifier` | `integer`) ("." `attribute_name` | "[" element_index "]")* attribute_name: `identifier` element_index: `integer` - conversion: "r" | "s" + conversion: "r" | "s" | "a" format_spec: In less formal terms, the replacement field starts with a *field_name*, which From python-3000-checkins at python.org Mon Nov 10 23:21:33 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Mon, 10 Nov 2008 23:21:33 +0100 (CET) Subject: [Python-3000-checkins] r67182 - in python/branches/py3k: Lib/lib2to3 Lib/lib2to3/fixes/fix_import.py Lib/lib2to3/fixes/fix_imports.py Lib/lib2to3/fixes/fix_metaclass.py Lib/lib2to3/refactor.py Lib/lib2to3/tests/test_fixers.py Message-ID: <20081110222133.D54711E4002@bag.python.org> Author: benjamin.peterson Date: Mon Nov 10 23:21:33 2008 New Revision: 67182 Log: Merged revisions 67180 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r67180 | benjamin.peterson | 2008-11-10 16:11:12 -0600 (Mon, 10 Nov 2008) | 29 lines Merged revisions 66985,67170,67173,67177-67179 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r66985 | benjamin.peterson | 2008-10-20 16:43:46 -0500 (Mon, 20 Oct 2008) | 1 line no need to use nested try, except, finally ........ r67170 | benjamin.peterson | 2008-11-08 12:28:31 -0600 (Sat, 08 Nov 2008) | 1 line fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b)) ........ r67173 | benjamin.peterson | 2008-11-08 17:42:08 -0600 (Sat, 08 Nov 2008) | 1 line consolidate test ........ r67177 | benjamin.peterson | 2008-11-09 21:52:52 -0600 (Sun, 09 Nov 2008) | 1 line let the metclass fixer handle complex assignments in the class body gracefully ........ r67178 | benjamin.peterson | 2008-11-10 15:26:43 -0600 (Mon, 10 Nov 2008) | 1 line the metaclass fixers shouldn't die when bases are not a simple name ........ r67179 | benjamin.peterson | 2008-11-10 15:29:58 -0600 (Mon, 10 Nov 2008) | 1 line allow the fix_import pattern to catch from imports with parenthesis ........ ................ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/lib2to3/ (props changed) python/branches/py3k/Lib/lib2to3/fixes/fix_import.py python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py python/branches/py3k/Lib/lib2to3/refactor.py python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_import.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_import.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_import.py Mon Nov 10 23:21:33 2008 @@ -18,7 +18,7 @@ class FixImport(fixer_base.BaseFix): PATTERN = """ - import_from< type='from' imp=any 'import' any > + import_from< type='from' imp=any 'import' ['('] any [')'] > | import_name< type='import' imp=any > """ Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py Mon Nov 10 23:21:33 2008 @@ -66,9 +66,9 @@ yield """import_name< 'import' ((%s) | dotted_as_names< any* (%s) any* >) > """ % (mod_list, mod_list) - yield """import_from< 'from' (%s) 'import' + yield """import_from< 'from' (%s) 'import' ['('] ( any | import_as_name< any 'as' any > | - import_as_names< any* >) > + import_as_names< any* >) [')'] > """ % mod_name_list yield """import_name< 'import' dotted_as_name< (%s) 'as' any > > Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py Mon Nov 10 23:21:33 2008 @@ -35,8 +35,9 @@ elif node.type == syms.simple_stmt and node.children: expr_node = node.children[0] if expr_node.type == syms.expr_stmt and expr_node.children: - leaf_node = expr_node.children[0] - if leaf_node.value == '__metaclass__': + left_side = expr_node.children[0] + if isinstance(left_side, Leaf) and \ + left_side.value == '__metaclass__': return True return False @@ -165,12 +166,10 @@ if node.children[3].type == syms.arglist: arglist = node.children[3] # Node(classdef, ['class', 'name', '(', 'Parent', ')', ':', suite]) - elif isinstance(node.children[3], Leaf): + else: parent = node.children[3].clone() arglist = Node(syms.arglist, [parent]) node.set_child(3, arglist) - else: - raise ValueError("Unexpected class inheritance arglist") elif len(node.children) == 6: # Node(classdef, ['class', 'name', '(', ')', ':', suite]) # 0 1 2 3 4 5 Modified: python/branches/py3k/Lib/lib2to3/refactor.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/refactor.py (original) +++ python/branches/py3k/Lib/lib2to3/refactor.py Mon Nov 10 23:21:33 2008 @@ -363,10 +363,9 @@ self.log_error("Can't create %s: %s", filename, err) return try: - try: - f.write(new_text) - except os.error as err: - self.log_error("Can't write %s: %s", filename, err) + f.write(new_text) + except os.error as err: + self.log_error("Can't write %s: %s", filename, err) finally: f.close() self.log_debug("Wrote changes to %s", filename) Modified: python/branches/py3k/Lib/lib2to3/tests/test_fixers.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/test_fixers.py (original) +++ python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Mon Nov 10 23:21:33 2008 @@ -1450,6 +1450,10 @@ a = "from %s import foo, bar" % new self.check(b, a) + b = "from %s import (yes, no)" % old + a = "from %s import (yes, no)" % new + self.check(b, a) + def test_import_module_as(self): for old, new in self.modules.items(): b = "import %s as foo_bar" % old @@ -3345,6 +3349,10 @@ a = "from .foo import bar" self.check_both(b, a) + b = "from foo import (bar, baz)" + a = "from .foo import (bar, baz)" + self.check_both(b, a) + def test_dotted_from(self): b = "from green.eggs import ham" a = "from .green.eggs import ham" @@ -3624,6 +3632,12 @@ """ self.unchanged(s) + s = """ + class X: + a[23] = 74 + """ + self.unchanged(s) + def test_comments(self): b = """ class X: @@ -3732,6 +3746,26 @@ a = """class m(a, arg=23, metaclass=Meta): pass""" self.check(b, a) + b = """ + class X(expression(2 + 4)): + __metaclass__ = Meta + """ + a = """ + class X(expression(2 + 4), metaclass=Meta): + pass + """ + self.check(b, a) + + b = """ + class X(expression(2 + 4), x**4): + __metaclass__ = Meta + """ + a = """ + class X(expression(2 + 4), x**4, metaclass=Meta): + pass + """ + self.check(b, a) + class Test_getcwdu(FixerTestCase): From python-3000-checkins at python.org Tue Nov 11 13:53:39 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Tue, 11 Nov 2008 13:53:39 +0100 (CET) Subject: [Python-3000-checkins] r67185 - python/branches/py3k/Modules/_testcapimodule.c Message-ID: <20081111125339.924081E4002@bag.python.org> Author: christian.heimes Date: Tue Nov 11 13:53:39 2008 New Revision: 67185 Log: Fixed a compiler warning Modified: python/branches/py3k/Modules/_testcapimodule.c Modified: python/branches/py3k/Modules/_testcapimodule.c ============================================================================== --- python/branches/py3k/Modules/_testcapimodule.c (original) +++ python/branches/py3k/Modules/_testcapimodule.c Tue Nov 11 13:53:39 2008 @@ -517,10 +517,12 @@ PyObject *tuple, *obj; Py_UNICODE *value; Py_ssize_t len; + int x; /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */ /* Just use the macro and check that it compiles */ - int x = Py_UNICODE_ISSPACE(25); + x = Py_UNICODE_ISSPACE(25); + x = x; tuple = PyTuple_New(1); if (tuple == NULL) From python-3000-checkins at python.org Tue Nov 11 21:05:07 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Tue, 11 Nov 2008 21:05:07 +0100 (CET) Subject: [Python-3000-checkins] r67187 - in python/branches/py3k: Lib/test/pickletester.py Misc/NEWS Modules/_pickle.c Message-ID: <20081111200507.694561E4036@bag.python.org> Author: amaury.forgeotdarc Date: Tue Nov 11 21:05:06 2008 New Revision: 67187 Log: #4298: pickle.load() can segfault on invalid or truncated input. Patch and test by Hirokazu Yamamoto. Modified: python/branches/py3k/Lib/test/pickletester.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_pickle.c Modified: python/branches/py3k/Lib/test/pickletester.py ============================================================================== --- python/branches/py3k/Lib/test/pickletester.py (original) +++ python/branches/py3k/Lib/test/pickletester.py Tue Nov 11 21:05:06 2008 @@ -1032,6 +1032,11 @@ self.assertRaises(pickle.PicklingError, BadPickler().dump, 0) self.assertRaises(pickle.UnpicklingError, BadUnpickler().load) + def test_bad_input(self): + # Test issue4298 + s = bytes([0x58, 0, 0, 0, 0x54]) + self.assertRaises(EOFError, pickle.loads, s) + class AbstractPersistentPicklerTests(unittest.TestCase): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Tue Nov 11 21:05:06 2008 @@ -16,7 +16,9 @@ Library ------- -- Issue #4283: fix a left-over "iteritems" call in distutils. +- Issue #4298: Fix a segfault when pickle.loads is passed a ill-formed input. + +- Issue #4283: Fix a left-over "iteritems" call in distutils. Build ----- Modified: python/branches/py3k/Modules/_pickle.c ============================================================================== --- python/branches/py3k/Modules/_pickle.c (original) +++ python/branches/py3k/Modules/_pickle.c Tue Nov 11 21:05:06 2008 @@ -489,6 +489,11 @@ return -1; } + if (PyBytes_GET_SIZE(data) != n) { + PyErr_SetNone(PyExc_EOFError); + return -1; + } + Py_XDECREF(self->last_string); self->last_string = data; From python-3000-checkins at python.org Tue Nov 11 22:43:43 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 11 Nov 2008 22:43:43 +0100 (CET) Subject: [Python-3000-checkins] r67188 - python/branches/py3k/Doc/library/functions.rst Message-ID: <20081111214343.2E73D1E4002@bag.python.org> Author: benjamin.peterson Date: Tue Nov 11 22:43:42 2008 New Revision: 67188 Log: exec won't take file objects anymore Modified: python/branches/py3k/Doc/library/functions.rst Modified: python/branches/py3k/Doc/library/functions.rst ============================================================================== --- python/branches/py3k/Doc/library/functions.rst (original) +++ python/branches/py3k/Doc/library/functions.rst Tue Nov 11 22:43:42 2008 @@ -391,16 +391,15 @@ .. function:: exec(object[, globals[, locals]]) - This function supports dynamic execution of Python code. *object* must be either - a string, an open file object, or a code object. If it is a string, the string - is parsed as a suite of Python statements which is then executed (unless a - syntax error occurs). If it is an open file, the file is parsed until EOF and - executed. If it is a code object, it is simply executed. In all cases, the + This function supports dynamic execution of Python code. *object* must be + either a string or a code object. If it is a string, the string is parsed as + a suite of Python statements which is then executed (unless a syntax error + occurs). If it is a code object, it is simply executed. In all cases, the code that's executed is expected to be valid as file input (see the section - "File input" in the Reference Manual). Be aware that the :keyword:`return` and - :keyword:`yield` statements may not be used outside of function definitions even - within the context of code passed to the :func:`exec` function. The return value - is ``None``. + "File input" in the Reference Manual). Be aware that the :keyword:`return` + and :keyword:`yield` statements may not be used outside of function + definitions even within the context of code passed to the :func:`exec` + function. The return value is ``None``. In all cases, if the optional parts are omitted, the code is executed in the current scope. If only *globals* is provided, it must be a dictionary, which From python-3000-checkins at python.org Wed Nov 12 00:05:00 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Wed, 12 Nov 2008 00:05:00 +0100 (CET) Subject: [Python-3000-checkins] r67190 - in python/branches/py3k: Lib/test/test_cmd_line.py Misc/NEWS Modules/main.c Python/import.c Message-ID: <20081111230500.026CF1E4002@bag.python.org> Author: amaury.forgeotdarc Date: Wed Nov 12 00:04:59 2008 New Revision: 67190 Log: #3705: Command-line arguments were not correctly decoded when the terminal does not use UTF8. Now the code propagates the unicode string as far as possible, and avoids the conversion to char* which implicitely uses utf-8. Reviewed by Benjamin. Modified: python/branches/py3k/Lib/test/test_cmd_line.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/main.c python/branches/py3k/Python/import.c Modified: python/branches/py3k/Lib/test/test_cmd_line.py ============================================================================== --- python/branches/py3k/Lib/test/test_cmd_line.py (original) +++ python/branches/py3k/Lib/test/test_cmd_line.py Wed Nov 12 00:04:59 2008 @@ -135,6 +135,12 @@ self.exit_code('-c', 'pass'), 0) + # Test handling of non-ascii data + command = "assert(ord('\xe9') == 0xe9)" + self.assertEqual( + self.exit_code('-c', command), + 0) + def test_main(): test.support.run_unittest(CmdLineTest) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 12 00:04:59 2008 @@ -13,6 +13,9 @@ Core and Builtins ----------------- +- Issue #3705: Command-line arguments were not correctly decoded when the + terminal does not use UTF8. + Library ------- Modified: python/branches/py3k/Modules/main.c ============================================================================== --- python/branches/py3k/Modules/main.c (original) +++ python/branches/py3k/Modules/main.c Wed Nov 12 00:04:59 2008 @@ -287,7 +287,7 @@ { int c; int sts; - char *command = NULL; + wchar_t *command = NULL; wchar_t *filename = NULL; wchar_t *module = NULL; FILE *fp = stdin; @@ -299,7 +299,6 @@ int version = 0; int saw_unbuffered_flag = 0; PyCompilerFlags cf; - char *oldloc; cf.cf_flags = 0; @@ -310,30 +309,19 @@ while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { if (c == 'c') { - size_t r1, r2; - oldloc = setlocale(LC_ALL, NULL); - setlocale(LC_ALL, ""); - r1 = wcslen(_PyOS_optarg); - r2 = wcstombs(NULL, _PyOS_optarg, r1); - if (r2 == (size_t) -1) - Py_FatalError( - "cannot convert character encoding of -c argument"); - if (r2 > r1) - r1 = r2; - r1 += 2; + size_t len; /* -c is the last option; following arguments that look like options are left for the command to interpret. */ - command = (char *)malloc(r1); + + len = wcslen(_PyOS_optarg) + 1 + 1; + command = (wchar_t *)malloc(sizeof(wchar_t) * len); if (command == NULL) Py_FatalError( "not enough memory to copy -c argument"); - r2 = wcstombs(command, _PyOS_optarg, r1); - if (r2 > r1-1) - Py_FatalError( - "not enough memory to copy -c argument"); - strcat(command, "\n"); - setlocale(LC_ALL, oldloc); + wcscpy(command, _PyOS_optarg); + command[len - 2] = '\n'; + command[len - 1] = 0; break; } @@ -543,8 +531,18 @@ } if (command) { - sts = PyRun_SimpleStringFlags(command, &cf) != 0; + PyObject *commandObj = PyUnicode_FromWideChar( + command, wcslen(command)); free(command); + if (commandObj != NULL) { + sts = PyRun_SimpleStringFlags( + _PyUnicode_AsString(commandObj), &cf) != 0; + } + else { + PyErr_Print(); + sts = 1; + } + Py_DECREF(commandObj); } else if (module) { sts = RunModule(module, 1); } Modified: python/branches/py3k/Python/import.c ============================================================================== --- python/branches/py3k/Python/import.c (original) +++ python/branches/py3k/Python/import.c Wed Nov 12 00:04:59 2008 @@ -2793,6 +2793,7 @@ { extern int fclose(FILE *); PyObject *fob, *ret; + PyObject *pathobj; struct filedescr *fdp; char pathname[MAXPATHLEN+1]; FILE *fp = NULL; @@ -2836,9 +2837,9 @@ fob = Py_None; Py_INCREF(fob); } - ret = Py_BuildValue("Os(ssi)", - fob, pathname, fdp->suffix, fdp->mode, fdp->type); - Py_DECREF(fob); + pathobj = PyUnicode_DecodeFSDefault(pathname); + ret = Py_BuildValue("NN(ssi)", + fob, pathobj, fdp->suffix, fdp->mode, fdp->type); PyMem_FREE(found_encoding); return ret; @@ -2849,7 +2850,9 @@ { char *name; PyObject *path = NULL; - if (!PyArg_ParseTuple(args, "s|O:find_module", &name, &path)) + if (!PyArg_ParseTuple(args, "es|O:find_module", + Py_FileSystemDefaultEncoding, &name, + &path)) return NULL; return call_find_module(name, path); } From python-3000-checkins at python.org Wed Nov 12 01:13:46 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Wed, 12 Nov 2008 01:13:46 +0100 (CET) Subject: [Python-3000-checkins] r67192 - python/branches/py3k/Lib/test/test_cmd_line.py Message-ID: <20081112001346.0B07C1E4002@bag.python.org> Author: amaury.forgeotdarc Date: Wed Nov 12 01:13:45 2008 New Revision: 67192 Log: Temporarily print some information in test_cmd_line, to understand why the test fails on some platforms. Modified: python/branches/py3k/Lib/test/test_cmd_line.py Modified: python/branches/py3k/Lib/test/test_cmd_line.py ============================================================================== --- python/branches/py3k/Lib/test/test_cmd_line.py (original) +++ python/branches/py3k/Lib/test/test_cmd_line.py Wed Nov 12 01:13:45 2008 @@ -136,6 +136,8 @@ 0) # Test handling of non-ascii data + if test.support.verbose: + print("FileSystemEncoding:", sys.getfilesystemencoding()) command = "assert(ord('\xe9') == 0xe9)" self.assertEqual( self.exit_code('-c', command), From python-3000-checkins at python.org Wed Nov 12 01:59:11 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Wed, 12 Nov 2008 01:59:11 +0100 (CET) Subject: [Python-3000-checkins] r67193 - python/branches/py3k/Lib/test/test_cmd_line.py Message-ID: <20081112005911.BD1C51E4002@bag.python.org> Author: amaury.forgeotdarc Date: Wed Nov 12 01:59:11 2008 New Revision: 67193 Log: Enable this test only when subprocess supports non-ascii arguments. (it is about parsing the python command line arguments, not about subprocess) Modified: python/branches/py3k/Lib/test/test_cmd_line.py Modified: python/branches/py3k/Lib/test/test_cmd_line.py ============================================================================== --- python/branches/py3k/Lib/test/test_cmd_line.py (original) +++ python/branches/py3k/Lib/test/test_cmd_line.py Wed Nov 12 01:59:11 2008 @@ -136,12 +136,11 @@ 0) # Test handling of non-ascii data - if test.support.verbose: - print("FileSystemEncoding:", sys.getfilesystemencoding()) - command = "assert(ord('\xe9') == 0xe9)" - self.assertEqual( - self.exit_code('-c', command), - 0) + if sys.getfilesystemencoding() != 'ascii': + command = "assert(ord('\xe9') == 0xe9)" + self.assertEqual( + self.exit_code('-c', command), + 0) def test_main(): From python-3000-checkins at python.org Wed Nov 12 02:57:36 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Wed, 12 Nov 2008 02:57:36 +0100 (CET) Subject: [Python-3000-checkins] r67194 - python/branches/py3k/Lib/test/test_zipfile64.py Message-ID: <20081112015736.618B71E4002@bag.python.org> Author: amaury.forgeotdarc Date: Wed Nov 12 02:57:36 2008 New Revision: 67194 Log: #2971: test_zipfile64 fails. This test is always skipped, but it is not a reason not to adapt it to py3k. I had to reduce most of the big figures to actually run the test. Modified: python/branches/py3k/Lib/test/test_zipfile64.py Modified: python/branches/py3k/Lib/test/test_zipfile64.py ============================================================================== --- python/branches/py3k/Lib/test/test_zipfile64.py (original) +++ python/branches/py3k/Lib/test/test_zipfile64.py Wed Nov 12 02:57:36 2008 @@ -35,7 +35,7 @@ def setUp(self): # Create test data. line_gen = ("Test of zipfile line %d." % i for i in range(1000000)) - self.data = '\n'.join(line_gen) + self.data = '\n'.join(line_gen).encode('ascii') # And write it to a file. fp = open(TESTFN, "wb") @@ -100,21 +100,22 @@ # and that the resulting archive can be read properly by ZipFile zipf = zipfile.ZipFile(TESTFN, mode="w") zipf.debug = 100 - numfiles = (1 << 16) * 3/2 - for i in xrange(numfiles): + numfiles = (1 << 16) * 3//2 + for i in range(numfiles): zipf.writestr("foo%08d" % i, "%d" % (i**3 % 57)) self.assertEqual(len(zipf.namelist()), numfiles) zipf.close() zipf2 = zipfile.ZipFile(TESTFN, mode="r") self.assertEqual(len(zipf2.namelist()), numfiles) - for i in xrange(numfiles): - self.assertEqual(zipf2.read("foo%08d" % i), "%d" % (i**3 % 57)) + for i in range(numfiles): + content = zipf2.read("foo%08d" % i).decode('ascii') + self.assertEqual(content, "%d" % (i**3 % 57)) zipf.close() def tearDown(self): - test_support.unlink(TESTFN) - test_support.unlink(TESTFN2) + support.unlink(TESTFN) + support.unlink(TESTFN2) def test_main(): run_unittest(TestsWithSourceFile, OtherTests) From python-3000-checkins at python.org Wed Nov 12 10:04:04 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Wed, 12 Nov 2008 10:04:04 +0100 (CET) Subject: [Python-3000-checkins] r67201 - python/branches/py3k/Modules/_testcapimodule.c Message-ID: <20081112090404.8C42C1E4002@bag.python.org> Author: christian.heimes Date: Wed Nov 12 10:04:04 2008 New Revision: 67201 Log: Style fix, use tab instead of space Modified: python/branches/py3k/Modules/_testcapimodule.c Modified: python/branches/py3k/Modules/_testcapimodule.c ============================================================================== --- python/branches/py3k/Modules/_testcapimodule.c (original) +++ python/branches/py3k/Modules/_testcapimodule.c Wed Nov 12 10:04:04 2008 @@ -521,8 +521,8 @@ /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */ /* Just use the macro and check that it compiles */ - x = Py_UNICODE_ISSPACE(25); - x = x; + x = Py_UNICODE_ISSPACE(25); + x = x; tuple = PyTuple_New(1); if (tuple == NULL) From python-3000-checkins at python.org Wed Nov 12 22:26:46 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 12 Nov 2008 22:26:46 +0100 (CET) Subject: [Python-3000-checkins] r67202 - python/branches/py3k/Doc/library/inspect.rst Message-ID: <20081112212646.DD7F11E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 12 22:26:46 2008 New Revision: 67202 Log: getfullargspec() has other virtues, too Modified: python/branches/py3k/Doc/library/inspect.rst Modified: python/branches/py3k/Doc/library/inspect.rst ============================================================================== --- python/branches/py3k/Doc/library/inspect.rst (original) +++ python/branches/py3k/Doc/library/inspect.rst Wed Nov 12 22:26:46 2008 @@ -394,7 +394,7 @@ .. deprecated:: 3.0 Use :func:`getfullargspec` instead, which provides information about - keyword-only arguments. + keyword-only arguments and annotations. .. function:: getfullargspec(func) From python-3000-checkins at python.org Wed Nov 12 22:39:02 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 12 Nov 2008 22:39:02 +0100 (CET) Subject: [Python-3000-checkins] r67203 - in python/branches/py3k: Lib/inspect.py Misc/ACKS Misc/NEWS Message-ID: <20081112213902.0F1061E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 12 22:39:01 2008 New Revision: 67203 Log: change the named tuple returned by inspect.getfullargspec to have a 'kwonlydefaults' (as claimed by the docs) attribute instead of 'kwdefaults' Fixes #4307 Reviewed by Christian Modified: python/branches/py3k/Lib/inspect.py python/branches/py3k/Misc/ACKS python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/inspect.py ============================================================================== --- python/branches/py3k/Lib/inspect.py (original) +++ python/branches/py3k/Lib/inspect.py Wed Nov 12 22:39:01 2008 @@ -791,7 +791,7 @@ return ArgSpec(args, varargs, varkw, defaults) FullArgSpec = namedtuple('FullArgSpec', - 'args, varargs, varkw, defaults, kwonlyargs, kwdefaults, annotations') + 'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations') def getfullargspec(func): """Get the names and default values of a function's arguments. Modified: python/branches/py3k/Misc/ACKS ============================================================================== --- python/branches/py3k/Misc/ACKS (original) +++ python/branches/py3k/Misc/ACKS Wed Nov 12 22:39:01 2008 @@ -230,6 +230,7 @@ Peter Funk Geoff Furnish Ulisses Furquim +Hagen F?rstenau Achim Gaedke Lele Gaifax Santiago Gala Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 12 22:39:01 2008 @@ -19,6 +19,9 @@ Library ------- +- Issue #4307: The named tuple that ``inspect.getfullargspec()`` returns now + uses ``kwonlydefaults`` instead of ``kwdefaults``. + - Issue #4298: Fix a segfault when pickle.loads is passed a ill-formed input. - Issue #4283: Fix a left-over "iteritems" call in distutils. From python-3000-checkins at python.org Thu Nov 13 00:23:37 2008 From: python-3000-checkins at python.org (mark.dickinson) Date: Thu, 13 Nov 2008 00:23:37 +0100 (CET) Subject: [Python-3000-checkins] r67204 - in python/branches/py3k: Lib/test/test_contains.py Lib/test/test_float.py Misc/NEWS Objects/object.c Message-ID: <20081112232337.599B01E4002@bag.python.org> Author: mark.dickinson Date: Thu Nov 13 00:23:36 2008 New Revision: 67204 Log: Issue #4296: Fix PyObject_RichCompareBool so that "x in [x]" evaluates to True, even when x doesn't compare equal to itself. This was a regression from 2.6. Reviewed by R. Hettinger and C. Heimes. Modified: python/branches/py3k/Lib/test/test_contains.py python/branches/py3k/Lib/test/test_float.py python/branches/py3k/Misc/NEWS python/branches/py3k/Objects/object.c Modified: python/branches/py3k/Lib/test/test_contains.py ============================================================================== --- python/branches/py3k/Lib/test/test_contains.py (original) +++ python/branches/py3k/Lib/test/test_contains.py Thu Nov 13 00:23:36 2008 @@ -1,3 +1,4 @@ +from collections import deque from test.support import run_unittest import unittest @@ -6,7 +7,7 @@ def __init__(self, el): self.el = el -class set(base_set): +class myset(base_set): def __contains__(self, el): return self.el == el @@ -17,7 +18,7 @@ class TestContains(unittest.TestCase): def test_common_tests(self): a = base_set(1) - b = set(1) + b = myset(1) c = seq(1) self.assert_(1 in b) self.assert_(0 not in b) @@ -80,6 +81,25 @@ except TypeError: pass + def test_nonreflexive(self): + # containment and equality tests involving elements that are + # not necessarily equal to themselves + + class MyNonReflexive(object): + def __eq__(self, other): + return False + def __hash__(self): + return 28 + + values = float('nan'), 1, None, 'abc', MyNonReflexive() + constructors = list, tuple, dict.fromkeys, set, frozenset, deque + for constructor in constructors: + container = constructor(values) + for elem in container: + self.assert_(elem in container) + self.assert_(container == constructor(values)) + self.assert_(container == container) + def test_main(): run_unittest(TestContains) Modified: python/branches/py3k/Lib/test/test_float.py ============================================================================== --- python/branches/py3k/Lib/test/test_float.py (original) +++ python/branches/py3k/Lib/test/test_float.py Thu Nov 13 00:23:36 2008 @@ -117,6 +117,33 @@ self.assertRaises(OverflowError, float('-inf').as_integer_ratio) self.assertRaises(ValueError, float('nan').as_integer_ratio) + def test_float_containment(self): + floats = (INF, -INF, 0.0, 1.0, NAN) + for f in floats: + self.assert_(f in [f], "'%r' not in []" % f) + self.assert_(f in (f,), "'%r' not in ()" % f) + self.assert_(f in {f}, "'%r' not in set()" % f) + self.assert_(f in {f: None}, "'%r' not in {}" % f) + self.assertEqual([f].count(f), 1, "[].count('%r') != 1" % f) + self.assert_(f in floats, "'%r' not in container" % f) + + for f in floats: + # nonidentical containers, same type, same contents + self.assert_([f] == [f], "[%r] != [%r]" % (f, f)) + self.assert_((f,) == (f,), "(%r,) != (%r,)" % (f, f)) + self.assert_({f} == {f}, "{%r} != {%r}" % (f, f)) + self.assert_({f : None} == {f: None}, "{%r : None} != " + "{%r : None}" % (f, f)) + + # identical containers + l, t, s, d = [f], (f,), {f}, {f: None} + self.assert_(l == l, "[%r] not equal to itself" % f) + self.assert_(t == t, "(%r,) not equal to itself" % f) + self.assert_(s == s, "{%r} not equal to itself" % f) + self.assert_(d == d, "{%r : None} not equal to itself" % f) + + + class FormatFunctionsTestCase(unittest.TestCase): def setUp(self): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Nov 13 00:23:36 2008 @@ -13,6 +13,10 @@ Core and Builtins ----------------- +- Issue #4296: Fix PyObject_RichCompareBool so that "x in [x]" evaluates to + True, even when x doesn't compare equal to itself. This was a regression + from 2.6. + - Issue #3705: Command-line arguments were not correctly decoded when the terminal does not use UTF8. Modified: python/branches/py3k/Objects/object.c ============================================================================== --- python/branches/py3k/Objects/object.c (original) +++ python/branches/py3k/Objects/object.c Thu Nov 13 00:23:36 2008 @@ -687,6 +687,15 @@ PyObject *res; int ok; + /* Quick result when objects are the same. + Guarantees that identity implies equality. */ + if (v == w) { + if (op == Py_EQ) + return 1; + else if (op == Py_NE) + return 0; + } + res = PyObject_RichCompare(v, w, op); if (res == NULL) return -1; From python-3000-checkins at python.org Sun Nov 16 12:44:56 2008 From: python-3000-checkins at python.org (raymond.hettinger) Date: Sun, 16 Nov 2008 12:44:56 +0100 (CET) Subject: [Python-3000-checkins] r67232 - in python/branches/py3k: Lib/test/test_set.py Misc/NEWS Objects/setobject.c Message-ID: <20081116114456.18F2C1E4002@bag.python.org> Author: raymond.hettinger Date: Sun Nov 16 12:44:54 2008 New Revision: 67232 Log: Issue #1721812: Binary operations and copy operations on set/frozenset subclasses need to return the base type, not the subclass itself. Modified: python/branches/py3k/Lib/test/test_set.py python/branches/py3k/Misc/NEWS python/branches/py3k/Objects/setobject.c Modified: python/branches/py3k/Lib/test/test_set.py ============================================================================== --- python/branches/py3k/Lib/test/test_set.py (original) +++ python/branches/py3k/Lib/test/test_set.py Sun Nov 16 12:44:54 2008 @@ -71,7 +71,7 @@ for c in self.letters: self.assertEqual(c in u, c in self.d or c in self.otherword) self.assertEqual(self.s, self.thetype(self.word)) - self.assertEqual(type(u), self.thetype) + self.assertEqual(type(u), self.basetype) self.assertRaises(PassThru, self.s.union, check_pass_thru()) self.assertRaises(TypeError, self.s.union, [[]]) for C in set, frozenset, dict.fromkeys, str, list, tuple: @@ -97,7 +97,7 @@ for c in self.letters: self.assertEqual(c in i, c in self.d and c in self.otherword) self.assertEqual(self.s, self.thetype(self.word)) - self.assertEqual(type(i), self.thetype) + self.assertEqual(type(i), self.basetype) self.assertRaises(PassThru, self.s.intersection, check_pass_thru()) for C in set, frozenset, dict.fromkeys, str, list, tuple: self.assertEqual(self.thetype('abcba').intersection(C('cdc')), set('cc')) @@ -142,7 +142,7 @@ for c in self.letters: self.assertEqual(c in i, c in self.d and c not in self.otherword) self.assertEqual(self.s, self.thetype(self.word)) - self.assertEqual(type(i), self.thetype) + self.assertEqual(type(i), self.basetype) self.assertRaises(PassThru, self.s.difference, check_pass_thru()) self.assertRaises(TypeError, self.s.difference, [[]]) for C in set, frozenset, dict.fromkeys, str, list, tuple: @@ -169,7 +169,7 @@ for c in self.letters: self.assertEqual(c in i, (c in self.d) ^ (c in self.otherword)) self.assertEqual(self.s, self.thetype(self.word)) - self.assertEqual(type(i), self.thetype) + self.assertEqual(type(i), self.basetype) self.assertRaises(PassThru, self.s.symmetric_difference, check_pass_thru()) self.assertRaises(TypeError, self.s.symmetric_difference, [[]]) for C in set, frozenset, dict.fromkeys, str, list, tuple: @@ -325,6 +325,7 @@ class TestSet(TestJointOps): thetype = set + basetype = set def test_init(self): s = self.thetype() @@ -357,6 +358,7 @@ dup = self.s.copy() self.assertEqual(self.s, dup) self.assertNotEqual(id(self.s), id(dup)) + self.assertEqual(type(dup), self.basetype) def test_add(self): self.s.add('Q') @@ -595,6 +597,7 @@ class TestSetSubclass(TestSet): thetype = SetSubclass + basetype = set class SetSubclassWithKeywordArgs(set): def __init__(self, iterable=[], newarg=None): @@ -608,6 +611,7 @@ class TestFrozenSet(TestJointOps): thetype = frozenset + basetype = frozenset def test_init(self): s = self.thetype(self.word) @@ -673,6 +677,7 @@ class TestFrozenSetSubclass(TestFrozenSet): thetype = FrozenSetSubclass + basetype = frozenset def test_constructor_identity(self): s = self.thetype(range(3)) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sun Nov 16 12:44:54 2008 @@ -13,6 +13,11 @@ Core and Builtins ----------------- +- Issue #1721812: Binary set operations and copy() returned the input type + instead of the appropriate base type. This was incorrect because set + subclasses would be created without their __init__() method being called. + The corrected behavior brings sets into line with lists and dicts. + - Issue #4296: Fix PyObject_RichCompareBool so that "x in [x]" evaluates to True, even when x doesn't compare equal to itself. This was a regression from 2.6. Modified: python/branches/py3k/Objects/setobject.c ============================================================================== --- python/branches/py3k/Objects/setobject.c (original) +++ python/branches/py3k/Objects/setobject.c Sun Nov 16 12:44:54 2008 @@ -1017,6 +1017,18 @@ return (PyObject *)so; } +static PyObject * +make_new_set_basetype(PyTypeObject *type, PyObject *iterable) +{ + if (type != &PySet_Type && type != &PyFrozenSet_Type) { + if (PyType_IsSubtype(type, &PySet_Type)) + type = &PySet_Type; + else + type = &PyFrozenSet_Type; + } + return make_new_set(type, iterable); +} + /* The empty frozenset is a singleton */ static PyObject *emptyfrozenset = NULL; @@ -1129,7 +1141,7 @@ static PyObject * set_copy(PySetObject *so) { - return make_new_set(Py_TYPE(so), (PyObject *)so); + return make_new_set_basetype(Py_TYPE(so), (PyObject *)so); } static PyObject * @@ -1225,7 +1237,7 @@ if ((PyObject *)so == other) return set_copy(so); - result = (PySetObject *)make_new_set(Py_TYPE(so), NULL); + result = (PySetObject *)make_new_set_basetype(Py_TYPE(so), NULL); if (result == NULL) return NULL; @@ -1520,7 +1532,7 @@ return NULL; } - result = make_new_set(Py_TYPE(so), NULL); + result = make_new_set_basetype(Py_TYPE(so), NULL); if (result == NULL) return NULL; @@ -1641,7 +1653,7 @@ Py_INCREF(other); otherset = (PySetObject *)other; } else { - otherset = (PySetObject *)make_new_set(Py_TYPE(so), other); + otherset = (PySetObject *)make_new_set_basetype(Py_TYPE(so), other); if (otherset == NULL) return NULL; } @@ -1672,7 +1684,7 @@ PyObject *rv; PySetObject *otherset; - otherset = (PySetObject *)make_new_set(Py_TYPE(so), other); + otherset = (PySetObject *)make_new_set_basetype(Py_TYPE(so), other); if (otherset == NULL) return NULL; rv = set_symmetric_difference_update(otherset, (PyObject *)so); From python-3000-checkins at python.org Sun Nov 16 19:33:54 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 16 Nov 2008 19:33:54 +0100 (CET) Subject: [Python-3000-checkins] r67237 - in python/branches/py3k: Doc/conf.py Doc/documenting/index.rst Doc/documenting/markup.rst Doc/documenting/rest.rst Doc/documenting/sphinx.rst Doc/documenting/style.rst Doc/library/http.client.rst Doc/library/locale.rst Doc/library/multiprocessing.rst Lib/http/client.py Lib/string.py Modules/posixmodule.c configure configure.in Message-ID: <20081116183354.53C1D1E4002@bag.python.org> Author: benjamin.peterson Date: Sun Nov 16 19:33:53 2008 New Revision: 67237 Log: Merged revisions 67154,67157-67159,67175-67176,67189,67224-67227,67234 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67154 | hirokazu.yamamoto | 2008-11-07 21:46:17 -0600 (Fri, 07 Nov 2008) | 1 line Issue #4071: ntpath.abspath returned an empty string for long unicode path. ........ r67157 | georg.brandl | 2008-11-08 05:47:44 -0600 (Sat, 08 Nov 2008) | 2 lines Don't use "HOWTO" as the title for all howto .tex files. ........ r67158 | georg.brandl | 2008-11-08 05:48:20 -0600 (Sat, 08 Nov 2008) | 2 lines Update "Documenting" a bit. Concentrate on Python-specifics. ........ r67159 | georg.brandl | 2008-11-08 06:52:25 -0600 (Sat, 08 Nov 2008) | 2 lines Fix warning. ........ r67175 | benjamin.peterson | 2008-11-08 19:44:32 -0600 (Sat, 08 Nov 2008) | 1 line update link ........ r67176 | benjamin.peterson | 2008-11-08 19:52:32 -0600 (Sat, 08 Nov 2008) | 1 line fix comment ........ r67189 | benjamin.peterson | 2008-11-11 15:56:06 -0600 (Tue, 11 Nov 2008) | 1 line use correct name ........ r67224 | georg.brandl | 2008-11-15 02:10:04 -0600 (Sat, 15 Nov 2008) | 2 lines #4324: fix getlocale() argument. ........ r67225 | brett.cannon | 2008-11-15 16:33:25 -0600 (Sat, 15 Nov 2008) | 1 line Clarify the docs for the 'strict' argument to httplib.HTTPConnection. ........ r67226 | brett.cannon | 2008-11-15 16:40:44 -0600 (Sat, 15 Nov 2008) | 4 lines The docs for httplib.HTTPConnection.putheader() have claimed for quite a while that their could be an arbitrary number of values passed in. Turns out the code did not match that. The code now matches the docs. ........ r67227 | georg.brandl | 2008-11-16 02:00:17 -0600 (Sun, 16 Nov 2008) | 2 lines #4316: fix configure.in markup problem. ........ r67234 | benjamin.peterson | 2008-11-16 11:54:55 -0600 (Sun, 16 Nov 2008) | 1 line run autoconf ........ Removed: python/branches/py3k/Doc/documenting/sphinx.rst Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/conf.py python/branches/py3k/Doc/documenting/index.rst python/branches/py3k/Doc/documenting/markup.rst python/branches/py3k/Doc/documenting/rest.rst python/branches/py3k/Doc/documenting/style.rst python/branches/py3k/Doc/library/http.client.rst python/branches/py3k/Doc/library/locale.rst python/branches/py3k/Doc/library/multiprocessing.rst python/branches/py3k/Lib/http/client.py python/branches/py3k/Lib/string.py python/branches/py3k/Modules/posixmodule.c python/branches/py3k/configure python/branches/py3k/configure.in Modified: python/branches/py3k/Doc/conf.py ============================================================================== --- python/branches/py3k/Doc/conf.py (original) +++ python/branches/py3k/Doc/conf.py Sun Nov 16 19:33:53 2008 @@ -131,7 +131,7 @@ ] # Collect all HOWTOs individually latex_documents.extend(('howto/' + fn[:-4], 'howto-' + fn[:-4] + '.tex', - 'HOWTO', _stdauthor, 'howto') + '', _stdauthor, 'howto') for fn in os.listdir('howto') if fn.endswith('.rst') and fn != 'index.rst') Modified: python/branches/py3k/Doc/documenting/index.rst ============================================================================== --- python/branches/py3k/Doc/documenting/index.rst (original) +++ python/branches/py3k/Doc/documenting/index.rst Sun Nov 16 19:33:53 2008 @@ -8,7 +8,7 @@ The Python language has a substantial body of documentation, much of it contributed by various authors. The markup used for the Python documentation is `reStructuredText`_, developed by the `docutils`_ project, amended by custom -directives and using a toolset named *Sphinx* to postprocess the HTML output. +directives and using a toolset named `Sphinx`_ to postprocess the HTML output. This document describes the style guide for our documentation, the custom reStructuredText markup introduced to support Python documentation and how it @@ -16,6 +16,7 @@ .. _reStructuredText: http://docutils.sf.net/rst.html .. _docutils: http://docutils.sf.net/ +.. _Sphinx: http://sphinx.pocoo.org/ If you're interested in contributing to Python's documentation, there's no need to write reStructuredText if you're not so inclined; plain text contributions @@ -28,7 +29,3 @@ rest.rst markup.rst fromlatex.rst - sphinx.rst - -.. XXX add credits, thanks etc. - Modified: python/branches/py3k/Doc/documenting/markup.rst ============================================================================== --- python/branches/py3k/Doc/documenting/markup.rst (original) +++ python/branches/py3k/Doc/documenting/markup.rst Sun Nov 16 19:33:53 2008 @@ -8,24 +8,11 @@ Documentation for "standard" reST constructs is not included here, though they are used in the Python documentation. -File-wide metadata ------------------- - -reST has the concept of "field lists"; these are a sequence of fields marked up -like this:: - - :Field name: Field content - -A field list at the very top of a file is parsed as the "docinfo", which in -normal documents can be used to record the author, date of publication and -other metadata. In Sphinx, the docinfo is used as metadata, too, but not -displayed in the output. - -At the moment, only one metadata field is recognized: +.. note:: -``nocomments`` - If set, the web application won't display a comment form for a page generated - from this source file. + This is just an overview of Sphinx' extended markup capabilities; full + coverage can be found in `its own documentation + `_. Meta-information markup @@ -88,7 +75,6 @@ authors of the module code, just like ``sectionauthor`` names the author(s) of a piece of documentation. It too does not result in any output currently. - .. note:: It is important to make the section title of a module-describing file @@ -272,7 +258,7 @@ This language is used until the next ``highlightlang`` directive is encountered. -* The valid values for the highlighting language are: +* The values normally used for the highlighting language are: * ``python`` (the default) * ``c`` @@ -799,7 +785,7 @@ ------------- The documentation system provides three substitutions that are defined by default. -They are set in the build configuration file, see :ref:`doc-build-config`. +They are set in the build configuration file :file:`conf.py`. .. describe:: |release| Modified: python/branches/py3k/Doc/documenting/rest.rst ============================================================================== --- python/branches/py3k/Doc/documenting/rest.rst (original) +++ python/branches/py3k/Doc/documenting/rest.rst Sun Nov 16 19:33:53 2008 @@ -67,12 +67,6 @@ #. This is a numbered list. #. It has two items too. -Note that Sphinx disables the use of enumerated lists introduced by alphabetic -or roman numerals, such as :: - - A. First item - B. Second item - Nested lists are possible, but be aware that they must be separated from the parent list items by blank lines:: @@ -247,5 +241,3 @@ * **Separation of inline markup:** As said above, inline markup spans must be separated from the surrounding text by non-word characters, you have to use an escaped space to get around that. - -.. XXX more? Deleted: python/branches/py3k/Doc/documenting/sphinx.rst ============================================================================== --- python/branches/py3k/Doc/documenting/sphinx.rst Sun Nov 16 19:33:53 2008 +++ (empty file) @@ -1,76 +0,0 @@ -.. highlightlang:: rest - -The Sphinx build system -======================= - -.. XXX: intro... - -.. _doc-build-config: - -The build configuration file ----------------------------- - -The documentation root, that is the ``Doc`` subdirectory of the source -distribution, contains a file named ``conf.py``. This file is called the "build -configuration file", and it contains several variables that are read and used -during a build run. - -These variables are: - -version : string - A string that is used as a replacement for the ``|version|`` reST - substitution. It should be the Python version the documentation refers to. - This consists only of the major and minor version parts, e.g. ``2.5``, even - for version 2.5.1. - -release : string - A string that is used as a replacement for the ``|release|`` reST - substitution. It should be the full version string including - alpha/beta/release candidate tags, e.g. ``2.5.2b3``. - -Both ``release`` and ``version`` can be ``'auto'``, which means that they are -determined at runtime from the ``Include/patchlevel.h`` file, if a complete -Python source distribution can be found, or else from the interpreter running -Sphinx. - -today_fmt : string - A ``strftime`` format that is used to format a replacement for the - ``|today|`` reST substitution. - -today : string - A string that can contain a date that should be written to the documentation - output literally. If this is nonzero, it is used instead of - ``strftime(today_fmt)``. - -unused_files : list of strings - A list of reST filenames that are to be disregarded during building. This - could be docs for temporarily disabled modules or documentation that's not - yet ready for public consumption. - -add_function_parentheses : bool - If true, ``()`` will be appended to the content of ``:func:``, ``:meth:`` and - ``:cfunc:`` cross-references. - -add_module_names : bool - If true, the current module name will be prepended to all description unit - titles (such as ``.. function::``). - -Builder-specific variables -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -html_download_base_url : string - The base URL for download links on the download page. - -html_last_updated_fmt : string - If this is not an empty string, it will be given to ``time.strftime()`` and - written to each generated output file after "last updated on:". - -html_use_smartypants : bool - If true, use SmartyPants to convert quotes and dashes to the typographically - correct entities. - -latex_paper_size : "letter" or "a4" - The paper size option for the LaTeX document class. - -latex_font_size : "10pt", "11pt" or "12pt" - The font size option for the LaTeX document class. \ No newline at end of file Modified: python/branches/py3k/Doc/documenting/style.rst ============================================================================== --- python/branches/py3k/Doc/documenting/style.rst (original) +++ python/branches/py3k/Doc/documenting/style.rst Sun Nov 16 19:33:53 2008 @@ -66,5 +66,5 @@ 1970s. -.. _Apple Publications Style Guide: http://developer.apple.com/documentation/UserExperience/Conceptual/APStyleGuide/AppleStyleGuide2006.pdf +.. _Apple Publications Style Guide: http://developer.apple.com/documentation/UserExperience/Conceptual/APStyleGuide/APSG_2008.pdf Modified: python/branches/py3k/Doc/library/http.client.rst ============================================================================== --- python/branches/py3k/Doc/library/http.client.rst (original) +++ python/branches/py3k/Doc/library/http.client.rst Sun Nov 16 19:33:53 2008 @@ -29,7 +29,8 @@ server. It should be instantiated passing it a host and optional port number. If no port number is passed, the port is extracted from the host string if it has the form ``host:port``, else the default HTTP port (80) is - used. When True, the optional parameter *strict* causes ``BadStatusLine`` to + used. When True, the optional parameter *strict* (which defaults to a false + value) causes ``BadStatusLine`` to be raised if the status line can't be parsed as a valid HTTP/1.0 or 1.1 status line. If the optional *timeout* parameter is given, blocking operations (like connection attempts) will timeout after that many seconds Modified: python/branches/py3k/Doc/library/locale.rst ============================================================================== --- python/branches/py3k/Doc/library/locale.rst (original) +++ python/branches/py3k/Doc/library/locale.rst Sun Nov 16 19:33:53 2008 @@ -472,7 +472,7 @@ Example:: >>> import locale - >>> loc = locale.getlocale(locale.LC_ALL) # get current locale + >>> loc = locale.getlocale() # get current locale >>> locale.setlocale(locale.LC_ALL, 'de_DE') # use German locale; name might vary with platform >>> locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut >>> locale.setlocale(locale.LC_ALL, '') # use user's preferred locale Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Sun Nov 16 19:33:53 2008 @@ -1780,7 +1780,7 @@ Below is an example session with logging turned on:: >>> import multiprocessing, logging - >>> logger = multiprocessing.getLogger() + >>> logger = multiprocessing.get_logger() >>> logger.setLevel(logging.INFO) >>> logger.warning('doomed') [WARNING/MainProcess] doomed Modified: python/branches/py3k/Lib/http/client.py ============================================================================== --- python/branches/py3k/Lib/http/client.py (original) +++ python/branches/py3k/Lib/http/client.py Sun Nov 16 19:33:53 2008 @@ -812,7 +812,7 @@ # For HTTP/1.0, the server will assume "not chunked" pass - def putheader(self, header, value): + def putheader(self, header, *values): """Send a request header line to the server. For example: h.putheader('Accept', 'text/html') @@ -822,8 +822,11 @@ if hasattr(header, 'encode'): header = header.encode('ascii') - if hasattr(value, 'encode'): - value = value.encode('ascii') + values = list(values) + for i, one_value in enumerate(values): + if hasattr(one_value, 'encode'): + values[i] = one_value.encode('ascii') + value = b'\r\n\t'.join(values) header = header + b': ' + value self._output(header) Modified: python/branches/py3k/Lib/string.py ============================================================================== --- python/branches/py3k/Lib/string.py (original) +++ python/branches/py3k/Lib/string.py Sun Nov 16 19:33:53 2008 @@ -189,9 +189,8 @@ # the Formatter class # see PEP 3101 for details and purpose of this class -# The hard parts are reused from the C implementation. They're -# exposed here via the sys module. sys was chosen because it's always -# available and doesn't have to be dynamically loaded. +# The hard parts are reused from the C implementation. They're exposed as "_" +# prefixed methods of str and unicode. # The overall parser is implemented in str._formatter_parser. # The field name parser is implemented in str._formatter_field_name_split Modified: python/branches/py3k/Modules/posixmodule.c ============================================================================== --- python/branches/py3k/Modules/posixmodule.c (original) +++ python/branches/py3k/Modules/posixmodule.c Sun Nov 16 19:33:53 2008 @@ -2395,13 +2395,27 @@ if (unicode_file_names()) { PyUnicodeObject *po; if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) { - Py_UNICODE woutbuf[MAX_PATH*2]; + Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po); + Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf; Py_UNICODE *wtemp; - if (!GetFullPathNameW(PyUnicode_AS_UNICODE(po), - sizeof(woutbuf)/sizeof(woutbuf[0]), - woutbuf, &wtemp)) - return win32_error("GetFullPathName", ""); - return PyUnicode_FromUnicode(woutbuf, wcslen(woutbuf)); + DWORD result; + PyObject *v; + result = GetFullPathNameW(wpath, + sizeof(woutbuf)/sizeof(woutbuf[0]), + woutbuf, &wtemp); + if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) { + woutbufp = malloc(result * sizeof(Py_UNICODE)); + if (!woutbufp) + return PyErr_NoMemory(); + result = GetFullPathNameW(wpath, result, woutbufp, &wtemp); + } + if (result) + v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp)); + else + v = win32_error_unicode("GetFullPathNameW", wpath); + if (woutbufp != woutbuf) + free(woutbufp); + return v; } /* Drop the argument parsing error as narrow strings are also valid. */ Modified: python/branches/py3k/configure ============================================================================== --- python/branches/py3k/configure (original) +++ python/branches/py3k/configure Sun Nov 16 19:33:53 2008 @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 66297 . +# From configure.in Revision: 67100 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for python 3.0. # @@ -2083,7 +2083,7 @@ # Defining _XOPEN_SOURCE on NetBSD version prior to the introduction of # _NETBSD_SOURCE disables certain features (eg. setgroups). Reported by # Marc Recht - NetBSD/1.5 | NetBSD/1.5.* | NetBSD/1.6 | NetBSD/1.6.* | NetBSD/1.6A-S) + NetBSD/1.5 | NetBSD/1.5.* | NetBSD/1.6 | NetBSD/1.6.* | NetBSD/1.6[A-S]) define_xopen_source=no;; # On Solaris 2.6, sys/wait.h is inconsistent in the usage # of union __?sigval. Reported by Stuart Bishop. Modified: python/branches/py3k/configure.in ============================================================================== --- python/branches/py3k/configure.in (original) +++ python/branches/py3k/configure.in Sun Nov 16 19:33:53 2008 @@ -260,7 +260,7 @@ # Defining _XOPEN_SOURCE on NetBSD version prior to the introduction of # _NETBSD_SOURCE disables certain features (eg. setgroups). Reported by # Marc Recht - NetBSD/1.5 | NetBSD/1.5.* | NetBSD/1.6 | NetBSD/1.6.* | NetBSD/1.6[A-S]) + NetBSD/1.5 | NetBSD/1.5.* | NetBSD/1.6 | NetBSD/1.6.* | NetBSD/1.6@<:@A-S@:>@) define_xopen_source=no;; # On Solaris 2.6, sys/wait.h is inconsistent in the usage # of union __?sigval. Reported by Stuart Bishop. From python-3000-checkins at python.org Mon Nov 17 17:04:11 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Mon, 17 Nov 2008 17:04:11 +0100 (CET) Subject: [Python-3000-checkins] r67241 - python/branches/py3k/Doc/distutils/setupscript.rst Message-ID: <20081117160411.52C421E4010@bag.python.org> Author: martin.v.loewis Date: Mon Nov 17 17:04:09 2008 New Revision: 67241 Log: Issue #4312: Remove claim that distutils parameters must not be Unicode. The opposite is true. Modified: python/branches/py3k/Doc/distutils/setupscript.rst Modified: python/branches/py3k/Doc/distutils/setupscript.rst ============================================================================== --- python/branches/py3k/Doc/distutils/setupscript.rst (original) +++ python/branches/py3k/Doc/distutils/setupscript.rst Mon Nov 17 17:04:09 2008 @@ -588,8 +588,6 @@ 'list of strings' See below. -None of the string values may be Unicode. - Encoding the version information is an art in itself. Python packages generally adhere to the version format *major.minor[.patch][sub]*. The major number is 0 for initial, experimental releases of software. It is incremented for releases From python-3000-checkins at python.org Mon Nov 17 17:22:12 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Mon, 17 Nov 2008 17:22:12 +0100 (CET) Subject: [Python-3000-checkins] r67242 - in python/branches/py3k: Misc/NEWS Python/pystate.c Message-ID: <20081117162212.214F51E4010@bag.python.org> Author: martin.v.loewis Date: Mon Nov 17 17:22:11 2008 New Revision: 67242 Log: Issue #3327: Don't overallocate in the modules_by_index list. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Python/pystate.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Mon Nov 17 17:22:11 2008 @@ -13,6 +13,8 @@ Core and Builtins ----------------- +- Issue #3327: Don't overallocate in the modules_by_index list. + - Issue #1721812: Binary set operations and copy() returned the input type instead of the appropriate base type. This was incorrect because set subclasses would be created without their __init__() method being called. Modified: python/branches/py3k/Python/pystate.c ============================================================================== --- python/branches/py3k/Python/pystate.c (original) +++ python/branches/py3k/Python/pystate.c Mon Nov 17 17:22:11 2008 @@ -234,7 +234,7 @@ if (!def) return -1; if (!state->modules_by_index) { - state->modules_by_index = PyList_New(20); + state->modules_by_index = PyList_New(0); if (!state->modules_by_index) return -1; } From python-3000-checkins at python.org Mon Nov 17 22:47:41 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Mon, 17 Nov 2008 22:47:41 +0100 (CET) Subject: [Python-3000-checkins] r67244 - python/branches/py3k/Doc/library/stdtypes.rst Message-ID: <20081117214741.B6C4B1E4010@bag.python.org> Author: benjamin.peterson Date: Mon Nov 17 22:47:41 2008 New Revision: 67244 Log: rephrase dict view docs Modified: python/branches/py3k/Doc/library/stdtypes.rst Modified: python/branches/py3k/Doc/library/stdtypes.rst ============================================================================== --- python/branches/py3k/Doc/library/stdtypes.rst (original) +++ python/branches/py3k/Doc/library/stdtypes.rst Mon Nov 17 22:47:41 2008 @@ -1881,8 +1881,7 @@ 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. The keys and items views have a set-like character -since their entries +reflects these changes. Dictionary views can be iterated over to yield their respective data, and support membership tests: @@ -1910,8 +1909,11 @@ items (in the latter case, *x* should be a ``(key, value)`` tuple). -The keys and items views also provide set-like operations ("other" here refers -to another dictionary view or a set): +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.) Then these set operations are +available ("other" refers either to another view or a set): .. describe:: dictview & other @@ -1931,11 +1933,6 @@ Return the symmetric difference (all elements either in *dictview* or *other*, but not in both) of the dictview and the other object as a new set. -.. warning:: - - Since a dictionary's values are not required to be hashable, any of these - four operations will fail if an involved dictionary contains such a value. - An example of dictionary view usage:: From python-3000-checkins at python.org Mon Nov 17 23:45:50 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Mon, 17 Nov 2008 23:45:50 +0100 (CET) Subject: [Python-3000-checkins] r67248 - in python/branches/py3k: Lib/test/test_descr.py Objects/typeobject.c Message-ID: <20081117224550.916DD1E400C@bag.python.org> Author: benjamin.peterson Date: Mon Nov 17 23:45:50 2008 New Revision: 67248 Log: Merged revisions 67246 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67246 | benjamin.peterson | 2008-11-17 16:39:09 -0600 (Mon, 17 Nov 2008) | 5 lines when __getattr__ is a descriptor, call it correctly; fixes #4230 patch from Ziga Seilnacht ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/test/test_descr.py python/branches/py3k/Objects/typeobject.c Modified: python/branches/py3k/Lib/test/test_descr.py ============================================================================== --- python/branches/py3k/Lib/test/test_descr.py (original) +++ python/branches/py3k/Lib/test/test_descr.py Mon Nov 17 23:45:50 2008 @@ -4001,6 +4001,46 @@ c[1:2] = 3 self.assertEqual(c.value, 3) + def test_getattr_hooks(self): + # issue 4230 + + class Descriptor(object): + counter = 0 + def __get__(self, obj, objtype=None): + def getter(name): + self.counter += 1 + raise AttributeError(name) + return getter + + descr = Descriptor() + class A(object): + __getattribute__ = descr + class B(object): + __getattr__ = descr + class C(object): + __getattribute__ = descr + __getattr__ = descr + + self.assertRaises(AttributeError, getattr, A(), "attr") + self.assertEquals(descr.counter, 1) + self.assertRaises(AttributeError, getattr, B(), "attr") + self.assertEquals(descr.counter, 2) + self.assertRaises(AttributeError, getattr, C(), "attr") + self.assertEquals(descr.counter, 4) + + import gc + class EvilGetattribute(object): + # This used to segfault + def __getattr__(self, name): + raise AttributeError(name) + def __getattribute__(self, name): + del EvilGetattribute.__getattr__ + for i in range(5): + gc.collect() + raise AttributeError(name) + + self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr") + class DictProxyTests(unittest.TestCase): def setUp(self): Modified: python/branches/py3k/Objects/typeobject.c ============================================================================== --- python/branches/py3k/Objects/typeobject.c (original) +++ python/branches/py3k/Objects/typeobject.c Mon Nov 17 23:45:50 2008 @@ -4960,6 +4960,24 @@ } static PyObject * +call_attribute(PyObject *self, PyObject *attr, PyObject *name) +{ + PyObject *res, *descr = NULL; + descrgetfunc f = Py_TYPE(attr)->tp_descr_get; + + if (f != NULL) { + descr = f(attr, self, (PyObject *)(Py_TYPE(self))); + if (descr == NULL) + return NULL; + else + attr = descr; + } + res = PyObject_CallFunctionObjArgs(attr, name, NULL); + Py_XDECREF(descr); + return res; +} + +static PyObject * slot_tp_getattr_hook(PyObject *self, PyObject *name) { PyTypeObject *tp = Py_TYPE(self); @@ -4978,24 +4996,39 @@ if (getattribute_str == NULL) return NULL; } + /* speed hack: we could use lookup_maybe, but that would resolve the + method fully for each attribute lookup for classes with + __getattr__, even when the attribute is present. So we use + _PyType_Lookup and create the method only when needed, with + call_attribute. */ getattr = _PyType_Lookup(tp, getattr_str); if (getattr == NULL) { /* No __getattr__ hook: use a simpler dispatcher */ tp->tp_getattro = slot_tp_getattro; return slot_tp_getattro(self, name); } + Py_INCREF(getattr); + /* speed hack: we could use lookup_maybe, but that would resolve the + method fully for each attribute lookup for classes with + __getattr__, even when self has the default __getattribute__ + method. So we use _PyType_Lookup and create the method only when + needed, with call_attribute. */ getattribute = _PyType_Lookup(tp, getattribute_str); if (getattribute == NULL || (Py_TYPE(getattribute) == &PyWrapperDescr_Type && ((PyWrapperDescrObject *)getattribute)->d_wrapped == (void *)PyObject_GenericGetAttr)) res = PyObject_GenericGetAttr(self, name); - else - res = PyObject_CallFunctionObjArgs(getattribute, self, name, NULL); + else { + Py_INCREF(getattribute); + res = call_attribute(self, getattribute, name); + Py_DECREF(getattribute); + } if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); - res = PyObject_CallFunctionObjArgs(getattr, self, name, NULL); + res = call_attribute(self, getattr, name); } + Py_DECREF(getattr); return res; } From python-3000-checkins at python.org Mon Nov 17 23:55:16 2008 From: python-3000-checkins at python.org (raymond.hettinger) Date: Mon, 17 Nov 2008 23:55:16 +0100 (CET) Subject: [Python-3000-checkins] r67249 - python/branches/py3k/Doc/reference/expressions.rst Message-ID: <20081117225516.86D721E400C@bag.python.org> Author: raymond.hettinger Date: Mon Nov 17 23:55:16 2008 New Revision: 67249 Log: Issue 4090 and 4087: Further documentation of comparisons. Modified: python/branches/py3k/Doc/reference/expressions.rst Modified: python/branches/py3k/Doc/reference/expressions.rst ============================================================================== --- python/branches/py3k/Doc/reference/expressions.rst (original) +++ python/branches/py3k/Doc/reference/expressions.rst Mon Nov 17 23:55:16 2008 @@ -1003,6 +1003,12 @@ * Numbers are compared arithmetically. +* The values :const:`float('NaN')` and :const:`Decimal('NaN')` are special. + The are identical to themselves, ``x is x`` but are not equal to themselves, + ``x != x``. Additionally, comparing any value to a not-a-number value + will return ``False``. For example, both ``3 < float('NaN')`` and + ``float('NaN') < 3`` will return ``False``. + * Bytes objects are compared lexicographically using the numeric values of their elements. @@ -1024,19 +1030,36 @@ value)`` lists compare equal. [#]_ Outcomes other than equality are resolved consistently, but are not otherwise defined. [#]_ +* Sets and frozensets define comparison operators to mean subset and superset + tests. Those relations do not define total orderings (the two sets ``{1,2}`` + and {2,3} are not equal, nor subsets of one another, nor supersets of one + another). Accordingly, sets are not appropriate arguments for functions + which depend on total ordering. For example, :func:`min`, :func:`max`, and + :func:`sorted` produce undefined results given a list of sets as inputs. + * Most other objects of builtin types compare unequal unless they are the same object; the choice whether one object is considered smaller or larger than another one is made arbitrarily but consistently within one execution of a program. +Comparison of objects of the differing types depends on whether either +of the types provide explicit support for the comparison. Most numberic types +can be compared with one another, but comparisons of :class:`float` and +:class:`Decimal` are not supported to avoid the inevitable confusion arising +from representation issues such as ``float('1.1')`` being inexactly represented +and therefore not exactly equal to ``Decimal('1.1')`` which is. When +cross-type comparison is not supported, the comparison method returns +``NotImplemented``. This can create the illusion of non-transitivity between +supported cross-type comparisons and unsupported comparisons. For example, +``Decimal(2) == 2`` and `2 == float(2)`` but ``Decimal(2) != float(2)``. + The operators :keyword:`in` and :keyword:`not in` test for membership. ``x in s`` evaluates to true if *x* is a member of *s*, and false otherwise. ``x not in s`` returns the negation of ``x in s``. All built-in sequences and set types support this as well as dictionary, for which :keyword:`in` tests whether a the -dictionary has a given key. - -For the list and tuple types, ``x in y`` is true if and only if there exists an -index *i* such that ``x == y[i]`` is true. +dictionary has a given key. For container types such as list, tuple, set, +frozenset, dict, or collections.deque, the expression ``x in y`` equivalent to +``any(x is e or x == e for val e in y)``. For the string and bytes types, ``x in y`` is true if and only if *x* is a substring of *y*. An equivalent test is ``y.find(x) != -1``. Empty strings are From python-3000-checkins at python.org Tue Nov 18 01:07:10 2008 From: python-3000-checkins at python.org (raymond.hettinger) Date: Tue, 18 Nov 2008 01:07:10 +0100 (CET) Subject: [Python-3000-checkins] r67253 - python/branches/py3k/Python/peephole.c Message-ID: <20081118000710.8E52E1E4002@bag.python.org> Author: raymond.hettinger Date: Tue Nov 18 01:07:10 2008 New Revision: 67253 Log: Issue 2260: Small peephole optimization -- eliminate unnecessary POP_TOP /JUMP_FORWARD 1 pairs. Modified: python/branches/py3k/Python/peephole.c Modified: python/branches/py3k/Python/peephole.c ============================================================================== --- python/branches/py3k/Python/peephole.c (original) +++ python/branches/py3k/Python/peephole.c Tue Nov 18 01:07:10 2008 @@ -430,6 +430,16 @@ cumlc = 0; break; + /* Replace POP_TOP JUMP_FORWARD 1 POP_TOP + with NOP NOP NOP NOP POP_TOP. */ + case POP_TOP: + if (UNCONDITIONAL_JUMP(codestr[i+1]) && + GETJUMPTGT(codestr, i+1) == i+5 && + codestr[i+4] == POP_TOP && + ISBASICBLOCK(blocks,i,4)) + memset(codestr+i, NOP, 4); + break; + /* Try to fold tuples of constants (includes a case for lists which are only used for "in" and "not in" tests). Skip over BUILD_SEQN 1 UNPACK_SEQN 1. From musiccomposition at gmail.com Tue Nov 18 01:10:31 2008 From: musiccomposition at gmail.com (Benjamin Peterson) Date: Mon, 17 Nov 2008 18:10:31 -0600 Subject: [Python-3000-checkins] r67253 - python/branches/py3k/Python/peephole.c In-Reply-To: <20081118000710.8E52E1E4002@bag.python.org> References: <20081118000710.8E52E1E4002@bag.python.org> Message-ID: <1afaf6160811171610q190e962dw5815b7776f339a2@mail.gmail.com> On Mon, Nov 17, 2008 at 6:07 PM, raymond. hettinger wrote: > Author: raymond.hettinger > Date: Tue Nov 18 01:07:10 2008 > New Revision: 67253 > > Log: > Issue 2260: Small peephole optimization -- eliminate unnecessary POP_TOP /JUMP_FORWARD 1 pairs. 1. Shouldn't this be applied in the trunk? 2. Shouldn't this have tests? 3. Isn't past the second RC too late for any optimizations? -- Cheers, Benjamin Peterson "There's nothing quite as beautiful as an oboe... except a chicken stuck in a vacuum cleaner." From python-3000-checkins at python.org Tue Nov 18 05:33:04 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Tue, 18 Nov 2008 05:33:04 +0100 (CET) Subject: [Python-3000-checkins] r67256 - python/branches/py3k/Modules/_tkinter.c Message-ID: <20081118043304.445D81E4002@bag.python.org> Author: hirokazu.yamamoto Date: Tue Nov 18 05:33:04 2008 New Revision: 67256 Log: Issue #4313: Fixed segfault on IDLE exit. Reverted r57540 and reopened Issue #1028. Modified: python/branches/py3k/Modules/_tkinter.c Modified: python/branches/py3k/Modules/_tkinter.c ============================================================================== --- python/branches/py3k/Modules/_tkinter.c (original) +++ python/branches/py3k/Modules/_tkinter.c Tue Nov 18 05:33:04 2008 @@ -1906,7 +1906,7 @@ PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; - PyObject *self, *func, *arg, *res, *s; + PyObject *self, *func, *arg, *res; int i, rv; Tcl_Obj *obj_res; @@ -1923,13 +1923,7 @@ return PythonCmd_Error(interp); for (i = 0; i < (argc - 1); i++) { - if (11 == (i + 1)) { /* the %A arg is the unicode char */ - char *a = argv[i + 1]; - s = PyUnicode_FromUnicode((Py_UNICODE *) a, strlen(a)); - } - else { - s = PyUnicode_FromString(argv[i + 1]); - } + PyObject *s = PyUnicode_FromString(argv[i + 1]); if (!s || PyTuple_SetItem(arg, i, s)) { Py_DECREF(arg); return PythonCmd_Error(interp); From python-3000-checkins at python.org Tue Nov 18 23:37:15 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 18 Nov 2008 23:37:15 +0100 (CET) Subject: [Python-3000-checkins] r67269 - in python/branches/py3k: Makefile.pre.in Misc/NEWS Message-ID: <20081118223715.7F7191E4002@bag.python.org> Author: benjamin.peterson Date: Tue Nov 18 23:37:15 2008 New Revision: 67269 Log: fix the Makefile so it doesn't pollute sys.path #4349 reviewed by Christian Modified: python/branches/py3k/Makefile.pre.in python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Makefile.pre.in ============================================================================== --- python/branches/py3k/Makefile.pre.in (original) +++ python/branches/py3k/Makefile.pre.in Tue Nov 18 23:37:15 2008 @@ -801,7 +801,6 @@ # Install the library PLATDIR= plat-$(MACHDEP) EXTRAPLATDIR= @EXTRAPLATDIR@ -EXTRAMACHDEPPATH=@EXTRAMACHDEPPATH@ MACHDEPS= $(PLATDIR) $(EXTRAPLATDIR) XMLLIBSUBDIRS= xml xml/dom xml/etree xml/parsers xml/sax LIBSUBDIRS= tkinter site-packages test test/output test/data \ Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Tue Nov 18 23:37:15 2008 @@ -13,6 +13,9 @@ Core and Builtins ----------------- +- Issue #4349: sys.path included a non-existent platform directory because of a + faulty Makefile. + - Issue #3327: Don't overallocate in the modules_by_index list. - Issue #1721812: Binary set operations and copy() returned the input type From python-3000-checkins at python.org Tue Nov 18 23:56:20 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Tue, 18 Nov 2008 23:56:20 +0100 (CET) Subject: [Python-3000-checkins] r67271 - python/branches/py3k Message-ID: <20081118225620.0CA441E4002@bag.python.org> Author: amaury.forgeotdarc Date: Tue Nov 18 23:56:19 2008 New Revision: 67271 Log: Blocked revisions 67266 via svnmerge ........ r67266 | amaury.forgeotdarc | 2008-11-18 23:19:37 +0100 (Tue, 18 Nov 2008) | 4 lines #4317: Fix an Array Bounds Read in imageop.rgb2rgb8. Will backport to 2.4. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Wed Nov 19 10:14:31 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Wed, 19 Nov 2008 10:14:31 +0100 (CET) Subject: [Python-3000-checkins] r67281 - in python/branches/py3k: Lib/turtle.py Misc/NEWS Message-ID: <20081119091431.2448A1E4002@bag.python.org> Author: martin.v.loewis Date: Wed Nov 19 10:14:30 2008 New Revision: 67281 Log: Merged revisions 67279 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67279 | martin.v.loewis | 2008-11-19 10:09:41 +0100 (Mi, 19 Nov 2008) | 2 lines Issue #4116: Resolve member name conflict in ScrolledCanvas.__init__ ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/turtle.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/turtle.py ============================================================================== --- python/branches/py3k/Lib/turtle.py (original) +++ python/branches/py3k/Lib/turtle.py Wed Nov 19 10:14:30 2008 @@ -357,7 +357,7 @@ def __init__(self, master, width=500, height=350, canvwidth=600, canvheight=500): TK.Frame.__init__(self, master, width=width, height=height) - self._root = self.winfo_toplevel() + self._rootwindow = self.winfo_toplevel() self.width, self.height = width, height self.canvwidth, self.canvheight = canvwidth, canvheight self.bg = "white" @@ -377,7 +377,7 @@ self.hscroll.grid(padx=1, in_ = self, pady=1, row=1, column=0, rowspan=1, columnspan=1, sticky='news') self.reset() - self._root.bind('', self.onResize) + self._rootwindow.bind('', self.onResize) def reset(self, canvwidth=None, canvheight=None, bg = None): """Ajust canvas and scrollbars according to given canvas size.""" Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 19 10:14:30 2008 @@ -33,6 +33,8 @@ Library ------- +- Issue #4116: Resolve member name conflict in ScrolledCanvas.__init__. + - Issue #4307: The named tuple that ``inspect.getfullargspec()`` returns now uses ``kwonlydefaults`` instead of ``kwdefaults``. From python-3000-checkins at python.org Wed Nov 19 14:55:07 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Wed, 19 Nov 2008 14:55:07 +0100 (CET) Subject: [Python-3000-checkins] r67285 - in python/branches/py3k: Misc/NEWS Tools/msi/msi.py Message-ID: <20081119135507.5BDFB1E4002@bag.python.org> Author: martin.v.loewis Date: Wed Nov 19 14:55:07 2008 New Revision: 67285 Log: Merged revisions 67283 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67283 | martin.v.loewis | 2008-11-19 14:51:44 +0100 (Mi, 19 Nov 2008) | 1 line Issue #4289: Remove Cancel button from AdvancedDlg. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/Tools/msi/msi.py Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 19 14:55:07 2008 @@ -45,6 +45,8 @@ Build ----- +- Issue #4289: Remove Cancel button from AdvancedDlg. + - Issue #1656675: Register a drop handler for .py* files on Windows. Tools/Demos Modified: python/branches/py3k/Tools/msi/msi.py ============================================================================== --- python/branches/py3k/Tools/msi/msi.py (original) +++ python/branches/py3k/Tools/msi/msi.py Wed Nov 19 14:55:07 2008 @@ -717,18 +717,15 @@ ##################################################################### # Advanced Dialog. advanced = PyDialog(db, "AdvancedDlg", x, y, w, h, modal, title, - "CompilePyc", "Next", "Cancel") + "CompilePyc", "Ok", "Ok") advanced.title("Advanced Options for [ProductName]") # A radio group with two options: allusers, justme advanced.checkbox("CompilePyc", 135, 60, 230, 50, 3, - "COMPILEALL", "Compile .py files to byte code after installation", "Next") + "COMPILEALL", "Compile .py files to byte code after installation", "Ok") - c = advanced.next("Finish", "Cancel") + c = advanced.cancel("Ok", "CompilePyc", name="Ok") # Button just has location of cancel button. c.event("EndDialog", "Return") - c = advanced.cancel("Cancel", "CompilePyc") - c.event("SpawnDialog", "CancelDlg") - ##################################################################### # Existing Directory dialog dlg = Dialog(db, "ExistingDirectoryDlg", 50, 30, 200, 80, modal, title, From python-3000-checkins at python.org Wed Nov 19 19:22:42 2008 From: python-3000-checkins at python.org (josiah.carlson) Date: Wed, 19 Nov 2008 19:22:42 +0100 (CET) Subject: [Python-3000-checkins] r67286 - python/branches/py3k/Lib/asyncore.py Message-ID: <20081119182242.4A49E1E4002@bag.python.org> Author: josiah.carlson Date: Wed Nov 19 19:22:41 2008 New Revision: 67286 Log: This fixes issue 4332 for Py3k. Modified: python/branches/py3k/Lib/asyncore.py Modified: python/branches/py3k/Lib/asyncore.py ============================================================================== --- python/branches/py3k/Lib/asyncore.py (original) +++ python/branches/py3k/Lib/asyncore.py Wed Nov 19 19:22:41 2008 @@ -614,6 +614,6 @@ fcntl.fcntl(fd, fcntl.F_SETFL, flags) def set_file(self, fd): - self._fileno = fd self.socket = file_wrapper(fd) + self._fileno = self.socket.fileno() self.add_channel() From lists at cheimes.de Wed Nov 19 19:32:52 2008 From: lists at cheimes.de (Christian Heimes) Date: Wed, 19 Nov 2008 19:32:52 +0100 Subject: [Python-3000-checkins] r67286 - python/branches/py3k/Lib/asyncore.py In-Reply-To: <20081119182242.4A49E1E4002@bag.python.org> References: <20081119182242.4A49E1E4002@bag.python.org> Message-ID: <49245BD4.5010508@cheimes.de> josiah.carlson wrote: > Author: josiah.carlson > Date: Wed Nov 19 19:22:41 2008 > New Revision: 67286 > > Log: > This fixes issue 4332 for Py3k. Please update Misc/NEWS, too! From python-3000-checkins at python.org Wed Nov 19 22:38:49 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 19 Nov 2008 22:38:49 +0100 (CET) Subject: [Python-3000-checkins] r67290 - python/branches/py3k Message-ID: <20081119213849.005481E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 19 22:38:48 2008 New Revision: 67290 Log: Blocked revisions 67287 via svnmerge ........ r67287 | josiah.carlson | 2008-11-19 12:26:12 -0600 (Wed, 19 Nov 2008) | 2 lines Fix for issue 4332 in trunk. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Wed Nov 19 23:05:52 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 19 Nov 2008 23:05:52 +0100 (CET) Subject: [Python-3000-checkins] r67292 - in python/branches/py3k: Lib/test/test_bytes.py Objects/bytearrayobject.c Message-ID: <20081119220552.EACA11E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 19 23:05:52 2008 New Revision: 67292 Log: Merged revisions 67291 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67291 | benjamin.peterson | 2008-11-19 15:49:09 -0600 (Wed, 19 Nov 2008) | 5 lines make sure that bytearray methods return a new bytearray even if there is no change Fixes #4348 Reviewed by Brett ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/test/test_bytes.py python/branches/py3k/Objects/bytearrayobject.c Modified: python/branches/py3k/Lib/test/test_bytes.py ============================================================================== --- python/branches/py3k/Lib/test/test_bytes.py (original) +++ python/branches/py3k/Lib/test/test_bytes.py Wed Nov 19 23:05:52 2008 @@ -738,6 +738,16 @@ b.insert(0, Indexable(ord('A'))) self.assertEqual(b, b'A') + def test_copied(self): + # Issue 4348. Make sure that operations that don't mutate the array + # copy the bytes. + b = bytearray(b'abc') + #self.assertFalse(b is b.replace(b'abc', b'cde', 0)) + + t = bytearray([i for i in range(256)]) + x = bytearray(b'') + self.assertFalse(x is x.translate(t)) + def test_partition_bytearray_doesnt_share_nullstring(self): a, b, c = bytearray(b"x").partition(b"y") self.assertEqual(b, b"") Modified: python/branches/py3k/Objects/bytearrayobject.c ============================================================================== --- python/branches/py3k/Objects/bytearrayobject.c (original) +++ python/branches/py3k/Objects/bytearrayobject.c Wed Nov 19 23:05:52 2008 @@ -1351,7 +1351,7 @@ { register char *input, *output; register const char *table; - register Py_ssize_t i, c, changed = 0; + register Py_ssize_t i, c; PyObject *input_obj = (PyObject*)self; const char *output_start; Py_ssize_t inlen; @@ -1397,14 +1397,8 @@ /* If no deletions are required, use faster code */ for (i = inlen; --i >= 0; ) { c = Py_CHARMASK(*input++); - if (Py_CHARMASK((*output++ = table[c])) != c) - changed = 1; + *output++ = table[c]; } - if (changed || !PyByteArray_CheckExact(input_obj)) - goto done; - Py_DECREF(result); - Py_INCREF(input_obj); - result = input_obj; goto done; } @@ -1419,13 +1413,6 @@ if (trans_table[c] != -1) if (Py_CHARMASK(*output++ = (char)trans_table[c]) == c) continue; - changed = 1; - } - if (!changed && PyByteArray_CheckExact(input_obj)) { - Py_DECREF(result); - Py_INCREF(input_obj); - result = input_obj; - goto done; } /* Fix the size of the resulting string */ if (inlen > 0) @@ -1454,8 +1441,7 @@ !memcmp(target+offset+1, pattern+1, length-2) ) -/* Bytes ops must return a string. */ -/* If the object is subclass of bytes, create a copy */ +/* Bytes ops must return a string, create a copy */ Py_LOCAL(PyByteArrayObject *) return_self(PyByteArrayObject *self) { From python-3000-checkins at python.org Wed Nov 19 23:38:29 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 19 Nov 2008 23:38:29 +0100 (CET) Subject: [Python-3000-checkins] r67294 - in python/branches/py3k: Doc/conf.py Doc/reference/datamodel.rst Doc/tools/sphinxext/download.html Lib/doctest.py Message-ID: <20081119223829.AC9B31E4002@bag.python.org> Author: benjamin.peterson Date: Wed Nov 19 23:38:29 2008 New Revision: 67294 Log: Merged revisions 67243,67245,67277-67278,67289 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67243 | benjamin.peterson | 2008-11-17 15:39:05 -0600 (Mon, 17 Nov 2008) | 1 line a few fixes on the download page ........ r67245 | benjamin.peterson | 2008-11-17 16:05:19 -0600 (Mon, 17 Nov 2008) | 1 line improve __hash__ docs ........ r67277 | skip.montanaro | 2008-11-18 21:35:41 -0600 (Tue, 18 Nov 2008) | 1 line patch from issue 1108 ........ r67278 | georg.brandl | 2008-11-19 01:59:09 -0600 (Wed, 19 Nov 2008) | 2 lines Try to fix problems with verbatim. ........ r67289 | brett.cannon | 2008-11-19 14:29:39 -0600 (Wed, 19 Nov 2008) | 2 lines Ignore .pyc and .pyo files. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/conf.py python/branches/py3k/Doc/reference/datamodel.rst python/branches/py3k/Doc/tools/sphinxext/download.html python/branches/py3k/Lib/doctest.py Modified: python/branches/py3k/Doc/conf.py ============================================================================== --- python/branches/py3k/Doc/conf.py (original) +++ python/branches/py3k/Doc/conf.py Wed Nov 19 23:38:29 2008 @@ -141,6 +141,8 @@ \strong{Python Software Foundation}\\ Email: \email{docs at python.org} } +\let\Verbatim=\OriginalVerbatim +\let\endVerbatim=\endOriginalVerbatim ''' # Documents to append as an appendix to all manuals. Modified: python/branches/py3k/Doc/reference/datamodel.rst ============================================================================== --- python/branches/py3k/Doc/reference/datamodel.rst (original) +++ python/branches/py3k/Doc/reference/datamodel.rst Wed Nov 19 23:38:29 2008 @@ -1202,20 +1202,22 @@ object: dictionary builtin: hash - Called for the key object for dictionary operations, and by the built-in - function :func:`hash`. Should return an integer usable as a hash value - for dictionary operations. The only required property is that objects which - compare equal have the same hash value; it is advised to somehow mix together - (e.g., using exclusive or) the hash values for the components of the object that - also play a part in comparison of objects. + Called by built-in function :func:`hash` and for operations on members of + hashed collections including :class:`set`, :class:`frozenset`, and + :class:`dict`. :meth:`__hash__` should return an integer. The only required + property is that objects which compare equal have the same hash value; it is + advised to somehow mix together (e.g. using exclusive or) the hash values for + the components of the object that also play a part in comparison of objects. If a class does not define an :meth:`__eq__` method it should not define a :meth:`__hash__` operation either; if it defines :meth:`__eq__` but not - :meth:`__hash__`, its instances will not be usable as dictionary keys. If a - class defines mutable objects and implements an :meth:`__eq__` method, it - should not implement :meth:`__hash__`, since the dictionary implementation - requires that a key's hash value is immutable (if the object's hash value - changes, it will be in the wrong hash bucket). + :meth:`__hash__`, its instances will not be usable as items in hashable + collections. If a class defines mutable objects and implements an + :meth:`__eq__` method, it should not implement :meth:`__hash__`, since the + implementation of hashable collections requires that a key's hash value is + immutable (if the object's hash value changes, it will be in the wrong hash + bucket). + User-defined classes have :meth:`__eq__` and :meth:`__hash__` methods by default; with them, all objects compare unequal (except with themselves) Modified: python/branches/py3k/Doc/tools/sphinxext/download.html ============================================================================== --- python/branches/py3k/Doc/tools/sphinxext/download.html (original) +++ python/branches/py3k/Doc/tools/sphinxext/download.html Wed Nov 19 23:38:29 2008 @@ -14,7 +14,7 @@

To download an archive containing all the documents for this version of Python in one of various formats, follow one of links in this table. The numbers -in the table are the size of the download files in Kilobytes.

+in the table are the size of the download files in megabytes.

@@ -54,7 +54,7 @@

Problems

If you have comments or suggestions for the Python documentation, please send -email to docs at python.org.

+email to docs at python.org.

{% endif %} {% endblock %} Modified: python/branches/py3k/Lib/doctest.py ============================================================================== --- python/branches/py3k/Lib/doctest.py (original) +++ python/branches/py3k/Lib/doctest.py Wed Nov 19 23:38:29 2008 @@ -847,12 +847,12 @@ """ if module is None: return True + elif inspect.getmodule(object) is not None: + return module is inspect.getmodule(object) elif inspect.isfunction(object): return module.__dict__ is object.__globals__ elif inspect.isclass(object): return module.__name__ == object.__module__ - elif inspect.getmodule(object) is not None: - return module is inspect.getmodule(object) elif hasattr(object, '__module__'): return module.__name__ == object.__module__ elif isinstance(object, property): From python-3000-checkins at python.org Thu Nov 20 17:21:55 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Thu, 20 Nov 2008 17:21:55 +0100 (CET) Subject: [Python-3000-checkins] r67298 - in python/branches/py3k: Lib/distutils/command/register.py Misc/NEWS Message-ID: <20081120162155.849A81E4002@bag.python.org> Author: martin.v.loewis Date: Thu Nov 20 17:21:55 2008 New Revision: 67298 Log: Issue #4354: Fix distutils register command. Modified: python/branches/py3k/Lib/distutils/command/register.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/distutils/command/register.py ============================================================================== --- python/branches/py3k/Lib/distutils/command/register.py (original) +++ python/branches/py3k/Lib/distutils/command/register.py Thu Nov 20 17:21:55 2008 @@ -15,11 +15,6 @@ from distutils.errors import * from distutils import log -def raw_input(prompt): - sys.stdout.write(prompt) - sys.stdout.flush() - return sys.stdin.readline() - class register(PyPIRCCommand): description = ("register the distribution with the Python package index") @@ -154,7 +149,7 @@ 3. have the server generate a new password for you (and email it to you), or 4. quit Your selection [default 1]: ''', end=' ') - choice = raw_input() + choice = input() if not choice: choice = '1' elif choice not in choices: @@ -163,7 +158,7 @@ if choice == '1': # get the username and password while not username: - username = raw_input('Username: ') + username = input('Username: ') while not password: password = getpass.getpass('Password: ') @@ -182,7 +177,7 @@ print('(the login will be stored in %s)' % self._get_rc_file()) choice = 'X' while choice.lower() not in 'yn': - choice = raw_input('Save your login (y/N)?') + choice = input('Save your login (y/N)?') if not choice: choice = 'n' if choice.lower() == 'y': @@ -193,7 +188,7 @@ data['name'] = data['password'] = data['email'] = '' data['confirm'] = None while not data['name']: - data['name'] = raw_input('Username: ') + data['name'] = input('Username: ') while data['password'] != data['confirm']: while not data['password']: data['password'] = getpass.getpass('Password: ') @@ -204,7 +199,7 @@ data['confirm'] = None print("Password and confirm don't match!") while not data['email']: - data['email'] = raw_input(' EMail: ') + data['email'] = input(' EMail: ') code, result = self.post_to_server(data) if code != 200: print('Server response (%s): %s'%(code, result)) @@ -215,7 +210,7 @@ data = {':action': 'password_reset'} data['email'] = '' while not data['email']: - data['email'] = raw_input('Your email address: ') + data['email'] = input('Your email address: ') code, result = self.post_to_server(data) print('Server response (%s): %s'%(code, result)) @@ -262,7 +257,7 @@ if type(value) not in (type([]), type( () )): value = [value] for value in value: - value = str(value).encode("utf-8") + value = str(value) body.write(sep_boundary) body.write('\nContent-Disposition: form-data; name="%s"'%key) body.write("\n\n") @@ -271,7 +266,7 @@ body.write('\n') # write an extra newline (lurve Macs) body.write(end_boundary) body.write("\n") - body = body.getvalue() + body = body.getvalue().encode("utf-8") # build the Request headers = { Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Nov 20 17:21:55 2008 @@ -33,6 +33,8 @@ Library ------- +- Issue #4354: Fix distutils register command. + - Issue #4116: Resolve member name conflict in ScrolledCanvas.__init__. - Issue #4307: The named tuple that ``inspect.getfullargspec()`` returns now From python-3000-checkins at python.org Thu Nov 20 21:01:58 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Thu, 20 Nov 2008 21:01:58 +0100 (CET) Subject: [Python-3000-checkins] r67299 - in python/branches/py3k: Lib/test/test_super.py Objects/typeobject.c RELNOTES Message-ID: <20081120200158.4B50E1E4002@bag.python.org> Author: barry.warsaw Date: Thu Nov 20 21:01:57 2008 New Revision: 67299 Log: Fix for bug 4360 "SystemError when method has both super() & closure". Patch by amaury.forgeotdarc and reviewed by brett.cannon. Also add release notes about the known problems with the email package. Modified: python/branches/py3k/Lib/test/test_super.py python/branches/py3k/Objects/typeobject.c python/branches/py3k/RELNOTES Modified: python/branches/py3k/Lib/test/test_super.py ============================================================================== --- python/branches/py3k/Lib/test/test_super.py (original) +++ python/branches/py3k/Lib/test/test_super.py Thu Nov 20 21:01:57 2008 @@ -70,6 +70,17 @@ e = E() self.assertEqual(e.cm(), (e, (E, (E, (E, 'A'), 'B'), 'C'), 'D')) + def testSuperWithClosure(self): + # Issue4360: super() did not work in a function that + # contains a closure + class E(A): + def f(self): + def nested(): + self + return super().f() + 'E' + + self.assertEqual(E().f(), 'AE') + def test_main(): support.run_unittest(TestSuper) Modified: python/branches/py3k/Objects/typeobject.c ============================================================================== --- python/branches/py3k/Objects/typeobject.c (original) +++ python/branches/py3k/Objects/typeobject.c Thu Nov 20 21:01:57 2008 @@ -6170,8 +6170,9 @@ assert(PyUnicode_Check(name)); if (!PyUnicode_CompareWithASCIIString(name, "__class__")) { - PyObject *cell = - f->f_localsplus[co->co_nlocals + i]; + Py_ssize_t index = co->co_nlocals + + PyTuple_GET_SIZE(co->co_cellvars) + i; + PyObject *cell = f->f_localsplus[index]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_SystemError, "super(): bad __class__ cell"); Modified: python/branches/py3k/RELNOTES ============================================================================== --- python/branches/py3k/RELNOTES (original) +++ python/branches/py3k/RELNOTES Thu Nov 20 21:01:57 2008 @@ -20,3 +20,10 @@ If you need bsddb3 support in Python 3.0, you can find it here: http://pypi.python.org/pypi/bsddb3 + +* The email package needs quite a bit of work to make it consistent with + respect to bytes and strings. There have been discussions on + email-sig at python.org about where to go with the email package for 3.0, but + this was not resolved in time for 3.0 final. With enough care though, the + email package in Python 3.0 should be about as usable as it is with Python + 2. From python-3000-checkins at python.org Thu Nov 20 21:14:51 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Thu, 20 Nov 2008 21:14:51 +0100 (CET) Subject: [Python-3000-checkins] r67300 - in python/branches/py3k/Lib: io.py test/test_io.py Message-ID: <20081120201451.3734E1E4002@bag.python.org> Author: barry.warsaw Date: Thu Nov 20 21:14:50 2008 New Revision: 67300 Log: Fix for bug 4362 "FileIO object in io module"; Patch by amaury.forgeotdarc. Modified: python/branches/py3k/Lib/io.py python/branches/py3k/Lib/test/test_io.py Modified: python/branches/py3k/Lib/io.py ============================================================================== --- python/branches/py3k/Lib/io.py (original) +++ python/branches/py3k/Lib/io.py Thu Nov 20 21:14:50 2008 @@ -239,8 +239,6 @@ raise ValueError("invalid buffering size") if buffering == 0: if binary: - raw._name = file - raw._mode = mode return raw raise ValueError("can't have unbuffered text I/O") if updating: @@ -252,11 +250,8 @@ else: raise ValueError("unknown mode: %r" % mode) if binary: - buffer.name = file - buffer.mode = mode return buffer text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering) - text.name = file text.mode = mode return text @@ -616,6 +611,10 @@ # that _fileio._FileIO inherits from io.RawIOBase (which would be hard # to do since _fileio.c is written in C). + def __init__(self, name, mode="r", closefd=True): + _fileio._FileIO.__init__(self, name, mode, closefd) + self._name = name + def close(self): _fileio._FileIO.close(self) RawIOBase.close(self) @@ -624,11 +623,6 @@ def name(self): return self._name - # XXX(gb): _FileIO already has a mode property - @property - def mode(self): - return self._mode - class BufferedIOBase(IOBase): @@ -762,6 +756,14 @@ def closed(self): return self.raw.closed + @property + def name(self): + return self.raw.name + + @property + def mode(self): + return self.raw.mode + ### Lower-level APIs ### def fileno(self): @@ -1464,6 +1466,10 @@ def closed(self): return self.buffer.closed + @property + def name(self): + return self.buffer.name + def fileno(self): return self.buffer.fileno() Modified: python/branches/py3k/Lib/test/test_io.py ============================================================================== --- python/branches/py3k/Lib/test/test_io.py (original) +++ python/branches/py3k/Lib/test/test_io.py Thu Nov 20 21:14:50 2008 @@ -1249,6 +1249,9 @@ class MiscIOTest(unittest.TestCase): + def tearDown(self): + support.unlink(support.TESTFN) + def testImport__all__(self): for name in io.__all__: obj = getattr(io, name, None) @@ -1261,6 +1264,34 @@ self.assert_(issubclass(obj, io.IOBase)) + def test_attributes(self): + f = io.open(support.TESTFN, "wb", buffering=0) + self.assertEquals(f.mode, "w") + f.close() + + f = io.open(support.TESTFN, "U") + self.assertEquals(f.name, support.TESTFN) + self.assertEquals(f.buffer.name, support.TESTFN) + self.assertEquals(f.buffer.raw.name, support.TESTFN) + self.assertEquals(f.mode, "U") + self.assertEquals(f.buffer.mode, "r") + self.assertEquals(f.buffer.raw.mode, "r") + f.close() + + f = io.open(support.TESTFN, "w+") + self.assertEquals(f.mode, "w+") + self.assertEquals(f.buffer.mode, "r+") # Does it really matter? + self.assertEquals(f.buffer.raw.mode, "r+") + + g = io.open(f.fileno(), "wb", closefd=False) + self.assertEquals(g.mode, "w") + self.assertEquals(g.raw.mode, "w") + self.assertEquals(g.name, f.fileno()) + self.assertEquals(g.raw.name, f.fileno()) + f.close() + g.close() + + def test_main(): support.run_unittest(IOTest, BytesIOTest, StringIOTest, BufferedReaderTest, BufferedWriterTest, From python-3000-checkins at python.org Thu Nov 20 23:38:21 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 20 Nov 2008 23:38:21 +0100 (CET) Subject: [Python-3000-checkins] r67304 - python/branches/py3k/Doc/c-api/buffer.rst Message-ID: <20081120223821.277851E4002@bag.python.org> Author: benjamin.peterson Date: Thu Nov 20 23:38:20 2008 New Revision: 67304 Log: fix Sphinx table warning Modified: python/branches/py3k/Doc/c-api/buffer.rst Modified: python/branches/py3k/Doc/c-api/buffer.rst ============================================================================== --- python/branches/py3k/Doc/c-api/buffer.rst (original) +++ python/branches/py3k/Doc/c-api/buffer.rst Thu Nov 20 23:38:20 2008 @@ -159,95 +159,95 @@ The following table gives possible values to the *flags* arguments. - +------------------------------+-----------------------------------------------+ - | Flag | Description | - +==============================+===============================================+ - | :cmacro:`PyBUF_SIMPLE` |This is the default flag state. The returned | - | |buffer may or may not have writable memory. | - | |The format will be assumed to be unsigned bytes| - | |. This is a "stand-alone" flag constant. It | - | |never needs to be |'d to the others. The | - | |exporter will raise an error if it cannot | - | |provide such a contiguous buffer of bytes. | - | | | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_WRITABLE` |The returned buffer must be writable. If it is | - | |not writable, then raise an error. | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_STRIDES` |This implies :cmacro:`PyBUF_ND`. The returned | - | |buffer must provide strides information | - | |(i.e. the strides cannot be NULL). This would | - | |be used when the consumer can handle strided, | - | |discontiguous arrays. Handling strides | - | |automatically assumes you can handle shape. The| - | |exporter may raise an error if cannot provide a| - | |strided-only representation of the data | - | |(i.e. without the suboffsets). | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_ND` |The returned buffer must provide shape | - | |information. The memory will be assumed C-style| - | |contiguous (last dimension varies the | - | |fastest). The exporter may raise an error if it| - | |cannot provide this kind of contiguous | - | |buffer. If this is not given then shape will be| - | |*NULL*. | - | | | - | | | - +------------------------------+-----------------------------------------------+ - |:cmacro:`PyBUF_C_CONTIGUOUS` |These flags indicate that the contiguoity | - |:cmacro:`PyBUF_F_CONTIGUOUS` |returned buffer must be respectively, | - |:cmacro:`PyBUF_ANY_CONTIGUOUS`|C-contiguous (last dimension varies the | - | |fastest), Fortran contiguous (first dimension | - | |varies the fastest) or either one. All of | - | |these flags imply :cmacro:`PyBUF_STRIDES` and | - | |guarantee that the strides buffer info | - | |structure will be filled in correctly. | - | | | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_INDIRECT` |This implies :cmacro:`PyBUF_STRIDES`. The | - | |returned buffer must have suboffsets | - | |information (which can be NULL if no suboffsets| - | |are needed). This would be used when the | - | |consumer can handle indirect array referencing | - | |implied by these suboffsets. | - | | | - | | | - | | | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_FORMAT` |The returned buffer must have true format | - | |information if this flag is provided. This | - | |would be used when the consumer is going to be | - | |checking for what 'kind' of data is actually | - | |stored. An exporter should always be able to | - | |provide this information if requested. If | - | |format is not explicitly requested then the | - | |format must be returned as *NULL* (which means | - | |``'B'``, or unsigned bytes) | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_STRIDED` |This is equivalent to ``(PyBUF_STRIDES | | - | |PyBUF_WRITABLE)``. | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_STRIDED_RO` |This is equivalent to ``(PyBUF_STRIDES)``. | - | | | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_RECORDS` |This is equivalent to ``(PyBUF_STRIDES | | - | |PyBUF_FORMAT | PyBUF_WRITABLE)``. | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_RECORDS_RO` |This is equivalent to ``(PyBUF_STRIDES | | - | |PyBUF_FORMAT)``. | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_FULL` |This is equivalent to ``(PyBUF_INDIRECT | | - | |PyBUF_FORMAT | PyBUF_WRITABLE)``. | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_FULL_RO`` |This is equivalent to ``(PyBUF_INDIRECT | | - | |PyBUF_FORMAT)``. | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_CONTIG` |This is equivalent to ``(PyBUF_ND | | - | |PyBUF_WRITABLE)``. | - +------------------------------+-----------------------------------------------+ - | :cmacro:`PyBUF_CONTIG_RO` |This is equivalent to ``(PyBUF_ND)``. | - | | | - +------------------------------+-----------------------------------------------+ + +------------------------------+---------------------------------------------------+ + | Flag | Description | + +==============================+===================================================+ + | :cmacro:`PyBUF_SIMPLE` | This is the default flag state. The returned | + | | buffer may or may not have writable memory. The | + | | format of the data will be assumed to be unsigned | + | | bytes. This is a "stand-alone" flag constant. It | + | | never needs to be '|'d to the others. The exporter| + | | will raise an error if it cannot provide such a | + | | contiguous buffer of bytes. | + | | | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_WRITABLE` | The returned buffer must be writable. If it is | + | | not writable, then raise an error. | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_STRIDES` | This implies :cmacro:`PyBUF_ND`. The returned | + | | buffer must provide strides information (i.e. the | + | | strides cannot be NULL). This would be used when | + | | the consumer can handle strided, discontiguous | + | | arrays. Handling strides automatically assumes | + | | you can handle shape. The exporter can raise an | + | | error if a strided representation of the data is | + | | not possible (i.e. without the suboffsets). | + | | | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_ND` | The returned buffer must provide shape | + | | information. The memory will be assumed C-style | + | | contiguous (last dimension varies the | + | | fastest). The exporter may raise an error if it | + | | cannot provide this kind of contiguous buffer. If | + | | this is not given then shape will be *NULL*. | + | | | + | | | + | | | + +------------------------------+---------------------------------------------------+ + |:cmacro:`PyBUF_C_CONTIGUOUS` | These flags indicate that the contiguity returned | + |:cmacro:`PyBUF_F_CONTIGUOUS` | buffer must be respectively, C-contiguous (last | + |:cmacro:`PyBUF_ANY_CONTIGUOUS`| dimension varies the fastest), Fortran contiguous | + | | (first dimension varies the fastest) or either | + | | one. All of these flags imply | + | | :cmacro:`PyBUF_STRIDES` and guarantee that the | + | | strides buffer info structure will be filled in | + | | correctly. | + | | | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_INDIRECT` | This flag indicates the returned buffer must have | + | | suboffsets information (which can be NULL if no | + | | suboffsets are needed). This can be used when | + | | the consumer can handle indirect array | + | | referencing implied by these suboffsets. This | + | | implies :cmacro:`PyBUF_STRIDES`. | + | | | + | | | + | | | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_FORMAT` | The returned buffer must have true format | + | | information if this flag is provided. This would | + | | be used when the consumer is going to be checking | + | | for what 'kind' of data is actually stored. An | + | | exporter should always be able to provide this | + | | information if requested. If format is not | + | | explicitly requested then the format must be | + | | returned as *NULL* (which means ``'B'``, or | + | | unsigned bytes) | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_STRIDED` | This is equivalent to ``(PyBUF_STRIDES | | + | | PyBUF_WRITABLE)``. | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_STRIDED_RO` | This is equivalent to ``(PyBUF_STRIDES)``. | + | | | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_RECORDS` | This is equivalent to ``(PyBUF_STRIDES | | + | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_RECORDS_RO` | This is equivalent to ``(PyBUF_STRIDES | | + | | PyBUF_FORMAT)``. | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_FULL` | This is equivalent to ``(PyBUF_INDIRECT | | + | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_FULL_RO`` | This is equivalent to ``(PyBUF_INDIRECT | | + | | PyBUF_FORMAT)``. | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_CONTIG` | This is equivalent to ``(PyBUF_ND | | + | | PyBUF_WRITABLE)``. | + +------------------------------+---------------------------------------------------+ + | :cmacro:`PyBUF_CONTIG_RO` | This is equivalent to ``(PyBUF_ND)``. | + | | | + +------------------------------+---------------------------------------------------+ .. cfunction:: void PyBuffer_Release(PyObject *obj, Py_buffer *view) From python-3000-checkins at python.org Thu Nov 20 23:42:44 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 20 Nov 2008 23:42:44 +0100 (CET) Subject: [Python-3000-checkins] r67305 - python/branches/py3k Message-ID: <20081120224244.BCB301E4002@bag.python.org> Author: benjamin.peterson Date: Thu Nov 20 23:42:44 2008 New Revision: 67305 Log: Blocked revisions 67303 via svnmerge ........ r67303 | benjamin.peterson | 2008-11-20 16:06:22 -0600 (Thu, 20 Nov 2008) | 1 line backport r67300 ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Fri Nov 21 00:15:53 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 21 Nov 2008 00:15:53 +0100 (CET) Subject: [Python-3000-checkins] r67306 - in python/branches/py3k/Lib: socket.py test/test_socket.py Message-ID: <20081120231553.1B4091E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Nov 21 00:15:52 2008 New Revision: 67306 Log: Follow-up of r67300: correct a failure in socket.makefile(). SocketIO objects now always have 'name' and 'mode' attributes. Modified: python/branches/py3k/Lib/socket.py python/branches/py3k/Lib/test/test_socket.py Modified: python/branches/py3k/Lib/socket.py ============================================================================== --- python/branches/py3k/Lib/socket.py (original) +++ python/branches/py3k/Lib/socket.py Fri Nov 21 00:15:52 2008 @@ -149,8 +149,6 @@ if buffering == 0: if not binary: raise ValueError("unbuffered streams must be binary") - raw.name = self.fileno() - raw.mode = mode return raw if reading and writing: buffer = io.BufferedRWPair(raw, raw, buffering) @@ -160,11 +158,8 @@ assert writing buffer = io.BufferedWriter(raw, buffering) if binary: - buffer.name = self.fileno() - buffer.mode = mode return buffer text = io.TextIOWrapper(buffer, encoding, newline) - text.name = self.fileno() text.mode = mode return text @@ -230,6 +225,14 @@ def fileno(self): return self._sock.fileno() + @property + def name(self): + return self._sock.fileno() + + @property + def mode(self): + return self._mode + def close(self): if self.closed: return Modified: python/branches/py3k/Lib/test/test_socket.py ============================================================================== --- python/branches/py3k/Lib/test/test_socket.py (original) +++ python/branches/py3k/Lib/test/test_socket.py Fri Nov 21 00:15:52 2008 @@ -848,6 +848,14 @@ def _testClosedAttr(self): self.assert_(not self.cli_file.closed) + def testAttributes(self): + self.assertEqual(self.serv_file.mode, 'r') + self.assertEqual(self.serv_file.name, self.cli_conn.fileno()) + + def _testAttributes(self): + self.assertEqual(self.cli_file.mode, 'w') + self.assertEqual(self.cli_file.name, self.serv_conn.fileno()) + class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): """Repeat the tests from FileObjectClassTestCase with bufsize==0. From python-3000-checkins at python.org Fri Nov 21 00:53:46 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 21 Nov 2008 00:53:46 +0100 (CET) Subject: [Python-3000-checkins] r67308 - in python/branches/py3k: Lib/distutils/command/upload.py Misc/NEWS Message-ID: <20081120235346.84D071E4037@bag.python.org> Author: amaury.forgeotdarc Date: Fri Nov 21 00:53:46 2008 New Revision: 67308 Log: #4338: Fix the distutils "setup.py upload" command. The code still mixed bytes and strings. Reviewed by Martin von Loewis. Modified: python/branches/py3k/Lib/distutils/command/upload.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/distutils/command/upload.py ============================================================================== --- python/branches/py3k/Lib/distutils/command/upload.py (original) +++ python/branches/py3k/Lib/distutils/command/upload.py Fri Nov 21 00:53:46 2008 @@ -7,11 +7,11 @@ from distutils.spawn import spawn from distutils import log from hashlib import md5 -import os +import os, io import socket import platform import configparser -import http.client +import http.client as httpclient import base64 import urllib.parse @@ -113,33 +113,35 @@ open(filename+".asc").read()) # set up the authentication - auth = "Basic " + base64.encodestring(self.username + ":" + self.password).strip() + user_pass = (self.username + ":" + self.password).encode('ascii') + # The exact encoding of the authentication string is debated. + # Anyway PyPI only accepts ascii for both username or password. + auth = "Basic " + base64.encodestring(user_pass).strip().decode('ascii') # Build up the MIME payload for the POST data boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' - sep_boundary = '\n--' + boundary - end_boundary = sep_boundary + '--' - body = io.StringIO() + sep_boundary = b'\n--' + boundary.encode('ascii') + end_boundary = sep_boundary + b'--' + body = io.BytesIO() for key, value in data.items(): + title = '\nContent-Disposition: form-data; name="%s"' % key # handle multiple entries for the same name if type(value) != type([]): value = [value] for value in value: if type(value) is tuple: - fn = ';filename="%s"' % value[0] + title += '; filename="%s"' % value[0] value = value[1] else: - fn = "" - value = str(value) + value = str(value).encode('utf-8') body.write(sep_boundary) - body.write('\nContent-Disposition: form-data; name="%s"'%key) - body.write(fn) - body.write("\n\n") + body.write(title.encode('utf-8')) + body.write(b"\n\n") body.write(value) - if value and value[-1] == '\r': - body.write('\n') # write an extra newline (lurve Macs) + if value and value[-1:] == b'\r': + body.write(b'\n') # write an extra newline (lurve Macs) body.write(end_boundary) - body.write("\n") + body.write(b"\n") body = body.getvalue() self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO) @@ -152,9 +154,9 @@ urllib.parse.urlparse(self.repository) assert not params and not query and not fragments if schema == 'http': - http = http.client.HTTPConnection(netloc) + http = httpclient.HTTPConnection(netloc) elif schema == 'https': - http = http.client.HTTPSConnection(netloc) + http = httpclient.HTTPSConnection(netloc) else: raise AssertionError("unsupported schema "+schema) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 21 00:53:46 2008 @@ -33,6 +33,8 @@ Library ------- +- Issue #4338: Fix distutils upload command. + - Issue #4354: Fix distutils register command. - Issue #4116: Resolve member name conflict in ScrolledCanvas.__init__. From python-3000-checkins at python.org Fri Nov 21 01:11:22 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 21 Nov 2008 01:11:22 +0100 (CET) Subject: [Python-3000-checkins] r67309 - python/branches/py3k/Lib/test/test_gzip.py Message-ID: <20081121001122.933571E400C@bag.python.org> Author: benjamin.peterson Date: Fri Nov 21 01:11:22 2008 New Revision: 67309 Log: fix test_gzip Modified: python/branches/py3k/Lib/test/test_gzip.py Modified: python/branches/py3k/Lib/test/test_gzip.py ============================================================================== --- python/branches/py3k/Lib/test/test_gzip.py (original) +++ python/branches/py3k/Lib/test/test_gzip.py Fri Nov 21 01:11:22 2008 @@ -150,7 +150,7 @@ def test_mode(self): self.test_write() f = gzip.GzipFile(self.filename, 'r') - self.assertEqual(f.myfileobj.mode, 'rb') + self.assertTrue(f.myfileobj.mode.startswith('r')) f.close() def test_1647484(self): From python-3000-checkins at python.org Fri Nov 21 01:17:54 2008 From: python-3000-checkins at python.org (brett.cannon) Date: Fri, 21 Nov 2008 01:17:54 +0100 (CET) Subject: [Python-3000-checkins] r67310 - in python/branches/py3k: Lib/dbm/dumb.py Lib/test/test_dbm_dumb.py Misc/NEWS Message-ID: <20081121001754.36DFA1E4002@bag.python.org> Author: brett.cannon Date: Fri Nov 21 01:17:53 2008 New Revision: 67310 Log: Make dbm.dumb encode strings as UTF-8. Also fix it so it accepts bytes and strings. Closes issue #3799. Modified: python/branches/py3k/Lib/dbm/dumb.py python/branches/py3k/Lib/test/test_dbm_dumb.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/dbm/dumb.py ============================================================================== --- python/branches/py3k/Lib/dbm/dumb.py (original) +++ python/branches/py3k/Lib/dbm/dumb.py Fri Nov 21 01:17:53 2008 @@ -84,6 +84,7 @@ for line in f: line = line.rstrip() key, pos_and_siz_pair = eval(line) + key = key.encode('Latin-1') self._index[key] = pos_and_siz_pair f.close() @@ -110,13 +111,16 @@ f = self._io.open(self._dirfile, 'w') self._chmod(self._dirfile) for key, pos_and_siz_pair in self._index.items(): - f.write("%r, %r\n" % (key, pos_and_siz_pair)) + # Use Latin-1 since it has no qualms with any value in any + # position; UTF-8, though, does care sometimes. + f.write("%r, %r\n" % (key.decode('Latin-1'), pos_and_siz_pair)) f.close() sync = _commit def __getitem__(self, key): - key = key.decode("latin-1") + if isinstance(key, str): + key = key.encode('utf-8') pos, siz = self._index[key] # may raise KeyError f = _io.open(self._datfile, 'rb') f.seek(pos) @@ -161,11 +165,12 @@ f.close() def __setitem__(self, key, val): - if not isinstance(key, bytes): - raise TypeError("keys must be bytes") - key = key.decode("latin-1") # hashable bytes + if isinstance(key, str): + key = key.encode('utf-8') + elif not isinstance(key, (bytes, bytearray)): + raise TypeError("keys must be bytes or strings") if not isinstance(val, (bytes, bytearray)): - raise TypeError("values must be byte strings") + raise TypeError("values must be bytes") if key not in self._index: self._addkey(key, self._addval(val)) else: @@ -191,7 +196,8 @@ # (so that _commit() never gets called). def __delitem__(self, key): - key = key.decode("latin-1") + if isinstance(key, str): + key = key.encode('utf-8') # The blocks used by the associated value are lost. del self._index[key] # XXX It's unclear why we do a _commit() here (the code always @@ -201,14 +207,14 @@ self._commit() def keys(self): - return [key.encode("latin-1") for key in self._index.keys()] + return list(self._index.keys()) def items(self): - return [(key.encode("latin-1"), self[key.encode("latin-1")]) - for key in self._index.keys()] + return [(key, self[key]) for key in self._index.keys()] def __contains__(self, key): - key = key.decode("latin-1") + if isinstance(key, str): + key = key.encode('utf-8') return key in self._index def iterkeys(self): Modified: python/branches/py3k/Lib/test/test_dbm_dumb.py ============================================================================== --- python/branches/py3k/Lib/test/test_dbm_dumb.py (original) +++ python/branches/py3k/Lib/test/test_dbm_dumb.py Fri Nov 21 01:17:53 2008 @@ -19,13 +19,14 @@ pass class DumbDBMTestCase(unittest.TestCase): - _dict = {'0': b'', - 'a': b'Python:', - 'b': b'Programming', - 'c': b'the', - 'd': b'way', - 'f': b'Guido', - 'g': b'intended', + _dict = {b'0': b'', + b'a': b'Python:', + b'b': b'Programming', + b'c': b'the', + b'd': b'way', + b'f': b'Guido', + b'g': b'intended', + '\u00fc'.encode('utf-8') : b'!', } def __init__(self, *args): @@ -35,7 +36,7 @@ f = dumbdbm.open(_fname, 'c') self.assertEqual(list(f.keys()), []) for key in self._dict: - f[key.encode("ascii")] = self._dict[key] + f[key] = self._dict[key] self.read_helper(f) f.close() @@ -73,7 +74,7 @@ def test_dumbdbm_modification(self): self.init_db() f = dumbdbm.open(_fname, 'w') - self._dict['g'] = f[b'g'] = b"indented" + self._dict[b'g'] = f[b'g'] = b"indented" self.read_helper(f) f.close() @@ -105,6 +106,21 @@ self.assertEqual(f[b'1'], b'hello2') f.close() + def test_str_read(self): + self.init_db() + f = dumbdbm.open(_fname, 'r') + self.assertEqual(f['\u00fc'], self._dict['\u00fc'.encode('utf-8')]) + + def test_str_write_contains(self): + self.init_db() + f = dumbdbm.open(_fname) + f['\u00fc'] = b'!' + f.close() + f = dumbdbm.open(_fname, 'r') + self.assert_('\u00fc' in f) + self.assertEqual(f['\u00fc'.encode('utf-8')], + self._dict['\u00fc'.encode('utf-8')]) + def test_line_endings(self): # test for bug #1172763: dumbdbm would die if the line endings # weren't what was expected. @@ -129,16 +145,16 @@ def read_helper(self, f): keys = self.keys_helper(f) for key in self._dict: - self.assertEqual(self._dict[key], f[key.encode("ascii")]) + self.assertEqual(self._dict[key], f[key]) def init_db(self): f = dumbdbm.open(_fname, 'w') for k in self._dict: - f[k.encode("ascii")] = self._dict[k] + f[k] = self._dict[k] f.close() def keys_helper(self, f): - keys = sorted(k.decode("ascii") for k in f.keys()) + keys = sorted(f.keys()) dkeys = sorted(self._dict.keys()) self.assertEqual(keys, dkeys) return keys @@ -155,12 +171,12 @@ if random.random() < 0.2: if k in d: del d[k] - del f[k.encode("ascii")] + del f[k] else: v = random.choice((b'a', b'b', b'c')) * random.randrange(10000) d[k] = v - f[k.encode("ascii")] = v - self.assertEqual(f[k.encode("ascii")], v) + f[k] = v + self.assertEqual(f[k], v) f.close() f = dumbdbm.open(_fname) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 21 01:17:53 2008 @@ -19,7 +19,7 @@ - Issue #3327: Don't overallocate in the modules_by_index list. - Issue #1721812: Binary set operations and copy() returned the input type - instead of the appropriate base type. This was incorrect because set + instead of the appropriate base type. This was incorrect because set subclasses would be created without their __init__() method being called. The corrected behavior brings sets into line with lists and dicts. @@ -33,6 +33,9 @@ Library ------- +- Issue #3799: Fix dbm.dumb to accept strings as well as bytes for keys. String + keys are now written out in UTF-8. + - Issue #4338: Fix distutils upload command. - Issue #4354: Fix distutils register command. From python-3000-checkins at python.org Fri Nov 21 01:25:02 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 21 Nov 2008 01:25:02 +0100 (CET) Subject: [Python-3000-checkins] r67311 - python/branches/py3k/Doc/glossary.rst Message-ID: <20081121002502.946801E4002@bag.python.org> Author: benjamin.peterson Date: Fri Nov 21 01:25:02 2008 New Revision: 67311 Log: a few updates to the gloassary with regards to __future__ and division Modified: python/branches/py3k/Doc/glossary.rst Modified: python/branches/py3k/Doc/glossary.rst ============================================================================== --- python/branches/py3k/Doc/glossary.rst (original) +++ python/branches/py3k/Doc/glossary.rst Fri Nov 21 01:25:02 2008 @@ -74,10 +74,7 @@ ``int(3.15)`` converts the floating point number to the integer ``3``, but in ``3+4.5``, each argument is of a different type (one int, one float), and both must be converted to the same type before they can be added or it - will raise a ``TypeError``. Coercion between two operands can be - performed with the ``coerce`` builtin function; thus, ``3+4.5`` is - equivalent to calling ``operator.add(*coerce(3, 4.5))`` and results in - ``operator.add(3.0, 4.5)``. Without coercion, all arguments of even + will raise a ``TypeError``. Without coercion, all arguments of even compatible types would have to be normalized to the same value by the programmer, e.g., ``float(3)+4.5`` rather than just ``3+4.5``. @@ -180,6 +177,11 @@ A module written in C or C++, using Python's C API to interact with the core and with user code. + floor division + Mathematical division discarding any remainder. The floor division + operator is ``//``. For example, the expression ``11//4`` evaluates to + ``2`` in contrast to the ``2.75`` returned by float true division. + function A series of statements which returns some value to a caller. It can also be passed zero or more arguments which may be used in the execution of @@ -187,16 +189,11 @@ __future__ A pseudo module which programmers can use to enable new language features - which are not compatible with the current interpreter. For example, the - expression ``11/4`` currently evaluates to ``2``. If the module in which - it is executed had enabled *true division* by executing:: - - from __future__ import division - - the expression ``11/4`` would evaluate to ``2.75``. By importing the - :mod:`__future__` module and evaluating its variables, you can see when a - new feature was first added to the language and when it will become the - default:: + which are not compatible with the current interpreter. + + By importing the :mod:`__future__` module and evaluating its variables, + you can see when a new feature was first added to the language and when it + becomes the default:: >>> import __future__ >>> __future__.division @@ -270,19 +267,7 @@ be created if a different value has to be stored. They play an important role in places where a constant hash value is needed, for example as a key in a dictionary. - - integer division - Mathematical division discarding any remainder. For example, the - expression ``11/4`` currently evaluates to ``2`` in contrast to the - ``2.75`` returned by float division. Also called *floor division*. When - dividing two integers the outcome will always be another integer (having - the floor function applied to it). However, if the operands types are - different, one of them will be converted to the other's type. For - example, an integer divided by a float will result in a float value, - possibly with a decimal fraction. Integer division can be forced by using - the ``//`` operator instead of the ``/`` operator. See also - :term:`__future__`. - + interactive Python has an interactive interpreter which means you can enter statements and expressions at the interpreter prompt, immediately From python-3000-checkins at python.org Fri Nov 21 02:18:22 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 21 Nov 2008 02:18:22 +0100 (CET) Subject: [Python-3000-checkins] r67312 - in python/branches/py3k: Include/patchlevel.h Lib/distutils/__init__.py Lib/idlelib/idlever.py Lib/pydoc_topics.py Misc/NEWS Misc/RPM/python-3.0.spec README Message-ID: <20081121011822.430D81E4002@bag.python.org> Author: barry.warsaw Date: Fri Nov 21 02:18:21 2008 New Revision: 67312 Log: Bump to 3.0rc3 Modified: python/branches/py3k/Include/patchlevel.h python/branches/py3k/Lib/distutils/__init__.py python/branches/py3k/Lib/idlelib/idlever.py python/branches/py3k/Lib/pydoc_topics.py python/branches/py3k/Misc/NEWS python/branches/py3k/Misc/RPM/python-3.0.spec python/branches/py3k/README Modified: python/branches/py3k/Include/patchlevel.h ============================================================================== --- python/branches/py3k/Include/patchlevel.h (original) +++ python/branches/py3k/Include/patchlevel.h Fri Nov 21 02:18:21 2008 @@ -20,10 +20,10 @@ #define PY_MINOR_VERSION 0 #define PY_MICRO_VERSION 0 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_GAMMA -#define PY_RELEASE_SERIAL 2 +#define PY_RELEASE_SERIAL 3 /* Version as a string */ -#define PY_VERSION "3.0rc2+" +#define PY_VERSION "3.0rc3" /*--end constants--*/ /* Subversion Revision number of this file (not of the repository) */ Modified: python/branches/py3k/Lib/distutils/__init__.py ============================================================================== --- python/branches/py3k/Lib/distutils/__init__.py (original) +++ python/branches/py3k/Lib/distutils/__init__.py Fri Nov 21 02:18:21 2008 @@ -20,5 +20,5 @@ # #--start constants-- -__version__ = "3.0rc2" +__version__ = "3.0rc3" #--end constants-- Modified: python/branches/py3k/Lib/idlelib/idlever.py ============================================================================== --- python/branches/py3k/Lib/idlelib/idlever.py (original) +++ python/branches/py3k/Lib/idlelib/idlever.py Fri Nov 21 02:18:21 2008 @@ -1 +1 @@ -IDLE_VERSION = "3.0rc2" +IDLE_VERSION = "3.0rc3" Modified: python/branches/py3k/Lib/pydoc_topics.py ============================================================================== --- python/branches/py3k/Lib/pydoc_topics.py (original) +++ python/branches/py3k/Lib/pydoc_topics.py Fri Nov 21 02:18:21 2008 @@ -1,4 +1,4 @@ -# Autogenerated by Sphinx on Thu Nov 6 20:34:10 2008 +# Autogenerated by Sphinx on Thu Nov 20 20:13:48 2008 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:\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 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 a sequence 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* 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(In the current implementation, the syntax for targets is taken to be\nthe same as for expressions, and invalid syntax is rejected during the\ncode generation phase, causing less 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 ::= target augop (expression_list | yield_expression)\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 initial value is\nretrieved with a ``getattr()`` and the result is assigned with a\n``setattr()``. Notice that the two methods do not necessarily refer\nto the same variable. When ``getattr()`` refers to a class variable,\n``setattr()`` still writes to an instance variable. For example:\n\n class A:\n x = 3 # class variable\n a = A()\n a.x += 1 # writes a.x as 4 leaving A.x as 3\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', @@ -18,12 +18,12 @@ 'callable-types': '\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', '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\nNote: An implementation may provide builtin functions whose positional\n parameters do not have names, even if they are \'named\' for the\n purpose of documentation, and which therefore cannot be supplied by\n keyword. In CPython, this is the case for functions implemented in\n C that use ``PyArg_ParseTuple`` to parse 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 a sequence. Elements from this\nsequence 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 ::= "(" [expression_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. It first evaluates the\ninheritance list, if present. Each item in the inheritance list\nshould evaluate to a class object or class type which allows\nsubclassing. The class\'s suite is then executed in a new execution\nframe (see section *Naming and binding*), using a newly created local\nnamespace and the original global namespace. (Usually, the suite\ncontains only function definitions.) When the class\'s suite finishes\nexecution, its execution frame is discarded but its local namespace is\nsaved. [4] A class object is then created using the inheritance list\nfor the base classes and the saved local namespace for the attribute\ndictionary. The class name is bound to this class object in the\noriginal local namespace.\n\nClasses can also be decorated; as with 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\n**Programmer\'s note:** Variables defined in the class definition are\nclass variables; they are shared by instances. Instance variables can\nbe set in a method with ``self.name = value``. Both class and\ninstance variables are accessible through the notation\n"``self.name``", and an instance variable hides a class variable with\nthe same name when accessed in this way. Class variables can be used\nas defaults for instance variables, but using mutable values there can\nlead to unexpected results. Descriptors can be used to create\ninstance variables with different implementation details.\n\nSee also:\n\n **PEP 3129** - Class Decorators\n\nClass definitions, like function definitions, may be wrapped by one or\nmore *decorator* expressions. The evaluation rules for the decorator\nexpressions are the same as for functions. The result must be a class\nobject, which is then bound to the class name.\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack only if there\n is no ``finally`` clause that negates the exception.\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-builtin\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* 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, ``cmp([1,2,x], [1,2,y])`` returns\n the same as ``cmp(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 their sorted\n ``(key, value)`` lists compare equal. [4] Outcomes other than\n equality are resolved consistently, but are not otherwise defined.\n [5]\n\n* Most other objects of builtin 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\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.\n\nFor the list and tuple types, ``x in y`` is true if and only if there\nexists an index *i* such that ``x == y[i]`` is true.\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__()`` and do\ndefine ``__getitem__()``, ``x in y`` is true if and only if there is a\nnon-negative 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. [6]\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-builtin\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, ``cmp([1,2,x], [1,2,y])`` returns\n the same as ``cmp(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 their sorted\n ``(key, value)`` lists compare equal. [4] Outcomes other than\n equality are resolved consistently, but are not otherwise defined.\n [5]\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 builtin 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\nnumberic 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`` equivalent to ``any(x is e or x == e for val e\nin y)``.\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__()`` and do\ndefine ``__getitem__()``, ``x in y`` is true if and only if there is a\nnon-negative 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. [6]\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., ``range(3)`` returns the list ``[0, 1, 2]``.\n\nWarning: 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 N = None\n del N\n\nThat means that you have to assign the exception to a different name\nif you want to be able to refer to it after the except clause. The\nreason for this is that with the traceback attached to them,\nexceptions will form a reference cycle with the stack frame, keeping\nall locals in that frame alive until the next garbage collection\noccurs.\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\nof: ``exc_type``, the exception class; ``exc_value``, the exception\ninstance; ``exc_traceback``, a traceback object (see section *The\nstandard type hierarchy*) identifying the point in the program where\nthe exception occurred. ``sys.exc_info()`` values are restored to\ntheir previous values (before the call) when returning from a function\nthat 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 lost. The exception information is not available to the\nprogram during execution 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" expression ["as" target] ":" suite\n\nThe execution of the ``with`` statement proceeds as follows:\n\n1. The context expression is evaluated to obtain a context manager.\n\n2. The context manager\'s ``__enter__()`` method is invoked.\n\n3. 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 5 below.\n\n4. The suite is executed.\n\n5. 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\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 ["(" [argument_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 that 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 *Expression lists*. Note that the lambda form is\nmerely a shorthand for a simplified function definition; a function\ndefined in a "``def``" statement can be passed around or assigned to\nanother name just like a function defined by a lambda form. The\n"``def``" form is actually more powerful since it allows the execution\nof multiple statements 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\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 ::= "(" [expression_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. It first evaluates the\ninheritance list, if present. Each item in the inheritance list\nshould evaluate to a class object or class type which allows\nsubclassing. The class\'s suite is then executed in a new execution\nframe (see section *Naming and binding*), using a newly created local\nnamespace and the original global namespace. (Usually, the suite\ncontains only function definitions.) When the class\'s suite finishes\nexecution, its execution frame is discarded but its local namespace is\nsaved. [4] A class object is then created using the inheritance list\nfor the base classes and the saved local namespace for the attribute\ndictionary. The class name is bound to this class object in the\noriginal local namespace.\n\nClasses can also be decorated; as with 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\n**Programmer\'s note:** Variables defined in the class definition are\nclass variables; they are shared by instances. Instance variables can\nbe set in a method with ``self.name = value``. Both class and\ninstance variables are accessible through the notation\n"``self.name``", and an instance variable hides a class variable with\nthe same name when accessed in this way. Class variables can be used\nas defaults for instance variables, but using mutable values there can\nlead to unexpected results. Descriptors can be used to create\ninstance variables with different implementation details.\n\nSee also:\n\n **PEP 3129** - Class Decorators\n\nClass definitions, like function definitions, may be wrapped by one or\nmore *decorator* expressions. The evaluation rules for the decorator\nexpressions are the same as for functions. The result must be a class\nobject, which is then bound to the class name.\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack only if there\n is no ``finally`` clause that negates the exception.\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', - '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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n 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.__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\nobject.__hash__(self)\n\n Called for the key object for dictionary operations, and by the\n built-in function ``hash()``. Should return an integer usable as a\n hash value for dictionary operations. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g., using exclusive or) the hash\n values for the components of the object that also play a part in\n 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 dictionary keys. If a class defines mutable objects and\n implements an ``__eq__()`` method, it should not implement\n ``__hash__()``, since the dictionary implementation requires that a\n key\'s hash value is immutable (if the object\'s hash value changes,\n 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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n 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.__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\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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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``\n(undocumented) and ``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\n``pdb.py`` can also be invoked as a script to debug other scripts.\nFor example:\n\n python -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\nTypical 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[, locals]])\n\n Execute the *statement* (given as a string) under debugger control.\n The debugger prompt appears before any code is executed; you can\n set breakpoints and type ``continue``, or you can step through the\n statement using ``step`` or ``next`` (all these commands are\n explained below). The optional *globals* and *locals* arguments\n specify the environment in which the code is executed; by default\n the dictionary of the module ``__main__`` is used. (See the\n explanation of the built-in ``exec()`` or ``eval()`` functions.)\n\npdb.runeval(expression[, globals[, locals]])\n\n Evaluate the *expression* (given as a string) under debugger\n control. When ``runeval()`` returns, it returns the value of the\n expression. Otherwise this function is similar to ``run()``.\n\npdb.runcall(function[, argument, ...])\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])\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', '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 that 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\nIt is illegal to delete a name from the local namespace if it occurs\nas a free variable in a nested block.\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', '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', @@ -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., ``range(3)`` returns the list ``[0, 1, 2]``.\n\nWarning: 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 ::= (identifier | integer) ("." attribute_name | "[" element_index "]")*\n attribute_name ::= identifier\n element_index ::= integer\n conversion ::= "r" | "s"\n format_spec ::= \n\nIn less formal terms, the replacement field starts with a\n*field_name*, which can either be a number (for a positional\nargument), or an identifier (for keyword arguments). Following this\nis an optional *conversion* field, which is preceded by an exclamation\npoint ``\'!\'``, and a *format_spec*, which is preceded by a colon\n``\':\'``.\n\nThe *field_name* itself begins with either a number or a keyword. If\nit\'s a number, it refers to a positional argument, and if it\'s a\nkeyword it refers to a named keyword argument. This can be followed\nby any 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\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\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\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 it\'s\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\nFor example, suppose you wanted to have a replacement field whose\nfield width is determined by another variable:\n\n "A man with two {0:{1}}".format("noses", 10)\n\nThis would first evaluate the inner replacement field, making the\nformat string effectively:\n\n "A man with two {0:10}"\n\nThen the outer replacement field would be evaluated, producing:\n\n "noses "\n\nWhich is substituted into the string, yielding:\n\n "A man with two noses "\n\n(The extra space is because we specified a field width of 10, and\nbecause left alignment is the default for strings.)\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\nbuiltin ``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.\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" | "x" | "X" | "%"\n\nThe *fill* character can be any character other than \'}\' (which\nsignifies the end of the field). The presence of a fill character is\nsignaled by the *next* character, which must be one of the alignment\noptions. If the second character of *format_spec* is not a valid\nalignment option, then it is assumed that both the fill character and\nthe alignment option are absent.\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.) |\n +-----------+------------------------------------------------------------+\n | ``\'>\'`` | Forces the field to be right-aligned within the available |\n | | space. |\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 is only valid for integers, and only for binary,\noctal, or hexadecimal output. If present, it specifies that the\noutput will be prefixed by ``\'0b\'``, ``\'0o\'``, or ``\'0x\'``,\nrespectively.\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 ignored for integer values.\n\nFinally, the *type* determines how the data should be presented.\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\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\'``. |\n +-----------+------------------------------------------------------------+\n | ``\'g\'`` | General format. This prints the number as a fixed-point |\n | | number, unless the number is too large, in which case it |\n | | switches to ``\'e\'`` exponent notation. Infinity and NaN |\n | | values are formatted as ``inf``, ``-inf`` and ``nan``, |\n | | respectively. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets to 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 | The same as ``\'g\'``. |\n +-----------+------------------------------------------------------------+\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 ::= (identifier | integer) ("." attribute_name | "[" element_index "]")*\n attribute_name ::= identifier\n element_index ::= integer\n conversion ::= "r" | "s" | "a"\n format_spec ::= \n\nIn less formal terms, the replacement field starts with a\n*field_name*, which can either be a number (for a positional\nargument), or an identifier (for keyword arguments). Following this\nis an optional *conversion* field, which is preceded by an exclamation\npoint ``\'!\'``, and a *format_spec*, which is preceded by a colon\n``\':\'``.\n\nThe *field_name* itself begins with either a number or a keyword. If\nit\'s a number, it refers to a positional argument, and if it\'s a\nkeyword it refers to a named keyword argument. This can be followed\nby any 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\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\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\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 it\'s\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\nFor example, suppose you wanted to have a replacement field whose\nfield width is determined by another variable:\n\n "A man with two {0:{1}}".format("noses", 10)\n\nThis would first evaluate the inner replacement field, making the\nformat string effectively:\n\n "A man with two {0:10}"\n\nThen the outer replacement field would be evaluated, producing:\n\n "noses "\n\nWhich is substituted into the string, yielding:\n\n "A man with two noses "\n\n(The extra space is because we specified a field width of 10, and\nbecause left alignment is the default for strings.)\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\nbuiltin ``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.\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" | "x" | "X" | "%"\n\nThe *fill* character can be any character other than \'}\' (which\nsignifies the end of the field). The presence of a fill character is\nsignaled by the *next* character, which must be one of the alignment\noptions. If the second character of *format_spec* is not a valid\nalignment option, then it is assumed that both the fill character and\nthe alignment option are absent.\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.) |\n +-----------+------------------------------------------------------------+\n | ``\'>\'`` | Forces the field to be right-aligned within the available |\n | | space. |\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 is only valid for integers, and only for binary,\noctal, or hexadecimal output. If present, it specifies that the\noutput will be prefixed by ``\'0b\'``, ``\'0o\'``, or ``\'0x\'``,\nrespectively.\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 ignored for integer values.\n\nFinally, the *type* determines how the data should be presented.\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\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\'``. |\n +-----------+------------------------------------------------------------+\n | ``\'g\'`` | General format. This prints the number as a fixed-point |\n | | number, unless the number is too large, in which case it |\n | | switches to ``\'e\'`` exponent notation. Infinity and NaN |\n | | values are formatted as ``inf``, ``-inf`` and ``nan``, |\n | | respectively. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets to 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 | The same as ``\'g\'``. |\n +-----------+------------------------------------------------------------+\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 ["(" [argument_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 that 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 *Expression lists*. Note that the lambda form is\nmerely a shorthand for a simplified function definition; a function\ndefined in a "``def``" statement can be passed around or assigned to\nanother name just like a function defined by a lambda form. The\n"``def``" form is actually more powerful since it allows the execution\nof multiple statements 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', '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(The current implementation does not enforce the latter two\nrestrictions, but programs should not abuse this freedom, as future\nimplementations may enforce them or silently change the meaning of the\nprogram.)\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 builtin ``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);\n applications should not expect to define additional names using\n this convention. The set of names of this class defined by Python\n may be extended in future versions. See section *Special method\n names*.\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', @@ -42,7 +42,7 @@ '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\nfirst form (without ``from``) repeats these steps for each identifier\nin the list. The form with ``from`` performs step (1) once, and then\nperforms step (2) repeatedly.\n\nIn this context, to "initialize" a built-in or extension module means\nto call an initialization function that the module must provide for\nthe purpose (in the reference implementation, the function\'s name is\nobtained by prepending string "init" to the module\'s name); to\n"initialize" a Python-coded module means to execute the module\'s body.\n\nThe system maintains a table of modules that have been or are being\ninitialized, indexed by module name. This table is accessible as\n``sys.modules``. When a module name is found in this table, step (1)\nis finished. If not, a search for a module definition is started.\nWhen a module is found, it is loaded. Details of the module searching\nand loading process are implementation and platform specific. It\ngenerally involves searching for a "built-in" module with the given\nname and then searching a list of locations given as ``sys.path``.\n\nIf a built-in module is found, its built-in initialization code is\nexecuted and step (1) is finished. If no matching file is found,\n``ImportError`` is raised. If a file is found, it is parsed, yielding\nan executable code block. If a syntax error occurs, ``SyntaxError``\nis raised. Otherwise, an empty module of the given name is created\nand inserted in the module table, and then the code block is executed\nin the context of this module. Exceptions during this execution\nterminate step (1).\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. If the\nwild card form of import --- ``import *`` --- is used in a function\nand the function contains or is a nested block with free variables,\nthe compiler will raise a ``SyntaxError``.\n\n**Hierarchical module names:** when the module names contains one or\nmore dots, the module search path is carried out differently. The\nsequence of identifiers up to the last dot is used to find a\n"package"; the final identifier is then searched inside the package.\nA package is generally a subdirectory of a directory on ``sys.path``\nthat has a file ``__init__.py``.\n\nThe built-in function ``__import__()`` is provided to support\napplications that determine which modules need to be loaded\ndynamically; refer to *Built-in Functions* for additional information.\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 builtin 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', - '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-builtin\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* 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, ``cmp([1,2,x], [1,2,y])`` returns\n the same as ``cmp(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 their sorted\n ``(key, value)`` lists compare equal. [4] Outcomes other than\n equality are resolved consistently, but are not otherwise defined.\n [5]\n\n* Most other objects of builtin 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\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.\n\nFor the list and tuple types, ``x in y`` is true if and only if there\nexists an index *i* such that ``x == y[i]`` is true.\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__()`` and do\ndefine ``__getitem__()``, ``x in y`` is true if and only if there is a\nnon-negative 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. [6]\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-builtin\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, ``cmp([1,2,x], [1,2,y])`` returns\n the same as ``cmp(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 their sorted\n ``(key, value)`` lists compare equal. [4] Outcomes other than\n equality are resolved consistently, but are not otherwise defined.\n [5]\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 builtin 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\nnumberic 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`` equivalent to ``any(x is e or x == e for val e\nin y)``.\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__()`` and do\ndefine ``__getitem__()``, ``x in y`` is true if and only if there is a\nnon-negative 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. [6]\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': '\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', 'lists': '\nList displays\n*************\n\nA list display is a possibly empty series of expressions enclosed in\nsquare brackets:\n\n list_display ::= "[" [expression_list | comprehension] "]"\n\nA list display yields a new list object, the contents being specified\nby either a list of expressions or a comprehension. When a comma-\nseparated list of expressions is supplied, its elements are evaluated\nfrom left to right and placed into the list object in that order.\nWhen a comprehension is supplied, the list is constructed from the\nelements resulting from the comprehension.\n', @@ -59,7 +59,7 @@ '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', '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. If there are no base\n classes, this will be an empty tuple.\n\nclass.__name__\n\n The name of the class or type.\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] To format only a tuple you should therefore provide a singleton\n tuple whose only element is the tuple to be formatted.\n\n[5] These numbers are fairly arbitrary. They are intended to avoid\n printing endless strings of meaningless digits without hampering\n correct use and without having to know the exact precision of\n floating point values on a particular machine.\n\n[6] The advantage of leaving the newline on is that returning an empty\n string is then an unambiguous EOF indication. It is also possible\n (in cases where it might matter, for example, if you want to make\n an exact copy of a file while scanning its lines) to tell whether\n the last line of a file ended in a newline or not (yes this\n happens!).\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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n 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.__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\nobject.__hash__(self)\n\n Called for the key object for dictionary operations, and by the\n built-in function ``hash()``. Should return an integer usable as a\n hash value for dictionary operations. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g., using exclusive or) the hash\n values for the components of the object that also play a part in\n 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 dictionary keys. If a class defines mutable objects and\n implements an ``__eq__()`` method, it should not implement\n ``__hash__()``, since the dictionary implementation requires that a\n key\'s hash value is immutable (if the object\'s hash value changes,\n 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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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 builtin 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 list must be\n returned.\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 the\nclass dictionary of another class, known as the *owner* class. 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, A)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. Normally, data\ndescriptors define both ``__get__()`` and ``__set__()``, while non-\ndata descriptors have just the ``__get__()`` method. Data descriptors\nalways override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances. [2]\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* 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* 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__*.\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()``. A class\ndefinition is read into a separate namespace and the value of class\nname is bound to the result of ``type(name, bases, dict)``.\n\nWhen the class definition is read, if a callable ``metaclass`` keyword\nargument is passed after the bases in the class definition, the\ncallable given will be called instead of ``type()``. If other keyword\narguments are passed, they will also be passed to the metaclass. This\nallows classes or functions to be written which monitor or alter the\nclass creation process:\n\n* Modifying the class dictionary prior to the class being created.\n\n* Returning an instance of another class -- essentially performing the\n role of a factory function.\n\nThese steps will have to be performed in the metaclass\'s ``__new__()``\nmethod -- ``type.__new__()`` can then be called from this method to\ncreate a class with different properties. This example adds a new\nelement to the class dictionary before creating the class:\n\n class metacls(type):\n def __new__(mcs, name, bases, dict):\n dict[\'foo\'] = \'metacls was here\'\n return type.__new__(mcs, name, bases, dict)\n\nYou can of course also override other class methods (or add new\nmethods); for example defining a custom ``__call__()`` method in the\nmetaclass allows custom behavior when the class is called, e.g. not\nalways creating a new instance.\n\nIf the metaclass has a ``__prepare__()`` attribute (usually\nimplemented as a class or static method), it is called before the\nclass body is evaluated with the name of the class and a tuple of its\nbases for arguments. It should return an object that supports the\nmapping interface that will be used to store the namespace of the\nclass. The default is a plain dictionary. This could be used, for\nexample, to keep track of the order that class attributes are declared\nin by returning an ordered dictionary.\n\nThe appropriate metaclass is determined by the following precedence\nrules:\n\n* If the ``metaclass`` keyword argument is based with the bases, it is\n used.\n\n* Otherwise, if there is at least one base class, its metaclass is\n used.\n\n* Otherwise, the default metaclass (``type``) is used.\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored including logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\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()`` builtin 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()`` builtin will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects should\n normally only provide ``__reversed__()`` if they do not support the\n sequence protocol and an efficient implementation of reverse\n iteration is possible.\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\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. [3] 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 operations (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\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 operation falls back to the normal methods. For instance, to\n evaluate the expression ``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(object):\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 may also bypass the\n``__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] A descriptor can define any combination of ``__get__()``,\n ``__set__()`` and ``__delete__()``. If it does not define\n ``__get__()``, then accessing the attribute even on an instance\n will return the descriptor object itself. If the descriptor\n defines ``__set__()`` and/or ``__delete__()``, it is a data\n descriptor; if it defines neither, it is a non-data descriptor.\n\n[3] 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', + '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. For this reason, ``__del__()`` methods should do\n the absolute minimum needed to maintain external invariants.\n Starting with version 1.5, Python guarantees that globals whose\n name begins with a single underscore are deleted from their\n module before other globals are deleted; if no other references\n to such globals exist, this may help in assuring that imported\n modules are still available at the time when the ``__del__()``\n 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.__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\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 ``id(x)``.\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 overrrides ``__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\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 (see\n below) and ``True`` is returned when the length is not zero. If a\n class defines neither ``__len__()`` nor ``__bool__()``, all its\n instances 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 builtin 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 list must be\n returned.\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 the\nclass dictionary of another class, known as the *owner* class. 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, A)``.\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. Normally, data\ndescriptors define both ``__get__()`` and ``__set__()``, while non-\ndata descriptors have just the ``__get__()`` method. Data descriptors\nalways override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances. [2]\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* 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* 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__*.\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()``. A class\ndefinition is read into a separate namespace and the value of class\nname is bound to the result of ``type(name, bases, dict)``.\n\nWhen the class definition is read, if a callable ``metaclass`` keyword\nargument is passed after the bases in the class definition, the\ncallable given will be called instead of ``type()``. If other keyword\narguments are passed, they will also be passed to the metaclass. This\nallows classes or functions to be written which monitor or alter the\nclass creation process:\n\n* Modifying the class dictionary prior to the class being created.\n\n* Returning an instance of another class -- essentially performing the\n role of a factory function.\n\nThese steps will have to be performed in the metaclass\'s ``__new__()``\nmethod -- ``type.__new__()`` can then be called from this method to\ncreate a class with different properties. This example adds a new\nelement to the class dictionary before creating the class:\n\n class metacls(type):\n def __new__(mcs, name, bases, dict):\n dict[\'foo\'] = \'metacls was here\'\n return type.__new__(mcs, name, bases, dict)\n\nYou can of course also override other class methods (or add new\nmethods); for example defining a custom ``__call__()`` method in the\nmetaclass allows custom behavior when the class is called, e.g. not\nalways creating a new instance.\n\nIf the metaclass has a ``__prepare__()`` attribute (usually\nimplemented as a class or static method), it is called before the\nclass body is evaluated with the name of the class and a tuple of its\nbases for arguments. It should return an object that supports the\nmapping interface that will be used to store the namespace of the\nclass. The default is a plain dictionary. This could be used, for\nexample, to keep track of the order that class attributes are declared\nin by returning an ordered dictionary.\n\nThe appropriate metaclass is determined by the following precedence\nrules:\n\n* If the ``metaclass`` keyword argument is based with the bases, it is\n used.\n\n* Otherwise, if there is at least one base class, its metaclass is\n used.\n\n* Otherwise, the default metaclass (``type``) is used.\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored including logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\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()`` builtin 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()`` builtin will fall back to using the sequence\n protocol (``__len__()`` and ``__getitem__()``). Objects should\n normally only provide ``__reversed__()`` if they do not support the\n sequence protocol and an efficient implementation of reverse\n iteration is possible.\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\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. [3] 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 operations (``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``,\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 operation falls back to the normal methods. For instance, to\n evaluate the expression ``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(object):\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 may also bypass the\n``__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] A descriptor can define any combination of ``__get__()``,\n ``__set__()`` and ``__delete__()``. If it does not define\n ``__get__()``, then accessing the attribute even on an instance\n will return the descriptor object itself. If the descriptor\n defines ``__set__()`` and/or ``__delete__()``, it is a data\n descriptor; if it defines neither, it is a non-data descriptor.\n\n[3] 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. Note that none of\nthese methods take keyword arguments.\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 only its first character\n capitalized.\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 occurrences of substring *sub* in the range\n [*start*, *end*]. Optional arguments *start* and *end* are\n interpreted as in slice notation.\n\nstr.encode([encoding[, errors]])\n\n Return an encoded version of the string. Default encoding is the\n current default string encoding. *errors* may be given to set a\n different error handling scheme. The default for *errors* is\n ``\'strict\'``, meaning that encoding errors raise a\n ``UnicodeError``. Other possible values are ``\'ignore\'``,\n ``\'replace\'``, ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and\n any other name registered via ``codecs.register_error()``, see\n section *Codec Base Classes*. For a list of possible encodings, see\n section *Standard Encodings*.\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 one 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 range [*start*, *end*].\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\nstr.format(format_string, *args, **kwargs)\n\n Perform a string formatting operation. The *format_string*\n argument can contain literal text or replacement fields delimited\n by braces ``{}``. Each replacement field contains either the\n numeric index of a positional argument, or the name of a keyword\n argument. Returns a copy of *format_string* where each replacement\n field is replaced with the string value of the corresponding\n 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.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.\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.\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 include digit characters, and all characters that that\n can be used to form decimal-radix numbers, e.g. U+0660, ARABIC-\n 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.\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 in the string are lowercase and\n 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.\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.\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 in the string are uppercase and\n there is at least one cased character, false otherwise.\n\nstr.join(seq)\n\n Return a string which is the concatenation of the strings in the\n sequence *seq*. A ``TypeError`` will be raised if there are any\n non-string values in *seq*, including ``bytes`` objects. The\n 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\n ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string converted to lowercase.\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\nstr.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]. Optional\n arguments *start* and *end* are interpreted as in slice notation.\n 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\n ``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[, maxsplit]])\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[, maxsplit]])\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, then there is no limit\n 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.\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.\n\nstr.title()\n\n Return a titlecased version of the string: words start with\n uppercase characters, all remaining cased characters are lowercase.\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\n ordinals(integers) to Unicode ordinals, strings or ``None``.\n Unmapped characters are left untouched. Characters mapped to\n ``None`` are deleted.\n\n A *map* for ``translate()`` is usually best created by\n ``str.maketrans()``.\n\n You can use the ``maketrans()`` helper function in the ``string``\n module to create a translation table. For string objects, set the\n *table* argument to ``None`` for translations that only delete\n characters:\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 converted to uppercase.\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 ``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" | "R"\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"\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\nString literals may optionally be prefixed with a letter ``\'r\'`` or\n``\'R\'``; such strings are called *raw strings* and treat backslashes\nas literal characters. As a result, ``\'\\U\'`` and ``\'\\u\'`` escapes in\nraw strings are not treated specially.\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\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 | |\n| | Unicode database | |\n+-------------------+-----------------------------------+---------+\n| ``\\uxxxx`` | Character with 16-bit hex value | (4) |\n| | *xxxx* | |\n+-------------------+-----------------------------------+---------+\n| ``\\Uxxxxxxxx`` | Character with 32-bit hex value | (5) |\n| | *xxxxxxxx* | |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. As in Standard C, up to three octal digits are accepted.\n\n2. Unlike in Standard C, at most two hex digits are accepted.\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. Individual code units which form parts of a surrogate pair can be\n encoded using this escape sequence. Unlike in Standard C, exactly\n two hex digits are required.\n\n5. 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). Individual code units which form parts of a surrogate\n pair can be encoded using this escape sequence.\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. If this value is negative, the length of the sequence is\nadded to it (so that, e.g., ``x[-1]`` selects the last item of ``x``.)\nThe resulting value must be a nonnegative integer less than the number\nof items in the sequence, and the subscription selects the item whose\nindex is that value (counting from zero).\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n', @@ -67,7 +67,7 @@ '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 N = None\n del N\n\nThat means that you have to assign the exception to a different name\nif you want to be able to refer to it after the except clause. The\nreason for this is that with the traceback attached to them,\nexceptions will form a reference cycle with the stack frame, keeping\nall locals in that frame alive until the next garbage collection\noccurs.\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\nof: ``exc_type``, the exception class; ``exc_value``, the exception\ninstance; ``exc_traceback``, a traceback object (see section *The\nstandard type hierarchy*) identifying the point in the program where\nthe exception occurred. ``sys.exc_info()`` values are restored to\ntheir previous values (before the call) when returning from a function\nthat 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 lost. The exception information is not available to the\nprogram during execution 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 The items of a string object are Unicode code units. A\n Unicode code unit is represented by a string object of one\n item and can hold either a 16-bit or 32-bit value\n representing a Unicode ordinal (the maximum value for the\n ordinal is given in ``sys.maxunicode``, and depends on how\n Python is configured at compile time). Surrogate pairs may\n be present in the Unicode object, and will be reported as two\n separate items. The built-in functions ``chr()`` and\n ``ord()`` convert between code units and nonnegative integers\n representing the Unicode ordinals as defined in the Unicode\n Standard 3.0. Conversion from and to other encodings are\n possible through the string method ``encode()``.\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 is currently a single intrinsic mutable sequence type:\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 | ``__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 *list*.\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 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 Custon 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\nFiles\n A file object represents an open file. File objects are created by\n the ``open()`` built-in function, and also by ``os.popen()``,\n ``os.fdopen()``, and the ``makefile()`` method of socket objects\n (and perhaps by other functions or methods provided by extension\n modules). The objects ``sys.stdin``, ``sys.stdout`` and\n ``sys.stderr`` are initialized to file objects corresponding to the\n interpreter\'s standard input, output and error streams. See *File\n Objects* for complete documentation of file objects.\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 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": 2, "two": 3}``:\n\n * ``dict(one=2, two=3)``\n\n * ``dict({\'one\': 2, \'two\': 3})``\n\n * ``dict(zip((\'one\', \'two\'), (2, 3)))``\n\n * ``dict([[\'two\', 3], [\'one\', 2]])``\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. For an example, see ``collections.defaultdict``.\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 clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n 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 below for documentation of view objects.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See below for\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 a tuple or other iterable of\n length two). If keyword arguments are specified, the\n dictionary is then is updated with those key/value pairs:\n ``d.update(red=1, blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See below for\n documentation of view objects.\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. The keys and items views\nhave a set-like character since their entries\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\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\nThe keys and items views also provide set-like operations ("other"\nhere refers to another dictionary view or a set):\n\ndictview & other\n\n Return the intersection of the dictview and the other object as a\n new set.\n\ndictview | other\n\n Return the union of the dictview and the other object as a new set.\n\ndictview - other\n\n Return the difference between the dictview and the other object\n (all elements in *dictview* that aren\'t in *other*) as a new set.\n\ndictview ^ other\n\n Return the symmetric difference (all elements either in *dictview*\n or *other*, but not in both) of the dictview and the other object\n as a new set.\n\nWarning: Since a dictionary\'s values are not required to be hashable, any of\n these four operations will fail if an involved dictionary contains\n such a value.\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', + '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 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": 2, "two": 3}``:\n\n * ``dict(one=2, two=3)``\n\n * ``dict({\'one\': 2, \'two\': 3})``\n\n * ``dict(zip((\'one\', \'two\'), (2, 3)))``\n\n * ``dict([[\'two\', 3], [\'one\', 2]])``\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. For an example, see ``collections.defaultdict``.\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 clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n 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 below for documentation of view objects.\n\n keys()\n\n Return a new view of the dictionary\'s keys. See below for\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 a tuple or other iterable of\n length two). If keyword arguments are specified, the\n dictionary is then is updated with those key/value pairs:\n ``d.update(red=1, blue=2)``.\n\n values()\n\n Return a new view of the dictionary\'s values. See below for\n documentation of view objects.\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\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 and\nhashable, then the items view is also set-like. (Values views are not\ntreated as set-like since the entries are generally not unique.) Then\nthese set operations are available ("other" refers either to another\nview or a set):\n\ndictview & other\n\n Return the intersection of the dictview and the other object as a\n new set.\n\ndictview | other\n\n Return the union of the dictview and the other object as a new set.\n\ndictview - other\n\n Return the difference between the dictview and the other object\n (all elements in *dictview* that aren\'t in *other*) as a new set.\n\ndictview ^ other\n\n Return the symmetric difference (all elements either in *dictview*\n or *other*, but not in both) of the dictview and the other object\n as a new set.\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', '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 member 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 five sequence types: strings, byte sequences, byte arrays,\nlists, tuples, and range objects. (For other containers see the\nbuilt-in ``dict``, ``list``, ``set``, and ``tuple`` classes, and the\n``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\nbe constructed the constructor, ``bytes()``, and from literals; use a\n``b`` prefix with normal string syntax: ``b\'xyzzy\'``. To construct\nbyte arrays, use the ``bytearray()`` function.\n\nWarning: While string objects are sequences of characters (represented by\n strings of length 1), bytes and bytearray objects are sequences of\n *integers* (between 0 and 255), representing the ASCII value of\n single bytes. That means that for a bytes or bytearray object *b*,\n ``b[0]`` will be an integer, while ``b[0:1]`` will be a bytes or\n bytearray object of length 1. The representation of bytes objects\n uses the literal format (``b\'...\'``) since it is generally more\n useful than e.g. ``bytes([50, 19, 100])``. You can always convert a\n bytes object into a list of integers using ``list(b)``.Also, while\n in previous Python versions, byte strings and Unicode strings could\n be exchanged for each other rather freely (barring encoding issues),\n strings and bytes are now completely separate concepts. There\'s no\n implicit en-/decoding if you pass and object of the wrong type. A\n string always compares unequal to a bytes or bytearray 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 slicing, concatenation or repetition, and using\n``in``, ``not in``, ``min()`` or ``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* and *j* 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\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. If *s* and *t* are both strings, some Python implementations such\n as CPython can usually perform an in-place optimization for\n assignments of the form ``s=s+t`` or ``s+=t``. When applicable,\n this optimization makes quadratic run-time much less likely. This\n optimization is both version and implementation dependent. For\n performance sensitive code, it is preferable to use the\n ``str.join()`` method which assures consistent linear concatenation\n performance across versions and implementations.\n\n\nString Methods\n==============\n\nString objects support the methods listed below. Note that none of\nthese methods take keyword arguments.\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 only its first character\n capitalized.\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 occurrences of substring *sub* in the range\n [*start*, *end*]. Optional arguments *start* and *end* are\n interpreted as in slice notation.\n\nstr.encode([encoding[, errors]])\n\n Return an encoded version of the string. Default encoding is the\n current default string encoding. *errors* may be given to set a\n different error handling scheme. The default for *errors* is\n ``\'strict\'``, meaning that encoding errors raise a\n ``UnicodeError``. Other possible values are ``\'ignore\'``,\n ``\'replace\'``, ``\'xmlcharrefreplace\'``, ``\'backslashreplace\'`` and\n any other name registered via ``codecs.register_error()``, see\n section *Codec Base Classes*. For a list of possible encodings, see\n section *Standard Encodings*.\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 one 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 range [*start*, *end*].\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return ``-1`` if *sub* is not found.\n\nstr.format(format_string, *args, **kwargs)\n\n Perform a string formatting operation. The *format_string*\n argument can contain literal text or replacement fields delimited\n by braces ``{}``. Each replacement field contains either the\n numeric index of a positional argument, or the name of a keyword\n argument. Returns a copy of *format_string* where each replacement\n field is replaced with the string value of the corresponding\n 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.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.\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.\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 include digit characters, and all characters that that\n can be used to form decimal-radix numbers, e.g. U+0660, ARABIC-\n 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.\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 in the string are lowercase and\n 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.\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.\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 in the string are uppercase and\n there is at least one cased character, false otherwise.\n\nstr.join(seq)\n\n Return a string which is the concatenation of the strings in the\n sequence *seq*. A ``TypeError`` will be raised if there are any\n non-string values in *seq*, including ``bytes`` objects. The\n 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\n ``len(s)``.\n\nstr.lower()\n\n Return a copy of the string converted to lowercase.\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\nstr.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]. Optional\n arguments *start* and *end* are interpreted as in slice notation.\n 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\n ``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[, maxsplit]])\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[, maxsplit]])\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, then there is no limit\n 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.\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.\n\nstr.title()\n\n Return a titlecased version of the string: words start with\n uppercase characters, all remaining cased characters are lowercase.\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\n ordinals(integers) to Unicode ordinals, strings or ``None``.\n Unmapped characters are left untouched. Characters mapped to\n ``None`` are deleted.\n\n A *map* for ``translate()`` is usually best created by\n ``str.maketrans()``.\n\n You can use the ``maketrans()`` helper function in the ``string``\n module to create a translation table. For string objects, set the\n *table* argument to ``None`` for translations that only delete\n characters:\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 converted to uppercase.\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 ``len(s)``.\n\n\nOld String Formatting Operations\n================================\n\nNote: The formatting operations described here are obsolete and may go\n away in future versions of Python. Use the new *String Formatting*\n in new code.\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. [4] 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 width\n is read from the next element of the tuple in *values*, and the\n 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 %(#)03d quote types.\' % \\\n... {\'language\': "Python", "#": 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\'`` | Obselete 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()``). | |\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. The precision determines the maximal number of characters used.\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\nFor safety reasons, floating point precisions are clipped to 50;\n``%f`` conversions for numbers whose absolute value is over 1e25 are\nreplaced by ``%g`` conversions. [5] All other errors raise\nexceptions.\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. There are no consistent performance\nadvantages.\n\nRange objects have very little behavior: they only support indexing,\niteration, and the ``len()`` function.\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.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``.\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 While a list is being sorted, the effect of attempting to mutate,\n or even inspect, the list is undefined. The C implementation makes\n the list appear empty for the duration, and raises ``ValueError``\n if it can detect that the list has been mutated during a sort.\n\n8. ``sort()`` is not supported by ``bytearray`` objects.\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\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\nThe bytes and bytearray types have an additional class method:\n\nbytes.fromhex(string)\nbytearray.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', Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 21 02:18:21 2008 @@ -7,7 +7,7 @@ What's New in Python 3.0 release candiate 3? ============================================ -*Release date: XX-XXX-2008* +*Release date: 20-Nov-2008* Core and Builtins Modified: python/branches/py3k/Misc/RPM/python-3.0.spec ============================================================================== --- python/branches/py3k/Misc/RPM/python-3.0.spec (original) +++ python/branches/py3k/Misc/RPM/python-3.0.spec Fri Nov 21 02:18:21 2008 @@ -34,7 +34,7 @@ %define name python #--start constants-- -%define version 3.0rc2 +%define version 3.0rc3 %define libver 3.0 #--end constants-- %define release 1pydotorg Modified: python/branches/py3k/README ============================================================================== --- python/branches/py3k/README (original) +++ python/branches/py3k/README Fri Nov 21 02:18:21 2008 @@ -1,4 +1,4 @@ -This is Python version 3.0 release candidate 2 +This is Python version 3.0 release candidate 3 ============================================== For notes specific to this release, see RELNOTES in this directory. From python-3000-checkins at python.org Fri Nov 21 11:40:51 2008 From: python-3000-checkins at python.org (raymond.hettinger) Date: Fri, 21 Nov 2008 11:40:51 +0100 (CET) Subject: [Python-3000-checkins] r67314 - python/branches/py3k/Doc/reference/expressions.rst Message-ID: <20081121104051.9C3D31E4002@bag.python.org> Author: raymond.hettinger Date: Fri Nov 21 11:40:51 2008 New Revision: 67314 Log: Fix minor typos. Modified: python/branches/py3k/Doc/reference/expressions.rst Modified: python/branches/py3k/Doc/reference/expressions.rst ============================================================================== --- python/branches/py3k/Doc/reference/expressions.rst (original) +++ python/branches/py3k/Doc/reference/expressions.rst Fri Nov 21 11:40:51 2008 @@ -1043,7 +1043,7 @@ program. Comparison of objects of the differing types depends on whether either -of the types provide explicit support for the comparison. Most numberic types +of the types provide explicit support for the comparison. Most numeric types can be compared with one another, but comparisons of :class:`float` and :class:`Decimal` are not supported to avoid the inevitable confusion arising from representation issues such as ``float('1.1')`` being inexactly represented @@ -1058,8 +1058,8 @@ in s`` returns the negation of ``x in s``. All built-in sequences and set types support this as well as dictionary, for which :keyword:`in` tests whether a the dictionary has a given key. For container types such as list, tuple, set, -frozenset, dict, or collections.deque, the expression ``x in y`` equivalent to -``any(x is e or x == e for val e in y)``. +frozenset, dict, or collections.deque, the expression ``x in y`` is equivalent +to ``any(x is e or x == e for val e in y)``. For the string and bytes types, ``x in y`` is true if and only if *x* is a substring of *y*. An equivalent test is ``y.find(x) != -1``. Empty strings are From skip at pobox.com Fri Nov 21 14:12:45 2008 From: skip at pobox.com (skip at pobox.com) Date: Fri, 21 Nov 2008 07:12:45 -0600 Subject: [Python-3000-checkins] r67310 - in python/branches/py3k: Lib/dbm/dumb.py Lib/test/test_dbm_dumb.py Misc/NEWS In-Reply-To: <20081121001754.36DFA1E4002@bag.python.org> References: <20081121001754.36DFA1E4002@bag.python.org> Message-ID: <18726.46029.968794.295880@montanaro-dyndns-org.local> Author: brett.cannon Date: Fri Nov 21 01:17:53 2008 New Revision: 67310 Log: Make dbm.dumb encode strings as UTF-8. Also fix it so it accepts bytes and strings. Closes issue #3799. I'm not online right now so I can't verify this by reviewing the ticket, but I thought Guido was of the opinion that the 3.0 version should be able to read dumb dbms written by earlier Python versions. That would mean that if trying to read utf-8 content fails you need to fall back to latin-1. Skip From python-3000-checkins at python.org Fri Nov 21 16:13:37 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 21 Nov 2008 16:13:37 +0100 (CET) Subject: [Python-3000-checkins] r67316 - in python/branches/py3k: Include/patchlevel.h Misc/NEWS Message-ID: <20081121151337.5566A1E4002@bag.python.org> Author: barry.warsaw Date: Fri Nov 21 16:13:37 2008 New Revision: 67316 Log: post-3.0rc3 Modified: python/branches/py3k/Include/patchlevel.h python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Include/patchlevel.h ============================================================================== --- python/branches/py3k/Include/patchlevel.h (original) +++ python/branches/py3k/Include/patchlevel.h Fri Nov 21 16:13:37 2008 @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 3 /* Version as a string */ -#define PY_VERSION "3.0rc3" +#define PY_VERSION "3.0rc3+" /*--end constants--*/ /* Subversion Revision number of this file (not of the repository) */ Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 21 16:13:37 2008 @@ -4,8 +4,20 @@ (editors: check NEWS.help for information about editing NEWS using ReST.) -What's New in Python 3.0 release candiate 3? -============================================ +What's New in Python 3.0 final +============================== + +*Release date: XX-XXX-2008* + +Core and Builtins +----------------- + +Library +------- + + +What's New in Python 3.0 release candidate 3? +============================================= *Release date: 20-Nov-2008* From skip at pobox.com Fri Nov 21 16:36:09 2008 From: skip at pobox.com (skip at pobox.com) Date: Fri, 21 Nov 2008 09:36:09 -0600 Subject: [Python-3000-checkins] [issue3799] Re: r67310 - in python/branches/py3k: Lib/dbm/dumb.py Lib/test/test_dbm_dumb.py Misc/NEWS In-Reply-To: <18726.46029.968794.295880@montanaro-dyndns-org.local> References: <20081121001754.36DFA1E4002@bag.python.org> <18726.46029.968794.295880@montanaro-dyndns-org.local> Message-ID: <18726.54633.145274.19866@montanaro-dyndns-org.local> me> ... I thought Guido was of the opinion that the 3.0 version should me> be able to read dumb dbms written by earlier Python versions.... And write them. From msg72963: (1) Be able to read databases written by Python 2.x. (1a) Write databases readable by Python 2.x. Ah, but wait a minute. I see your comment in msg76080: If you look at the 2.7 code all it requires of keys and values in __setitem__ is that they are strings; there is nothing about Latin-1 in terms of specific encoding (must be a 3.0 addition to make the str/unicode transition the easiest). The acid test. I executed the attached mydb2write.py using Python 2.5 then executed the attached mydb3read.py using Python 3.0. The output: % python2.5 mydb2write.py 1 abc 2 [4, {4.2999999999999998: 12}] 3 <__main__.C instance at 0x34bb70> % python3.0 mydb3read.py 1 b'abc' 2 [4, {4.2999999999999998: 12}] Traceback (most recent call last): File "mydb3read.py", line 13, in print(3, pickle.loads(db['3'])) File "/Users/skip/local/lib/python3.0/pickle.py", line 1329, in loads return Unpickler(file, encoding=encoding, errors=errors).load() _pickle.UnpicklingError: bad pickle data so if the ability to read Python 2.x dumbdbm files is still a requirement I think there's a little more work to do. cc'ing report at bugs.python.org to preserve the scripts with the ticket. Skip -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/octet-stream Size: 492 bytes Desc: dumbdbm write (Python 2.5) URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/octet-stream Size: 237 bytes Desc: dbm.dumb read script (Python 3.0) URL: From guido at python.org Fri Nov 21 16:44:54 2008 From: guido at python.org (Guido van Rossum) Date: Fri, 21 Nov 2008 07:44:54 -0800 Subject: [Python-3000-checkins] [issue3799] Re: r67310 - in python/branches/py3k: Lib/dbm/dumb.py Lib/test/test_dbm_dumb.py Misc/NEWS In-Reply-To: <18726.54633.145274.19866@montanaro-dyndns-org.local> References: <20081121001754.36DFA1E4002@bag.python.org> <18726.46029.968794.295880@montanaro-dyndns-org.local> <18726.54633.145274.19866@montanaro-dyndns-org.local> Message-ID: I think the ability to read old files is essential. The ability to write them is a mer nice-to-have. On Fri, Nov 21, 2008 at 7:36 AM, wrote: > > me> ... I thought Guido was of the opinion that the 3.0 version should > me> be able to read dumb dbms written by earlier Python versions.... > > And write them. From msg72963: > > (1) Be able to read databases written by Python 2.x. > > (1a) Write databases readable by Python 2.x. > > Ah, but wait a minute. I see your comment in msg76080: > > If you look at the 2.7 code all it requires of keys and values in > __setitem__ is that they are strings; there is nothing about Latin-1 in > terms of specific encoding (must be a 3.0 addition to make the > str/unicode transition the easiest). > > The acid test. I executed the attached mydb2write.py using Python 2.5 then > executed the attached mydb3read.py using Python 3.0. The output: > > % python2.5 mydb2write.py > 1 abc > 2 [4, {4.2999999999999998: 12}] > 3 <__main__.C instance at 0x34bb70> > % python3.0 mydb3read.py > 1 b'abc' > 2 [4, {4.2999999999999998: 12}] > Traceback (most recent call last): > File "mydb3read.py", line 13, in > print(3, pickle.loads(db['3'])) > File "/Users/skip/local/lib/python3.0/pickle.py", line 1329, in loads > return Unpickler(file, encoding=encoding, errors=errors).load() > _pickle.UnpicklingError: bad pickle data > > so if the ability to read Python 2.x dumbdbm files is still a requirement I > think there's a little more work to do. > > cc'ing report at bugs.python.org to preserve the scripts with the ticket. > > Skip > > > _______________________________________________ > Python-3000-checkins mailing list > Python-3000-checkins at python.org > http://mail.python.org/mailman/listinfo/python-3000-checkins > > -- --Guido van Rossum (home page: http://www.python.org/~guido/) From brett at python.org Fri Nov 21 19:27:20 2008 From: brett at python.org (Brett Cannon) Date: Fri, 21 Nov 2008 10:27:20 -0800 Subject: [Python-3000-checkins] r67310 - in python/branches/py3k: Lib/dbm/dumb.py Lib/test/test_dbm_dumb.py Misc/NEWS In-Reply-To: <18726.46029.968794.295880@montanaro-dyndns-org.local> References: <20081121001754.36DFA1E4002@bag.python.org> <18726.46029.968794.295880@montanaro-dyndns-org.local> Message-ID: I have taken this over to the issue tracker (http://bugs.python.org/issue3799). On Fri, Nov 21, 2008 at 05:12, wrote: > > Author: brett.cannon > Date: Fri Nov 21 01:17:53 2008 > New Revision: 67310 > > Log: > Make dbm.dumb encode strings as UTF-8. Also fix it so it accepts bytes and > strings. > > Closes issue #3799. > > I'm not online right now so I can't verify this by reviewing the ticket, but > I thought Guido was of the opinion that the 3.0 version should be able to > read dumb dbms written by earlier Python versions. That would mean that if > trying to read utf-8 content fails you need to fall back to latin-1. > > Skip > _______________________________________________ > Python-3000-checkins mailing list > Python-3000-checkins at python.org > http://mail.python.org/mailman/listinfo/python-3000-checkins > From python-3000-checkins at python.org Fri Nov 21 19:35:44 2008 From: python-3000-checkins at python.org (guido.van.rossum) Date: Fri, 21 Nov 2008 19:35:44 +0100 (CET) Subject: [Python-3000-checkins] r67317 - python/branches/py3k/Doc/whatsnew/3.0.rst Message-ID: <20081121183544.104F71E4002@bag.python.org> Author: guido.van.rossum Date: Fri Nov 21 19:35:43 2008 New Revision: 67317 Log: A few tiny improvements that I had sitting in an edit buffer. More to come. Much, much more. :-) Modified: python/branches/py3k/Doc/whatsnew/3.0.rst Modified: python/branches/py3k/Doc/whatsnew/3.0.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/3.0.rst (original) +++ python/branches/py3k/Doc/whatsnew/3.0.rst Fri Nov 21 19:35:43 2008 @@ -2,10 +2,14 @@ What's New in Python 3.0 **************************** +.. XXX add trademark info for Apple, Microsoft, SourceForge. + :Author: Guido van Rossum -:Release: 0.1 +:Release: |release| +:Date: |today| -.. Rules for maintenance: +.. $Id$ + Rules for maintenance: * Anyone can add text to this document. Do not spend very much time on the wording of your changes, because your text will probably @@ -46,10 +50,10 @@ This saves the maintainer the effort of going through the SVN log when researching a change. -This article explains the new features in Python 3.0, comparing to 2.6 -(or in some cases 2.5, since 2.6 isn't released yet). - -The best estimate for a release date is August 2008. +This article explains the new features in Python 3.0, comparing to 2.6. +In some cases it will also summarize changes since 2.5, with a reference +to "What's New in Python 2.6" for the details. Python 2.6 was released +on October 1 2008. Python 3.0 will be released in December 2008. This article doesn't attempt to provide a complete specification of the new features, but instead provides a convenient overview. For @@ -131,6 +135,17 @@ that if a file is opened using an incorrect mode or encoding, I/O will likely fail. +* The ordering comparison operators (``<``, ``<=``, ``>=``, ``>``) + raise a TypeError exception when the operands don't have a + meaningful natural ordering. Thus, expressions like ``1 < ''``, ``0 + > None`` or ``len < len`` are no longer valid. A corollary is that + sorting a heterogeneous list no longer makes sense -- all the + elements must be comparable to each other. Note that this does not + apply to the ``==`` and ``!=`` operators: objects of different + uncomparable types always compare unequal to each other, and an + object always compares equal to itself (i.e., ``x is y`` implies ``x + = y``; this is true even for ``NaN``). + * :func:`map` and :func:`filter` return iterators. A quick fix is e.g. ``list(map(...))``, but a better fix is often to use a list comprehension (especially when the original code uses :keyword:`lambda`). @@ -147,6 +162,8 @@ * ``1/2`` returns a float. Use ``1//2`` to get the truncating behavior. +.. XXX move the next one to a later point, it's not a common stumbling block. + * The :func:`repr` of a long integer doesn't include the trailing ``L`` anymore, so code that unconditionally strips that character will chop off the last digit instead. @@ -168,7 +185,7 @@ or :meth:`bytes.decode` (bytes -> str) methods. * All backslashes in raw strings are interpreted literally. This means that - Unicode escapes are not treated specially. + ``'\U'`` and ``'\u'`` escapes in raw strings are not treated specially. .. XXX add bytearray @@ -186,16 +203,17 @@ * The :mod:`StringIO` and :mod:`cStringIO` modules are gone. Instead, import :class:`io.StringIO` or :class:`io.BytesIO`. -* ``'\U'`` and ``'\u'`` escapes in raw strings are not treated specially. PEP 3101: A New Approach to String Formatting ============================================= -.. XXX expand this +* A new system for built-in string formatting operations replaces the + ``%`` string formatting operator. (However, the ``%`` operator is + still supported; it will be deprecated in Python 3.1 and removed + from the language at some later time.) -* A new system for built-in string formatting operations replaces the ``%`` - string formatting operator. +.. XXX expand this PEP 3106: Revamping dict :meth:`dict.keys`, :meth:`dict.items` and :meth:`dict.values` @@ -207,7 +225,8 @@ methods have been removed. * :meth:`dict.keys`, :meth:`dict.values` and :meth:`dict.items` return objects - with set behavior that reference the underlying dict. + with set behavior that reference the underlying dict; these are often + referred to as *dictionary views*. PEP 3107: Function Annotations From python-3000-checkins at python.org Fri Nov 21 23:58:57 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 21 Nov 2008 23:58:57 +0100 (CET) Subject: [Python-3000-checkins] r67322 - in python/branches/py3k: Lib/test/test_unicodedata.py Python/ast.c Message-ID: <20081121225857.E72161E4002@bag.python.org> Author: benjamin.peterson Date: Fri Nov 21 23:58:57 2008 New Revision: 67322 Log: Merged revisions 67320 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67320 | benjamin.peterson | 2008-11-21 16:27:24 -0600 (Fri, 21 Nov 2008) | 4 lines don't segfault when \N escapes are used and unicodedata fails to load Fixes #4367 ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/test/test_unicodedata.py python/branches/py3k/Python/ast.c Modified: python/branches/py3k/Lib/test/test_unicodedata.py ============================================================================== --- python/branches/py3k/Lib/test/test_unicodedata.py (original) +++ python/branches/py3k/Lib/test/test_unicodedata.py Fri Nov 21 23:58:57 2008 @@ -4,9 +4,13 @@ (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. -"""#" -import unittest, test.support +""" + +import sys +import unittest import hashlib +import subprocess +import test.support encoding = 'utf-8' @@ -197,6 +201,25 @@ class UnicodeMiscTest(UnicodeDatabaseTest): + def test_failed_import_during_compiling(self): + # Issue 4367 + # Decoding \N escapes requires the unicodedata module. If it can't be + # imported, we shouldn't segfault. + + # This program should raise a SyntaxError in the eval. + code = "import sys;" \ + "sys.modules['unicodedata'] = None;" \ + """eval("'\\\\N{SOFT HYPHEN}'")""" + args = [sys.executable, "-c", code] + # We use a subprocess because the unicodedata module may already have + # been loaded in this process. + popen = subprocess.Popen(args, stderr=subprocess.PIPE) + popen.wait() + self.assertEqual(popen.returncode, 1) + error = "SyntaxError: (unicode error) \\N escapes not supported " \ + "(can't load unicodedata module)" + self.assertTrue(error in popen.stderr.read().decode("ascii")) + def test_decimal_numeric_consistent(self): # Test that decimal and numeric are consistent, # i.e. if a character has a decimal value, Modified: python/branches/py3k/Python/ast.c ============================================================================== --- python/branches/py3k/Python/ast.c (original) +++ python/branches/py3k/Python/ast.c Fri Nov 21 23:58:57 2008 @@ -1321,13 +1321,14 @@ if (PyErr_ExceptionMatches(PyExc_UnicodeError)) { PyObject *type, *value, *tback, *errstr; PyErr_Fetch(&type, &value, &tback); - errstr = ((PyUnicodeErrorObject *)value)->reason; + errstr = PyObject_Str(value); if (errstr) { char *s = ""; char buf[128]; s = _PyUnicode_AsString(errstr); PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s); ast_error(n, buf); + Py_DECREF(errstr); } else { ast_error(n, "(unicode error) unknown error"); } From python-3000-checkins at python.org Sat Nov 22 00:08:10 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 22 Nov 2008 00:08:10 +0100 (CET) Subject: [Python-3000-checkins] r67323 - in python/branches/py3k: Lib/idlelib/run.py Misc/NEWS Message-ID: <20081121230810.577731E4002@bag.python.org> Author: amaury.forgeotdarc Date: Sat Nov 22 00:08:09 2008 New Revision: 67323 Log: #4383: UnboundLocalError when IDLE cannot connect to its subprocess. Python 3.0 clears the exception variable upon exit of the "except:" clause, and the displaying code fails miserably. Reviewed by Benjamin. Modified: python/branches/py3k/Lib/idlelib/run.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/idlelib/run.py ============================================================================== --- python/branches/py3k/Lib/idlelib/run.py (original) +++ python/branches/py3k/Lib/idlelib/run.py Sat Nov 22 00:08:09 2008 @@ -119,10 +119,11 @@ except socket.error as err: print("IDLE Subprocess: socket error: " + err.args[1] + ", retrying....", file=sys.__stderr__) + socket_error = err else: - print("IDLE Subprocess: Connection to "\ - "IDLE GUI failed, exiting.", file=sys.__stderr__) - show_socket_error(err, address) + print("IDLE Subprocess: Connection to " + "IDLE GUI failed, exiting.", file=sys.__stderr__) + show_socket_error(socket_error, address) global exit_now exit_now = True return Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Nov 22 00:08:09 2008 @@ -15,6 +15,9 @@ Library ------- +- Issue #4383: When IDLE cannot make the connection to its subprocess, it would + fail to properly display the error message. + What's New in Python 3.0 release candidate 3? ============================================= From python-3000-checkins at python.org Sat Nov 22 00:22:00 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 22 Nov 2008 00:22:00 +0100 (CET) Subject: [Python-3000-checkins] r67324 - python/branches/py3k/Doc/glossary.rst Message-ID: <20081121232200.7D60C1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 22 00:22:00 2008 New Revision: 67324 Log: add a glossary entry for "view" Modified: python/branches/py3k/Doc/glossary.rst Modified: python/branches/py3k/Doc/glossary.rst ============================================================================== --- python/branches/py3k/Doc/glossary.rst (original) +++ python/branches/py3k/Doc/glossary.rst Sat Nov 22 00:22:00 2008 @@ -498,6 +498,13 @@ object has a type. An object's type is accessible as its :attr:`__class__` attribute or can be retrieved with ``type(obj)``. + view + The objects returned from :meth:`dict.keys`, :meth:`dict.items`, and + :meth:`dict.items` are called dictionary views. They are lazy sequences + that will see changes in the underlying dictionary. To force the + dictionary view to become a full list use ``list(dictview)``. See + :ref:`dict-views`. + virtual machine A computer defined entirely in software. Python's virtual machine executes the :term:`bytecode` emitted by the bytecode compiler. From python-3000-checkins at python.org Sat Nov 22 01:41:46 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 22 Nov 2008 01:41:46 +0100 (CET) Subject: [Python-3000-checkins] r67325 - in python/branches/py3k: Doc/library/stdtypes.rst Lib/socket.py Lib/test/test_fileio.py Lib/test/test_gzip.py Lib/test/test_io.py Lib/test/test_socket.py Misc/NEWS Modules/_fileio.c Message-ID: <20081122004146.178E31E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 22 01:41:45 2008 New Revision: 67325 Log: make FileIO.mode always include 'b' #4386 Reviewed by Amaury Modified: python/branches/py3k/Doc/library/stdtypes.rst python/branches/py3k/Lib/socket.py python/branches/py3k/Lib/test/test_fileio.py python/branches/py3k/Lib/test/test_gzip.py python/branches/py3k/Lib/test/test_io.py python/branches/py3k/Lib/test/test_socket.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_fileio.c Modified: python/branches/py3k/Doc/library/stdtypes.rst ============================================================================== --- python/branches/py3k/Doc/library/stdtypes.rst (original) +++ python/branches/py3k/Doc/library/stdtypes.rst Sat Nov 22 01:41:45 2008 @@ -1875,6 +1875,8 @@ view objects. +.. _dict-views: + Dictionary view objects ----------------------- Modified: python/branches/py3k/Lib/socket.py ============================================================================== --- python/branches/py3k/Lib/socket.py (original) +++ python/branches/py3k/Lib/socket.py Sat Nov 22 01:41:45 2008 @@ -198,10 +198,12 @@ # XXX More docs def __init__(self, sock, mode): - if mode not in ("r", "w", "rw"): + if mode not in ("r", "w", "rw", "rb", "wb", "rwb"): raise ValueError("invalid mode: %r" % mode) io.RawIOBase.__init__(self) self._sock = sock + if "b" not in mode: + mode += "b" self._mode = mode self._reading = "r" in mode self._writing = "w" in mode Modified: python/branches/py3k/Lib/test/test_fileio.py ============================================================================== --- python/branches/py3k/Lib/test/test_fileio.py (original) +++ python/branches/py3k/Lib/test/test_fileio.py Sat Nov 22 01:41:45 2008 @@ -49,7 +49,7 @@ # verify expected attributes exist f = self.f - self.assertEquals(f.mode, "w") + self.assertEquals(f.mode, "wb") self.assertEquals(f.closed, False) # verify the attributes are readonly @@ -159,7 +159,7 @@ def testModeStrings(self): # check invalid mode strings - for mode in ("", "aU", "wU+", "rb", "rt"): + for mode in ("", "aU", "wU+", "rw", "rt"): try: f = _fileio._FileIO(TESTFN, mode) except ValueError: Modified: python/branches/py3k/Lib/test/test_gzip.py ============================================================================== --- python/branches/py3k/Lib/test/test_gzip.py (original) +++ python/branches/py3k/Lib/test/test_gzip.py Sat Nov 22 01:41:45 2008 @@ -150,7 +150,7 @@ def test_mode(self): self.test_write() f = gzip.GzipFile(self.filename, 'r') - self.assertTrue(f.myfileobj.mode.startswith('r')) + self.assertEqual(f.myfileobj.mode, 'rb') f.close() def test_1647484(self): Modified: python/branches/py3k/Lib/test/test_io.py ============================================================================== --- python/branches/py3k/Lib/test/test_io.py (original) +++ python/branches/py3k/Lib/test/test_io.py Sat Nov 22 01:41:45 2008 @@ -1266,7 +1266,7 @@ def test_attributes(self): f = io.open(support.TESTFN, "wb", buffering=0) - self.assertEquals(f.mode, "w") + self.assertEquals(f.mode, "wb") f.close() f = io.open(support.TESTFN, "U") @@ -1274,18 +1274,18 @@ self.assertEquals(f.buffer.name, support.TESTFN) self.assertEquals(f.buffer.raw.name, support.TESTFN) self.assertEquals(f.mode, "U") - self.assertEquals(f.buffer.mode, "r") - self.assertEquals(f.buffer.raw.mode, "r") + self.assertEquals(f.buffer.mode, "rb") + self.assertEquals(f.buffer.raw.mode, "rb") f.close() f = io.open(support.TESTFN, "w+") self.assertEquals(f.mode, "w+") - self.assertEquals(f.buffer.mode, "r+") # Does it really matter? - self.assertEquals(f.buffer.raw.mode, "r+") + self.assertEquals(f.buffer.mode, "rb+") # Does it really matter? + self.assertEquals(f.buffer.raw.mode, "rb+") g = io.open(f.fileno(), "wb", closefd=False) - self.assertEquals(g.mode, "w") - self.assertEquals(g.raw.mode, "w") + self.assertEquals(g.mode, "wb") + self.assertEquals(g.raw.mode, "wb") self.assertEquals(g.name, f.fileno()) self.assertEquals(g.raw.name, f.fileno()) f.close() Modified: python/branches/py3k/Lib/test/test_socket.py ============================================================================== --- python/branches/py3k/Lib/test/test_socket.py (original) +++ python/branches/py3k/Lib/test/test_socket.py Sat Nov 22 01:41:45 2008 @@ -849,11 +849,11 @@ self.assert_(not self.cli_file.closed) def testAttributes(self): - self.assertEqual(self.serv_file.mode, 'r') + self.assertEqual(self.serv_file.mode, 'rb') self.assertEqual(self.serv_file.name, self.cli_conn.fileno()) def _testAttributes(self): - self.assertEqual(self.cli_file.mode, 'w') + self.assertEqual(self.cli_file.mode, 'wb') self.assertEqual(self.cli_file.name, self.serv_conn.fileno()) class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Nov 22 01:41:45 2008 @@ -48,6 +48,8 @@ Library ------- +- FileIO's mode attribute now always includes ``"b"``. + - Issue #3799: Fix dbm.dumb to accept strings as well as bytes for keys. String keys are now written out in UTF-8. Modified: python/branches/py3k/Modules/_fileio.c ============================================================================== --- python/branches/py3k/Modules/_fileio.c (original) +++ python/branches/py3k/Modules/_fileio.c Sat Nov 22 01:41:45 2008 @@ -208,6 +208,8 @@ flags |= O_CREAT; append = 1; break; + case 'b': + break; case '+': if (plus) goto bad_mode; @@ -682,12 +684,12 @@ { if (self->readable) { if (self->writable) - return "r+"; + return "rb+"; else - return "r"; + return "rb"; } else - return "w"; + return "wb"; } static PyObject * From python-3000-checkins at python.org Sat Nov 22 03:02:16 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 22 Nov 2008 03:02:16 +0100 (CET) Subject: [Python-3000-checkins] r67327 - python/branches/py3k Message-ID: <20081122020216.507131E400C@bag.python.org> Author: benjamin.peterson Date: Sat Nov 22 03:02:16 2008 New Revision: 67327 Log: Blocked revisions 67326 via svnmerge ........ r67326 | benjamin.peterson | 2008-11-21 19:59:15 -0600 (Fri, 21 Nov 2008) | 1 line backport r67325: make FileIO.mode always contain 'b' ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Nov 22 09:27:25 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 09:27:25 +0100 (CET) Subject: [Python-3000-checkins] r67328 - python/branches/py3k/Doc/howto/functional.rst Message-ID: <20081122082725.4DAEE1E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 22 09:27:24 2008 New Revision: 67328 Log: #4378: fix a few functional HOWTO 2.xisms. Modified: python/branches/py3k/Doc/howto/functional.rst Modified: python/branches/py3k/Doc/howto/functional.rst ============================================================================== --- python/branches/py3k/Doc/howto/functional.rst (original) +++ python/branches/py3k/Doc/howto/functional.rst Sat Nov 22 09:27:24 2008 @@ -659,54 +659,6 @@ >>> list(x for x in range(10) if is_even(x)) [0, 2, 4, 6, 8] -``functools.reduce(func, iter, [initial_value])`` cumulatively performs an -operation on all the iterable's elements and, therefore, can't be applied to -infinite iterables. (Note it is not in :mod:`builtins`, but in the -:mod:`functools` module.) ``func`` must be a function that takes two elements -and returns a single value. :func:`functools.reduce` takes the first two -elements A and B returned by the iterator and calculates ``func(A, B)``. It -then requests the third element, C, calculates ``func(func(A, B), C)``, combines -this result with the fourth element returned, and continues until the iterable -is exhausted. If the iterable returns no values at all, a :exc:`TypeError` -exception is raised. If the initial value is supplied, it's used as a starting -point and ``func(initial_value, A)`` is the first calculation. :: - - >>> import operator, functools - >>> functools.reduce(operator.concat, ['A', 'BB', 'C']) - 'ABBC' - >>> functools.reduce(operator.concat, []) - Traceback (most recent call last): - ... - TypeError: reduce() of empty sequence with no initial value - >>> functools.reduce(operator.mul, [1,2,3], 1) - 6 - >>> functools.reduce(operator.mul, [], 1) - 1 - -If you use :func:`operator.add` with :func:`functools.reduce`, you'll add up all the -elements of the iterable. This case is so common that there's a special -built-in called :func:`sum` to compute it: - - >>> import functools - >>> functools.reduce(operator.add, [1,2,3,4], 0) - 10 - >>> sum([1,2,3,4]) - 10 - >>> sum([]) - 0 - -For many uses of :func:`functools.reduce`, though, it can be clearer to just write the -obvious :keyword:`for` loop:: - - import functools - # Instead of: - product = functools.reduce(operator.mul, [1,2,3], 1) - - # You can write: - product = 1 - for i in [1,2,3]: - product *= i - ``enumerate(iter)`` counts off the elements in the iterable, returning 2-tuples containing the count and each element. :: @@ -744,6 +696,7 @@ (For a more detailed discussion of sorting, see the Sorting mini-HOWTO in the Python wiki at http://wiki.python.org/moin/HowTo/Sorting.) + The ``any(iter)`` and ``all(iter)`` built-ins look at the truth values of an iterable's contents. :func:`any` returns True if any element in the iterable is a true value, and :func:`all` returns True if all of the elements are true @@ -763,90 +716,27 @@ True -Small functions and the lambda expression -========================================= - -When writing functional-style programs, you'll often need little functions that -act as predicates or that combine elements in some way. - -If there's a Python built-in or a module function that's suitable, you don't -need to define a new function at all:: - - stripped_lines = [line.strip() for line in lines] - existing_files = filter(os.path.exists, file_list) - -If the function you need doesn't exist, you need to write it. One way to write -small functions is to use the ``lambda`` statement. ``lambda`` takes a number -of parameters and an expression combining these parameters, and creates a small -function that returns the value of the expression:: - - lowercase = lambda x: x.lower() - - print_assign = lambda name, value: name + '=' + str(value) - - adder = lambda x, y: x+y - -An alternative is to just use the ``def`` statement and define a function in the -usual way:: - - def lowercase(x): - return x.lower() - - def print_assign(name, value): - return name + '=' + str(value) - - def adder(x,y): - return x + y - -Which alternative is preferable? That's a style question; my usual course is to -avoid using ``lambda``. - -One reason for my preference is that ``lambda`` is quite limited in the -functions it can define. The result has to be computable as a single -expression, which means you can't have multiway ``if... elif... else`` -comparisons or ``try... except`` statements. If you try to do too much in a -``lambda`` statement, you'll end up with an overly complicated expression that's -hard to read. Quick, what's the following code doing? - -:: - - import functools - total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1] - -You can figure it out, but it takes time to disentangle the expression to figure -out what's going on. Using a short nested ``def`` statements makes things a -little bit better:: - - import functools - def combine (a, b): - return 0, a[1] + b[1] - - total = functools.reduce(combine, items)[1] - -But it would be best of all if I had simply used a ``for`` loop:: - - total = 0 - for a, b in items: - total += b - -Or the :func:`sum` built-in and a generator expression:: +``zip(iterA, iterB, ...)`` takes one element from each iterable and +returns them in a tuple:: - total = sum(b for a,b in items) + zip(['a', 'b', 'c'], (1, 2, 3)) => + ('a', 1), ('b', 2), ('c', 3) -Many uses of :func:`functools.reduce` are clearer when written as ``for`` loops. +It doesn't construct an in-memory list and exhaust all the input iterators +before returning; instead tuples are constructed and returned only if they're +requested. (The technical term for this behaviour is `lazy evaluation +`__.) -Fredrik Lundh once suggested the following set of rules for refactoring uses of -``lambda``: +This iterator is intended to be used with iterables that are all of the same +length. If the iterables are of different lengths, the resulting stream will be +the same length as the shortest iterable. :: -1) Write a lambda function. -2) Write a comment explaining what the heck that lambda does. -3) Study the comment for a while, and think of a name that captures the essence - of the comment. -4) Convert the lambda to a def statement, using that name. -5) Remove the comment. + zip(['a', 'b'], (1, 2, 3)) => + ('a', 1), ('b', 2) -I really like these rules, but you're free to disagree -about whether this lambda-free style is better. +You should avoid doing this, though, because an element may be taken from the +longer iterators and discarded. This means you can't go on to use the iterators +further because you risk skipping a discarded element. The itertools module @@ -896,29 +786,6 @@ itertools.chain(['a', 'b', 'c'], (1, 2, 3)) => a, b, c, 1, 2, 3 -``itertools.izip(iterA, iterB, ...)`` takes one element from each iterable and -returns them in a tuple:: - - itertools.izip(['a', 'b', 'c'], (1, 2, 3)) => - ('a', 1), ('b', 2), ('c', 3) - -It's similar to the built-in :func:`zip` function, but doesn't construct an -in-memory list and exhaust all the input iterators before returning; instead -tuples are constructed and returned only if they're requested. (The technical -term for this behaviour is `lazy evaluation -`__.) - -This iterator is intended to be used with iterables that are all of the same -length. If the iterables are of different lengths, the resulting stream will be -the same length as the shortest iterable. :: - - itertools.izip(['a', 'b'], (1, 2, 3)) => - ('a', 1), ('b', 2) - -You should avoid doing this, though, because an element may be taken from the -longer iterators and discarded. This means you can't go on to use the iterators -further because you risk skipping a discarded element. - ``itertools.islice(iter, [start], stop, [step])`` returns a stream that's a slice of the iterator. With a single ``stop`` argument, it will return the first ``stop`` elements. If you supply a starting index, you'll get @@ -953,8 +820,6 @@ Calling functions on elements ----------------------------- -``itertools.imap(func, iter)`` is the same as built-in :func:`map`. - The ``operator`` module contains a set of functions corresponding to Python's operators. Some examples are ``operator.add(a, b)`` (adds two values), ``operator.ne(a, b)`` (same as ``a!=b``), and ``operator.attrgetter('id')`` @@ -976,12 +841,10 @@ Another group of functions chooses a subset of an iterator's elements based on a predicate. -``itertools.ifilter(predicate, iter)`` is the same as built-in :func:`filter`. - -``itertools.ifilterfalse(predicate, iter)`` is the opposite, returning all +``itertools.filterfalse(predicate, iter)`` is the opposite, returning all elements for which the predicate returns false:: - itertools.ifilterfalse(is_even, itertools.count()) => + itertools.filterfalse(is_even, itertools.count()) => 1, 3, 5, 7, 9, 11, 13, 15, ... ``itertools.takewhile(predicate, iter)`` returns elements for as long as the @@ -1083,6 +946,54 @@ server_log = functools.partial(log, subsystem='server') server_log('Unable to open socket') +``functools.reduce(func, iter, [initial_value])`` cumulatively performs an +operation on all the iterable's elements and, therefore, can't be applied to +infinite iterables. (Note it is not in :mod:`builtins`, but in the +:mod:`functools` module.) ``func`` must be a function that takes two elements +and returns a single value. :func:`functools.reduce` takes the first two +elements A and B returned by the iterator and calculates ``func(A, B)``. It +then requests the third element, C, calculates ``func(func(A, B), C)``, combines +this result with the fourth element returned, and continues until the iterable +is exhausted. If the iterable returns no values at all, a :exc:`TypeError` +exception is raised. If the initial value is supplied, it's used as a starting +point and ``func(initial_value, A)`` is the first calculation. :: + + >>> import operator, functools + >>> functools.reduce(operator.concat, ['A', 'BB', 'C']) + 'ABBC' + >>> functools.reduce(operator.concat, []) + Traceback (most recent call last): + ... + TypeError: reduce() of empty sequence with no initial value + >>> functools.reduce(operator.mul, [1,2,3], 1) + 6 + >>> functools.reduce(operator.mul, [], 1) + 1 + +If you use :func:`operator.add` with :func:`functools.reduce`, you'll add up all the +elements of the iterable. This case is so common that there's a special +built-in called :func:`sum` to compute it: + + >>> import functools + >>> functools.reduce(operator.add, [1,2,3,4], 0) + 10 + >>> sum([1,2,3,4]) + 10 + >>> sum([]) + 0 + +For many uses of :func:`functools.reduce`, though, it can be clearer to just write the +obvious :keyword:`for` loop:: + + import functools + # Instead of: + product = functools.reduce(operator.mul, [1,2,3], 1) + + # You can write: + product = 1 + for i in [1,2,3]: + product *= i + The operator module ------------------- @@ -1232,6 +1143,92 @@ join = partial(foldl, concat, "") +Small functions and the lambda expression +========================================= + +When writing functional-style programs, you'll often need little functions that +act as predicates or that combine elements in some way. + +If there's a Python built-in or a module function that's suitable, you don't +need to define a new function at all:: + + stripped_lines = [line.strip() for line in lines] + existing_files = filter(os.path.exists, file_list) + +If the function you need doesn't exist, you need to write it. One way to write +small functions is to use the ``lambda`` statement. ``lambda`` takes a number +of parameters and an expression combining these parameters, and creates a small +function that returns the value of the expression:: + + lowercase = lambda x: x.lower() + + print_assign = lambda name, value: name + '=' + str(value) + + adder = lambda x, y: x+y + +An alternative is to just use the ``def`` statement and define a function in the +usual way:: + + def lowercase(x): + return x.lower() + + def print_assign(name, value): + return name + '=' + str(value) + + def adder(x,y): + return x + y + +Which alternative is preferable? That's a style question; my usual course is to +avoid using ``lambda``. + +One reason for my preference is that ``lambda`` is quite limited in the +functions it can define. The result has to be computable as a single +expression, which means you can't have multiway ``if... elif... else`` +comparisons or ``try... except`` statements. If you try to do too much in a +``lambda`` statement, you'll end up with an overly complicated expression that's +hard to read. Quick, what's the following code doing? + +:: + + import functools + total = functools.reduce(lambda a, b: (0, a[1] + b[1]), items)[1] + +You can figure it out, but it takes time to disentangle the expression to figure +out what's going on. Using a short nested ``def`` statements makes things a +little bit better:: + + import functools + def combine (a, b): + return 0, a[1] + b[1] + + total = functools.reduce(combine, items)[1] + +But it would be best of all if I had simply used a ``for`` loop:: + + total = 0 + for a, b in items: + total += b + +Or the :func:`sum` built-in and a generator expression:: + + total = sum(b for a,b in items) + +Many uses of :func:`functools.reduce` are clearer when written as ``for`` loops. + +Fredrik Lundh once suggested the following set of rules for refactoring uses of +``lambda``: + +1) Write a lambda function. +2) Write a comment explaining what the heck that lambda does. +3) Study the comment for a while, and think of a name that captures the essence + of the comment. +4) Convert the lambda to a def statement, using that name. +5) Remove the comment. + +I really like these rules, but you're free to disagree +about whether this lambda-free style is better. + + Revision History and Acknowledgements ===================================== From python-3000-checkins at python.org Sat Nov 22 09:31:09 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 09:31:09 +0100 (CET) Subject: [Python-3000-checkins] r67329 - in python/branches/py3k: Doc/library/string.rst Lib/string.py Message-ID: <20081122083109.A25DA1E4042@bag.python.org> Author: georg.brandl Date: Sat Nov 22 09:31:09 2008 New Revision: 67329 Log: #4361: fix string.py docstring, clarify that only ASCII characters are in its constants. Modified: python/branches/py3k/Doc/library/string.rst python/branches/py3k/Lib/string.py Modified: python/branches/py3k/Doc/library/string.rst ============================================================================== --- python/branches/py3k/Doc/library/string.rst (original) +++ python/branches/py3k/Doc/library/string.rst Sat Nov 22 09:31:09 2008 @@ -71,7 +71,7 @@ .. data:: whitespace - A string containing all characters that are considered whitespace. + A string containing all ASCII characters that are considered whitespace. This includes the characters space, tab, linefeed, return, formfeed, and vertical tab. Modified: python/branches/py3k/Lib/string.py ============================================================================== --- python/branches/py3k/Lib/string.py (original) +++ python/branches/py3k/Lib/string.py Sat Nov 22 09:31:09 2008 @@ -2,15 +2,15 @@ Public module variables: -whitespace -- a string containing all characters considered whitespace -lowercase -- a string containing all characters considered lowercase letters -uppercase -- a string containing all characters considered uppercase letters -letters -- a string containing all characters considered letters -digits -- a string containing all characters considered decimal digits -hexdigits -- a string containing all characters considered hexadecimal digits -octdigits -- a string containing all characters considered octal digits -punctuation -- a string containing all characters considered punctuation -printable -- a string containing all characters considered printable +whitespace -- a string containing all ASCII whitespace +ascii_lowercase -- a string containing all ASCII lowercase letters +ascii_uppercase -- a string containing all ASCII uppercase letters +ascii_letters -- a string containing all ASCII letters +digits -- a string containing all ASCII decimal digits +hexdigits -- a string containing all ASCII hexadecimal digits +octdigits -- a string containing all ASCII octal digits +punctuation -- a string containing all ASCII punctuation characters +printable -- a string containing all ASCII characters considered printable """ From python-3000-checkins at python.org Sat Nov 22 09:35:59 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 09:35:59 +0100 (CET) Subject: [Python-3000-checkins] r67331 - python/branches/py3k/Doc/whatsnew/3.0.rst Message-ID: <20081122083559.A2D8B1E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 22 09:35:59 2008 New Revision: 67331 Log: #4372: add bullet point for __cmp__ removal. Modified: python/branches/py3k/Doc/whatsnew/3.0.rst Modified: python/branches/py3k/Doc/whatsnew/3.0.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/3.0.rst (original) +++ python/branches/py3k/Doc/whatsnew/3.0.rst Sat Nov 22 09:35:59 2008 @@ -160,6 +160,10 @@ argument providing a comparison function. Use the *key* argument instead. N.B. the *key* and *reverse* arguments are now "keyword-only". +* The :meth:`__cmp__` special method is no longer supported. Use :meth:`__lt__` + for sorting, :meth:`__eq__` with :meth:`__hash__`, and other rich comparisons + as needed. + * ``1/2`` returns a float. Use ``1//2`` to get the truncating behavior. .. XXX move the next one to a later point, it's not a common stumbling block. From python-3000-checkins at python.org Sat Nov 22 09:46:36 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 09:46:36 +0100 (CET) Subject: [Python-3000-checkins] r67333 - python/branches/py3k Message-ID: <20081122084636.C787E1E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 22 09:46:36 2008 New Revision: 67333 Log: Blocked revisions 67332 via svnmerge ........ r67332 | georg.brandl | 2008-11-22 09:45:33 +0100 (Sat, 22 Nov 2008) | 2 lines Fix typo. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Nov 22 09:51:39 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 09:51:39 +0100 (CET) Subject: [Python-3000-checkins] r67334 - in python/branches/py3k: Doc/library/multiprocessing.rst Lib/multiprocessing/pool.py Message-ID: <20081122085139.4B3421E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 22 09:51:39 2008 New Revision: 67334 Log: #4206: fix 2.xisms in multiprocessing docs and docstrings. Modified: python/branches/py3k/Doc/library/multiprocessing.rst python/branches/py3k/Lib/multiprocessing/pool.py Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Sat Nov 22 09:51:39 2008 @@ -1447,8 +1447,8 @@ .. method:: map(func, iterable[, chunksize]) - A parallel equivalent of the :func:`map` builtin function. It blocks till - the result is ready. + A parallel equivalent of the :func:`map` builtin function, collecting the + result in a list. It blocks till the whole result is ready. This method chops the iterable into a number of chunks which it submits to the process pool as separate tasks. The (approximate) size of these @@ -1465,7 +1465,7 @@ .. method:: imap(func, iterable[, chunksize]) - An lazier version of :meth:`map`. + A lazier version of :meth:`map`. The *chunksize* argument is the same as the one used by the :meth:`.map` method. For very long iterables using a large value for *chunksize* can Modified: python/branches/py3k/Lib/multiprocessing/pool.py ============================================================================== --- python/branches/py3k/Lib/multiprocessing/pool.py (original) +++ python/branches/py3k/Lib/multiprocessing/pool.py Sat Nov 22 09:51:39 2008 @@ -76,7 +76,7 @@ class Pool(object): ''' - Class which supports an async version of the `apply()` builtin + Class which supports an async version of applying functions to arguments. ''' Process = Process @@ -135,21 +135,22 @@ def apply(self, func, args=(), kwds={}): ''' - Equivalent of `apply()` builtin + Equivalent of `func(*args, **kwds)`. ''' assert self._state == RUN return self.apply_async(func, args, kwds).get() def map(self, func, iterable, chunksize=None): ''' - Equivalent of `map()` builtin + Apply `func` to each element in `iterable`, collecting the results + in a list that is returned. ''' assert self._state == RUN return self.map_async(func, iterable, chunksize).get() def imap(self, func, iterable, chunksize=1): ''' - Equivalent of `itertool.imap()` -- can be MUCH slower than `Pool.map()` + Equivalent of `map()` -- can be MUCH slower than `Pool.map()`. ''' assert self._state == RUN if chunksize == 1: @@ -167,7 +168,7 @@ def imap_unordered(self, func, iterable, chunksize=1): ''' - Like `imap()` method but ordering of results is arbitrary + Like `imap()` method but ordering of results is arbitrary. ''' assert self._state == RUN if chunksize == 1: @@ -185,7 +186,7 @@ def apply_async(self, func, args=(), kwds={}, callback=None): ''' - Asynchronous equivalent of `apply()` builtin + Asynchronous version of `apply()` method. ''' assert self._state == RUN result = ApplyResult(self._cache, callback) @@ -194,7 +195,7 @@ def map_async(self, func, iterable, chunksize=None, callback=None): ''' - Asynchronous equivalent of `map()` builtin + Asynchronous version of `map()` method. ''' assert self._state == RUN if not hasattr(iterable, '__len__'): From python-3000-checkins at python.org Sat Nov 22 09:54:21 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 09:54:21 +0100 (CET) Subject: [Python-3000-checkins] r67335 - python/branches/py3k/Doc/library/multiprocessing.rst Message-ID: <20081122085421.95B9A1E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 22 09:54:21 2008 New Revision: 67335 Log: Fix two mp doc issues from #4012. Modified: python/branches/py3k/Doc/library/multiprocessing.rst Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Sat Nov 22 09:54:21 2008 @@ -232,7 +232,7 @@ if __name__ == '__main__': pool = Pool(processes=4) # start 4 worker processes - result = pool.applyAsync(f, [10]) # evaluate "f(10)" asynchronously + result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously print(result.get(timeout=1)) # prints "100" unless your computer is *very* slow print(pool.map(f, range(10))) # prints "[0, 1, 4,..., 81]" @@ -1505,7 +1505,7 @@ The class of the result returned by :meth:`Pool.apply_async` and :meth:`Pool.map_async`. - .. method:: get([timeout) + .. method:: get([timeout]) Return the result when it arrives. If *timeout* is not ``None`` and the result does not arrive within *timeout* seconds then @@ -1535,7 +1535,7 @@ if __name__ == '__main__': pool = Pool(processes=4) # start 4 worker processes - result = pool.applyAsync(f, (10,)) # evaluate "f(10)" asynchronously + result = pool.apply_async(f, (10,)) # evaluate "f(10)" asynchronously print(result.get(timeout=1)) # prints "100" unless your computer is *very* slow print(pool.map(f, range(10))) # prints "[0, 1, 4,..., 81]" @@ -1546,7 +1546,7 @@ print(it.next(timeout=1)) # prints "4" unless your computer is *very* slow import time - result = pool.applyAsync(time.sleep, (10,)) + result = pool.apply_async(time.sleep, (10,)) print(result.get(timeout=1)) # raises TimeoutError From python-3000-checkins at python.org Sat Nov 22 11:10:59 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 11:10:59 +0100 (CET) Subject: [Python-3000-checkins] r67337 - python/branches/py3k Message-ID: <20081122101059.953F51E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 22 11:10:59 2008 New Revision: 67337 Log: Blocked revisions 67336 via svnmerge ........ r67336 | georg.brandl | 2008-11-22 11:08:50 +0100 (Sat, 22 Nov 2008) | 2 lines Fix error about "-*-" being mandatory in coding cookies. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Nov 22 11:27:00 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 22 Nov 2008 11:27:00 +0100 (CET) Subject: [Python-3000-checkins] r67338 - python/branches/py3k/Doc/howto/unicode.rst Message-ID: <20081122102700.300A91E4002@bag.python.org> Author: georg.brandl Date: Sat Nov 22 11:26:59 2008 New Revision: 67338 Log: #4153: finish updating Unicode HOWTO for Py3k changes. Modified: python/branches/py3k/Doc/howto/unicode.rst Modified: python/branches/py3k/Doc/howto/unicode.rst ============================================================================== --- python/branches/py3k/Doc/howto/unicode.rst (original) +++ python/branches/py3k/Doc/howto/unicode.rst Sat Nov 22 11:26:59 2008 @@ -2,16 +2,11 @@ Unicode HOWTO ***************** -:Release: 1.02 +:Release: 1.1 This HOWTO discusses Python's support for Unicode, and explains various problems that people commonly encounter when trying to work with Unicode. -.. XXX fix it -.. warning:: - - This HOWTO has not yet been updated for Python 3000's string object changes. - Introduction to Unicode ======================= @@ -21,9 +16,8 @@ In 1968, the American Standard Code for Information Interchange, better known by its acronym ASCII, was standardized. ASCII defined numeric codes for various -characters, with the numeric values running from 0 to -127. For example, the lowercase letter 'a' is assigned 97 as its code -value. +characters, with the numeric values running from 0 to 127. For example, the +lowercase letter 'a' is assigned 97 as its code value. ASCII was an American-developed standard, so it only defined unaccented characters. There was an 'e', but no '?' or '?'. This meant that languages @@ -256,25 +250,25 @@ The *errors* argument specifies the response when the input string can't be converted according to the encoding's rules. Legal values for this argument are -'strict' (raise a :exc:`UnicodeDecodeError` exception), 'replace' (add U+FFFD, +'strict' (raise a :exc:`UnicodeDecodeError` exception), 'replace' (use U+FFFD, 'REPLACEMENT CHARACTER'), or 'ignore' (just leave the character out of the Unicode result). The following examples show the differences:: >>> b'\x80abc'.decode("utf-8", "strict") Traceback (most recent call last): File "", line 1, in ? - UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: - ordinal not in range(128) + UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0: + unexpected code byte >>> b'\x80abc'.decode("utf-8", "replace") '\ufffdabc' >>> b'\x80abc'.decode("utf-8", "ignore") 'abc' -Encodings are specified as strings containing the encoding's name. Python -comes with roughly 100 different encodings; see the Python Library Reference at -:ref:`standard-encodings` for a list. Some encodings -have multiple names; for example, 'latin-1', 'iso_8859_1' and '8859' are all -synonyms for the same encoding. +Encodings are specified as strings containing the encoding's name. Python comes +with roughly 100 different encodings; see the Python Library Reference at +:ref:`standard-encodings` for a list. Some encodings have multiple names; for +example, 'latin-1', 'iso_8859_1' and '8859' are all synonyms for the same +encoding. One-character Unicode strings can also be created with the :func:`chr` built-in function, which takes integers and returns a Unicode string of length 1 @@ -294,8 +288,9 @@ which returns a ``bytes`` representation of the Unicode string, encoded in the requested encoding. The ``errors`` parameter is the same as the parameter of the :meth:`decode` method, with one additional possibility; as well as 'strict', -'ignore', and 'replace', you can also pass 'xmlcharrefreplace' which uses XML's -character references. The following example shows the different results:: +'ignore', and 'replace' (which in this case inserts a question mark instead of +the unencodable character), you can also pass 'xmlcharrefreplace' which uses +XML's character references. The following example shows the different results:: >>> u = chr(40960) + 'abcd' + chr(1972) >>> u.encode('utf-8') @@ -303,7 +298,8 @@ >>> u.encode('ascii') Traceback (most recent call last): File "", line 1, in ? - UnicodeEncodeError: 'ascii' codec can't encode character '\ua000' in position 0: ordinal not in range(128) + UnicodeEncodeError: 'ascii' codec can't encode character '\ua000' in + position 0: ordinal not in range(128) >>> u.encode('ascii', 'ignore') b'abcd' >>> u.encode('ascii', 'replace') @@ -319,10 +315,6 @@ interfaces, but implementing encodings is a specialized task that also won't be covered here. Consult the Python documentation to learn more about this module. -The most commonly used part of the :mod:`codecs` module is the -:func:`codecs.open` function which will be discussed in the section on input and -output. - Unicode Literals in Python Source Code -------------------------------------- @@ -350,10 +342,9 @@ which would display the accented characters naturally, and have the right characters used at runtime. -Python supports writing Unicode literals in UTF-8 by default, but you can use -(almost) any encoding if you declare the encoding being used. This is done by -including a special comment as either the first or second line of the source -file:: +Python supports writing source code in UTF-8 by default, but you can use almost +any encoding if you declare the encoding being used. This is done by including +a special comment as either the first or second line of the source file:: #!/usr/bin/env python # -*- coding: latin-1 -*- @@ -363,9 +354,9 @@ The syntax is inspired by Emacs's notation for specifying variables local to a file. Emacs supports many different variables, but Python only supports -'coding'. The ``-*-`` symbols indicate that the comment is special; within -them, you must supply the name ``coding`` and the name of your chosen encoding, -separated by ``':'``. +'coding'. The ``-*-`` symbols indicate to Emacs that the comment is special; +they have no significance to Python but are a convention. Python looks for +``coding: name`` or ``coding=name`` in the comment. If you don't include such a comment, the default encoding used will be UTF-8 as already mentioned. @@ -426,7 +417,9 @@ Marc-Andr? Lemburg gave a presentation at EuroPython 2002 titled "Python and Unicode". A PDF version of his slides is available at , and is an -excellent overview of the design of Python's Unicode features. +excellent overview of the design of Python's Unicode features (based on Python +2, where the Unicode string type is called ``unicode`` and literals start with +``u``). Reading and Writing Unicode Data @@ -444,8 +437,8 @@ Unicode data is usually converted to a particular encoding before it gets written to disk or sent over a socket. It's possible to do all the work -yourself: open a file, read an 8-bit string from it, and convert the string with -``unicode(str, encoding)``. However, the manual approach is not recommended. +yourself: open a file, read an 8-bit byte string from it, and convert the string +with ``str(bytes, encoding)``. However, the manual approach is not recommended. One problem is the multi-byte nature of encodings; one Unicode character can be represented by several bytes. If you want to read the file in arbitrary-sized @@ -459,39 +452,28 @@ The solution would be to use the low-level decoding interface to catch the case of partial coding sequences. The work of implementing this has already been -done for you: the :mod:`codecs` module includes a version of the :func:`open` -function that returns a file-like object that assumes the file's contents are in -a specified encoding and accepts Unicode parameters for methods such as -``.read()`` and ``.write()``. - -The function's parameters are ``open(filename, mode='rb', encoding=None, -errors='strict', buffering=1)``. ``mode`` can be ``'r'``, ``'w'``, or ``'a'``, -just like the corresponding parameter to the regular built-in ``open()`` -function; add a ``'+'`` to update the file. ``buffering`` is similarly parallel -to the standard function's parameter. ``encoding`` is a string giving the -encoding to use; if it's left as ``None``, a regular Python file object that -accepts 8-bit strings is returned. Otherwise, a wrapper object is returned, and -data written to or read from the wrapper object will be converted as needed. -``errors`` specifies the action for encoding errors and can be one of the usual -values of 'strict', 'ignore', and 'replace'. +done for you: the built-in :func:`open` function can return a file-like object +that assumes the file's contents are in a specified encoding and accepts Unicode +parameters for methods such as ``.read()`` and ``.write()``. This works through +:func:`open`\'s *encoding* and *errors* parameters which are interpreted just +like those in string objects' :meth:`encode` and :meth:`decode` methods. Reading Unicode from a file is therefore simple:: - import codecs - f = codecs.open('unicode.rst', encoding='utf-8') + f = open('unicode.rst', encoding='utf-8') for line in f: print(repr(line)) It's also possible to open files in update mode, allowing both reading and writing:: - f = codecs.open('test', encoding='utf-8', mode='w+') + f = open('test', encoding='utf-8', mode='w+') f.write('\u4500 blah blah blah\n') f.seek(0) print(repr(f.readline()[:1])) f.close() -Unicode character U+FEFF is used as a byte-order mark (BOM), and is often +The Unicode character U+FEFF is used as a byte-order mark (BOM), and is often written as the first character of a file in order to assist with autodetection of the file's byte ordering. Some encodings, such as UTF-16, expect a BOM to be present at the start of a file; when such an encoding is used, the BOM will be @@ -500,6 +482,12 @@ and 'utf-16-be' for little-endian and big-endian encodings, that specify one particular byte ordering and don't skip the BOM. +In some areas, it is also convention to use a "BOM" at the start of UTF-8 +encoded files; the name is misleading since UTF-8 is not byte-order dependent. +The mark simply announces that the file is encoded in UTF-8. Use the +'utf-8-sig' codec to automatically skip the mark if present for reading such +files. + Unicode filenames ----------------- @@ -528,31 +516,36 @@ filenames. :func:`os.listdir`, which returns filenames, raises an issue: should it return -the Unicode version of filenames, or should it return 8-bit strings containing +the Unicode version of filenames, or should it return byte strings containing the encoded versions? :func:`os.listdir` will do both, depending on whether you -provided the directory path as an 8-bit string or a Unicode string. If you pass -a Unicode string as the path, filenames will be decoded using the filesystem's -encoding and a list of Unicode strings will be returned, while passing an 8-bit -path will return the 8-bit versions of the filenames. For example, assuming the -default filesystem encoding is UTF-8, running the following program:: +provided the directory path as a byte string or a Unicode string. If you pass a +Unicode string as the path, filenames will be decoded using the filesystem's +encoding and a list of Unicode strings will be returned, while passing a byte +path will return the byte string versions of the filenames. For example, +assuming the default filesystem encoding is UTF-8, running the following +program:: fn = 'filename\u4500abc' f = open(fn, 'w') f.close() import os + print(os.listdir(b'.')) print(os.listdir('.')) - print(os.listdir(u'.')) will produce the following output:: amk:~$ python t.py - ['.svn', 'filename\xe4\x94\x80abc', ...] + [b'.svn', b'filename\xe4\x94\x80abc', ...] ['.svn', 'filename\u4500abc', ...] The first list contains UTF-8-encoded filenames, and the second list contains the Unicode versions. +Note that in most occasions, the Uniode APIs should be used. The bytes APIs +should only be used on systems where undecodable file names can be present, +i.e. Unix systems. + Tips for Writing Unicode-aware Programs @@ -566,12 +559,10 @@ Software should only work with Unicode strings internally, converting to a particular encoding on output. -If you attempt to write processing functions that accept both Unicode and 8-bit +If you attempt to write processing functions that accept both Unicode and byte strings, you will find your program vulnerable to bugs wherever you combine the -two different kinds of strings. Python's default encoding is ASCII, so whenever -a character with an ASCII value > 127 is in the input data, you'll get a -:exc:`UnicodeDecodeError` because that character can't be handled by the ASCII -encoding. +two different kinds of strings. There is no automatic encoding or decoding if +you do e.g. ``str + bytes``, a :exc:`TypeError` is raised for this expression. It's easy to miss such problems if you only test your software with data that doesn't contain any accents; everything will seem to work, but there's actually @@ -594,7 +585,7 @@ filename, and you want to disallow paths with a '/' character. You might write this code:: - def read_file (filename, encoding): + def read_file(filename, encoding): if '/' in filename: raise ValueError("'/' not allowed in filenames") unicode_name = filename.decode(encoding) @@ -631,9 +622,10 @@ Version 1.02: posted August 16 2005. Corrects factual errors. +Version 1.1: Feb-Nov 2008. Updates the document with respect to Python 3 changes. + .. comment Additional topic: building Python w/ UCS2 or UCS4 support -.. comment Describe obscure -U switch somewhere? .. comment Describe use of codecs.StreamRecoder and StreamReaderWriter .. comment From python-3000-checkins at python.org Sat Nov 22 17:13:42 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Sat, 22 Nov 2008 17:13:42 +0100 (CET) Subject: [Python-3000-checkins] r67340 - python/branches/py3k/Tools/msi/uuids.py Message-ID: <20081122161342.0839E1E4002@bag.python.org> Author: martin.v.loewis Date: Sat Nov 22 17:13:41 2008 New Revision: 67340 Log: Add 3.0rc3 UUID. Modified: python/branches/py3k/Tools/msi/uuids.py Modified: python/branches/py3k/Tools/msi/uuids.py ============================================================================== --- python/branches/py3k/Tools/msi/uuids.py (original) +++ python/branches/py3k/Tools/msi/uuids.py Sat Nov 22 17:13:41 2008 @@ -58,5 +58,6 @@ '3.0.114': '{e95c31af-69be-4dd7-96e6-e5fc85e660e6}', # 3.0b4 '3.0.121': '{d0979c5e-cd3c-42ec-be4c-e294da793573}', # 3.0c1 '3.0.122': '{f707b8e9-a257-4045-818e-4923fc20fbb6}', # 3.0c2 + '3.0.123': '{5e7208f1-8643-4ea2-ab5e-4644887112e3}', # 3.0c3 '3.0.150': '{e0e56e21-55de-4f77-a109-1baa72348743}', # 3.0.0 } From python-3000-checkins at python.org Sat Nov 22 19:30:57 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 22 Nov 2008 19:30:57 +0100 (CET) Subject: [Python-3000-checkins] r67341 - python/branches/py3k Message-ID: <20081122183057.D137D1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 22 19:30:57 2008 New Revision: 67341 Log: Blocked revisions 67307 via svnmerge ........ r67307 | amaury.forgeotdarc | 2008-11-20 17:34:31 -0600 (Thu, 20 Nov 2008) | 9 lines Fixed issue #4233. Changed semantic of _fileio.FileIO's close() method on file objects with closefd=False. The file descriptor is still kept open but the file object behaves like a closed file. The FileIO object also got a new readonly attribute closefd. Approved by Barry Backport of r67106 from the py3k branch ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Nov 22 23:18:04 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 22 Nov 2008 23:18:04 +0100 (CET) Subject: [Python-3000-checkins] r67345 - in python/branches/py3k: Doc/library/multiprocessing.rst Doc/library/pdb.rst Doc/library/sys.rst Lib/test/test_bytes.py Lib/uuid.py Misc/NEWS PC/VC6/pythoncore.dsp PC/VS7.1/pythoncore.vcproj PC/VS8.0/pythoncore.vcproj PC/os2vacpp/makefile PC/os2vacpp/makefile.omk PCbuild/pythoncore.vcproj Python/pythonrun.c Message-ID: <20081122221804.794911E4002@bag.python.org> Author: amaury.forgeotdarc Date: Sat Nov 22 23:18:04 2008 New Revision: 67345 Log: Merged revisions 67295,67301-67302,67318,67330,67342-67343 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67295 | benjamin.peterson | 2008-11-20 05:05:12 +0100 (jeu., 20 nov. 2008) | 1 line move useful sys.settrace information to the function's documentation from the debugger ........ r67301 | benjamin.peterson | 2008-11-20 22:25:31 +0100 (jeu., 20 nov. 2008) | 1 line fix indentation and a sphinx warning ........ r67302 | benjamin.peterson | 2008-11-20 22:44:23 +0100 (jeu., 20 nov. 2008) | 1 line oops! didn't mean to disable that test ........ r67318 | amaury.forgeotdarc | 2008-11-21 23:05:48 +0100 (ven., 21 nov. 2008) | 4 lines #4363: Let uuid.uuid1() and uuid.uuid4() run even if the ctypes module is not present. Will backport to 2.6 ........ r67330 | georg.brandl | 2008-11-22 09:34:14 +0100 (sam., 22 nov. 2008) | 2 lines #4364: fix attribute name on ctypes object. ........ r67342 | amaury.forgeotdarc | 2008-11-22 20:39:38 +0100 (sam., 22 nov. 2008) | 3 lines yuvconvert.c is a part of the "sv" module, an old IRIX thing and certainly not useful for any Windows build. ........ r67343 | amaury.forgeotdarc | 2008-11-22 21:01:18 +0100 (sam., 22 nov. 2008) | 5 lines #3996: On Windows, PyOS_CheckStack is supposed to protect the interpreter from stack overflow. But doing this, it always crashes when the stack is nearly full. Reviewed by Martin von Loewis. Will backport to 2.6. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/multiprocessing.rst python/branches/py3k/Doc/library/pdb.rst python/branches/py3k/Doc/library/sys.rst python/branches/py3k/Lib/test/test_bytes.py python/branches/py3k/Lib/uuid.py python/branches/py3k/Misc/NEWS python/branches/py3k/PC/VC6/pythoncore.dsp python/branches/py3k/PC/VS7.1/pythoncore.vcproj python/branches/py3k/PC/VS8.0/pythoncore.vcproj python/branches/py3k/PC/os2vacpp/makefile python/branches/py3k/PC/os2vacpp/makefile.omk python/branches/py3k/PCbuild/pythoncore.vcproj python/branches/py3k/Python/pythonrun.c Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Sat Nov 22 23:18:04 2008 @@ -872,7 +872,7 @@ Note that *lock* is a keyword only argument. - Note that an array of :data:`ctypes.c_char` has *value* and *rawvalue* + Note that an array of :data:`ctypes.c_char` has *value* and *raw* attributes which allow one to use it to store and retrieve strings. @@ -921,7 +921,7 @@ :func:`Value` instead to make sure that access is automatically synchronized using a lock. - Note that an array of :data:`ctypes.c_char` has ``value`` and ``rawvalue`` + Note that an array of :data:`ctypes.c_char` has ``value`` and ``raw`` attributes which allow one to use it to store and retrieve strings -- see documentation for :mod:`ctypes`. Modified: python/branches/py3k/Doc/library/pdb.rst ============================================================================== --- python/branches/py3k/Doc/library/pdb.rst (original) +++ python/branches/py3k/Doc/library/pdb.rst Sat Nov 22 23:18:04 2008 @@ -336,68 +336,3 @@ q(uit) Quit from the debugger. The program being executed is aborted. - - -.. _debugger-hooks: - -How It Works -============ - -Some changes were made to the interpreter: - -* ``sys.settrace(func)`` sets the global trace function - -* there can also a local trace function (see later) - -Trace functions have three arguments: *frame*, *event*, and *arg*. *frame* is -the current stack frame. *event* is a string: ``'call'``, ``'line'``, -``'return'``, ``'exception'``, ``'c_call'``, ``'c_return'``, or -``'c_exception'``. *arg* depends on the event type. - -The global trace function is invoked (with *event* set to ``'call'``) whenever a -new local scope is entered; it should return a reference to the local trace -function to be used that scope, or ``None`` if the scope shouldn't be traced. - -The local trace function should return a reference to itself (or to another -function for further tracing in that scope), or ``None`` to turn off tracing in -that scope. - -Instance methods are accepted (and very useful!) as trace functions. - -The events have the following meaning: - -``'call'`` - A function is called (or some other code block entered). The global trace - function is called; *arg* is ``None``; the return value specifies the local - trace function. - -``'line'`` - The interpreter is about to execute a new line of code (sometimes multiple line - events on one line exist). The local trace function is called; *arg* is - ``None``; the return value specifies the new local trace function. - -``'return'`` - A function (or other code block) is about to return. The local trace function - is called; *arg* is the value that will be returned. The trace function's - return value is ignored. - -``'exception'`` - An exception has occurred. The local trace function is called; *arg* is a - triple ``(exception, value, traceback)``; the return value specifies the new - local trace function. - -``'c_call'`` - A C function is about to be called. This may be an extension function or a - builtin. *arg* is the C function object. - -``'c_return'`` - A C function has returned. *arg* is ``None``. - -``'c_exception'`` - A C function has thrown an exception. *arg* is ``None``. - -Note that as an exception is propagated down the chain of callers, an -``'exception'`` event is generated at each level. - -For more information on code and frame objects, refer to :ref:`types`. - Modified: python/branches/py3k/Doc/library/sys.rst ============================================================================== --- python/branches/py3k/Doc/library/sys.rst (original) +++ python/branches/py3k/Doc/library/sys.rst Sat Nov 22 23:18:04 2008 @@ -623,11 +623,60 @@ single: debugger Set the system's trace function, which allows you to implement a Python - source code debugger in Python. See section :ref:`debugger-hooks` in the - chapter on the Python debugger. The function is thread-specific; for a + source code debugger in Python. The function is thread-specific; for a debugger to support multiple threads, it must be registered using :func:`settrace` for each thread being debugged. + Trace functions should have three arguments: *frame*, *event*, and + *arg*. *frame* is the current stack frame. *event* is a string: ``'call'``, + ``'line'``, ``'return'``, ``'exception'``, ``'c_call'``, ``'c_return'``, or + ``'c_exception'``. *arg* depends on the event type. + + The trace function is invoked (with *event* set to ``'call'``) whenever a new + local scope is entered; it should return a reference to a local trace + function to be used that scope, or ``None`` if the scope shouldn't be traced. + + The local trace function should return a reference to itself (or to another + function for further tracing in that scope), or ``None`` to turn off tracing + in that scope. + + The events have the following meaning: + + ``'call'`` + A function is called (or some other code block entered). The + global trace function is called; *arg* is ``None``; the return value + specifies the local trace function. + + ``'line'`` + The interpreter is about to execute a new line of code (sometimes multiple + line events on one line exist). The local trace function is called; *arg* + is ``None``; the return value specifies the new local trace function. + + ``'return'`` + A function (or other code block) is about to return. The local trace + function is called; *arg* is the value that will be returned. The trace + function's return value is ignored. + + ``'exception'`` + An exception has occurred. The local trace function is called; *arg* is a + tuple ``(exception, value, traceback)``; the return value specifies the + new local trace function. + + ``'c_call'`` + A C function is about to be called. This may be an extension function or + a builtin. *arg* is the C function object. + + ``'c_return'`` + A C function has returned. *arg* is ``None``. + + ``'c_exception'`` + A C function has thrown an exception. *arg* is ``None``. + + Note that as an exception is propagated down the chain of callers, an + ``'exception'`` event is generated at each level. + + For more information on code and frame objects, refer to :ref:`types`. + .. note:: The :func:`settrace` function is intended only for implementing debuggers, Modified: python/branches/py3k/Lib/test/test_bytes.py ============================================================================== --- python/branches/py3k/Lib/test/test_bytes.py (original) +++ python/branches/py3k/Lib/test/test_bytes.py Sat Nov 22 23:18:04 2008 @@ -742,7 +742,7 @@ # Issue 4348. Make sure that operations that don't mutate the array # copy the bytes. b = bytearray(b'abc') - #self.assertFalse(b is b.replace(b'abc', b'cde', 0)) + self.assertFalse(b is b.replace(b'abc', b'cde', 0)) t = bytearray([i for i in range(256)]) x = bytearray(b'') Modified: python/branches/py3k/Lib/uuid.py ============================================================================== --- python/branches/py3k/Lib/uuid.py (original) +++ python/branches/py3k/Lib/uuid.py Sat Nov 22 23:18:04 2008 @@ -500,8 +500,8 @@ # When the system provides a version-1 UUID generator, use it (but don't # use UuidCreate here because its UUIDs don't conform to RFC 4122). - _buffer = ctypes.create_string_buffer(16) if _uuid_generate_time and node is clock_seq is None: + _buffer = ctypes.create_string_buffer(16) _uuid_generate_time(_buffer) return UUID(bytes=bytes_(_buffer.raw)) @@ -537,8 +537,8 @@ """Generate a random UUID.""" # When the system provides a version-4 UUID generator, use it. - _buffer = ctypes.create_string_buffer(16) if _uuid_generate_random: + _buffer = ctypes.create_string_buffer(16) _uuid_generate_random(_buffer) return UUID(bytes=bytes_(_buffer.raw)) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Nov 22 23:18:04 2008 @@ -12,6 +12,13 @@ Core and Builtins ----------------- +- Issue #3996: On Windows, the PyOS_CheckStack function would cause the + interpreter to abort ("Fatal Python error: Could not reset the stack!") + instead of throwing a MemoryError. + +- Issue #4367: Python would segfault during compiling when the unicodedata + module couldn't be imported and \N escapes were present. + Library ------- @@ -48,6 +55,9 @@ Library ------- +- Issue #4363: The uuid.uuid1() and uuid.uuid4() functions now work even if + the ctypes module is not present. + - FileIO's mode attribute now always includes ``"b"``. - Issue #3799: Fix dbm.dumb to accept strings as well as bytes for keys. String Modified: python/branches/py3k/PC/VC6/pythoncore.dsp ============================================================================== --- python/branches/py3k/PC/VC6/pythoncore.dsp (original) +++ python/branches/py3k/PC/VC6/pythoncore.dsp Sat Nov 22 23:18:04 2008 @@ -723,10 +723,6 @@ # End Source File # Begin Source File -SOURCE=..\..\Modules\yuvconvert.c -# End Source File -# Begin Source File - SOURCE=..\..\Modules\zipimport.c # End Source File # Begin Source File Modified: python/branches/py3k/PC/VS7.1/pythoncore.vcproj ============================================================================== --- python/branches/py3k/PC/VS7.1/pythoncore.vcproj (original) +++ python/branches/py3k/PC/VS7.1/pythoncore.vcproj Sat Nov 22 23:18:04 2008 @@ -804,9 +804,6 @@ RelativePath="..\..\Modules\xxsubtype.c"> - - Modified: python/branches/py3k/PC/VS8.0/pythoncore.vcproj ============================================================================== --- python/branches/py3k/PC/VS8.0/pythoncore.vcproj (original) +++ python/branches/py3k/PC/VS8.0/pythoncore.vcproj Sat Nov 22 23:18:04 2008 @@ -1143,14 +1143,6 @@ > - - - - Modified: python/branches/py3k/PC/os2vacpp/makefile ============================================================================== --- python/branches/py3k/PC/os2vacpp/makefile (original) +++ python/branches/py3k/PC/os2vacpp/makefile Sat Nov 22 23:18:04 2008 @@ -200,8 +200,7 @@ $(PATHOBJ)\StropModule.obj \ $(PATHOBJ)\StructModule.obj \ $(PATHOBJ)\TimeModule.obj \ - $(PATHOBJ)\ThreadModule.obj \ - $(PATHOBJ)\YUVConvert.obj + $(PATHOBJ)\ThreadModule.obj # Standalone Parser Generator Program (Shares Some of Python's Modules) PGEN = \ @@ -894,8 +893,6 @@ $(PY_INCLUDE)\sliceobject.h $(PY_INCLUDE)\stringobject.h \ $(PY_INCLUDE)\sysmodule.h $(PY_INCLUDE)\traceback.h $(PY_INCLUDE)\tupleobject.h -yuvconvert.obj: $(PY_MODULES)\yuv.h - zlibmodule.obj: $(PY_INCLUDE)\abstract.h $(PY_INCLUDE)\ceval.h $(PY_INCLUDE)\classobject.h \ $(PY_INCLUDE)\cobject.h $(PY_INCLUDE)\complexobject.h pyconfig.h \ $(PY_INCLUDE)\dictobject.h $(PY_INCLUDE)\fileobject.h $(PY_INCLUDE)\floatobject.h \ Modified: python/branches/py3k/PC/os2vacpp/makefile.omk ============================================================================== --- python/branches/py3k/PC/os2vacpp/makefile.omk (original) +++ python/branches/py3k/PC/os2vacpp/makefile.omk Sat Nov 22 23:18:04 2008 @@ -161,8 +161,7 @@ StropModule.obj \ StructModule.obj \ TimeModule.obj \ - ThreadModule.obj \ - YUVConvert.obj + ThreadModule.obj # Omitted Modules (and Description/Reason): # @@ -645,8 +644,6 @@ pythonrun.h rangeobject.h sliceobject.h stringobject.h sysmodule.h \ traceback.h tupleobject.h -yuvconvert.obj: yuv.h - zlibmodule.obj: abstract.h ceval.h classobject.h cobject.h complexobject.h \ pyconfig.h dictobject.h fileobject.h floatobject.h funcobject.h \ import.h intobject.h intrcheck.h listobject.h longobject.h \ Modified: python/branches/py3k/PCbuild/pythoncore.vcproj ============================================================================== --- python/branches/py3k/PCbuild/pythoncore.vcproj (original) +++ python/branches/py3k/PCbuild/pythoncore.vcproj Sat Nov 22 23:18:04 2008 @@ -1143,14 +1143,6 @@ > - - - - Modified: python/branches/py3k/Python/pythonrun.c ============================================================================== --- python/branches/py3k/Python/pythonrun.c (original) +++ python/branches/py3k/Python/pythonrun.c Sat Nov 22 23:18:04 2008 @@ -2039,7 +2039,7 @@ EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { int errcode = _resetstkoflw(); - if (errcode) + if (errcode == 0) { Py_FatalError("Could not reset the stack!"); } From python-3000-checkins at python.org Sat Nov 22 23:59:15 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 22 Nov 2008 23:59:15 +0100 (CET) Subject: [Python-3000-checkins] r67346 - in python/branches/py3k/Modules: yuv.h yuvconvert.c Message-ID: <20081122225915.931341E4002@bag.python.org> Author: amaury.forgeotdarc Date: Sat Nov 22 23:59:15 2008 New Revision: 67346 Log: These files used to belong to the "sv" module, which was deleted. Removed: python/branches/py3k/Modules/yuv.h python/branches/py3k/Modules/yuvconvert.c Deleted: python/branches/py3k/Modules/yuv.h ============================================================================== --- python/branches/py3k/Modules/yuv.h Sat Nov 22 23:59:15 2008 +++ (empty file) @@ -1,99 +0,0 @@ - -#ifndef Py_YUV_H -#define Py_YUV_H -#ifdef __cplusplus -extern "C" { -#endif - -/* - * SVideo YUV 4:1:1 format. - * - * 4 consecutive quadwords describe 8 pixels on 2 lines, as depicted - * below. An array of (width/4) of the below structure describes 2 - * scan lines. - * - * +-------------------+ - * | 00 | 01 | 02 | 03 | . . . - * +-------------------+ - * | 10 | 11 | 12 | 13 | . . . - * +-------------------+ - */ -struct yuv411 { - struct { - unsigned int dummy:8; - unsigned int y0:8; - unsigned int u0:2; - unsigned int v0:2; - unsigned int y1:8; - unsigned int u1:2; - unsigned int v1:2; - } v[4]; -}; - -#define YUV411_Y00(y) (y).v[0].y0 -#define YUV411_Y01(y) (y).v[1].y0 -#define YUV411_Y02(y) (y).v[2].y0 -#define YUV411_Y03(y) (y).v[3].y0 -#define YUV411_Y10(y) (y).v[0].y1 -#define YUV411_Y11(y) (y).v[1].y1 -#define YUV411_Y12(y) (y).v[2].y1 -#define YUV411_Y13(y) (y).v[3].y1 -#define YUV411_U00(y) ((y).v[0].u0<<6|(y).v[1].u0<<4|(y).v[2].u0<<2|(y).v[3].u0) -#define YUV411_U01(y) YUV411_U00(y) -#define YUV411_U02(y) YUV411_U00(y) -#define YUV411_U03(y) YUV411_U00(y) -#define YUV411_U10(y) ((y).v[0].u1<<6|(y).v[1].u1<<4|(y).v[2].u1<<2|(y).v[3].u1) -#define YUV411_U11(y) YUV411_U10(y) -#define YUV411_U12(y) YUV411_U10(y) -#define YUV411_U13(y) YUV411_U10(y) -#define YUV411_V00(y) ((y).v[0].v0<<6|(y).v[1].v0<<4|(y).v[2].v0<<2|(y).v[3].v0) -#define YUV411_V01(y) YUV411_V00(y) -#define YUV411_V02(y) YUV411_V00(y) -#define YUV411_V03(y) YUV411_V00(y) -#define YUV411_V10(y) ((y).v[0].v1<<6|(y).v[1].v1<<4|(y).v[2].v1<<2|(y).v[3].v1) -#define YUV411_V11(y) YUV411_V10(y) -#define YUV411_V12(y) YUV411_V10(y) -#define YUV411_V13(y) YUV411_V10(y) - -/* - * Compression Library YUV 4:2:2 format. - * - * 1 longword describes 2 pixels. - * - * +-------+ - * | 0 | 1 | - * +-------+ - */ -struct yuv422 { - unsigned int u:8; - unsigned int y0:8; - unsigned int v:8; - unsigned int y1:8; -}; -#define YUV422_Y0(y) (y).y0 -#define YUV422_Y1(y) (y).y1 -#define YUV422_U0(y) (y).u -#define YUV422_U1(y) (y).u -#define YUV422_V0(y) (y).v -#define YUV422_V1(y) (y).v - -/* - * Compression library YUV 4:2:2 Duplicate Chroma format. - * - * This is like the previous format, but the U and V values are - * duplicated vertically (and hence there is some redundancy in the - * data). With other words, lines 2*n and 2*n+1 have the same U and V - * values but different Y values. - */ - -/* - * Conversion functions. - */ -void yuv_sv411_to_cl422dc(int, void *, void *, int, int); -void yuv_sv411_to_cl422dc_quartersize(int, void *, void *, int, int); -void yuv_sv411_to_cl422dc_sixteenthsize(int, void *, void *, int, int); - -#ifdef __cplusplus -} -#endif -#endif /* !Py_YUV_H */ Deleted: python/branches/py3k/Modules/yuvconvert.c ============================================================================== --- python/branches/py3k/Modules/yuvconvert.c Sat Nov 22 23:59:15 2008 +++ (empty file) @@ -1,118 +0,0 @@ - -#include "yuv.h" - -void -yuv_sv411_to_cl422dc(int invert, void *data, void *yuv, int width, int height) -{ - struct yuv411 *in = data; - struct yuv422 *out_even = yuv; - struct yuv422 *out_odd = out_even + width / 2; - int i, j; /* counters */ - - for (i = height / 2; i--; ) { - for (j = width / 4; j--; ) { - YUV422_Y0(*out_even) = YUV411_Y00(*in); - YUV422_U0(*out_even) = YUV411_U00(*in); - YUV422_V0(*out_even) = YUV411_V00(*in); - YUV422_Y1(*out_even) = YUV411_Y01(*in); - out_even++; - YUV422_Y0(*out_even) = YUV411_Y02(*in); - YUV422_U0(*out_even) = YUV411_U02(*in); - YUV422_V0(*out_even) = YUV411_V02(*in); - YUV422_Y1(*out_even) = YUV411_Y03(*in); - out_even++; - YUV422_Y0(*out_odd) = YUV411_Y10(*in); - YUV422_U0(*out_odd) = YUV411_U10(*in); - YUV422_V0(*out_odd) = YUV411_V10(*in); - YUV422_Y1(*out_odd) = YUV411_Y11(*in); - out_odd++; - YUV422_Y0(*out_odd) = YUV411_Y12(*in); - YUV422_U0(*out_odd) = YUV411_U12(*in); - YUV422_V0(*out_odd) = YUV411_V12(*in); - YUV422_Y1(*out_odd) = YUV411_Y13(*in); - out_odd++; - in++; - } - out_even += width / 2; - out_odd += width / 2; - } -} - -void -yuv_sv411_to_cl422dc_quartersize(int invert, void *data, void *yuv, - int width, int height) -{ - int w4 = width / 4; /* quarter of width is used often */ - struct yuv411 *in_even = data; - struct yuv411 *in_odd = in_even + w4; - struct yuv422 *out_even = yuv; - struct yuv422 *out_odd = out_even + w4; - int i, j; /* counters */ - int u, v; /* U and V values */ - - for (i = height / 4; i--; ) { - for (j = w4; j--; ) { - u = YUV411_U00(*in_even); - v = YUV411_V00(*in_even); - - YUV422_Y0(*out_even) = YUV411_Y00(*in_even); - YUV422_U0(*out_even) = u; - YUV422_V0(*out_even) = v; - YUV422_Y1(*out_even) = YUV411_Y02(*in_even); - - YUV422_Y0(*out_odd) = YUV411_Y10(*in_odd); - YUV422_U0(*out_odd) = u; - YUV422_V0(*out_odd) = v; - YUV422_Y1(*out_odd) = YUV411_Y12(*in_odd); - - in_even++; - in_odd++; - out_even++; - out_odd++; - } - in_even += w4; - in_odd += w4; - out_even += w4; - out_odd += w4; - } -} - -void -yuv_sv411_to_cl422dc_sixteenthsize(int invert, void *data, void *yuv, - int width, int height) -{ - int w4_3 = 3 * width / 4; /* three quarters of width is used often */ - int w8 = width / 8; /* and so is one eighth */ - struct yuv411 *in_even = data; - struct yuv411 *in_odd = in_even + width / 2; - struct yuv422 *out_even = yuv; - struct yuv422 *out_odd = out_even + w8; - int i, j; /* counters */ - int u, v; /* U and V values */ - - for (i = height / 8; i--; ) { - for (j = w8; j--; ) { - u = YUV411_U00(in_even[0]); - v = YUV411_V00(in_even[0]); - - YUV422_Y0(*out_even) = YUV411_Y00(in_even[0]); - YUV422_U0(*out_even) = u; - YUV422_V0(*out_even) = v; - YUV422_Y1(*out_even) = YUV411_Y00(in_even[1]); - - YUV422_Y0(*out_odd) = YUV411_Y00(in_odd[0]); - YUV422_U0(*out_odd) = u; - YUV422_V0(*out_odd) = v; - YUV422_Y1(*out_odd) = YUV411_Y00(in_even[1]); - - in_even += 2; - in_odd += 2; - out_even++; - out_odd++; - } - in_even += w4_3; - in_odd += w4_3; - out_even += w8; - out_odd += w8; - } -} From python-3000-checkins at python.org Sun Nov 23 02:55:23 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 23 Nov 2008 02:55:23 +0100 (CET) Subject: [Python-3000-checkins] r67347 - python/branches/py3k/Doc/library/shlex.rst Message-ID: <20081123015523.97B991E4002@bag.python.org> Author: benjamin.peterson Date: Sun Nov 23 02:55:23 2008 New Revision: 67347 Log: remove warning about not accepting unicode I don't know if it actually works with unicode, though... Modified: python/branches/py3k/Doc/library/shlex.rst Modified: python/branches/py3k/Doc/library/shlex.rst ============================================================================== --- python/branches/py3k/Doc/library/shlex.rst (original) +++ python/branches/py3k/Doc/library/shlex.rst Sun Nov 23 02:55:23 2008 @@ -15,10 +15,6 @@ writing minilanguages, (for example, in run control files for Python applications) or for parsing quoted strings. -.. note:: - - The :mod:`shlex` module currently does not support Unicode input. - The :mod:`shlex` module defines the following functions: From python-3000-checkins at python.org Sun Nov 23 14:40:48 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Sun, 23 Nov 2008 14:40:48 +0100 (CET) Subject: [Python-3000-checkins] r67350 - python/branches/py3k/Modules/Setup.dist Message-ID: <20081123134048.E442C1E4002@bag.python.org> Author: matthias.klose Date: Sun Nov 23 14:40:48 2008 New Revision: 67350 Log: Merge 67349 from the trunk: - Modules/Setup.dist: Mention _functools in section "Modules that should always be present (non UNIX dependent)" Modified: python/branches/py3k/Modules/Setup.dist Modified: python/branches/py3k/Modules/Setup.dist ============================================================================== --- python/branches/py3k/Modules/Setup.dist (original) +++ python/branches/py3k/Modules/Setup.dist Sun Nov 23 14:40:48 2008 @@ -164,6 +164,7 @@ #_collections _collectionsmodule.c # Container types #itertools itertoolsmodule.c # Functions creating iterators for efficient looping #atexit atexitmodule.c # Register functions to be run at interpreter-shutdown +#_functools functoolsmodule.c # Tools for working with functions and callable objects #unicodedata unicodedata.c # static Unicode character database From python-3000-checkins at python.org Sun Nov 23 14:55:26 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Sun, 23 Nov 2008 14:55:26 +0100 (CET) Subject: [Python-3000-checkins] r67354 - python/branches/py3k/Modules/Setup.dist Message-ID: <20081123135526.412A31E4002@bag.python.org> Author: matthias.klose Date: Sun Nov 23 14:55:26 2008 New Revision: 67354 Log: - Fix typo in last checkin Modified: python/branches/py3k/Modules/Setup.dist Modified: python/branches/py3k/Modules/Setup.dist ============================================================================== --- python/branches/py3k/Modules/Setup.dist (original) +++ python/branches/py3k/Modules/Setup.dist Sun Nov 23 14:55:26 2008 @@ -164,7 +164,7 @@ #_collections _collectionsmodule.c # Container types #itertools itertoolsmodule.c # Functions creating iterators for efficient looping #atexit atexitmodule.c # Register functions to be run at interpreter-shutdown -#_functools functoolsmodule.c # Tools for working with functions and callable objects +#_functools _functoolsmodule.c # Tools for working with functions and callable objects #unicodedata unicodedata.c # static Unicode character database From python-3000-checkins at python.org Mon Nov 24 00:49:16 2008 From: python-3000-checkins at python.org (gregory.p.smith) Date: Mon, 24 Nov 2008 00:49:16 +0100 (CET) Subject: [Python-3000-checkins] r67361 - in python/branches/py3k/Doc: c-api/arg.rst extending/extending.rst Message-ID: <20081123234916.F2A2B1E4002@bag.python.org> Author: gregory.p.smith Date: Mon Nov 24 00:49:16 2008 New Revision: 67361 Log: Document PY_SSIZE_T_CLEAN use and behavior for PyArg_ParseTuple and mention that it will become the default in a future python version. Modified: python/branches/py3k/Doc/c-api/arg.rst python/branches/py3k/Doc/extending/extending.rst Modified: python/branches/py3k/Doc/c-api/arg.rst ============================================================================== --- python/branches/py3k/Doc/c-api/arg.rst (original) +++ python/branches/py3k/Doc/c-api/arg.rst Mon Nov 24 00:49:16 2008 @@ -42,12 +42,18 @@ responsible** for calling ``PyBuffer_Release`` with the structure after it has processed the data. -``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int] +``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int or :ctype:`Py_ssize_t`] This variant on ``s*`` stores into two C variables, the first one a pointer to a character string, the second one its length. All other read-buffer compatible objects pass back a reference to the raw internal data representation. Since this format doesn't allow writable buffer compatible - objects like byte arrays, ``s*`` is to be preferred. + objects like byte arrays, ``s*`` is to be preferred. The type of + the length argument (int or :ctype:`Py_ssize_t`) is controlled by + defining the macro :cmacro:`PY_SSIZE_T_CLEAN` before including + :file:`Python.h`. If the macro was defined, length is a :ctype:`Py_ssize_t` + rather than an int. This behavior will change in a future Python + version to only support :ctype:`Py_ssize_t` and drop int support. + It is best to always define :cmacro:`PY_SSIZE_T_CLEAN`. ``y`` (bytes object) [const char \*] This variant on ``s`` converts a Python bytes or bytearray object to a C Modified: python/branches/py3k/Doc/extending/extending.rst ============================================================================== --- python/branches/py3k/Doc/extending/extending.rst (original) +++ python/branches/py3k/Doc/extending/extending.rst Mon Nov 24 00:49:16 2008 @@ -587,11 +587,16 @@ Some example calls:: + #define PY_SSIZE_T_CLEAN /* Make "s#" use Py_ssize_t rather than int. */ + #include + +:: + int ok; int i, j; long k, l; const char *s; - int size; + Py_ssize_t size; ok = PyArg_ParseTuple(args, ""); /* No arguments */ /* Python call: f() */ From python-3000-checkins at python.org Mon Nov 24 22:09:59 2008 From: python-3000-checkins at python.org (brett.cannon) Date: Mon, 24 Nov 2008 22:09:59 +0100 (CET) Subject: [Python-3000-checkins] r67369 - in python/branches/py3k: Lib/dbm/dumb.py Misc/NEWS Message-ID: <20081124210959.249331E4002@bag.python.org> Author: brett.cannon Date: Mon Nov 24 22:09:58 2008 New Revision: 67369 Log: dbm.dumb was opening files without specifying the encoding. Caused problem on at least OS X where the default is macroman. Closes issue #4382. Modified: python/branches/py3k/Lib/dbm/dumb.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/dbm/dumb.py ============================================================================== --- python/branches/py3k/Lib/dbm/dumb.py (original) +++ python/branches/py3k/Lib/dbm/dumb.py Mon Nov 24 22:09:58 2008 @@ -66,9 +66,9 @@ # Mod by Jack: create data file if needed try: - f = _io.open(self._datfile, 'r') + f = _io.open(self._datfile, 'r', encoding="Latin-1") except IOError: - f = _io.open(self._datfile, 'w') + f = _io.open(self._datfile, 'w', encoding="Latin-1") self._chmod(self._datfile) f.close() self._update() @@ -77,7 +77,7 @@ def _update(self): self._index = {} try: - f = _io.open(self._dirfile, 'r') + f = _io.open(self._dirfile, 'r', encoding="Latin-1") except IOError: pass else: @@ -108,7 +108,7 @@ except self._os.error: pass - f = self._io.open(self._dirfile, 'w') + f = self._io.open(self._dirfile, 'w', encoding="Latin-1") self._chmod(self._dirfile) for key, pos_and_siz_pair in self._index.items(): # Use Latin-1 since it has no qualms with any value in any @@ -159,9 +159,9 @@ # the in-memory index dict, and append one to the directory file. def _addkey(self, key, pos_and_siz_pair): self._index[key] = pos_and_siz_pair - f = _io.open(self._dirfile, 'a') + f = _io.open(self._dirfile, 'a', encoding="Latin-1") self._chmod(self._dirfile) - f.write("%r, %r\n" % (key, pos_and_siz_pair)) + f.write("%r, %r\n" % (key.decode("Latin-1"), pos_and_siz_pair)) f.close() def __setitem__(self, key, val): @@ -169,8 +169,10 @@ key = key.encode('utf-8') elif not isinstance(key, (bytes, bytearray)): raise TypeError("keys must be bytes or strings") - if not isinstance(val, (bytes, bytearray)): - raise TypeError("values must be bytes") + if isinstance(val, str): + val = val.encode('utf-8') + elif not isinstance(val, (bytes, bytearray)): + raise TypeError("values must be bytes or strings") if key not in self._index: self._addkey(key, self._addval(val)) else: Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Mon Nov 24 22:09:58 2008 @@ -22,6 +22,9 @@ Library ------- +- Issue #4382: dbm.dumb did not specify the expected file encoding for opened + files. + - Issue #4383: When IDLE cannot make the connection to its subprocess, it would fail to properly display the error message. From python-3000-checkins at python.org Tue Nov 25 04:08:21 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Tue, 25 Nov 2008 04:08:21 +0100 (CET) Subject: [Python-3000-checkins] r67372 - in python/branches/py3k/Lib/lib2to3: fixes/fix_import.py fixes/fix_metaclass.py tests/test_fixers.py Message-ID: <20081125030821.57F5D1E4002@bag.python.org> Author: martin.v.loewis Date: Tue Nov 25 04:08:21 2008 New Revision: 67372 Log: Merged revisions 67183,67191,67371 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67183 | benjamin.peterson | 2008-11-11 04:51:33 +0100 (Di, 11 Nov 2008) | 1 line handle 'import x as y' in fix_imports; this still needs more work... ........ r67191 | benjamin.peterson | 2008-11-12 00:24:51 +0100 (Mi, 12 Nov 2008) | 1 line super() is good ........ r67371 | benjamin.peterson | 2008-11-24 23:02:00 +0100 (Mo, 24 Nov 2008) | 1 line don't blow up in the metaclass fixer when assignments in the class statement aren't simple ........ Modified: python/branches/py3k/Lib/lib2to3/ (props changed) python/branches/py3k/Lib/lib2to3/fixes/fix_import.py python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_import.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_import.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_import.py Tue Nov 25 04:08:21 2008 @@ -13,7 +13,7 @@ # Local imports from .. import fixer_base from os.path import dirname, join, exists, pathsep -from ..fixer_util import FromImport +from ..fixer_util import FromImport, syms class FixImport(fixer_base.BaseFix): @@ -26,11 +26,14 @@ def transform(self, node, results): imp = results['imp'] + mod_name = str(imp.children[0] if imp.type == syms.dotted_as_name \ + else imp) + if str(imp).startswith('.'): # Already a new-style import return - if not probably_a_local_import(str(imp), self.filename): + if not probably_a_local_import(str(mod_name), self.filename): # I guess this is a global import -- skip it! return Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_metaclass.py Tue Nov 25 04:08:21 2008 @@ -110,8 +110,11 @@ if simple_node.type == syms.simple_stmt and simple_node.children: expr_node = simple_node.children[0] if expr_node.type == syms.expr_stmt and expr_node.children: - leaf_node = expr_node.children[0] - if leaf_node.value == '__metaclass__': + # Check if the expr_node is a simple assignment. + left_node = expr_node.children[0] + if isinstance(left_node, Leaf) and \ + left_node.value == '__metaclass__': + # We found a assignment to __metaclass__. fixup_simple_stmt(node, i, simple_node) remove_trailing_newline(simple_node) yield (node, i, simple_node) Modified: python/branches/py3k/Lib/lib2to3/tests/test_fixers.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/test_fixers.py (original) +++ python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Tue Nov 25 04:08:21 2008 @@ -2622,7 +2622,7 @@ def check(self, b, a): self.unchanged("from future_builtins import map; " + b, a) - FixerTestCase.check(self, b, a) + super(Test_map, self).check(b, a) def test_prefix_preservation(self): b = """x = map( f, 'abc' )""" @@ -2729,7 +2729,7 @@ def check(self, b, a): self.unchanged("from future_builtins import zip; " + b, a) - FixerTestCase.check(self, b, a) + super(Test_zip, self).check(b, a) def test_zip_basic(self): b = """x = zip(a, b, c)""" @@ -3274,7 +3274,7 @@ fixer = "import" def setUp(self): - FixerTestCase.setUp(self) + super(Test_import, self).setUp() # Need to replace fix_import's exists method # so we can check that it's doing the right thing self.files_checked = [] @@ -3293,9 +3293,9 @@ def check_both(self, b, a): self.always_exists = True - FixerTestCase.check(self, b, a) + super(Test_import, self).check(b, a) self.always_exists = False - FixerTestCase.unchanged(self, b) + super(Test_import, self).unchanged(b) def test_files_checked(self): def p(path): @@ -3372,6 +3372,11 @@ a = "from . import foo, bar" self.check_both(b, a) + def test_import_as(self): + b = "import foo as x" + a = "from . import foo as x" + self.check_both(b, a) + def test_dotted_import(self): b = "import foo.bar" a = "from . import foo.bar" @@ -3766,6 +3771,17 @@ """ self.check(b, a) + b = """ + class X: + __metaclass__ = Meta + save.py = 23 + """ + a = """ + class X(metaclass=Meta): + save.py = 23 + """ + self.check(b, a) + class Test_getcwdu(FixerTestCase): From python-3000-checkins at python.org Tue Nov 25 05:02:29 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 25 Nov 2008 05:02:29 +0100 (CET) Subject: [Python-3000-checkins] r67375 - in python/branches/py3k: Python/ast.c Message-ID: <20081125040229.255731E4002@bag.python.org> Author: benjamin.peterson Date: Tue Nov 25 05:02:28 2008 New Revision: 67375 Log: Merged revisions 67373 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67373 | benjamin.peterson | 2008-11-24 21:43:14 -0600 (Mon, 24 Nov 2008) | 2 lines always check the return value of NEW_IDENTIFIER ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Python/ast.c Modified: python/branches/py3k/Python/ast.c ============================================================================== --- python/branches/py3k/Python/ast.c (original) +++ python/branches/py3k/Python/ast.c Tue Nov 25 05:02:28 2008 @@ -51,6 +51,8 @@ new_identifier(const char* n, PyArena *arena) { PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); + if (!id) + return NULL; Py_UNICODE *u = PyUnicode_AS_UNICODE(id); /* Check whether there are non-ASCII characters in the identifier; if so, normalize to NFKC. */ @@ -826,7 +828,6 @@ if (!arg) goto error; asdl_seq_SET(posargs, k++, arg); - i += 2; /* the name and the comma */ break; case STAR: @@ -846,6 +847,8 @@ } else { vararg = NEW_IDENTIFIER(CHILD(ch, 0)); + if (!vararg) + return NULL; if (NCH(ch) > 1) { /* there is an annotation on the vararg */ varargannotation = ast_for_expr(c, CHILD(ch, 2)); @@ -869,6 +872,8 @@ /* there is an annotation on the kwarg */ kwargannotation = ast_for_expr(c, CHILD(ch, 2)); } + if (!kwarg) + goto error; i += 3; break; default: @@ -1311,10 +1316,14 @@ int bytesmode = 0; switch (TYPE(ch)) { - case NAME: + case NAME: { /* All names start in Load context, but may later be changed. */ - return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, c->c_arena); + PyObject *name = NEW_IDENTIFIER(ch); + if (!name) + return NULL; + return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena); + } case STRING: { PyObject *str = parsestrplus(c, n, &bytesmode); if (!str) { @@ -1589,7 +1598,10 @@ return ast_for_call(c, CHILD(n, 1), left_expr); } else if (TYPE(CHILD(n, 0)) == DOT ) { - return Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load, + PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1)); + if (!attr_id) + return NULL; + return Attribute(left_expr, attr_id, Load, LINENO(n), n->n_col_offset, c->c_arena); } else { @@ -2275,7 +2287,7 @@ dotted_as_name: dotted_name ['as' NAME] dotted_name: NAME ('.' NAME)* */ - PyObject *str; + PyObject *str, *name; loop: switch (TYPE(n)) { @@ -2283,8 +2295,13 @@ str = NULL; if (NCH(n) == 3) { str = NEW_IDENTIFIER(CHILD(n, 2)); + if (!str) + return NULL; } - return alias(NEW_IDENTIFIER(CHILD(n, 0)), str, c->c_arena); + name = NEW_IDENTIFIER(CHILD(n, 0)); + if (!name) + return NULL; + return alias(name, str, c->c_arena); case dotted_as_name: if (NCH(n) == 1) { n = CHILD(n, 0); @@ -2296,12 +2313,18 @@ return NULL; assert(!a->asname); a->asname = NEW_IDENTIFIER(CHILD(n, 2)); + if (!a->asname) + return NULL; return a; } break; case dotted_name: - if (NCH(n) == 1) - return alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL, c->c_arena); + if (NCH(n) == 1) { + name = NEW_IDENTIFIER(CHILD(n, 0)); + if (!name) + return NULL; + return alias(name, NULL, c->c_arena); + } else { /* Create a string of the form "a.b.c" */ int i; @@ -2974,6 +2997,7 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) { /* classdef: 'class' NAME ['(' arglist ')'] ':' suite */ + PyObject *classname; asdl_seq *s; expr_ty call, dummy; @@ -2983,16 +3007,22 @@ s = ast_for_suite(c, CHILD(n, 3)); if (!s) return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, NULL, NULL, NULL, s, - decorator_seq, LINENO(n), n->n_col_offset, c->c_arena); + classname = NEW_IDENTIFIER(CHILD(n, 1)); + if (!classname) + return NULL; + return ClassDef(classname, NULL, NULL, NULL, NULL, s, decorator_seq, + LINENO(n), n->n_col_offset, c->c_arena); } if (TYPE(CHILD(n, 3)) == RPAR) { /* class NAME '(' ')' ':' suite */ s = ast_for_suite(c, CHILD(n,5)); if (!s) - return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, NULL, NULL, NULL, s, - decorator_seq, LINENO(n), n->n_col_offset, c->c_arena); + return NULL; + classname = NEW_IDENTIFIER(CHILD(n, 1)); + if (!classname) + return NULL; + return ClassDef(classname, NULL, NULL, NULL, NULL, s, decorator_seq, + LINENO(n), n->n_col_offset, c->c_arena); } /* class NAME '(' arglist ')' ':' suite */ @@ -3004,9 +3034,11 @@ s = ast_for_suite(c, CHILD(n, 6)); if (!s) return NULL; + classname = NEW_IDENTIFIER(CHILD(n, 1)); + if (!classname) + return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), - call->v.Call.args, call->v.Call.keywords, + return ClassDef(classname, call->v.Call.args, call->v.Call.keywords, call->v.Call.starargs, call->v.Call.kwargs, s, decorator_seq, LINENO(n), n->n_col_offset, c->c_arena); } From python-3000-checkins at python.org Tue Nov 25 05:09:48 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 25 Nov 2008 05:09:48 +0100 (CET) Subject: [Python-3000-checkins] r67377 - python/branches/py3k Message-ID: <20081125040948.F1D7D1E4002@bag.python.org> Author: benjamin.peterson Date: Tue Nov 25 05:09:48 2008 New Revision: 67377 Log: Blocked revisions 67376 via svnmerge ................ r67376 | benjamin.peterson | 2008-11-24 22:07:45 -0600 (Mon, 24 Nov 2008) | 17 lines Merged revisions 67183,67191,67371 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67183 | benjamin.peterson | 2008-11-10 21:51:33 -0600 (Mon, 10 Nov 2008) | 1 line handle 'import x as y' in fix_imports; this still needs more work... ........ r67191 | benjamin.peterson | 2008-11-11 17:24:51 -0600 (Tue, 11 Nov 2008) | 1 line super() is good ........ r67371 | benjamin.peterson | 2008-11-24 16:02:00 -0600 (Mon, 24 Nov 2008) | 1 line don't blow up in the metaclass fixer when assignments in the class statement aren't simple ........ ................ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Tue Nov 25 13:35:58 2008 From: python-3000-checkins at python.org (thomas.heller) Date: Tue, 25 Nov 2008 13:35:58 +0100 (CET) Subject: [Python-3000-checkins] r67378 - python/branches/py3k/Python/ast.c Message-ID: <20081125123558.B9CE21E4002@bag.python.org> Author: thomas.heller Date: Tue Nov 25 13:35:58 2008 New Revision: 67378 Log: Make ast.c compile on Windows again. Modified: python/branches/py3k/Python/ast.c Modified: python/branches/py3k/Python/ast.c ============================================================================== --- python/branches/py3k/Python/ast.c (original) +++ python/branches/py3k/Python/ast.c Tue Nov 25 13:35:58 2008 @@ -51,9 +51,10 @@ new_identifier(const char* n, PyArena *arena) { PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); + Py_UNICODE *u; if (!id) return NULL; - Py_UNICODE *u = PyUnicode_AS_UNICODE(id); + u = PyUnicode_AS_UNICODE(id); /* Check whether there are non-ASCII characters in the identifier; if so, normalize to NFKC. */ for (; *u; u++) { From python-3000-checkins at python.org Tue Nov 25 20:19:17 2008 From: python-3000-checkins at python.org (brett.cannon) Date: Tue, 25 Nov 2008 20:19:17 +0100 (CET) Subject: [Python-3000-checkins] r67380 - in python/branches/py3k: Doc/library/dbm.rst Lib/test/test_dbm_dumb.py Lib/test/test_dbm_gnu.py Lib/test/test_dbm_ndbm.py Misc/NEWS Modules/_dbmmodule.c Modules/_gdbmmodule.c Message-ID: <20081125191917.B85611E4012@bag.python.org> Author: brett.cannon Date: Tue Nov 25 20:19:17 2008 New Revision: 67380 Log: dbm.gnu and dbm.ndbm accept both strings and bytes as keys and values. For the former they are converted to bytes before being written to the DB. Closes issue 3799. Reviewed by Skip Montanaro. Modified: python/branches/py3k/Doc/library/dbm.rst python/branches/py3k/Lib/test/test_dbm_dumb.py python/branches/py3k/Lib/test/test_dbm_gnu.py python/branches/py3k/Lib/test/test_dbm_ndbm.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_dbmmodule.c python/branches/py3k/Modules/_gdbmmodule.c Modified: python/branches/py3k/Doc/library/dbm.rst ============================================================================== --- python/branches/py3k/Doc/library/dbm.rst (original) +++ python/branches/py3k/Doc/library/dbm.rst Tue Nov 25 20:19:17 2008 @@ -52,7 +52,9 @@ The object returned by :func:`open` supports most of the same functionality as dictionaries; keys and their corresponding values can be stored, retrieved, and deleted, and the :keyword:`in` operator and the :meth:`keys` method are -available. Keys and values must always be strings. +available. Key and values are always stored as bytes. This means that when +strings are used they are implicitly converted to the default encoding before +being stored. The following example records some hostnames and a corresponding title, and then prints out the contents of the database:: @@ -63,9 +65,15 @@ db = dbm.open('cache', 'c') # Record some values + db[b'hello'] = b'there' db['www.python.org'] = 'Python Website' db['www.cnn.com'] = 'Cable News Network' + # Note that the keys are considered bytes now. + assert db[b'www.python.org'] == b'Python Website' + # Notice how the value is now in bytes. + assert db['www.cnn.com'] == b'Cable News Network' + # Loop through contents. Other dictionary methods # such as .keys(), .values() also work. for k, v in db.iteritems(): @@ -98,17 +106,18 @@ This module is quite similar to the :mod:`dbm` module, but uses the GNU library ``gdbm`` instead to provide some additional functionality. Please note that the -file formats created by ``gdbm`` and ``dbm`` are incompatible. +file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible. The :mod:`dbm.gnu` module provides an interface to the GNU DBM library. -``gdbm`` objects behave like mappings (dictionaries), except that keys and -values are always strings. Printing a :mod:`dbm.gnu` object doesn't print the +``dbm.gnu.gdbm`` objects behave like mappings (dictionaries), except that keys and +values are always converted to bytes before storing. Printing a ``gdbm`` +object doesn't print the keys and values, and the :meth:`items` and :meth:`values` methods are not supported. .. exception:: error - Raised on ``gdbm``\ -specific errors, such as I/O errors. :exc:`KeyError` is + Raised on :mod:`dbm.gnu`-specific errors, such as I/O errors. :exc:`KeyError` is raised for general mapping errors like specifying an incorrect key. @@ -183,7 +192,7 @@ If you have carried out a lot of deletions and would like to shrink the space used by the ``gdbm`` file, this routine will reorganize the database. ``gdbm`` - will not shorten the length of a database file except by using this + objects will not shorten the length of a database file except by using this reorganization; otherwise, deleted file space will be kept and reused as new (key, value) pairs are added. @@ -203,8 +212,8 @@ The :mod:`dbm.ndbm` module provides an interface to the Unix "(n)dbm" library. Dbm objects behave like mappings (dictionaries), except that keys and values are -always strings. Printing a dbm object doesn't print the keys and values, and the -:meth:`items` and :meth:`values` methods are not supported. +always stored as bytes. Printing a ``dbm`` object doesn't print the keys and +values, and the :meth:`items` and :meth:`values` methods are not supported. This module can be used with the "classic" ndbm interface, the BSD DB compatibility interface, or the GNU GDBM compatibility interface. On Unix, the @@ -213,7 +222,7 @@ .. exception:: error - Raised on dbm-specific errors, such as I/O errors. :exc:`KeyError` is raised + Raised on :mod:`dbm.ndbm`-specific errors, such as I/O errors. :exc:`KeyError` is raised for general mapping errors like specifying an incorrect key. @@ -224,7 +233,7 @@ .. function:: open(filename[, flag[, mode]]) - Open a dbm database and return a dbm object. The *filename* argument is the + Open a dbm database and return a ``dbm`` object. The *filename* argument is the name of the database file (without the :file:`.dir` or :file:`.pag` extensions; note that the BSD DB implementation of the interface will append the extension :file:`.db` and only create one file). @@ -264,27 +273,27 @@ .. note:: The :mod:`dbm.dumb` module is intended as a last resort fallback for the - :mod:`dbm` module when no more robust module is available. The :mod:`dbm.dumb` + :mod:`dbm` module when a more robust module is not available. The :mod:`dbm.dumb` module is not written for speed and is not nearly as heavily used as the other database modules. The :mod:`dbm.dumb` module provides a persistent dictionary-like interface which -is written entirely in Python. Unlike other modules such as :mod:`gdbm` no +is written entirely in Python. Unlike other modules such as :mod:`dbm.gnu` no external library is required. As with other persistent mappings, the keys and -values must always be strings. +values are always stored as bytes. The module defines the following: .. exception:: error - Raised on dbm.dumb-specific errors, such as I/O errors. :exc:`KeyError` is + Raised on :mod:`dbm.dumb`-specific errors, such as I/O errors. :exc:`KeyError` is raised for general mapping errors like specifying an incorrect key. .. function:: open(filename[, flag[, mode]]) - Open a dumbdbm database and return a dumbdbm object. The *filename* argument is + Open a ``dumbdbm`` database and return a dumbdbm object. The *filename* argument is the basename of the database file (without any specific extensions). When a dumbdbm database is created, files with :file:`.dat` and :file:`.dir` extensions are created. Modified: python/branches/py3k/Lib/test/test_dbm_dumb.py ============================================================================== --- python/branches/py3k/Lib/test/test_dbm_dumb.py (original) +++ python/branches/py3k/Lib/test/test_dbm_dumb.py Tue Nov 25 20:19:17 2008 @@ -115,11 +115,13 @@ self.init_db() f = dumbdbm.open(_fname) f['\u00fc'] = b'!' + f['1'] = 'a' f.close() f = dumbdbm.open(_fname, 'r') self.assert_('\u00fc' in f) self.assertEqual(f['\u00fc'.encode('utf-8')], self._dict['\u00fc'.encode('utf-8')]) + self.assertEqual(f[b'1'], b'a') def test_line_endings(self): # test for bug #1172763: dumbdbm would die if the line endings Modified: python/branches/py3k/Lib/test/test_dbm_gnu.py ============================================================================== --- python/branches/py3k/Lib/test/test_dbm_gnu.py (original) +++ python/branches/py3k/Lib/test/test_dbm_gnu.py Tue Nov 25 20:19:17 2008 @@ -20,9 +20,11 @@ self.assertEqual(self.g.keys(), []) self.g['a'] = 'b' self.g['12345678910'] = '019237410982340912840198242' + self.g[b'bytes'] = b'data' key_set = set(self.g.keys()) self.assertEqual(key_set, set([b'a', b'12345678910'])) self.assert_(b'a' in self.g) + self.assertEqual(self.g[b'bytes'], b'data') key = self.g.firstkey() while key: self.assert_(key in key_set) Modified: python/branches/py3k/Lib/test/test_dbm_ndbm.py ============================================================================== --- python/branches/py3k/Lib/test/test_dbm_ndbm.py (original) +++ python/branches/py3k/Lib/test/test_dbm_ndbm.py Tue Nov 25 20:19:17 2008 @@ -20,9 +20,11 @@ self.d = dbm.ndbm.open(self.filename, 'c') self.assert_(self.d.keys() == []) self.d['a'] = 'b' + self.d[b'bytes'] = b'data' self.d['12345678910'] = '019237410982340912840198242' self.d.keys() self.assert_(b'a' in self.d) + self.assertEqual(self.d[b'bytes'], b'data') self.d.close() def test_modes(self): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Tue Nov 25 20:19:17 2008 @@ -28,6 +28,12 @@ - Issue #4383: When IDLE cannot make the connection to its subprocess, it would fail to properly display the error message. +Docs +---- + +- Issue #3799: Document that dbm.gnu and dbm.ndbm will accept string arguments + for keys and values which will be converted to bytes before committal. + What's New in Python 3.0 release candidate 3? ============================================= Modified: python/branches/py3k/Modules/_dbmmodule.c ============================================================================== --- python/branches/py3k/Modules/_dbmmodule.c (original) +++ python/branches/py3k/Modules/_dbmmodule.c Tue Nov 25 20:19:17 2008 @@ -122,7 +122,7 @@ if ( !PyArg_Parse(v, "s#", &krec.dptr, &tmp_size) ) { PyErr_SetString(PyExc_TypeError, - "dbm mappings have string keys only"); + "dbm mappings have bytes or string keys only"); return -1; } krec.dsize = tmp_size; @@ -140,7 +140,7 @@ } else { if ( !PyArg_Parse(w, "s#", &drec.dptr, &tmp_size) ) { PyErr_SetString(PyExc_TypeError, - "dbm mappings have byte string elements only"); + "dbm mappings have byte or string elements only"); return -1; } drec.dsize = tmp_size; Modified: python/branches/py3k/Modules/_gdbmmodule.c ============================================================================== --- python/branches/py3k/Modules/_gdbmmodule.c (original) +++ python/branches/py3k/Modules/_gdbmmodule.c Tue Nov 25 20:19:17 2008 @@ -142,7 +142,7 @@ if (!PyArg_Parse(v, "s#", &krec.dptr, &krec.dsize) ) { PyErr_SetString(PyExc_TypeError, - "gdbm mappings have string indices only"); + "gdbm mappings have bytes or string indices only"); return -1; } if (dp->di_dbm == NULL) { @@ -160,7 +160,7 @@ else { if (!PyArg_Parse(w, "s#", &drec.dptr, &drec.dsize)) { PyErr_SetString(PyExc_TypeError, - "gdbm mappings have byte string elements only"); + "gdbm mappings have byte or string elements only"); return -1; } errno = 0; From python-3000-checkins at python.org Tue Nov 25 22:12:07 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Tue, 25 Nov 2008 22:12:07 +0100 (CET) Subject: [Python-3000-checkins] r67381 - in python/branches/py3k: Misc/NEWS Modules/_pickle.c Message-ID: <20081125211207.916361E4002@bag.python.org> Author: amaury.forgeotdarc Date: Tue Nov 25 22:11:54 2008 New Revision: 67381 Log: #4373: Reference leak in the pickle module. Reviewed by Brett Cannon. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_pickle.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Tue Nov 25 22:11:54 2008 @@ -22,6 +22,8 @@ Library ------- +- Issue #4373: Corrected a potential reference leak in the pickle module. + - Issue #4382: dbm.dumb did not specify the expected file encoding for opened files. Modified: python/branches/py3k/Modules/_pickle.c ============================================================================== --- python/branches/py3k/Modules/_pickle.c (original) +++ python/branches/py3k/Modules/_pickle.c Tue Nov 25 22:11:54 2008 @@ -486,11 +486,13 @@ PyErr_SetString(PyExc_ValueError, "read() from the underlying stream did not" "return bytes"); + Py_DECREF(data); return -1; } if (PyBytes_GET_SIZE(data) != n) { PyErr_SetNone(PyExc_EOFError); + Py_DECREF(data); return -1; } From python-3000-checkins at python.org Tue Nov 25 22:21:32 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Tue, 25 Nov 2008 22:21:32 +0100 (CET) Subject: [Python-3000-checkins] r67382 - in python/branches/py3k: Lib/distutils/tests/test_build_ext.py Misc/NEWS Message-ID: <20081125212132.E846D1E4002@bag.python.org> Author: christian.heimes Date: Tue Nov 25 22:21:32 2008 New Revision: 67382 Log: Second fix for issue #4373 Modified: python/branches/py3k/Lib/distutils/tests/test_build_ext.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/distutils/tests/test_build_ext.py ============================================================================== --- python/branches/py3k/Lib/distutils/tests/test_build_ext.py (original) +++ python/branches/py3k/Lib/distutils/tests/test_build_ext.py Tue Nov 25 22:21:32 2008 @@ -11,6 +11,10 @@ import unittest from test import support +# http://bugs.python.org/issue4373 +# Don't load the xx module more than once. +ALREADY_TESTED = False + class BuildExtTestCase(unittest.TestCase): def setUp(self): # Create a simple test environment @@ -23,6 +27,7 @@ shutil.copy(xx_c, self.tmp_dir) def test_build_ext(self): + global ALREADY_TESTED xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') xx_ext = Extension('xx', [xx_c]) dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]}) @@ -45,6 +50,11 @@ finally: sys.stdout = old_stdout + if ALREADY_TESTED: + return + else: + ALREADY_TESTED = True + import xx for attr in ('error', 'foo', 'new', 'roj'): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Tue Nov 25 22:21:32 2008 @@ -22,7 +22,8 @@ Library ------- -- Issue #4373: Corrected a potential reference leak in the pickle module. +- Issue #4373: Corrected a potential reference leak in the pickle module and + silenced a false positive ref leak in distutils.tests.test_build_ext. - Issue #4382: dbm.dumb did not specify the expected file encoding for opened files. From python-3000-checkins at python.org Tue Nov 25 22:27:00 2008 From: python-3000-checkins at python.org (brett.cannon) Date: Tue, 25 Nov 2008 22:27:00 +0100 (CET) Subject: [Python-3000-checkins] r67383 - python/branches/py3k/Lib/test/test_dbm_gnu.py Message-ID: <20081125212700.AF3AC1E4002@bag.python.org> Author: brett.cannon Date: Tue Nov 25 22:27:00 2008 New Revision: 67383 Log: Fix a broken test_dbm_gnu as introducted by r67380. Modified: python/branches/py3k/Lib/test/test_dbm_gnu.py Modified: python/branches/py3k/Lib/test/test_dbm_gnu.py ============================================================================== --- python/branches/py3k/Lib/test/test_dbm_gnu.py (original) +++ python/branches/py3k/Lib/test/test_dbm_gnu.py Tue Nov 25 22:27:00 2008 @@ -22,7 +22,7 @@ self.g['12345678910'] = '019237410982340912840198242' self.g[b'bytes'] = b'data' key_set = set(self.g.keys()) - self.assertEqual(key_set, set([b'a', b'12345678910'])) + self.assertEqual(key_set, set([b'a', b'bytes', b'12345678910'])) self.assert_(b'a' in self.g) self.assertEqual(self.g[b'bytes'], b'data') key = self.g.firstkey() From python-3000-checkins at python.org Tue Nov 25 23:19:53 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 25 Nov 2008 23:19:53 +0100 (CET) Subject: [Python-3000-checkins] r67385 - python/branches/py3k/Python/ast.c Message-ID: <20081125221953.78E701E4002@bag.python.org> Author: benjamin.peterson Date: Tue Nov 25 23:19:53 2008 New Revision: 67385 Log: check the return value of NEW_IDENTIFIER in some more places Modified: python/branches/py3k/Python/ast.c Modified: python/branches/py3k/Python/ast.c ============================================================================== --- python/branches/py3k/Python/ast.c (original) +++ python/branches/py3k/Python/ast.c Tue Nov 25 23:19:53 2008 @@ -654,6 +654,7 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start, asdl_seq *kwonlyargs, asdl_seq *kwdefaults) { + PyObject *argname; node *ch; expr_ty expression, annotation; arg_ty arg; @@ -690,11 +691,12 @@ annotation = NULL; } ch = CHILD(ch, 0); - arg = arg(NEW_IDENTIFIER(ch), annotation, c->c_arena); - if (!arg) { - ast_error(ch, "expecting name"); + argname = NEW_IDENTIFIER(ch); + if (!argname) + goto error; + arg = arg(argname, annotation, c->c_arena); + if (!arg) goto error; - } asdl_seq_SET(kwonlyargs, j++, arg); i += 2; /* the name and the comma */ break; @@ -3000,7 +3002,7 @@ /* classdef: 'class' NAME ['(' arglist ')'] ':' suite */ PyObject *classname; asdl_seq *s; - expr_ty call, dummy; + expr_ty call; REQ(n, classdef); @@ -3028,10 +3030,17 @@ /* class NAME '(' arglist ')' ':' suite */ /* build up a fake Call node so we can extract its pieces */ - dummy = Name(NEW_IDENTIFIER(CHILD(n, 1)), Load, LINENO(n), n->n_col_offset, c->c_arena); - call = ast_for_call(c, CHILD(n, 3), dummy); - if (!call) - return NULL; + { + PyObject *dummy_name; + expr_ty dummy; + dummy_name = NEW_IDENTIFIER(CHILD(n, 1)); + if (!dummy_name) + return NULL; + dummy = Name(dummy_name, Load, LINENO(n), n->n_col_offset, c->c_arena); + call = ast_for_call(c, CHILD(n, 3), dummy); + if (!call) + return NULL; + } s = ast_for_suite(c, CHILD(n, 6)); if (!s) return NULL; From python-3000-checkins at python.org Wed Nov 26 09:45:36 2008 From: python-3000-checkins at python.org (thomas.heller) Date: Wed, 26 Nov 2008 09:45:36 +0100 (CET) Subject: [Python-3000-checkins] r67391 - in python/branches/py3k: Misc/NEWS Modules/_ctypes/callproc.c Message-ID: <20081126084536.E6B7B1E4002@bag.python.org> Author: thomas.heller Date: Wed Nov 26 09:45:36 2008 New Revision: 67391 Log: Prevent UnicodeDecodeErrors in ctypes with non-ascii error messages. Fixes issue #4429. Reviewed by Amaury Forgeot d'Arc. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_ctypes/callproc.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 26 09:45:36 2008 @@ -22,6 +22,8 @@ Library ------- +- Issue #4429: Fixed UnicodeDecodeError in ctypes. + - Issue #4373: Corrected a potential reference leak in the pickle module and silenced a false positive ref leak in distutils.tests.test_build_ext. Modified: python/branches/py3k/Modules/_ctypes/callproc.c ============================================================================== --- python/branches/py3k/Modules/_ctypes/callproc.c (original) +++ python/branches/py3k/Modules/_ctypes/callproc.c Wed Nov 26 09:45:36 2008 @@ -209,21 +209,21 @@ PyObject *ComError; -static TCHAR *FormatError(DWORD code) +static WCHAR *FormatError(DWORD code) { - TCHAR *lpMsgBuf; + WCHAR *lpMsgBuf; DWORD n; - n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL); + n = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPWSTR) &lpMsgBuf, + 0, + NULL); if (n) { - while (_istspace(lpMsgBuf[n-1])) + while (iswspace(lpMsgBuf[n-1])) --n; - lpMsgBuf[n] = _T('\0'); /* rstrip() */ + lpMsgBuf[n] = L'\0'; /* rstrip() */ } return lpMsgBuf; } @@ -231,7 +231,7 @@ #ifndef DONT_USE_SEH void SetException(DWORD code, EXCEPTION_RECORD *pr) { - TCHAR *lpMsgBuf; + WCHAR *lpMsgBuf; lpMsgBuf = FormatError(code); if(lpMsgBuf) { PyErr_SetFromWindowsErr(code); @@ -972,7 +972,7 @@ DWORD helpcontext=0; LPOLESTR progid; PyObject *obj; - TCHAR *text; + LPOLESTR text; /* We absolutely have to release the GIL during COM method calls, otherwise we may get a deadlock! @@ -1012,11 +1012,7 @@ text = FormatError(errcode); obj = Py_BuildValue( -#ifdef _UNICODE "iu(uuuiu)", -#else - "is(uuuiu)", -#endif errcode, text, descr, source, helpfile, helpcontext, @@ -1202,15 +1198,6 @@ #ifdef MS_WIN32 -#ifdef _UNICODE -# define PYBUILD_TSTR "u" -#else -# define PYBUILD_TSTR "s" -# ifndef _T -# define _T(text) text -# endif -#endif - static char format_error_doc[] = "FormatError([integer]) -> string\n\ \n\ @@ -1219,7 +1206,7 @@ static PyObject *format_error(PyObject *self, PyObject *args) { PyObject *result; - TCHAR *lpMsgBuf; + wchar_t *lpMsgBuf; DWORD code = 0; if (!PyArg_ParseTuple(args, "|i:FormatError", &code)) return NULL; @@ -1227,10 +1214,10 @@ code = GetLastError(); lpMsgBuf = FormatError(code); if (lpMsgBuf) { - result = Py_BuildValue(PYBUILD_TSTR, lpMsgBuf); + result = PyUnicode_FromWideChar(lpMsgBuf, wcslen(lpMsgBuf)); LocalFree(lpMsgBuf); } else { - result = Py_BuildValue("s", ""); + result = PyUnicode_FromString(""); } return result; } From python-3000-checkins at python.org Wed Nov 26 18:18:22 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Wed, 26 Nov 2008 18:18:22 +0100 (CET) Subject: [Python-3000-checkins] r67393 - python/branches/py3k/Modules/fpectlmodule.c Message-ID: <20081126171822.7CCC31E4002@bag.python.org> Author: matthias.klose Date: Wed Nov 26 18:18:22 2008 New Revision: 67393 Log: - fix build failure in Modules/fpectlmodule.c (not built by default) Modified: python/branches/py3k/Modules/fpectlmodule.c Modified: python/branches/py3k/Modules/fpectlmodule.c ============================================================================== --- python/branches/py3k/Modules/fpectlmodule.c (original) +++ python/branches/py3k/Modules/fpectlmodule.c Wed Nov 26 18:18:22 2008 @@ -302,7 +302,7 @@ PyMODINIT_FUNC PyInit_fpectl(void) { PyObject *m, *d; - m = PyModule_Create("fpectl", fpectl_methods); + m = PyModule_Create(&fpectlmodule); if (m == NULL) return NULL; d = PyModule_GetDict(m); From python-3000-checkins at python.org Wed Nov 26 18:22:04 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Wed, 26 Nov 2008 18:22:04 +0100 (CET) Subject: [Python-3000-checkins] r67394 - in python/branches/py3k: Misc/NEWS Modules/_cursesmodule.c Message-ID: <20081126172204.44F2A1E4002@bag.python.org> Author: matthias.klose Date: Wed Nov 26 18:22:04 2008 New Revision: 67394 Log: - Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_cursesmodule.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 26 18:22:04 2008 @@ -19,6 +19,8 @@ - Issue #4367: Python would segfault during compiling when the unicodedata module couldn't be imported and \N escapes were present. +- Fix build failure of _cursesmodule.c building with -D_FORTIFY_SOURCE=2. + Library ------- Modified: python/branches/py3k/Modules/_cursesmodule.c ============================================================================== --- python/branches/py3k/Modules/_cursesmodule.c (original) +++ python/branches/py3k/Modules/_cursesmodule.c Wed Nov 26 18:22:04 2008 @@ -1857,6 +1857,7 @@ int fd; FILE *fp; PyObject *data; + size_t datalen; WINDOW *win; PyCursesInitialised @@ -1886,7 +1887,13 @@ remove(fn); return NULL; } - fwrite(PyBytes_AS_STRING(data), 1, PyBytes_GET_SIZE(data), fp); + datalen = PyBytes_GET_SIZE(data); + if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) { + Py_DECREF(data); + fclose(fp); + remove(fn); + return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); + } Py_DECREF(data); fseek(fp, 0, 0); win = getwin(fp); From python-3000-checkins at python.org Wed Nov 26 18:23:18 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Wed, 26 Nov 2008 18:23:18 +0100 (CET) Subject: [Python-3000-checkins] r67395 - python/branches/py3k/Modules/Setup.dist Message-ID: <20081126172318.EC74A1E4002@bag.python.org> Author: matthias.klose Date: Wed Nov 26 18:23:18 2008 New Revision: 67395 Log: - Modules/Setup.dist: Mention _elementtree and _pickle. Modified: python/branches/py3k/Modules/Setup.dist Modified: python/branches/py3k/Modules/Setup.dist ============================================================================== --- python/branches/py3k/Modules/Setup.dist (original) +++ python/branches/py3k/Modules/Setup.dist Wed Nov 26 18:23:18 2008 @@ -165,6 +165,8 @@ #itertools itertoolsmodule.c # Functions creating iterators for efficient looping #atexit atexitmodule.c # Register functions to be run at interpreter-shutdown #_functools _functoolsmodule.c # Tools for working with functions and callable objects +#_elementtreee _elementtree.c # elementtree accelerator +#_pickle _pickle.c # pickle accelerator #unicodedata unicodedata.c # static Unicode character database From python-3000-checkins at python.org Wed Nov 26 19:28:07 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Wed, 26 Nov 2008 19:28:07 +0100 (CET) Subject: [Python-3000-checkins] r67401 - python/branches/py3k/Modules/Setup.dist Message-ID: <20081126182807.A69301E4002@bag.python.org> Author: matthias.klose Date: Wed Nov 26 19:28:07 2008 New Revision: 67401 Log: - Modules/Setup.dist: Fix typo in last checkin Modified: python/branches/py3k/Modules/Setup.dist Modified: python/branches/py3k/Modules/Setup.dist ============================================================================== --- python/branches/py3k/Modules/Setup.dist (original) +++ python/branches/py3k/Modules/Setup.dist Wed Nov 26 19:28:07 2008 @@ -165,7 +165,7 @@ #itertools itertoolsmodule.c # Functions creating iterators for efficient looping #atexit atexitmodule.c # Register functions to be run at interpreter-shutdown #_functools _functoolsmodule.c # Tools for working with functions and callable objects -#_elementtreee _elementtree.c # elementtree accelerator +#_elementtree _elementtree.c # elementtree accelerator #_pickle _pickle.c # pickle accelerator #unicodedata unicodedata.c # static Unicode character database From python-3000-checkins at python.org Wed Nov 26 19:40:58 2008 From: python-3000-checkins at python.org (thomas.heller) Date: Wed, 26 Nov 2008 19:40:58 +0100 (CET) Subject: [Python-3000-checkins] r67402 - in python/branches/py3k: Misc/NEWS Modules/_ctypes/_ctypes.c Message-ID: <20081126184058.9CEAF1E4002@bag.python.org> Author: thomas.heller Date: Wed Nov 26 19:40:58 2008 New Revision: 67402 Log: Remove the Py_TPFLAGS_HAVE_GC from the _ctypes.COMError type. Fixes issue #4433; reviewed by Benjamin Peterson. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_ctypes/_ctypes.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Nov 26 19:40:58 2008 @@ -24,6 +24,9 @@ Library ------- +- Issue #4433: Fixed an access violation when garbage collecting + _ctypes.COMError instances. + - Issue #4429: Fixed UnicodeDecodeError in ctypes. - Issue #4373: Corrected a potential reference leak in the pickle module and Modified: python/branches/py3k/Modules/_ctypes/_ctypes.c ============================================================================== --- python/branches/py3k/Modules/_ctypes/_ctypes.c (original) +++ python/branches/py3k/Modules/_ctypes/_ctypes.c Wed Nov 26 19:40:58 2008 @@ -5097,8 +5097,7 @@ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE - | Py_TPFLAGS_HAVE_GC, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ PyDoc_STR(comerror_doc), /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ From python-3000-checkins at python.org Thu Nov 27 08:43:44 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Thu, 27 Nov 2008 08:43:44 +0100 (CET) Subject: [Python-3000-checkins] r67406 - python/branches/py3k/Modules/Setup.dist Message-ID: <20081127074344.A17D01E4002@bag.python.org> Author: matthias.klose Date: Thu Nov 27 08:43:44 2008 New Revision: 67406 Log: - Modules/Setup.dist: Update pyexpat Modified: python/branches/py3k/Modules/Setup.dist Modified: python/branches/py3k/Modules/Setup.dist ============================================================================== --- python/branches/py3k/Modules/Setup.dist (original) +++ python/branches/py3k/Modules/Setup.dist Thu Nov 27 08:43:44 2008 @@ -380,9 +380,7 @@ # # More information on Expat can be found at www.libexpat.org. # -#EXPAT_DIR=/usr/local/src/expat-1.95.2 -#pyexpat pyexpat.c -DHAVE_EXPAT_H -I$(EXPAT_DIR)/lib -L$(EXPAT_DIR) -lexpat - +#pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI # Hye-Shik Chang's CJKCodecs From python-3000-checkins at python.org Thu Nov 27 10:51:39 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Thu, 27 Nov 2008 10:51:39 +0100 (CET) Subject: [Python-3000-checkins] r67409 - python/branches/py3k/Modules/Setup.dist Message-ID: <20081127095139.658B21E4002@bag.python.org> Author: matthias.klose Date: Thu Nov 27 10:51:39 2008 New Revision: 67409 Log: - Modules/Setup.dist: add datetime, update _elementtree Modified: python/branches/py3k/Modules/Setup.dist Modified: python/branches/py3k/Modules/Setup.dist ============================================================================== --- python/branches/py3k/Modules/Setup.dist (original) +++ python/branches/py3k/Modules/Setup.dist Thu Nov 27 10:51:39 2008 @@ -165,8 +165,9 @@ #itertools itertoolsmodule.c # Functions creating iterators for efficient looping #atexit atexitmodule.c # Register functions to be run at interpreter-shutdown #_functools _functoolsmodule.c # Tools for working with functions and callable objects -#_elementtree _elementtree.c # elementtree accelerator +#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator #_pickle _pickle.c # pickle accelerator +#datetime datetimemodule.c # date/time type #unicodedata unicodedata.c # static Unicode character database From python-3000-checkins at python.org Thu Nov 27 10:53:28 2008 From: python-3000-checkins at python.org (matthias.klose) Date: Thu, 27 Nov 2008 10:53:28 +0100 (CET) Subject: [Python-3000-checkins] r67410 - python/branches/py3k/Modules/Setup.dist Message-ID: <20081127095328.E9CA71E4002@bag.python.org> Author: matthias.klose Date: Thu Nov 27 10:53:28 2008 New Revision: 67410 Log: - Modules/Setup.dist: Add _bisect Modified: python/branches/py3k/Modules/Setup.dist Modified: python/branches/py3k/Modules/Setup.dist ============================================================================== --- python/branches/py3k/Modules/Setup.dist (original) +++ python/branches/py3k/Modules/Setup.dist Thu Nov 27 10:53:28 2008 @@ -168,6 +168,7 @@ #_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator #_pickle _pickle.c # pickle accelerator #datetime datetimemodule.c # date/time type +#_bisect _bisectmodule.c # Bisection algorithms #unicodedata unicodedata.c # static Unicode character database From python-3000-checkins at python.org Fri Nov 28 12:05:18 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 28 Nov 2008 12:05:18 +0100 (CET) Subject: [Python-3000-checkins] r67416 - in python/branches/py3k: Lib/distutils/msvc9compiler.py Misc/NEWS Message-ID: <20081128110518.04A871E4002@bag.python.org> Author: christian.heimes Date: Fri Nov 28 12:05:17 2008 New Revision: 67416 Log: Merged revisions 67414 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67414 | christian.heimes | 2008-11-28 12:02:32 +0100 (Fri, 28 Nov 2008) | 1 line Fixed issue ##3741: DISTUTILS_USE_SDK set causes msvc9compiler.py to raise an exception ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/distutils/msvc9compiler.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/distutils/msvc9compiler.py ============================================================================== --- python/branches/py3k/Lib/distutils/msvc9compiler.py (original) +++ python/branches/py3k/Lib/distutils/msvc9compiler.py Fri Nov 28 12:05:17 2008 @@ -316,7 +316,7 @@ self.__version = VERSION self.__root = r"Software\Microsoft\VisualStudio" # self.__macros = MACROS - self.__path = [] + self.__paths = [] # target platform (.plat_name is consistent with 'bdist') self.plat_name = None self.__arch = None # deprecated name Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 28 12:05:17 2008 @@ -24,6 +24,9 @@ Library ------- +- Issue #3741: DISTUTILS_USE_SDK set causes msvc9compiler.py to raise an + exception. + - Issue #4433: Fixed an access violation when garbage collecting _ctypes.COMError instances. From python-3000-checkins at python.org Fri Nov 28 12:23:27 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 28 Nov 2008 12:23:27 +0100 (CET) Subject: [Python-3000-checkins] r67417 - in python/branches/py3k/Doc/includes: mp_benchmarks.py mp_newtype.py mp_pool.py mp_synchronize.py mp_webserver.py mp_workers.py Message-ID: <20081128112327.3E1BA1E4002@bag.python.org> Author: christian.heimes Date: Fri Nov 28 12:23:26 2008 New Revision: 67417 Log: 2to3 run of multiprocessing examples. mp_benchmarks, mp_newtypes and mp_distribution are still broken but the others are working properly. We should include the examples in our unit test suite ... Modified: python/branches/py3k/Doc/includes/mp_benchmarks.py python/branches/py3k/Doc/includes/mp_newtype.py python/branches/py3k/Doc/includes/mp_pool.py python/branches/py3k/Doc/includes/mp_synchronize.py python/branches/py3k/Doc/includes/mp_webserver.py python/branches/py3k/Doc/includes/mp_workers.py Modified: python/branches/py3k/Doc/includes/mp_benchmarks.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_benchmarks.py (original) +++ python/branches/py3k/Doc/includes/mp_benchmarks.py Fri Nov 28 12:23:26 2008 @@ -2,7 +2,7 @@ # Simple benchmarks for the multiprocessing package # -import time, sys, multiprocessing, threading, Queue, gc +import time, sys, multiprocessing, threading, queue, gc if sys.platform == 'win32': _timer = time.clock @@ -20,7 +20,7 @@ c.notify() c.release() - for i in xrange(iterations): + for i in range(iterations): q.put(a) q.put('STOP') @@ -48,8 +48,8 @@ p.join() - print iterations, 'objects passed through the queue in', elapsed, 'seconds' - print 'average number/sec:', iterations/elapsed + print(iterations, 'objects passed through the queue in', elapsed, 'seconds') + print('average number/sec:', iterations/elapsed) #### TEST_PIPESPEED @@ -60,7 +60,7 @@ cond.notify() cond.release() - for i in xrange(iterations): + for i in range(iterations): c.send(a) c.send('STOP') @@ -90,8 +90,8 @@ elapsed = _timer() - t p.join() - print iterations, 'objects passed through connection in',elapsed,'seconds' - print 'average number/sec:', iterations/elapsed + print(iterations, 'objects passed through connection in',elapsed,'seconds') + print('average number/sec:', iterations/elapsed) #### TEST_SEQSPEED @@ -105,13 +105,13 @@ t = _timer() - for i in xrange(iterations): + for i in range(iterations): a = seq[5] elapsed = _timer()-t - print iterations, 'iterations in', elapsed, 'seconds' - print 'average number/sec:', iterations/elapsed + print(iterations, 'iterations in', elapsed, 'seconds') + print('average number/sec:', iterations/elapsed) #### TEST_LOCK @@ -125,14 +125,14 @@ t = _timer() - for i in xrange(iterations): + for i in range(iterations): l.acquire() l.release() elapsed = _timer()-t - print iterations, 'iterations in', elapsed, 'seconds' - print 'average number/sec:', iterations/elapsed + print(iterations, 'iterations in', elapsed, 'seconds') + print('average number/sec:', iterations/elapsed) #### TEST_CONDITION @@ -141,7 +141,7 @@ c.acquire() c.notify() - for i in xrange(N): + for i in range(N): c.wait() c.notify() @@ -162,7 +162,7 @@ t = _timer() - for i in xrange(iterations): + for i in range(iterations): c.notify() c.wait() @@ -171,8 +171,8 @@ c.release() p.join() - print iterations * 2, 'waits in', elapsed, 'seconds' - print 'average number/sec:', iterations * 2 / elapsed + print(iterations * 2, 'waits in', elapsed, 'seconds') + print('average number/sec:', iterations * 2 / elapsed) #### @@ -181,51 +181,51 @@ gc.disable() - print '\n\t######## testing Queue.Queue\n' - test_queuespeed(threading.Thread, Queue.Queue(), + print('\n\t######## testing Queue.Queue\n') + test_queuespeed(threading.Thread, queue.Queue(), threading.Condition()) - print '\n\t######## testing multiprocessing.Queue\n' + print('\n\t######## testing multiprocessing.Queue\n') test_queuespeed(multiprocessing.Process, multiprocessing.Queue(), multiprocessing.Condition()) - print '\n\t######## testing Queue managed by server process\n' + print('\n\t######## testing Queue managed by server process\n') test_queuespeed(multiprocessing.Process, manager.Queue(), manager.Condition()) - print '\n\t######## testing multiprocessing.Pipe\n' + print('\n\t######## testing multiprocessing.Pipe\n') test_pipespeed() - print + print() - print '\n\t######## testing list\n' - test_seqspeed(range(10)) - print '\n\t######## testing list managed by server process\n' - test_seqspeed(manager.list(range(10))) - print '\n\t######## testing Array("i", ..., lock=False)\n' - test_seqspeed(multiprocessing.Array('i', range(10), lock=False)) - print '\n\t######## testing Array("i", ..., lock=True)\n' - test_seqspeed(multiprocessing.Array('i', range(10), lock=True)) + print('\n\t######## testing list\n') + test_seqspeed(list(range(10))) + print('\n\t######## testing list managed by server process\n') + test_seqspeed(manager.list(list(range(10)))) + print('\n\t######## testing Array("i", ..., lock=False)\n') + test_seqspeed(multiprocessing.Array('i', list(range(10)), lock=False)) + print('\n\t######## testing Array("i", ..., lock=True)\n') + test_seqspeed(multiprocessing.Array('i', list(range(10)), lock=True)) - print + print() - print '\n\t######## testing threading.Lock\n' + print('\n\t######## testing threading.Lock\n') test_lockspeed(threading.Lock()) - print '\n\t######## testing threading.RLock\n' + print('\n\t######## testing threading.RLock\n') test_lockspeed(threading.RLock()) - print '\n\t######## testing multiprocessing.Lock\n' + print('\n\t######## testing multiprocessing.Lock\n') test_lockspeed(multiprocessing.Lock()) - print '\n\t######## testing multiprocessing.RLock\n' + print('\n\t######## testing multiprocessing.RLock\n') test_lockspeed(multiprocessing.RLock()) - print '\n\t######## testing lock managed by server process\n' + print('\n\t######## testing lock managed by server process\n') test_lockspeed(manager.Lock()) - print '\n\t######## testing rlock managed by server process\n' + print('\n\t######## testing rlock managed by server process\n') test_lockspeed(manager.RLock()) - print + print() - print '\n\t######## testing threading.Condition\n' + print('\n\t######## testing threading.Condition\n') test_conditionspeed(threading.Thread, threading.Condition()) - print '\n\t######## testing multiprocessing.Condition\n' + print('\n\t######## testing multiprocessing.Condition\n') test_conditionspeed(multiprocessing.Process, multiprocessing.Condition()) - print '\n\t######## testing condition managed by a server process\n' + print('\n\t######## testing condition managed by a server process\n') test_conditionspeed(multiprocessing.Process, manager.Condition()) gc.enable() Modified: python/branches/py3k/Doc/includes/mp_newtype.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_newtype.py (original) +++ python/branches/py3k/Doc/includes/mp_newtype.py Fri Nov 28 12:23:26 2008 @@ -11,15 +11,15 @@ class Foo(object): def f(self): - print 'you called Foo.f()' + print('you called Foo.f()') def g(self): - print 'you called Foo.g()' + print('you called Foo.g()') def _h(self): - print 'you called Foo._h()' + print('you called Foo._h()') # A simple generator function def baz(): - for i in xrange(10): + for i in range(10): yield i*i # Proxy type for generator objects @@ -27,7 +27,7 @@ _exposed_ = ('next', '__next__') def __iter__(self): return self - def next(self): + def __next__(self): return self._callmethod('next') def __next__(self): return self._callmethod('__next__') @@ -59,7 +59,7 @@ manager = MyManager() manager.start() - print '-' * 20 + print('-' * 20) f1 = manager.Foo1() f1.f() @@ -67,7 +67,7 @@ assert not hasattr(f1, '_h') assert sorted(f1._exposed_) == sorted(['f', 'g']) - print '-' * 20 + print('-' * 20) f2 = manager.Foo2() f2.g() @@ -75,21 +75,21 @@ assert not hasattr(f2, 'f') assert sorted(f2._exposed_) == sorted(['g', '_h']) - print '-' * 20 + print('-' * 20) it = manager.baz() for i in it: - print '<%d>' % i, - print + print('<%d>' % i, end=' ') + print() - print '-' * 20 + print('-' * 20) op = manager.operator() - print 'op.add(23, 45) =', op.add(23, 45) - print 'op.pow(2, 94) =', op.pow(2, 94) - print 'op.getslice(range(10), 2, 6) =', op.getslice(range(10), 2, 6) - print 'op.repeat(range(5), 3) =', op.repeat(range(5), 3) - print 'op._exposed_ =', op._exposed_ + print('op.add(23, 45) =', op.add(23, 45)) + print('op.pow(2, 94) =', op.pow(2, 94)) + print('op.getslice(range(10), 2, 6) =', op.getslice(list(range(10)), 2, 6)) + print('op.repeat(range(5), 3) =', op.repeat(list(range(5)), 3)) + print('op._exposed_ =', op._exposed_) ## Modified: python/branches/py3k/Doc/includes/mp_pool.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_pool.py (original) +++ python/branches/py3k/Doc/includes/mp_pool.py Fri Nov 28 12:23:26 2008 @@ -43,17 +43,17 @@ # def test(): - print 'cpu_count() = %d\n' % multiprocessing.cpu_count() + print('cpu_count() = %d\n' % multiprocessing.cpu_count()) # # Create pool # PROCESSES = 4 - print 'Creating pool with %d processes\n' % PROCESSES + print('Creating pool with %d processes\n' % PROCESSES) pool = multiprocessing.Pool(PROCESSES) - print 'pool = %s' % pool - print + print('pool = %s' % pool) + print() # # Tests @@ -66,72 +66,72 @@ imap_it = pool.imap(calculatestar, TASKS) imap_unordered_it = pool.imap_unordered(calculatestar, TASKS) - print 'Ordered results using pool.apply_async():' + print('Ordered results using pool.apply_async():') for r in results: - print '\t', r.get() - print + print('\t', r.get()) + print() - print 'Ordered results using pool.imap():' + print('Ordered results using pool.imap():') for x in imap_it: - print '\t', x - print + print('\t', x) + print() - print 'Unordered results using pool.imap_unordered():' + print('Unordered results using pool.imap_unordered():') for x in imap_unordered_it: - print '\t', x - print + print('\t', x) + print() - print 'Ordered results using pool.map() --- will block till complete:' + print('Ordered results using pool.map() --- will block till complete:') for x in pool.map(calculatestar, TASKS): - print '\t', x - print + print('\t', x) + print() # # Simple benchmarks # N = 100000 - print 'def pow3(x): return x**3' + print('def pow3(x): return x**3') t = time.time() - A = map(pow3, xrange(N)) - print '\tmap(pow3, xrange(%d)):\n\t\t%s seconds' % \ - (N, time.time() - t) + A = list(map(pow3, range(N))) + print('\tmap(pow3, xrange(%d)):\n\t\t%s seconds' % \ + (N, time.time() - t)) t = time.time() - B = pool.map(pow3, xrange(N)) - print '\tpool.map(pow3, xrange(%d)):\n\t\t%s seconds' % \ - (N, time.time() - t) + B = pool.map(pow3, range(N)) + print('\tpool.map(pow3, xrange(%d)):\n\t\t%s seconds' % \ + (N, time.time() - t)) t = time.time() - C = list(pool.imap(pow3, xrange(N), chunksize=N//8)) - print '\tlist(pool.imap(pow3, xrange(%d), chunksize=%d)):\n\t\t%s' \ - ' seconds' % (N, N//8, time.time() - t) + C = list(pool.imap(pow3, range(N), chunksize=N//8)) + print('\tlist(pool.imap(pow3, xrange(%d), chunksize=%d)):\n\t\t%s' \ + ' seconds' % (N, N//8, time.time() - t)) assert A == B == C, (len(A), len(B), len(C)) - print + print() L = [None] * 1000000 - print 'def noop(x): pass' - print 'L = [None] * 1000000' + print('def noop(x): pass') + print('L = [None] * 1000000') t = time.time() - A = map(noop, L) - print '\tmap(noop, L):\n\t\t%s seconds' % \ - (time.time() - t) + A = list(map(noop, L)) + print('\tmap(noop, L):\n\t\t%s seconds' % \ + (time.time() - t)) t = time.time() B = pool.map(noop, L) - print '\tpool.map(noop, L):\n\t\t%s seconds' % \ - (time.time() - t) + print('\tpool.map(noop, L):\n\t\t%s seconds' % \ + (time.time() - t)) t = time.time() C = list(pool.imap(noop, L, chunksize=len(L)//8)) - print '\tlist(pool.imap(noop, L, chunksize=%d)):\n\t\t%s seconds' % \ - (len(L)//8, time.time() - t) + print('\tlist(pool.imap(noop, L, chunksize=%d)):\n\t\t%s seconds' % \ + (len(L)//8, time.time() - t)) assert A == B == C, (len(A), len(B), len(C)) - print + print() del A, B, C, L @@ -139,33 +139,33 @@ # Test error handling # - print 'Testing error handling:' + print('Testing error handling:') try: - print pool.apply(f, (5,)) + print(pool.apply(f, (5,))) except ZeroDivisionError: - print '\tGot ZeroDivisionError as expected from pool.apply()' + print('\tGot ZeroDivisionError as expected from pool.apply()') else: - raise AssertionError, 'expected ZeroDivisionError' + raise AssertionError('expected ZeroDivisionError') try: - print pool.map(f, range(10)) + print(pool.map(f, list(range(10)))) except ZeroDivisionError: - print '\tGot ZeroDivisionError as expected from pool.map()' + print('\tGot ZeroDivisionError as expected from pool.map()') else: - raise AssertionError, 'expected ZeroDivisionError' + raise AssertionError('expected ZeroDivisionError') try: - print list(pool.imap(f, range(10))) + print(list(pool.imap(f, list(range(10))))) except ZeroDivisionError: - print '\tGot ZeroDivisionError as expected from list(pool.imap())' + print('\tGot ZeroDivisionError as expected from list(pool.imap())') else: - raise AssertionError, 'expected ZeroDivisionError' + raise AssertionError('expected ZeroDivisionError') - it = pool.imap(f, range(10)) + it = pool.imap(f, list(range(10))) for i in range(10): try: - x = it.next() + x = next(it) except ZeroDivisionError: if i == 5: pass @@ -173,17 +173,17 @@ break else: if i == 5: - raise AssertionError, 'expected ZeroDivisionError' + raise AssertionError('expected ZeroDivisionError') assert i == 9 - print '\tGot ZeroDivisionError as expected from IMapIterator.next()' - print + print('\tGot ZeroDivisionError as expected from IMapIterator.next()') + print() # # Testing timeouts # - print 'Testing ApplyResult.get() with timeout:', + print('Testing ApplyResult.get() with timeout:', end=' ') res = pool.apply_async(calculate, TASKS[0]) while 1: sys.stdout.flush() @@ -192,10 +192,10 @@ break except multiprocessing.TimeoutError: sys.stdout.write('.') - print - print + print() + print() - print 'Testing IMapIterator.next() with timeout:', + print('Testing IMapIterator.next() with timeout:', end=' ') it = pool.imap(calculatestar, TASKS) while 1: sys.stdout.flush() @@ -205,14 +205,14 @@ break except multiprocessing.TimeoutError: sys.stdout.write('.') - print - print + print() + print() # # Testing callback # - print 'Testing callback:' + print('Testing callback:') A = [] B = [56, 0, 1, 8, 27, 64, 125, 216, 343, 512, 729] @@ -220,13 +220,13 @@ r = pool.apply_async(mul, (7, 8), callback=A.append) r.wait() - r = pool.map_async(pow3, range(10), callback=A.extend) + r = pool.map_async(pow3, list(range(10)), callback=A.extend) r.wait() if A == B: - print '\tcallbacks succeeded\n' + print('\tcallbacks succeeded\n') else: - print '\t*** callbacks failed\n\t\t%s != %s\n' % (A, B) + print('\t*** callbacks failed\n\t\t%s != %s\n' % (A, B)) # # Check there are no outstanding tasks @@ -238,7 +238,7 @@ # Check close() methods # - print 'Testing close():' + print('Testing close():') for worker in pool._pool: assert worker.is_alive() @@ -252,13 +252,13 @@ for worker in pool._pool: assert not worker.is_alive() - print '\tclose() succeeded\n' + print('\tclose() succeeded\n') # # Check terminate() method # - print 'Testing terminate():' + print('Testing terminate():') pool = multiprocessing.Pool(2) DELTA = 0.1 @@ -270,13 +270,13 @@ for worker in pool._pool: assert not worker.is_alive() - print '\tterminate() succeeded\n' + print('\tterminate() succeeded\n') # # Check garbage collection # - print 'Testing garbage collection:' + print('Testing garbage collection:') pool = multiprocessing.Pool(2) DELTA = 0.1 @@ -291,7 +291,7 @@ for worker in processes: assert not worker.is_alive() - print '\tgarbage collection succeeded\n' + print('\tgarbage collection succeeded\n') if __name__ == '__main__': @@ -300,12 +300,12 @@ assert len(sys.argv) in (1, 2) if len(sys.argv) == 1 or sys.argv[1] == 'processes': - print ' Using processes '.center(79, '-') + print(' Using processes '.center(79, '-')) elif sys.argv[1] == 'threads': - print ' Using threads '.center(79, '-') + print(' Using threads '.center(79, '-')) import multiprocessing.dummy as multiprocessing else: - print 'Usage:\n\t%s [processes | threads]' % sys.argv[0] + print('Usage:\n\t%s [processes | threads]' % sys.argv[0]) raise SystemExit(2) test() Modified: python/branches/py3k/Doc/includes/mp_synchronize.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_synchronize.py (original) +++ python/branches/py3k/Doc/includes/mp_synchronize.py Fri Nov 28 12:23:26 2008 @@ -3,7 +3,7 @@ # import time, sys, random -from Queue import Empty +from queue import Empty import multiprocessing # may get overwritten @@ -15,7 +15,7 @@ time.sleep(random.random()*4) mutex.acquire() - print '\n\t\t\t' + str(multiprocessing.current_process()) + ' has finished' + print('\n\t\t\t' + str(multiprocessing.current_process()) + ' has finished') running.value -= 1 mutex.release() @@ -31,12 +31,12 @@ while running.value > 0: time.sleep(0.08) mutex.acquire() - print running.value, + print(running.value, end=' ') sys.stdout.flush() mutex.release() - print - print 'No more running processes' + print() + print('No more running processes') #### TEST_QUEUE @@ -57,22 +57,22 @@ while o != 'STOP': try: o = q.get(timeout=0.3) - print o, + print(o, end=' ') sys.stdout.flush() except Empty: - print 'TIMEOUT' + print('TIMEOUT') - print + print() #### TEST_CONDITION def condition_func(cond): cond.acquire() - print '\t' + str(cond) + print('\t' + str(cond)) time.sleep(2) - print '\tchild is notifying' - print '\t' + str(cond) + print('\tchild is notifying') + print('\t' + str(cond)) cond.notify() cond.release() @@ -80,26 +80,26 @@ cond = multiprocessing.Condition() p = multiprocessing.Process(target=condition_func, args=(cond,)) - print cond + print(cond) cond.acquire() - print cond + print(cond) cond.acquire() - print cond + print(cond) p.start() - print 'main is waiting' + print('main is waiting') cond.wait() - print 'main has woken up' + print('main has woken up') - print cond + print(cond) cond.release() - print cond + print(cond) cond.release() p.join() - print cond + print(cond) #### TEST_SEMAPHORE @@ -109,7 +109,7 @@ mutex.acquire() running.value += 1 - print running.value, 'tasks are running' + print(running.value, 'tasks are running') mutex.release() random.seed() @@ -117,7 +117,7 @@ mutex.acquire() running.value -= 1 - print '%s has finished' % multiprocessing.current_process() + print('%s has finished' % multiprocessing.current_process()) mutex.release() sema.release() @@ -143,30 +143,30 @@ #### TEST_JOIN_TIMEOUT def join_timeout_func(): - print '\tchild sleeping' + print('\tchild sleeping') time.sleep(5.5) - print '\n\tchild terminating' + print('\n\tchild terminating') def test_join_timeout(): p = multiprocessing.Process(target=join_timeout_func) p.start() - print 'waiting for process to finish' + print('waiting for process to finish') while 1: p.join(timeout=1) if not p.is_alive(): break - print '.', + print('.', end=' ') sys.stdout.flush() #### TEST_EVENT def event_func(event): - print '\t%r is waiting' % multiprocessing.current_process() + print('\t%r is waiting' % multiprocessing.current_process()) event.wait() - print '\t%r has woken up' % multiprocessing.current_process() + print('\t%r has woken up' % multiprocessing.current_process()) def test_event(): event = multiprocessing.Event() @@ -177,10 +177,10 @@ for p in processes: p.start() - print 'main is sleeping' + print('main is sleeping') time.sleep(2) - print 'main is setting event' + print('main is setting event') event.set() for p in processes: @@ -200,7 +200,7 @@ sa = list(shared_arrays[i][:]) assert a == sa - print 'Tests passed' + print('Tests passed') def test_sharedvalues(): values = [ @@ -209,9 +209,9 @@ ('d', 1.25) ] arrays = [ - ('i', range(100)), + ('i', list(range(100))), ('d', [0.25 * i for i in range(100)]), - ('H', range(1000)) + ('H', list(range(1000))) ] shared_values = [multiprocessing.Value(id, v) for id, v in values] @@ -238,15 +238,15 @@ test_semaphore, test_join_timeout, test_event, test_sharedvalues ]: - print '\n\t######## %s\n' % func.__name__ + print('\n\t######## %s\n' % func.__name__) func() ignore = multiprocessing.active_children() # cleanup any old processes if hasattr(multiprocessing, '_debug_info'): info = multiprocessing._debug_info() if info: - print info - raise ValueError, 'there should be no positive refcounts left' + print(info) + raise ValueError('there should be no positive refcounts left') if __name__ == '__main__': @@ -255,19 +255,19 @@ assert len(sys.argv) in (1, 2) if len(sys.argv) == 1 or sys.argv[1] == 'processes': - print ' Using processes '.center(79, '-') + print(' Using processes '.center(79, '-')) namespace = multiprocessing elif sys.argv[1] == 'manager': - print ' Using processes and a manager '.center(79, '-') + print(' Using processes and a manager '.center(79, '-')) namespace = multiprocessing.Manager() namespace.Process = multiprocessing.Process namespace.current_process = multiprocessing.current_process namespace.active_children = multiprocessing.active_children elif sys.argv[1] == 'threads': - print ' Using threads '.center(79, '-') + print(' Using threads '.center(79, '-')) import multiprocessing.dummy as namespace else: - print 'Usage:\n\t%s [processes | manager | threads]' % sys.argv[0] - raise SystemExit, 2 + print('Usage:\n\t%s [processes | manager | threads]' % sys.argv[0]) + raise SystemExit(2) test(namespace) Modified: python/branches/py3k/Doc/includes/mp_webserver.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_webserver.py (original) +++ python/branches/py3k/Doc/includes/mp_webserver.py Fri Nov 28 12:23:26 2008 @@ -13,8 +13,8 @@ import sys from multiprocessing import Process, current_process, freeze_support -from BaseHTTPServer import HTTPServer -from SimpleHTTPServer import SimpleHTTPRequestHandler +from http.server import HTTPServer +from http.server import SimpleHTTPRequestHandler if sys.platform == 'win32': import multiprocessing.reduction # make sockets pickable/inheritable @@ -54,9 +54,9 @@ ADDRESS = ('localhost', 8000) NUMBER_OF_PROCESSES = 4 - print 'Serving at http://%s:%d using %d worker processes' % \ - (ADDRESS[0], ADDRESS[1], NUMBER_OF_PROCESSES) - print 'To exit press Ctrl-' + ['C', 'Break'][sys.platform=='win32'] + print('Serving at http://%s:%d using %d worker processes' % \ + (ADDRESS[0], ADDRESS[1], NUMBER_OF_PROCESSES)) + print('To exit press Ctrl-' + ['C', 'Break'][sys.platform=='win32']) os.chdir(DIR) runpool(ADDRESS, NUMBER_OF_PROCESSES) Modified: python/branches/py3k/Doc/includes/mp_workers.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_workers.py (original) +++ python/branches/py3k/Doc/includes/mp_workers.py Fri Nov 28 12:23:26 2008 @@ -65,9 +65,9 @@ Process(target=worker, args=(task_queue, done_queue)).start() # Get and print results - print 'Unordered results:' + print('Unordered results:') for i in range(len(TASKS1)): - print '\t', done_queue.get() + print('\t', done_queue.get()) # Add more tasks using `put()` for task in TASKS2: @@ -75,7 +75,7 @@ # Get and print some more results for i in range(len(TASKS2)): - print '\t', done_queue.get() + print('\t', done_queue.get()) # Tell child processes to stop for i in range(NUMBER_OF_PROCESSES): From python-3000-checkins at python.org Fri Nov 28 12:24:16 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 28 Nov 2008 12:24:16 +0100 (CET) Subject: [Python-3000-checkins] r67418 - python/branches/py3k/Misc/NEWS Message-ID: <20081128112416.745111E4002@bag.python.org> Author: christian.heimes Date: Fri Nov 28 12:24:16 2008 New Revision: 67418 Log: Forgot to update Misc/NEWS Modified: python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Nov 28 12:24:16 2008 @@ -44,6 +44,8 @@ Docs ---- +- Issue #4449: Fixed multiprocessing examples + - Issue #3799: Document that dbm.gnu and dbm.ndbm will accept string arguments for keys and values which will be converted to bytes before committal. From python-3000-checkins at python.org Fri Nov 28 19:46:20 2008 From: python-3000-checkins at python.org (jesse.noller) Date: Fri, 28 Nov 2008 19:46:20 +0100 (CET) Subject: [Python-3000-checkins] r67421 - in python/branches/py3k: Doc/library/multiprocessing.rst Message-ID: <20081128184620.7EAB51E4002@bag.python.org> Author: jesse.noller Date: Fri Nov 28 19:46:19 2008 New Revision: 67421 Log: Merge r67419 to py3k, mp doc fixes Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/multiprocessing.rst Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Fri Nov 28 19:46:19 2008 @@ -24,6 +24,29 @@ import it will result in an :exc:`ImportError`. See :issue:`3770` for additional information. +.. note:: + + Functionality within this package requires that the ``__main__`` method be + importable by the children. This is covered in :ref:`multiprocessing-programming` + however it is worth pointing out here. This means that some examples, such + as the :class:`multiprocessing.Pool` examples will not work in the + interactive interpreter. For example:: + + >>> from multiprocessing import Pool + >>> p = Pool(5) + >>> def f(x): + ... return x*x + ... + >>> p.map(f, [1,2,3]) + Process PoolWorker-1: + Process PoolWorker-2: + Traceback (most recent call last): + Traceback (most recent call last): + AttributeError: 'module' object has no attribute 'f' + AttributeError: 'module' object has no attribute 'f' + AttributeError: 'module' object has no attribute 'f' + + The :class:`Process` class ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -32,17 +55,36 @@ follows the API of :class:`threading.Thread`. A trivial example of a multiprocess program is :: - from multiprocessing import Process + from multiprocessing import Process def f(name): print('hello', name) - if __name__ == '__main__': - p = Process(target=f, args=('bob',)) - p.start() - p.join() + if __name__ == '__main__': + p = Process(target=f, args=('bob',)) + p.start() + p.join() -Here the function ``f`` is run in a child process. +To show the individual process IDs involved, here is an expanded example:: + + from multiprocessing import Process + import os + + def info(title): + print title + print 'module name:', __name__ + print 'parent process:', os.getppid() + print 'process id:', os.getpid() + + def f(name): + info('function f') + print 'hello', name + + if __name__ == '__main__': + info('main line') + p = Process(target=f, args=('bob',)) + p.start() + p.join() For an explanation of why (on Windows) the ``if __name__ == '__main__'`` part is necessary, see :ref:`multiprocessing-programming`. @@ -231,10 +273,10 @@ return x*x if __name__ == '__main__': - pool = Pool(processes=4) # start 4 worker processes - result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously - print(result.get(timeout=1)) # prints "100" unless your computer is *very* slow - print(pool.map(f, range(10))) # prints "[0, 1, 4,..., 81]" + pool = Pool(processes=4) # start 4 worker processes + result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously + print result.get(timeout=1) # prints "100" unless your computer is *very* slow + print pool.map(f, range(10)) # prints "[0, 1, 4,..., 81]" Reference @@ -305,7 +347,7 @@ semantics. Multiple processes may be given the same name. The initial name is set by the constructor. - .. method:: is_alive() + .. method:: is_alive Return whether the process is alive. @@ -814,6 +856,9 @@ acceptable. If *block* is ``True`` and *timeout* is not ``None`` then it specifies a timeout in seconds. If *block* is ``False`` then *timeout* is ignored. + + Note that on OS/X ``sem_timedwait`` is unsupported, so timeout arguments + for these will be ignored. .. note:: @@ -1087,6 +1132,27 @@ A class method which creates a manager object referring to a pre-existing server process which is using the given address and authentication key. + .. method:: get_server() + + Returns a :class:`Server` object which represents the actual server under + the control of the Manager. The :class:`Server` object supports the + :meth:`serve_forever` method:: + + >>> from multiprocessing.managers import BaseManager + >>> m = BaseManager(address=('', 50000), authkey='abc')) + >>> server = m.get_server() + >>> s.serve_forever() + + :class:`Server` additionally have an :attr:`address` attribute. + + .. method:: connect() + + Connect a local manager object to a remote manager process:: + + >>> from multiprocessing.managers import BaseManager + >>> m = BaseManager(address='127.0.0.1', authkey='abc)) + >>> m.connect() + .. method:: shutdown() Stop the process used by the manager. This is only available if @@ -1265,19 +1331,20 @@ >>> queue = queue.Queue() >>> class QueueManager(BaseManager): pass ... - >>> QueueManager.register('getQueue', callable=lambda:queue) + >>> QueueManager.register('get_queue', callable=lambda:queue) >>> m = QueueManager(address=('', 50000), authkey='abracadabra') - >>> m.serveForever() + >>> s = m.get_server() + >>> s.serveForever() One client can access the server as follows:: >>> from multiprocessing.managers import BaseManager >>> class QueueManager(BaseManager): pass ... - >>> QueueManager.register('getQueue') - >>> m = QueueManager.from_address(address=('foo.bar.org', 50000), - >>> authkey='abracadabra') - >>> queue = m.getQueue() + >>> QueueManager.register('get_queue') + >>> m = QueueManager(address=('foo.bar.org', 50000), authkey='abracadabra') + >>> m.connect() + >>> queue = m.get_queue() >>> queue.put('hello') Another client can also use it:: @@ -1291,6 +1358,27 @@ >>> queue.get() 'hello' +Local processes can also access that queue, using the code from above on the +client to access it remotely:: + + >>> from multiprocessing import Process, Queue + >>> from multiprocessing.managers import BaseManager + >>> class Worker(Process): + ... def __init__(self, q): + ... self.q = q + ... super(Worker, self).__init__() + ... def run(self): + ... self.q.put('local hello') + ... + >>> queue = Queue() + >>> w = Worker(queue) + >>> w.start() + >>> class QueueManager(BaseManager): pass + ... + >>> QueueManager.register('get_queue', callable=lambda: queue) + >>> m = QueueManager(address=('', 50000), authkey='abracadabra') + >>> s = m.get_server() + >>> s.serve_forever() Proxy Objects ~~~~~~~~~~~~~ From python-3000-checkins at python.org Fri Nov 28 19:47:25 2008 From: python-3000-checkins at python.org (jesse.noller) Date: Fri, 28 Nov 2008 19:47:25 +0100 (CET) Subject: [Python-3000-checkins] r67422 - python/branches/py3k/Doc/includes/mp_distributing.py Message-ID: <20081128184725.10DC41E400C@bag.python.org> Author: jesse.noller Date: Fri Nov 28 19:47:24 2008 New Revision: 67422 Log: Fix mp example, remove fix_logger call Modified: python/branches/py3k/Doc/includes/mp_distributing.py Modified: python/branches/py3k/Doc/includes/mp_distributing.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_distributing.py (original) +++ python/branches/py3k/Doc/includes/mp_distributing.py Fri Nov 28 19:47:24 2008 @@ -37,7 +37,6 @@ _logger = logging.getLogger('distributing') _logger.propogate = 0 -util.fix_up_logger(_logger) _formatter = logging.Formatter(util.DEFAULT_LOGGING_FORMAT) _handler = logging.StreamHandler() _handler.setFormatter(_formatter) From python-3000-checkins at python.org Fri Nov 28 21:57:28 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 28 Nov 2008 21:57:28 +0100 (CET) Subject: [Python-3000-checkins] r67425 - python/branches/py3k Message-ID: <20081128205728.65AC41E4002@bag.python.org> Author: benjamin.peterson Date: Fri Nov 28 21:57:28 2008 New Revision: 67425 Log: Blocked revisions 67349,67353,67396,67407,67411 via svnmerge ........ r67349 | matthias.klose | 2008-11-23 07:37:03 -0600 (Sun, 23 Nov 2008) | 3 lines - Modules/Setup.dist: Mention _functools in section "Modules that should always be present (non UNIX dependent)" ........ r67353 | matthias.klose | 2008-11-23 07:54:42 -0600 (Sun, 23 Nov 2008) | 2 lines - Fix typo in last checkin ........ r67396 | matthias.klose | 2008-11-26 11:32:49 -0600 (Wed, 26 Nov 2008) | 2 lines - Modules/Setup.dist: Mention _elementtree and _pickle. ........ r67407 | matthias.klose | 2008-11-27 01:45:25 -0600 (Thu, 27 Nov 2008) | 2 lines - Modules/Setup.dist: Update pyexpat ........ r67411 | matthias.klose | 2008-11-27 04:14:22 -0600 (Thu, 27 Nov 2008) | 2 lines - Modules/Setup.dist: Update _elementtree, add _bisect, datetime ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Nov 29 00:01:28 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 29 Nov 2008 00:01:28 +0100 (CET) Subject: [Python-3000-checkins] r67429 - in python/branches/py3k: Lib/lib2to3/fixer_base.py Lib/lib2to3/fixer_util.py Lib/lib2to3/fixes/fix_dict.py Lib/lib2to3/fixes/fix_except.py Lib/lib2to3/fixes/fix_imports.py Lib/lib2to3/fixes/fix_imports2.py Lib/lib2to3/fixes/fix_next.py Lib/lib2to3/fixes/fix_numliterals.py Lib/lib2to3/fixes/fix_renames.py Lib/lib2to3/fixes/fix_urllib.py Lib/lib2to3/pgen2/parse.py Lib/lib2to3/pytree.py Lib/lib2to3/refactor.py Lib/lib2to3/tests Lib/lib2to3/tests/data Lib/lib2to3/tests/test_fixers.py Lib/lib2to3/tests/test_refactor.py Message-ID: <20081128230128.E298B1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Nov 29 00:01:28 2008 New Revision: 67429 Log: Merged revisions 67428 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r67428 | benjamin.peterson | 2008-11-28 16:12:14 -0600 (Fri, 28 Nov 2008) | 57 lines Merged revisions 67384,67386-67387,67389-67390,67392,67399-67400,67403-67405,67426 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r67384 | benjamin.peterson | 2008-11-25 16:13:31 -0600 (Tue, 25 Nov 2008) | 4 lines don't duplicate calls to start_tree() RefactoringTool.pre_order values now holds a list of the fixers while pre_order_mapping holds the dict. ........ r67386 | benjamin.peterson | 2008-11-25 16:44:52 -0600 (Tue, 25 Nov 2008) | 1 line #4423 fix_imports was still replacing usage of a module if attributes were being used ........ r67387 | benjamin.peterson | 2008-11-25 16:47:54 -0600 (Tue, 25 Nov 2008) | 1 line fix broken test ........ r67389 | benjamin.peterson | 2008-11-25 17:13:17 -0600 (Tue, 25 Nov 2008) | 1 line remove compatibility code; we only cater to 2.5+ ........ r67390 | benjamin.peterson | 2008-11-25 22:03:36 -0600 (Tue, 25 Nov 2008) | 1 line fix #3994; the usage of changed imports was fixed in nested cases ........ r67392 | benjamin.peterson | 2008-11-26 11:11:40 -0600 (Wed, 26 Nov 2008) | 1 line simpilfy and comment fix_imports ........ r67399 | benjamin.peterson | 2008-11-26 11:47:03 -0600 (Wed, 26 Nov 2008) | 1 line remove more compatibility code ........ r67400 | benjamin.peterson | 2008-11-26 12:07:41 -0600 (Wed, 26 Nov 2008) | 1 line set svn:ignore ........ r67403 | benjamin.peterson | 2008-11-26 13:11:11 -0600 (Wed, 26 Nov 2008) | 1 line wrap import ........ r67404 | benjamin.peterson | 2008-11-26 13:29:49 -0600 (Wed, 26 Nov 2008) | 1 line build the fix_imports pattern in compile_pattern, so MAPPING can be changed and reflected in the pattern ........ r67405 | benjamin.peterson | 2008-11-26 14:01:24 -0600 (Wed, 26 Nov 2008) | 1 line stop ugly messages about runtime errors being from printed ........ r67426 | benjamin.peterson | 2008-11-28 16:01:40 -0600 (Fri, 28 Nov 2008) | 5 lines don't replace a module name if it is in the middle of a attribute lookup This fix also stops module names from being replaced if they are not in an attribute lookup. ........ ................ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/lib2to3/fixer_base.py python/branches/py3k/Lib/lib2to3/fixer_util.py python/branches/py3k/Lib/lib2to3/fixes/fix_dict.py python/branches/py3k/Lib/lib2to3/fixes/fix_except.py python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py python/branches/py3k/Lib/lib2to3/fixes/fix_imports2.py python/branches/py3k/Lib/lib2to3/fixes/fix_next.py python/branches/py3k/Lib/lib2to3/fixes/fix_numliterals.py python/branches/py3k/Lib/lib2to3/fixes/fix_renames.py python/branches/py3k/Lib/lib2to3/fixes/fix_urllib.py python/branches/py3k/Lib/lib2to3/pgen2/parse.py python/branches/py3k/Lib/lib2to3/pytree.py python/branches/py3k/Lib/lib2to3/refactor.py python/branches/py3k/Lib/lib2to3/tests/ (props changed) python/branches/py3k/Lib/lib2to3/tests/data/ (props changed) python/branches/py3k/Lib/lib2to3/tests/test_fixers.py python/branches/py3k/Lib/lib2to3/tests/test_refactor.py Modified: python/branches/py3k/Lib/lib2to3/fixer_base.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixer_base.py (original) +++ python/branches/py3k/Lib/lib2to3/fixer_base.py Sat Nov 29 00:01:28 2008 @@ -7,12 +7,6 @@ import logging import itertools -# Get a usable 'set' constructor -try: - set -except NameError: - from sets import Set as set - # Local imports from .patcomp import PatternCompiler from . import pygram Modified: python/branches/py3k/Lib/lib2to3/fixer_util.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixer_util.py (original) +++ python/branches/py3k/Lib/lib2to3/fixer_util.py Sat Nov 29 00:01:28 2008 @@ -153,30 +153,6 @@ and node.children[0].value == "[" and node.children[-1].value == "]") -########################################################### -### Common portability code. This allows fixers to do, eg, -### "from .util import set" and forget about it. -########################################################### - -try: - any = any -except NameError: - def any(l): - for o in l: - if o: - return True - return False - -try: - set = set -except NameError: - from sets import Set as set - -try: - reversed = reversed -except NameError: - def reversed(l): - return l[::-1] ########################################################### ### Misc Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_dict.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_dict.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_dict.py Sat Nov 29 00:01:28 2008 @@ -28,7 +28,7 @@ from .. import patcomp from ..pgen2 import token from .. import fixer_base -from ..fixer_util import Name, Call, LParen, RParen, ArgList, Dot, set +from ..fixer_util import Name, Call, LParen, RParen, ArgList, Dot from .. import fixer_util Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_except.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_except.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_except.py Sat Nov 29 00:01:28 2008 @@ -25,7 +25,7 @@ from .. import pytree from ..pgen2 import token from .. import fixer_base -from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, reversed +from ..fixer_util import Assign, Attr, Name, is_tuple, is_list def find_excepts(nodes): for i, n in enumerate(nodes): Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_imports.py Sat Nov 29 00:01:28 2008 @@ -1,9 +1,9 @@ """Fix incompatible imports and module references.""" -# Author: Collin Winter +# Authors: Collin Winter, Nick Edds # Local imports from .. import fixer_base -from ..fixer_util import Name, attr_chain, any, set +from ..fixer_util import Name, attr_chain MAPPING = {'StringIO': 'io', 'cStringIO': 'io', @@ -61,36 +61,49 @@ def build_pattern(mapping=MAPPING): - mod_list = ' | '.join(["module='" + key + "'" for key in mapping.keys()]) - mod_name_list = ' | '.join(["module_name='" + key + "'" for key in mapping.keys()]) - yield """import_name< 'import' ((%s) + mod_list = ' | '.join(["module_name='%s'" % key for key in mapping]) + bare_names = alternates(mapping.keys()) + + yield """name_import=import_name< 'import' ((%s) | dotted_as_names< any* (%s) any* >) > """ % (mod_list, mod_list) yield """import_from< 'from' (%s) 'import' ['('] ( any | import_as_name< any 'as' any > | import_as_names< any* >) [')'] > - """ % mod_name_list + """ % mod_list yield """import_name< 'import' dotted_as_name< (%s) 'as' any > > - """ % mod_name_list - # Find usages of module members in code e.g. urllib.foo(bar) - yield """power< (%s) - trailer<'.' any > any* > - """ % mod_name_list - yield """bare_name=%s""" % alternates(mapping.keys()) + """ % mod_list + + # Find usages of module members in code e.g. thread.foo(bar) + yield "power< bare_with_attr=(%s) trailer<'.' any > any* >" % bare_names + class FixImports(fixer_base.BaseFix): - PATTERN = "|".join(build_pattern()) + order = "pre" # Pre-order tree traversal + # This is overridden in fix_imports2. mapping = MAPPING - # Don't match the node if it's within another match + def build_pattern(self): + return "|".join(build_pattern(self.mapping)) + + def compile_pattern(self): + # We override this, so MAPPING can be pragmatically altered and the + # changes will be reflected in PATTERN. + self.PATTERN = self.build_pattern() + super(FixImports, self).compile_pattern() + + # Don't match the node if it's within another match. def match(self, node): match = super(FixImports, self).match results = match(node) if results: - if any([match(obj) for obj in attr_chain(node, "parent")]): + # Module usage could be in the trailier of an attribute lookup, so + # we might have nested matches when "bare_with_attr" is present. + if "bare_with_attr" not in results and \ + any([match(obj) for obj in attr_chain(node, "parent")]): return False return results return False @@ -100,20 +113,17 @@ self.replace = {} def transform(self, node, results): - import_mod = results.get("module") - mod_name = results.get("module_name") - bare_name = results.get("bare_name") - - if import_mod or mod_name: - new_name = self.mapping[(import_mod or mod_name).value] - + import_mod = results.get("module_name") if import_mod: - self.replace[import_mod.value] = new_name + new_name = self.mapping[(import_mod or mod_name).value] + if "name_import" in results: + # If it's not a "from x import x, y" or "import x as y" import, + # marked its usage to be replaced. + self.replace[import_mod.value] = new_name import_mod.replace(Name(new_name, prefix=import_mod.get_prefix())) - elif mod_name: - mod_name.replace(Name(new_name, prefix=mod_name.get_prefix())) - elif bare_name: - bare_name = bare_name[0] + else: + # Replace usage of the module. + bare_name = results["bare_with_attr"][0] new_name = self.replace.get(bare_name.value) if new_name: bare_name.replace(Name(new_name, prefix=bare_name.get_prefix())) Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_imports2.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_imports2.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_imports2.py Sat Nov 29 00:01:28 2008 @@ -10,7 +10,6 @@ class FixImports2(fix_imports.FixImports): - PATTERN = "|".join((fix_imports.build_pattern(MAPPING))) order = "post" Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_next.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_next.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_next.py Sat Nov 29 00:01:28 2008 @@ -9,7 +9,7 @@ from ..pgen2 import token from ..pygram import python_symbols as syms from .. import fixer_base -from ..fixer_util import Name, Call, find_binding, any +from ..fixer_util import Name, Call, find_binding bind_warning = "Calls to builtin next() possibly shadowed by global binding" Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_numliterals.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_numliterals.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_numliterals.py Sat Nov 29 00:01:28 2008 @@ -6,7 +6,7 @@ # Local imports from ..pgen2 import token from .. import fixer_base -from ..fixer_util import Number, set +from ..fixer_util import Number class FixNumliterals(fixer_base.BaseFix): Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_renames.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_renames.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_renames.py Sat Nov 29 00:01:28 2008 @@ -8,7 +8,7 @@ # Local imports from .. import fixer_base -from ..fixer_util import Name, attr_chain, any, set +from ..fixer_util import Name, attr_chain MAPPING = {"sys": {"maxint" : "maxsize"}, } Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_urllib.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/fixes/fix_urllib.py (original) +++ python/branches/py3k/Lib/lib2to3/fixes/fix_urllib.py Sat Nov 29 00:01:28 2008 @@ -7,7 +7,7 @@ # Local imports from .fix_imports import alternates, FixImports from .. import fixer_base -from ..fixer_util import Name, Comma, FromImport, Newline, attr_chain, any, set +from ..fixer_util import Name, Comma, FromImport, Newline, attr_chain MAPPING = {'urllib': [ ('urllib.request', @@ -65,7 +65,9 @@ class FixUrllib(FixImports): - PATTERN = "|".join(build_pattern()) + + def build_pattern(self): + return "|".join(build_pattern()) def transform_import(self, node, results): """Transform for the basic import case. Replaces the old Modified: python/branches/py3k/Lib/lib2to3/pgen2/parse.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/pgen2/parse.py (original) +++ python/branches/py3k/Lib/lib2to3/pgen2/parse.py Sat Nov 29 00:01:28 2008 @@ -10,12 +10,6 @@ """ -# Get a usable 'set' constructor -try: - set -except NameError: - from sets import Set as set - # Local imports from . import token Modified: python/branches/py3k/Lib/lib2to3/pytree.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/pytree.py (original) +++ python/branches/py3k/Lib/lib2to3/pytree.py Sat Nov 29 00:01:28 2008 @@ -11,6 +11,9 @@ __author__ = "Guido van Rossum " +import sys +from io import StringIO + HUGE = 0x7FFFFFFF # maximum repeat count, default max @@ -655,6 +658,11 @@ elif self.name == "bare_name": yield self._bare_name_matches(nodes) else: + # The reason for this is that hitting the recursion limit usually + # results in some ugly messages about how RuntimeErrors are being + # ignored. + save_stderr = sys.stderr + sys.stderr = StringIO() try: for count, r in self._recursive_matches(nodes, 0): if self.name: @@ -667,6 +675,8 @@ if self.name: r[self.name] = nodes[:count] yield count, r + finally: + sys.stderr = save_stderr def _iterative_matches(self, nodes): """Helper to iteratively yield the matches.""" Modified: python/branches/py3k/Lib/lib2to3/refactor.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/refactor.py (original) +++ python/branches/py3k/Lib/lib2to3/refactor.py Sat Nov 29 00:01:28 2008 @@ -123,8 +123,8 @@ logger=self.logger) self.pre_order, self.post_order = self.get_fixers() - self.pre_order = get_headnode_dict(self.pre_order) - self.post_order = get_headnode_dict(self.post_order) + self.pre_order_mapping = get_headnode_dict(self.pre_order) + self.post_order_mapping = get_headnode_dict(self.post_order) self.files = [] # List of files that were or should be modified @@ -290,13 +290,12 @@ # Two calls to chain are required because pre_order.values() # will be a list of lists of fixers: # [[, ], []] - all_fixers = chain(chain(*self.pre_order.values()),\ - chain(*self.post_order.values())) + all_fixers = chain(self.pre_order, self.post_order) for fixer in all_fixers: fixer.start_tree(tree, name) - self.traverse_by(self.pre_order, tree.pre_order()) - self.traverse_by(self.post_order, tree.post_order()) + self.traverse_by(self.pre_order_mapping, tree.pre_order()) + self.traverse_by(self.post_order_mapping, tree.post_order()) for fixer in all_fixers: fixer.finish_tree(tree, name) Modified: python/branches/py3k/Lib/lib2to3/tests/test_fixers.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/test_fixers.py (original) +++ python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Sat Nov 29 00:01:28 2008 @@ -15,10 +15,7 @@ from operator import itemgetter # Local imports -from .. import pygram -from .. import pytree -from .. import refactor -from .. import fixer_util +from lib2to3 import pygram, pytree, refactor, fixer_util class FixerTestCase(support.TestCase): @@ -30,10 +27,9 @@ self.fixer_log = [] self.filename = "" - for order in (self.refactor.pre_order.values(),\ - self.refactor.post_order.values()): - for fixer in chain(*order): - fixer.log = self.fixer_log + for fixer in chain(self.refactor.pre_order, + self.refactor.post_order): + fixer.log = self.fixer_log def _check(self, before, after): before = support.reformat(before) @@ -1488,6 +1484,44 @@ """ % (new, new) self.check(b, a) + b = """ + from %s import x + %s = 23 + """ % (old, old) + a = """ + from %s import x + %s = 23 + """ % (new, old) + self.check(b, a) + + s = """ + def f(): + %s.method() + """ % (old,) + self.unchanged(s) + + # test nested usage + b = """ + import %s + %s.bar(%s.foo) + """ % (old, old, old) + a = """ + import %s + %s.bar(%s.foo) + """ % (new, new, new) + self.check(b, a) + + b = """ + import %s + x.%s + """ % (old, old) + a = """ + import %s + x.%s + """ % (new, old) + self.check(b, a) + + class Test_imports2(Test_imports): fixer = "imports2" Modified: python/branches/py3k/Lib/lib2to3/tests/test_refactor.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/test_refactor.py (original) +++ python/branches/py3k/Lib/lib2to3/tests/test_refactor.py Sat Nov 29 00:01:28 2008 @@ -161,7 +161,7 @@ self.assertEqual(len(rt.post_order), 0) rt = self.rt(explicit=["myfixes.fix_explicit"]) - for fix in rt.post_order[None]: + for fix in rt.post_order: if isinstance(fix, FixExplicit): break else: From python-3000-checkins at python.org Sat Nov 29 00:28:42 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 29 Nov 2008 00:28:42 +0100 (CET) Subject: [Python-3000-checkins] r67436 - in python/branches/py3k: Lib/idlelib/WindowList.py Misc/NEWS Message-ID: <20081128232842.2FFB31E4002@bag.python.org> Author: amaury.forgeotdarc Date: Sat Nov 29 00:28:42 2008 New Revision: 67436 Log: #4455: IDLE failed to display the windows list when two windows have the same title. Windows objects cannot be compared, and it's better to have a consistent order; so We add the window unique ID to the sort key. Reviewed by Benjamin Peterson. Modified: python/branches/py3k/Lib/idlelib/WindowList.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/idlelib/WindowList.py ============================================================================== --- python/branches/py3k/Lib/idlelib/WindowList.py (original) +++ python/branches/py3k/Lib/idlelib/WindowList.py Sat Nov 29 00:28:42 2008 @@ -26,9 +26,9 @@ title = window.get_title() except TclError: continue - list.append((title, window)) + list.append((title, key, window)) list.sort() - for title, window in list: + for title, key, window in list: menu.add_command(label=title, command=window.wakeup) def register_callback(self, callback): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Nov 29 00:28:42 2008 @@ -24,6 +24,9 @@ Library ------- +- Issue #4455: IDLE failed to display the windows list when two windows have + the same title. + - Issue #3741: DISTUTILS_USE_SDK set causes msvc9compiler.py to raise an exception. From python-3000-checkins at python.org Sat Nov 29 02:48:48 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 29 Nov 2008 02:48:48 +0100 (CET) Subject: [Python-3000-checkins] r67443 - in python/branches/py3k: Lib/idlelib/rpc.py Lib/idlelib/run.py Misc/NEWS Message-ID: <20081129014848.15AB91E4002@bag.python.org> Author: amaury.forgeotdarc Date: Sat Nov 29 02:48:47 2008 New Revision: 67443 Log: Fix more threading API related bugs: Thread.get_name() --> Thread.name. Seen when setting RPCHandler.debugging=True Modified: python/branches/py3k/Lib/idlelib/rpc.py python/branches/py3k/Lib/idlelib/run.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/idlelib/rpc.py ============================================================================== --- python/branches/py3k/Lib/idlelib/rpc.py (original) +++ python/branches/py3k/Lib/idlelib/rpc.py Sat Nov 29 02:48:47 2008 @@ -106,7 +106,7 @@ erf = sys.__stderr__ print('\n' + '-'*40, file=erf) print('Unhandled server exception!', file=erf) - print('Thread: %s' % threading.current_thread().get_name(), file=erf) + print('Thread: %s' % threading.current_thread().name, file=erf) print('Client Address: ', client_address, file=erf) print('Request: ', repr(request), file=erf) traceback.print_exc(file=erf) @@ -149,7 +149,7 @@ def debug(self, *args): if not self.debugging: return - s = self.location + " " + str(threading.current_thread().get_name()) + s = self.location + " " + str(threading.current_thread().name) for a in args: s = s + " " + str(a) print(s, file=sys.__stderr__) Modified: python/branches/py3k/Lib/idlelib/run.py ============================================================================== --- python/branches/py3k/Lib/idlelib/run.py (original) +++ python/branches/py3k/Lib/idlelib/run.py Sat Nov 29 02:48:47 2008 @@ -230,7 +230,7 @@ erf = sys.__stderr__ print('\n' + '-'*40, file=erf) print('Unhandled server exception!', file=erf) - print('Thread: %s' % threading.current_thread().get_name(), file=erf) + print('Thread: %s' % threading.current_thread().name, file=erf) print('Client Address: ', client_address, file=erf) print('Request: ', repr(request), file=erf) traceback.print_exc(file=erf) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sat Nov 29 02:48:47 2008 @@ -24,6 +24,9 @@ Library ------- +- IDLE would print a "Unhandled server exception!" message when internal + debugging is enabled. + - Issue #4455: IDLE failed to display the windows list when two windows have the same title. From python-3000-checkins at python.org Sun Nov 30 04:23:14 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 30 Nov 2008 04:23:14 +0100 (CET) Subject: [Python-3000-checkins] r67446 - python/branches/py3k Message-ID: <20081130032314.25EE21E4002@bag.python.org> Author: benjamin.peterson Date: Sun Nov 30 04:23:13 2008 New Revision: 67446 Log: Blocked revisions 67370 via svnmerge ........ r67370 | jeremy.hylton | 2008-11-24 16:00:29 -0600 (Mon, 24 Nov 2008) | 8 lines Add unittests that verify documented behavior of public methods in Transport class. These methods can be overridden. The tests verify that the overridden methods are called, and that changes to the connection have a visible effect on the request. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sun Nov 30 11:36:49 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Sun, 30 Nov 2008 11:36:49 +0100 (CET) Subject: [Python-3000-checkins] r67448 - in python/branches/py3k: Lib/test/crashers/iter.py Misc/NEWS Message-ID: <20081130103649.457E61E4002@bag.python.org> Author: martin.v.loewis Date: Sun Nov 30 11:36:49 2008 New Revision: 67448 Log: Issue #4407: Fix source file that caused the compileall step in Windows installer to fail. Modified: python/branches/py3k/Lib/test/crashers/iter.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Lib/test/crashers/iter.py ============================================================================== --- python/branches/py3k/Lib/test/crashers/iter.py (original) +++ python/branches/py3k/Lib/test/crashers/iter.py Sun Nov 30 11:36:49 2008 @@ -46,7 +46,7 @@ if __name__ == '__main__': if len(sys.argv) < 2: - print __doc__.replace('', str(N)) + print(__doc__.replace('', str(N))) else: n = int(sys.argv[1]) func = globals()['case%d' % n] Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sun Nov 30 11:36:49 2008 @@ -47,6 +47,12 @@ - Issue #4383: When IDLE cannot make the connection to its subprocess, it would fail to properly display the error message. +Build +----- + +- Issue #4407: Fix source file that caused the compileall step in Windows installer + to fail. + Docs ---- From python-3000-checkins at python.org Sun Nov 30 12:12:01 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Sun, 30 Nov 2008 12:12:01 +0100 (CET) Subject: [Python-3000-checkins] r67451 - in python/branches/py3k: Misc/NEWS Tools/msi/msi.py Message-ID: <20081130111201.116A11E4002@bag.python.org> Author: martin.v.loewis Date: Sun Nov 30 12:12:00 2008 New Revision: 67451 Log: Merged revisions 67449 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67449 | martin.v.loewis | 2008-11-30 12:08:26 +0100 (So, 30 Nov 2008) | 3 lines Issue #4389: Add icon to the uninstall entry in "add-and-remove-programs". ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/Tools/msi/msi.py Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sun Nov 30 12:12:00 2008 @@ -115,6 +115,8 @@ Build ----- +- Issue #4389: Add icon to the uninstall entry in "add-and-remove-programs". + - Issue #4289: Remove Cancel button from AdvancedDlg. - Issue #1656675: Register a drop handler for .py* files on Windows. Modified: python/branches/py3k/Tools/msi/msi.py ============================================================================== --- python/branches/py3k/Tools/msi/msi.py (original) +++ python/branches/py3k/Tools/msi/msi.py Sun Nov 30 12:12:00 2008 @@ -1249,7 +1249,10 @@ "[TARGETDIR]Doc\\"+docfile , "REGISTRY.doc"), ("Modules", -1, prefix+r"\Modules", "+", None, "REGISTRY"), ("AppPaths", -1, r"Software\Microsoft\Windows\CurrentVersion\App Paths\Python.exe", - "", r"[TARGETDIR]Python.exe", "REGISTRY.def") + "", r"[TARGETDIR]Python.exe", "REGISTRY.def"), + ("DisplayIcon", -1, + r"Software\Microsoft\Windows\CurrentVersion\Uninstall\%s" % product_code, + "DisplayIcon", "[TARGETDIR]python.exe", "REGISTRY.def") ]) # Shortcuts, see "Shortcut Table" add_data(db, "Directory", From python-3000-checkins at python.org Sun Nov 30 23:15:30 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 30 Nov 2008 23:15:30 +0100 (CET) Subject: [Python-3000-checkins] r67460 - in python/branches/py3k: Lib/http/client.py Message-ID: <20081130221530.35E191E4002@bag.python.org> Author: benjamin.peterson Date: Sun Nov 30 23:15:29 2008 New Revision: 67460 Log: Merged revisions 67442 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67442 | jeremy.hylton | 2008-11-28 19:09:35 -0600 (Fri, 28 Nov 2008) | 18 lines Send HTTP headers and message body in a single send() call. This change addresses part of issue 4336. Change endheaders() to take an optional message_body argument that is sent along with the headers. Change xmlrpclib and httplib's other methods to use this new interface. It is more efficient to make a single send() call, which should get the entire client request into one packet (assuming it is smaller than the MTU) and will avoid the long pause for delayed ack following timeout. Also: - Add a comment about the buffer size for makefile(). - Extract _set_content_length() method and fix whitespace issues there. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/http/client.py Modified: python/branches/py3k/Lib/http/client.py ============================================================================== --- python/branches/py3k/Lib/http/client.py (original) +++ python/branches/py3k/Lib/http/client.py Sun Nov 30 23:15:29 2008 @@ -693,7 +693,7 @@ """ self._buffer.append(s) - def _send_output(self): + def _send_output(self, message_body=None): """Send the currently buffered request and clear the buffer. Appends an extra \\r\\n to the buffer. @@ -701,6 +701,11 @@ self._buffer.extend((b"", b"")) msg = b"\r\n".join(self._buffer) del self._buffer[:] + # If msg and message_body are sent in a single send() call, + # it will avoid performance problems caused by the interaction + # between delayed ack and the Nagle algorithim. + if message_body is not None: + msg += message_body self.send(msg) def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0): @@ -830,15 +835,20 @@ header = header + b': ' + value self._output(header) - def endheaders(self): - """Indicate that the last header line has been sent to the server.""" + def endheaders(self, message_body=None): + """Indicate that the last header line has been sent to the server. + This method sends the request to the server. The optional + message_body argument can be used to pass message body + associated with the request. The message body will be sent in + the same packet as the message headers if possible. The + message_body should be a string. + """ if self.__state == _CS_REQ_STARTED: self.__state = _CS_REQ_SENT else: raise CannotSendHeader() - - self._send_output() + self._send_output(message_body) def request(self, method, url, body=None, headers={}): """Send a complete request to the server.""" @@ -851,6 +861,24 @@ # try one more time self._send_request(method, url, body, headers) + def _set_content_length(self, body): + # Set the content-length based on the body. + thelen = None + try: + thelen = str(len(body)) + except TypeError as te: + # If this is a file-like object, try to + # fstat its file descriptor + import os + try: + thelen = str(os.fstat(body.fileno()).st_size) + except (AttributeError, OSError): + # Don't send a length if this failed + if self.debuglevel > 0: print("Cannot stat!!") + + if thelen is not None: + self.putheader('Content-Length', thelen) + def _send_request(self, method, url, body, headers): # honour explicitly requested Host: and Accept-Encoding headers header_names = dict.fromkeys([k.lower() for k in headers]) @@ -863,28 +891,15 @@ self.putrequest(method, url, **skips) if body and ('content-length' not in header_names): - thelen = None - try: - thelen = str(len(body)) - except TypeError as te: - # If this is a file-like object, try to - # fstat its file descriptor - import os - try: - thelen = str(os.fstat(body.fileno()).st_size) - except (AttributeError, OSError): - # Don't send a length if this failed - if self.debuglevel > 0: print("Cannot stat!!") - - if thelen is not None: - self.putheader('Content-Length',thelen) + self._set_content_length(body) for hdr, value in headers.items(): self.putheader(hdr, value) - self.endheaders() - - if body: - if isinstance(body, str): body = body.encode('ascii') - self.send(body) + if isinstance(body, str): + self.endheaders(body.encode('ascii')) + else: + self.endheaders() + if body: # when body is a file rather than a string + self.send(body) def getresponse(self): """Get the response from the server.""" From python-3000-checkins at python.org Sun Nov 30 23:46:24 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 30 Nov 2008 23:46:24 +0100 (CET) Subject: [Python-3000-checkins] r67461 - in python/branches/py3k: Doc/c-api/arg.rst Doc/includes/mp_benchmarks.py Doc/includes/mp_distributing.py Doc/includes/mp_newtype.py Doc/includes/mp_pool.py Doc/includes/mp_synchronize.py Doc/includes/mp_webserver.py Doc/includes/mp_workers.py Doc/library/bdb.rst Doc/library/collections.rst Doc/library/ctypes.rst Doc/library/os.rst Doc/library/sqlite3.rst Doc/tools/sphinxext/pyspecific.py Lib/multiprocessing/__init__.py Lib/optparse.py Lib/test/test_parser.py Modules/_multiprocessing/semaphore.c Modules/parsermodule.c Objects/unicodeobject.c PC/msvcrtmodule.c Tools/scripts/svneol.py configure.in Message-ID: <20081130224624.B32A51E4002@bag.python.org> Author: benjamin.peterson Date: Sun Nov 30 23:46:23 2008 New Revision: 67461 Log: Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67348 | benjamin.peterson | 2008-11-22 20:09:41 -0600 (Sat, 22 Nov 2008) | 1 line raise a better error ........ r67355 | georg.brandl | 2008-11-23 13:17:25 -0600 (Sun, 23 Nov 2008) | 2 lines #4392: fix parameter name. ........ r67359 | georg.brandl | 2008-11-23 15:57:30 -0600 (Sun, 23 Nov 2008) | 2 lines #4399: fix typo. ........ r67362 | gregory.p.smith | 2008-11-23 18:41:43 -0600 (Sun, 23 Nov 2008) | 2 lines Document PY_SSIZE_T_CLEAN for PyArg_ParseTuple. ........ r67364 | benjamin.peterson | 2008-11-23 19:16:29 -0600 (Sun, 23 Nov 2008) | 2 lines replace reference to debugger-hooks ........ r67365 | benjamin.peterson | 2008-11-23 22:09:03 -0600 (Sun, 23 Nov 2008) | 1 line #4396 make the parser module correctly validate the with syntax ........ r67367 | georg.brandl | 2008-11-24 10:16:07 -0600 (Mon, 24 Nov 2008) | 2 lines Fix typo. ........ r67368 | georg.brandl | 2008-11-24 13:56:47 -0600 (Mon, 24 Nov 2008) | 2 lines #4404: make clear what "path" is. ........ r67398 | benjamin.peterson | 2008-11-26 11:39:17 -0600 (Wed, 26 Nov 2008) | 1 line fix typo in sqlite3 docs ........ r67423 | jesse.noller | 2008-11-28 12:59:35 -0600 (Fri, 28 Nov 2008) | 2 lines issue4238: bsd support for cpu_count ........ r67424 | christian.heimes | 2008-11-28 13:33:33 -0600 (Fri, 28 Nov 2008) | 1 line Retain copyright of processing examples. This was requested by a Debian maintainer during packaging of the multiprocessing package for 2.4/2.5 ........ r67432 | benjamin.peterson | 2008-11-28 17:18:46 -0600 (Fri, 28 Nov 2008) | 1 line SVN format 9 is the same it seems ........ r67440 | jeremy.hylton | 2008-11-28 17:42:59 -0600 (Fri, 28 Nov 2008) | 4 lines Move definition int sval into branch of ifdef where it is used. Otherwise, you get a warning about an undefined variable. ........ r67441 | jeremy.hylton | 2008-11-28 18:09:16 -0600 (Fri, 28 Nov 2008) | 2 lines Reflow long lines. ........ r67444 | amaury.forgeotdarc | 2008-11-28 20:03:32 -0600 (Fri, 28 Nov 2008) | 2 lines Fix a small typo in docstring ........ r67445 | benjamin.peterson | 2008-11-29 21:07:33 -0600 (Sat, 29 Nov 2008) | 1 line StringIO.close() stops you from using the buffer, too ........ r67454 | benjamin.peterson | 2008-11-30 08:43:23 -0600 (Sun, 30 Nov 2008) | 1 line note the version that works ........ r67455 | martin.v.loewis | 2008-11-30 13:28:27 -0600 (Sun, 30 Nov 2008) | 1 line Issue #4365: Add crtassem.h constants to the msvcrt module. ........ r67457 | christian.heimes | 2008-11-30 15:16:28 -0600 (Sun, 30 Nov 2008) | 1 line w# requires Py_ssize_t ........ r67458 | benjamin.peterson | 2008-11-30 15:46:16 -0600 (Sun, 30 Nov 2008) | 1 line fix pyspecific extensions that were broken by Sphinx's grand renaming ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/c-api/arg.rst python/branches/py3k/Doc/includes/mp_benchmarks.py python/branches/py3k/Doc/includes/mp_distributing.py python/branches/py3k/Doc/includes/mp_newtype.py python/branches/py3k/Doc/includes/mp_pool.py python/branches/py3k/Doc/includes/mp_synchronize.py python/branches/py3k/Doc/includes/mp_webserver.py python/branches/py3k/Doc/includes/mp_workers.py python/branches/py3k/Doc/library/bdb.rst python/branches/py3k/Doc/library/collections.rst python/branches/py3k/Doc/library/ctypes.rst python/branches/py3k/Doc/library/os.rst python/branches/py3k/Doc/library/sqlite3.rst python/branches/py3k/Doc/tools/sphinxext/pyspecific.py python/branches/py3k/Lib/multiprocessing/__init__.py python/branches/py3k/Lib/optparse.py python/branches/py3k/Lib/test/test_parser.py python/branches/py3k/Modules/_multiprocessing/semaphore.c python/branches/py3k/Modules/parsermodule.c python/branches/py3k/Objects/unicodeobject.c python/branches/py3k/PC/msvcrtmodule.c python/branches/py3k/Tools/scripts/svneol.py python/branches/py3k/configure.in Modified: python/branches/py3k/Doc/c-api/arg.rst ============================================================================== --- python/branches/py3k/Doc/c-api/arg.rst (original) +++ python/branches/py3k/Doc/c-api/arg.rst Sun Nov 30 23:46:23 2008 @@ -32,6 +32,11 @@ converted to C strings using the default encoding. If this conversion fails, a :exc:`UnicodeError` is raised. + Starting with Python 2.5 the type of the length argument can be + controlled by defining the macro :cmacro:`PY_SSIZE_T_CLEAN` before + including :file:`Python.h`. If the macro is defined, length is a + :ctype:`Py_ssize_t` rather than an int. + ``s*`` (string, Unicode, or any buffer compatible object) [Py_buffer \*] This is similar to ``s``, but the code fills a :ctype:`Py_buffer` structure provided by the caller. In this case the Python string may contain embedded @@ -43,17 +48,20 @@ has processed the data. ``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int or :ctype:`Py_ssize_t`] - This variant on ``s*`` stores into two C variables, the first one a pointer - to a character string, the second one its length. All other read-buffer - compatible objects pass back a reference to the raw internal data - representation. Since this format doesn't allow writable buffer compatible - objects like byte arrays, ``s*`` is to be preferred. The type of - the length argument (int or :ctype:`Py_ssize_t`) is controlled by + This variant on ``s`` stores into two C variables, the first one a pointer to + a character string, the second one its length. In this case the Python + string may contain embedded null bytes. Unicode objects pass back a pointer + to the default encoded string version of the object if such a conversion is + possible. All other read-buffer compatible objects pass back a reference to + the raw internal data representation. Since this format doesn't allow writable buffer compatible objects like byte + arrays, ``s*`` is to be preferred. + + The type of the length argument (int or :ctype:`Py_ssize_t`) is controlled by defining the macro :cmacro:`PY_SSIZE_T_CLEAN` before including :file:`Python.h`. If the macro was defined, length is a :ctype:`Py_ssize_t` - rather than an int. This behavior will change in a future Python - version to only support :ctype:`Py_ssize_t` and drop int support. - It is best to always define :cmacro:`PY_SSIZE_T_CLEAN`. + rather than an int. This behavior will change in a future Python version to + only support :ctype:`Py_ssize_t` and drop int support. It is best to always + define :cmacro:`PY_SSIZE_T_CLEAN`. ``y`` (bytes object) [const char \*] This variant on ``s`` converts a Python bytes or bytearray object to a C Modified: python/branches/py3k/Doc/includes/mp_benchmarks.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_benchmarks.py (original) +++ python/branches/py3k/Doc/includes/mp_benchmarks.py Sun Nov 30 23:46:23 2008 @@ -1,6 +1,9 @@ # # Simple benchmarks for the multiprocessing package # +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# import time, sys, multiprocessing, threading, queue, gc Modified: python/branches/py3k/Doc/includes/mp_distributing.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_distributing.py (original) +++ python/branches/py3k/Doc/includes/mp_distributing.py Sun Nov 30 23:46:23 2008 @@ -3,6 +3,9 @@ # # Depends on `multiprocessing` package -- tested with `processing-0.60` # +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# __all__ = ['Cluster', 'Host', 'get_logger', 'current_process'] Modified: python/branches/py3k/Doc/includes/mp_newtype.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_newtype.py (original) +++ python/branches/py3k/Doc/includes/mp_newtype.py Sun Nov 30 23:46:23 2008 @@ -2,6 +2,9 @@ # This module shows how to use arbitrary callables with a subclass of # `BaseManager`. # +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# from multiprocessing import freeze_support from multiprocessing.managers import BaseManager, BaseProxy Modified: python/branches/py3k/Doc/includes/mp_pool.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_pool.py (original) +++ python/branches/py3k/Doc/includes/mp_pool.py Sun Nov 30 23:46:23 2008 @@ -1,6 +1,9 @@ # # A test of `multiprocessing.Pool` class # +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# import multiprocessing import time Modified: python/branches/py3k/Doc/includes/mp_synchronize.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_synchronize.py (original) +++ python/branches/py3k/Doc/includes/mp_synchronize.py Sun Nov 30 23:46:23 2008 @@ -1,6 +1,9 @@ # # A test file for the `multiprocessing` package # +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# import time, sys, random from queue import Empty Modified: python/branches/py3k/Doc/includes/mp_webserver.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_webserver.py (original) +++ python/branches/py3k/Doc/includes/mp_webserver.py Sun Nov 30 23:46:23 2008 @@ -8,6 +8,9 @@ # Not sure if we should synchronize access to `socket.accept()` method by # using a process-shared lock -- does not seem to be necessary. # +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# import os import sys Modified: python/branches/py3k/Doc/includes/mp_workers.py ============================================================================== --- python/branches/py3k/Doc/includes/mp_workers.py (original) +++ python/branches/py3k/Doc/includes/mp_workers.py Sun Nov 30 23:46:23 2008 @@ -7,6 +7,9 @@ # in the original order then consider using `Pool.map()` or # `Pool.imap()` (which will save on the amount of code needed anyway). # +# Copyright (c) 2006-2008, R Oudkerk +# All rights reserved. +# import time import random Modified: python/branches/py3k/Doc/library/bdb.rst ============================================================================== --- python/branches/py3k/Doc/library/bdb.rst (original) +++ python/branches/py3k/Doc/library/bdb.rst Sun Nov 30 23:46:23 2008 @@ -107,8 +107,9 @@ The *arg* parameter depends on the previous event. - For more information on trace functions, see :ref:`debugger-hooks`. For - more information on code and frame objects, refer to :ref:`types`. + See the documentation for :func:`sys.settrace` for more information on the + trace function. For more information on code and frame objects, refer to + :ref:`types`. .. method:: dispatch_line(frame) Modified: python/branches/py3k/Doc/library/collections.rst ============================================================================== --- python/branches/py3k/Doc/library/collections.rst (original) +++ python/branches/py3k/Doc/library/collections.rst Sun Nov 30 23:46:23 2008 @@ -48,7 +48,7 @@ :class:`Iterable`, and ``__len__`` ``index``, and ``count`` :class:`Container` -:class:`MutableSequnce` :class:`Sequence` ``__getitem__`` Inherited Sequence methods and +:class:`MutableSequence` :class:`Sequence` ``__getitem__`` Inherited Sequence methods and ``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``, ``insert``, ``remove``, and ``__iadd__`` and ``__len__`` @@ -466,16 +466,16 @@ self-documenting code. They can be used wherever regular tuples are used, and they add the ability to access fields by name instead of position index. -.. function:: namedtuple(typename, fieldnames, [verbose]) +.. function:: namedtuple(typename, field_names, [verbose]) Returns a new tuple subclass named *typename*. The new subclass is used to create tuple-like objects that have fields accessible by attribute lookup as well as being indexable and iterable. Instances of the subclass also have a - helpful docstring (with typename and fieldnames) and a helpful :meth:`__repr__` + helpful docstring (with typename and field_names) and a helpful :meth:`__repr__` method which lists the tuple contents in a ``name=value`` format. - The *fieldnames* are a single string with each fieldname separated by whitespace - and/or commas, for example ``'x y'`` or ``'x, y'``. Alternatively, *fieldnames* + The *field_names* are a single string with each fieldname separated by whitespace + and/or commas, for example ``'x y'`` or ``'x, y'``. Alternatively, *field_names* can be a sequence of strings such as ``['x', 'y']``. Any valid Python identifier may be used for a fieldname except for names Modified: python/branches/py3k/Doc/library/ctypes.rst ============================================================================== --- python/branches/py3k/Doc/library/ctypes.rst (original) +++ python/branches/py3k/Doc/library/ctypes.rst Sun Nov 30 23:46:23 2008 @@ -1368,7 +1368,7 @@ All these classes can be instantiated by calling them with at least one argument, the pathname of the shared library. If you have an existing handle to -an already loaded shard library, it can be passed as the ``handle`` named +an already loaded shared library, it can be passed as the ``handle`` named parameter, otherwise the underlying platforms ``dlopen`` or :meth:`LoadLibrary` function is used to load the library into the process, and to get a handle to it. Modified: python/branches/py3k/Doc/library/os.rst ============================================================================== --- python/branches/py3k/Doc/library/os.rst (original) +++ python/branches/py3k/Doc/library/os.rst Sun Nov 30 23:46:23 2008 @@ -805,10 +805,10 @@ .. function:: listdir(path) - Return a list containing the names of the entries in the directory. The list - is in arbitrary order. It does not include the special entries ``.`` and - ``..`` even if they are present in the directory. Availability: Unix, - Windows. + Return a list containing the names of the entries in the directory given by + *path*. The list is in arbitrary order. It does not include the special + entries ``'.'`` and ``'..'`` even if they are present in the directory. + Availability: Unix, Windows. This function can be called with a bytes or string argument. In the bytes case, all filenames will be listed as returned by the underlying API. In the Modified: python/branches/py3k/Doc/library/sqlite3.rst ============================================================================== --- python/branches/py3k/Doc/library/sqlite3.rst (original) +++ python/branches/py3k/Doc/library/sqlite3.rst Sun Nov 30 23:46:23 2008 @@ -221,8 +221,8 @@ .. attribute:: Connection.isolation_level - Get or set the current isolation level. :const:`None` for autocommit mode or one of - "DEFERRED", "IMMEDIATE" or "EXLUSIVE". See section + Get or set the current isolation level. :const:`None` for autocommit mode or + one of "DEFERRED", "IMMEDIATE" or "EXCLUSIVE". See section :ref:`sqlite3-controlling-transactions` for a more detailed explanation. Modified: python/branches/py3k/Doc/tools/sphinxext/pyspecific.py ============================================================================== --- python/branches/py3k/Doc/tools/sphinxext/pyspecific.py (original) +++ python/branches/py3k/Doc/tools/sphinxext/pyspecific.py Sun Nov 30 23:46:23 2008 @@ -46,7 +46,7 @@ from docutils.io import StringOutput from docutils.utils import new_document from sphinx.builder import Builder -from sphinx.textwriter import TextWriter +from sphinx.writers.text import TextWriter class PydocTopicsBuilder(Builder): name = 'pydoc-topics' Modified: python/branches/py3k/Lib/multiprocessing/__init__.py ============================================================================== --- python/branches/py3k/Lib/multiprocessing/__init__.py (original) +++ python/branches/py3k/Lib/multiprocessing/__init__.py Sun Nov 30 23:46:23 2008 @@ -112,7 +112,7 @@ num = int(os.environ['NUMBER_OF_PROCESSORS']) except (ValueError, KeyError): num = 0 - elif sys.platform == 'darwin': + elif 'bsd' in sys.platform or sys.platform == 'darwin': try: num = int(os.popen('sysctl -n hw.ncpu').read()) except ValueError: Modified: python/branches/py3k/Lib/optparse.py ============================================================================== --- python/branches/py3k/Lib/optparse.py (original) +++ python/branches/py3k/Lib/optparse.py Sun Nov 30 23:46:23 2008 @@ -797,7 +797,7 @@ parser.print_version() parser.exit() else: - raise RuntimeError("unknown action %r" % self.action) + raise ValueError("unknown action %r" % self.action) return 1 Modified: python/branches/py3k/Lib/test/test_parser.py ============================================================================== --- python/branches/py3k/Lib/test/test_parser.py (original) +++ python/branches/py3k/Lib/test/test_parser.py Sun Nov 30 23:46:23 2008 @@ -189,6 +189,10 @@ def test_assert(self): self.check_suite("assert alo < ahi and blo < bhi\n") + def test_with(self): + self.check_suite("with open('x'): pass\n") + self.check_suite("with open('x') as f: pass\n") + def test_position(self): # An absolutely minimal test of position information. Better # tests would be a big project. Modified: python/branches/py3k/Modules/_multiprocessing/semaphore.c ============================================================================== --- python/branches/py3k/Modules/_multiprocessing/semaphore.c (original) +++ python/branches/py3k/Modules/_multiprocessing/semaphore.c Sun Nov 30 23:46:23 2008 @@ -512,7 +512,6 @@ static PyObject * semlock_iszero(SemLockObject *self) { - int sval; #if HAVE_BROKEN_SEM_GETVALUE if (sem_trywait(self->handle) < 0) { if (errno == EAGAIN) @@ -524,6 +523,7 @@ Py_RETURN_FALSE; } #else + int sval; if (SEM_GETVALUE(self->handle, &sval) < 0) return mp_SetError(NULL, MP_STANDARD_ERROR); return PyBool_FromLong((long)sval == 0); Modified: python/branches/py3k/Modules/parsermodule.c ============================================================================== --- python/branches/py3k/Modules/parsermodule.c (original) +++ python/branches/py3k/Modules/parsermodule.c Sun Nov 30 23:46:23 2008 @@ -1438,7 +1438,7 @@ /* compound_stmt: - * if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef | decorated + * if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated */ static int validate_compound_stmt(node *tree) @@ -1456,6 +1456,7 @@ || (ntype == while_stmt) || (ntype == for_stmt) || (ntype == try_stmt) + || (ntype == with_stmt) || (ntype == funcdef) || (ntype == classdef) || (ntype == decorated)) @@ -2399,6 +2400,38 @@ return ok; } +/* with_var +with_var: 'as' expr + */ +static int +validate_with_var(node *tree) +{ + int nch = NCH(tree); + int ok = (validate_ntype(tree, with_var) + && (nch == 2) + && validate_name(CHILD(tree, 0), "as") + && validate_expr(CHILD(tree, 1))); + return ok; +} + +/* with_stmt + * 0 1 2 -2 -1 +with_stmt: 'with' test [ with_var ] ':' suite + */ +static int +validate_with_stmt(node *tree) +{ + int nch = NCH(tree); + int ok = (validate_ntype(tree, with_stmt) + && ((nch == 4) || (nch == 5)) + && validate_name(CHILD(tree, 0), "with") + && validate_test(CHILD(tree, 1)) + && (nch == 4 || validate_with_var(CHILD(tree, 2))) + && validate_colon(RCHILD(tree, -2)) + && validate_suite(RCHILD(tree, -1))); + return ok; +} + /* funcdef: * * -5 -4 -3 -2 -1 @@ -2775,6 +2808,9 @@ case funcdef: res = validate_funcdef(tree); break; + case with_stmt: + res = validate_with_stmt(tree); + break; case classdef: res = validate_class(tree); break; Modified: python/branches/py3k/Objects/unicodeobject.c ============================================================================== --- python/branches/py3k/Objects/unicodeobject.c (original) +++ python/branches/py3k/Objects/unicodeobject.c Sun Nov 30 23:46:23 2008 @@ -8030,7 +8030,7 @@ } PyDoc_STRVAR(splitlines__doc__, -"S.splitlines([keepends]]) -> list of strings\n\ +"S.splitlines([keepends]) -> list of strings\n\ \n\ Return a list of the lines in S, breaking at line boundaries.\n\ Line breaks are not included in the resulting list unless keepends\n\ Modified: python/branches/py3k/PC/msvcrtmodule.c ============================================================================== --- python/branches/py3k/PC/msvcrtmodule.c (original) +++ python/branches/py3k/PC/msvcrtmodule.c Sun Nov 30 23:46:23 2008 @@ -24,6 +24,12 @@ #include #include +#ifdef _MSC_VER +#if _MSC_VER >= 1500 +#include +#endif +#endif + // Force the malloc heap to clean itself up, and free unused blocks // back to the OS. (According to the docs, only works on NT.) static PyObject * @@ -373,6 +379,7 @@ PyMODINIT_FUNC PyInit_msvcrt(void) { + int st; PyObject *d; PyObject *m = PyModule_Create(&msvcrtmodule); if (m == NULL) @@ -401,5 +408,23 @@ insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT); insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE); #endif - return m; + + /* constants for the crt versions */ +#ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN + st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", + _VC_ASSEMBLY_PUBLICKEYTOKEN); + if (st < 0) return NULL; +#endif +#ifdef _CRT_ASSEMBLY_VERSION + st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION", + _CRT_ASSEMBLY_VERSION); + if (st < 0) return NULL; +#endif +#ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX + st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX", + __LIBRARIES_ASSEMBLY_NAME_PREFIX); + if (st < 0) return NULL; +#endif + + return m; } Modified: python/branches/py3k/Tools/scripts/svneol.py ============================================================================== --- python/branches/py3k/Tools/scripts/svneol.py (original) +++ python/branches/py3k/Tools/scripts/svneol.py Sun Nov 30 23:46:23 2008 @@ -39,9 +39,9 @@ format = int(open(os.path.join(root, ".svn", "format")).read().strip()) except IOError: return [] - if format == 8: - # In version 8, committed props are stored in prop-base, - # local modifications in props + if format in (8, 9): + # In version 8 and 9, committed props are stored in prop-base, local + # modifications in props return [os.path.join(root, ".svn", "prop-base", fn+".svn-base"), os.path.join(root, ".svn", "props", fn+".svn-work")] raise ValueError, "Unknown repository format" Modified: python/branches/py3k/configure.in ============================================================================== --- python/branches/py3k/configure.in (original) +++ python/branches/py3k/configure.in Sun Nov 30 23:46:23 2008 @@ -1,7 +1,7 @@ dnl *********************************************** dnl * Please run autoreconf to test your changes! * dnl *********************************************** -dnl NOTE: autoconf 2.64 doesn't seem to work (use 2.63). +dnl NOTE: autoconf 2.64 doesn't seem to work (use 2.61). # Set VERSION so we only need to edit in one place (i.e., here) m4_define(PYTHON_VERSION, 3.0)
FormatPacked as .zipPacked as .tar.bz2