From python-3000-checkins at python.org Wed Oct 1 13:22:32 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Wed, 1 Oct 2008 13:22:32 +0200 (CEST) Subject: [Python-3000-checkins] r66711 - in python/branches/py3k: Tools/msi/msi.py Message-ID: <20081001112232.BE6611E4002@bag.python.org> Author: martin.v.loewis Date: Wed Oct 1 13:22:32 2008 New Revision: 66711 Log: Merged revisions 66710 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66710 | martin.v.loewis | 2008-10-01 13:19:50 +0200 (Mi, 01 Okt 2008) | 2 lines Bug #3989: Package the 2to3 script (as 2to3.py) in the Windows installer. ........ 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 Wed Oct 1 13:22:32 2008 @@ -1121,6 +1121,7 @@ if os.path.exists(os.path.join(lib.absolute, "README")): lib.add_file("README.txt", src="README") if f == 'Scripts': + lib.add_file("2to3.py", src="2to3") if have_tcl: lib.start_component("pydocgui.pyw", tcltk, keyfile="pydocgui.pyw") lib.add_file("pydocgui.pyw") From python-3000-checkins at python.org Thu Oct 2 13:46:10 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Thu, 2 Oct 2008 13:46:10 +0200 (CEST) Subject: [Python-3000-checkins] r66723 - in python/branches/py3k: Tools/msi/merge.py Message-ID: <20081002114610.0266B1E4002@bag.python.org> Author: martin.v.loewis Date: Thu Oct 2 13:46:09 2008 New Revision: 66723 Log: Merged revisions 66722 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66722 | martin.v.loewis | 2008-10-02 13:44:17 +0200 (Do, 02 Okt 2008) | 1 line Use CRT 9 policy files. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Tools/msi/merge.py Modified: python/branches/py3k/Tools/msi/merge.py ============================================================================== --- python/branches/py3k/Tools/msi/merge.py (original) +++ python/branches/py3k/Tools/msi/merge.py Thu Oct 2 13:46:09 2008 @@ -9,10 +9,10 @@ if len(sys.argv)==2: msi = sys.argv[1] if Win64: - modules = ["Microsoft_VC90_CRT_x86_x64.msm", "policy_8_0_Microsoft_VC80_CRT_x86_x64.msm"] + modules = ["Microsoft_VC90_CRT_x86_x64.msm", "policy_9_0_Microsoft_VC90_CRT_x86_x64.msm"] if not msi: msi = "python-%s.amd64.msi" % full_current_version else: - modules = ["Microsoft_VC90_CRT_x86.msm","policy_8_0_Microsoft_VC80_CRT_x86.msm"] + modules = ["Microsoft_VC90_CRT_x86.msm","policy_9_0_Microsoft_VC90_CRT_x86.msm"] if not msi: msi = "python-%s.msi" % full_current_version for i, n in enumerate(modules): modules[i] = os.path.join(mod_dir, n) From python-3000-checkins at python.org Thu Oct 2 18:57:06 2008 From: python-3000-checkins at python.org (guido.van.rossum) Date: Thu, 2 Oct 2008 18:57:06 +0200 (CEST) Subject: [Python-3000-checkins] r66737 - in python/branches/py3k/Lib/lib2to3/tests/data/fixers: myfixes Message-ID: <20081002165706.2668C1E4002@bag.python.org> Author: guido.van.rossum Date: Thu Oct 2 18:57:05 2008 New Revision: 66737 Log: Fix svn:ignore properties on these two directories. Modified: python/branches/py3k/Lib/lib2to3/tests/data/fixers/ (props changed) python/branches/py3k/Lib/lib2to3/tests/data/fixers/myfixes/ (props changed) From python-3000-checkins at python.org Thu Oct 2 20:38:12 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Thu, 2 Oct 2008 20:38:12 +0200 (CEST) Subject: [Python-3000-checkins] r66741 - in python/branches/py3k: Objects/frameobject.c Message-ID: <20081002183812.0B1161E4002@bag.python.org> Author: christian.heimes Date: Thu Oct 2 20:38:11 2008 New Revision: 66741 Log: Merged revisions 66739 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66739 | christian.heimes | 2008-10-02 20:33:41 +0200 (Thu, 02 Oct 2008) | 1 line Fixed a comment to C89 style as of http://drj11.wordpress.com/2008/10/02/python-and-bragging-about-c89/ ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Objects/frameobject.c Modified: python/branches/py3k/Objects/frameobject.c ============================================================================== --- python/branches/py3k/Objects/frameobject.c (original) +++ python/branches/py3k/Objects/frameobject.c Thu Oct 2 20:38:11 2008 @@ -522,7 +522,7 @@ nfrees = PyTuple_GET_SIZE(f->f_code->co_freevars); extras = f->f_code->co_stacksize + f->f_code->co_nlocals + ncells + nfrees; - // subtract one as it is already included in PyFrameObject + /* subtract one as it is already included in PyFrameObject */ res = sizeof(PyFrameObject) + (extras-1) * sizeof(PyObject *); return PyLong_FromSsize_t(res); From python-3000-checkins at python.org Thu Oct 2 20:55:38 2008 From: python-3000-checkins at python.org (guido.van.rossum) Date: Thu, 2 Oct 2008 20:55:38 +0200 (CEST) Subject: [Python-3000-checkins] r66743 - in python/branches/py3k: Lib/fnmatch.py Lib/genericpath.py Lib/glob.py Lib/io.py Lib/posixpath.py Lib/test/test_fnmatch.py Lib/test/test_posix.py Lib/test/test_posixpath.py Lib/test/test_unicode_file.py Misc/NEWS Modules/posixmodule.c Message-ID: <20081002185538.315151E400D@bag.python.org> Author: guido.van.rossum Date: Thu Oct 2 20:55:37 2008 New Revision: 66743 Log: Issue #3187: Better support for "undecodable" filenames. Code by Victor Stinner, with small tweaks by GvR. Modified: python/branches/py3k/Lib/fnmatch.py python/branches/py3k/Lib/genericpath.py python/branches/py3k/Lib/glob.py python/branches/py3k/Lib/io.py python/branches/py3k/Lib/posixpath.py python/branches/py3k/Lib/test/test_fnmatch.py python/branches/py3k/Lib/test/test_posix.py python/branches/py3k/Lib/test/test_posixpath.py python/branches/py3k/Lib/test/test_unicode_file.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/posixmodule.c Modified: python/branches/py3k/Lib/fnmatch.py ============================================================================== --- python/branches/py3k/Lib/fnmatch.py (original) +++ python/branches/py3k/Lib/fnmatch.py Thu Oct 2 20:55:37 2008 @@ -37,15 +37,24 @@ pat = os.path.normcase(pat) return fnmatchcase(name, pat) +def _compile_pattern(pat): + regex = _cache.get(pat) + if regex is None: + if isinstance(pat, bytes): + pat_str = str(pat, 'ISO-8859-1') + res_str = translate(pat_str) + res = bytes(res_str, 'ISO-8859-1') + else: + res = translate(pat) + _cache[pat] = regex = re.compile(res) + return regex.match + def filter(names, pat): """Return the subset of the list NAMES that match PAT""" import os,posixpath - result=[] - pat=os.path.normcase(pat) - if not pat in _cache: - res = translate(pat) - _cache[pat] = re.compile(res) - match=_cache[pat].match + result = [] + pat = os.path.normcase(pat) + match = _compile_pattern(pat) if os.path is posixpath: # normcase on posix is NOP. Optimize it away from the loop. for name in names: @@ -64,10 +73,8 @@ its arguments. """ - if not pat in _cache: - res = translate(pat) - _cache[pat] = re.compile(res) - return _cache[pat].match(name) is not None + match = _compile_pattern(pat) + return match(name) is not None def translate(pat): """Translate a shell PATTERN to a regular expression. Modified: python/branches/py3k/Lib/genericpath.py ============================================================================== --- python/branches/py3k/Lib/genericpath.py (original) +++ python/branches/py3k/Lib/genericpath.py Thu Oct 2 20:55:37 2008 @@ -87,6 +87,7 @@ Extension is everything from the last dot to the end, ignoring leading dots. Returns "(root, ext)"; ext may be empty.""" + # NOTE: This code must work for text and bytes strings. sepIndex = p.rfind(sep) if altsep: @@ -98,8 +99,8 @@ # skip all leading dots filenameIndex = sepIndex + 1 while filenameIndex < dotIndex: - if p[filenameIndex] != extsep: + if p[filenameIndex:filenameIndex+1] != extsep: return p[:dotIndex], p[dotIndex:] filenameIndex += 1 - return p, '' + return p, p[:0] Modified: python/branches/py3k/Lib/glob.py ============================================================================== --- python/branches/py3k/Lib/glob.py (original) +++ python/branches/py3k/Lib/glob.py Thu Oct 2 20:55:37 2008 @@ -27,7 +27,7 @@ return dirname, basename = os.path.split(pathname) if not dirname: - for name in glob1(os.curdir, basename): + for name in glob1(None, basename): yield name return if has_magic(dirname): @@ -48,10 +48,10 @@ def glob1(dirname, pattern): if not dirname: - dirname = os.curdir - if isinstance(pattern, str) and not isinstance(dirname, str): - dirname = str(dirname, sys.getfilesystemencoding() or - sys.getdefaultencoding()) + if isinstance(pattern, bytes): + dirname = bytes(os.curdir, 'ASCII') + else: + dirname = os.curdir try: names = os.listdir(dirname) except os.error: @@ -73,6 +73,11 @@ magic_check = re.compile('[*?[]') +magic_check_bytes = re.compile(b'[*?[]') def has_magic(s): - return magic_check.search(s) is not None + if isinstance(s, bytes): + match = magic_check_bytes.search(s) + else: + match = magic_check.search(s) + return match is not None Modified: python/branches/py3k/Lib/io.py ============================================================================== --- python/branches/py3k/Lib/io.py (original) +++ python/branches/py3k/Lib/io.py Thu Oct 2 20:55:37 2008 @@ -82,14 +82,13 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None, newline=None, closefd=True): - r"""Open file and return a stream. If the file cannot be opened, an IOError is - raised. + r"""Open file and return a stream. Raise IOError upon failure. - file is either a string giving the name (and the path if the file - isn't in the current working directory) of the file to be opened or an - integer file descriptor of the file to be wrapped. (If a file - descriptor is given, it is closed when the returned I/O object is - closed, unless closefd is set to False.) + file is either a text or byte string giving the name (and the path + if the file isn't in the current working directory) of the file to + be opened or an integer file descriptor of the file to be + wrapped. (If a file descriptor is given, it is closed when the + returned I/O object is closed, unless closefd is set to False.) mode is an optional string that specifies the mode in which the file is opened. It defaults to 'r' which means open for reading in text @@ -180,7 +179,7 @@ opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode. """ - if not isinstance(file, (str, int)): + if not isinstance(file, (str, bytes, int)): raise TypeError("invalid file: %r" % file) if not isinstance(mode, str): raise TypeError("invalid mode: %r" % mode) Modified: python/branches/py3k/Lib/posixpath.py ============================================================================== --- python/branches/py3k/Lib/posixpath.py (original) +++ python/branches/py3k/Lib/posixpath.py Thu Oct 2 20:55:37 2008 @@ -11,6 +11,7 @@ """ import os +import sys import stat import genericpath from genericpath import * @@ -23,7 +24,8 @@ "curdir","pardir","sep","pathsep","defpath","altsep","extsep", "devnull","realpath","supports_unicode_filenames","relpath"] -# strings representing various path-related bits and pieces +# Strings representing various path-related bits and pieces. +# These are primarily for export; internally, they are hardcoded. curdir = '.' pardir = '..' extsep = '.' @@ -33,6 +35,12 @@ altsep = None devnull = '/dev/null' +def _get_sep(path): + if isinstance(path, bytes): + return b'/' + else: + return '/' + # Normalize the case of a pathname. Trivial in Posix, string.lower on Mac. # On MS-DOS this may also turn slashes into backslashes; however, other # normalizations (such as optimizing '../' away) are not allowed @@ -40,6 +48,7 @@ def normcase(s): """Normalize case of pathname. Has no effect under Posix""" + # TODO: on Mac OS X, this should really return s.lower(). return s @@ -48,7 +57,8 @@ def isabs(s): """Test whether a path is absolute""" - return s.startswith('/') + sep = _get_sep(s) + return s.startswith(sep) # Join pathnames. @@ -59,14 +69,15 @@ """Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded.""" + sep = _get_sep(a) path = a for b in p: - if b.startswith('/'): + if b.startswith(sep): path = b - elif path == '' or path.endswith('/'): + elif not path or path.endswith(sep): path += b else: - path += '/' + b + path += sep + b return path @@ -78,10 +89,11 @@ def split(p): """Split a pathname. Returns tuple "(head, tail)" where "tail" is everything after the final slash. Either part may be empty.""" - i = p.rfind('/') + 1 + sep = _get_sep(p) + i = p.rfind(sep) + 1 head, tail = p[:i], p[i:] - if head and head != '/'*len(head): - head = head.rstrip('/') + if head and head != sep*len(head): + head = head.rstrip(sep) return head, tail @@ -91,7 +103,13 @@ # It is always true that root + ext == p. def splitext(p): - return genericpath._splitext(p, sep, altsep, extsep) + if isinstance(p, bytes): + sep = b'/' + extsep = b'.' + else: + sep = '/' + extsep = '.' + return genericpath._splitext(p, sep, None, extsep) splitext.__doc__ = genericpath._splitext.__doc__ # Split a pathname into a drive specification and the rest of the @@ -100,14 +118,15 @@ def splitdrive(p): """Split a pathname into drive and path. On Posix, drive is always empty.""" - return '', p + return p[:0], p # Return the tail (basename) part of a path, same as split(path)[1]. def basename(p): """Returns the final component of a pathname""" - i = p.rfind('/') + 1 + sep = _get_sep(p) + i = p.rfind(sep) + 1 return p[i:] @@ -115,10 +134,11 @@ def dirname(p): """Returns the directory component of a pathname""" - i = p.rfind('/') + 1 + sep = _get_sep(p) + i = p.rfind(sep) + 1 head = p[:i] - if head and head != '/'*len(head): - head = head.rstrip('/') + if head and head != sep*len(head): + head = head.rstrip(sep) return head @@ -179,7 +199,11 @@ """Test whether a path is a mount point""" try: s1 = os.lstat(path) - s2 = os.lstat(join(path, '..')) + if isinstance(path, bytes): + parent = join(path, b'..') + else: + parent = join(path, '..') + s2 = os.lstat(parent) except os.error: return False # It doesn't exist -- so not a mount point :-) dev1 = s1.st_dev @@ -205,9 +229,14 @@ def expanduser(path): """Expand ~ and ~user constructions. If user or $HOME is unknown, do nothing.""" - if not path.startswith('~'): + if isinstance(path, bytes): + tilde = b'~' + else: + tilde = '~' + if not path.startswith(tilde): return path - i = path.find('/', 1) + sep = _get_sep(path) + i = path.find(sep, 1) if i < 0: i = len(path) if i == 1: @@ -218,12 +247,17 @@ userhome = os.environ['HOME'] else: import pwd + name = path[1:i] + if isinstance(name, bytes): + name = str(name, 'ASCII') try: - pwent = pwd.getpwnam(path[1:i]) + pwent = pwd.getpwnam(name) except KeyError: return path userhome = pwent.pw_dir - userhome = userhome.rstrip('/') + if isinstance(path, bytes): + userhome = userhome.encode(sys.getfilesystemencoding()) + userhome = userhome.rstrip(sep) return userhome + path[i:] @@ -232,28 +266,47 @@ # Non-existent variables are left unchanged. _varprog = None +_varprogb = None def expandvars(path): """Expand shell variables of form $var and ${var}. Unknown variables are left unchanged.""" - global _varprog - if '$' not in path: - return path - if not _varprog: - import re - _varprog = re.compile(r'\$(\w+|\{[^}]*\})', re.ASCII) + global _varprog, _varprogb + if isinstance(path, bytes): + if b'$' not in path: + return path + if not _varprogb: + import re + _varprogb = re.compile(br'\$(\w+|\{[^}]*\})', re.ASCII) + search = _varprogb.search + start = b'{' + end = b'}' + else: + if '$' not in path: + return path + if not _varprog: + import re + _varprog = re.compile(r'\$(\w+|\{[^}]*\})', re.ASCII) + search = _varprog.search + start = '{' + end = '}' i = 0 while True: - m = _varprog.search(path, i) + m = search(path, i) if not m: break i, j = m.span(0) name = m.group(1) - if name.startswith('{') and name.endswith('}'): + if name.startswith(start) and name.endswith(end): name = name[1:-1] + if isinstance(name, bytes): + name = str(name, 'ASCII') if name in os.environ: tail = path[j:] - path = path[:i] + os.environ[name] + value = os.environ[name] + if isinstance(path, bytes): + value = value.encode('ASCII') + path = path[:i] + value i = len(path) path += tail else: @@ -267,35 +320,49 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" - if path == '': - return '.' - initial_slashes = path.startswith('/') + if isinstance(path, bytes): + sep = b'/' + empty = b'' + dot = b'.' + dotdot = b'..' + else: + sep = '/' + empty = '' + dot = '.' + dotdot = '..' + if path == empty: + return dot + initial_slashes = path.startswith(sep) # POSIX allows one or two initial slashes, but treats three or more # as single slash. if (initial_slashes and - path.startswith('//') and not path.startswith('///')): + path.startswith(sep*2) and not path.startswith(sep*3)): initial_slashes = 2 - comps = path.split('/') + comps = path.split(sep) new_comps = [] for comp in comps: - if comp in ('', '.'): + if comp in (empty, dot): continue - if (comp != '..' or (not initial_slashes and not new_comps) or - (new_comps and new_comps[-1] == '..')): + if (comp != dotdot or (not initial_slashes and not new_comps) or + (new_comps and new_comps[-1] == dotdot)): new_comps.append(comp) elif new_comps: new_comps.pop() comps = new_comps - path = '/'.join(comps) + path = sep.join(comps) if initial_slashes: - path = '/'*initial_slashes + path - return path or '.' + path = sep*initial_slashes + path + return path or dot def abspath(path): """Return an absolute path.""" if not isabs(path): - path = join(os.getcwd(), path) + if isinstance(path, bytes): + cwd = os.getcwdb() + else: + cwd = os.getcwd() + path = join(cwd, path) return normpath(path) @@ -305,10 +372,16 @@ def realpath(filename): """Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path.""" + if isinstance(filename, bytes): + sep = b'/' + empty = b'' + else: + sep = '/' + empty = '' if isabs(filename): - bits = ['/'] + filename.split('/')[1:] + bits = [sep] + filename.split(sep)[1:] else: - bits = [''] + filename.split('/') + bits = [empty] + filename.split(sep) for i in range(2, len(bits)+1): component = join(*bits[0:i]) @@ -347,12 +420,24 @@ supports_unicode_filenames = False -def relpath(path, start=curdir): +def relpath(path, start=None): """Return a relative version of a path""" if not path: raise ValueError("no path specified") + if isinstance(path, bytes): + curdir = b'.' + sep = b'/' + pardir = b'..' + else: + curdir = '.' + sep = '/' + pardir = '..' + + if start is None: + start = curdir + start_list = abspath(start).split(sep) path_list = abspath(path).split(sep) Modified: python/branches/py3k/Lib/test/test_fnmatch.py ============================================================================== --- python/branches/py3k/Lib/test/test_fnmatch.py (original) +++ python/branches/py3k/Lib/test/test_fnmatch.py Thu Oct 2 20:55:37 2008 @@ -37,6 +37,15 @@ check('a', r'[!\]') check('\\', r'[!\]', 0) + def test_mix_bytes_str(self): + self.assertRaises(TypeError, fnmatch, 'test', b'*') + self.assertRaises(TypeError, fnmatch, b'test', '*') + self.assertRaises(TypeError, fnmatchcase, 'test', b'*') + self.assertRaises(TypeError, fnmatchcase, b'test', '*') + + def test_bytes(self): + self.check_match(b'test', b'te*') + self.check_match(b'test\xff', b'te*\xff') def test_main(): support.run_unittest(FnmatchTestCase) Modified: python/branches/py3k/Lib/test/test_posix.py ============================================================================== --- python/branches/py3k/Lib/test/test_posix.py (original) +++ python/branches/py3k/Lib/test/test_posix.py Thu Oct 2 20:55:37 2008 @@ -29,7 +29,7 @@ def testNoArgFunctions(self): # test posix functions which take no arguments and have # no side-effects which we need to cleanup (e.g., fork, wait, abort) - NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdu", "uname", + NO_ARG_FUNCTIONS = [ "ctermid", "getcwd", "getcwdb", "uname", "times", "getloadavg", "getegid", "geteuid", "getgid", "getgroups", "getpid", "getpgrp", "getppid", "getuid", Modified: python/branches/py3k/Lib/test/test_posixpath.py ============================================================================== --- python/branches/py3k/Lib/test/test_posixpath.py (original) +++ python/branches/py3k/Lib/test/test_posixpath.py Thu Oct 2 20:55:37 2008 @@ -31,20 +31,34 @@ def test_normcase(self): # Check that normcase() is idempotent p = "FoO/./BaR" - p = posixpath.normcase(p) + self.assertEqual(p, posixpath.normcase(p)) + + p = b"FoO/./BaR" self.assertEqual(p, posixpath.normcase(p)) self.assertRaises(TypeError, posixpath.normcase) def test_join(self): - self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"), "/bar/baz") + self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"), + "/bar/baz") self.assertEqual(posixpath.join("/foo", "bar", "baz"), "/foo/bar/baz") - self.assertEqual(posixpath.join("/foo/", "bar/", "baz/"), "/foo/bar/baz/") + self.assertEqual(posixpath.join("/foo/", "bar/", "baz/"), + "/foo/bar/baz/") + + self.assertEqual(posixpath.join(b"/foo", b"bar", b"/bar", b"baz"), + b"/bar/baz") + self.assertEqual(posixpath.join(b"/foo", b"bar", b"baz"), + b"/foo/bar/baz") + self.assertEqual(posixpath.join(b"/foo/", b"bar/", b"baz/"), + b"/foo/bar/baz/") self.assertRaises(TypeError, posixpath.join) + self.assertRaises(TypeError, posixpath.join, b"bytes", "str") + self.assertRaises(TypeError, posixpath.join, "str", b"bytes") def test_splitdrive(self): self.assertEqual(posixpath.splitdrive("/foo/bar"), ("", "/foo/bar")) + self.assertEqual(posixpath.splitdrive(b"/foo/bar"), (b"", b"/foo/bar")) self.assertRaises(TypeError, posixpath.splitdrive) @@ -55,15 +69,41 @@ self.assertEqual(posixpath.split("////foo"), ("////", "foo")) self.assertEqual(posixpath.split("//foo//bar"), ("//foo", "bar")) + self.assertEqual(posixpath.split(b"/foo/bar"), (b"/foo", b"bar")) + self.assertEqual(posixpath.split(b"/"), (b"/", b"")) + self.assertEqual(posixpath.split(b"foo"), (b"", b"foo")) + self.assertEqual(posixpath.split(b"////foo"), (b"////", b"foo")) + self.assertEqual(posixpath.split(b"//foo//bar"), (b"//foo", b"bar")) + self.assertRaises(TypeError, posixpath.split) def splitextTest(self, path, filename, ext): self.assertEqual(posixpath.splitext(path), (filename, ext)) self.assertEqual(posixpath.splitext("/" + path), ("/" + filename, ext)) - self.assertEqual(posixpath.splitext("abc/" + path), ("abc/" + filename, ext)) - self.assertEqual(posixpath.splitext("abc.def/" + path), ("abc.def/" + filename, ext)) - self.assertEqual(posixpath.splitext("/abc.def/" + path), ("/abc.def/" + filename, ext)) - self.assertEqual(posixpath.splitext(path + "/"), (filename + ext + "/", "")) + self.assertEqual(posixpath.splitext("abc/" + path), + ("abc/" + filename, ext)) + self.assertEqual(posixpath.splitext("abc.def/" + path), + ("abc.def/" + filename, ext)) + self.assertEqual(posixpath.splitext("/abc.def/" + path), + ("/abc.def/" + filename, ext)) + self.assertEqual(posixpath.splitext(path + "/"), + (filename + ext + "/", "")) + + path = bytes(path, "ASCII") + filename = bytes(filename, "ASCII") + ext = bytes(ext, "ASCII") + + self.assertEqual(posixpath.splitext(path), (filename, ext)) + self.assertEqual(posixpath.splitext(b"/" + path), + (b"/" + filename, ext)) + self.assertEqual(posixpath.splitext(b"abc/" + path), + (b"abc/" + filename, ext)) + self.assertEqual(posixpath.splitext(b"abc.def/" + path), + (b"abc.def/" + filename, ext)) + self.assertEqual(posixpath.splitext(b"/abc.def/" + path), + (b"/abc.def/" + filename, ext)) + self.assertEqual(posixpath.splitext(path + b"/"), + (filename + ext + b"/", b"")) def test_splitext(self): self.splitextTest("foo.bar", "foo", ".bar") @@ -87,12 +127,13 @@ self.assertIs(posixpath.isabs("/foo/bar"), True) self.assertIs(posixpath.isabs("foo/bar"), False) - self.assertRaises(TypeError, posixpath.isabs) + self.assertIs(posixpath.isabs(b""), False) + self.assertIs(posixpath.isabs(b"/"), True) + self.assertIs(posixpath.isabs(b"/foo"), True) + self.assertIs(posixpath.isabs(b"/foo/bar"), True) + self.assertIs(posixpath.isabs(b"foo/bar"), False) - def test_splitdrive(self): - self.assertEqual(posixpath.splitdrive("/foo/bar"), ("", "/foo/bar")) - - self.assertRaises(TypeError, posixpath.splitdrive) + self.assertRaises(TypeError, posixpath.isabs) def test_basename(self): self.assertEqual(posixpath.basename("/foo/bar"), "bar") @@ -101,6 +142,12 @@ self.assertEqual(posixpath.basename("////foo"), "foo") self.assertEqual(posixpath.basename("//foo//bar"), "bar") + self.assertEqual(posixpath.basename(b"/foo/bar"), b"bar") + self.assertEqual(posixpath.basename(b"/"), b"") + self.assertEqual(posixpath.basename(b"foo"), b"foo") + self.assertEqual(posixpath.basename(b"////foo"), b"foo") + self.assertEqual(posixpath.basename(b"//foo//bar"), b"bar") + self.assertRaises(TypeError, posixpath.basename) def test_dirname(self): @@ -110,6 +157,12 @@ self.assertEqual(posixpath.dirname("////foo"), "////") self.assertEqual(posixpath.dirname("//foo//bar"), "//foo") + self.assertEqual(posixpath.dirname(b"/foo/bar"), b"/foo") + self.assertEqual(posixpath.dirname(b"/"), b"/") + self.assertEqual(posixpath.dirname(b"foo"), b"") + self.assertEqual(posixpath.dirname(b"////foo"), b"////") + self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo") + self.assertRaises(TypeError, posixpath.dirname) def test_commonprefix(self): @@ -130,6 +183,19 @@ "/home/swen/spam" ) + self.assertEqual( + posixpath.commonprefix([b"/home/swenson/spam", b"/home/swen/spam"]), + b"/home/swen" + ) + self.assertEqual( + posixpath.commonprefix([b"/home/swen/spam", b"/home/swen/eggs"]), + b"/home/swen/" + ) + self.assertEqual( + posixpath.commonprefix([b"/home/swen/spam", b"/home/swen/spam"]), + b"/home/swen/spam" + ) + testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd', 'aXc', 'abd', 'ab', 'aX', 'abcX'] for s1 in testlist: for s2 in testlist: @@ -330,20 +396,28 @@ def test_expanduser(self): self.assertEqual(posixpath.expanduser("foo"), "foo") + self.assertEqual(posixpath.expanduser(b"foo"), b"foo") try: import pwd except ImportError: pass else: self.assert_(isinstance(posixpath.expanduser("~/"), str)) + self.assert_(isinstance(posixpath.expanduser(b"~/"), bytes)) # if home directory == root directory, this test makes no sense if posixpath.expanduser("~") != '/': self.assertEqual( posixpath.expanduser("~") + "/", posixpath.expanduser("~/") ) + self.assertEqual( + posixpath.expanduser(b"~") + b"/", + posixpath.expanduser(b"~/") + ) self.assert_(isinstance(posixpath.expanduser("~root/"), str)) self.assert_(isinstance(posixpath.expanduser("~foo/"), str)) + self.assert_(isinstance(posixpath.expanduser(b"~root/"), bytes)) + self.assert_(isinstance(posixpath.expanduser(b"~foo/"), bytes)) self.assertRaises(TypeError, posixpath.expanduser) @@ -366,6 +440,19 @@ self.assertEqual(posixpath.expandvars("${{foo}}"), "baz1}") self.assertEqual(posixpath.expandvars("$foo$foo"), "barbar") self.assertEqual(posixpath.expandvars("$bar$bar"), "$bar$bar") + + self.assertEqual(posixpath.expandvars(b"foo"), b"foo") + self.assertEqual(posixpath.expandvars(b"$foo bar"), b"bar bar") + self.assertEqual(posixpath.expandvars(b"${foo}bar"), b"barbar") + self.assertEqual(posixpath.expandvars(b"$[foo]bar"), b"$[foo]bar") + self.assertEqual(posixpath.expandvars(b"$bar bar"), b"$bar bar") + self.assertEqual(posixpath.expandvars(b"$?bar"), b"$?bar") + self.assertEqual(posixpath.expandvars(b"${foo}bar"), b"barbar") + self.assertEqual(posixpath.expandvars(b"$foo}bar"), b"bar}bar") + self.assertEqual(posixpath.expandvars(b"${foo"), b"${foo") + self.assertEqual(posixpath.expandvars(b"${{foo}}"), b"baz1}") + self.assertEqual(posixpath.expandvars(b"$foo$foo"), b"barbar") + self.assertEqual(posixpath.expandvars(b"$bar$bar"), b"$bar$bar") finally: os.environ.clear() os.environ.update(oldenv) @@ -378,18 +465,31 @@ self.assertEqual(posixpath.normpath("//"), "//") self.assertEqual(posixpath.normpath("///"), "/") self.assertEqual(posixpath.normpath("///foo/.//bar//"), "/foo/bar") - self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"), "/foo/baz") + self.assertEqual(posixpath.normpath("///foo/.//bar//.//..//.//baz"), + "/foo/baz") self.assertEqual(posixpath.normpath("///..//./foo/.//bar"), "/foo/bar") + self.assertEqual(posixpath.normpath(b""), b".") + self.assertEqual(posixpath.normpath(b"/"), b"/") + self.assertEqual(posixpath.normpath(b"//"), b"//") + self.assertEqual(posixpath.normpath(b"///"), b"/") + self.assertEqual(posixpath.normpath(b"///foo/.//bar//"), b"/foo/bar") + self.assertEqual(posixpath.normpath(b"///foo/.//bar//.//..//.//baz"), + b"/foo/baz") + self.assertEqual(posixpath.normpath(b"///..//./foo/.//bar"), + b"/foo/bar") + self.assertRaises(TypeError, posixpath.normpath) def test_abspath(self): self.assert_("foo" in posixpath.abspath("foo")) + self.assert_(b"foo" in posixpath.abspath(b"foo")) self.assertRaises(TypeError, posixpath.abspath) def test_realpath(self): self.assert_("foo" in realpath("foo")) + self.assert_(b"foo" in realpath(b"foo")) self.assertRaises(TypeError, posixpath.realpath) if hasattr(os, "symlink"): @@ -499,12 +599,34 @@ self.assertEqual(posixpath.relpath("a/b"), "a/b") self.assertEqual(posixpath.relpath("../a/b"), "../a/b") self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a") - self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b") + self.assertEqual(posixpath.relpath("a/b", "../c"), + "../"+curdir+"/a/b") self.assertEqual(posixpath.relpath("a", "b/c"), "../../a") self.assertEqual(posixpath.relpath("a", "a"), ".") finally: os.getcwd = real_getcwd + def test_relpath_bytes(self): + (real_getcwdb, os.getcwdb) = (os.getcwdb, lambda: br"/home/user/bar") + try: + curdir = os.path.split(os.getcwdb())[-1] + self.assertRaises(ValueError, posixpath.relpath, b"") + self.assertEqual(posixpath.relpath(b"a"), b"a") + self.assertEqual(posixpath.relpath(posixpath.abspath(b"a")), b"a") + self.assertEqual(posixpath.relpath(b"a/b"), b"a/b") + self.assertEqual(posixpath.relpath(b"../a/b"), b"../a/b") + self.assertEqual(posixpath.relpath(b"a", b"../b"), + b"../"+curdir+b"/a") + self.assertEqual(posixpath.relpath(b"a/b", b"../c"), + b"../"+curdir+b"/a/b") + self.assertEqual(posixpath.relpath(b"a", b"b/c"), b"../../a") + self.assertEqual(posixpath.relpath(b"a", b"a"), b".") + + self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str") + self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes") + finally: + os.getcwdb = real_getcwdb + def test_main(): support.run_unittest(PosixPathTest) Modified: python/branches/py3k/Lib/test/test_unicode_file.py ============================================================================== --- python/branches/py3k/Lib/test/test_unicode_file.py (original) +++ python/branches/py3k/Lib/test/test_unicode_file.py Thu Oct 2 20:55:37 2008 @@ -90,7 +90,7 @@ os.unlink(filename1 + ".new") def _do_directory(self, make_name, chdir_name, encoded): - cwd = os.getcwd() + cwd = os.getcwdb() if os.path.isdir(make_name): os.rmdir(make_name) os.mkdir(make_name) @@ -98,10 +98,10 @@ os.chdir(chdir_name) try: if not encoded: - cwd_result = os.getcwdu() + cwd_result = os.getcwd() name_result = make_name else: - cwd_result = os.getcwd().decode(TESTFN_ENCODING) + cwd_result = os.getcwdb().decode(TESTFN_ENCODING) name_result = make_name.decode(TESTFN_ENCODING) cwd_result = unicodedata.normalize("NFD", cwd_result) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Oct 2 20:55:37 2008 @@ -4,8 +4,11 @@ (editors: check NEWS.help for information about editing NEWS using ReST.) -What's New in Python 3.0 release candidate 2 -============================================ +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.] *Release date: XX-XXX-2008* @@ -22,6 +25,9 @@ Library ------- +- Issue #3187: Better support for "undecodable" filenames. Code by Victor + Stinner, with small tweaks by GvR. + - Issue #3965: Allow repeated calls to turtle.Screen, by making it a true singleton object. Modified: python/branches/py3k/Modules/posixmodule.c ============================================================================== --- python/branches/py3k/Modules/posixmodule.c (original) +++ python/branches/py3k/Modules/posixmodule.c Thu Oct 2 20:55:37 2008 @@ -1968,63 +1968,18 @@ #ifdef HAVE_GETCWD -PyDoc_STRVAR(posix_getcwd__doc__, -"getcwd() -> path\n\n\ -Return a string representing the current working directory."); - static PyObject * -posix_getcwd(PyObject *self, PyObject *noargs) -{ - int bufsize_incr = 1024; - int bufsize = 0; - char *tmpbuf = NULL; - char *res = NULL; - PyObject *dynamic_return; - - Py_BEGIN_ALLOW_THREADS - do { - bufsize = bufsize + bufsize_incr; - tmpbuf = malloc(bufsize); - if (tmpbuf == NULL) { - break; - } -#if defined(PYOS_OS2) && defined(PYCC_GCC) - res = _getcwd2(tmpbuf, bufsize); -#else - res = getcwd(tmpbuf, bufsize); -#endif - - if (res == NULL) { - free(tmpbuf); - } - } while ((res == NULL) && (errno == ERANGE)); - Py_END_ALLOW_THREADS - - if (res == NULL) - return posix_error(); - - dynamic_return = PyUnicode_FromString(tmpbuf); - free(tmpbuf); - - return dynamic_return; -} - -PyDoc_STRVAR(posix_getcwdu__doc__, -"getcwdu() -> path\n\n\ -Return a unicode string representing the current working directory."); - -static PyObject * -posix_getcwdu(PyObject *self, PyObject *noargs) +posix_getcwd(int use_bytes) { char buf[1026]; char *res; #ifdef Py_WIN_WIDE_FILENAMES - DWORD len; - if (unicode_file_names()) { + if (!use_bytes && unicode_file_names()) { wchar_t wbuf[1026]; wchar_t *wbuf2 = wbuf; PyObject *resobj; + DWORD len; Py_BEGIN_ALLOW_THREADS len = GetCurrentDirectoryW(sizeof wbuf/ sizeof wbuf[0], wbuf); /* If the buffer is large enough, len does not include the @@ -2059,8 +2014,30 @@ Py_END_ALLOW_THREADS if (res == NULL) return posix_error(); + if (use_bytes) + return PyBytes_FromStringAndSize(buf, strlen(buf)); return PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,"strict"); } + +PyDoc_STRVAR(posix_getcwd__doc__, +"getcwd() -> path\n\n\ +Return a unicode string representing the current working directory."); + +static PyObject * +posix_getcwd_unicode(PyObject *self) +{ + return posix_getcwd(0); +} + +PyDoc_STRVAR(posix_getcwdb__doc__, +"getcwdb() -> path\n\n\ +Return a bytes string representing the current working directory."); + +static PyObject * +posix_getcwd_bytes(PyObject *self) +{ + return posix_getcwd(1); +} #endif @@ -2378,9 +2355,12 @@ v = w; } else { - /* fall back to the original byte string, as - discussed in patch #683592 */ + /* Ignore undecodable filenames, as discussed + * in issue 3187. To include these, + * use getcwdb(). */ PyErr_Clear(); + Py_DECREF(v); + continue; } } if (PyList_Append(d, v) != 0) { @@ -4477,9 +4457,7 @@ v = w; } else { - /* fall back to the original byte string, as - discussed in patch #683592 */ - PyErr_Clear(); + v = NULL; } } return v; @@ -6810,8 +6788,10 @@ {"ctermid", posix_ctermid, METH_NOARGS, posix_ctermid__doc__}, #endif #ifdef HAVE_GETCWD - {"getcwd", posix_getcwd, METH_NOARGS, posix_getcwd__doc__}, - {"getcwdu", posix_getcwdu, METH_NOARGS, posix_getcwdu__doc__}, + {"getcwd", (PyCFunction)posix_getcwd_unicode, + METH_NOARGS, posix_getcwd__doc__}, + {"getcwdb", (PyCFunction)posix_getcwd_bytes, + METH_NOARGS, posix_getcwdb__doc__}, #endif #ifdef HAVE_LINK {"link", posix_link, METH_VARARGS, posix_link__doc__}, From python-3000-checkins at python.org Thu Oct 2 21:10:18 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 2 Oct 2008 21:10:18 +0200 (CEST) Subject: [Python-3000-checkins] r66746 - python/branches/py3k Message-ID: <20081002191018.61B841E4002@bag.python.org> Author: benjamin.peterson Date: Thu Oct 2 21:10:18 2008 New Revision: 66746 Log: Blocked revisions 66744 via svnmerge ........ r66744 | benjamin.peterson | 2008-10-02 14:00:31 -0500 (Thu, 02 Oct 2008) | 1 line we're in 2.7 now ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Thu Oct 2 21:56:02 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Thu, 2 Oct 2008 21:56:02 +0200 (CEST) Subject: [Python-3000-checkins] r66751 - in python/branches/py3k: Modules/_ctypes/libffi/src/x86/ffi.c Modules/signalmodule.c Modules/tkappinit.c Objects/bytesobject.c Objects/unicodeobject.c Python/_warnings.c Message-ID: <20081002195602.6B3341E4002@bag.python.org> Author: christian.heimes Date: Thu Oct 2 21:56:01 2008 New Revision: 66751 Log: Merged revisions 66748 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66748 | christian.heimes | 2008-10-02 21:47:50 +0200 (Thu, 02 Oct 2008) | 1 line Fixed a couple more C99 comments and one occurence of inline. ........ + another // comment in bytesobject Modified: python/branches/py3k/ (props changed) python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi.c python/branches/py3k/Modules/signalmodule.c python/branches/py3k/Modules/tkappinit.c python/branches/py3k/Objects/bytesobject.c python/branches/py3k/Objects/unicodeobject.c python/branches/py3k/Python/_warnings.c Modified: python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi.c ============================================================================== --- python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi.c (original) +++ python/branches/py3k/Modules/_ctypes/libffi/src/x86/ffi.c Thu Oct 2 21:56:01 2008 @@ -388,10 +388,10 @@ return FFI_BAD_ABI; } - // we currently don't support certain kinds of arguments for raw + /* we currently don't support certain kinds of arguments for raw // closures. This should be implemented by a separate assembly language // routine, since it would require argument processing, something we - // don't do now for performance. + // don't do now for performance. */ for (i = cif->nargs-1; i >= 0; i--) { Modified: python/branches/py3k/Modules/signalmodule.c ============================================================================== --- python/branches/py3k/Modules/signalmodule.c (original) +++ python/branches/py3k/Modules/signalmodule.c Thu Oct 2 21:56:01 2008 @@ -107,7 +107,7 @@ tv->tv_usec = fmod(d, 1.0) * 1000000.0; } -static inline double +Py_LOCAL_INLINE(double) double_from_timeval(struct timeval *tv) { return tv->tv_sec + (double)(tv->tv_usec / 1000000.0); Modified: python/branches/py3k/Modules/tkappinit.c ============================================================================== --- python/branches/py3k/Modules/tkappinit.c (original) +++ python/branches/py3k/Modules/tkappinit.c Thu Oct 2 21:56:01 2008 @@ -71,7 +71,7 @@ #endif #ifdef WITH_XXX - // Initialize modules that don't require Tk + /* Initialize modules that don't require Tk */ #endif _tkinter_skip_tk_init = Tcl_GetVar(interp, "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY); Modified: python/branches/py3k/Objects/bytesobject.c ============================================================================== --- python/branches/py3k/Objects/bytesobject.c (original) +++ python/branches/py3k/Objects/bytesobject.c Thu Oct 2 21:56:01 2008 @@ -2965,7 +2965,7 @@ new = PyBytes_FromStringAndSize(NULL, view.len); if (!new) goto fail; - // XXX(brett.cannon): Better way to get to internal buffer? + /* XXX(brett.cannon): Better way to get to internal buffer? */ if (PyBuffer_ToContiguous(((PyBytesObject *)new)->ob_sval, &view, view.len, 'C') < 0) goto fail; Modified: python/branches/py3k/Objects/unicodeobject.c ============================================================================== --- python/branches/py3k/Objects/unicodeobject.c (original) +++ python/branches/py3k/Objects/unicodeobject.c Thu Oct 2 21:56:01 2008 @@ -126,19 +126,19 @@ /* Fast detection of the most frequent whitespace characters */ const unsigned char _Py_ascii_whitespace[] = { 0, 0, 0, 0, 0, 0, 0, 0, -// case 0x0009: /* HORIZONTAL TABULATION */ -// case 0x000A: /* LINE FEED */ -// case 0x000B: /* VERTICAL TABULATION */ -// case 0x000C: /* FORM FEED */ -// case 0x000D: /* CARRIAGE RETURN */ +/* case 0x0009: * HORIZONTAL TABULATION */ +/* case 0x000A: * LINE FEED */ +/* case 0x000B: * VERTICAL TABULATION */ +/* case 0x000C: * FORM FEED */ +/* case 0x000D: * CARRIAGE RETURN */ 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -// case 0x001C: /* FILE SEPARATOR */ -// case 0x001D: /* GROUP SEPARATOR */ -// case 0x001E: /* RECORD SEPARATOR */ -// case 0x001F: /* UNIT SEPARATOR */ +/* case 0x001C: * FILE SEPARATOR */ +/* case 0x001D: * GROUP SEPARATOR */ +/* case 0x001E: * RECORD SEPARATOR */ +/* case 0x001F: * UNIT SEPARATOR */ 0, 0, 0, 0, 1, 1, 1, 1, -// case 0x0020: /* SPACE */ +/* case 0x0020: * SPACE */ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -157,13 +157,13 @@ /* Same for linebreaks */ static unsigned char ascii_linebreak[] = { 0, 0, 0, 0, 0, 0, 0, 0, -// 0x000A, /* LINE FEED */ -// 0x000D, /* CARRIAGE RETURN */ +/* 0x000A, * LINE FEED */ +/* 0x000D, * CARRIAGE RETURN */ 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -// 0x001C, /* FILE SEPARATOR */ -// 0x001D, /* GROUP SEPARATOR */ -// 0x001E, /* RECORD SEPARATOR */ +/* 0x001C, * FILE SEPARATOR */ +/* 0x001D, * GROUP SEPARATOR */ +/* 0x001E, * RECORD SEPARATOR */ 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Modified: python/branches/py3k/Python/_warnings.c ============================================================================== --- python/branches/py3k/Python/_warnings.c (original) +++ python/branches/py3k/Python/_warnings.c Thu Oct 2 21:56:01 2008 @@ -382,7 +382,7 @@ } } - if (rc == 1) // Already warned for this module. */ + if (rc == 1) /* Already warned for this module. */ goto return_none; if (rc == 0) { PyObject *show_fxn = get_warnings_attr("showwarning"); @@ -776,8 +776,8 @@ warn_doc}, {"warn_explicit", (PyCFunction)warnings_warn_explicit, METH_VARARGS | METH_KEYWORDS, warn_explicit_doc}, - // XXX(brett.cannon): add showwarning? - // XXX(brett.cannon): Reasonable to add formatwarning? + /* XXX(brett.cannon): add showwarning? */ + /* XXX(brett.cannon): Reasonable to add formatwarning? */ {NULL, NULL} /* sentinel */ }; From python-3000-checkins at python.org Thu Oct 2 22:09:01 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Thu, 2 Oct 2008 22:09:01 +0200 (CEST) Subject: [Python-3000-checkins] r66753 - in python/branches/py3k: Tools/msi/msi.py Message-ID: <20081002200901.D238A1E4002@bag.python.org> Author: martin.v.loewis Date: Thu Oct 2 22:09:01 2008 New Revision: 66753 Log: Merged revisions 66752 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66752 | martin.v.loewis | 2008-10-02 22:04:47 +0200 (Do, 02 Okt 2008) | 2 lines Add UUID for 2.7. ........ 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 Oct 2 22:09:01 2008 @@ -110,6 +110,7 @@ "24":"{9B81E618-2301-4035-AC77-75D9ABEB7301}", "25":"{2e41b118-38bd-4c1b-a840-6977efd1b911}", "26":"{34ebecac-f046-4e1c-b0e3-9bac3cdaacfa}", + "27":"{4fe21c76-1760-437b-a2f2-99909130a175}", "30":"{6953bc3b-6768-4291-8410-7914ce6e2ca8}", } [major+minor] From python-3000-checkins at python.org Thu Oct 2 22:09:47 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Thu, 2 Oct 2008 22:09:47 +0200 (CEST) Subject: [Python-3000-checkins] r66754 - python/branches/py3k/Tools/msi/msi.py Message-ID: <20081002200947.6B4FF1E4002@bag.python.org> Author: martin.v.loewis Date: Thu Oct 2 22:09:47 2008 New Revision: 66754 Log: Add UUID for 3.1. Modified: 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 Oct 2 22:09:47 2008 @@ -112,6 +112,7 @@ "26":"{34ebecac-f046-4e1c-b0e3-9bac3cdaacfa}", "27":"{4fe21c76-1760-437b-a2f2-99909130a175}", "30":"{6953bc3b-6768-4291-8410-7914ce6e2ca8}", + "31":"{4afcba0b-13e4-47c3-bebe-477428b46913}", } [major+minor] # Compute the name that Sphinx gives to the docfile From python-3000-checkins at python.org Thu Oct 2 22:10:41 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Thu, 2 Oct 2008 22:10:41 +0200 (CEST) Subject: [Python-3000-checkins] r66755 - python/branches/py3k/Tools/msi/uuids.py Message-ID: <20081002201041.3D12B1E403C@bag.python.org> Author: martin.v.loewis Date: Thu Oct 2 22:10:40 2008 New Revision: 66755 Log: Add UUID for 3.0b4. 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 Thu Oct 2 22:10:40 2008 @@ -55,6 +55,7 @@ '3.0.111': '{36c26f55-837d-45cf-848c-5f5c0fb47a28}', # 3.0b1 '3.0.112': '{056a0fbc-c8fe-4c61-aade-c4411b70c998}', # 3.0b2 '3.0.113': '{2b2e89a9-83af-43f9-b7d5-96e80c5a3f26}', # 3.0b3 + '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.150': '{e0e56e21-55de-4f77-a109-1baa72348743}', # 3.0.0 From python-3000-checkins at python.org Thu Oct 2 22:52:36 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 2 Oct 2008 22:52:36 +0200 (CEST) Subject: [Python-3000-checkins] r66757 - python/branches/py3k Message-ID: <20081002205236.B153E1E4002@bag.python.org> Author: benjamin.peterson Date: Thu Oct 2 22:52:36 2008 New Revision: 66757 Log: Blocked revisions 66756 via svnmerge ........ r66756 | benjamin.peterson | 2008-10-02 15:46:58 -0500 (Thu, 02 Oct 2008) | 1 line update pydoc topics ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Thu Oct 2 23:02:28 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 2 Oct 2008 23:02:28 +0200 (CEST) Subject: [Python-3000-checkins] r66758 - python/branches/py3k/Lib/pydoc_topics.py Message-ID: <20081002210228.EFA741E4002@bag.python.org> Author: benjamin.peterson Date: Thu Oct 2 23:02:27 2008 New Revision: 66758 Log: update pydoc-topics 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 Thu Oct 2 23:02:27 2008 @@ -1,29 +1,29 @@ -# Autogenerated by Sphinx on Sun Jun 1 23:04:03 2008 +# Autogenerated by Sphinx on Thu Oct 2 15:58:57 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', + '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 ``__setattr__()``\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\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\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. [1]\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* 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* *__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-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', + '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', 'bitwise': '\nBinary bitwise operations\n*************************\n\nEach of the three bitwise operations has a different priority level:\n\n and_expr ::= shift_expr | and_expr "&" shift_expr\n xor_expr ::= and_expr | xor_expr "^" and_expr\n or_expr ::= xor_expr | or_expr "|" xor_expr\n\nThe ``&`` operator yields the bitwise AND of its arguments, which must\nbe integers.\n\nThe ``^`` operator yields the bitwise XOR (exclusive OR) of its\narguments, which must be integers.\n\nThe ``|`` operator yields the bitwise (inclusive) OR of its arguments,\nwhich must be integers.\n', 'bltin-code-objects': '\nCode Objects\n************\n\nCode objects are used by the implementation to represent "pseudo-\ncompiled" executable Python code such as a function body. They differ\nfrom function objects because they don\'t contain a reference to their\nglobal execution environment. Code objects are returned by the built-\nin ``compile()`` function and can be extracted from function objects\nthrough their ``__code__`` attribute. See also the ``code`` module.\n\nA code object can be executed or evaluated by passing it (instead of a\nsource string) to the ``exec()`` or ``eval()`` built-in functions.\n\nSee *The standard type hierarchy* for more information.\n', 'bltin-ellipsis-object': '\nThe Ellipsis Object\n*******************\n\nThis object is commonly used by slicing (see *Slicings*). It supports\nno special operations. There is exactly one ellipsis object, named\n``Ellipsis`` (a built-in name).\n\nIt is written as ``Ellipsis`` or ``...``.\n', - 'bltin-file-objects': '\nFile Objects\n************\n\nFile objects are implemented using C\'s ``stdio`` package and can be\ncreated with the built-in ``open()`` function. File objects are also\nreturned by some other built-in functions and methods, such as\n``os.popen()`` and ``os.fdopen()`` and the ``makefile()`` method of\nsocket objects. Temporary files can be created using the ``tempfile``\nmodule, and high-level file operations such as copying, moving, and\ndeleting files and directories can be achieved with the ``shutil``\nmodule.\n\nWhen a file operation fails for an I/O-related reason, the exception\n``IOError`` is raised. This includes situations where the operation\nis not defined for some reason, like ``seek()`` on a tty device or\nwriting a file opened for reading.\n\nFiles have the following methods:\n\nfile.close()\n\n Close the file. A closed file cannot be read or written any more.\n Any operation which requires that the file be open will raise a\n ``ValueError`` after the file has been closed. Calling ``close()``\n more than once is allowed.\n\n You can avoid having to call this method explicitly if you use the\n ``with`` statement. For example, the following code will\n automatically close *f* when the ``with`` block is exited:\n\n from __future__ import with_statement\n\n with open("hello.txt") as f:\n for line in f:\n print(line)\n\n In older versions of Python, you would have needed to do this to\n get the same effect:\n\n f = open("hello.txt")\n try:\n for line in f:\n print(line)\n finally:\n f.close()\n\n Note: Not all "file-like" types in Python support use as a context\n manager for the ``with`` statement. If your code is intended to\n work with any file-like object, you can use the function\n ``contextlib.closing()`` instead of using the object directly.\n\nfile.flush()\n\n Flush the internal buffer, like ``stdio``\'s ``fflush``. This may\n be a no-op on some file-like objects.\n\nfile.fileno()\n\n Return the integer "file descriptor" that is used by the underlying\n implementation to request I/O operations from the operating system.\n This can be useful for other, lower level interfaces that use file\n descriptors, such as the ``fcntl`` module or ``os.read()`` and\n friends.\n\n Note: File-like objects which do not have a real file descriptor should\n *not* provide this method!\n\nfile.isatty()\n\n Return ``True`` if the file is connected to a tty(-like) device,\n else ``False``.\n\n Note: If a file-like object is not associated with a real file, this\n method should *not* be implemented.\n\nfile.__next__()\n\n A file object is its own iterator, for example ``iter(f)`` returns\n *f* (unless *f* is closed). When a file is used as an iterator,\n typically in a ``for`` loop (for example, ``for line in f:\n print(line)``), the ``__next__()`` method is called repeatedly.\n This method returns the next input line, or raises\n ``StopIteration`` when EOF is hit when the file is open for reading\n (behavior is undefined when the file is open for writing). In\n order to make a ``for`` loop the most efficient way of looping over\n the lines of a file (a very common operation), the ``__next__()``\n method uses a hidden read-ahead buffer. As a consequence of using\n a read-ahead buffer, combining ``__next__()`` with other file\n methods (like ``readline()``) does not work right. However, using\n ``seek()`` to reposition the file to an absolute position will\n flush the read-ahead buffer.\n\nfile.read([size])\n\n Read at most *size* bytes from the file (less if the read hits EOF\n before obtaining *size* bytes). If the *size* argument is negative\n or omitted, read all data until EOF is reached. The bytes are\n returned as a string object. An empty string is returned when EOF\n is encountered immediately. (For certain files, like ttys, it\n makes sense to continue reading after an EOF is hit.) Note that\n this method may call the underlying C function ``fread`` more than\n once in an effort to acquire as close to *size* bytes as possible.\n Also note that when in non-blocking mode, less data than what was\n requested may be returned, even if no *size* parameter was given.\n\nfile.readline([size])\n\n Read one entire line from the file. A trailing newline character\n is kept in the string (but may be absent when a file ends with an\n incomplete line). [6] If the *size* argument is present and non-\n negative, it is a maximum byte count (including the trailing\n newline) and an incomplete line may be returned. An empty string is\n returned *only* when EOF is encountered immediately.\n\n Note: Unlike ``stdio``\'s ``fgets``, the returned string contains null\n characters (``\'\\0\'``) if they occurred in the input.\n\nfile.readlines([sizehint])\n\n Read until EOF using ``readline()`` and return a list containing\n the lines thus read. If the optional *sizehint* argument is\n present, instead of reading up to EOF, whole lines totalling\n approximately *sizehint* bytes (possibly after rounding up to an\n internal buffer size) are read. Objects implementing a file-like\n interface may choose to ignore *sizehint* if it cannot be\n implemented, or cannot be implemented efficiently.\n\nfile.seek(offset[, whence])\n\n Set the file\'s current position, like ``stdio``\'s ``fseek``. The\n *whence* argument is optional and defaults to ``os.SEEK_SET`` or\n ``0`` (absolute file positioning); other values are ``os.SEEK_CUR``\n or ``1`` (seek relative to the current position) and\n ``os.SEEK_END`` or ``2`` (seek relative to the file\'s end). There\n is no return value.\n\n For example, ``f.seek(2, os.SEEK_CUR)`` advances the position by\n two and ``f.seek(-3, os.SEEK_END)`` sets the position to the third\n to last.\n\n Note that if the file is opened for appending (mode ``\'a\'`` or\n ``\'a+\'``), any ``seek()`` operations will be undone at the next\n write. If the file is only opened for writing in append mode (mode\n ``\'a\'``), this method is essentially a no-op, but it remains useful\n for files opened in append mode with reading enabled (mode\n ``\'a+\'``). If the file is opened in text mode (without ``\'b\'``),\n only offsets returned by ``tell()`` are legal. Use of other\n offsets causes undefined behavior.\n\n Note that not all file objects are seekable.\n\nfile.tell()\n\n Return the file\'s current position, like ``stdio``\'s ``ftell``.\n\n Note: On Windows, ``tell()`` can return illegal values (after an\n ``fgets``) when reading files with Unix-style line-endings. Use\n binary mode (``\'rb\'``) to circumvent this problem.\n\nfile.truncate([size])\n\n Truncate the file\'s size. If the optional *size* argument is\n present, the file is truncated to (at most) that size. The size\n defaults to the current position. The current file position is not\n changed. Note that if a specified size exceeds the file\'s current\n size, the result is platform-dependent: possibilities include that\n the file may remain unchanged, increase to the specified size as if\n zero-filled, or increase to the specified size with undefined new\n content. Availability: Windows, many Unix variants.\n\nfile.write(str)\n\n Write a string to the file. Due to buffering, the string may not\n actually show up in the file until the ``flush()`` or ``close()``\n method is called.\n\n The meaning of the return value is not defined for every file-like\n object. Some (mostly low-level) file-like objects may return the\n number of bytes actually written, others return ``None``.\n\nfile.writelines(sequence)\n\n Write a sequence of strings to the file. The sequence can be any\n iterable object producing strings, typically a list of strings.\n There is no return value. (The name is intended to match\n ``readlines()``; ``writelines()`` does not add line separators.)\n\nFiles support the iterator protocol. Each iteration returns the same\nresult as ``file.readline()``, and iteration ends when the\n``readline()`` method returns an empty string.\n\nFile objects also offer a number of other interesting attributes.\nThese are not required for file-like objects, but should be\nimplemented if they make sense for the particular object.\n\nfile.closed\n\n bool indicating the current state of the file object. This is a\n read-only attribute; the ``close()`` method changes the value. It\n may not be available on all file-like objects.\n\nfile.encoding\n\n The encoding that this file uses. When strings are written to a\n file, they will be converted to byte strings using this encoding.\n In addition, when the file is connected to a terminal, the\n attribute gives the encoding that the terminal is likely to use\n (that information might be incorrect if the user has misconfigured\n the terminal). The attribute is read-only and may not be present\n on all file-like objects. It may also be ``None``, in which case\n the file uses the system default encoding for converting strings.\n\nfile.mode\n\n The I/O mode for the file. If the file was created using the\n ``open()`` built-in function, this will be the value of the *mode*\n parameter. This is a read-only attribute and may not be present on\n all file-like objects.\n\nfile.name\n\n If the file object was created using ``open()``, the name of the\n file. Otherwise, some string that indicates the source of the file\n object, of the form ``<...>``. This is a read-only attribute and\n may not be present on all file-like objects.\n\nfile.newlines\n\n If Python was built with the *--with-universal-newlines* option to\n **configure** (the default) this read-only attribute exists, and\n for files opened in universal newline read mode it keeps track of\n the types of newlines encountered while reading the file. The\n values it can take are ``\'\\r\'``, ``\'\\n\'``, ``\'\\r\\n\'``, ``None``\n (unknown, no newlines read yet) or a tuple containing all the\n newline types seen, to indicate that multiple newline conventions\n were encountered. For files not opened in universal newline read\n mode the value of this attribute will be ``None``.\n', + 'bltin-file-objects': '\nFile Objects\n************\n\nFile objects are implemented using C\'s ``stdio`` package and can be\ncreated with the built-in ``open()`` function. File objects are also\nreturned by some other built-in functions and methods, such as\n``os.popen()`` and ``os.fdopen()`` and the ``makefile()`` method of\nsocket objects. Temporary files can be created using the ``tempfile``\nmodule, and high-level file operations such as copying, moving, and\ndeleting files and directories can be achieved with the ``shutil``\nmodule.\n\nWhen a file operation fails for an I/O-related reason, the exception\n``IOError`` is raised. This includes situations where the operation\nis not defined for some reason, like ``seek()`` on a tty device or\nwriting a file opened for reading.\n\nFiles have the following methods:\n\nfile.close()\n\n Close the file. A closed file cannot be read or written any more.\n Any operation which requires that the file be open will raise a\n ``ValueError`` after the file has been closed. Calling ``close()``\n more than once is allowed.\n\n You can avoid having to call this method explicitly if you use the\n ``with`` statement. For example, the following code will\n automatically close *f* when the ``with`` block is exited:\n\n from __future__ import with_statement # This isn\'t required in Python 2.6\n\n with open("hello.txt") as f:\n for line in f:\n print(line)\n\n In older versions of Python, you would have needed to do this to\n get the same effect:\n\n f = open("hello.txt")\n try:\n for line in f:\n print(line)\n finally:\n f.close()\n\n Note: Not all "file-like" types in Python support use as a context\n manager for the ``with`` statement. If your code is intended to\n work with any file-like object, you can use the function\n ``contextlib.closing()`` instead of using the object directly.\n\nfile.flush()\n\n Flush the internal buffer, like ``stdio``\'s ``fflush``. This may\n be a no-op on some file-like objects.\n\nfile.fileno()\n\n Return the integer "file descriptor" that is used by the underlying\n implementation to request I/O operations from the operating system.\n This can be useful for other, lower level interfaces that use file\n descriptors, such as the ``fcntl`` module or ``os.read()`` and\n friends.\n\n Note: File-like objects which do not have a real file descriptor should\n *not* provide this method!\n\nfile.isatty()\n\n Return ``True`` if the file is connected to a tty(-like) device,\n else ``False``.\n\n Note: If a file-like object is not associated with a real file, this\n method should *not* be implemented.\n\nfile.__next__()\n\n A file object is its own iterator, for example ``iter(f)`` returns\n *f* (unless *f* is closed). When a file is used as an iterator,\n typically in a ``for`` loop (for example, ``for line in f:\n print(line)``), the ``__next__()`` method is called repeatedly.\n This method returns the next input line, or raises\n ``StopIteration`` when EOF is hit when the file is open for reading\n (behavior is undefined when the file is open for writing). In\n order to make a ``for`` loop the most efficient way of looping over\n the lines of a file (a very common operation), the ``__next__()``\n method uses a hidden read-ahead buffer. As a consequence of using\n a read-ahead buffer, combining ``__next__()`` with other file\n methods (like ``readline()``) does not work right. However, using\n ``seek()`` to reposition the file to an absolute position will\n flush the read-ahead buffer.\n\nfile.read([size])\n\n Read at most *size* bytes from the file (less if the read hits EOF\n before obtaining *size* bytes). If the *size* argument is negative\n or omitted, read all data until EOF is reached. The bytes are\n returned as a string object. An empty string is returned when EOF\n is encountered immediately. (For certain files, like ttys, it\n makes sense to continue reading after an EOF is hit.) Note that\n this method may call the underlying C function ``fread`` more than\n once in an effort to acquire as close to *size* bytes as possible.\n Also note that when in non-blocking mode, less data than was\n requested may be returned, even if no *size* parameter was given.\n\nfile.readline([size])\n\n Read one entire line from the file. A trailing newline character\n is kept in the string (but may be absent when a file ends with an\n incomplete line). [6] If the *size* argument is present and non-\n negative, it is a maximum byte count (including the trailing\n newline) and an incomplete line may be returned. An empty string is\n returned *only* when EOF is encountered immediately.\n\n Note: Unlike ``stdio``\'s ``fgets``, the returned string contains null\n characters (``\'\\0\'``) if they occurred in the input.\n\nfile.readlines([sizehint])\n\n Read until EOF using ``readline()`` and return a list containing\n the lines thus read. If the optional *sizehint* argument is\n present, instead of reading up to EOF, whole lines totalling\n approximately *sizehint* bytes (possibly after rounding up to an\n internal buffer size) are read. Objects implementing a file-like\n interface may choose to ignore *sizehint* if it cannot be\n implemented, or cannot be implemented efficiently.\n\nfile.seek(offset[, whence])\n\n Set the file\'s current position, like ``stdio``\'s ``fseek``. The\n *whence* argument is optional and defaults to ``os.SEEK_SET`` or\n ``0`` (absolute file positioning); other values are ``os.SEEK_CUR``\n or ``1`` (seek relative to the current position) and\n ``os.SEEK_END`` or ``2`` (seek relative to the file\'s end). There\n is no return value.\n\n For example, ``f.seek(2, os.SEEK_CUR)`` advances the position by\n two and ``f.seek(-3, os.SEEK_END)`` sets the position to the third\n to last.\n\n Note that if the file is opened for appending (mode ``\'a\'`` or\n ``\'a+\'``), any ``seek()`` operations will be undone at the next\n write. If the file is only opened for writing in append mode (mode\n ``\'a\'``), this method is essentially a no-op, but it remains useful\n for files opened in append mode with reading enabled (mode\n ``\'a+\'``). If the file is opened in text mode (without ``\'b\'``),\n only offsets returned by ``tell()`` are legal. Use of other\n offsets causes undefined behavior.\n\n Note that not all file objects are seekable.\n\nfile.tell()\n\n Return the file\'s current position, like ``stdio``\'s ``ftell``.\n\n Note: On Windows, ``tell()`` can return illegal values (after an\n ``fgets``) when reading files with Unix-style line-endings. Use\n binary mode (``\'rb\'``) to circumvent this problem.\n\nfile.truncate([size])\n\n Truncate the file\'s size. If the optional *size* argument is\n present, the file is truncated to (at most) that size. The size\n defaults to the current position. The current file position is not\n changed. Note that if a specified size exceeds the file\'s current\n size, the result is platform-dependent: possibilities include that\n the file may remain unchanged, increase to the specified size as if\n zero-filled, or increase to the specified size with undefined new\n content. Availability: Windows, many Unix variants.\n\nfile.write(str)\n\n Write a string to the file. Due to buffering, the string may not\n actually show up in the file until the ``flush()`` or ``close()``\n method is called.\n\n The meaning of the return value is not defined for every file-like\n object. Some (mostly low-level) file-like objects may return the\n number of bytes actually written, others return ``None``.\n\nfile.writelines(sequence)\n\n Write a sequence of strings to the file. The sequence can be any\n iterable object producing strings, typically a list of strings.\n There is no return value. (The name is intended to match\n ``readlines()``; ``writelines()`` does not add line separators.)\n\nFiles support the iterator protocol. Each iteration returns the same\nresult as ``file.readline()``, and iteration ends when the\n``readline()`` method returns an empty string.\n\nFile objects also offer a number of other interesting attributes.\nThese are not required for file-like objects, but should be\nimplemented if they make sense for the particular object.\n\nfile.closed\n\n bool indicating the current state of the file object. This is a\n read-only attribute; the ``close()`` method changes the value. It\n may not be available on all file-like objects.\n\nfile.encoding\n\n The encoding that this file uses. When strings are written to a\n file, they will be converted to byte strings using this encoding.\n In addition, when the file is connected to a terminal, the\n attribute gives the encoding that the terminal is likely to use\n (that information might be incorrect if the user has misconfigured\n the terminal). The attribute is read-only and may not be present\n on all file-like objects. It may also be ``None``, in which case\n the file uses the system default encoding for converting strings.\n\nfile.errors\n\n The Unicode error handler used along with the encoding.\n\nfile.mode\n\n The I/O mode for the file. If the file was created using the\n ``open()`` built-in function, this will be the value of the *mode*\n parameter. This is a read-only attribute and may not be present on\n all file-like objects.\n\nfile.name\n\n If the file object was created using ``open()``, the name of the\n file. Otherwise, some string that indicates the source of the file\n object, of the form ``<...>``. This is a read-only attribute and\n may not be present on all file-like objects.\n\nfile.newlines\n\n If Python was built with the *--with-universal-newlines* option to\n **configure** (the default) this read-only attribute exists, and\n for files opened in universal newline read mode it keeps track of\n the types of newlines encountered while reading the file. The\n values it can take are ``\'\\r\'``, ``\'\\n\'``, ``\'\\r\\n\'``, ``None``\n (unknown, no newlines read yet) or a tuple containing all the\n newline types seen, to indicate that multiple newline conventions\n were encountered. For files not opened in universal newline read\n mode the value of this attribute will be ``None``.\n', 'bltin-null-object': "\nThe Null Object\n***************\n\nThis object is returned by functions that don't explicitly return a\nvalue. It supports no special operations. There is exactly one null\nobject, named ``None`` (a built-in name).\n\nIt is written as ``None``.\n", 'bltin-type-objects': "\nType Objects\n************\n\nType objects represent the various object types. An object's type is\naccessed by the built-in function ``type()``. There are no special\noperations on types. The standard module ``types`` defines names for\nall standard built-in types.\n\nTypes are written like this: ````.\n", 'booleans': '\nBoolean operations\n******************\n\nBoolean operations have the lowest priority of all Python operations:\n\n expression ::= conditional_expression | lambda_form\n expression_nocond ::= or_test | lambda_form_nocond\n conditional_expression ::= or_test ["if" or_test "else" expression]\n or_test ::= and_test | or_test "or" and_test\n and_test ::= not_test | and_test "and" not_test\n not_test ::= comparison | "not" not_test\n\nIn the context of Boolean operations, and also when expressions are\nused by control flow statements, the following values are interpreted\nas false: ``False``, ``None``, numeric zero of all types, and empty\nstrings and containers (including strings, tuples, lists,\ndictionaries, sets and frozensets). All other values are interpreted\nas true. User-defined objects can customize their truth value by\nproviding a ``__bool__()`` method.\n\nThe operator ``not`` yields ``True`` if its argument is false,\n``False`` otherwise.\n\nThe expression ``x if C else y`` first evaluates *C* (*not* *x*); if\n*C* is true, *x* is evaluated and its value is returned; otherwise,\n*y* is evaluated and its value is returned.\n\nThe expression ``x and y`` first evaluates *x*; if *x* is false, its\nvalue is returned; otherwise, *y* is evaluated and the resulting value\nis returned.\n\nThe expression ``x or y`` first evaluates *x*; if *x* is true, its\nvalue is returned; otherwise, *y* is evaluated and the resulting value\nis returned.\n\n(Note that neither ``and`` nor ``or`` restrict the value and type they\nreturn to ``False`` and ``True``, but rather return the last evaluated\nargument. This is sometimes useful, e.g., if ``s`` is a string that\nshould be replaced by a default value if it is empty, the expression\n``s or \'foo\'`` yields the desired value. Because ``not`` has to\ninvent a value anyway, it does not bother to return a value of the\nsame type as its argument, so e.g., ``not \'foo\'`` yields ``False``,\nnot ``\'\'``.)\n', 'break': '\nThe ``break`` statement\n***********************\n\n break_stmt ::= "break"\n\n``break`` may only occur syntactically nested in a ``for`` or\n``while`` loop, but not nested in a function or class definition\nwithin that loop.\n\nIt terminates the nearest enclosing loop, skipping the optional\n``else`` clause if the loop has one.\n\nIf a ``for`` loop is terminated by ``break``, the loop control target\nkeeps its current value.\n\nWhen ``break`` passes control out of a ``try`` statement with a\n``finally`` clause, that ``finally`` clause is executed before really\nleaving the loop.\n', '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 [","]\n | expression genexpr_for] ")"\n argument_list ::= positional_arguments ["," keyword_arguments]\n ["," "*" expression]\n ["," "**" expression]\n | keyword_arguments ["," "*" expression]\n ["," "**" expression]\n | "*" expression ["," "**" 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\nappears *after* any 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. A class object is then created using the inheritance list for\nthe 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 can be set in a method with ``self.name = value``. Both class\nand instance 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', - '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,\nobjects of different types *always* compare unequal, and are ordered\nconsistently but arbitrarily. You can control comparison behavior of\nobjects of non-builtin types by defining a ``__cmp__()`` method or\nrich comparison methods like ``__gt__()``, described in section\n*Special method names*.\n\n(This unusual definition of comparison was used to simplify the\ndefinition of operations like sorting and the ``in`` and ``not in``\noperators. In the future, the comparison rules for objects of\ndifferent types are likely to change.)\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.\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 | decorated\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 funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite\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.\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. A class object is then created using the inheritance list for\nthe 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 can be set in a method with ``self.name = value``. Both class\nand instance 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', - '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\n-[ Footnotes ]-\n\n[1] 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[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', + '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', + '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 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, and are called\n for comparison operators in preference to ``__cmp__()`` below. 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.__cmp__(self, other)\n\n Called by comparison operations if rich comparison (see above) is\n not defined. Should return a negative integer if ``self < other``,\n zero if ``self == other``, a positive integer if ``self > other``.\n If no ``__cmp__()``, ``__eq__()`` or ``__ne__()`` operation is\n defined, class instances are compared by object identity\n ("address"). See also the description of ``__hash__()`` for some\n important notes on creating *hashable* objects which support custom\n comparison operations and are usable as dictionary keys.\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 a ``__cmp__()`` or ``__eq__()`` method\n it should not define a ``__hash__()`` operation either; if it\n defines ``__cmp__()`` or ``__eq__()`` but not ``__hash__()``, its\n instances will not be usable as dictionary keys. If a class\n defines mutable objects and implements a ``__cmp__()`` or\n ``__eq__()`` method, it should not implement ``__hash__()``, since\n the dictionary implementation requires that a key\'s hash value is\n immutable (if the object\'s hash value changes, it will be in the\n wrong hash bucket).\n\n User-defined classes have ``__cmp__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal and\n ``x.__hash__()`` returns ``id(x)``.\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 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', '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,43 +34,43 @@ '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\nTwo conversion flags are currently supported: ``\'!s\'`` which calls\n``str()`` on the value, and ``\'!r\'`` which calls ``repr()``.\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 subsitituted 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\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. For\nnon-number types the field indicates the maximum field size - in other\nwords, how many characters will be used from the field content. The\n*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. 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. |\n +-----------+------------------------------------------------------------+\n | ``\'G\'`` | General format. Same as ``\'g\'`` except switches to ``\'E\'`` |\n | | if the number gets to large. |\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 funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite\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.\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', + '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', + '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', '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``. [XXX Can\'t be bothered to spell this\nout right now; see the URL\nhttp://www.python.org/doc/essays/packages.html for more details, also\nabout how the module search works from inside a package.]\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', - '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,\nobjects of different types *always* compare unequal, and are ordered\nconsistently but arbitrarily. You can control comparison behavior of\nobjects of non-builtin types by defining a ``__cmp__()`` method or\nrich comparison methods like ``__gt__()``, described in section\n*Special method names*.\n\n(This unusual definition of comparison was used to simplify the\ndefinition of operations like sorting and the ``in`` and ``not in``\noperators. In the future, the comparison rules for objects of\ndifferent types are likely to change.)\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.\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', + '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', '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', 'naming': '\nNaming and binding\n******************\n\n*Names* refer to objects. Names are introduced by name binding\noperations. Each occurrence of a name in the program text refers to\nthe *binding* of that name established in the innermost function block\ncontaining the use.\n\nA *block* is a piece of Python program text that is executed as a\nunit. The following are blocks: a module, a function body, and a class\ndefinition. Each command typed interactively is a block. A script\nfile (a file given as standard input to the interpreter or specified\non the interpreter command line the first argument) is a code block.\nA script command (a command specified on the interpreter command line\nwith the \'**-c**\' option) is a code block. The string argument passed\nto the built-in functions ``eval()`` and ``exec()`` is a code block.\n\nA code block is executed in an *execution frame*. A frame contains\nsome administrative information (used for debugging) and determines\nwhere and how execution continues after the code block\'s execution has\ncompleted.\n\nA *scope* defines the visibility of a name within a block. If a local\nvariable is defined in a block, its scope includes that block. If the\ndefinition occurs in a function block, the scope extends to any blocks\ncontained within the defining one, unless a contained block introduces\na different binding for the name. The scope of names defined in a\nclass block is limited to the class block; it does not extend to the\ncode blocks of methods -- this includes generator expressions since\nthey are implemented using a function scope. This means that the\nfollowing will fail:\n\n class A:\n a = 42\n b = list(a + i for i in range(10))\n\nWhen a name is used in a code block, it is resolved using the nearest\nenclosing scope. The set of all such scopes visible to a code block\nis called the block\'s *environment*.\n\nIf a name is bound in a block, it is a local variable of that block,\nunless declared as ``nonlocal``. If a name is bound at the module\nlevel, it is a global variable. (The variables of the module code\nblock are local and global.) If a variable is used in a code block\nbut not defined there, it is a *free variable*.\n\nWhen a name is not found at all, a ``NameError`` exception is raised.\nIf the name refers to a local variable that has not been bound, a\n``UnboundLocalError`` exception is raised. ``UnboundLocalError`` is a\nsubclass of ``NameError``.\n\nThe following constructs bind names: formal parameters to functions,\n``import`` statements, class and function definitions (these bind the\nclass or function name in the defining block), and targets that are\nidentifiers if occurring in an assignment, ``for`` loop header, or in\nthe second position of an ``except`` clause header. The ``import``\nstatement of the form "``from ...import *``" binds all names defined\nin the imported module, except those beginning with an underscore.\nThis form may only be used at the module level.\n\nA target occurring in a ``del`` statement is also considered bound for\nthis purpose (though the actual semantics are to unbind the name). It\nis illegal to unbind a name that is referenced by an enclosing scope;\nthe compiler will report a ``SyntaxError``.\n\nEach assignment or import statement occurs within a block defined by a\nclass or function definition or at the module level (the top-level\ncode block).\n\nIf a name binding operation occurs anywhere within a code block, all\nuses of the name within the block are treated as references to the\ncurrent block. This can lead to errors when a name is used within a\nblock before it is bound. This rule is subtle. Python lacks\ndeclarations and allows name binding operations to occur anywhere\nwithin a code block. The local variables of a code block can be\ndetermined by scanning the entire text of the block for name binding\noperations.\n\nIf the ``global`` statement occurs within a block, all uses of the\nname specified in the statement refer to the binding of that name in\nthe top-level namespace. Names are resolved in the top-level\nnamespace by searching the global namespace, i.e. the namespace of the\nmodule containing the code block, and the builtin namespace, the\nnamespace of the module ``builtins``. The global namespace is\nsearched first. If the name is not found there, the builtin namespace\nis searched. The global statement must precede all uses of the name.\n\nThe built-in namespace associated with the execution of a code block\nis actually found by looking up the name ``__builtins__`` in its\nglobal namespace; this should be a dictionary or a module (in the\nlatter case the module\'s dictionary is used). By default, when in the\n``__main__`` module, ``__builtins__`` is the built-in module\n``builtins``; when in any other module, ``__builtins__`` is an alias\nfor the dictionary of the ``builtins`` module itself.\n``__builtins__`` can be set to a user-created dictionary to create a\nweak form of restricted execution.\n\nNote: Users should not touch ``__builtins__``; it is strictly an\n implementation detail. Users wanting to override values in the\n built-in namespace should ``import`` the ``builtins`` module and\n modify its attributes appropriately.\n\nThe namespace for a module is automatically created the first time a\nmodule is imported. The main module for a script is always called\n``__main__``.\n\nThe global statement has the same scope as a name binding operation in\nthe same block. If the nearest enclosing scope for a free variable\ncontains a global statement, the free variable is treated as a global.\n\nA class definition is an executable statement that may use and define\nnames. These references follow the normal rules for name resolution.\nThe namespace of the class definition becomes the attribute dictionary\nof the class. Names defined at the class scope are not visible in\nmethods.\n\n\nInteraction with dynamic features\n=================================\n\nThere are several cases where Python statements are illegal when used\nin conjunction with nested scopes that contain free variables.\n\nIf a variable is referenced in an enclosing scope, it is illegal to\ndelete the name. An error will be reported at compile time.\n\nIf the wild card form of import --- ``import *`` --- is used in a\nfunction and the function contains or is a nested block with free\nvariables, the compiler will raise a ``SyntaxError``.\n\nThe ``eval()`` and ``exec()`` functions do not have access to the full\nenvironment for resolving names. Names may be resolved in the local\nand global namespaces of the caller. Free variables are not resolved\nin the nearest enclosing namespace, but in the global namespace. [1]\nThe ``exec()`` and ``eval()`` functions have optional arguments to\noverride the global and local namespace. If only one namespace is\nspecified, it is used for both.\n', 'numbers': "\nNumeric literals\n****************\n\nThere are three types of numeric literals: integers, floating point\nnumbers, and imaginary numbers. There are no complex literals\n(complex numbers can be formed by adding a real number and an\nimaginary number).\n\nNote that numeric literals do not include a sign; a phrase like ``-1``\nis actually an expression composed of the unary operator '``-``' and\nthe literal ``1``.\n", - 'numeric-types': "\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.__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 (``+``, ``-``, ``*``, ``//``, ``%``, ``divmod()``,\n ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``, ``|``). For\n instance, to evaluate the expression *x*``+``*y*, where *x* is an\n 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__()`` (described below). Note\n that ``__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.__div__(self, other)\nobject.__truediv__(self, other)\n\n The division operator (``/``) is implemented by these methods. The\n ``__truediv__()`` method is used when ``__future__.division`` is in\n effect, otherwise ``__div__()`` is used. If only one of these two\n methods is defined, the object will not support division in the\n alternate context; ``TypeError`` will be raised instead.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rdiv__(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 (``+``, ``-``, ``*``, ``/``, ``%``, ``divmod()``,\n ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``, ``|``) with\n reflected (swapped) operands. These functions are only called if\n the left operand does not support the corresponding operation and\n the operands are of different types. [2] For instance, to evaluate\n the expression *x*``-``*y*, where *y* is an instance of a class\n that has an ``__rsub__()`` method, ``y.__rsub__(x)`` is called if\n ``x.__sub__(y)`` returns *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.__idiv__(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)\n\n Called to implement the built-in functions ``complex()``, ``int()``\n and ``float()``. Should return a value of 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", - 'objects': '\nObjects, values and types\n*************************\n\n*Objects* are Python\'s abstraction for data. All data in a Python\nprogram is represented by objects or by relations between objects. (In\na sense, and in conformance to Von Neumann\'s model of a "stored\nprogram computer," code is also represented by objects.)\n\nEvery object has an identity, a type and a value. An object\'s\n*identity* never changes once it has been created; you may think of it\nas the object\'s address in memory. The \'``is``\' operator compares the\nidentity of two objects; the ``id()`` function returns an integer\nrepresenting its identity (currently implemented as its address). An\nobject\'s *type* is also unchangeable. An object\'s type determines the\noperations that the object supports (e.g., "does it have a length?")\nand also defines the possible values for objects of that type. The\n``type()`` function returns an object\'s type (which is an object\nitself). The *value* of some objects can change. Objects whose value\ncan change are said to be *mutable*; objects whose value is\nunchangeable once they are created are called *immutable*. (The value\nof an immutable container object that contains a reference to a\nmutable object can change when the latter\'s value is changed; however\nthe container is still considered immutable, because the collection of\nobjects it contains cannot be changed. So, immutability is not\nstrictly the same as having an unchangeable value, it is more subtle.)\nAn object\'s mutability is determined by its type; for instance,\nnumbers, strings and tuples are immutable, while dictionaries and\nlists are mutable.\n\nObjects are never explicitly destroyed; however, when they become\nunreachable they may be garbage-collected. An implementation is\nallowed to postpone garbage collection or omit it altogether --- it is\na matter of implementation quality how garbage collection is\nimplemented, as long as no objects are collected that are still\nreachable. (Implementation note: the current implementation uses a\nreference-counting scheme with (optional) delayed detection of\ncyclically linked garbage, which collects most objects as soon as they\nbecome unreachable, but is not guaranteed to collect garbage\ncontaining circular references. See the documentation of the ``gc``\nmodule for information on controlling the collection of cyclic\ngarbage.)\n\nNote that the use of the implementation\'s tracing or debugging\nfacilities may keep objects alive that would normally be collectable.\nAlso note that catching an exception with a \'``try``...``except``\'\nstatement may keep objects alive.\n\nSome objects contain references to "external" resources such as open\nfiles or windows. It is understood that these resources are freed\nwhen the object is garbage-collected, but since garbage collection is\nnot guaranteed to happen, such objects also provide an explicit way to\nrelease the external resource, usually a ``close()`` method. Programs\nare strongly recommended to explicitly close such objects. The\n\'``try``...``finally``\' statement provides a convenient way to do\nthis.\n\nSome objects contain references to other objects; these are called\n*containers*. Examples of containers are tuples, lists and\ndictionaries. The references are part of a container\'s value. In\nmost cases, when we talk about the value of a container, we imply the\nvalues, not the identities of the contained objects; however, when we\ntalk about the mutability of a container, only the identities of the\nimmediately contained objects are implied. So, if an immutable\ncontainer (like a tuple) contains a reference to a mutable object, its\nvalue changes if that mutable object is changed.\n\nTypes affect almost all aspects of object behavior. Even the\nimportance of object identity is affected in some sense: for immutable\ntypes, operations that compute new values may actually return a\nreference to any existing object with the same type and value, while\nfor mutable objects this is not allowed. E.g., after ``a = 1; b =\n1``, ``a`` and ``b`` may or may not refer to the same object with the\nvalue one, depending on the implementation, but after ``c = []; d =\n[]``, ``c`` and ``d`` are guaranteed to refer to two different,\nunique, newly created empty lists. (Note that ``c = d = []`` assigns\nthe same object to both ``c`` and ``d``.)\n', - 'operator-summary': '\nSummary\n*******\n\nThe following table summarizes the operator precedences in Python,\nfrom lowest precedence (least binding) to highest precedence (most\nbinding). Operators in the same box have the same precedence. Unless\nthe syntax is explicitly given, operators are binary. Operators in\nthe same box group left to right (except for comparisons, including\ntests, which all have the same precedence and chain from left to right\n--- see section *Comparisons* --- and exponentiation, which groups\nfrom right to left).\n\n+------------------------------------------------+---------------------------------------+\n| Operator | Description |\n+================================================+=======================================+\n| ``lambda`` | Lambda expression |\n+------------------------------------------------+---------------------------------------+\n| ``or`` | Boolean OR |\n+------------------------------------------------+---------------------------------------+\n| ``and`` | Boolean AND |\n+------------------------------------------------+---------------------------------------+\n| ``not`` *x* | Boolean NOT |\n+------------------------------------------------+---------------------------------------+\n| ``in``, ``not`` ``in`` | Membership tests |\n+------------------------------------------------+---------------------------------------+\n| ``is``, ``is not`` | Identity tests |\n+------------------------------------------------+---------------------------------------+\n| ``<``, ``<=``, ``>``, ``>=``, ``!=``, ``==`` | Comparisons |\n+------------------------------------------------+---------------------------------------+\n| ``|`` | Bitwise OR |\n+------------------------------------------------+---------------------------------------+\n| ``^`` | Bitwise XOR |\n+------------------------------------------------+---------------------------------------+\n| ``&`` | Bitwise AND |\n+------------------------------------------------+---------------------------------------+\n| ``<<``, ``>>`` | Shifts |\n+------------------------------------------------+---------------------------------------+\n| ``+``, ``-`` | Addition and subtraction |\n+------------------------------------------------+---------------------------------------+\n| ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder |\n+------------------------------------------------+---------------------------------------+\n| ``+x``, ``-x`` | Positive, negative |\n+------------------------------------------------+---------------------------------------+\n| ``~x`` | Bitwise not |\n+------------------------------------------------+---------------------------------------+\n| ``**`` | Exponentiation |\n+------------------------------------------------+---------------------------------------+\n| ``x.attribute`` | Attribute reference |\n+------------------------------------------------+---------------------------------------+\n| ``x[index]`` | Subscription |\n+------------------------------------------------+---------------------------------------+\n| ``x[index:index]`` | Slicing |\n+------------------------------------------------+---------------------------------------+\n| ``f(arguments...)`` | Function call |\n+------------------------------------------------+---------------------------------------+\n| ``(expressions...)`` | Binding, tuple display, generator |\n| | expressions |\n+------------------------------------------------+---------------------------------------+\n| ``[expressions...]`` | List display |\n+------------------------------------------------+---------------------------------------+\n| ``{expressions...}`` | Dictionary or set display |\n+------------------------------------------------+---------------------------------------+\n\n-[ Footnotes ]-\n\n[1] While ``abs(x%y) < abs(y)`` is true mathematically, for floats it\n may not be true numerically due to roundoff. For example, and\n assuming a platform on which a Python float is an IEEE 754 double-\n precision number, in order that ``-1e-100 % 1e100`` have the same\n sign as ``1e100``, the computed result is ``-1e-100 + 1e100``,\n which is numerically exactly equal to ``1e100``. Function\n ``fmod()`` in the ``math`` module returns a result whose sign\n matches the sign of the first argument instead, and so returns\n ``-1e-100`` in this case. Which approach is more appropriate\n depends on the application.\n\n[2] If x is very close to an exact integer multiple of y, it\'s\n possible for ``x//y`` to be one larger than ``(x-x%y)//y`` due to\n rounding. In such cases, Python returns the latter result, in\n order to preserve that ``divmod(x,y)[0] * y + x % y`` be very\n close to ``x``.\n\n[3] While comparisons between strings make sense at the byte level,\n they may be counter-intuitive to users. For example, the strings\n ``"\\u00C7"`` and ``"\\u0327\\u0043"`` compare differently, even\n though they both represent the same unicode character (LATIN\n CAPTITAL LETTER C WITH CEDILLA). To compare strings in a human\n recognizable way, compare using ``unicodedata.normalize()``.\n\n[4] The implementation computes this efficiently, without constructing\n lists or sorting.\n\n[5] Earlier versions of Python used lexicographic comparison of the\n sorted (key, value) lists, but this was very expensive for the\n common case of comparing for equality. An even earlier version of\n Python compared dictionaries by identity only, but this caused\n surprises because people expected to be able to test a dictionary\n for emptiness by comparing it to ``{}``.\n', + 'numeric-types': "\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", + 'objects': '\nObjects, values and types\n*************************\n\n*Objects* are Python\'s abstraction for data. All data in a Python\nprogram is represented by objects or by relations between objects. (In\na sense, and in conformance to Von Neumann\'s model of a "stored\nprogram computer," code is also represented by objects.)\n\nEvery object has an identity, a type and a value. An object\'s\n*identity* never changes once it has been created; you may think of it\nas the object\'s address in memory. The \'``is``\' operator compares the\nidentity of two objects; the ``id()`` function returns an integer\nrepresenting its identity (currently implemented as its address). An\nobject\'s *type* is also unchangeable. [1] An object\'s type determines\nthe operations that the object supports (e.g., "does it have a\nlength?") and also defines the possible values for objects of that\ntype. The ``type()`` function returns an object\'s type (which is an\nobject itself). The *value* of some objects can change. Objects\nwhose value can change are said to be *mutable*; objects whose value\nis unchangeable once they are created are called *immutable*. (The\nvalue of an immutable container object that contains a reference to a\nmutable object can change when the latter\'s value is changed; however\nthe container is still considered immutable, because the collection of\nobjects it contains cannot be changed. So, immutability is not\nstrictly the same as having an unchangeable value, it is more subtle.)\nAn object\'s mutability is determined by its type; for instance,\nnumbers, strings and tuples are immutable, while dictionaries and\nlists are mutable.\n\nObjects are never explicitly destroyed; however, when they become\nunreachable they may be garbage-collected. An implementation is\nallowed to postpone garbage collection or omit it altogether --- it is\na matter of implementation quality how garbage collection is\nimplemented, as long as no objects are collected that are still\nreachable. (Implementation note: the current implementation uses a\nreference-counting scheme with (optional) delayed detection of\ncyclically linked garbage, which collects most objects as soon as they\nbecome unreachable, but is not guaranteed to collect garbage\ncontaining circular references. See the documentation of the ``gc``\nmodule for information on controlling the collection of cyclic\ngarbage.)\n\nNote that the use of the implementation\'s tracing or debugging\nfacilities may keep objects alive that would normally be collectable.\nAlso note that catching an exception with a \'``try``...``except``\'\nstatement may keep objects alive.\n\nSome objects contain references to "external" resources such as open\nfiles or windows. It is understood that these resources are freed\nwhen the object is garbage-collected, but since garbage collection is\nnot guaranteed to happen, such objects also provide an explicit way to\nrelease the external resource, usually a ``close()`` method. Programs\nare strongly recommended to explicitly close such objects. The\n\'``try``...``finally``\' statement and the \'``with``\' statement provide\nconvenient ways to do this.\n\nSome objects contain references to other objects; these are called\n*containers*. Examples of containers are tuples, lists and\ndictionaries. The references are part of a container\'s value. In\nmost cases, when we talk about the value of a container, we imply the\nvalues, not the identities of the contained objects; however, when we\ntalk about the mutability of a container, only the identities of the\nimmediately contained objects are implied. So, if an immutable\ncontainer (like a tuple) contains a reference to a mutable object, its\nvalue changes if that mutable object is changed.\n\nTypes affect almost all aspects of object behavior. Even the\nimportance of object identity is affected in some sense: for immutable\ntypes, operations that compute new values may actually return a\nreference to any existing object with the same type and value, while\nfor mutable objects this is not allowed. E.g., after ``a = 1; b =\n1``, ``a`` and ``b`` may or may not refer to the same object with the\nvalue one, depending on the implementation, but after ``c = []; d =\n[]``, ``c`` and ``d`` are guaranteed to refer to two different,\nunique, newly created empty lists. (Note that ``c = d = []`` assigns\nthe same object to both ``c`` and ``d``.)\n', + 'operator-summary': '\nSummary\n*******\n\nThe following table summarizes the operator precedences in Python,\nfrom lowest precedence (least binding) to highest precedence (most\nbinding). Operators in the same box have the same precedence. Unless\nthe syntax is explicitly given, operators are binary. Operators in\nthe same box group left to right (except for comparisons, including\ntests, which all have the same precedence and chain from left to right\n--- see section *Comparisons* --- and exponentiation, which groups\nfrom right to left).\n\n+------------------------------------------------+---------------------------------------+\n| Operator | Description |\n+================================================+=======================================+\n| ``lambda`` | Lambda expression |\n+------------------------------------------------+---------------------------------------+\n| ``or`` | Boolean OR |\n+------------------------------------------------+---------------------------------------+\n| ``and`` | Boolean AND |\n+------------------------------------------------+---------------------------------------+\n| ``not`` *x* | Boolean NOT |\n+------------------------------------------------+---------------------------------------+\n| ``in``, ``not`` ``in`` | Membership tests |\n+------------------------------------------------+---------------------------------------+\n| ``is``, ``is not`` | Identity tests |\n+------------------------------------------------+---------------------------------------+\n| ``<``, ``<=``, ``>``, ``>=``, ``!=``, ``==`` | Comparisons |\n+------------------------------------------------+---------------------------------------+\n| ``|`` | Bitwise OR |\n+------------------------------------------------+---------------------------------------+\n| ``^`` | Bitwise XOR |\n+------------------------------------------------+---------------------------------------+\n| ``&`` | Bitwise AND |\n+------------------------------------------------+---------------------------------------+\n| ``<<``, ``>>`` | Shifts |\n+------------------------------------------------+---------------------------------------+\n| ``+``, ``-`` | Addition and subtraction |\n+------------------------------------------------+---------------------------------------+\n| ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder |\n+------------------------------------------------+---------------------------------------+\n| ``+x``, ``-x`` | Positive, negative |\n+------------------------------------------------+---------------------------------------+\n| ``~x`` | Bitwise not |\n+------------------------------------------------+---------------------------------------+\n| ``**`` | Exponentiation |\n+------------------------------------------------+---------------------------------------+\n| ``x[index]`` | Subscription |\n+------------------------------------------------+---------------------------------------+\n| ``x[index:index]`` | Slicing |\n+------------------------------------------------+---------------------------------------+\n| ``x(arguments...)`` | Call |\n+------------------------------------------------+---------------------------------------+\n| ``x.attribute`` | Attribute reference |\n+------------------------------------------------+---------------------------------------+\n| ``(expressions...)`` | Binding, tuple display, generator |\n| | expressions |\n+------------------------------------------------+---------------------------------------+\n| ``[expressions...]`` | List display |\n+------------------------------------------------+---------------------------------------+\n| ``{expressions...}`` | Dictionary or set display |\n+------------------------------------------------+---------------------------------------+\n\n-[ Footnotes ]-\n\n[1] While ``abs(x%y) < abs(y)`` is true mathematically, for floats it\n may not be true numerically due to roundoff. For example, and\n assuming a platform on which a Python float is an IEEE 754 double-\n precision number, in order that ``-1e-100 % 1e100`` have the same\n sign as ``1e100``, the computed result is ``-1e-100 + 1e100``,\n which is numerically exactly equal to ``1e100``. Function\n ``fmod()`` in the ``math`` module returns a result whose sign\n matches the sign of the first argument instead, and so returns\n ``-1e-100`` in this case. Which approach is more appropriate\n depends on the application.\n\n[2] If x is very close to an exact integer multiple of y, it\'s\n possible for ``x//y`` to be one larger than ``(x-x%y)//y`` due to\n rounding. In such cases, Python returns the latter result, in\n order to preserve that ``divmod(x,y)[0] * y + x % y`` be very\n close to ``x``.\n\n[3] While comparisons between strings make sense at the byte level,\n they may be counter-intuitive to users. For example, the strings\n ``"\\u00C7"`` and ``"\\u0327\\u0043"`` compare differently, even\n though they both represent the same unicode character (LATIN\n CAPTITAL LETTER C WITH CEDILLA). To compare strings in a human\n recognizable way, compare using ``unicodedata.normalize()``.\n\n[4] The implementation computes this efficiently, without constructing\n lists or sorting.\n\n[5] Earlier versions of Python used lexicographic comparison of the\n sorted (key, value) lists, but this was very expensive for the\n common case of comparing for equality. An even earlier version of\n Python compared dictionaries by identity only, but this caused\n surprises because people expected to be able to test a dictionary\n for emptiness by comparing it to ``{}``.\n\n[6] Due to automatic garbage-collection, free lists, and the dynamic\n nature of descriptors, you may notice seemingly unusual behaviour\n in certain uses of the ``is`` operator, like those involving\n comparisons between instance methods, or constants. Check their\n documentation for more info.\n', 'pass': '\nThe ``pass`` statement\n**********************\n\n pass_stmt ::= "pass"\n\n``pass`` is a null operation --- when it is executed, nothing happens.\nIt is useful as a placeholder when a statement is required\nsyntactically, but no code needs to be executed, for example:\n\n def f(arg): pass # a function that does nothing (yet)\n\n class C: pass # a class with no methods (yet)\n', 'power': '\nThe power operator\n******************\n\nThe power operator binds more tightly than unary operators on its\nleft; it binds less tightly than unary operators on its right. The\nsyntax is:\n\n power ::= primary ["**" u_expr]\n\nThus, in an unparenthesized sequence of power and unary operators, the\noperators are evaluated from right to left (this does not constrain\nthe evaluation order for the operands): ``-1**2`` results in ``-1``.\n\nThe power operator has the same semantics as the built-in ``pow()``\nfunction, when called with two arguments: it yields its left argument\nraised to the power of its right argument. The numeric arguments are\nfirst converted to a common type, and the result is of that type.\n\nFor int operands, the result has the same type as the operands unless\nthe second argument is negative; in that case, all arguments are\nconverted to float and a float result is delivered. For example,\n``10**2`` returns ``100``, but ``10**-2`` returns ``0.01``.\n\nRaising ``0.0`` to a negative power results in a\n``ZeroDivisionError``. Raising a negative number to a fractional power\nresults in a ``complex`` number. (In earlier versions it raised a\n``ValueError``.)\n', - 'raise': '\nThe ``raise`` statement\n***********************\n\n raise_stmt ::= "raise" [expression ["from" expression]]\n\nIf no expressions are present, ``raise`` re-raises the last exception\nthat was active in the current scope. If no exception is active in\nthe current scope, a ``TypeError`` exception is raised indicating that\nthis is an error (if running under IDLE, a ``queue.Empty`` exception\nis raised instead).\n\nOtherwise, ``raise`` evaluates the first expression as the exception\nobject. It must be either a subclass or an instance of\n``BaseException``. If it is a class, the exception instance will be\nobtained when needed by instantiating the class with no arguments.\n\nThe *type* of the exception is the exception instance\'s class, the\n*value* is the instance itself.\n\nA traceback object is normally created automatically when an exception\nis raised and attached to it as the ``__traceback__`` attribute, which\nis writable. You can create an exception and set your own traceback in\none step using the ``with_traceback()`` exception method (which\nreturns the same exception instance, with its traceback set to its\nargument), like so:\n\n raise RuntimeError("foo occurred").with_traceback(tracebackobj)\n\nThe "from" clause is used for exception chaining, which is not\ndocumented yet.\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information about handling exceptions is in section\n*The try statement*.\n', + 'raise': '\nThe ``raise`` statement\n***********************\n\n raise_stmt ::= "raise" [expression ["from" expression]]\n\nIf no expressions are present, ``raise`` re-raises the last exception\nthat was active in the current scope. If no exception is active in\nthe current scope, a ``TypeError`` exception is raised indicating that\nthis is an error (if running under IDLE, a ``queue.Empty`` exception\nis raised instead).\n\nOtherwise, ``raise`` evaluates the first expression as the exception\nobject. It must be either a subclass or an instance of\n``BaseException``. If it is a class, the exception instance will be\nobtained when needed by instantiating the class with no arguments.\n\nThe *type* of the exception is the exception instance\'s class, the\n*value* is the instance itself.\n\nA traceback object is normally created automatically when an exception\nis raised and attached to it as the ``__traceback__`` attribute, which\nis writable. You can create an exception and set your own traceback in\none step using the ``with_traceback()`` exception method (which\nreturns the same exception instance, with its traceback set to its\nargument), like so:\n\n raise RuntimeError("foo occurred").with_traceback(tracebackobj)\n\nThe ``from`` clause is used for exception chaining: if given, the\nsecond *expression* must be another exception class or instance, which\nwill then be attached to the raised exception as the ``__cause__``\nattribute (which is writable). If the raised exception is not\nhandled, both exceptions will be printed:\n\n >>> try:\n ... print(1 / 0)\n ... except Exception as exc:\n ... raise RuntimeError("Something bad happened") from exc\n ...\n Traceback (most recent call last):\n File "", line 2, in \n ZeroDivisionError: int division or modulo by zero\n\n The above exception was the direct cause of the following exception:\n\n Traceback (most recent call last):\n File "", line 4, in \n RuntimeError: Something bad happened\n\nA similar mechanism works implicitly if an exception is raised inside\nan exception handler: the previous exception is then attached as the\nnew exception\'s ``__context__`` attribute:\n\n >>> try:\n ... print(1 / 0)\n ... except:\n ... raise RuntimeError("Something bad happened")\n ...\n Traceback (most recent call last):\n File "", line 2, in \n ZeroDivisionError: int division or modulo by zero\n\n During handling of the above exception, another exception occurred:\n\n Traceback (most recent call last):\n File "", line 4, in \n RuntimeError: Something bad happened\n\nAdditional information on exceptions can be found in section\n*Exceptions*, and information about handling exceptions is in section\n*The try statement*.\n', 'return': '\nThe ``return`` statement\n************************\n\n return_stmt ::= "return" [expression_list]\n\n``return`` may only occur syntactically nested in a function\ndefinition, not within a nested class definition.\n\nIf an expression list is present, it is evaluated, else ``None`` is\nsubstituted.\n\n``return`` leaves the current function call with the expression list\n(or ``None``) as return value.\n\nWhen ``return`` passes control out of a ``try`` statement with a\n``finally`` clause, that ``finally`` clause is executed before really\nleaving the function.\n\nIn a generator function, the ``return`` statement is not allowed to\ninclude an **expression_list**. In that context, a bare ``return``\nindicates that the generator is done and will cause ``StopIteration``\nto be raised.\n', 'sequence-types': "\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", '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 equivalent to ``x.__getitem__(i)``. Except\nwhere mentioned, attempts to execute an operation raise an exception\nwhen no appropriate method is defined.\n\nSpecial methods are only guaranteed to work if defined in an object\'s\nclass, not in the object\'s instance dictionary. That explains why\nthis won\'t work:\n\n >>> class C:\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "", line 1, in \n TypeError: object of type \'C\' has no len()\n\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, and are called\n for comparison operators in preference to ``__cmp__()`` below. 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.__cmp__(self, other)\n\n Called by comparison operations if rich comparison (see above) is\n not defined. Should return a negative integer if ``self < other``,\n zero if ``self == other``, a positive integer if ``self > other``.\n If no ``__cmp__()``, ``__eq__()`` or ``__ne__()`` operation is\n defined, class instances are compared by object identity\n ("address"). See also the description of ``__hash__()`` for some\n important notes on creating *hashable* objects which support custom\n comparison operations and are usable as dictionary keys.\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 a ``__cmp__()`` or ``__eq__()`` method\n it should not define a ``__hash__()`` operation either; if it\n defines ``__cmp__()`` or ``__eq__()`` but not ``__hash__()``, its\n instances will not be usable as dictionary keys. If a class\n defines mutable objects and implements a ``__cmp__()`` or\n ``__eq__()`` method, it should not implement ``__hash__()``, since\n the dictionary implementation requires that a key\'s hash value is\n immutable (if the object\'s hash value changes, it will be in the\n wrong hash bucket).\n\n User-defined classes have ``__cmp__()`` and ``__hash__()`` methods\n by default; with them, all objects compare unequal and\n ``x.__hash__()`` returns ``id(x)``.\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 ``__setattr__()``\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\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\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. [1]\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* 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.__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 (``+``, ``-``, ``*``, ``//``, ``%``, ``divmod()``,\n ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``, ``|``). For\n instance, to evaluate the expression *x*``+``*y*, where *x* is an\n 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__()`` (described below). Note\n that ``__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.__div__(self, other)\nobject.__truediv__(self, other)\n\n The division operator (``/``) is implemented by these methods. The\n ``__truediv__()`` method is used when ``__future__.division`` is in\n effect, otherwise ``__div__()`` is used. If only one of these two\n methods is defined, the object will not support division in the\n alternate context; ``TypeError`` will be raised instead.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rdiv__(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 (``+``, ``-``, ``*``, ``/``, ``%``, ``divmod()``,\n ``pow()``, ``**``, ``<<``, ``>>``, ``&``, ``^``, ``|``) with\n reflected (swapped) operands. These functions are only called if\n the left operand does not support the corresponding operation and\n the operands are of different types. [2] For instance, to evaluate\n the expression *x*``-``*y*, where *y* is an instance of a class\n that has an ``__rsub__()`` method, ``y.__rsub__(x)`` is called if\n ``x.__sub__(y)`` returns *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.__idiv__(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)\n\n Called to implement the built-in functions ``complex()``, ``int()``\n and ``float()``. Should return a value of 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-[ Footnotes ]-\n\n[1] 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[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as ``__add__()``) fails the operation is\n not supported, which is why the reflected method is not called.\n', - 'string-methods': '\nString Methods\n**************\n\nString objects support the methods listed below. 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.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.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 values in the\n sequence *seq*. Non-string values in *seq* will be converted to a\n string using their respective ``str()`` value. If there are any\n ``bytes`` objects in *seq*, a ``TypeError`` will be raised. 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\nstr.isnumeric()\n\n Return ``True`` if there are only numeric characters in S,\n ``False`` otherwise. Numeric characters include digit characters,\n and all characters that have the Unicode numeric value property,\n e.g. U+2155, VULGAR FRACTION ONE FIFTH.\n\nstr.isdecimal()\n\n Return ``True`` if there are only decimal characters in S,\n ``False`` otherwise. Decimal characters include digit characters,\n and all characters that that can be used to form decimal-radix\n numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\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', + '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', - 'truth': "\nTruth Value Testing\n*******************\n\nAny object can be tested for truth value, for use in an ``if`` or\n``while`` condition or as operand of the Boolean operations below. The\nfollowing values are considered false:\n\n* ``None``\n\n* ``False``\n\n* zero of any numeric type, for example, ``0``, ``0L``, ``0.0``,\n ``0j``.\n\n* any empty sequence, for example, ``''``, ``()``, ``[]``.\n\n* any empty mapping, for example, ``{}``.\n\n* instances of user-defined classes, if the class defines a\n ``__bool__()`` or ``__len__()`` method, when that method returns the\n integer zero or ``bool`` value ``False``. [1]\n\nAll other values are considered true --- so objects of many types are\nalways true.\n\nOperations and built-in functions that have a Boolean result always\nreturn ``0`` or ``False`` for false and ``1`` or ``True`` for true,\nunless otherwise stated. (Important exception: the Boolean operations\n``or`` and ``and`` always return one of their operands.)\n", + 'truth': "\nTruth Value Testing\n*******************\n\nAny object can be tested for truth value, for use in an ``if`` or\n``while`` condition or as operand of the Boolean operations below. The\nfollowing values are considered false:\n\n* ``None``\n\n* ``False``\n\n* zero of any numeric type, for example, ``0``, ``0.0``, ``0j``.\n\n* any empty sequence, for example, ``''``, ``()``, ``[]``.\n\n* any empty mapping, for example, ``{}``.\n\n* instances of user-defined classes, if the class defines a\n ``__bool__()`` or ``__len__()`` method, when that method returns the\n integer zero or ``bool`` value ``False``. [1]\n\nAll other values are considered true --- so objects of many types are\nalways true.\n\nOperations and built-in functions that have a Boolean result always\nreturn ``0`` or ``False`` for false and ``1`` or ``True`` for true,\nunless otherwise stated. (Important exception: the Boolean operations\n``or`` and ``and`` always return one of their operands.)\n", 'try': '\nThe ``try`` statement\n*********************\n\nThe ``try`` statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression ["as" target]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nThe ``except`` clause(s) specify one or more exception handlers. When\nno exception occurs in the ``try`` clause, no exception handler is\nexecuted. When an exception occurs in the ``try`` suite, a search for\nan exception handler is started. This search inspects the except\nclauses in turn until one is found that matches the exception. An\nexpression-less except clause, if present, must be last; it matches\nany exception. For an except clause with an expression, that\nexpression is evaluated, and the clause matches the exception if the\nresulting object is "compatible" with the exception. An object is\ncompatible with an exception if it is the class or a base class of the\nexception object or a tuple containing an item compatible with the\nexception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire ``try`` statement\nraised the exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified after the ``as`` keyword in that except clause,\nif present, and the except clause\'s suite is executed. All except\nclauses must have an executable block. When the end of this block is\nreached, execution continues normally after the entire try statement.\n(This means that if two nested handlers exist for the same exception,\nand the exception occurs in the try clause of the inner handler, the\nouter handler will not handle the exception.)\n\nWhen an exception has been assigned using ``as target``, it is cleared\nat the end of the except clause. This is as if\n\n except E as N:\n foo\n\nwas translated to\n\n except E as N:\n try:\n foo\n finally:\n 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.).\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\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\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``\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 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 Bytes\n A bytes object is a mutable 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 The extension module ``array`` provides an additional example of\n a mutable sequence type.\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``, ``dbm.gnu``, and ``bsddb``\n provide additional examples of mapping types.\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 Class objects are created by class definitions (see section *Class\n definitions*). A class has a namespace implemented by a dictionary\n object. Class attribute references are translated to lookups in\n this dictionary, e.g., ``C.x`` is translated to\n ``C.__dict__["x"]``. When the attribute name is not found there,\n the attribute search continues in the base classes. The search is\n depth-first, left-to-right in the order of occurrence in the base\n class list.\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_exc_type``, ``f_exc_value``,\n ``f_exc_traceback`` represent the last exception raised in the\n parent frame provided another exception was ever raised in the\n current frame (in all other cases they are None); ``f_lineno``\n is the current line number of the frame --- writing to this from\n within a trace function jumps to the given line (only for the\n bottom-most frame). A debugger can implement a Jump command\n (aka Set Next Statement) by writing to f_lineno.\n\n Traceback objects\n Traceback objects represent a stack trace of an exception. A\n traceback object is created when an exception occurs. When the\n search for an exception handler unwinds the execution stack, at\n each unwound level a traceback object is inserted in front of\n the current traceback. When an exception handler is entered,\n the stack trace is made available to the program. (See section\n *The try statement*.) It is accessible as the third item of the\n tuple returned by ``sys.exc_info()``. When the program contains\n no suitable handler, the stack trace is written (nicely\n formatted) to the standard error stream; if the interpreter is\n interactive, it is also made available to the user as\n ``sys.last_traceback``.\n\n Special read-only attributes: ``tb_next`` is the next level in\n the stack trace (towards the frame where the exception\n occurred), or ``None`` if there is no next level; ``tb_frame``\n points to the execution frame of the current level;\n ``tb_lineno`` gives the line number where the exception\n occurred; ``tb_lasti`` indicates the precise instruction. The\n line number and last instruction in the traceback may differ\n from the line number of its frame object if the exception\n occurred in a ``try`` statement with no matching except clause\n or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices for ``__getitem__()``\n methods. They are also created by the built-in ``slice()``\n function.\n\n Special read-only attributes: ``start`` is the lower bound;\n ``stop`` is the upper bound; ``step`` is the step value; each is\n ``None`` if omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the slice that the slice object\n would describe if applied to a sequence of *length* items.\n It returns a tuple of three integers; respectively these are\n the *start* and *stop* indices and the *step* or stride\n length of the slice. Missing or out-of-bounds indices are\n handled in a manner consistent with regular slices.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n ``staticmethod()`` constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in ``classmethod()`` constructor.\n', + 'types': '\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.), although such additions\nwill often be provided via the standard library instead.\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name ``None``.\n It is used to signify the absence of a value in many situations,\n e.g., it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n ``NotImplemented``. Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the literal ``...`` or the\n built-in name ``Ellipsis``. Its truth value is true.\n\n``numbers.Number``\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n ``numbers.Integral``\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are two types of integers:\n\n Integers (``int``)\n\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans (``bool``)\n These represent the truth values False and True. The two\n objects representing the values False and True are the only\n Boolean objects. The Boolean type is a subtype of the integer\n type, and Boolean values behave like the values 0 and 1,\n respectively, in almost all contexts, the exception being\n that when converted to a string, the strings ``"False"`` or\n ``"True"`` are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers.\n\n ``numbers.Real`` (``float``)\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these is\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n ``numbers.Complex`` (``complex``)\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number ``z`` can be retrieved through the read-only\n attributes ``z.real`` and ``z.imag``.\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function ``len()`` returns the number of\n items of a sequence. When the length of a sequence is *n*, the\n index set contains the numbers 0, 1, ..., *n*-1. Item *i* of\n sequence *a* is selected by ``a[i]``.\n\n Sequences also support slicing: ``a[i:j]`` selects all items with\n index *k* such that *i* ``<=`` *k* ``<`` *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: ``a[i:j:k]`` selects all items of *a* with index *x*\n where ``x = i + n*k``, *n* ``>=`` ``0`` and *i* ``<=`` *x* ``<``\n *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n 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 {\'eggs\', \'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. 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', '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 from literals too; use a ``b`` prefix with normal\nstring syntax: ``b\'xyzzy\'``. To construct byte arrays, use the\n``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.Also, while in previous Python\n versions, byte strings and Unicode strings could be exchanged for\n each other rather freely (barring encoding issues), strings and\n bytes are now completely separate concepts. There\'s no implicit\n en-/decoding if you pass and object of the wrong type. A string\n 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.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.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 values in the\n sequence *seq*. Non-string values in *seq* will be converted to a\n string using their respective ``str()`` value. If there are any\n ``bytes`` objects in *seq*, a ``TypeError`` will be raised. 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\nstr.isnumeric()\n\n Return ``True`` if there are only numeric characters in S,\n ``False`` otherwise. Numeric characters include digit characters,\n and all characters that have the Unicode numeric value property,\n e.g. U+2155, VULGAR FRACTION ONE FIFTH.\n\nstr.isdecimal()\n\n Return ``True`` if there are only decimal characters in S,\n ``False`` otherwise. Decimal characters include digit characters,\n and all characters that that can be used to form decimal-radix\n numbers, e.g. U+0660, ARABIC-INDIC DIGIT ZERO.\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)\n\n This ``bytes`` class method returns a bytes object, decoding the\n given string object. The string must contain two hexadecimal\n digits per byte, spaces are ignored.\n\n Example:\n\n >>> bytes.fromhex(\'f0 f1f2 \')\n b\'\\xf0\\xf1\\xf2\'\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', 'typesseq-mutable': '\nMutable Sequence Types\n**********************\n\nList and bytearray objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object).\n\nNote that while lists allow their items to be of any type, bytearray\nobject "items" are all integers in the range 0 <= x < 256.\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| ``s[i] = x`` | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j] = t`` | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j]`` | same as ``s[i:j] = []`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s[i:j:k] = t`` | the elements of ``s[i:j:k]`` are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``del s[i:j:k]`` | removes the elements of | |\n| | ``s[i:j:k]`` from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.append(x)`` | same as ``s[len(s):len(s)] = | |\n| | [x]`` | |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.extend(x)`` | same as ``s[len(s):len(s)] = x`` | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| ``s.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', 'unary': '\nUnary arithmetic operations\n***************************\n\nAll unary arithmetic (and bitwise) operations have the same priority:\n\n u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n\nThe unary ``-`` (minus) operator yields the negation of its numeric\nargument.\n\nThe unary ``+`` (plus) operator yields its numeric argument unchanged.\n\nThe unary ``~`` (invert) operator yields the bitwise inversion of its\ninteger argument. The bitwise inversion of ``x`` is defined as\n``-(x+1)``. It only applies to integral numbers.\n\nIn all three cases, if the argument does not have the proper type, a\n``TypeError`` exception is raised.\n', 'while': '\nThe ``while`` statement\n***********************\n\nThe ``while`` statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the ``else`` clause, if present, is\nexecuted and the loop terminates.\n\nA ``break`` statement executed in the first suite terminates the loop\nwithout executing the ``else`` clause\'s suite. A ``continue``\nstatement executed in the first suite skips the rest of the suite and\ngoes back to testing the expression.\n', From python-3000-checkins at python.org Sat Oct 4 09:33:07 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Sat, 4 Oct 2008 09:33:07 +0200 (CEST) Subject: [Python-3000-checkins] r66769 - in python/branches/py3k: Doc/library/sys.rst Include/fileobject.h Lib/test/test_sys.py Misc/NEWS Python/bltinmodule.c Python/sysmodule.c Message-ID: <20081004073307.9CC2F1E400F@bag.python.org> Author: martin.v.loewis Date: Fri Oct 3 18:09:28 2008 New Revision: 66769 Log: Issue #3187: Add sys.setfilesystemencoding. Modified: python/branches/py3k/Doc/library/sys.rst python/branches/py3k/Include/fileobject.h python/branches/py3k/Lib/test/test_sys.py python/branches/py3k/Misc/NEWS python/branches/py3k/Python/bltinmodule.c python/branches/py3k/Python/sysmodule.c Modified: python/branches/py3k/Doc/library/sys.rst ============================================================================== --- python/branches/py3k/Doc/library/sys.rst (original) +++ python/branches/py3k/Doc/library/sys.rst Fri Oct 3 18:09:28 2008 @@ -578,6 +578,14 @@ :file:`/usr/include/dlfcn.h` using the :program:`h2py` script. Availability: Unix. +.. function:: setfilesystemencoding(enc) + + Set the encoding used when converting Python strings to file names to *enc*. + By default, Python tries to determine the encoding it should use automatically + on Unix; on Windows, it avoids such conversion completely. This function can + be used when Python's determination of the encoding needs to be overwritten, + e.g. when not all file names on disk can be decoded using the encoding that + Python had chosen. .. function:: setprofile(profilefunc) Modified: python/branches/py3k/Include/fileobject.h ============================================================================== --- python/branches/py3k/Include/fileobject.h (original) +++ python/branches/py3k/Include/fileobject.h Fri Oct 3 18:09:28 2008 @@ -20,7 +20,8 @@ If non-NULL, this is different than the default encoding for strings */ PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding; -PyAPI_DATA(const int) Py_HasFileSystemDefaultEncoding; +PyAPI_DATA(int) Py_HasFileSystemDefaultEncoding; +PyAPI_FUNC(int) _Py_SetFileSystemEncoding(PyObject *); /* Internal API Modified: python/branches/py3k/Lib/test/test_sys.py ============================================================================== --- python/branches/py3k/Lib/test/test_sys.py (original) +++ python/branches/py3k/Lib/test/test_sys.py Fri Oct 3 18:09:28 2008 @@ -658,6 +658,11 @@ # sys.flags check(sys.flags, size(vh) + self.P * len(sys.flags)) + def test_setfilesystemencoding(self): + old = sys.getfilesystemencoding() + sys.setfilesystemencoding("iso-8859-1") + self.assertEqual(sys.getfilesystemencoding(), "iso-8859-1") + sys.setfilesystemencoding(old) def test_main(): test.support.run_unittest(SysModuleTest, SizeofTest) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Oct 3 18:09:28 2008 @@ -25,6 +25,8 @@ Library ------- +- Issue #3187: Add sys.setfilesystemencoding. + - Issue #3187: Better support for "undecodable" filenames. Code by Victor Stinner, with small tweaks by GvR. Modified: python/branches/py3k/Python/bltinmodule.c ============================================================================== --- python/branches/py3k/Python/bltinmodule.c (original) +++ python/branches/py3k/Python/bltinmodule.c Fri Oct 3 18:09:28 2008 @@ -17,15 +17,34 @@ */ #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) const char *Py_FileSystemDefaultEncoding = "mbcs"; -const int Py_HasFileSystemDefaultEncoding = 1; +int Py_HasFileSystemDefaultEncoding = 1; #elif defined(__APPLE__) const char *Py_FileSystemDefaultEncoding = "utf-8"; -const int Py_HasFileSystemDefaultEncoding = 1; +int Py_HasFileSystemDefaultEncoding = 1; #else const char *Py_FileSystemDefaultEncoding = NULL; /* use default */ -const int Py_HasFileSystemDefaultEncoding = 0; +int Py_HasFileSystemDefaultEncoding = 0; #endif +int +_Py_SetFileSystemEncoding(PyObject *s) +{ + PyObject *defenc; + if (!PyUnicode_Check(s)) { + PyErr_BadInternalCall(); + return -1; + } + defenc = _PyUnicode_AsDefaultEncodedString(s, NULL); + if (!defenc) + return -1; + if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) + /* A file system encoding was set at run-time */ + free((char*)Py_FileSystemDefaultEncoding); + Py_FileSystemDefaultEncoding = strdup(PyBytes_AsString(defenc)); + Py_HasFileSystemDefaultEncoding = 0; + return 0; +} + static PyObject * builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds) { Modified: python/branches/py3k/Python/sysmodule.c ============================================================================== --- python/branches/py3k/Python/sysmodule.c (original) +++ python/branches/py3k/Python/sysmodule.c Fri Oct 3 18:09:28 2008 @@ -216,7 +216,24 @@ operating system filenames." ); +static PyObject * +sys_setfilesystemencoding(PyObject *self, PyObject *args) +{ + PyObject *new_encoding; + if (!PyArg_ParseTuple(args, "U:setfilesystemencoding", &new_encoding)) + return NULL; + if (_Py_SetFileSystemEncoding(new_encoding)) + return NULL; + Py_INCREF(Py_None); + return Py_None; +} +PyDoc_STRVAR(setfilesystemencoding_doc, +"setfilesystemencoding(string) -> None\n\ +\n\ +Set the encoding used to convert Unicode filenames in\n\ +operating system filenames." +); static PyObject * sys_intern(PyObject *self, PyObject *args) @@ -872,6 +889,8 @@ #endif {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS, setdefaultencoding_doc}, + {"setfilesystemencoding", sys_setfilesystemencoding, METH_VARARGS, + setfilesystemencoding_doc}, {"setcheckinterval", sys_setcheckinterval, METH_VARARGS, setcheckinterval_doc}, {"getcheckinterval", sys_getcheckinterval, METH_NOARGS, From python-3000-checkins at python.org Sat Oct 4 09:33:12 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Sat, 4 Oct 2008 09:33:12 +0200 (CEST) Subject: [Python-3000-checkins] r66770 - python/branches/py3k Message-ID: <20081004073312.672301E4016@bag.python.org> Author: hirokazu.yamamoto Date: Fri Oct 3 18:16:20 2008 New Revision: 66770 Log: Blocked revisions 66768 via svnmerge ........ r66768 | hirokazu.yamamoto | 2008-10-04 01:07:28 +0900 | 1 line Follows to python's version change (VC6) ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Oct 4 09:33:23 2008 From: python-3000-checkins at python.org (guido.van.rossum) Date: Sat, 4 Oct 2008 09:33:23 +0200 (CEST) Subject: [Python-3000-checkins] r66773 - python/branches/py3k/Lib/fnmatch.py Message-ID: <20081004073323.D84F21E4035@bag.python.org> Author: guido.van.rossum Date: Fri Oct 3 18:38:30 2008 New Revision: 66773 Log: Change fnmatch.py to use separate caches for str and bytes keys. This is necessary to pass the tests with -bb. Modified: python/branches/py3k/Lib/fnmatch.py Modified: python/branches/py3k/Lib/fnmatch.py ============================================================================== --- python/branches/py3k/Lib/fnmatch.py (original) +++ python/branches/py3k/Lib/fnmatch.py Fri Oct 3 18:38:30 2008 @@ -14,7 +14,8 @@ __all__ = ["filter", "fnmatch","fnmatchcase","translate"] -_cache = {} +_cache = {} # Maps text patterns to compiled regexen. +_cacheb = {} # Ditto for bytes patterns. def fnmatch(name, pat): """Test whether FILENAME matches PATTERN. @@ -38,7 +39,8 @@ return fnmatchcase(name, pat) def _compile_pattern(pat): - regex = _cache.get(pat) + cache = _cacheb if isinstance(pat, bytes) else _cache + regex = cache.get(pat) if regex is None: if isinstance(pat, bytes): pat_str = str(pat, 'ISO-8859-1') @@ -46,7 +48,7 @@ res = bytes(res_str, 'ISO-8859-1') else: res = translate(pat) - _cache[pat] = regex = re.compile(res) + cache[pat] = regex = re.compile(res) return regex.match def filter(names, pat): From python-3000-checkins at python.org Sat Oct 4 09:33:31 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 4 Oct 2008 09:33:31 +0200 (CEST) Subject: [Python-3000-checkins] r66777 - in python/branches/py3k: Lib/ntpath.py Lib/test/test_ntpath.py Modules/posixmodule.c Message-ID: <20081004073331.F409C1E4012@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 3 20:38:26 2008 New Revision: 66777 Log: Second part of #3187, for windows: os and os.path functions now accept both unicode and byte strings for file names. Reviewed by Guido. Modified: python/branches/py3k/Lib/ntpath.py python/branches/py3k/Lib/test/test_ntpath.py python/branches/py3k/Modules/posixmodule.c Modified: python/branches/py3k/Lib/ntpath.py ============================================================================== --- python/branches/py3k/Lib/ntpath.py (original) +++ python/branches/py3k/Lib/ntpath.py Fri Oct 3 20:38:26 2008 @@ -19,6 +19,7 @@ "extsep","devnull","realpath","supports_unicode_filenames","relpath"] # strings representing various path-related bits and pieces +# These are primarily for export; internally, they are hardcoded. curdir = '.' pardir = '..' extsep = '.' @@ -33,6 +34,36 @@ altsep = '/' devnull = 'nul' +def _get_sep(path): + if isinstance(path, bytes): + return b'\\' + else: + return '\\' + +def _get_altsep(path): + if isinstance(path, bytes): + return b'/' + else: + return '/' + +def _get_bothseps(path): + if isinstance(path, bytes): + return b'\\/' + else: + return '\\/' + +def _get_dot(path): + if isinstance(path, bytes): + return b'.' + else: + return '.' + +def _get_colon(path): + if isinstance(path, bytes): + return b':' + else: + return ':' + # Normalize the case of a pathname and map slashes to backslashes. # Other normalizations (such as optimizing '../' away) are not done # (this is done by normpath). @@ -41,7 +72,7 @@ """Normalize case of pathname. Makes all characters lowercase and all slashes into backslashes.""" - return s.replace("/", "\\").lower() + return s.replace(_get_altsep(s), _get_sep(s)).lower() # Return whether a path is absolute. @@ -53,7 +84,7 @@ def isabs(s): """Test whether a path is absolute""" s = splitdrive(s)[1] - return s != '' and s[:1] in '/\\' + return len(s) > 0 and s[:1] in _get_bothseps(s) # Join two (or more) paths. @@ -62,10 +93,13 @@ """Join two or more pathname components, inserting "\\" as needed. If any component is an absolute path, all previous path components will be discarded.""" + sep = _get_sep(a) + seps = _get_bothseps(a) + colon = _get_colon(a) path = a for b in p: b_wins = 0 # set to 1 iff b makes path irrelevant - if path == "": + if not path: b_wins = 1 elif isabs(b): @@ -77,13 +111,13 @@ # 3. join('c:/a', '/b') == '/b' # 4. join('c:', 'd:/') = 'd:/' # 5. join('c:/', 'd:/') = 'd:/' - if path[1:2] != ":" or b[1:2] == ":": + if path[1:2] != colon or b[1:2] == colon: # Path doesn't start with a drive letter, or cases 4 and 5. b_wins = 1 # Else path has a drive letter, and b doesn't but is absolute. elif len(path) > 3 or (len(path) == 3 and - path[-1] not in "/\\"): + path[-1:] not in seps): # case 3 b_wins = 1 @@ -92,24 +126,24 @@ else: # Join, and ensure there's a separator. assert len(path) > 0 - if path[-1] in "/\\": - if b and b[0] in "/\\": + if path[-1:] in seps: + if b and b[:1] in seps: path += b[1:] else: path += b - elif path[-1] == ":": + elif path[-1:] == colon: path += b elif b: - if b[0] in "/\\": + if b[:1] in seps: path += b else: - path += "\\" + b + path += sep + b else: # path is not empty and does not end with a backslash, # but b is empty; since, e.g., split('a/') produces # ('a', ''), it's best if join() adds a backslash in # this case. - path += '\\' + path += sep return path @@ -120,9 +154,9 @@ def splitdrive(p): """Split a pathname into drive and path specifiers. Returns a 2-tuple "(drive,path)"; either part may be empty""" - if p[1:2] == ':': + if p[1:2] == _get_colon(p): return p[0:2], p[2:] - return '', p + return p[:0], p # Parse UNC paths @@ -134,24 +168,25 @@ using backslashes). unc+rest is always the input path. Paths containing drive letters never have an UNC part. """ - if p[1:2] == ':': - return '', p # Drive letter present + sep = _get_sep(p) + if not p[1:2]: + return p[:0], p # Drive letter present firstTwo = p[0:2] - if firstTwo == '//' or firstTwo == '\\\\': + if normcase(firstTwo) == sep + sep: # is a UNC path: # vvvvvvvvvvvvvvvvvvvv equivalent to drive letter # \\machine\mountpoint\directories... # directory ^^^^^^^^^^^^^^^ normp = normcase(p) - index = normp.find('\\', 2) + index = normp.find(sep, 2) if index == -1: ##raise RuntimeError, 'illegal UNC path: "' + p + '"' - return ("", p) - index = normp.find('\\', index + 1) + return (p[:0], p) + index = normp.find(sep, index + 1) if index == -1: index = len(p) return p[:index], p[index:] - return '', p + return p[:0], p # Split a path in head (everything up to the last '/') and tail (the @@ -165,15 +200,16 @@ Return tuple (head, tail) where tail is everything after the final slash. Either part may be empty.""" + seps = _get_bothseps(p) d, p = splitdrive(p) # set i to index beyond p's last slash i = len(p) - while i and p[i-1] not in '/\\': + while i and p[i-1] not in seps: i = i - 1 head, tail = p[:i], p[i:] # now tail has no slashes # remove trailing slashes from head, unless it's all slashes head2 = head - while head2 and head2[-1] in '/\\': + while head2 and head2[-1:] in seps: head2 = head2[:-1] head = head2 or head return d + head, tail @@ -185,7 +221,8 @@ # It is always true that root + ext == p. def splitext(p): - return genericpath._splitext(p, sep, altsep, extsep) + return genericpath._splitext(p, _get_sep(p), _get_altsep(p), + _get_dot(p)) splitext.__doc__ = genericpath._splitext.__doc__ @@ -220,10 +257,11 @@ def ismount(path): """Test whether a path is a mount point (defined as root of drive)""" unc, rest = splitunc(path) + seps = _get_bothseps(p) if unc: - return rest in ("", "/", "\\") + return rest in p[:0] + seps p = splitdrive(path)[1] - return len(p) == 1 and p[0] in '/\\' + return len(p) == 1 and p[0] in seps # Expand paths beginning with '~' or '~user'. @@ -239,10 +277,14 @@ """Expand ~ and ~user constructs. If user or $HOME is unknown, do nothing.""" - if path[:1] != '~': + if isinstance(path, bytes): + tilde = b'~' + else: + tilde = '~' + if not path.startswith(tilde): return path i, n = 1, len(path) - while i < n and path[i] not in '/\\': + while i < n and path[i] not in _get_bothseps(path): i = i + 1 if 'HOME' in os.environ: @@ -258,6 +300,9 @@ drive = '' userhome = join(drive, os.environ['HOMEPATH']) + if isinstance(path, bytes): + userhome = userhome.encode(sys.getfilesystemencoding()) + if i != 1: #~user userhome = join(dirname(userhome), path[1:i]) @@ -281,72 +326,104 @@ """Expand shell variables of the forms $var, ${var} and %var%. Unknown variables are left unchanged.""" - if '$' not in path and '%' not in path: - return path - import string - varchars = string.ascii_letters + string.digits + '_-' - res = '' + if isinstance(path, bytes): + if ord('$') not in path and ord('%') not in path: + return path + import string + varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii') + else: + if '$' not in path and '%' not in path: + return path + import string + varchars = string.ascii_letters + string.digits + '_-' + res = path[:0] index = 0 pathlen = len(path) while index < pathlen: - c = path[index] - if c == '\'': # no expansion within single quotes + c = path[index:index+1] + if c in ('\'', b'\''): # no expansion within single quotes path = path[index + 1:] pathlen = len(path) try: - index = path.index('\'') - res = res + '\'' + path[:index + 1] + index = path.index(c) + res = res + c + path[:index + 1] except ValueError: res = res + path index = pathlen - 1 - elif c == '%': # variable or '%' - if path[index + 1:index + 2] == '%': + elif c in ('%', b'%'): # variable or '%' + if isinstance(path, bytes): + percent = b'%' + else: + percent = '%' + if path[index + 1:index + 2] == percent: res = res + c index = index + 1 else: path = path[index+1:] pathlen = len(path) try: - index = path.index('%') + index = path.index(percent) except ValueError: - res = res + '%' + path + res = res + percent + path index = pathlen - 1 else: var = path[:index] + if isinstance(path, bytes): + var = var.decode('ascii') if var in os.environ: - res = res + os.environ[var] + value = os.environ[var] else: - res = res + '%' + var + '%' - elif c == '$': # variable or '$$' + value = '%' + var + '%' + if isinstance(path, bytes): + value = value.encode('ascii') + res = res + value + elif c in ('$', b'$'): # variable or '$$' if path[index + 1:index + 2] == '$': res = res + c index = index + 1 - elif path[index + 1:index + 2] == '{': + elif path[index + 1:index + 2] in ('{', b'{'): path = path[index+2:] pathlen = len(path) try: - index = path.index('}') + if isinstance(path, bytes): + index = path.index(b'}') + else: + index = path.index('}') var = path[:index] + if isinstance(path, bytes): + var = var.decode('ascii') if var in os.environ: - res = res + os.environ[var] + value = os.environ[var] else: - res = res + '${' + var + '}' + value = '${' + var + '}' + if isinstance(path, bytes): + value = value.encode('ascii') + res = res + value except ValueError: - res = res + '${' + path + if isinstance(path, bytes): + res = res + b'${' + path + else: + res = res + '${' + path index = pathlen - 1 else: var = '' index = index + 1 c = path[index:index + 1] - while c != '' and c in varchars: - var = var + c + while c and c in varchars: + if isinstance(path, bytes): + var = var + c.decode('ascii') + else: + var = var + c index = index + 1 c = path[index:index + 1] if var in os.environ: - res = res + os.environ[var] + value = os.environ[var] else: - res = res + '$' + var - if c != '': + value = '$' + var + if isinstance(path, bytes): + value = value.encode('ascii') + res = res + value + if c: index = index - 1 else: res = res + c @@ -360,7 +437,8 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" - path = path.replace("/", "\\") + sep = _get_sep(path) + path = path.replace(_get_altsep(path), sep) prefix, path = splitdrive(path) # We need to be careful here. If the prefix is empty, and the path starts # with a backslash, it could either be an absolute path on the current @@ -371,20 +449,20 @@ # letter. This means that the invalid filename \\\a\b is preserved # unchanged, where a\\\b is normalised to a\b. It's not clear that there # is any better behaviour for such edge cases. - if prefix == '': + if not prefix: # No drive letter - preserve initial backslashes - while path[:1] == "\\": - prefix = prefix + "\\" + while path[:1] == sep: + prefix = prefix + sep path = path[1:] else: # We have a drive letter - collapse initial backslashes - if path.startswith("\\"): - prefix = prefix + "\\" - path = path.lstrip("\\") - comps = path.split("\\") + if path.startswith(sep): + prefix = prefix + sep + path = path.lstrip(sep) + comps = path.split(sep) i = 0 while i < len(comps): - if comps[i] in ('.', ''): + if comps[i] in ('.', '', b'.', b''): del comps[i] elif comps[i] == '..': if i > 0 and comps[i-1] != '..': @@ -394,12 +472,20 @@ del comps[i] else: i += 1 + elif comps[i] == b'..': + if i > 0 and comps[i-1] != b'..': + del comps[i-1:i+1] + i -= 1 + elif i == 0 and prefix.endswith(b"\\"): + del comps[i] + else: + i += 1 else: i += 1 # If the path is now empty, substitute '.' if not prefix and not comps: - comps.append('.') - return prefix + "\\".join(comps) + comps.append(_get_dot(path)) + return prefix + sep.join(comps) # Return an absolute path. @@ -410,7 +496,11 @@ def abspath(path): """Return the absolute version of a path.""" if not isabs(path): - path = join(os.getcwd(), path) + if isinstance(path, bytes): + cwd = os.getcwdb() + else: + cwd = os.getcwd() + path = join(cwd, path) return normpath(path) else: # use native Windows method on Windows @@ -434,6 +524,10 @@ def relpath(path, start=curdir): """Return a relative version of a path""" + sep = _get_sep(path) + + if start is curdir: + start = _get_dot(path) if not path: raise ValueError("no path specified") @@ -455,7 +549,11 @@ else: i += 1 + if isinstance(path, bytes): + pardir = b'..' + else: + pardir = '..' rel_list = [pardir] * (len(start_list)-i) + path_list[i:] if not rel_list: - return curdir + return _get_dot(path) return join(*rel_list) Modified: python/branches/py3k/Lib/test/test_ntpath.py ============================================================================== --- python/branches/py3k/Lib/test/test_ntpath.py (original) +++ python/branches/py3k/Lib/test/test_ntpath.py Fri Oct 3 20:38:26 2008 @@ -12,6 +12,23 @@ raise TestFailed("%s should return: %s but returned: %s" \ %(str(fn), str(wantResult), str(gotResult))) + # then with bytes + fn = fn.replace("('", "(b'") + fn = fn.replace('("', '(b"') + fn = fn.replace("['", "[b'") + fn = fn.replace('["', '[b"') + fn = fn.replace(", '", ", b'") + fn = fn.replace(', "', ', b"') + gotResult = eval(fn) + if isinstance(wantResult, str): + wantResult = wantResult.encode('ascii') + elif isinstance(wantResult, tuple): + wantResult = tuple(r.encode('ascii') for r in wantResult) + + gotResult = eval(fn) + if wantResult != gotResult: + raise TestFailed("%s should return: %s but returned: %s" \ + %(str(fn), str(wantResult), repr(gotResult))) class TestNtpath(unittest.TestCase): def test_splitext(self): Modified: python/branches/py3k/Modules/posixmodule.c ============================================================================== --- python/branches/py3k/Modules/posixmodule.c (original) +++ python/branches/py3k/Modules/posixmodule.c Fri Oct 3 20:38:26 2008 @@ -1651,7 +1651,7 @@ posix_chdir(PyObject *self, PyObject *args) { #ifdef MS_WINDOWS - return win32_1str(args, "chdir", "s:chdir", win32_chdir, "U:chdir", win32_wchdir); + return win32_1str(args, "chdir", "y:chdir", win32_chdir, "U:chdir", win32_wchdir); #elif defined(PYOS_OS2) && defined(PYCC_GCC) return posix_1str(args, "et:chdir", _chdir2); #elif defined(__VMS) @@ -2586,7 +2586,7 @@ posix_rmdir(PyObject *self, PyObject *args) { #ifdef MS_WINDOWS - return win32_1str(args, "rmdir", "s:rmdir", RemoveDirectoryA, "U:rmdir", RemoveDirectoryW); + return win32_1str(args, "rmdir", "y:rmdir", RemoveDirectoryA, "U:rmdir", RemoveDirectoryW); #else return posix_1str(args, "et:rmdir", rmdir); #endif @@ -2667,7 +2667,7 @@ posix_unlink(PyObject *self, PyObject *args) { #ifdef MS_WINDOWS - return win32_1str(args, "remove", "s:remove", DeleteFileA, "U:remove", DeleteFileW); + return win32_1str(args, "remove", "y:remove", DeleteFileA, "U:remove", DeleteFileW); #else return posix_1str(args, "et:remove", unlink); #endif From python-3000-checkins at python.org Sat Oct 4 09:33:33 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 4 Oct 2008 09:33:33 +0200 (CEST) Subject: [Python-3000-checkins] r66778 - python/branches/py3k/Lib/test/test_unicode_file.py Message-ID: <20081004073333.A6E061E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 3 21:34:30 2008 New Revision: 66778 Log: Make the test more robust in face of remaining files. Modified: python/branches/py3k/Lib/test/test_unicode_file.py Modified: python/branches/py3k/Lib/test/test_unicode_file.py ============================================================================== --- python/branches/py3k/Lib/test/test_unicode_file.py (original) +++ python/branches/py3k/Lib/test/test_unicode_file.py Fri Oct 3 21:34:30 2008 @@ -5,7 +5,7 @@ import unicodedata import unittest -from test.support import run_unittest, TestSkipped, TESTFN_UNICODE +from test.support import run_unittest, TestSkipped, TESTFN_UNICODE, rmtree from test.support import TESTFN_ENCODING, TESTFN_UNICODE_UNENCODEABLE try: TESTFN_UNICODE.encode(TESTFN_ENCODING) @@ -92,7 +92,7 @@ def _do_directory(self, make_name, chdir_name, encoded): cwd = os.getcwdb() if os.path.isdir(make_name): - os.rmdir(make_name) + rmtree(make_name) os.mkdir(make_name) try: os.chdir(chdir_name) From python-3000-checkins at python.org Sat Oct 4 09:33:35 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 4 Oct 2008 09:33:35 +0200 (CEST) Subject: [Python-3000-checkins] r66779 - python/branches/py3k/Lib/ntpath.py Message-ID: <20081004073335.E14801E401D@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 3 22:32:33 2008 New Revision: 66779 Log: Issue3187 again: test_ntpath failed when run with the -bb option (BytesWarning: Comparison between bytes and string) Modified: python/branches/py3k/Lib/ntpath.py Modified: python/branches/py3k/Lib/ntpath.py ============================================================================== --- python/branches/py3k/Lib/ntpath.py (original) +++ python/branches/py3k/Lib/ntpath.py Fri Oct 3 22:32:33 2008 @@ -331,17 +331,25 @@ return path import string varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii') + quote = b'\'' + percent = b'%' + brace = b'{' + dollar = b'$' else: if '$' not in path and '%' not in path: return path import string varchars = string.ascii_letters + string.digits + '_-' + quote = '\'' + percent = '%' + brace = '{' + dollar = '$' res = path[:0] index = 0 pathlen = len(path) while index < pathlen: c = path[index:index+1] - if c in ('\'', b'\''): # no expansion within single quotes + if c == quote: # no expansion within single quotes path = path[index + 1:] pathlen = len(path) try: @@ -350,11 +358,7 @@ except ValueError: res = res + path index = pathlen - 1 - elif c in ('%', b'%'): # variable or '%' - if isinstance(path, bytes): - percent = b'%' - else: - percent = '%' + elif c == percent: # variable or '%' if path[index + 1:index + 2] == percent: res = res + c index = index + 1 @@ -377,11 +381,11 @@ if isinstance(path, bytes): value = value.encode('ascii') res = res + value - elif c in ('$', b'$'): # variable or '$$' - if path[index + 1:index + 2] == '$': + elif c == dollar: # variable or '$$' + if path[index + 1:index + 2] == dollar: res = res + c index = index + 1 - elif path[index + 1:index + 2] in ('{', b'{'): + elif path[index + 1:index + 2] == brace: path = path[index+2:] pathlen = len(path) try: @@ -438,6 +442,7 @@ def normpath(path): """Normalize path, eliminating double slashes, etc.""" sep = _get_sep(path) + dotdot = _get_dot(path) * 2 path = path.replace(_get_altsep(path), sep) prefix, path = splitdrive(path) # We need to be careful here. If the prefix is empty, and the path starts @@ -462,21 +467,13 @@ comps = path.split(sep) i = 0 while i < len(comps): - if comps[i] in ('.', '', b'.', b''): + if not comps[i] or comps[i] == _get_dot(path): del comps[i] - elif comps[i] == '..': - if i > 0 and comps[i-1] != '..': - del comps[i-1:i+1] - i -= 1 - elif i == 0 and prefix.endswith("\\"): - del comps[i] - else: - i += 1 - elif comps[i] == b'..': - if i > 0 and comps[i-1] != b'..': + elif comps[i] == dotdot: + if i > 0 and comps[i-1] != dotdot: del comps[i-1:i+1] i -= 1 - elif i == 0 and prefix.endswith(b"\\"): + elif i == 0 and prefix.endswith(_get_sep(path)): del comps[i] else: i += 1 From python-3000-checkins at python.org Sat Oct 4 09:33:38 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 4 Oct 2008 09:33:38 +0200 (CEST) Subject: [Python-3000-checkins] r66780 - python/branches/py3k Message-ID: <20081004073338.D09C21E403F@bag.python.org> Author: benjamin.peterson Date: Fri Oct 3 23:35:48 2008 New Revision: 66780 Log: Blocked revisions 66714,66721,66763-66765 via svnmerge ........ r66714 | barry.warsaw | 2008-10-01 16:46:40 -0500 (Wed, 01 Oct 2008) | 2 lines Bumping to 2.6 final. ........ r66721 | barry.warsaw | 2008-10-01 22:33:51 -0500 (Wed, 01 Oct 2008) | 1 line Bump to 2.7a0 ........ r66763 | neal.norwitz | 2008-10-02 23:13:08 -0500 (Thu, 02 Oct 2008) | 1 line Update the version to 2.7. Hopefully this fixes the test_distutils failure ........ r66764 | martin.v.loewis | 2008-10-03 03:59:41 -0500 (Fri, 03 Oct 2008) | 2 lines Bump version to 2.7. Regenerate. ........ r66765 | martin.v.loewis | 2008-10-03 05:59:55 -0500 (Fri, 03 Oct 2008) | 1 line Update version number to 2.7. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Oct 4 09:33:46 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Sat, 4 Oct 2008 09:33:46 +0200 (CEST) Subject: [Python-3000-checkins] r66781 - in python/branches/py3k/Lib: macpath.py test/test_macpath.py Message-ID: <20081004073346.828091E4006@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 3 23:57:20 2008 New Revision: 66781 Log: Issue3187 for Macintosh platform: macpath.py now accepts both unicode string and bytes as file names. Also add more tests for these functions. Reviewed by Benjamin. Modified: python/branches/py3k/Lib/macpath.py python/branches/py3k/Lib/test/test_macpath.py Modified: python/branches/py3k/Lib/macpath.py ============================================================================== --- python/branches/py3k/Lib/macpath.py (original) +++ python/branches/py3k/Lib/macpath.py Fri Oct 3 23:57:20 2008 @@ -13,6 +13,7 @@ "devnull","realpath","supports_unicode_filenames"] # strings representing various path-related bits and pieces +# These are primarily for export; internally, they are hardcoded. curdir = ':' pardir = '::' extsep = '.' @@ -22,6 +23,12 @@ altsep = None devnull = 'Dev:Null' +def _get_colon(path): + if isinstance(path, bytes): + return b':' + else: + return ':' + # Normalize the case of a pathname. Dummy in Posix, but .lower() here. def normcase(path): @@ -35,21 +42,23 @@ Anything else is absolute (the string up to the first colon is the volume name).""" - return ':' in s and s[0] != ':' + colon = _get_colon(s) + return colon in s and s[:1] != colon def join(s, *p): + colon = _get_colon(s) path = s for t in p: if (not s) or isabs(t): path = t continue - if t[:1] == ':': + if t[:1] == colon: t = t[1:] - if ':' not in path: - path = ':' + path - if path[-1:] != ':': - path = path + ':' + if colon not in path: + path = colon + path + if path[-1:] != colon: + path = path + colon path = path + t return path @@ -59,18 +68,22 @@ bit, and the basename (the filename, without colons, in that directory). The result (s, t) is such that join(s, t) yields the original argument.""" - if ':' not in s: return '', s - colon = 0 + colon = _get_colon(s) + if colon not in s: return s[:0], s + col = 0 for i in range(len(s)): - if s[i] == ':': colon = i + 1 - path, file = s[:colon-1], s[colon:] - if path and not ':' in path: - path = path + ':' + if s[i:i+1] == colon: col = i + 1 + path, file = s[:col-1], s[col:] + if path and not colon in path: + path = path + colon return path, file def splitext(p): - return genericpath._splitext(p, sep, altsep, extsep) + if isinstance(p, bytes): + return genericpath._splitext(p, b':', altsep, b'.') + else: + return genericpath._splitext(p, sep, altsep, extsep) splitext.__doc__ = genericpath._splitext.__doc__ def splitdrive(p): @@ -80,7 +93,7 @@ syntactic and semantic oddities as DOS drive letters, such as there being a separate current directory per drive).""" - return '', p + return p[:0], p # Short interfaces to split() @@ -92,7 +105,7 @@ if not isabs(s): return False components = split(s) - return len(components) == 2 and components[1] == '' + return len(components) == 2 and not components[1] def islink(s): """Return true if the pathname refers to a symbolic link.""" @@ -131,13 +144,15 @@ """Normalize a pathname. Will return the same result for equivalent paths.""" - if ":" not in s: - return ":"+s + colon = _get_colon(s) + + if colon not in s: + return colon + s - comps = s.split(":") + comps = s.split(colon) i = 1 while i < len(comps)-1: - if comps[i] == "" and comps[i-1] != "": + if not comps[i] and comps[i-1]: if i > 1: del comps[i-1:i+1] i = i - 1 @@ -147,10 +162,10 @@ else: i = i + 1 - s = ":".join(comps) + s = colon.join(comps) # remove trailing ":" except for ":" and "Volume:" - if s[-1] == ":" and len(comps) > 2 and s != ":"*len(s): + if s[-1:] == colon and len(comps) > 2 and s != colon*len(s): s = s[:-1] return s @@ -169,8 +184,9 @@ return path if not path: return path - components = path.split(':') - path = components[0] + ':' + colon = _get_colon(path) + components = path.split(colon) + path = components[0] + colon for c in components[1:]: path = join(path, c) path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname() Modified: python/branches/py3k/Lib/test/test_macpath.py ============================================================================== --- python/branches/py3k/Lib/test/test_macpath.py (original) +++ python/branches/py3k/Lib/test/test_macpath.py Fri Oct 3 23:57:20 2008 @@ -18,6 +18,14 @@ self.failIf(isabs(":foo:bar")) self.failIf(isabs(":foo:bar:")) + self.assert_(isabs(b"xx:yy")) + self.assert_(isabs(b"xx:yy:")) + self.assert_(isabs(b"xx:")) + self.failIf(isabs(b"foo")) + self.failIf(isabs(b":foo")) + self.failIf(isabs(b":foo:bar")) + self.failIf(isabs(b":foo:bar:")) + def test_commonprefix(self): commonprefix = macpath.commonprefix @@ -28,6 +36,13 @@ self.assert_(commonprefix([":home:swen:spam", ":home:swen:spam"]) == ":home:swen:spam") + self.assert_(commonprefix([b"home:swenson:spam", b"home:swen:spam"]) + == b"home:swen") + self.assert_(commonprefix([b":home:swen:spam", b":home:swen:eggs"]) + == b":home:swen:") + self.assert_(commonprefix([b":home:swen:spam", b":home:swen:spam"]) + == b":home:swen:spam") + def test_split(self): split = macpath.split self.assertEquals(split("foo:bar"), @@ -39,11 +54,37 @@ self.assertEquals(split(":conky:mountpoint:"), (':conky:mountpoint', '')) + self.assertEquals(split(b"foo:bar"), + (b'foo:', b'bar')) + self.assertEquals(split(b"conky:mountpoint:foo:bar"), + (b'conky:mountpoint:foo', b'bar')) + + self.assertEquals(split(b":"), (b'', b'')) + self.assertEquals(split(b":conky:mountpoint:"), + (b':conky:mountpoint', b'')) + + def test_join(self): + join = macpath.join + self.assertEquals(join('a', 'b'), ':a:b') + self.assertEquals(join('', 'a:b'), 'a:b') + self.assertEquals(join('a:b', 'c'), 'a:b:c') + self.assertEquals(join('a:b', ':c'), 'a:b:c') + self.assertEquals(join('a', ':b', ':c'), ':a:b:c') + + self.assertEquals(join(b'a', b'b'), b':a:b') + self.assertEquals(join(b'', b'a:b'), b'a:b') + self.assertEquals(join(b'a:b', b'c'), b'a:b:c') + self.assertEquals(join(b'a:b', b':c'), b'a:b:c') + self.assertEquals(join(b'a', b':b', b':c'), b':a:b:c') + def test_splitdrive(self): splitdrive = macpath.splitdrive self.assertEquals(splitdrive("foo:bar"), ('', 'foo:bar')) self.assertEquals(splitdrive(":foo:bar"), ('', ':foo:bar')) + self.assertEquals(splitdrive(b"foo:bar"), (b'', b'foo:bar')) + self.assertEquals(splitdrive(b":foo:bar"), (b'', b':foo:bar')) + def test_splitext(self): splitext = macpath.splitext self.assertEquals(splitext(":foo.ext"), (':foo', '.ext')) @@ -54,6 +95,49 @@ self.assertEquals(splitext(""), ('', '')) self.assertEquals(splitext("foo.bar.ext"), ('foo.bar', '.ext')) + self.assertEquals(splitext(b":foo.ext"), (b':foo', b'.ext')) + self.assertEquals(splitext(b"foo:foo.ext"), (b'foo:foo', b'.ext')) + self.assertEquals(splitext(b".ext"), (b'.ext', b'')) + self.assertEquals(splitext(b"foo.ext:foo"), (b'foo.ext:foo', b'')) + self.assertEquals(splitext(b":foo.ext:"), (b':foo.ext:', b'')) + self.assertEquals(splitext(b""), (b'', b'')) + self.assertEquals(splitext(b"foo.bar.ext"), (b'foo.bar', b'.ext')) + + def test_ismount(self): + ismount = macpath.ismount + self.assertEquals(ismount("a:"), True) + self.assertEquals(ismount("a:b"), False) + self.assertEquals(ismount("a:b:"), True) + self.assertEquals(ismount(""), False) + self.assertEquals(ismount(":"), False) + + self.assertEquals(ismount(b"a:"), True) + self.assertEquals(ismount(b"a:b"), False) + self.assertEquals(ismount(b"a:b:"), True) + self.assertEquals(ismount(b""), False) + self.assertEquals(ismount(b":"), False) + + def test_normpath(self): + normpath = macpath.normpath + self.assertEqual(normpath("a:b"), "a:b") + self.assertEqual(normpath("a"), ":a") + self.assertEqual(normpath("a:b::c"), "a:c") + self.assertEqual(normpath("a:b:c:::d"), "a:d") + self.assertRaises(macpath.norm_error, normpath, "a::b") + self.assertRaises(macpath.norm_error, normpath, "a:b:::c") + self.assertEqual(normpath(":"), ":") + self.assertEqual(normpath("a:"), "a:") + self.assertEqual(normpath("a:b:"), "a:b") + + self.assertEqual(normpath(b"a:b"), b"a:b") + self.assertEqual(normpath(b"a"), b":a") + self.assertEqual(normpath(b"a:b::c"), b"a:c") + self.assertEqual(normpath(b"a:b:c:::d"), b"a:d") + self.assertRaises(macpath.norm_error, normpath, b"a::b") + self.assertRaises(macpath.norm_error, normpath, b"a:b:::c") + self.assertEqual(normpath(b":"), b":") + self.assertEqual(normpath(b"a:"), b"a:") + self.assertEqual(normpath(b"a:b:"), b"a:b") def test_main(): support.run_unittest(MacPathTestCase) From python-3000-checkins at python.org Sat Oct 4 20:33:26 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 4 Oct 2008 20:33:26 +0200 (CEST) Subject: [Python-3000-checkins] r66794 - in python/branches/py3k/Doc: howto/functional.rst library/collections.rst library/reprlib.rst reference/lexical_analysis.rst Message-ID: <20081004183326.836DB1E4002@bag.python.org> Author: georg.brandl Date: Sat Oct 4 20:33:26 2008 New Revision: 66794 Log: #4000: fix several 2.x atavisms. Modified: python/branches/py3k/Doc/howto/functional.rst python/branches/py3k/Doc/library/collections.rst python/branches/py3k/Doc/library/reprlib.rst python/branches/py3k/Doc/reference/lexical_analysis.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 Oct 4 20:33:26 2008 @@ -69,9 +69,9 @@ Some languages are very strict about purity and don't even have assignment statements such as ``a=3`` or ``c = a + b``, but it's difficult to avoid all side effects. Printing to the screen or writing to a disk file are side -effects, for example. For example, in Python a ``print`` statement or a -``time.sleep(1)`` both return no useful value; they're only called for their -side effects of sending some text to the screen or pausing execution for a +effects, for example. For example, in Python a call to the :func:`print` or +:func:`time.sleep` function both return no useful value; they're only called for +their side effects of sending some text to the screen or pausing execution for a second. Python programs written in functional style usually won't go to the extreme of @@ -1031,8 +1031,8 @@ ... ] - def get_state ((city, state)): - return state + def get_state (city_state): + return city_state[1] itertools.groupby(city_list, get_state) => ('AL', iterator-1), Modified: python/branches/py3k/Doc/library/collections.rst ============================================================================== --- python/branches/py3k/Doc/library/collections.rst (original) +++ python/branches/py3k/Doc/library/collections.rst Sat Oct 4 20:33:26 2008 @@ -632,7 +632,7 @@ ... def __str__(self): ... return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot) - >>> for p in Point(3, 4), Point(14, 5/7.): + >>> for p in Point(3, 4), Point(14, 5/7): ... print(p) Point: x= 3.000 y= 4.000 hypot= 5.000 Point: x=14.000 y= 0.714 hypot=14.018 Modified: python/branches/py3k/Doc/library/reprlib.rst ============================================================================== --- python/branches/py3k/Doc/library/reprlib.rst (original) +++ python/branches/py3k/Doc/library/reprlib.rst Sat Oct 4 20:33:26 2008 @@ -126,7 +126,7 @@ if obj.name in ['', '', '']: return obj.name else: - return `obj` + return repr(obj) aRepr = MyRepr() print aRepr.repr(sys.stdin) # prints '' Modified: python/branches/py3k/Doc/reference/lexical_analysis.rst ============================================================================== --- python/branches/py3k/Doc/reference/lexical_analysis.rst (original) +++ python/branches/py3k/Doc/reference/lexical_analysis.rst Sat Oct 4 20:33:26 2008 @@ -676,8 +676,8 @@ The following tokens serve as delimiters in the grammar:: - ( ) [ ] { } @ - , : . ` = ; + ( ) [ ] { } + , : . ; @ = += -= *= /= //= %= &= |= ^= >>= <<= **= From python-3000-checkins at python.org Sat Oct 4 20:37:20 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Sat, 4 Oct 2008 20:37:20 +0200 (CEST) Subject: [Python-3000-checkins] r66795 - python/branches/py3k/Doc/library/functions.rst Message-ID: <20081004183720.633551E4002@bag.python.org> Author: georg.brandl Date: Sat Oct 4 20:37:20 2008 New Revision: 66795 Log: #4029: fix typo. 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 Oct 4 20:37:20 2008 @@ -832,7 +832,7 @@ must be of integer types, and *y* must be non-negative. -.. function:: print([object, ...][, sep=' '][, end='\n'][, file=sys.stdout]) +.. function:: print([object, ...][, sep=' '][, end='\\n'][, file=sys.stdout]) Print *object*\(s) to the stream *file*, separated by *sep* and followed by *end*. *sep*, *end* and *file*, if present, must be given as keyword From python-3000-checkins at python.org Sat Oct 4 23:04:36 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 4 Oct 2008 23:04:36 +0200 (CEST) Subject: [Python-3000-checkins] r66798 - in python/branches/py3k: Lib/lib2to3 Lib/lib2to3/fixes/fix_getcwdu.py Lib/lib2to3/fixes/fix_import.py Lib/lib2to3/pytree.py Lib/lib2to3/tests/data/README Lib/lib2to3/tests/data/infinite_recursion.py Lib/lib2to3/tests/test_fixers.py Message-ID: <20081004210436.8FD2E1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 4 23:04:36 2008 New Revision: 66798 Log: Merged revisions 66797 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r66797 | benjamin.peterson | 2008-10-04 15:55:50 -0500 (Sat, 04 Oct 2008) | 19 lines Merged revisions 66707,66775,66782 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r66707 | benjamin.peterson | 2008-09-30 18:27:10 -0500 (Tue, 30 Sep 2008) | 1 line fix #4001: fix_imports didn't check for __init__.py before converting to relative imports ........ r66775 | collin.winter | 2008-10-03 12:08:26 -0500 (Fri, 03 Oct 2008) | 4 lines Add an alternative iterative pattern matching system that, while slower, correctly parses files that cause the faster recursive pattern matcher to fail with a recursion error. lib2to3 falls back to the iterative matcher if the recursive one fails. Fixes http://bugs.python.org/issue2532. Thanks to Nick Edds. ........ r66782 | benjamin.peterson | 2008-10-03 17:51:36 -0500 (Fri, 03 Oct 2008) | 1 line add Victor Stinner's fixer for os.getcwdu -> os.getcwd #4023 ........ ................ Added: python/branches/py3k/Lib/lib2to3/fixes/fix_getcwdu.py - copied unchanged from r66797, /python/trunk/Lib/lib2to3/fixes/fix_getcwdu.py python/branches/py3k/Lib/lib2to3/tests/data/README - copied unchanged from r66797, /python/trunk/Lib/lib2to3/tests/data/README python/branches/py3k/Lib/lib2to3/tests/data/infinite_recursion.py - copied unchanged from r66797, /python/trunk/Lib/lib2to3/tests/data/infinite_recursion.py 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/pytree.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 Sat Oct 4 23:04:36 2008 @@ -54,6 +54,10 @@ imp_name = imp_name.split('.', 1)[0].strip() base_path = dirname(file_path) base_path = join(base_path, imp_name) + # If there is no __init__.py next to the file its not in a package + # so can't be a relative import. + if not exists(join(dirname(base_path), '__init__.py')): + return False for ext in ['.py', pathsep, '.pyc', '.so', '.sl', '.pyd']: if exists(base_path + ext): return True Modified: python/branches/py3k/Lib/lib2to3/pytree.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/pytree.py (original) +++ python/branches/py3k/Lib/lib2to3/pytree.py Sat Oct 4 23:04:36 2008 @@ -655,10 +655,47 @@ elif self.name == "bare_name": yield self._bare_name_matches(nodes) else: - for count, r in self._recursive_matches(nodes, 0): - if self.name: - r[self.name] = nodes[:count] - yield count, r + try: + for count, r in self._recursive_matches(nodes, 0): + if self.name: + r[self.name] = nodes[:count] + yield count, r + except RuntimeError: + # We fall back to the iterative pattern matching scheme if the recursive + # scheme hits the recursion limit. + for count, r in self._iterative_matches(nodes): + if self.name: + r[self.name] = nodes[:count] + yield count, r + + def _iterative_matches(self, nodes): + """Helper to iteratively yield the matches.""" + nodelen = len(nodes) + if 0 >= self.min: + yield 0, {} + + results = [] + # generate matches that use just one alt from self.content + for alt in self.content: + for c, r in generate_matches(alt, nodes): + yield c, r + results.append((c, r)) + + # for each match, iterate down the nodes + while results: + new_results = [] + for c0, r0 in results: + # stop if the entire set of nodes has been matched + if c0 < nodelen and c0 <= self.max: + for alt in self.content: + for c1, r1 in generate_matches(alt, nodes[c0:]): + if c1 > 0: + r = {} + r.update(r0) + r.update(r1) + yield c0 + c1, r + new_results.append((c0 + c1, r)) + results = new_results def _bare_name_matches(self, nodes): """Special optimized matcher for bare_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 Oct 4 23:04:36 2008 @@ -9,10 +9,10 @@ from . import support # Python imports +import os import unittest from itertools import chain from operator import itemgetter -from os.path import dirname, pathsep # Local imports from .. import pygram @@ -3274,14 +3274,19 @@ # Need to replace fix_import's exists method # so we can check that it's doing the right thing self.files_checked = [] + self.present_files = set() self.always_exists = True def fake_exists(name): self.files_checked.append(name) - return self.always_exists + return self.always_exists or (name in self.present_files) from ..fixes import fix_import fix_import.exists = fake_exists + def tearDown(self): + from lib2to3.fixes import fix_import + fix_import.exists = os.path.exists + def check_both(self, b, a): self.always_exists = True FixerTestCase.check(self, b, a) @@ -3291,10 +3296,12 @@ def test_files_checked(self): def p(path): # Takes a unix path and returns a path with correct separators - return pathsep.join(path.split("/")) + return os.path.pathsep.join(path.split("/")) self.always_exists = False - expected_extensions = ('.py', pathsep, '.pyc', '.so', '.sl', '.pyd') + self.present_files = set(['__init__.py']) + expected_extensions = ('.py', os.path.pathsep, '.pyc', '.so', + '.sl', '.pyd') names_to_test = (p("/spam/eggs.py"), "ni.py", p("../../shrubbery.py")) for name in names_to_test: @@ -3302,11 +3309,32 @@ self.filename = name self.unchanged("import jam") - if dirname(name): name = dirname(name) + '/jam' - else: name = 'jam' + if os.path.dirname(name): + name = os.path.dirname(name) + '/jam' + else: + name = 'jam' expected_checks = set(name + ext for ext in expected_extensions) + expected_checks.add("__init__.py") + + self.assertEqual(set(self.files_checked), expected_checks) - self.failUnlessEqual(set(self.files_checked), expected_checks) + def test_not_in_package(self): + s = "import bar" + self.always_exists = False + self.present_files = set(["bar.py"]) + self.unchanged(s) + + def test_in_package(self): + b = "import bar" + a = "from . import bar" + self.always_exists = False + self.present_files = set(["__init__.py", "bar.py"]) + self.check(b, a) + + def test_comments_and_indent(self): + b = "import bar # Foo" + a = "from . import bar # Foo" + self.check(b, a) def test_from(self): b = "from foo import bar, baz" @@ -3577,6 +3605,67 @@ self.check(b, a) +class Test_getcwdu(FixerTestCase): + + fixer = 'getcwdu' + + def test_basic(self): + b = """os.getcwdu""" + a = """os.getcwd""" + self.check(b, a) + + b = """os.getcwdu()""" + a = """os.getcwd()""" + self.check(b, a) + + b = """meth = os.getcwdu""" + a = """meth = os.getcwd""" + self.check(b, a) + + b = """os.getcwdu(args)""" + a = """os.getcwd(args)""" + self.check(b, a) + + def test_comment(self): + b = """os.getcwdu() # Foo""" + a = """os.getcwd() # Foo""" + self.check(b, a) + + def test_unchanged(self): + s = """os.getcwd()""" + self.unchanged(s) + + s = """getcwdu()""" + self.unchanged(s) + + s = """os.getcwdb()""" + self.unchanged(s) + + def test_indentation(self): + b = """ + if 1: + os.getcwdu() + """ + a = """ + if 1: + os.getcwd() + """ + self.check(b, a) + + def test_multilation(self): + b = """os .getcwdu()""" + a = """os .getcwd()""" + self.check(b, a) + + b = """os. getcwdu""" + a = """os. getcwd""" + self.check(b, a) + + b = """os.getcwdu ( )""" + a = """os.getcwd ( )""" + self.check(b, a) + + if __name__ == "__main__": import __main__ support.run_all_tests(__main__) From python-3000-checkins at python.org Sun Oct 5 00:00:46 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 5 Oct 2008 00:00:46 +0200 (CEST) Subject: [Python-3000-checkins] r66802 - in python/branches/py3k: Doc/c-api/number.rst Doc/c-api/object.rst Doc/howto/urllib2.rst Doc/library/ctypes.rst Doc/library/multiprocessing.rst Doc/library/optparse.rst Doc/library/subprocess.rst Doc/tools/sphinxext/download.html Lib/multiprocessing/synchronize.py Lib/test/regrtest.py Lib/test/test_multiprocessing.py PCbuild/readme.txt setup.py Message-ID: <20081004220046.B26851E4002@bag.python.org> Author: benjamin.peterson Date: Sun Oct 5 00:00:42 2008 New Revision: 66802 Log: Merged revisions 66670,66681,66688,66696-66699 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66670 | georg.brandl | 2008-09-28 15:01:36 -0500 (Sun, 28 Sep 2008) | 2 lines Don't show version in title. ........ r66681 | georg.brandl | 2008-09-29 11:51:35 -0500 (Mon, 29 Sep 2008) | 2 lines Update nasm location. ........ r66688 | jesse.noller | 2008-09-29 19:15:45 -0500 (Mon, 29 Sep 2008) | 2 lines issue3770: if SEM_OPEN is 0, disable the mp.synchronize module, rev. Nick Coghlan, Damien Miller ........ r66696 | andrew.kuchling | 2008-09-30 07:31:07 -0500 (Tue, 30 Sep 2008) | 1 line Edits, and add markup ........ r66697 | andrew.kuchling | 2008-09-30 08:00:34 -0500 (Tue, 30 Sep 2008) | 1 line Markup fix ........ r66698 | andrew.kuchling | 2008-09-30 08:00:51 -0500 (Tue, 30 Sep 2008) | 1 line Markup fixes ........ r66699 | andrew.kuchling | 2008-09-30 08:01:46 -0500 (Tue, 30 Sep 2008) | 1 line Markup fixes. (optparse.rst probably needs an entire revision pass.) ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/c-api/number.rst python/branches/py3k/Doc/c-api/object.rst python/branches/py3k/Doc/howto/urllib2.rst python/branches/py3k/Doc/library/ctypes.rst python/branches/py3k/Doc/library/multiprocessing.rst python/branches/py3k/Doc/library/optparse.rst python/branches/py3k/Doc/library/subprocess.rst python/branches/py3k/Doc/tools/sphinxext/download.html python/branches/py3k/Lib/multiprocessing/synchronize.py python/branches/py3k/Lib/test/regrtest.py python/branches/py3k/Lib/test/test_multiprocessing.py python/branches/py3k/PCbuild/readme.txt python/branches/py3k/setup.py Modified: python/branches/py3k/Doc/c-api/number.rst ============================================================================== --- python/branches/py3k/Doc/c-api/number.rst (original) +++ python/branches/py3k/Doc/c-api/number.rst Sun Oct 5 00:00:42 2008 @@ -256,7 +256,7 @@ .. cfunction:: PyObject* PyNumber_Index(PyObject *o) Returns the *o* converted to a Python int or long on success or *NULL* with a - TypeError exception raised on failure. + :exc:`TypeError` exception raised on failure. .. cfunction:: PyObject* PyNumber_ToBase(PyObject *n, int base) Modified: python/branches/py3k/Doc/c-api/object.rst ============================================================================== --- python/branches/py3k/Doc/c-api/object.rst (original) +++ python/branches/py3k/Doc/c-api/object.rst Sun Oct 5 00:00:42 2008 @@ -257,7 +257,7 @@ .. cfunction:: long PyObject_HashNotImplemented(PyObject *o) - Set a TypeError indicating that ``type(o)`` is not hashable and return ``-1``. + Set a :exc:`TypeError` indicating that ``type(o)`` is not hashable and return ``-1``. This function receives special treatment when stored in a ``tp_hash`` slot, allowing a type to explicitly indicate to the interpreter that it is not hashable. Modified: python/branches/py3k/Doc/howto/urllib2.rst ============================================================================== --- python/branches/py3k/Doc/howto/urllib2.rst (original) +++ python/branches/py3k/Doc/howto/urllib2.rst Sun Oct 5 00:00:42 2008 @@ -182,11 +182,12 @@ Handling Exceptions =================== -*urlopen* raises ``URLError`` when it cannot handle a response (though as usual -with Python APIs, builtin exceptions such as ValueError, TypeError etc. may also +*urlopen* raises :exc:`URLError` when it cannot handle a response (though as usual +with Python APIs, builtin exceptions such as +:exc:`ValueError`, :exc:`TypeError` etc. may also be raised). -``HTTPError`` is the subclass of ``URLError`` raised in the specific case of +:exc:`HTTPError` is the subclass of :exc:`URLError` raised in the specific case of HTTP URLs. The exception classes are exported from the :mod:`urllib.error` module. @@ -217,12 +218,12 @@ default handlers will handle some of these responses for you (for example, if the response is a "redirection" that requests the client fetch the document from a different URL, urllib will handle that for you). For those it can't handle, -urlopen will raise an ``HTTPError``. Typical errors include '404' (page not +urlopen will raise an :exc:`HTTPError`. Typical errors include '404' (page not found), '403' (request forbidden), and '401' (authentication required). See section 10 of RFC 2616 for a reference on all the HTTP error codes. -The ``HTTPError`` instance raised will have an integer 'code' attribute, which +The :exc:`HTTPError` instance raised will have an integer 'code' attribute, which corresponds to the error sent by the server. Error Codes @@ -305,7 +306,7 @@ } When an error is raised the server responds by returning an HTTP error code -*and* an error page. You can use the ``HTTPError`` instance as a response on the +*and* an error page. You can use the :exc:`HTTPError` instance as a response on the page returned. This means that as well as the code attribute, it also has read, geturl, and info, methods as returned by the ``urllib.response`` module:: @@ -327,7 +328,7 @@ Wrapping it Up -------------- -So if you want to be prepared for ``HTTPError`` *or* ``URLError`` there are two +So if you want to be prepared for :exc:`HTTPError` *or* :exc:`URLError` there are two basic approaches. I prefer the second approach. Number 1 @@ -354,7 +355,7 @@ .. note:: The ``except HTTPError`` *must* come first, otherwise ``except URLError`` - will *also* catch an ``HTTPError``. + will *also* catch an :exc:`HTTPError`. Number 2 ~~~~~~~~ @@ -380,9 +381,9 @@ info and geturl =============== -The response returned by urlopen (or the ``HTTPError`` instance) has two useful -methods ``info`` and ``geturl`` and is defined in the module -:mod:`urllib.response`. +The response returned by urlopen (or the :exc:`HTTPError` instance) has two +useful methods :meth:`info` and :meth:`geturl` and is defined in the module +:mod:`urllib.response`.. **geturl** - this returns the real URL of the page fetched. This is useful because ``urlopen`` (or the opener object used) may have followed a Modified: python/branches/py3k/Doc/library/ctypes.rst ============================================================================== --- python/branches/py3k/Doc/library/ctypes.rst (original) +++ python/branches/py3k/Doc/library/ctypes.rst Sun Oct 5 00:00:42 2008 @@ -1390,7 +1390,7 @@ The *use_last_error* parameter, when set to True, enables the same mechanism for the Windows error code which is managed by the -GetLastError() and SetLastError() Windows api functions; +:func:`GetLastError` and :func:`SetLastError` Windows API functions; `ctypes.get_last_error()` and `ctypes.set_last_error(value)` are used to request and change the ctypes private copy of the windows error code. Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Sun Oct 5 00:00:42 2008 @@ -16,6 +16,13 @@ leverage multiple processors on a given machine. It runs on both Unix and Windows. +.. warning:: + + Some of this package's functionality requires a functioning shared semaphore + implementation on the host operating system. Without one, the + :mod:`multiprocessing.synchronize` module will be disabled, and attempts to + import it will result in an :exc:`ImportError`. See + :issue:`3770` for additional information. The :class:`Process` class ~~~~~~~~~~~~~~~~~~~~~~~~~~ Modified: python/branches/py3k/Doc/library/optparse.rst ============================================================================== --- python/branches/py3k/Doc/library/optparse.rst (original) +++ python/branches/py3k/Doc/library/optparse.rst Sun Oct 5 00:00:42 2008 @@ -597,7 +597,7 @@ programmer errors and user errors. Programmer errors are usually erroneous calls to ``parser.add_option()``, e.g. invalid option strings, unknown option attributes, missing option attributes, etc. These are dealt with in the usual -way: raise an exception (either ``optparse.OptionError`` or ``TypeError``) and +way: raise an exception (either ``optparse.OptionError`` or :exc:`TypeError`) and let the program crash. Handling user errors is much more important, since they are guaranteed to happen @@ -794,10 +794,10 @@ The keyword arguments define attributes of the new Option object. The most important option attribute is :attr:`action`, and it largely determines which other attributes are relevant or required. If you pass irrelevant option -attributes, or fail to pass required ones, :mod:`optparse` raises an OptionError -exception explaining your mistake. +attributes, or fail to pass required ones, :mod:`optparse` raises an +:exc:`OptionError` exception explaining your mistake. -An options's *action* determines what :mod:`optparse` does when it encounters +An option's *action* determines what :mod:`optparse` does when it encounters this option on the command-line. The standard option actions hard-coded into :mod:`optparse` are: @@ -1054,7 +1054,7 @@ The following option attributes may be passed as keyword arguments to ``parser.add_option()``. If you pass an option attribute that is not relevant to a particular option, or fail to pass a required option attribute, -:mod:`optparse` raises OptionError. +:mod:`optparse` raises :exc:`OptionError`. * :attr:`action` (default: ``"store"``) @@ -1147,7 +1147,7 @@ ``choice`` options are a subtype of ``string`` options. The ``choices`` option attribute (a sequence of strings) defines the set of allowed option arguments. ``optparse.check_choice()`` compares user-supplied option arguments against this -master list and raises OptionValueError if an invalid string is given. +master list and raises :exc:`OptionValueError` if an invalid string is given. .. _optparse-parsing-arguments: @@ -1220,10 +1220,10 @@ (e.g., ``"-q"`` or ``"--verbose"``). ``remove_option(opt_str)`` - If the OptionParser has an option corresponding to ``opt_str``, that option is + If the :class:`OptionParser` has an option corresponding to ``opt_str``, that option is removed. If that option provided any other option strings, all of those option strings become invalid. If ``opt_str`` does not occur in any option belonging to - this OptionParser, raises ValueError. + this :class:`OptionParser`, raises :exc:`ValueError`. .. _optparse-conflicts-between-options: @@ -1254,13 +1254,13 @@ The available conflict handlers are: ``error`` (default) - assume option conflicts are a programming error and raise OptionConflictError + assume option conflicts are a programming error and raise :exc:`OptionConflictError` ``resolve`` resolve option conflicts intelligently (see below) -As an example, let's define an OptionParser that resolves conflicts +As an example, let's define an :class:`OptionParser` that resolves conflicts intelligently and add conflicting options to it:: parser = OptionParser(conflict_handler="resolve") @@ -1490,7 +1490,7 @@ Raising errors in a callback ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The callback function should raise OptionValueError if there are any problems +The callback function should raise :exc:`OptionValueError` if there are any problems with the option or its argument(s). :mod:`optparse` catches this and terminates the program, printing the error message you supply to stderr. Your message should be clear, concise, accurate, and mention the option at fault. Otherwise, @@ -1691,9 +1691,9 @@ :meth:`OptionParser.parse_args`, or be passed to a callback as the ``value`` parameter. -Your type-checking function should raise OptionValueError if it encounters any -problems. OptionValueError takes a single string argument, which is passed -as-is to OptionParser's :meth:`error` method, which in turn prepends the program +Your type-checking function should raise :exc:`OptionValueError` if it encounters any +problems. :exc:`OptionValueError` takes a single string argument, which is passed +as-is to :class:`OptionParser`'s :meth:`error` method, which in turn prepends the program name and the string ``"error:"`` and prints everything to stderr before terminating the process. Modified: python/branches/py3k/Doc/library/subprocess.rst ============================================================================== --- python/branches/py3k/Doc/library/subprocess.rst (original) +++ python/branches/py3k/Doc/library/subprocess.rst Sun Oct 5 00:00:42 2008 @@ -133,7 +133,7 @@ .. function:: check_call(*popenargs, **kwargs) Run command with arguments. Wait for command to complete. If the exit code was - zero then return, otherwise raise :exc:`CalledProcessError.` The + zero then return, otherwise raise :exc:`CalledProcessError`. The :exc:`CalledProcessError` object will have the return code in the :attr:`returncode` attribute. 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 Sun Oct 5 00:00:42 2008 @@ -3,14 +3,15 @@ {% set dlbase = 'http://docs.python.org/ftp/python/doc/' + release %} {% block body %} -

Download Python {{ release }} Documentation - {%- if last_updated %} (last updated on {{ last_updated }}){% endif %}

+

Download Python {{ release }} Documentation

{% if 'a' in release or 'b' in release or 'c' in release %}

We don't package the documentation for development releases for download. Downloads will be available for the final release.

{% else %} +{% if last_updated %}

Last updated on: {{ last_updated }}.

{% endif %} +

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.

Modified: python/branches/py3k/Lib/multiprocessing/synchronize.py ============================================================================== --- python/branches/py3k/Lib/multiprocessing/synchronize.py (original) +++ python/branches/py3k/Lib/multiprocessing/synchronize.py Sun Oct 5 00:00:42 2008 @@ -21,6 +21,17 @@ from multiprocessing.util import Finalize, register_after_fork, debug from multiprocessing.forking import assert_spawning, Popen +# Try to import the mp.synchronize module cleanly, if it fails +# raise ImportError for platforms lacking a working sem_open implementation. +# See issue 3770 +try: + from _multiprocessing import SemLock +except (ImportError): + raise ImportError("This platform lacks a functioning sem_open" + + " implementation, therefore, the required" + + " synchronization primitives needed will not" + + " function, see issue 3770.") + # # Constants # Modified: python/branches/py3k/Lib/test/regrtest.py ============================================================================== --- python/branches/py3k/Lib/test/regrtest.py (original) +++ python/branches/py3k/Lib/test/regrtest.py Sun Oct 5 00:00:42 2008 @@ -1075,6 +1075,7 @@ test_tcl test_timeout test_urllibnet + test_multiprocessing """, 'aix5': """ @@ -1102,6 +1103,7 @@ test_ossaudiodev test_pep277 test_tcl + test_multiprocessing """, 'netbsd3': """ @@ -1115,6 +1117,7 @@ test_ossaudiodev test_pep277 test_tcl + test_multiprocessing """, } _expectations['freebsd5'] = _expectations['freebsd4'] Modified: python/branches/py3k/Lib/test/test_multiprocessing.py ============================================================================== --- python/branches/py3k/Lib/test/test_multiprocessing.py (original) +++ python/branches/py3k/Lib/test/test_multiprocessing.py Sun Oct 5 00:00:42 2008 @@ -18,6 +18,14 @@ import random import logging + +# Work around broken sem_open implementations +try: + import multiprocessing.synchronize +except ImportError as e: + from test.test_support import TestSkipped + raise TestSkipped(e) + import multiprocessing.dummy import multiprocessing.connection import multiprocessing.managers Modified: python/branches/py3k/PCbuild/readme.txt ============================================================================== --- python/branches/py3k/PCbuild/readme.txt (original) +++ python/branches/py3k/PCbuild/readme.txt Sun Oct 5 00:00:42 2008 @@ -153,7 +153,7 @@ build process will automatically select the latest version. You must install the NASM assembler from - http://www.kernel.org/pub/software/devel/nasm/binaries/win32/ + http://nasm.sf.net for x86 builds. Put nasmw.exe anywhere in your PATH. You can also install ActivePerl from Modified: python/branches/py3k/setup.py ============================================================================== --- python/branches/py3k/setup.py (original) +++ python/branches/py3k/setup.py Sun Oct 5 00:00:42 2008 @@ -1019,6 +1019,14 @@ ) libraries = [] + elif platform.startswith('openbsd'): + macros = dict( # OpenBSD + HAVE_SEM_OPEN=0, # Not implemented + HAVE_SEM_TIMEDWAIT=0, + HAVE_FD_TRANSFER=1, + ) + libraries = [] + else: # Linux and other unices macros = dict( HAVE_SEM_OPEN=1, From python-3000-checkins at python.org Sun Oct 5 11:00:29 2008 From: python-3000-checkins at python.org (mark.hammond) Date: Sun, 5 Oct 2008 11:00:29 +0200 (CEST) Subject: [Python-3000-checkins] r66806 - python/branches/py3k/Lib/distutils/file_util.py Message-ID: <20081005090029.461DF1E4048@bag.python.org> Author: mark.hammond Date: Sun Oct 5 11:00:28 2008 New Revision: 66806 Log: Fix [issue4038] py3k error in distutils file_copy exception handlers. r=martin. Modified: python/branches/py3k/Lib/distutils/file_util.py Modified: python/branches/py3k/Lib/distutils/file_util.py ============================================================================== --- python/branches/py3k/Lib/distutils/file_util.py (original) +++ python/branches/py3k/Lib/distutils/file_util.py Sun Oct 5 11:00:28 2008 @@ -30,31 +30,27 @@ try: fsrc = open(src, 'rb') except os.error as e: - (errno, errstr) = e - raise DistutilsFileError("could not open '%s': %s" % (src, errstr)) + raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror)) if os.path.exists(dst): try: os.unlink(dst) except os.error as e: - (errno, errstr) = e raise DistutilsFileError( - "could not delete '%s': %s" % (dst, errstr)) + "could not delete '%s': %s" % (dst, e.strerror)) try: fdst = open(dst, 'wb') except os.error as e: - (errno, errstr) = e raise DistutilsFileError( - "could not create '%s': %s" % (dst, errstr)) + "could not create '%s': %s" % (dst, e.strerror)) while True: try: buf = fsrc.read(buffer_size) except os.error as e: - (errno, errstr) = e raise DistutilsFileError( - "could not read from '%s': %s" % (src, errstr)) + "could not read from '%s': %s" % (src, e.strerror)) if not buf: break @@ -62,9 +58,8 @@ try: fdst.write(buf) except os.error as e: - (errno, errstr) = e raise DistutilsFileError( - "could not write to '%s': %s" % (dst, errstr)) + "could not write to '%s': %s" % (dst, e.strerror)) finally: if fdst: fdst.close() From python-3000-checkins at python.org Sun Oct 5 18:46:29 2008 From: python-3000-checkins at python.org (raymond.hettinger) Date: Sun, 5 Oct 2008 18:46:29 +0200 (CEST) Subject: [Python-3000-checkins] r66807 - python/branches/py3k/Doc/tutorial/floatingpoint.rst Message-ID: <20081005164629.D07691E4002@bag.python.org> Author: raymond.hettinger Date: Sun Oct 5 18:46:29 2008 New Revision: 66807 Log: Issue 3288: document as_integer_ratio(), fromhex(), and hex(). Modified: python/branches/py3k/Doc/tutorial/floatingpoint.rst Modified: python/branches/py3k/Doc/tutorial/floatingpoint.rst ============================================================================== --- python/branches/py3k/Doc/tutorial/floatingpoint.rst (original) +++ python/branches/py3k/Doc/tutorial/floatingpoint.rst Sun Oct 5 18:46:29 2008 @@ -138,7 +138,39 @@ If you are a heavy user of floating point operations you should take a look at the Numerical Python package and many other packages for mathematical and statistical operations supplied by the SciPy project. See . - + +Python provides tools that may help on those rare occasions when you really +*do* want to know the exact value of a float. The +:meth:`float.as_integer_ratio` method expresses the value of a float as a +fraction:: + + >>> x = 3.14159 + >>> x.as_integer_ratio() + (3537115888337719L, 1125899906842624L) + +Since the ratio is exact, it can be used to losslessly recreate the +original value:: + + >>> x == 3537115888337719 / 1125899906842624 + True + +The :meth:`float.hex` method expresses a float in hexadecimal (base +16), again giving the exact value stored by your computer:: + + >>> x.hex() + '0x1.921f9f01b866ep+1' + +This precise hexadecimal representation can be used to reconstruct +the float value exactly:: + + >>> x == float.fromhex('0x1.921f9f01b866ep+1') + True + +Since the representation is exact, it is useful for reliably porting values +across different versions of Python (platform independence) and exchanging +data with other languages that support the same format (such as Java and C99). + + .. _tut-fp-error: Representation Error From musiccomposition at gmail.com Sun Oct 5 19:08:38 2008 From: musiccomposition at gmail.com (Benjamin Peterson) Date: Sun, 5 Oct 2008 12:08:38 -0500 Subject: [Python-3000-checkins] r66807 - python/branches/py3k/Doc/tutorial/floatingpoint.rst In-Reply-To: <20081005164629.D07691E4002@bag.python.org> References: <20081005164629.D07691E4002@bag.python.org> Message-ID: <1afaf6160810051008j4682ca4cn4767caecb6f0f5b8@mail.gmail.com> On Sun, Oct 5, 2008 at 11:46 AM, raymond. hettinger wrote: > Author: raymond.hettinger > Date: Sun Oct 5 18:46:29 2008 > New Revision: 66807 > > Log: > Issue 3288: document as_integer_ratio(), fromhex(), and hex(). Shouldn't this information also go in the library reference? (such as stdtypes.rst) -- 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 Sun Oct 5 19:57:52 2008 From: python-3000-checkins at python.org (raymond.hettinger) Date: Sun, 5 Oct 2008 19:57:52 +0200 (CEST) Subject: [Python-3000-checkins] r66808 - python/branches/py3k/Doc/tutorial/floatingpoint.rst Message-ID: <20081005175752.D95211E4002@bag.python.org> Author: raymond.hettinger Date: Sun Oct 5 19:57:52 2008 New Revision: 66808 Log: Issue 3412: Mention fractions and decimal in the tutorial section on floating point. Modified: python/branches/py3k/Doc/tutorial/floatingpoint.rst Modified: python/branches/py3k/Doc/tutorial/floatingpoint.rst ============================================================================== --- python/branches/py3k/Doc/tutorial/floatingpoint.rst (original) +++ python/branches/py3k/Doc/tutorial/floatingpoint.rst Sun Oct 5 19:57:52 2008 @@ -135,6 +135,14 @@ :func:`str` usually suffices, and for finer control see the :meth:`str.format` method's format specifiers in :ref:`formatstrings`. +For use cases which require exact decimal representation, try using the +:mod:`decimal` module which implements decimal arithmetic suitable for +accounting applications and high-precision applications. + +Another form of exact arithmetic is supported by the :mod:`fractions` module +which implements arithmetic based on rational numbers (so the numbers like +1/3 can be represented exactly). + If you are a heavy user of floating point operations you should take a look at the Numerical Python package and many other packages for mathematical and statistical operations supplied by the SciPy project. See . From python at rcn.com Sun Oct 5 20:01:21 2008 From: python at rcn.com (Raymond Hettinger) Date: Sun, 5 Oct 2008 11:01:21 -0700 Subject: [Python-3000-checkins] r66807 -python/branches/py3k/Doc/tutorial/floatingpoint.rst References: <20081005164629.D07691E4002@bag.python.org> <1afaf6160810051008j4682ca4cn4767caecb6f0f5b8@mail.gmail.com> Message-ID: It's already there starting at line 422 in stdtypes.rst. ----- Original Message ----- From: "Benjamin Peterson" To: "raymond. hettinger" Sent: Sunday, October 05, 2008 10:08 AM Subject: Re: [Python-3000-checkins] r66807 -python/branches/py3k/Doc/tutorial/floatingpoint.rst > On Sun, Oct 5, 2008 at 11:46 AM, raymond. hettinger > wrote: >> Author: raymond.hettinger >> Date: Sun Oct 5 18:46:29 2008 >> New Revision: 66807 >> >> Log: >> Issue 3288: document as_integer_ratio(), fromhex(), and hex(). > > Shouldn't this information also go in the library reference? (such as > stdtypes.rst) > > > -- > Cheers, > Benjamin Peterson > "There's nothing quite as beautiful as an oboe... except a chicken > stuck in a vacuum cleaner." > _______________________________________________ > 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 Mon Oct 6 06:51:12 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Mon, 6 Oct 2008 06:51:12 +0200 (CEST) Subject: [Python-3000-checkins] r66811 - python/branches/py3k/Lib/test/test_platform.py Message-ID: <20081006045112.2C67B1E4002@bag.python.org> Author: hirokazu.yamamoto Date: Mon Oct 6 06:51:11 2008 New Revision: 66811 Log: Added the test for issue3762. Modified: python/branches/py3k/Lib/test/test_platform.py Modified: python/branches/py3k/Lib/test/test_platform.py ============================================================================== --- python/branches/py3k/Lib/test/test_platform.py (original) +++ python/branches/py3k/Lib/test/test_platform.py Mon Oct 6 06:51:11 2008 @@ -2,6 +2,7 @@ import os import unittest import platform +import subprocess from test import support @@ -9,6 +10,21 @@ def test_architecture(self): res = platform.architecture() + if hasattr(os, "symlink"): + def test_architecture_via_symlink(self): # issue3762 + def get(python): + cmd = [python, '-c', + 'import platform; print(platform.architecture())'] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE) + return p.communicate() + real = os.path.realpath(sys.executable) + link = os.path.abspath(support.TESTFN) + os.symlink(real, link) + try: + self.assertEqual(get(real), get(link)) + finally: + os.remove(link) + def test_machine(self): res = platform.machine() From python-3000-checkins at python.org Mon Oct 6 06:53:43 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Mon, 6 Oct 2008 06:53:43 +0200 (CEST) Subject: [Python-3000-checkins] r66812 - python/branches/py3k Message-ID: <20081006045343.697391E4002@bag.python.org> Author: hirokazu.yamamoto Date: Mon Oct 6 06:53:43 2008 New Revision: 66812 Log: Blocked revisions 66809-66810 via svnmerge ........ r66809 | hirokazu.yamamoto | 2008-10-06 10:57:03 +0900 | 1 line Added the test for issue3762. ........ r66810 | hirokazu.yamamoto | 2008-10-06 11:41:59 +0900 | 1 line More strict test. Consider the case sys.executable itself is symlink. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Mon Oct 6 17:19:22 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Mon, 6 Oct 2008 17:19:22 +0200 (CEST) Subject: [Python-3000-checkins] r66816 - in python/branches/py3k: Misc/NEWS setup.py Message-ID: <20081006151922.475831E4002@bag.python.org> Author: martin.v.loewis Date: Mon Oct 6 17:19:21 2008 New Revision: 66816 Log: Merged revisions 66814 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66814 | martin.v.loewis | 2008-10-06 17:15:40 +0200 (Mo, 06 Okt 2008) | 3 lines Issue #4014: Don't claim that Python has an Alpha release status, in addition to claiming it is Mature. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Misc/NEWS python/branches/py3k/setup.py Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Mon Oct 6 17:19:21 2008 @@ -25,6 +25,9 @@ Library ------- +- Issue #4014: Don't claim that Python has an Alpha release status, in addition + to claiming it is Mature. + - Issue #3187: Add sys.setfilesystemencoding. - Issue #3187: Better support for "undecodable" filenames. Code by Victor Modified: python/branches/py3k/setup.py ============================================================================== --- python/branches/py3k/setup.py (original) +++ python/branches/py3k/setup.py Mon Oct 6 17:19:21 2008 @@ -1489,7 +1489,6 @@ """ CLASSIFIERS = """ -Development Status :: 3 - Alpha Development Status :: 6 - Mature License :: OSI Approved :: Python Software Foundation License Natural Language :: English From python-3000-checkins at python.org Mon Oct 6 23:03:05 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Mon, 6 Oct 2008 23:03:05 +0200 (CEST) Subject: [Python-3000-checkins] r66817 - in python/branches/py3k/Lib/test: regrtest.py test_cProfile.py test_cprofile.py Message-ID: <20081006210305.C89EC1E4002@bag.python.org> Author: benjamin.peterson Date: Mon Oct 6 23:03:05 2008 New Revision: 66817 Log: unbreak test_cprofile Added: python/branches/py3k/Lib/test/test_cprofile.py (contents, props changed) Removed: python/branches/py3k/Lib/test/test_cProfile.py Modified: python/branches/py3k/Lib/test/regrtest.py Modified: python/branches/py3k/Lib/test/regrtest.py ============================================================================== --- python/branches/py3k/Lib/test/regrtest.py (original) +++ python/branches/py3k/Lib/test/regrtest.py Mon Oct 6 23:03:05 2008 @@ -1137,7 +1137,6 @@ # These are broken tests, for now skipped on every platform. # XXX Fix these! - self.expected.add('test_cProfile') self.expected.add('test_nis') # expected to be skipped on every platform, even Linux Deleted: python/branches/py3k/Lib/test/test_cProfile.py ============================================================================== --- python/branches/py3k/Lib/test/test_cProfile.py Mon Oct 6 23:03:05 2008 +++ (empty file) @@ -1,129 +0,0 @@ -"""Test suite for the cProfile module.""" - -import cProfile, pstats, sys - -# In order to have reproducible time, we simulate a timer in the global -# variable 'ticks', which represents simulated time in milliseconds. -# (We can't use a helper function increment the timer since it would be -# included in the profile and would appear to consume all the time.) -ticks = 0 - -# IMPORTANT: this is an output test. *ALL* NUMBERS in the expected -# output are relevant. If you change the formatting of pstats, -# please don't just regenerate output/test_cProfile without checking -# very carefully that not a single number has changed. - -def test_main(): - global ticks - ticks = 42000 - prof = cProfile.Profile(timer, 0.001) - prof.runctx("testfunc()", globals(), locals()) - assert ticks == 43000, ticks - st = pstats.Stats(prof) - st.strip_dirs().sort_stats('stdname').print_stats() - st.print_callees() - st.print_callers() - -def timer(): - return ticks - -def testfunc(): - # 1 call - # 1000 ticks total: 270 ticks local, 730 ticks in subfunctions - global ticks - ticks += 99 - helper() # 300 - helper() # 300 - ticks += 171 - factorial(14) # 130 - -def factorial(n): - # 23 calls total - # 170 ticks total, 150 ticks local - # 3 primitive calls, 130, 20 and 20 ticks total - # including 116, 17, 17 ticks local - global ticks - if n > 0: - ticks += n - return mul(n, factorial(n-1)) - else: - ticks += 11 - return 1 - -def mul(a, b): - # 20 calls - # 1 tick, local - global ticks - ticks += 1 - return a * b - -def helper(): - # 2 calls - # 300 ticks total: 20 ticks local, 260 ticks in subfunctions - global ticks - ticks += 1 - helper1() # 30 - ticks += 2 - helper1() # 30 - ticks += 6 - helper2() # 50 - ticks += 3 - helper2() # 50 - ticks += 2 - helper2() # 50 - ticks += 5 - helper2_indirect() # 70 - ticks += 1 - -def helper1(): - # 4 calls - # 30 ticks total: 29 ticks local, 1 tick in subfunctions - global ticks - ticks += 10 - hasattr(C(), "foo") # 1 - ticks += 19 - lst = [] - lst.append(42) # 0 - sys.exc_info() # 0 - -def helper2_indirect(): - helper2() # 50 - factorial(3) # 20 - -def helper2(): - # 8 calls - # 50 ticks local: 39 ticks local, 11 ticks in subfunctions - global ticks - ticks += 11 - hasattr(C(), "bar") # 1 - ticks += 13 - subhelper() # 10 - ticks += 15 - -def subhelper(): - # 8 calls - # 10 ticks total: 8 ticks local, 2 ticks in subfunctions - global ticks - ticks += 2 - for i in range(2): # 0 - try: - C().foo # 1 x 2 - except AttributeError: - ticks += 3 # 3 x 2 - -class C: - def __getattr__(self, name): - # 28 calls - # 1 tick, local - global ticks - ticks += 1 - raise AttributeError - - -def test_main(): - from test.support import TestSkipped - raise TestSkipped('test_cProfile test is current broken') - - -if __name__ == "__main__": - test_main() Added: python/branches/py3k/Lib/test/test_cprofile.py ============================================================================== --- (empty file) +++ python/branches/py3k/Lib/test/test_cprofile.py Mon Oct 6 23:03:05 2008 @@ -0,0 +1,72 @@ +"""Test suite for the cProfile module.""" + +import sys +from test.support import run_unittest + +# rip off all interesting stuff from test_profile +import cProfile +from test.test_profile import ProfileTest, regenerate_expected_output + +class CProfileTest(ProfileTest): + profilerclass = cProfile.Profile + + +def test_main(): + run_unittest(CProfileTest) + +def main(): + if '-r' not in sys.argv: + test_main() + else: + regenerate_expected_output(__file__, CProfileTest) + + +# Don't remove this comment. Everything below it is auto-generated. +#--cut-------------------------------------------------------------------------- +CProfileTest.expected_output['print_stats'] = """\ + 28 0.028 0.001 0.028 0.001 profilee.py:110(__getattr__) + 1 0.270 0.270 1.000 1.000 profilee.py:25(testfunc) + 23/3 0.150 0.007 0.170 0.057 profilee.py:35(factorial) + 20 0.020 0.001 0.020 0.001 profilee.py:48(mul) + 2 0.040 0.020 0.600 0.300 profilee.py:55(helper) + 4 0.116 0.029 0.120 0.030 profilee.py:73(helper1) + 2 0.000 0.000 0.140 0.070 profilee.py:84(helper2_indirect) + 8 0.312 0.039 0.400 0.050 profilee.py:88(helper2) + 8 0.064 0.008 0.080 0.010 profilee.py:98(subhelper)""" +CProfileTest.expected_output['print_callers'] = """\ +profilee.py:110(__getattr__) <- 16 0.016 0.016 profilee.py:98(subhelper) +profilee.py:25(testfunc) <- 1 0.270 1.000 :1() +profilee.py:35(factorial) <- 1 0.014 0.130 profilee.py:25(testfunc) + 20/3 0.130 0.147 profilee.py:35(factorial) + 2 0.006 0.040 profilee.py:84(helper2_indirect) +profilee.py:48(mul) <- 20 0.020 0.020 profilee.py:35(factorial) +profilee.py:55(helper) <- 2 0.040 0.600 profilee.py:25(testfunc) +profilee.py:73(helper1) <- 4 0.116 0.120 profilee.py:55(helper) +profilee.py:84(helper2_indirect) <- 2 0.000 0.140 profilee.py:55(helper) +profilee.py:88(helper2) <- 6 0.234 0.300 profilee.py:55(helper) + 2 0.078 0.100 profilee.py:84(helper2_indirect) +profilee.py:98(subhelper) <- 8 0.064 0.080 profilee.py:88(helper2) +{built-in method exc_info} <- 4 0.000 0.000 profilee.py:73(helper1) +{built-in method hasattr} <- 4 0.000 0.004 profilee.py:73(helper1) + 8 0.000 0.008 profilee.py:88(helper2) +{method 'append' of 'list' objects} <- 4 0.000 0.000 profilee.py:73(helper1)""" +CProfileTest.expected_output['print_callees'] = """\ +:1() -> 1 0.270 1.000 profilee.py:25(testfunc) +profilee.py:110(__getattr__) -> +profilee.py:25(testfunc) -> 1 0.014 0.130 profilee.py:35(factorial) + 2 0.040 0.600 profilee.py:55(helper) +profilee.py:35(factorial) -> 20/3 0.130 0.147 profilee.py:35(factorial) + 20 0.020 0.020 profilee.py:48(mul) +profilee.py:48(mul) -> +profilee.py:55(helper) -> 4 0.116 0.120 profilee.py:73(helper1) + 2 0.000 0.140 profilee.py:84(helper2_indirect) + 6 0.234 0.300 profilee.py:88(helper2) +profilee.py:73(helper1) -> 4 0.000 0.000 {built-in method exc_info} +profilee.py:84(helper2_indirect) -> 2 0.006 0.040 profilee.py:35(factorial) + 2 0.078 0.100 profilee.py:88(helper2) +profilee.py:88(helper2) -> 8 0.064 0.080 profilee.py:98(subhelper) +profilee.py:98(subhelper) -> 16 0.016 0.016 profilee.py:110(__getattr__) +{built-in method hasattr} -> 12 0.012 0.012 profilee.py:110(__getattr__)""" + +if __name__ == "__main__": + main() From python-3000-checkins at python.org Tue Oct 7 00:05:00 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 7 Oct 2008 00:05:00 +0200 (CEST) Subject: [Python-3000-checkins] r66818 - in python/branches/py3k/Lib/test: test_cprofile.py test_profile.py Message-ID: <20081006220500.B1D2E1E4002@bag.python.org> Author: benjamin.peterson Date: Tue Oct 7 00:05:00 2008 New Revision: 66818 Log: a trival fix to let test_profile pass if it runs after test_cprofile Modified: python/branches/py3k/Lib/test/test_cprofile.py python/branches/py3k/Lib/test/test_profile.py Modified: python/branches/py3k/Lib/test/test_cprofile.py ============================================================================== --- python/branches/py3k/Lib/test/test_cprofile.py (original) +++ python/branches/py3k/Lib/test/test_cprofile.py Tue Oct 7 00:05:00 2008 @@ -10,6 +10,9 @@ class CProfileTest(ProfileTest): profilerclass = cProfile.Profile + def get_expected_output(self): + return _ProfileOutput + def test_main(): run_unittest(CProfileTest) @@ -23,7 +26,8 @@ # Don't remove this comment. Everything below it is auto-generated. #--cut-------------------------------------------------------------------------- -CProfileTest.expected_output['print_stats'] = """\ +_ProfileOutput = {} +_ProfileOutput['print_stats'] = """\ 28 0.028 0.001 0.028 0.001 profilee.py:110(__getattr__) 1 0.270 0.270 1.000 1.000 profilee.py:25(testfunc) 23/3 0.150 0.007 0.170 0.057 profilee.py:35(factorial) @@ -33,7 +37,7 @@ 2 0.000 0.000 0.140 0.070 profilee.py:84(helper2_indirect) 8 0.312 0.039 0.400 0.050 profilee.py:88(helper2) 8 0.064 0.008 0.080 0.010 profilee.py:98(subhelper)""" -CProfileTest.expected_output['print_callers'] = """\ +_ProfileOutput['print_callers'] = """\ profilee.py:110(__getattr__) <- 16 0.016 0.016 profilee.py:98(subhelper) profilee.py:25(testfunc) <- 1 0.270 1.000 :1() profilee.py:35(factorial) <- 1 0.014 0.130 profilee.py:25(testfunc) @@ -50,7 +54,7 @@ {built-in method hasattr} <- 4 0.000 0.004 profilee.py:73(helper1) 8 0.000 0.008 profilee.py:88(helper2) {method 'append' of 'list' objects} <- 4 0.000 0.000 profilee.py:73(helper1)""" -CProfileTest.expected_output['print_callees'] = """\ +_ProfileOutput['print_callees'] = """\ :1() -> 1 0.270 1.000 profilee.py:25(testfunc) profilee.py:110(__getattr__) -> profilee.py:25(testfunc) -> 1 0.014 0.130 profilee.py:35(factorial) Modified: python/branches/py3k/Lib/test/test_profile.py ============================================================================== --- python/branches/py3k/Lib/test/test_profile.py (original) +++ python/branches/py3k/Lib/test/test_profile.py Tue Oct 7 00:05:00 2008 @@ -16,7 +16,9 @@ profilerclass = profile.Profile methodnames = ['print_stats', 'print_callers', 'print_callees'] - expected_output = {} + + def get_expected_output(self): + return _ProfileOutput @classmethod def do_profiling(cls): @@ -41,14 +43,15 @@ def test_cprofile(self): results = self.do_profiling() + expected = self.get_expected_output() self.assertEqual(results[0], 1000) for i, method in enumerate(self.methodnames): - if results[i+1] != self.expected_output[method]: + if results[i+1] != expected[method]: print("Stats.%s output for %s doesn't fit expectation!" % (method, self.profilerclass.__name__)) print('\n'.join(unified_diff( results[i+1].split('\n'), - self.expected_output[method].split('\n')))) + expected[method].split('\n')))) def regenerate_expected_output(filename, cls): @@ -65,9 +68,10 @@ with open(filename, 'w') as f: f.writelines(newfile) + f.write("_ProfileOutput = {}\n") for i, method in enumerate(cls.methodnames): - f.write('%s.expected_output[%r] = """\\\n%s"""\n' % ( - cls.__name__, method, results[i+1])) + f.write('_ProfileOutput[%r] = """\\\n%s"""\n' % ( + method, results[i+1])) f.write('\nif __name__ == "__main__":\n main()\n') @@ -83,7 +87,8 @@ # Don't remove this comment. Everything below it is auto-generated. #--cut-------------------------------------------------------------------------- -ProfileTest.expected_output['print_stats'] = """\ +_ProfileOutput = {} +_ProfileOutput['print_stats'] = """\ 28 27.972 0.999 27.972 0.999 profilee.py:110(__getattr__) 1 269.996 269.996 999.769 999.769 profilee.py:25(testfunc) 23/3 149.937 6.519 169.917 56.639 profilee.py:35(factorial) @@ -93,7 +98,7 @@ 2 -0.006 -0.003 139.946 69.973 profilee.py:84(helper2_indirect) 8 311.976 38.997 399.912 49.989 profilee.py:88(helper2) 8 63.976 7.997 79.960 9.995 profilee.py:98(subhelper)""" -ProfileTest.expected_output['print_callers'] = """\ +_ProfileOutput['print_callers'] = """\ :0(append) <- profilee.py:73(helper1)(4) 119.964 :0(exc_info) <- profilee.py:73(helper1)(4) 119.964 :0(hasattr) <- profilee.py:73(helper1)(4) 119.964 @@ -111,7 +116,7 @@ profilee.py:88(helper2) <- profilee.py:55(helper)(6) 599.830 profilee.py:84(helper2_indirect)(2) 139.946 profilee.py:98(subhelper) <- profilee.py:88(helper2)(8) 399.912""" -ProfileTest.expected_output['print_callees'] = """\ +_ProfileOutput['print_callees'] = """\ :0(hasattr) -> profilee.py:110(__getattr__)(12) 27.972 :1() -> profilee.py:25(testfunc)(1) 999.769 profilee.py:110(__getattr__) -> From python-3000-checkins at python.org Tue Oct 7 00:48:12 2008 From: python-3000-checkins at python.org (brett.cannon) Date: Tue, 7 Oct 2008 00:48:12 +0200 (CEST) Subject: [Python-3000-checkins] r66821 - in python/branches/py3k: Makefile.pre.in Message-ID: <20081006224812.3DC241E4002@bag.python.org> Author: brett.cannon Date: Tue Oct 7 00:48:11 2008 New Revision: 66821 Log: Merged revisions 66819 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66819 | brett.cannon | 2008-10-06 15:44:37 -0700 (Mon, 06 Oct 2008) | 4 lines Add the 'patchcheck' build target to .PHONY. Re-closes issue 3758. Thanks to Ralph Corderoy for the catch. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Makefile.pre.in Modified: python/branches/py3k/Makefile.pre.in ============================================================================== --- python/branches/py3k/Makefile.pre.in (original) +++ python/branches/py3k/Makefile.pre.in Tue Oct 7 00:48:11 2008 @@ -1205,6 +1205,6 @@ .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools .PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean -.PHONY: smelly funny +.PHONY: smelly funny patchcheck # IF YOU PUT ANYTHING HERE IT WILL GO AWAY From python-3000-checkins at python.org Tue Oct 7 04:22:25 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 7 Oct 2008 04:22:25 +0200 (CEST) Subject: [Python-3000-checkins] r66826 - python/branches/py3k Message-ID: <20081007022225.137981E4002@bag.python.org> Author: benjamin.peterson Date: Tue Oct 7 04:22:24 2008 New Revision: 66826 Log: Unblocked revisions 66677 via svnmerge ........ r66677 | brett.cannon | 2008-09-28 22:41:21 -0500 (Sun, 28 Sep 2008) | 7 lines The _lsprof module could crash the interpreter if it was given an external timer that did not return a float and a timer was still running when the Profiler object was garbage collected. Fixes issue 3895. Code review by Benjamin Peterson. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Tue Oct 7 04:33:00 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 7 Oct 2008 04:33:00 +0200 (CEST) Subject: [Python-3000-checkins] r66827 - in python/branches/py3k: Lib/test/test_cprofile.py Modules/_lsprof.c Message-ID: <20081007023300.508FB1E4002@bag.python.org> Author: benjamin.peterson Date: Tue Oct 7 04:32:59 2008 New Revision: 66827 Log: Merged revisions 66677,66700 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66677 | brett.cannon | 2008-09-28 22:41:21 -0500 (Sun, 28 Sep 2008) | 7 lines The _lsprof module could crash the interpreter if it was given an external timer that did not return a float and a timer was still running when the Profiler object was garbage collected. Fixes issue 3895. Code review by Benjamin Peterson. ........ r66700 | brett.cannon | 2008-09-30 12:46:03 -0500 (Tue, 30 Sep 2008) | 5 lines Fix a refleak introduced by r66677. Fix suggested by Amaury Forgeot d'Arc. Closes issue #4003. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/test/test_cprofile.py python/branches/py3k/Modules/_lsprof.c Modified: python/branches/py3k/Lib/test/test_cprofile.py ============================================================================== --- python/branches/py3k/Lib/test/test_cprofile.py (original) +++ python/branches/py3k/Lib/test/test_cprofile.py Tue Oct 7 04:32:59 2008 @@ -1,7 +1,7 @@ """Test suite for the cProfile module.""" import sys -from test.support import run_unittest +from test.support import run_unittest, TESTFN, unlink # rip off all interesting stuff from test_profile import cProfile @@ -13,6 +13,20 @@ def get_expected_output(self): return _ProfileOutput + # Issue 3895. + def test_bad_counter_during_dealloc(self): + import _lsprof + # Must use a file as StringIO doesn't trigger the bug. + sys.stderr = open(TESTFN, 'w') + try: + obj = _lsprof.Profiler(lambda: int) + obj.enable() + obj = _lsprof.Profiler(1) + obj.disable() + finally: + sys.stderr = sys.__stderr__ + unlink(TESTFN) + def test_main(): run_unittest(CProfileTest) Modified: python/branches/py3k/Modules/_lsprof.c ============================================================================== --- python/branches/py3k/Modules/_lsprof.c (original) +++ python/branches/py3k/Modules/_lsprof.c Tue Oct 7 04:32:59 2008 @@ -150,7 +150,7 @@ } Py_DECREF(o); if (PyErr_Occurred()) { - PyErr_WriteUnraisable((PyObject *) pObj); + PyErr_WriteUnraisable(pObj->externalTimer); return 0; } return result; From python-3000-checkins at python.org Tue Oct 7 04:51:48 2008 From: python-3000-checkins at python.org (skip.montanaro) Date: Tue, 7 Oct 2008 04:51:48 +0200 (CEST) Subject: [Python-3000-checkins] r66828 - python/branches/py3k/setup.py Message-ID: <20081007025148.563591E4002@bag.python.org> Author: skip.montanaro Date: Tue Oct 7 04:51:48 2008 New Revision: 66828 Log: merge from trunk Modified: python/branches/py3k/setup.py Modified: python/branches/py3k/setup.py ============================================================================== --- python/branches/py3k/setup.py (original) +++ python/branches/py3k/setup.py Tue Oct 7 04:51:48 2008 @@ -319,12 +319,13 @@ # the environment variable is not set even though the value were passed # into configure and stored in the Makefile (issue found on OS X 10.3). for env_var, arg_name, dir_list in ( + ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), ('LDFLAGS', '-L', self.compiler.library_dirs), ('CPPFLAGS', '-I', self.compiler.include_dirs)): env_val = sysconfig.get_config_var(env_var) if env_val: # To prevent optparse from raising an exception about any - # options in env_val that is doesn't know about we strip out + # options in env_val that it doesn't know about we strip out # all double dashes and any dashes followed by a character # that is not for the option we are dealing with. # From python-3000-checkins at python.org Tue Oct 7 08:36:32 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Tue, 7 Oct 2008 08:36:32 +0200 (CEST) Subject: [Python-3000-checkins] r66829 - python/branches/py3k/Doc/library/os.rst Message-ID: <20081007063632.28D421E4002@bag.python.org> Author: martin.v.loewis Date: Tue Oct 7 08:36:31 2008 New Revision: 66829 Log: Patch #3187 (file 11721): Document byte vs. string parameters and results. Modified: python/branches/py3k/Doc/library/os.rst Modified: python/branches/py3k/Doc/library/os.rst ============================================================================== --- python/branches/py3k/Doc/library/os.rst (original) +++ python/branches/py3k/Doc/library/os.rst Tue Oct 7 08:36:31 2008 @@ -693,13 +693,13 @@ .. function:: getcwd() - Return a bytestring representing the current working directory. + Return a string representing the current working directory. Availability: Unix, Windows. -.. function:: getcwdu() +.. function:: getcwdb() - Return a string representing the current working directory. + Return a bytestring representing the current working directory. Availability: Unix, Windows. @@ -801,8 +801,10 @@ ``'..'`` even if they are present in the directory. Availability: Unix, Windows. - On Windows NT/2k/XP and Unix, if *path* is a Unicode object, the result will be - a list of Unicode objects. + If *path* is a Unicode object, the result will be a list of Unicode objects. + If a filename can not be decoded to unicode, it is skipped. If *path* is a + bytes string, the result will be list of bytes objects included files + skipped by the unicode version. .. function:: lstat(path) @@ -916,7 +918,9 @@ be converted to an absolute pathname using ``os.path.join(os.path.dirname(path), result)``. - If the *path* is a Unicode object, the result will also be a Unicode object. + If the *path* is an Unicode object, the result will also be a Unicode object + and may raise an UnicodeDecodeError. If the *path* is a bytes object, the + result will be a bytes object. Availability: Unix. From python-3000-checkins at python.org Tue Oct 7 09:03:04 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Tue, 7 Oct 2008 09:03:04 +0200 (CEST) Subject: [Python-3000-checkins] r66830 - in python/branches/py3k/Doc/library: functions.rst os.path.rst os.rst Message-ID: <20081007070304.E3E611E4002@bag.python.org> Author: martin.v.loewis Date: Tue Oct 7 09:03:04 2008 New Revision: 66830 Log: More bytes vs. strings documentation. Modified: python/branches/py3k/Doc/library/functions.rst python/branches/py3k/Doc/library/os.path.rst python/branches/py3k/Doc/library/os.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 Oct 7 09:03:04 2008 @@ -710,10 +710,11 @@ Open a file. If the file cannot be opened, :exc:`IOError` is raised. - *file* is either a string giving the name (and the path if the file isn't in - the current working directory) of the file to be opened or an integer file - descriptor of the file to be wrapped. (If a file descriptor is given, it is - closed when the returned I/O object is closed, unless *closefd* is set to + *file* is either a string or bytes object giving the name (and the + path if the file isn't in the current working directory) of the + file to be opened or an integer file descriptor of the file to be + wrapped. (If a file descriptor is given, it is closed when the + returned I/O object is closed, unless *closefd* is set to ``False``.) *mode* is an optional string that specifies the mode in which the file is Modified: python/branches/py3k/Doc/library/os.path.rst ============================================================================== --- python/branches/py3k/Doc/library/os.path.rst (original) +++ python/branches/py3k/Doc/library/os.path.rst Tue Oct 7 09:03:04 2008 @@ -10,7 +10,14 @@ This module implements some useful functions on pathnames. To read or write files see :func:`open`, and for accessing the filesystem see the -:mod:`os` module. +:mod:`os` module. The path parameters can be passed as either strings, +or bytes. Applications are encouraged to represent file names as +(Unicode) character strings. Unfortunately, some file names may not be +representable as strings on Unix, so applications that need to support +arbitrary file names on Unix should use bytes objects to represent +path names. Vice versa, using bytes objects cannot represent all file +names on Windows (in the standard ``mbcs`` encoding), hence Windows +applications should use string objects to access all files. .. warning:: Modified: python/branches/py3k/Doc/library/os.rst ============================================================================== --- python/branches/py3k/Doc/library/os.rst (original) +++ python/branches/py3k/Doc/library/os.rst Tue Oct 7 09:03:04 2008 @@ -694,6 +694,8 @@ .. function:: getcwd() Return a string representing the current working directory. + May raise UnicodeDecodeError if the current directory path fails + to decode in the file system encoding. Availability: Unix, Windows. From python-3000-checkins at python.org Tue Oct 7 15:16:29 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Tue, 7 Oct 2008 15:16:29 +0200 (CEST) Subject: [Python-3000-checkins] r66831 - in python/branches/py3k: Misc/NEWS Objects/moduleobject.c Message-ID: <20081007131629.5305D1E4002@bag.python.org> Author: martin.v.loewis Date: Tue Oct 7 15:16:28 2008 New Revision: 66831 Log: Issue #3740: Null-initialize module state. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Objects/moduleobject.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Tue Oct 7 15:16:28 2008 @@ -15,6 +15,8 @@ Core and Builtins ----------------- +- Issue #3740: Null-initialize module state. + - Issue #3946: PyObject_CheckReadBuffer crashed on a memoryview object. - Issue #1688: On Windows, the input() prompt was not correctly displayed if it Modified: python/branches/py3k/Objects/moduleobject.c ============================================================================== --- python/branches/py3k/Objects/moduleobject.c (original) +++ python/branches/py3k/Objects/moduleobject.c Tue Oct 7 15:16:28 2008 @@ -113,6 +113,7 @@ Py_DECREF(m); return NULL; } + memset(m->md_state, 0, module->m_size); } d = PyModule_GetDict((PyObject*)m); From python-3000-checkins at python.org Tue Oct 7 23:06:18 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Tue, 7 Oct 2008 23:06:18 +0200 (CEST) Subject: [Python-3000-checkins] r66838 - in python/branches/py3k: Modules/python.c Python/frozenmain.c Message-ID: <20081007210618.568A81E4002@bag.python.org> Author: amaury.forgeotdarc Date: Tue Oct 7 23:06:18 2008 New Revision: 66838 Log: #4004: Missing newline in some startup error messages. Patch by Victor. Modified: python/branches/py3k/Modules/python.c python/branches/py3k/Python/frozenmain.c Modified: python/branches/py3k/Modules/python.c ============================================================================== --- python/branches/py3k/Modules/python.c (original) +++ python/branches/py3k/Modules/python.c Tue Oct 7 23:06:18 2008 @@ -34,7 +34,7 @@ fpsetmask(m & ~FP_X_OFL); #endif if (!argv_copy || !argv_copy2) { - fprintf(stderr, "out of memory"); + fprintf(stderr, "out of memory\n"); return 1; } oldloc = setlocale(LC_ALL, NULL); @@ -51,18 +51,18 @@ #endif size_t count; if (argsize == (size_t)-1) { - fprintf(stderr, "Could not convert argument %d to string", i); + fprintf(stderr, "Could not convert argument %d to string\n", i); return 1; } argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); argv_copy2[i] = argv_copy[i]; if (!argv_copy[i]) { - fprintf(stderr, "out of memory"); + fprintf(stderr, "out of memory\n"); return 1; } count = mbstowcs(argv_copy[i], argv[i], argsize+1); if (count == (size_t)-1) { - fprintf(stderr, "Could not convert argument %d to string", i); + fprintf(stderr, "Could not convert argument %d to string\n", i); return 1; } } Modified: python/branches/py3k/Python/frozenmain.c ============================================================================== --- python/branches/py3k/Python/frozenmain.c (original) +++ python/branches/py3k/Python/frozenmain.c Tue Oct 7 23:06:18 2008 @@ -38,7 +38,7 @@ } if (!argv_copy) { - fprintf(stderr, "out of memory"); + fprintf(stderr, "out of memory\n"); return 1; } @@ -52,18 +52,18 @@ #endif size_t count; if (argsize == (size_t)-1) { - fprintf(stderr, "Could not convert argument %d to string", i); + fprintf(stderr, "Could not convert argument %d to string\n", i); return 1; } argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); argv_copy2[i] = argv_copy[i]; if (!argv_copy[i]) { - fprintf(stderr, "out of memory"); + fprintf(stderr, "out of memory\n"); return 1; } count = mbstowcs(argv_copy[i], argv[i], argsize+1); if (count == (size_t)-1) { - fprintf(stderr, "Could not convert argument %d to string", i); + fprintf(stderr, "Could not convert argument %d to string\n", i); return 1; } } From python-3000-checkins at python.org Tue Oct 7 23:27:43 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Tue, 7 Oct 2008 23:27:43 +0200 (CEST) Subject: [Python-3000-checkins] r66839 - python/branches/py3k/Include/intobject.h Message-ID: <20081007212743.7F9661E4002@bag.python.org> Author: amaury.forgeotdarc Date: Tue Oct 7 23:27:43 2008 New Revision: 66839 Log: The #warning directive is a gcc extension to standard C, and Microsoft compilers spells it differently. Modified: python/branches/py3k/Include/intobject.h Modified: python/branches/py3k/Include/intobject.h ============================================================================== --- python/branches/py3k/Include/intobject.h (original) +++ python/branches/py3k/Include/intobject.h Tue Oct 7 23:27:43 2008 @@ -11,7 +11,11 @@ extern "C" { #endif +#if defined(__GNUC__) #warning "DeprecationWarning: intobject.h is going to be removed in 3.1" +#elif defined(MS_WINDOWS) +#pragma message("DeprecationWarning: intobject.h is going to be removed in 3.1") +#endif #define PyInt_Check(op) PyLong_Check(op) #define PyInt_FromString PyLong_FromString From python-3000-checkins at python.org Wed Oct 8 18:34:57 2008 From: python-3000-checkins at python.org (georg.brandl) Date: Wed, 8 Oct 2008 18:34:57 +0200 (CEST) Subject: [Python-3000-checkins] r66853 - in python/branches/py3k/Doc/library: functions.rst os.path.rst os.rst Message-ID: <20081008163457.9298F1E4002@bag.python.org> Author: georg.brandl Date: Wed Oct 8 18:34:57 2008 New Revision: 66853 Log: Some more notes about bytes/string filename APIs. Modified: python/branches/py3k/Doc/library/functions.rst python/branches/py3k/Doc/library/os.path.rst python/branches/py3k/Doc/library/os.rst Modified: python/branches/py3k/Doc/library/functions.rst ============================================================================== --- python/branches/py3k/Doc/library/functions.rst (original) +++ python/branches/py3k/Doc/library/functions.rst Wed Oct 8 18:34:57 2008 @@ -710,12 +710,11 @@ Open a file. If the file cannot be opened, :exc:`IOError` is raised. - *file* is either a string or bytes object giving the name (and the - path if the file isn't in the current working directory) of the - file to be opened or an integer file descriptor of the file to be - wrapped. (If a file descriptor is given, it is closed when the - returned I/O object is closed, unless *closefd* is set to - ``False``.) + *file* is either a string or bytes object giving the name (and the path if + the file isn't in the current working directory) of the file to be opened or + an integer file descriptor of the file to be wrapped. (If a file descriptor + is given, it is closed when the returned I/O object is closed, unless + *closefd* is set to ``False``.) *mode* is an optional string that specifies the mode in which the file is opened. It defaults to ``'r'`` which means open for reading in text mode. Modified: python/branches/py3k/Doc/library/os.path.rst ============================================================================== --- python/branches/py3k/Doc/library/os.path.rst (original) +++ python/branches/py3k/Doc/library/os.path.rst Wed Oct 8 18:34:57 2008 @@ -19,6 +19,12 @@ names on Windows (in the standard ``mbcs`` encoding), hence Windows applications should use string objects to access all files. +.. note:: + + All of these functions accept either only bytes or only string objects as + their parameters. The result is an object of the same type, if a path or + file name is returned. + .. warning:: On Windows, many of these functions do not properly support UNC pathnames. Modified: python/branches/py3k/Doc/library/os.rst ============================================================================== --- python/branches/py3k/Doc/library/os.rst (original) +++ python/branches/py3k/Doc/library/os.rst Wed Oct 8 18:34:57 2008 @@ -24,6 +24,12 @@ .. note:: + All functions accepting path or file names accept both bytes and string + objects, and result in an object of the same type, if a path or file name is + returned. + +.. note:: + If not separately noted, all functions that claim "Availability: Unix" are supported on Mac OS X, which builds on a Unix core. @@ -693,15 +699,16 @@ .. function:: getcwd() - Return a string representing the current working directory. - May raise UnicodeDecodeError if the current directory path fails - to decode in the file system encoding. - Availability: Unix, Windows. + Return a string representing the current working directory. On Unix + platforms, this function may raise :exc:`UnicodeDecodeError` if the name of + the current directory is not decodable in the file system encoding. Use + :func:`getcwdb` if you need the call to never fail. Availability: Unix, + Windows. .. function:: getcwdb() - Return a bytestring representing the current working directory. + Return a bytestring representing the current working directory. Availability: Unix, Windows. @@ -798,15 +805,15 @@ .. 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. 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. - If *path* is a Unicode object, the result will be a list of Unicode objects. - If a filename can not be decoded to unicode, it is skipped. If *path* is a - bytes string, the result will be list of bytes objects included files - skipped by the unicode version. + 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 + string case, filenames will be decoded using the file system encoding, and + skipped if a decoding error occurs. .. function:: lstat(path) @@ -920,9 +927,9 @@ be converted to an absolute pathname using ``os.path.join(os.path.dirname(path), result)``. - If the *path* is an Unicode object, the result will also be a Unicode object - and may raise an UnicodeDecodeError. If the *path* is a bytes object, the - result will be a bytes object. + If the *path* is a string object, the result will also be a string object, + and the call may raise an UnicodeDecodeError. If the *path* is a bytes + object, the result will be a bytes object. Availability: Unix. From nnorwitz at gmail.com Wed Oct 8 14:46:23 2008 From: nnorwitz at gmail.com (Neal Norwitz) Date: Wed, 8 Oct 2008 08:46:23 -0400 Subject: [Python-3000-checkins] Python Regression Test Failures doc (1) Message-ID: <20081008124623.GA23226@python.psfb.org> svn update tools/sphinx svn: PROPFIND request failed on '/projects/doctools/trunk/sphinx' svn: PROPFIND of '/projects/doctools/trunk/sphinx': could not connect to server (http://svn.python.org) make: *** [update] Error 1 From python-3000-checkins at python.org Fri Oct 10 01:37:49 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 10 Oct 2008 01:37:49 +0200 (CEST) Subject: [Python-3000-checkins] r66867 - in python/branches/py3k: Lib/test/test_traceback.py Misc/NEWS Parser/tokenizer.c Python/traceback.c Message-ID: <20081009233749.BE37E1E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 10 01:37:48 2008 New Revision: 66867 Log: Issues #2384 and #3975: Tracebacks were not correctly printed when the source file contains a ``coding:`` header: the wrong line was displayed, and the encoding was not respected. Patch by Victor Stinner. Modified: python/branches/py3k/Lib/test/test_traceback.py python/branches/py3k/Misc/NEWS python/branches/py3k/Parser/tokenizer.c python/branches/py3k/Python/traceback.c Modified: python/branches/py3k/Lib/test/test_traceback.py ============================================================================== --- python/branches/py3k/Lib/test/test_traceback.py (original) +++ python/branches/py3k/Lib/test/test_traceback.py Fri Oct 10 01:37:48 2008 @@ -6,6 +6,7 @@ import unittest import re from test.support import run_unittest, is_jython, Error, captured_output +from test.support import TESTFN, unlink import traceback @@ -90,6 +91,70 @@ err = traceback.format_exception_only(None, None) self.assertEqual(err, ['None\n']) + def test_encoded_file(self): + # Test that tracebacks are correctly printed for encoded source files: + # - correct line number (Issue2384) + # - respect file encoding (Issue3975) + import tempfile, sys, subprocess, os + + # The spawned subprocess has its stdout redirected to a PIPE, and its + # encoding may be different from the current interpreter, on Windows + # at least. + process = subprocess.Popen([sys.executable, "-c", + "import sys; print(sys.stdout.encoding)"], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + stdout, stderr = process.communicate() + output_encoding = str(stdout, 'ascii').splitlines()[0] + + def do_test(firstlines, message, charset, lineno): + # Raise the message in a subprocess, and catch the output + try: + output = open(TESTFN, "w", encoding=charset) + output.write("""{0}if 1: + import traceback; + raise RuntimeError('{1}') + """.format(firstlines, message)) + output.close() + process = subprocess.Popen([sys.executable, TESTFN], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout, stderr = process.communicate() + stdout = stdout.decode(output_encoding).splitlines() + finally: + unlink(TESTFN) + + # The source lines are encoded with the 'backslashreplace' handler + encoded_message = message.encode(output_encoding, + 'backslashreplace') + # and we just decoded them with the output_encoding. + message_ascii = encoded_message.decode(output_encoding) + + err_line = "raise RuntimeError('{0}')".format(message_ascii) + err_msg = "RuntimeError: {0}".format(message_ascii) + + self.assert_(("line %s" % lineno) in stdout[1], + "Invalid line number: {0!r} instead of {1}".format( + stdout[1], lineno)) + self.assert_(stdout[2].endswith(err_line), + "Invalid traceback line: {0!r} instead of {1!r}".format( + stdout[2], err_line)) + self.assert_(stdout[3] == err_msg, + "Invalid error message: {0!r} instead of {1!r}".format( + stdout[3], err_msg)) + + do_test("", "foo", "ascii", 3) + for charset in ("ascii", "iso-8859-1", "utf-8", "GBK"): + if charset == "ascii": + text = "foo" + elif charset == "GBK": + text = "\u4E02\u5100" + else: + text = "h\xe9 ho" + do_test("# coding: {0}\n".format(charset), + text, charset, 4) + do_test("#!shebang\n# coding: {0}\n".format(charset), + text, charset, 5) + class TracebackFormatTests(unittest.TestCase): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Oct 10 01:37:48 2008 @@ -15,6 +15,10 @@ Core and Builtins ----------------- +- Issues #2384 and #3975: Tracebacks were not correctly printed when the + source file contains a ``coding:`` header: the wrong line was displayed, and + the encoding was not respected. + - Issue #3740: Null-initialize module state. - Issue #3946: PyObject_CheckReadBuffer crashed on a memoryview object. Modified: python/branches/py3k/Parser/tokenizer.c ============================================================================== --- python/branches/py3k/Parser/tokenizer.c (original) +++ python/branches/py3k/Parser/tokenizer.c Fri Oct 10 01:37:48 2008 @@ -461,6 +461,14 @@ readline = PyObject_GetAttrString(stream, "readline"); tok->decoding_readline = readline; + /* The file has been reopened; parsing will restart from + * the beginning of the file, we have to reset the line number. + * But this function has been called from inside tok_nextc() which + * will increment lineno before it returns. So we set it -1 so that + * the next call to tok_nextc() will start with tok->lineno == 0. + */ + tok->lineno = -1; + cleanup: Py_XDECREF(stream); Py_XDECREF(io); Modified: python/branches/py3k/Python/traceback.c ============================================================================== --- python/branches/py3k/Python/traceback.c (original) +++ python/branches/py3k/Python/traceback.c Fri Oct 10 01:37:48 2008 @@ -8,9 +8,15 @@ #include "structmember.h" #include "osdefs.h" #include "traceback.h" +#ifdef HAVE_FCNTL_H +#include +#endif #define OFF(x) offsetof(PyTracebackObject, x) +/* Method from Parser/tokenizer.c */ +extern char * PyTokenizer_FindEncoding(int); + static PyObject * tb_dir(PyTracebackObject *self) { @@ -128,102 +134,156 @@ return 0; } +static int +_Py_FindSourceFile(const char* filename, char* namebuf, size_t namelen, int open_flags) +{ + int i; + int fd = -1; + PyObject *v; + Py_ssize_t _npath; + int npath; + size_t taillen; + PyObject *syspath; + const char* path; + const char* tail; + Py_ssize_t len; + + /* Search tail of filename in sys.path before giving up */ + tail = strrchr(filename, SEP); + if (tail == NULL) + tail = filename; + else + tail++; + taillen = strlen(tail); + + syspath = PySys_GetObject("path"); + if (syspath == NULL || !PyList_Check(syspath)) + return -1; + _npath = PyList_Size(syspath); + npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int); + + for (i = 0; i < npath; i++) { + v = PyList_GetItem(syspath, i); + if (v == NULL) { + PyErr_Clear(); + break; + } + if (!PyUnicode_Check(v)) + continue; + path = _PyUnicode_AsStringAndSize(v, &len); + if (len + 1 + taillen >= (Py_ssize_t)namelen - 1) + continue; /* Too long */ + strcpy(namebuf, path); + if (strlen(namebuf) != len) + continue; /* v contains '\0' */ + if (len > 0 && namebuf[len-1] != SEP) + namebuf[len++] = SEP; + strcpy(namebuf+len, tail); + Py_BEGIN_ALLOW_THREADS + fd = open(namebuf, open_flags); + Py_END_ALLOW_THREADS + if (0 <= fd) { + return fd; + } + } + return -1; +} + int _Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent) { int err = 0; - FILE *xfp = NULL; - char linebuf[2000]; + int fd; int i; - char namebuf[MAXPATHLEN+1]; + char *found_encoding; + char *encoding; + PyObject *fob = NULL; + PyObject *lineobj = NULL; +#ifdef O_BINARY + const int open_flags = O_RDONLY | O_BINARY; /* necessary for Windows */ +#else + const int open_flags = O_RDONLY; +#endif + char buf[MAXPATHLEN+1]; + Py_UNICODE *u, *p; + Py_ssize_t len; + /* open the file */ if (filename == NULL) - return -1; - xfp = fopen(filename, "r" PY_STDIOTEXTMODE); - if (xfp == NULL) { - /* Search tail of filename in sys.path before giving up */ - PyObject *path; - const char *tail = strrchr(filename, SEP); - if (tail == NULL) - tail = filename; - else - tail++; - path = PySys_GetObject("path"); - if (path != NULL && PyList_Check(path)) { - Py_ssize_t _npath = PyList_Size(path); - int npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int); - size_t taillen = strlen(tail); - for (i = 0; i < npath; i++) { - PyObject *v = PyList_GetItem(path, i); - if (v == NULL) { - PyErr_Clear(); - break; - } - if (PyBytes_Check(v)) { - size_t len; - len = PyBytes_GET_SIZE(v); - if (len + 1 + taillen >= MAXPATHLEN) - continue; /* Too long */ - strcpy(namebuf, PyBytes_AsString(v)); - if (strlen(namebuf) != len) - continue; /* v contains '\0' */ - if (len > 0 && namebuf[len-1] != SEP) - namebuf[len++] = SEP; - strcpy(namebuf+len, tail); - xfp = fopen(namebuf, "r" PY_STDIOTEXTMODE); - if (xfp != NULL) { - filename = namebuf; - break; - } - } - } - } + return 0; + Py_BEGIN_ALLOW_THREADS + fd = open(filename, open_flags); + Py_END_ALLOW_THREADS + if (fd < 0) { + fd = _Py_FindSourceFile(filename, buf, sizeof(buf), open_flags); + if (fd < 0) + return 0; + filename = buf; } - if (xfp == NULL) - return err; - if (err != 0) { - fclose(xfp); - return err; - } + /* use the right encoding to decode the file as unicode */ + found_encoding = PyTokenizer_FindEncoding(fd); + encoding = (found_encoding != NULL) ? found_encoding : + (char*)PyUnicode_GetDefaultEncoding(); + lseek(fd, 0, 0); /* Reset position */ + fob = PyFile_FromFd(fd, (char*)filename, "r", -1, (char*)encoding, + NULL, NULL, 1); + PyMem_FREE(found_encoding); + if (fob == NULL) { + PyErr_Clear(); + close(fd); + return 0; + } + /* get the line number lineno */ for (i = 0; i < lineno; i++) { - char* pLastChar = &linebuf[sizeof(linebuf)-2]; - do { - *pLastChar = '\0'; - if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf, xfp, NULL) == NULL) - break; - /* fgets read *something*; if it didn't get as - far as pLastChar, it must have found a newline - or hit the end of the file; if pLastChar is \n, - it obviously found a newline; else we haven't - yet seen a newline, so must continue */ - } while (*pLastChar != '\0' && *pLastChar != '\n'); - } - if (i == lineno) { - char buf[11]; - char *p = linebuf; - while (*p == ' ' || *p == '\t' || *p == '\014') - p++; - - /* Write some spaces before the line */ - strcpy(buf, " "); - assert (strlen(buf) == 10); - while (indent > 0) { - if(indent < 10) - buf[indent] = '\0'; - err = PyFile_WriteString(buf, f); - if (err != 0) - break; - indent -= 10; + Py_XDECREF(lineobj); + lineobj = PyFile_GetLine(fob, -1); + if (!lineobj) { + err = -1; + break; } + } + Py_DECREF(fob); + if (!lineobj || !PyUnicode_Check(lineobj)) { + Py_XDECREF(lineobj); + return err; + } - if (err == 0) - err = PyFile_WriteString(p, f); - if (err == 0 && strchr(p, '\n') == NULL) - err = PyFile_WriteString("\n", f); + /* remove the indentation of the line */ + u = PyUnicode_AS_UNICODE(lineobj); + len = PyUnicode_GET_SIZE(lineobj); + for (p=u; *p == ' ' || *p == '\t' || *p == '\014'; p++) + len--; + if (u != p) { + PyObject *truncated; + truncated = PyUnicode_FromUnicode(p, len); + if (truncated) { + Py_DECREF(lineobj); + lineobj = truncated; + } else { + PyErr_Clear(); + } } - fclose(xfp); + + /* Write some spaces before the line */ + strcpy(buf, " "); + assert (strlen(buf) == 10); + while (indent > 0) { + if(indent < 10) + buf[indent] = '\0'; + err = PyFile_WriteString(buf, f); + if (err != 0) + break; + indent -= 10; + } + + /* finally display the line */ + if (err == 0) + err = PyFile_WriteObject(lineobj, f, Py_PRINT_RAW); + Py_DECREF(lineobj); + if (err == 0) + err = PyFile_WriteString("\n", f); return err; } From python-3000-checkins at python.org Sat Oct 11 00:20:53 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 11 Oct 2008 00:20:53 +0200 (CEST) Subject: [Python-3000-checkins] r66873 - in python/branches/py3k: Doc/library/os.rst Lib/test/test_array.py Lib/test/test_threading.py Message-ID: <20081010222053.4C5911E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 11 00:20:52 2008 New Revision: 66873 Log: Merged revisions 66703,66708 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66703 | gregory.p.smith | 2008-09-30 15:41:13 -0500 (Tue, 30 Sep 2008) | 6 lines Works around issue3863: freebsd4/5/6 and os2emx are known to have OS bugs when calling fork() from a child thread. This disables that unit test (with a note printed to stderr) on those platforms. A caveat about buggy platforms is added to the os.fork documentation. ........ r66708 | andrew.macintyre | 2008-09-30 22:25:25 -0500 (Tue, 30 Sep 2008) | 9 lines fix for issue 3862: test_array fails FreeBSD 7 amd64 FreeBSD 7's underlying malloc() is behaves differently to earlier versions and seriously overcommits available memory on amd64. This may affect other 64bit platforms in some circumstances, so the scale of the problematic test is wound back. Patch by Mark Dickinson, reviewed by Martin von Loewis. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/os.rst python/branches/py3k/Lib/test/test_array.py python/branches/py3k/Lib/test/test_threading.py Modified: python/branches/py3k/Doc/library/os.rst ============================================================================== --- python/branches/py3k/Doc/library/os.rst (original) +++ python/branches/py3k/Doc/library/os.rst Sat Oct 11 00:20:52 2008 @@ -1389,6 +1389,10 @@ Fork a child process. Return ``0`` in the child and the child's process id in the parent. If an error occurs :exc:`OSError` is raised. + + Note that some platforms including FreeBSD <= 6.3, Cygwin and OS/2 EMX have + known issues when using fork() from a thread. + Availability: Unix. Modified: python/branches/py3k/Lib/test/test_array.py ============================================================================== --- python/branches/py3k/Lib/test/test_array.py (original) +++ python/branches/py3k/Lib/test/test_array.py Sat Oct 11 00:20:52 2008 @@ -964,20 +964,21 @@ minitemsize = 8 def test_alloc_overflow(self): + from sys import maxsize a = array.array('d', [-1]*65536) try: - a *= 65536 + a *= maxsize//65536 + 1 except MemoryError: pass else: - self.fail("a *= 2**16 didn't raise MemoryError") + self.fail("Array of size > maxsize created - MemoryError expected") b = array.array('d', [ 2.71828183, 3.14159265, -1]) try: - b * 1431655766 + b * (maxsize//3 + 1) except MemoryError: pass else: - self.fail("a * 1431655766 didn't raise MemoryError") + self.fail("Array of size > maxsize created - MemoryError expected") tests.append(DoubleTest) Modified: python/branches/py3k/Lib/test/test_threading.py ============================================================================== --- python/branches/py3k/Lib/test/test_threading.py (original) +++ python/branches/py3k/Lib/test/test_threading.py Sat Oct 11 00:20:52 2008 @@ -397,6 +397,12 @@ import os if not hasattr(os, 'fork'): return + # Skip platforms with known problems forking from a worker thread. + # See http://bugs.python.org/issue3863. + if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'os2emx'): + print >>sys.stderr, ('Skipping test_3_join_in_forked_from_thread' + ' due to known OS bugs on'), sys.platform + return script = """if 1: main_thread = threading.current_thread() def worker(): From python-3000-checkins at python.org Sat Oct 11 01:15:38 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 11 Oct 2008 01:15:38 +0200 (CEST) Subject: [Python-3000-checkins] r66875 - python/branches/py3k Message-ID: <20081010231538.866451E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 11 01:15:38 2008 New Revision: 66875 Log: Blocked revisions 66822 via svnmerge ........ r66822 | skip.montanaro | 2008-10-06 20:55:20 -0500 (Mon, 06 Oct 2008) | 2 lines Simplify individual tests by defining setUp and tearDown methods. ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Oct 11 02:49:59 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 11 Oct 2008 02:49:59 +0200 (CEST) Subject: [Python-3000-checkins] r66876 - in python/branches/py3k: Doc/Makefile Doc/c-api/init.rst Doc/conf.py Doc/contents.rst Doc/library/ftplib.rst Doc/library/functions.rst Doc/library/sqlite3.rst Doc/library/subprocess.rst Doc/reference/simple_stmts.rst Doc/tools/sphinxext/download.html Doc/tools/sphinxext/indexcontent.html Doc/tools/sphinxext/layout.html Doc/whatsnew/2.2.rst Doc/whatsnew/2.3.rst Doc/whatsnew/2.4.rst Doc/whatsnew/2.5.rst Doc/whatsnew/2.6.rst Doc/whatsnew/2.7.rst Doc/whatsnew/3.0.rst Doc/whatsnew/index.rst Lib/optparse.py Lib/test/test_atexit.py Lib/test/test_bisect.py Lib/test/test_datetime.py Lib/test/test_dbm.py Lib/test/test_docxmlrpc.py Lib/test/test_set.py Mac/BuildScript/build-installer.py Makefile.pre.in Modules/_bisectmodule.c Modules/_codecsmodule.c Modules/cjkcodecs/multibytecodec.c Modules/posixmodule.c Objects/dictobject.c Objects/floatobject.c Objects/listobject.c Objects/setobject.c Objects/tupleobject.c Objects/unicodeobject.c setup.py Message-ID: <20081011004959.51A291E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 11 02:49:57 2008 New Revision: 66876 Log: Added: python/branches/py3k/Doc/whatsnew/2.7.rst - copied unchanged from r66793, /python/trunk/Doc/whatsnew/2.7.rst python/branches/py3k/Doc/whatsnew/index.rst - copied, changed from r66874, /python/trunk/Doc/whatsnew/index.rst Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/Makefile python/branches/py3k/Doc/c-api/init.rst python/branches/py3k/Doc/conf.py python/branches/py3k/Doc/contents.rst python/branches/py3k/Doc/library/ftplib.rst python/branches/py3k/Doc/library/functions.rst python/branches/py3k/Doc/library/sqlite3.rst python/branches/py3k/Doc/library/subprocess.rst python/branches/py3k/Doc/reference/simple_stmts.rst python/branches/py3k/Doc/tools/sphinxext/download.html python/branches/py3k/Doc/tools/sphinxext/indexcontent.html python/branches/py3k/Doc/tools/sphinxext/layout.html python/branches/py3k/Doc/whatsnew/2.2.rst python/branches/py3k/Doc/whatsnew/2.3.rst python/branches/py3k/Doc/whatsnew/2.4.rst python/branches/py3k/Doc/whatsnew/2.5.rst python/branches/py3k/Doc/whatsnew/2.6.rst (contents, props changed) python/branches/py3k/Doc/whatsnew/3.0.rst python/branches/py3k/Lib/optparse.py python/branches/py3k/Lib/test/test_atexit.py python/branches/py3k/Lib/test/test_bisect.py python/branches/py3k/Lib/test/test_datetime.py python/branches/py3k/Lib/test/test_dbm.py python/branches/py3k/Lib/test/test_docxmlrpc.py python/branches/py3k/Lib/test/test_set.py python/branches/py3k/Mac/BuildScript/build-installer.py python/branches/py3k/Makefile.pre.in python/branches/py3k/Modules/_bisectmodule.c python/branches/py3k/Modules/_codecsmodule.c python/branches/py3k/Modules/cjkcodecs/multibytecodec.c python/branches/py3k/Modules/posixmodule.c python/branches/py3k/Objects/dictobject.c python/branches/py3k/Objects/floatobject.c python/branches/py3k/Objects/listobject.c python/branches/py3k/Objects/setobject.c python/branches/py3k/Objects/tupleobject.c python/branches/py3k/Objects/unicodeobject.c python/branches/py3k/setup.py Modified: python/branches/py3k/Doc/Makefile ============================================================================== --- python/branches/py3k/Doc/Makefile (original) +++ python/branches/py3k/Doc/Makefile Sat Oct 11 02:49:57 2008 @@ -111,7 +111,7 @@ # archive the HTML make html - cp -a build/html dist/python$(DISTVERSION)-docs-html + cp -pPR build/html dist/python$(DISTVERSION)-docs-html tar -C dist -cf dist/python$(DISTVERSION)-docs-html.tar python$(DISTVERSION)-docs-html bzip2 -9 -k dist/python$(DISTVERSION)-docs-html.tar (cd dist; zip -q -r -9 python$(DISTVERSION)-docs-html.zip python$(DISTVERSION)-docs-html) @@ -120,7 +120,7 @@ # archive the text build make text - cp -a build/text dist/python$(DISTVERSION)-docs-text + cp -pPR build/text dist/python$(DISTVERSION)-docs-text tar -C dist -cf dist/python$(DISTVERSION)-docs-text.tar python$(DISTVERSION)-docs-text bzip2 -9 -k dist/python$(DISTVERSION)-docs-text.tar (cd dist; zip -q -r -9 python$(DISTVERSION)-docs-text.zip python$(DISTVERSION)-docs-text) Modified: python/branches/py3k/Doc/c-api/init.rst ============================================================================== --- python/branches/py3k/Doc/c-api/init.rst (original) +++ python/branches/py3k/Doc/c-api/init.rst Sat Oct 11 02:49:57 2008 @@ -744,11 +744,11 @@ :cmacro:`Py_END_ALLOW_THREADS` macros is acceptable. The return value is an opaque "handle" to the thread state when - :cfunc:`PyGILState_Acquire` was called, and must be passed to + :cfunc:`PyGILState_Ensure` was called, and must be passed to :cfunc:`PyGILState_Release` to ensure Python is left in the same state. Even though recursive calls are allowed, these handles *cannot* be shared - each - unique call to :cfunc:`PyGILState_Ensure` must save the handle for its call to - :cfunc:`PyGILState_Release`. + unique call to :cfunc:`PyGILState_Ensure` must save the handle for its call + to :cfunc:`PyGILState_Release`. When the function returns, the current thread will hold the GIL. Failure is a fatal error. Modified: python/branches/py3k/Doc/conf.py ============================================================================== --- python/branches/py3k/Doc/conf.py (original) +++ python/branches/py3k/Doc/conf.py Sat Oct 11 02:49:57 2008 @@ -41,13 +41,6 @@ # List of files that shouldn't be included in the build. unused_docs = [ - 'whatsnew/2.0', - 'whatsnew/2.1', - 'whatsnew/2.2', - 'whatsnew/2.3', - 'whatsnew/2.4', - 'whatsnew/2.5', - 'whatsnew/2.6', 'maclib/scrap', 'library/xmllib', 'library/xml.etree', Modified: python/branches/py3k/Doc/contents.rst ============================================================================== --- python/branches/py3k/Doc/contents.rst (original) +++ python/branches/py3k/Doc/contents.rst Sat Oct 11 02:49:57 2008 @@ -4,7 +4,7 @@ .. toctree:: - whatsnew/3.0.rst + whatsnew/index.rst tutorial/index.rst using/index.rst reference/index.rst Modified: python/branches/py3k/Doc/library/ftplib.rst ============================================================================== --- python/branches/py3k/Doc/library/ftplib.rst (original) +++ python/branches/py3k/Doc/library/ftplib.rst Sat Oct 11 02:49:57 2008 @@ -299,7 +299,7 @@ .. method:: FTP.quit() Send a ``QUIT`` command to the server and close the connection. This is the - "polite" way to close a connection, but it may raise an exception of the server + "polite" way to close a connection, but it may raise an exception if the server responds with an error to the ``QUIT`` command. This implies a call to the :meth:`close` method which renders the :class:`FTP` instance useless for subsequent calls (see below). Modified: python/branches/py3k/Doc/library/functions.rst ============================================================================== --- python/branches/py3k/Doc/library/functions.rst (original) +++ python/branches/py3k/Doc/library/functions.rst Sat Oct 11 02:49:57 2008 @@ -22,9 +22,8 @@ The function is invoked by the :keyword:`import` statement. It mainly exists so that you can replace it with another function that has a compatible interface, in order to change the semantics of the :keyword:`import` - statement. See also the built-in module :mod:`imp`, which - defines some useful operations out of which you can build your own - :func:`__import__` function. + statement. See the built-in module :mod:`imp`, which defines some useful + operations out of which you can build your own :func:`__import__` function. For example, the statement ``import spam`` results in the following call: ``__import__('spam', globals(), locals(), [], -1)``; the statement @@ -1201,6 +1200,18 @@ care about trailing, unmatched values from the longer iterables. If those values are important, use :func:`itertools.zip_longest` instead. + :func:`zip` in conjunction with the ``*`` operator can be used to unzip a + list:: + + >>> x = [1, 2, 3] + >>> y = [4, 5, 6] + >>> zipped = zip(x, y) + >>> zipped + [(1, 4), (2, 5), (3, 6)] + >>> x2, y2 = zip(*zipped) + >>> x == x2, y == y2 + True + .. rubric:: Footnotes Modified: python/branches/py3k/Doc/library/sqlite3.rst ============================================================================== --- python/branches/py3k/Doc/library/sqlite3.rst (original) +++ python/branches/py3k/Doc/library/sqlite3.rst Sat Oct 11 02:49:57 2008 @@ -25,7 +25,7 @@ You can also supply the special name ``:memory:`` to create a database in RAM. Once you have a :class:`Connection`, you can create a :class:`Cursor` object -and call its :meth:`execute` method to perform SQL commands:: +and call its :meth:`~Cursor.execute` method to perform SQL commands:: c = conn.cursor() @@ -50,7 +50,7 @@ Instead, use the DB-API's parameter substitution. Put ``?`` as a placeholder wherever you want to use a value, and then provide a tuple of values as the -second argument to the cursor's :meth:`execute` method. (Other database modules +second argument to the cursor's :meth:`~Cursor.execute` method. (Other database modules may use a different placeholder, such as ``%s`` or ``:1``.) For example:: # Never do this -- insecure! @@ -69,8 +69,8 @@ c.execute('insert into stocks values (?,?,?,?,?)', t) To retrieve data after executing a SELECT statement, you can either treat the -cursor as an :term:`iterator`, call the cursor's :meth:`fetchone` method to -retrieve a single matching row, or call :meth:`fetchall` to get a list of the +cursor as an :term:`iterator`, call the cursor's :meth:`~Cursor.fetchone` method to +retrieve a single matching row, or call :meth:`~Cursor.fetchall` to get a list of the matching rows. This example uses the iterator form:: @@ -128,7 +128,7 @@ returns. It will look for a string formed [mytype] in there, and then decide that 'mytype' is the type of the column. It will try to find an entry of 'mytype' in the converters dictionary and then use the converter function found - there to return the value. The column name found in :attr:`cursor.description` + there to return the value. The column name found in :attr:`Cursor.description` is only the first word of the column name, i. e. if you use something like ``'as "x [datetime]"'`` in your SQL, then we will parse out everything until the first blank for the column name: the column name would simply be "x". @@ -215,11 +215,13 @@ Connection Objects ------------------ -A :class:`Connection` instance has the following attributes and methods: +.. class:: Connection + + A SQLite database connection has the following attributes and methods: .. attribute:: Connection.isolation_level - Get or set the current isolation level. None for autocommit mode or one of + Get or set the current isolation level. :const:`None` for autocommit mode or one of "DEFERRED", "IMMEDIATE" or "EXLUSIVE". See section :ref:`sqlite3-controlling-transactions` for a more detailed explanation. @@ -234,7 +236,7 @@ .. method:: Connection.commit() This method commits the current transaction. If you don't call this method, - anything you did since the last call to commit() is not visible from from + anything you did since the last call to ``commit()`` is not visible from from other database connections. If you wonder why you don't see the data you've written to the database, please check you didn't forget to call this method. @@ -383,9 +385,9 @@ .. attribute:: Connection.text_factory - Using this attribute you can control what objects are returned for the TEXT data - type. By default, this attribute is set to :class:`str` and the - :mod:`sqlite3` module will return strings for TEXT. If you want to + Using this attribute you can control what objects are returned for the ``TEXT`` + data type. By default, this attribute is set to :class:`str` and the + :mod:`sqlite3` module will return Unicode objects for ``TEXT``. If you want to return bytestrings instead, you can set it to :class:`bytes`. For efficiency reasons, there's also a way to return :class:`str` objects @@ -430,8 +432,9 @@ Cursor Objects -------------- -A :class:`Cursor` instance has the following attributes and methods: +.. class:: Cursor + A SQLite database cursor has the following attributes and methods: .. method:: Cursor.execute(sql, [parameters]) @@ -470,7 +473,7 @@ .. method:: Cursor.executescript(sql_script) This is a nonstandard convenience method for executing multiple SQL statements - at once. It issues a COMMIT statement first, then executes the SQL script it + at once. It issues a ``COMMIT`` statement first, then executes the SQL script it gets as a parameter. *sql_script* can be an instance of :class:`str` or :class:`bytes`. @@ -483,7 +486,7 @@ .. method:: Cursor.fetchone() Fetches the next row of a query result set, returning a single sequence, - or ``None`` when no more data is available. + or :const:`None` when no more data is available. .. method:: Cursor.fetchmany([size=cursor.arraysize]) @@ -522,8 +525,8 @@ into :attr:`rowcount`. As required by the Python DB API Spec, the :attr:`rowcount` attribute "is -1 in - case no executeXX() has been performed on the cursor or the rowcount of the last - operation is not determinable by the interface". + case no ``executeXX()`` has been performed on the cursor or the rowcount of the + last operation is not determinable by the interface". This includes ``SELECT`` statements because we cannot determine the number of rows a query produced until all rows were fetched. @@ -535,6 +538,81 @@ method. For operations other than ``INSERT`` or when :meth:`executemany` is called, :attr:`lastrowid` is set to :const:`None`. +.. attribute:: Cursor.description + + This read-only attribute provides the column names of the last query. To + remain compatible with the Python DB API, it returns a 7-tuple for each + column where the last six items of each tuple are :const:`None`. + + It is set for ``SELECT`` statements without any matching rows as well. + +.. _sqlite3-row-objects: + +Row Objects +----------- + +.. class:: Row + + A :class:`Row` instance serves as a highly optimized + :attr:`~Connection.row_factory` for :class:`Connection` objects. + It tries to mimic a tuple in most of its features. + + It supports mapping access by column name and index, iteration, + representation, equality testing and :func:`len`. + + If two :class:`Row` objects have exactly the same columns and their + members are equal, they compare equal. + + .. versionchanged:: 2.6 + Added iteration and equality (hashability). + + .. method:: keys + + This method returns a tuple of column names. Immediately after a query, + it is the first member of each tuple in :attr:`Cursor.description`. + + .. versionadded:: 2.6 + +Let's assume we initialize a table as in the example given above:: + + conn = sqlite3.connect(":memory:") + c = conn.cursor() + c.execute('''create table stocks + (date text, trans text, symbol text, + qty real, price real)''') + c.execute("""insert into stocks + values ('2006-01-05','BUY','RHAT',100,35.14)""") + conn.commit() + c.close() + +Now we plug :class:`Row` in:: + + >>> conn.row_factory = sqlite3.Row + >>> c = conn.cursor() + >>> c.execute('select * from stocks') + + >>> r = c.fetchone() + >>> type(r) + + >>> r + (u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.140000000000001) + >>> len(r) + 5 + >>> r[2] + u'RHAT' + >>> r.keys() + ['date', 'trans', 'symbol', 'qty', 'price'] + >>> r['qty'] + 100.0 + >>> for member in r: print member + ... + 2006-01-05 + BUY + RHAT + 100.0 + 35.14 + + .. _sqlite3-types: SQLite and Python types @@ -544,36 +622,38 @@ Introduction ^^^^^^^^^^^^ -SQLite natively supports the following types: NULL, INTEGER, REAL, TEXT, BLOB. +SQLite natively supports the following types: ``NULL``, ``INTEGER``, +``REAL``, ``TEXT``, ``BLOB``. The following Python types can thus be sent to SQLite without any problem: +-------------------------------+-------------+ | Python type | SQLite type | +===============================+=============+ -| ``None`` | NULL | +| :const:`None` | ``NULL`` | +-------------------------------+-------------+ -| :class:`int` | INTEGER | +| :class:`int` | ``INTEGER`` | +-------------------------------+-------------+ -| :class:`float` | REAL | +| :class:`float` | ``REAL`` | +-------------------------------+-------------+ -| :class:`bytes` (UTF8-encoded) | TEXT | +| :class:`bytes` (UTF8-encoded) | ``TEXT`` | +-------------------------------+-------------+ -| :class:`str` | TEXT | +| :class:`str` | ``TEXT`` | +-------------------------------+-------------+ -| :class:`buffer` | BLOB | +| :class:`buffer` | ``BLOB`` | +-------------------------------+-------------+ + This is how SQLite types are converted to Python types by default: +-------------+---------------------------------------------+ | SQLite type | Python type | +=============+=============================================+ -| ``NULL`` | None | +| ``NULL`` | :const:`None` | +-------------+---------------------------------------------+ -| ``INTEGER`` | int | +| ``INTEGER`` | :class`int` | +-------------+---------------------------------------------+ -| ``REAL`` | float | +| ``REAL`` | :class:`float` | +-------------+---------------------------------------------+ | ``TEXT`` | depends on text_factory, str by default | +-------------+---------------------------------------------+ @@ -701,9 +781,10 @@ ------------------------ By default, the :mod:`sqlite3` module opens transactions implicitly before a -Data Modification Language (DML) statement (i.e. INSERT/UPDATE/DELETE/REPLACE), -and commits transactions implicitly before a non-DML, non-query statement (i. e. -anything other than SELECT/INSERT/UPDATE/DELETE/REPLACE). +Data Modification Language (DML) statement (i.e. +``INSERT``/``UPDATE``/``DELETE``/``REPLACE``), and commits transactions +implicitly before a non-DML, non-query statement (i. e. +anything other than ``SELECT`` or the aforementioned). So if you are within a transaction and issue a command like ``CREATE TABLE ...``, ``VACUUM``, ``PRAGMA``, the :mod:`sqlite3` module will commit implicitly @@ -712,7 +793,7 @@ is that pysqlite needs to keep track of the transaction state (if a transaction is active or not). -You can control which kind of "BEGIN" statements pysqlite implicitly executes +You can control which kind of ``BEGIN`` statements pysqlite implicitly executes (or none at all) via the *isolation_level* parameter to the :func:`connect` call, or via the :attr:`isolation_level` property of connections. @@ -736,7 +817,7 @@ be written more concisely because you don't have to create the (often superfluous) :class:`Cursor` objects explicitly. Instead, the :class:`Cursor` objects are created implicitly and these shortcut methods return the cursor -objects. This way, you can execute a SELECT statement and iterate over it +objects. This way, you can execute a ``SELECT`` statement and iterate over it directly using only a single call on the :class:`Connection` object. .. literalinclude:: ../includes/sqlite3/shortcut_methods.py Modified: python/branches/py3k/Doc/library/subprocess.rst ============================================================================== --- python/branches/py3k/Doc/library/subprocess.rst (original) +++ python/branches/py3k/Doc/library/subprocess.rst Sat Oct 11 02:49:57 2008 @@ -334,8 +334,8 @@ output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0] -Replacing shell pipe line -^^^^^^^^^^^^^^^^^^^^^^^^^ +Replacing shell pipeline +^^^^^^^^^^^^^^^^^^^^^^^^ :: Modified: python/branches/py3k/Doc/reference/simple_stmts.rst ============================================================================== --- python/branches/py3k/Doc/reference/simple_stmts.rst (original) +++ python/branches/py3k/Doc/reference/simple_stmts.rst Sat Oct 11 02:49:57 2008 @@ -775,9 +775,9 @@ .. XXX change this if future is cleaned out The features recognized by Python 3.0 are ``absolute_import``, ``division``, -``generators``, ``nested_scopes`` and ``with_statement``. They are all -redundant because they are always enabled, and only kept for backwards -compatibility. +``generators``, ``unicode_literals``, ``print_function``, ``nested_scopes`` and +``with_statement``. They are all redundant because they are always enabled, and +only kept for backwards compatibility. A future statement is recognized and treated specially at compile time: Changes to the semantics of core constructs are often implemented by generating 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 Sat Oct 11 02:49:57 2008 @@ -31,8 +31,8 @@
Download (ca. 4 MB) Plain Text - Download (ca. 2 MB) - Download (ca. 1.5 MB) + Download (ca. 2 MB) + Download (ca. 1.5 MB) Modified: python/branches/py3k/Doc/tools/sphinxext/indexcontent.html ============================================================================== --- python/branches/py3k/Doc/tools/sphinxext/indexcontent.html (original) +++ python/branches/py3k/Doc/tools/sphinxext/indexcontent.html Sat Oct 11 02:49:57 2008 @@ -4,7 +4,7 @@
+ or all "What's new" documents since 2.0

  • -{{ super() }} +
  • {{ shorttitle }}{{ reldelim1 }}
  • {% endblock %} Modified: python/branches/py3k/Doc/whatsnew/2.2.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/2.2.rst (original) +++ python/branches/py3k/Doc/whatsnew/2.2.rst Sat Oct 11 02:49:57 2008 @@ -714,7 +714,7 @@ presented with two integer arguments: it returns an integer result that's truncated down when there would be a fractional part. For example, ``3/2`` is 1, not 1.5, and ``(-1)/2`` is -1, not -0.5. This means that the results of -divison can vary unexpectedly depending on the type of the two operands and +division can vary unexpectedly depending on the type of the two operands and because Python is dynamically typed, it can be difficult to determine the possible types of the operands. Modified: python/branches/py3k/Doc/whatsnew/2.3.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/2.3.rst (original) +++ python/branches/py3k/Doc/whatsnew/2.3.rst Sat Oct 11 02:49:57 2008 @@ -1196,7 +1196,7 @@ * The ``SET_LINENO`` opcode is now gone. This may provide a small speed increase, depending on your compiler's idiosyncrasies. See section - :ref:`section-other` for a longer explanation. (Removed by Michael Hudson.) + :ref:`23section-other` for a longer explanation. (Removed by Michael Hudson.) * :func:`xrange` objects now have their own iterator, making ``for i in xrange(n)`` slightly faster than ``for i in range(n)``. (Patch by Raymond @@ -1951,7 +1951,7 @@ .. ====================================================================== -.. _section-other: +.. _23section-other: Other Changes and Fixes ======================= @@ -2062,7 +2062,7 @@ .. ====================================================================== -.. _acks: +.. _23acks: Acknowledgements ================ Modified: python/branches/py3k/Doc/whatsnew/2.4.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/2.4.rst (original) +++ python/branches/py3k/Doc/whatsnew/2.4.rst Sat Oct 11 02:49:57 2008 @@ -1551,7 +1551,7 @@ .. ====================================================================== -.. _acks: +.. _24acks: Acknowledgements ================ Modified: python/branches/py3k/Doc/whatsnew/2.5.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/2.5.rst (original) +++ python/branches/py3k/Doc/whatsnew/2.5.rst Sat Oct 11 02:49:57 2008 @@ -16,9 +16,9 @@ The changes in Python 2.5 are an interesting mix of language and library improvements. The library enhancements will be more important to Python's user community, I think, because several widely-useful packages were added. New -modules include ElementTree for XML processing (section :ref:`module-etree`), -the SQLite database module (section :ref:`module-sqlite`), and the :mod:`ctypes` -module for calling C functions (section :ref:`module-ctypes`). +modules include ElementTree for XML processing (:mod:`xml.etree`), +the SQLite database module (:mod:`sqlite`), and the :mod:`ctypes` +module for calling C functions. The language changes are of middling significance. Some pleasant new features were added, but most of them aren't features that you'll use every day. @@ -736,7 +736,7 @@ # return False -.. _module-contextlib: +.. _contextlibmod: The contextlib module --------------------- @@ -1109,7 +1109,7 @@ .. ====================================================================== -.. _interactive: +.. _25interactive: Interactive Interpreter Changes ------------------------------- @@ -1211,7 +1211,7 @@ .. ====================================================================== -.. _modules: +.. _25modules: New, Improved, and Removed Modules ================================== @@ -1273,7 +1273,7 @@ (Contributed by Raymond Hettinger.) * New module: The :mod:`contextlib` module contains helper functions for use - with the new ':keyword:`with`' statement. See section :ref:`module-contextlib` + with the new ':keyword:`with`' statement. See section :ref:`contextlibmod` for more about this module. * New module: The :mod:`cProfile` module is a C implementation of the existing @@ -2272,8 +2272,6 @@ .. ====================================================================== -.. _acks: - Acknowledgements ================ Modified: python/branches/py3k/Doc/whatsnew/2.6.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/2.6.rst (original) +++ python/branches/py3k/Doc/whatsnew/2.6.rst Sat Oct 11 02:49:57 2008 @@ -8,7 +8,7 @@ :Release: |release| :Date: |today| -.. $Id: whatsnew26.tex 55746 2007-06-02 18:33:53Z neal.norwitz $ +.. $Id$ Rules for maintenance: * Anyone can add text to this document. Do not spend very much time @@ -49,9 +49,8 @@ This saves the maintainer some effort going through the SVN logs when researching a change. -This article explains the new features in Python 2.6. The release -schedule is described in :pep:`361`; currently the final release is -scheduled for October 1 2008. +This article explains the new features in Python 2.6, released on October 1 +2008. The release schedule is described in :pep:`361`. The major theme of Python 2.6 is preparing the migration path to Python 3.0, a major redesign of the language. Whenever possible, @@ -663,33 +662,33 @@ from multiprocessing import Pool, Manager def factorial(N, dictionary): - "Compute a factorial." - # Calculate the result - fact = 1L - for i in range(1, N+1): - fact = fact * i + "Compute a factorial." + # Calculate the result + fact = 1L + for i in range(1, N+1): + fact = fact * i # Store result in dictionary - dictionary[N] = fact + dictionary[N] = fact if __name__ == '__main__': - p = Pool(5) - mgr = Manager() - d = mgr.dict() # Create shared dictionary - - # Run tasks using the pool - for N in range(1, 1000, 10): - p.apply_async(factorial, (N, d)) - - # Mark pool as closed -- no more tasks can be added. - p.close() - - # Wait for tasks to exit - p.join() - - # Output results - for k, v in sorted(d.items()): - print k, v + p = Pool(5) + mgr = Manager() + d = mgr.dict() # Create shared dictionary + + # Run tasks using the pool + for N in range(1, 1000, 10): + p.apply_async(factorial, (N, d)) + + # Mark pool as closed -- no more tasks can be added. + p.close() + + # Wait for tasks to exit + p.join() + + # Output results + for k, v in sorted(d.items()): + print k, v This will produce the output:: @@ -724,32 +723,33 @@ treats the string as a template and takes the arguments to be formatted. The formatting template uses curly brackets (`{`, `}`) as special characters:: - # Substitute positional argument 0 into the string. - "User ID: {0}".format("root") -> "User ID: root" - - # Use the named keyword arguments - 'User ID: {uid} Last seen: {last_login}'.format( - uid='root', - last_login = '5 Mar 2008 07:20') -> - 'User ID: root Last seen: 5 Mar 2008 07:20' + >>> # Substitute positional argument 0 into the string. + >>> "User ID: {0}".format("root") + 'User ID: root' + >>> # Use the named keyword arguments + >>> "User ID: {uid} Last seen: {last_login}".format( + ... uid="root", + ... last_login = "5 Mar 2008 07:20") + 'User ID: root Last seen: 5 Mar 2008 07:20' Curly brackets can be escaped by doubling them:: - format("Empty dict: {{}}") -> "Empty dict: {}" + >>> format("Empty dict: {{}}") + "Empty dict: {}" Field names can be integers indicating positional arguments, such as ``{0}``, ``{1}``, etc. or names of keyword arguments. You can also supply compound field names that read attributes or access dictionary keys:: - import sys - 'Platform: {0.platform}\nPython version: {0.version}'.format(sys) -> - 'Platform: darwin\n - Python version: 2.6a1+ (trunk:61261M, Mar 5 2008, 20:29:41) \n - [GCC 4.0.1 (Apple Computer, Inc. build 5367)]' - - import mimetypes - 'Content-type: {0[.mp4]}'.format(mimetypes.types_map) -> - 'Content-type: video/mp4' + >>> import sys + >>> print 'Platform: {0.platform}\nPython version: {0.version}'.format(sys) + Platform: darwin + Python version: 2.6a1+ (trunk:61261M, Mar 5 2008, 20:29:41) + [GCC 4.0.1 (Apple Computer, Inc. build 5367)]' + + >>> import mimetypes + >>> 'Content-type: {0[.mp4]}'.format(mimetypes.types_map) + 'Content-type: video/mp4' Note that when using dictionary-style notation such as ``[.mp4]``, you don't need to put any quotation marks around the string; it will look @@ -761,30 +761,25 @@ resulting string. The precise formatting used is also controllable by adding a colon followed by a format specifier. For example:: - # Field 0: left justify, pad to 15 characters - # Field 1: right justify, pad to 6 characters - fmt = '{0:15} ${1:>6}' - - fmt.format('Registration', 35) -> - 'Registration $ 35' - - fmt.format('Tutorial', 50) -> - 'Tutorial $ 50' - - fmt.format('Banquet', 125) -> - 'Banquet $ 125' + >>> # Field 0: left justify, pad to 15 characters + >>> # Field 1: right justify, pad to 6 characters + >>> fmt = '{0:15} ${1:>6}' + >>> fmt.format('Registration', 35) + 'Registration $ 35' + >>> fmt.format('Tutorial', 50) + 'Tutorial $ 50' + >>> fmt.format('Banquet', 125) + 'Banquet $ 125' Format specifiers can reference other fields through nesting:: - fmt = '{0:{1}}' - - width = 15 - fmt.format('Invoice #1234', width) -> - 'Invoice #1234 ' - - width = 35 - fmt.format('Invoice #1234', width) -> - 'Invoice #1234 ' + >>> fmt = '{0:{1}}' + >>> width = 15 + >>> fmt.format('Invoice #1234', width) + 'Invoice #1234 ' + >>> width = 35 + >>> fmt.format('Invoice #1234', width) + 'Invoice #1234 ' The alignment of a field within the desired width can be specified: @@ -799,7 +794,7 @@ Format specifiers can also include a presentation type, which controls how the value is formatted. For example, floating-point numbers -can be formatted as a general number or in exponential notation: +can be formatted as a general number or in exponential notation:: >>> '{0:g}'.format(3.75) '3.75' @@ -807,25 +802,27 @@ '3.750000e+00' A variety of presentation types are available. Consult the 2.6 -documentation for a :ref:`complete list `; here's a sample:: +documentation for a :ref:`complete list `; here's a sample: - 'b' - Binary. Outputs the number in base 2. - 'c' - Character. Converts the integer to the corresponding - Unicode character before printing. - 'd' - Decimal Integer. Outputs the number in base 10. - 'o' - Octal format. Outputs the number in base 8. - 'x' - Hex format. Outputs the number in base 16, using lower- - case letters for the digits above 9. - 'e' - Exponent notation. Prints the number in scientific - notation using the letter 'e' to indicate the exponent. - 'g' - General format. This prints the number as a fixed-point - number, unless the number is too large, in which case - it switches to 'e' exponent notation. - 'n' - Number. This is the same as 'g' (for floats) or 'd' (for - integers), except that it uses the current locale setting to - insert the appropriate number separator characters. - '%' - Percentage. Multiplies the number by 100 and displays - in fixed ('f') format, followed by a percent sign. +===== ======================================================================== +``b`` Binary. Outputs the number in base 2. +``c`` Character. Converts the integer to the corresponding Unicode character + before printing. +``d`` Decimal Integer. Outputs the number in base 10. +``o`` Octal format. Outputs the number in base 8. +``x`` Hex format. Outputs the number in base 16, using lower-case letters for + the digits above 9. +``e`` Exponent notation. Prints the number in scientific notation using the + letter 'e' to indicate the exponent. +``g`` General format. This prints the number as a fixed-point number, unless + the number is too large, in which case it switches to 'e' exponent + notation. +``n`` Number. This is the same as 'g' (for floats) or 'd' (for integers), + except that it uses the current locale setting to insert the appropriate + number separator characters. +``%`` Percentage. Multiplies the number by 100 and displays in fixed ('f') + format, followed by a percent sign. +===== ======================================================================== Classes and types can define a :meth:`__format__` method to control how they're formatted. It receives a single argument, the format specifier:: @@ -866,13 +863,14 @@ Python 2.6 has a ``__future__`` import that removes ``print`` as language syntax, letting you use the functional form instead. For example:: - from __future__ import print_function - print('# of entries', len(dictionary), file=sys.stderr) + >>> from __future__ import print_function + >>> print('# of entries', len(dictionary), file=sys.stderr) The signature of the new function is:: def print(*args, sep=' ', end='\n', file=None) + The parameters are: * *args*: positional arguments whose values will be printed out. @@ -950,6 +948,20 @@ Python 2.6 adds :class:`bytes` as a synonym for the :class:`str` type, and it also supports the ``b''`` notation. + +The 2.6 :class:`str` differs from 3.0's :class:`bytes` type in various +ways; most notably, the constructor is completely different. In 3.0, +``bytes([65, 66, 67])`` is 3 elements long, containing the bytes +representing ``ABC``; in 2.6, ``bytes([65, 66, 67])`` returns the +12-byte string representing the :func:`str` of the list. + +The primary use of :class:`bytes` in 2.6 will be to write tests of +object type such as ``isinstance(x, bytes)``. This will help the 2to3 +converter, which can't tell whether 2.x code intends strings to +contain either characters or 8-bit bytes; you can now +use either :class:`bytes` or :class:`str` to represent your intention +exactly, and the resulting code will also be correct in Python 3.0. + There's also a ``__future__`` import that causes all string literals to become Unicode strings. This means that ``\u`` escape sequences can be used to include Unicode characters:: @@ -989,6 +1001,8 @@ and some of the methods of lists, such as :meth:`append`, :meth:`pop`, and :meth:`reverse`. +:: + >>> b = bytearray('ABC') >>> b.append('d') >>> b.append(ord('e')) @@ -1211,8 +1225,8 @@ now write:: def func(d): - if not isinstance(d, collections.MutableMapping): - raise ValueError("Mapping object expected, not %r" % d) + if not isinstance(d, collections.MutableMapping): + raise ValueError("Mapping object expected, not %r" % d) Don't feel that you must now begin writing lots of checks as in the above example. Python has a strong tradition of duck-typing, where @@ -1224,22 +1238,22 @@ You can write your own ABCs by using ``abc.ABCMeta`` as the metaclass in a class definition:: - from abc import ABCMeta, abstractmethod + from abc import ABCMeta, abstractmethod - class Drawable(): - __metaclass__ = ABCMeta + class Drawable(): + __metaclass__ = ABCMeta - @abstractmethod - def draw(self, x, y, scale=1.0): - pass + @abstractmethod + def draw(self, x, y, scale=1.0): + pass - def draw_doubled(self, x, y): - self.draw(x, y, scale=2.0) + def draw_doubled(self, x, y): + self.draw(x, y, scale=2.0) - class Square(Drawable): - def draw(self, x, y, scale): - ... + class Square(Drawable): + def draw(self, x, y, scale): + ... In the :class:`Drawable` ABC above, the :meth:`draw_doubled` method @@ -1259,7 +1273,7 @@ >>> class Circle(Drawable): ... pass ... - >>> c=Circle() + >>> c = Circle() Traceback (most recent call last): File "", line 1, in TypeError: Can't instantiate abstract class Circle with abstract methods draw @@ -1318,7 +1332,7 @@ The :func:`int` and :func:`long` built-ins will now accept the "0o" and "0b" prefixes when base-8 or base-2 are requested, or when the *base* argument is zero (signalling that the base used should be -determined from the string): +determined from the string):: >>> int ('0o52', 0) 42 @@ -1491,7 +1505,7 @@ (Contributed by Alexander Belopolsky; :issue:`1686487`.) It's also become legal to provide keyword arguments after a ``*args`` argument - to a function call. + to a function call. :: >>> def f(*args, **kw): ... print args, kw @@ -1532,17 +1546,17 @@ property. You would use them like this:: class C(object): - @property - def x(self): - return self._x - - @x.setter - def x(self, value): - self._x = value - - @x.deleter - def x(self): - del self._x + @property + def x(self): + return self._x + + @x.setter + def x(self, value): + self._x = value + + @x.deleter + def x(self): + del self._x class D(C): @C.x.getter @@ -1865,8 +1879,8 @@ >>> var_type = collections.namedtuple('variable', ... 'id name type size') - # Names are separated by spaces or commas. - # 'id, name, type, size' would also work. + >>> # Names are separated by spaces or commas. + >>> # 'id, name, type, size' would also work. >>> var_type._fields ('id', 'name', 'type', 'size') @@ -1916,11 +1930,13 @@ * A new window method in the :mod:`curses` module, :meth:`chgat`, changes the display attributes for a certain number of - characters on a single line. (Contributed by Fabian Kreutz.) :: + characters on a single line. (Contributed by Fabian Kreutz.) + + :: # Boldface text starting at y=0,x=21 # and affecting the rest of the line. - stdscr.chgat(0,21, curses.A_BOLD) + stdscr.chgat(0, 21, curses.A_BOLD) The :class:`Textbox` class in the :mod:`curses.textpad` module now supports editing in insert mode as well as overwrite mode. @@ -1986,8 +2002,8 @@ order, and returns a new generator that returns the contents of all the iterators, also in sorted order. For example:: - heapq.merge([1, 3, 5, 9], [2, 8, 16]) -> - [1, 2, 3, 5, 8, 9, 16] + >>> list(heapq.merge([1, 3, 5, 9], [2, 8, 16])) + [1, 2, 3, 5, 8, 9, 16] Another new function, ``heappushpop(heap, item)``, pushes *item* onto *heap*, then pops off and returns the smallest item. @@ -2021,57 +2037,55 @@ each of the elements; if some of the iterables are shorter than others, the missing values are set to *fillvalue*. For example:: - itertools.izip_longest([1,2,3], [1,2,3,4,5]) -> - (1, 1), (2, 2), (3, 3), (None, 4), (None, 5) + >>> tuple(itertools.izip_longest([1,2,3], [1,2,3,4,5])) + ((1, 1), (2, 2), (3, 3), (None, 4), (None, 5)) ``product(iter1, iter2, ..., [repeat=N])`` returns the Cartesian product of the supplied iterables, a set of tuples containing every possible combination of the elements returned from each iterable. :: - itertools.product([1,2,3], [4,5,6]) -> - (1, 4), (1, 5), (1, 6), - (2, 4), (2, 5), (2, 6), - (3, 4), (3, 5), (3, 6) + >>> list(itertools.product([1,2,3], [4,5,6])) + [(1, 4), (1, 5), (1, 6), + (2, 4), (2, 5), (2, 6), + (3, 4), (3, 5), (3, 6)] The optional *repeat* keyword argument is used for taking the product of an iterable or a set of iterables with themselves, repeated *N* times. With a single iterable argument, *N*-tuples are returned:: - itertools.product([1,2], repeat=3) -> - (1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), - (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2) + >>> list(itertools.product([1,2], repeat=3)) + [(1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), + (2, 1, 1), (2, 1, 2), (2, 2, 1), (2, 2, 2)] With two iterables, *2N*-tuples are returned. :: - itertools.product([1,2], [3,4], repeat=2) -> - (1, 3, 1, 3), (1, 3, 1, 4), (1, 3, 2, 3), (1, 3, 2, 4), - (1, 4, 1, 3), (1, 4, 1, 4), (1, 4, 2, 3), (1, 4, 2, 4), - (2, 3, 1, 3), (2, 3, 1, 4), (2, 3, 2, 3), (2, 3, 2, 4), - (2, 4, 1, 3), (2, 4, 1, 4), (2, 4, 2, 3), (2, 4, 2, 4) + >>> list(itertools.product([1,2], [3,4], repeat=2)) + [(1, 3, 1, 3), (1, 3, 1, 4), (1, 3, 2, 3), (1, 3, 2, 4), + (1, 4, 1, 3), (1, 4, 1, 4), (1, 4, 2, 3), (1, 4, 2, 4), + (2, 3, 1, 3), (2, 3, 1, 4), (2, 3, 2, 3), (2, 3, 2, 4), + (2, 4, 1, 3), (2, 4, 1, 4), (2, 4, 2, 3), (2, 4, 2, 4)] ``combinations(iterable, r)`` returns sub-sequences of length *r* from the elements of *iterable*. :: - itertools.combinations('123', 2) -> - ('1', '2'), ('1', '3'), ('2', '3') - - itertools.combinations('123', 3) -> - ('1', '2', '3') - - itertools.combinations('1234', 3) -> - ('1', '2', '3'), ('1', '2', '4'), ('1', '3', '4'), - ('2', '3', '4') + >>> list(itertools.combinations('123', 2)) + [('1', '2'), ('1', '3'), ('2', '3')] + >>> list(itertools.combinations('123', 3)) + [('1', '2', '3')] + >>> list(itertools.combinations('1234', 3)) + [('1', '2', '3'), ('1', '2', '4'), + ('1', '3', '4'), ('2', '3', '4')] ``permutations(iter[, r])`` returns all the permutations of length *r* of the iterable's elements. If *r* is not specified, it will default to the number of elements produced by the iterable. :: - itertools.permutations([1,2,3,4], 2) -> - (1, 2), (1, 3), (1, 4), - (2, 1), (2, 3), (2, 4), - (3, 1), (3, 2), (3, 4), - (4, 1), (4, 2), (4, 3) + >>> list(itertools.permutations([1,2,3,4], 2)) + [(1, 2), (1, 3), (1, 4), + (2, 1), (2, 3), (2, 4), + (3, 1), (3, 2), (3, 4), + (4, 1), (4, 2), (4, 3)] ``itertools.chain(*iterables)`` is an existing function in :mod:`itertools` that gained a new constructor in Python 2.6. @@ -2080,8 +2094,8 @@ then return all the elements of the first iterable, then all the elements of the second, and so on. :: - chain.from_iterable([[1,2,3], [4,5,6]]) -> - 1, 2, 3, 4, 5, 6 + >>> list(itertools.chain.from_iterable([[1,2,3], [4,5,6]])) + [1, 2, 3, 4, 5, 6] (All contributed by Raymond Hettinger.) @@ -2252,16 +2266,15 @@ with an installed Python package. For example:: >>> import pkgutil - >>> pkgutil.get_data('test', 'exception_hierarchy.txt') - 'BaseException + >>> print pkgutil.get_data('test', 'exception_hierarchy.txt') + BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception +-- StopIteration +-- StandardError - ...' - >>> + ... (Contributed by Paul Moore; :issue:`2439`.) @@ -2535,9 +2548,9 @@ with test_support.check_warnings() as wrec: warnings.simplefilter("always") - ... code that triggers a warning ... + # ... code that triggers a warning ... assert str(wrec.message) == "function is outdated" - assert len(wrec.warnings) == 1, "Multiple warnings raised" + assert len(wrec.warnings) == 1, "Multiple warnings raised" (Contributed by Brett Cannon.) @@ -2711,7 +2724,7 @@ t = ast.parse(""" d = {} for i in 'abcdefghijklm': - d[i + i] = ord(i) - ord('a') + 1 + d[i + i] = ord(i) - ord('a') + 1 print d """) print ast.dump(t) @@ -2720,32 +2733,32 @@ Module(body=[ Assign(targets=[ - Name(id='d', ctx=Store()) + Name(id='d', ctx=Store()) ], value=Dict(keys=[], values=[])) For(target=Name(id='i', ctx=Store()), - iter=Str(s='abcdefghijklm'), body=[ - Assign(targets=[ - Subscript(value= - Name(id='d', ctx=Load()), - slice= - Index(value= - BinOp(left=Name(id='i', ctx=Load()), op=Add(), - right=Name(id='i', ctx=Load()))), ctx=Store()) - ], value= - BinOp(left= - BinOp(left= - Call(func= - Name(id='ord', ctx=Load()), args=[ - Name(id='i', ctx=Load()) - ], keywords=[], starargs=None, kwargs=None), - op=Sub(), right=Call(func= - Name(id='ord', ctx=Load()), args=[ - Str(s='a') - ], keywords=[], starargs=None, kwargs=None)), - op=Add(), right=Num(n=1))) - ], orelse=[]) - Print(dest=None, values=[ - Name(id='d', ctx=Load()) + iter=Str(s='abcdefghijklm'), body=[ + Assign(targets=[ + Subscript(value= + Name(id='d', ctx=Load()), + slice= + Index(value= + BinOp(left=Name(id='i', ctx=Load()), op=Add(), + right=Name(id='i', ctx=Load()))), ctx=Store()) + ], value= + BinOp(left= + BinOp(left= + Call(func= + Name(id='ord', ctx=Load()), args=[ + Name(id='i', ctx=Load()) + ], keywords=[], starargs=None, kwargs=None), + op=Sub(), right=Call(func= + Name(id='ord', ctx=Load()), args=[ + Str(s='a') + ], keywords=[], starargs=None, kwargs=None)), + op=Add(), right=Num(n=1))) + ], orelse=[]) + Print(dest=None, values=[ + Name(id='d', ctx=Load()) ], nl=True) ]) @@ -2754,7 +2767,7 @@ returns the resulting value. A literal expression is a Python expression containing only strings, numbers, dictionaries, etc. but no statements or function calls. If you need to -evaluate an expression but accept the security risk of using an +evaluate an expression but cannot accept the security risk of using an :func:`eval` call, :func:`literal_eval` will handle it safely:: >>> literal = '("a", "b", {2:4, 3:8, 1:2})' @@ -2849,8 +2862,8 @@ # Create data structure data_struct = dict(lastAccessed=datetime.datetime.now(), - version=1, - categories=('Personal','Shared','Private')) + version=1, + categories=('Personal','Shared','Private')) # Create string containing XML. plist_str = plistlib.writePlistToString(data_struct) @@ -3040,7 +3053,7 @@ ``numfree``, and a macro ``Py_MAXFREELIST`` is always defined. -* A new Makefile target, "make check", prepares the Python source tree +* A new Makefile target, "make patchcheck", prepares the Python source tree for making a patch: it fixes trailing whitespace in all modified ``.py`` files, checks whether the documentation has been changed, and reports whether the :file:`Misc/ACKS` and :file:`Misc/NEWS` files @@ -3261,13 +3274,13 @@ .. ====================================================================== -.. _acks: +.. _26acks: Acknowledgements ================ The author would like to thank the following people for offering suggestions, corrections and assistance with various drafts of this -article: Georg Brandl, Steve Brown, Nick Coghlan, Jim Jewett, Kent -Johnson, Chris Lambacher, Antoine Pitrou. +article: Georg Brandl, Steve Brown, Nick Coghlan, Ralph Corderoy, +Jim Jewett, Kent Johnson, Chris Lambacher, Antoine Pitrou, Brian Warner. 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 Oct 11 02:49:57 2008 @@ -440,7 +440,7 @@ .. ====================================================================== -.. _section-other: +.. _30section-other: Other Changes and Fixes ======================= Copied: python/branches/py3k/Doc/whatsnew/index.rst (from r66874, /python/trunk/Doc/whatsnew/index.rst) ============================================================================== --- /python/trunk/Doc/whatsnew/index.rst (original) +++ python/branches/py3k/Doc/whatsnew/index.rst Sat Oct 11 02:49:57 2008 @@ -11,6 +11,7 @@ .. toctree:: :maxdepth: 1 + 3.0.rst 2.7.rst 2.6.rst 2.5.rst Modified: python/branches/py3k/Lib/optparse.py ============================================================================== --- python/branches/py3k/Lib/optparse.py (original) +++ python/branches/py3k/Lib/optparse.py Sat Oct 11 02:49:57 2008 @@ -1,21 +1,13 @@ -"""optparse - a powerful, extensible, and easy-to-use option parser. +"""A powerful, extensible, and easy-to-use option parser. By Greg Ward -Originally distributed as Optik; see http://optik.sourceforge.net/ . - -If you have problems with this module, please do not file bugs, -patches, or feature requests with Python; instead, use Optik's -SourceForge project page: - http://sourceforge.net/projects/optik +Originally distributed as Optik. For support, use the optik-users at lists.sourceforge.net mailing list (http://lists.sourceforge.net/lists/listinfo/optik-users). """ -# Python developers: please do not make changes to this file, since -# it is automatically generated from the Optik source code. - __version__ = "1.5.3" __all__ = ['Option', @@ -1263,9 +1255,19 @@ self.usage = usage def enable_interspersed_args(self): + """Set parsing to not stop on the first non-option, allowing + interspersing switches with command arguments. This is the + default behavior. See also disable_interspersed_args() and the + class documentation description of the attribute + allow_interspersed_args.""" self.allow_interspersed_args = True def disable_interspersed_args(self): + """Set parsing to stop on the first non-option. Use this if + you have a command processor which runs another command that + has options of its own and you want to make sure these options + don't get confused. + """ self.allow_interspersed_args = False def set_process_default_values(self, process): Modified: python/branches/py3k/Lib/test/test_atexit.py ============================================================================== --- python/branches/py3k/Lib/test/test_atexit.py (original) +++ python/branches/py3k/Lib/test/test_atexit.py Sat Oct 11 02:49:57 2008 @@ -26,12 +26,13 @@ class TestCase(unittest.TestCase): def setUp(self): self.stream = io.StringIO() + self.save_stdout, self.save_stderr = sys.stderr, sys.stdout sys.stdout = sys.stderr = self.stream atexit._clear() def tearDown(self): - sys.stdout = sys.__stdout__ - sys.stderr = sys.__stderr__ + sys.stdout = self.save_stdout + sys.stderr = self.save_stderr atexit._clear() def test_args(self): Modified: python/branches/py3k/Lib/test/test_bisect.py ============================================================================== --- python/branches/py3k/Lib/test/test_bisect.py (original) +++ python/branches/py3k/Lib/test/test_bisect.py Sat Oct 11 02:49:57 2008 @@ -196,6 +196,17 @@ def test_backcompatibility(self): self.assertEqual(self.module.insort, self.module.insort_right) + def test_listDerived(self): + class List(list): + data = [] + def insert(self, index, item): + self.data.insert(index, item) + + lst = List() + self.module.insort_left(lst, 10) + self.module.insort_right(lst, 5) + self.assertEqual([5, 10], lst.data) + class TestInsortPython(TestInsort): module = py_bisect Modified: python/branches/py3k/Lib/test/test_datetime.py ============================================================================== --- python/branches/py3k/Lib/test/test_datetime.py (original) +++ python/branches/py3k/Lib/test/test_datetime.py Sat Oct 11 02:49:57 2008 @@ -249,7 +249,7 @@ self.assertRaises(TypeError, lambda: a // x) self.assertRaises(TypeError, lambda: x // a) - # Divison of int by timedelta doesn't make sense. + # Division of int by timedelta doesn't make sense. # Division by zero doesn't make sense. for zero in 0, 0: self.assertRaises(TypeError, lambda: zero // a) Modified: python/branches/py3k/Lib/test/test_dbm.py ============================================================================== --- python/branches/py3k/Lib/test/test_dbm.py (original) +++ python/branches/py3k/Lib/test/test_dbm.py Sat Oct 11 02:49:57 2008 @@ -140,6 +140,23 @@ def setUp(self): delete_files() + self.filename = test.support.TESTFN + self.d = dbm.open(self.filename, 'c') + self.d.close() + + def test_keys(self): + self.d = dbm.open(self.filename, 'c') + self.assertEqual(self.d.keys(), []) + a = [(b'a', b'b'), (b'12345678910', b'019237410982340912840198242')] + for k, v in a: + self.d[k] = v + self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a)) + for k, v in a: + self.assert_(k in self.d) + self.assertEqual(self.d[k], v) + self.assert_('xxx' not in self.d) + self.assertRaises(KeyError, lambda: self.d['xxx']) + self.d.close() def test_main(): Modified: python/branches/py3k/Lib/test/test_docxmlrpc.py ============================================================================== --- python/branches/py3k/Lib/test/test_docxmlrpc.py (original) +++ python/branches/py3k/Lib/test/test_docxmlrpc.py Sat Oct 11 02:49:57 2008 @@ -8,9 +8,9 @@ PORT = None def server(evt, numrequests): - try: - serv = DocXMLRPCServer(("localhost", 0), logRequests=False) + serv = DocXMLRPCServer(("localhost", 0), logRequests=False) + try: global PORT PORT = serv.socket.getsockname()[1] 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 Sat Oct 11 02:49:57 2008 @@ -391,6 +391,17 @@ else: self.fail() + def test_remove_keyerror_set(self): + key = self.thetype([3, 4]) + try: + self.s.remove(key) + except KeyError as e: + self.assert_(e.args[0] is key, + "KeyError should be {0}, not {1}".format(key, + e.args[0])) + else: + self.fail() + def test_discard(self): self.s.discard('a') self.assert_('a' not in self.s) Modified: python/branches/py3k/Mac/BuildScript/build-installer.py ============================================================================== --- python/branches/py3k/Mac/BuildScript/build-installer.py (original) +++ python/branches/py3k/Mac/BuildScript/build-installer.py Sat Oct 11 02:49:57 2008 @@ -130,8 +130,8 @@ ), dict( - name="SQLite 3.3.5", - url="http://www.sqlite.org/sqlite-3.3.5.tar.gz", + name="SQLite 3.6.3", + url="http://www.sqlite.org/sqlite-3.6.3.tar.gz", checksum='93f742986e8bc2dfa34792e16df017a6feccf3a2', configure_pre=[ '--enable-threadsafe', @@ -171,8 +171,8 @@ ), ), dict( - name="Sleepycat DB 4.4", - url="http://downloads.sleepycat.com/db-4.4.20.tar.gz", + name="Sleepycat DB 4.7.25", + url="http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz", #name="Sleepycat DB 4.3.29", #url="http://downloads.sleepycat.com/db-4.3.29.tar.gz", buildDir="build_unix", @@ -586,21 +586,23 @@ version = getVersion() docdir = os.path.join(rootDir, 'pydocs') + novername = 'python-docs-html.tar.bz2' name = 'html-%s.tar.bz2'%(getFullVersion(),) sourceArchive = os.path.join(DEPSRC, name) if os.path.exists(sourceArchive): print("Using local copy of %s"%(name,)) else: - print("Downloading %s"%(name,)) + print "Downloading %s"%(novername,) downloadURL('http://www.python.org/ftp/python/doc/%s/%s'%( - getFullVersion(), name), sourceArchive) + getFullVersion(), novername), sourceArchive) print("Archive for %s stored as %s"%(name, sourceArchive)) extractArchive(os.path.dirname(docdir), sourceArchive) + os.rename( os.path.join( - os.path.dirname(docdir), 'Python-Docs-%s'%(getFullVersion(),)), + os.path.dirname(docdir), 'python-docs-html'), docdir) @@ -1029,11 +1031,11 @@ buildPython() buildPythonDocs() fn = os.path.join(WORKDIR, "_root", "Applications", - "MacPython %s"%(getVersion(),), "Update Shell Profile.command") + "Python %s"%(getVersion(),), "Update Shell Profile.command") patchFile("scripts/postflight.patch-profile", fn) os.chmod(fn, 0755) - folder = os.path.join(WORKDIR, "_root", "Applications", "MacPython %s"%( + folder = os.path.join(WORKDIR, "_root", "Applications", "Python %s"%( getVersion(),)) os.chmod(folder, 0755) setIcon(folder, "../Icons/Python Folder.icns") Modified: python/branches/py3k/Makefile.pre.in ============================================================================== --- python/branches/py3k/Makefile.pre.in (original) +++ python/branches/py3k/Makefile.pre.in Sat Oct 11 02:49:57 2008 @@ -176,8 +176,8 @@ BUILDPYTHON= python$(BUILDEXE) # The task to run while instrument when building the profile-opt target -PROFILE_TASK= Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck -#PROFILE_TASK= Lib/test/regrtest.py +PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck +#PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py # === Definitions added by makesetup === Modified: python/branches/py3k/Modules/_bisectmodule.c ============================================================================== --- python/branches/py3k/Modules/_bisectmodule.c (original) +++ python/branches/py3k/Modules/_bisectmodule.c Sat Oct 11 02:49:57 2008 @@ -82,7 +82,7 @@ index = internal_bisect_right(list, item, lo, hi); if (index < 0) return NULL; - if (PyList_Check(list)) { + if (PyList_CheckExact(list)) { if (PyList_Insert(list, index, item) < 0) return NULL; } else { @@ -183,7 +183,7 @@ index = internal_bisect_left(list, item, lo, hi); if (index < 0) return NULL; - if (PyList_Check(list)) { + if (PyList_CheckExact(list)) { if (PyList_Insert(list, index, item) < 0) return NULL; } else { Modified: python/branches/py3k/Modules/_codecsmodule.c ============================================================================== --- python/branches/py3k/Modules/_codecsmodule.c (original) +++ python/branches/py3k/Modules/_codecsmodule.c Sat Oct 11 02:49:57 2008 @@ -108,7 +108,7 @@ to the default encoding. errors may be given to set a different error\n\ handling scheme. Default is 'strict' meaning that encoding errors raise\n\ a ValueError. Other possible values are 'ignore' and 'replace'\n\ -as well as any other name registerd with codecs.register_error that is\n\ +as well as any other name registered with codecs.register_error that is\n\ able to handle ValueErrors."); static PyObject * Modified: python/branches/py3k/Modules/cjkcodecs/multibytecodec.c ============================================================================== --- python/branches/py3k/Modules/cjkcodecs/multibytecodec.c (original) +++ python/branches/py3k/Modules/cjkcodecs/multibytecodec.c Sat Oct 11 02:49:57 2008 @@ -36,7 +36,7 @@ Decodes `string' using I, an MultibyteCodec instance. errors may be given\n\ to set a different error handling scheme. Default is 'strict' meaning\n\ that encoding errors raise a UnicodeDecodeError. Other possible values\n\ -are 'ignore' and 'replace' as well as any other name registerd with\n\ +are 'ignore' and 'replace' as well as any other name registered with\n\ codecs.register_error that is able to handle UnicodeDecodeErrors."); static char *codeckwarglist[] = {"input", "errors", NULL}; Modified: python/branches/py3k/Modules/posixmodule.c ============================================================================== --- python/branches/py3k/Modules/posixmodule.c (original) +++ python/branches/py3k/Modules/posixmodule.c Sat Oct 11 02:49:57 2008 @@ -751,11 +751,16 @@ if (!result) return FALSE; if (result > MAX_PATH+1) { - new_path = malloc(result); + new_path = malloc(result * sizeof(wchar_t)); if (!new_path) { SetLastError(ERROR_OUTOFMEMORY); return FALSE; } + result = GetCurrentDirectoryW(result, new_path); + if (!result) { + free(new_path); + return FALSE; + } } if (wcsncmp(new_path, L"\\\\", 2) == 0 || wcsncmp(new_path, L"//", 2) == 0) Modified: python/branches/py3k/Objects/dictobject.c ============================================================================== --- python/branches/py3k/Objects/dictobject.c (original) +++ python/branches/py3k/Objects/dictobject.c Sat Oct 11 02:49:57 2008 @@ -1870,16 +1870,18 @@ "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D"); PyDoc_STRVAR(pop__doc__, -"D.pop(k[,d]) -> v, remove specified key and return the corresponding value\n\ +"D.pop(k[,d]) -> v, remove specified key and return the corresponding value.\n\ If key is not found, d is returned if given, otherwise KeyError is raised"); PyDoc_STRVAR(popitem__doc__, "D.popitem() -> (k, v), remove and return some (key, value) pair as a\n\ -2-tuple; but raise KeyError if D is empty"); +2-tuple; but raise KeyError if D is empty."); PyDoc_STRVAR(update__doc__, -"D.update(E, **F) -> None. Update D from E and F: for k in E: D[k] = E[k]\ -\n(if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]"); +"D.update(E, **F) -> None. Update D from dict/iterable E and F.\n" +"If E has a .keys() method, does: for k in E: D[k] = E[k]\n\ +If E lacks .keys() method, does: for (k, v) in E: D[k] = v\n\ +In either case, this is followed by: for k in F: D[k] = F[k]"); PyDoc_STRVAR(fromkeys__doc__, "dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.\n\ Modified: python/branches/py3k/Objects/floatobject.c ============================================================================== --- python/branches/py3k/Objects/floatobject.c (original) +++ python/branches/py3k/Objects/floatobject.c Sat Oct 11 02:49:57 2008 @@ -1457,7 +1457,7 @@ #ifdef Py_NAN if (Py_IS_NAN(self)) { PyErr_SetString(PyExc_ValueError, - "Cannot pass nan to float.as_integer_ratio."); + "Cannot pass NaN to float.as_integer_ratio."); return NULL; } #endif @@ -1516,7 +1516,7 @@ "\n" "Returns a pair of integers, whose ratio is exactly equal to the original\n" "float and with a positive denominator.\n" -"Raises OverflowError on infinities and a ValueError on nans.\n" +"Raises OverflowError on infinities and a ValueError on NaNs.\n" "\n" ">>> (10.0).as_integer_ratio()\n" "(10, 1)\n" Modified: python/branches/py3k/Objects/listobject.c ============================================================================== --- python/branches/py3k/Objects/listobject.c (original) +++ python/branches/py3k/Objects/listobject.c Sat Oct 11 02:49:57 2008 @@ -2286,11 +2286,14 @@ PyDoc_STRVAR(insert_doc, "L.insert(index, object) -- insert object before index"); PyDoc_STRVAR(pop_doc, -"L.pop([index]) -> item -- remove and return item at index (default last)"); +"L.pop([index]) -> item -- remove and return item at index (default last).\n" +"Raises IndexError if list is empty or index is out of range."); PyDoc_STRVAR(remove_doc, -"L.remove(value) -- remove first occurrence of value"); +"L.remove(value) -- remove first occurrence of value.\n" +"Raises ValueError if the value is not present."); PyDoc_STRVAR(index_doc, -"L.index(value, [start, [stop]]) -> integer -- return first index of value"); +"L.index(value, [start, [stop]]) -> integer -- return first index of value.\n" +"Raises ValueError if the value is not present."); PyDoc_STRVAR(count_doc, "L.count(value) -> integer -- return number of occurrences of value"); PyDoc_STRVAR(reverse_doc, Modified: python/branches/py3k/Objects/setobject.c ============================================================================== --- python/branches/py3k/Objects/setobject.c (original) +++ python/branches/py3k/Objects/setobject.c Sat Oct 11 02:49:57 2008 @@ -746,7 +746,8 @@ return key; } -PyDoc_STRVAR(pop_doc, "Remove and return an arbitrary set element."); +PyDoc_STRVAR(pop_doc, "Remove and return an arbitrary set element.\n\ +Raises KeyError if the set is empty."); static int set_traverse(PySetObject *so, visitproc visit, void *arg) @@ -1861,7 +1862,7 @@ static PyObject * set_remove(PySetObject *so, PyObject *key) { - PyObject *tmpkey, *result; + PyObject *tmpkey; int rv; rv = set_discard_key(so, key); @@ -1873,11 +1874,14 @@ if (tmpkey == NULL) return NULL; set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); - result = set_remove(so, tmpkey); + rv = set_discard_key(so, tmpkey); set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); Py_DECREF(tmpkey); - return result; - } else if (rv == DISCARD_NOTFOUND) { + if (rv == -1) + return NULL; + } + + if (rv == DISCARD_NOTFOUND) { set_key_error(key); return NULL; } Modified: python/branches/py3k/Objects/tupleobject.c ============================================================================== --- python/branches/py3k/Objects/tupleobject.c (original) +++ python/branches/py3k/Objects/tupleobject.c Sat Oct 11 02:49:57 2008 @@ -694,7 +694,9 @@ } PyDoc_STRVAR(index_doc, -"T.index(value, [start, [stop]]) -> integer -- return first index of value"); +"T.index(value, [start, [stop]]) -> integer -- return first index of value.\n" +"Raises ValueError if the value is not present." +); PyDoc_STRVAR(count_doc, "T.count(value) -> integer -- return number of occurrences of value"); PyDoc_STRVAR(sizeof_doc, Modified: python/branches/py3k/Objects/unicodeobject.c ============================================================================== --- python/branches/py3k/Objects/unicodeobject.c (original) +++ python/branches/py3k/Objects/unicodeobject.c Sat Oct 11 02:49:57 2008 @@ -7300,7 +7300,7 @@ PyDoc_STRVAR(ljust__doc__, "S.ljust(width[, fillchar]) -> str\n\ \n\ -Return S left justified in a Unicode string of length width. Padding is\n\ +Return S left-justified in a Unicode string of length width. Padding is\n\ done using the specified fill character (default is a space)."); static PyObject * @@ -7815,7 +7815,7 @@ PyDoc_STRVAR(rjust__doc__, "S.rjust(width[, fillchar]) -> str\n\ \n\ -Return S right justified in a string of length width. Padding is\n\ +Return S right-justified in a string of length width. Padding is\n\ done using the specified fill character (default is a space)."); static PyObject * @@ -7945,7 +7945,7 @@ \n\ Search for the separator sep in S, and return the part before it,\n\ the separator itself, and the part after it. If the separator is not\n\ -found, returns S and two empty strings."); +found, return S and two empty strings."); static PyObject* unicode_partition(PyUnicodeObject *self, PyObject *separator) @@ -7958,7 +7958,7 @@ \n\ Search for the separator sep in S, starting at the end of S, and return\n\ the part before it, the separator itself, and the part after it. If the\n\ -separator is not found, returns two empty strings and S."); +separator is not found, return two empty strings and S."); static PyObject* unicode_rpartition(PyUnicodeObject *self, PyObject *separator) Modified: python/branches/py3k/setup.py ============================================================================== --- python/branches/py3k/setup.py (original) +++ python/branches/py3k/setup.py Sat Oct 11 02:49:57 2008 @@ -730,7 +730,8 @@ ] sqlite_libfile = self.compiler.find_library_file( sqlite_dirs_to_check + lib_dirs, 'sqlite3') - sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] + if sqlite_libfile: + sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] if sqlite_incdir and sqlite_libdir: sqlite_srcs = ['_sqlite/cache.c', From python-3000-checkins at python.org Sat Oct 11 04:19:19 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 11 Oct 2008 04:19:19 +0200 (CEST) Subject: [Python-3000-checkins] r66877 - python/branches/py3k/Lib/test/test_dbm.py Message-ID: <20081011021919.1B5A11E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 11 04:19:18 2008 New Revision: 66877 Log: fix merge boo-boo Modified: python/branches/py3k/Lib/test/test_dbm.py Modified: python/branches/py3k/Lib/test/test_dbm.py ============================================================================== --- python/branches/py3k/Lib/test/test_dbm.py (original) +++ python/branches/py3k/Lib/test/test_dbm.py Sat Oct 11 04:19:18 2008 @@ -154,8 +154,8 @@ for k, v in a: self.assert_(k in self.d) self.assertEqual(self.d[k], v) - self.assert_('xxx' not in self.d) - self.assertRaises(KeyError, lambda: self.d['xxx']) + self.assert_(b'xxx' not in self.d) + self.assertRaises(KeyError, lambda: self.d[b'xxx']) self.d.close() From python-3000-checkins at python.org Sun Oct 12 14:51:12 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 12 Oct 2008 14:51:12 +0200 (CEST) Subject: [Python-3000-checkins] r66880 - python/branches/py3k/Doc/reference/datamodel.rst Message-ID: <20081012125112.6695F1E401F@bag.python.org> Author: benjamin.peterson Date: Sun Oct 12 14:51:12 2008 New Revision: 66880 Log: remove a mention of backtick repr Modified: python/branches/py3k/Doc/reference/datamodel.rst Modified: python/branches/py3k/Doc/reference/datamodel.rst ============================================================================== --- python/branches/py3k/Doc/reference/datamodel.rst (original) +++ python/branches/py3k/Doc/reference/datamodel.rst Sun Oct 12 14:51:12 2008 @@ -1108,15 +1108,14 @@ .. index:: builtin: repr - Called by the :func:`repr` built-in function and by string conversions (reverse - quotes) to compute the "official" string representation of an object. If at all - possible, this should look like a valid Python expression that could be used to - recreate an object with the same value (given an appropriate environment). If - this is not possible, a string of the form ``<...some useful description...>`` - should be returned. The return value must be a string object. If a class - defines :meth:`__repr__` but not :meth:`__str__`, then :meth:`__repr__` is also - used when an "informal" string representation of instances of that class is - required. + Called by the :func:`repr` built-in function to compute the "official" string + representation of an object. If at all possible, this should look like a + valid Python expression that could be used to recreate an object with the + same value (given an appropriate environment). If this is not possible, a + string of the form ``<...some useful description...>`` should be returned. + The return value must be a string object. If a class defines :meth:`__repr__` + but not :meth:`__str__`, then :meth:`__repr__` is also used when an + "informal" string representation of instances of that class is required. This is typically used for debugging, so it is important that the representation is information-rich and unambiguous. From python-3000-checkins at python.org Mon Oct 13 13:30:30 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Mon, 13 Oct 2008 13:30:30 +0200 (CEST) Subject: [Python-3000-checkins] r66883 - in python/branches/py3k: Misc/NEWS Tools/msi/msi.py Message-ID: <20081013113030.A7E351E4002@bag.python.org> Author: martin.v.loewis Date: Mon Oct 13 13:30:30 2008 New Revision: 66883 Log: Merged revisions 66881 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66881 | martin.v.loewis | 2008-10-13 13:23:35 +0200 (Mo, 13 Okt 2008) | 2 lines Issue #4018: Disable "for me" installations on Vista. ........ 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 Mon Oct 13 13:30:30 2008 @@ -58,6 +58,11 @@ - Issue #3659: Subclasses of str didn't work as SQL parameters. +Build +----- + +- Issue #4018: Disable "for me" installations on Vista. + What's New in Python 3.0 release candidate 1 ============================================ Modified: python/branches/py3k/Tools/msi/msi.py ============================================================================== --- python/branches/py3k/Tools/msi/msi.py (original) +++ python/branches/py3k/Tools/msi/msi.py Mon Oct 13 13:30:30 2008 @@ -218,7 +218,8 @@ schema, ProductName="Python "+full_current_version+productsuffix, ProductCode=product_code, ProductVersion=current_version, - Manufacturer=u"Python Software Foundation") + Manufacturer=u"Python Software Foundation", + request_uac = True) # The default sequencing of the RemoveExistingProducts action causes # removal of files that got just installed. Place it after # InstallInitialize, so we first uninstall everything, but still roll @@ -698,10 +699,11 @@ "AdminInstall", "Next", "Cancel") whichusers.title("Select whether to install [ProductName] for all users of this computer.") # A radio group with two options: allusers, justme - g = whichusers.radiogroup("AdminInstall", 135, 60, 160, 50, 3, + g = whichusers.radiogroup("AdminInstall", 135, 60, 235, 80, 3, "WhichUsers", "", "Next") + g.condition("Disable", "VersionNT=600") # Not available on Vista and Windows 2008 g.add("ALL", 0, 5, 150, 20, "Install for all users") - g.add("JUSTME", 0, 25, 150, 20, "Install just for me") + g.add("JUSTME", 0, 25, 235, 20, "Install just for me (not available on Windows Vista)") whichusers.back("Back", None, active=0) From python-3000-checkins at python.org Wed Oct 15 01:07:40 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 15 Oct 2008 01:07:40 +0200 (CEST) Subject: [Python-3000-checkins] r66895 - in python/branches/py3k: Lib/sre_compile.py Lib/sre_parse.py Message-ID: <20081014230740.6BD531E4002@bag.python.org> Author: benjamin.peterson Date: Wed Oct 15 01:07:40 2008 New Revision: 66895 Log: Merged revisions 66894 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66894 | benjamin.peterson | 2008-10-14 17:37:18 -0500 (Tue, 14 Oct 2008) | 1 line remove set compat cruft ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/sre_compile.py python/branches/py3k/Lib/sre_parse.py Modified: python/branches/py3k/Lib/sre_compile.py ============================================================================== --- python/branches/py3k/Lib/sre_compile.py (original) +++ python/branches/py3k/Lib/sre_compile.py Wed Oct 15 01:07:40 2008 @@ -24,12 +24,6 @@ def _identityfunction(x): return x -def set(seq): - s = {} - for elem in seq: - s[elem] = 1 - return s - _LITERAL_CODES = set([LITERAL, NOT_LITERAL]) _REPEATING_CODES = set([REPEAT, MIN_REPEAT, MAX_REPEAT]) _SUCCESS_CODES = set([SUCCESS, FAILURE]) Modified: python/branches/py3k/Lib/sre_parse.py ============================================================================== --- python/branches/py3k/Lib/sre_parse.py (original) +++ python/branches/py3k/Lib/sre_parse.py Wed Oct 15 01:07:40 2008 @@ -16,12 +16,6 @@ from sre_constants import * -def set(seq): - s = {} - for elem in seq: - s[elem] = 1 - return s - SPECIAL_CHARS = ".\\[{()*+?^$|" REPEAT_CHARS = "*+?{" From python-3000-checkins at python.org Wed Oct 15 05:09:46 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 15 Oct 2008 05:09:46 +0200 (CEST) Subject: [Python-3000-checkins] r66897 - python/branches/py3k/Doc/library/reprlib.rst Message-ID: <20081015030946.8FB071E4002@bag.python.org> Author: benjamin.peterson Date: Wed Oct 15 05:09:45 2008 New Revision: 66897 Log: correct changed import Modified: python/branches/py3k/Doc/library/reprlib.rst Modified: python/branches/py3k/Doc/library/reprlib.rst ============================================================================== --- python/branches/py3k/Doc/library/reprlib.rst (original) +++ python/branches/py3k/Doc/library/reprlib.rst Wed Oct 15 05:09:45 2008 @@ -118,10 +118,10 @@ the handling of types already supported. This example shows how special support for file objects could be added:: - import repr + import reprlib import sys - class MyRepr(repr.Repr): + class MyRepr(reprlib.Repr): def repr_file(self, obj, level): if obj.name in ['', '', '']: return obj.name From python-3000-checkins at python.org Wed Oct 15 07:58:18 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Wed, 15 Oct 2008 07:58:18 +0200 (CEST) Subject: [Python-3000-checkins] r66901 - in python/branches/py3k: Demo/distutils Demo/distutils/test2to3 Demo/distutils/test2to3/README Demo/distutils/test2to3/setup.py Demo/distutils/test2to3/test2to3 Demo/distutils/test2to3/test2to3/__init__.py Demo/distutils/test2to3/test2to3/hello.py Lib/distutils/command/build_py.py Misc/NEWS Message-ID: <20081015055818.8A4401E4002@bag.python.org> Author: martin.v.loewis Date: Wed Oct 15 07:58:17 2008 New Revision: 66901 Log: Issue #4072: Restore build_py_2to3. Add a distutils demo for build_py_2to3. Added: python/branches/py3k/Demo/distutils/ python/branches/py3k/Demo/distutils/test2to3/ python/branches/py3k/Demo/distutils/test2to3/README (contents, props changed) python/branches/py3k/Demo/distutils/test2to3/setup.py (contents, props changed) python/branches/py3k/Demo/distutils/test2to3/test2to3/ python/branches/py3k/Demo/distutils/test2to3/test2to3/__init__.py (contents, props changed) python/branches/py3k/Demo/distutils/test2to3/test2to3/hello.py (contents, props changed) Modified: python/branches/py3k/Lib/distutils/command/build_py.py python/branches/py3k/Misc/NEWS Added: python/branches/py3k/Demo/distutils/test2to3/README ============================================================================== --- (empty file) +++ python/branches/py3k/Demo/distutils/test2to3/README Wed Oct 15 07:58:17 2008 @@ -0,0 +1,3 @@ +This project demonstrates how a distutils package +can support Python 2.x and Python 3.x from a single +source, using lib2to3. \ No newline at end of file Added: python/branches/py3k/Demo/distutils/test2to3/setup.py ============================================================================== --- (empty file) +++ python/branches/py3k/Demo/distutils/test2to3/setup.py Wed Oct 15 07:58:17 2008 @@ -0,0 +1,18 @@ +# -*- coding: iso-8859-1 -*- +from distutils.core import setup + +try: + from distutils.command.build_py import build_py_2to3 as build_py +except ImportError: + from distutils.command.build_py import build_py + +setup( + name = "test2to3", + version = "1.0", + description = "2to3 distutils test package", + author = "Martin v. L?wis", + author_email = "python-dev at python.org", + license = "PSF license", + packages = ["test2to3"], + cmdclass = {'build_py':build_py} +) Added: python/branches/py3k/Demo/distutils/test2to3/test2to3/__init__.py ============================================================================== --- (empty file) +++ python/branches/py3k/Demo/distutils/test2to3/test2to3/__init__.py Wed Oct 15 07:58:17 2008 @@ -0,0 +1 @@ +# empty Added: python/branches/py3k/Demo/distutils/test2to3/test2to3/hello.py ============================================================================== --- (empty file) +++ python/branches/py3k/Demo/distutils/test2to3/test2to3/hello.py Wed Oct 15 07:58:17 2008 @@ -0,0 +1,5 @@ +def hello(): + try: + print "Hello, world" + except IOError, e: + print e.errno Modified: python/branches/py3k/Lib/distutils/command/build_py.py ============================================================================== --- python/branches/py3k/Lib/distutils/command/build_py.py (original) +++ python/branches/py3k/Lib/distutils/command/build_py.py Wed Oct 15 07:58:17 2008 @@ -384,6 +384,18 @@ byte_compile(files, optimize=self.optimize, force=self.force, prefix=prefix, dry_run=self.dry_run) +from lib2to3.refactor import RefactoringTool, get_fixers_from_package +class DistutilsRefactoringTool(RefactoringTool): + def log_error(self, msg, *args, **kw): + # XXX ignores kw + log.error(msg, *args) + + def log_message(self, msg, *args): + log.info(msg, *args) + + def log_debug(self, msg, *args): + log.debug(msg, *args) + class build_py_2to3(build_py): def run(self): self.updated_files = [] @@ -396,18 +408,12 @@ self.build_package_data() # 2to3 - from lib2to3.refactor import RefactoringTool - class Options: - pass - o = Options() - o.doctests_only = False - o.fix = [] - o.list_fixes = [] - o.print_function = False - o.verbose = False - o.write = True - r = RefactoringTool(o) - r.refactor_args(self.updated_files) + fixers = get_fixers_from_package('lib2to3.fixes') + options = dict(fix=[], list_fixes=[], + print_function=False, verbose=False, + write=True) + r = DistutilsRefactoringTool(fixers, options) + r.refactor(self.updated_files, write=True) # Remaining base class code self.byte_compile(self.get_outputs(include_bytecode=0)) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Oct 15 07:58:17 2008 @@ -31,6 +31,8 @@ Library ------- +- Issue #4072: Restore build_py_2to3. + - Issue #4014: Don't claim that Python has an Alpha release status, in addition to claiming it is Mature. @@ -63,6 +65,11 @@ - Issue #4018: Disable "for me" installations on Vista. +Tools/Demos +----------- + +- Issue #4072: Add a distutils demo for build_py_2to3. + What's New in Python 3.0 release candidate 1 ============================================ From python-3000-checkins at python.org Wed Oct 15 22:54:25 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 15 Oct 2008 22:54:25 +0200 (CEST) Subject: [Python-3000-checkins] r66904 - in python/branches/py3k: Doc/library/telnetlib.rst Lib/telnetlib.py Misc/NEWS Message-ID: <20081015205425.4F5671E4002@bag.python.org> Author: benjamin.peterson Date: Wed Oct 15 22:54:24 2008 New Revision: 66904 Log: Victor Stinner's patch to make telnetlib use bytes 3725 Modified: python/branches/py3k/Doc/library/telnetlib.rst python/branches/py3k/Lib/telnetlib.py python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Doc/library/telnetlib.rst ============================================================================== --- python/branches/py3k/Doc/library/telnetlib.rst (original) +++ python/branches/py3k/Doc/library/telnetlib.rst Wed Oct 15 22:54:24 2008 @@ -225,14 +225,14 @@ tn = telnetlib.Telnet(HOST) - tn.read_until("login: ") - tn.write(user + "\n") + tn.read_until(b"login: ") + tn.write(user.encode('ascii') + b"\n") if password: - tn.read_until("Password: ") - tn.write(password + "\n") + tn.read_until(b"Password: ") + tn.write(password.encode('ascii') + b"\n") - tn.write("ls\n") - tn.write("exit\n") + tn.write(b"ls\n") + tn.write(b"exit\n") print(tn.read_all()) Modified: python/branches/py3k/Lib/telnetlib.py ============================================================================== --- python/branches/py3k/Lib/telnetlib.py (original) +++ python/branches/py3k/Lib/telnetlib.py Wed Oct 15 22:54:24 2008 @@ -7,7 +7,7 @@ >>> from telnetlib import Telnet >>> tn = Telnet('www.python.org', 79) # connect to finger port ->>> tn.write('guido\r\n') +>>> tn.write(b'guido\r\n') >>> print(tn.read_all()) Login Name TTY Idle When Where guido Guido van Rossum pts/2 snag.cnri.reston.. @@ -19,7 +19,7 @@ It is possible to pass a Telnet object to select.select() in order to wait until more data is available. Note that in this case, -read_eager() may return '' even if there was data on the socket, +read_eager() may return b'' even if there was data on the socket, because the protocol negotiation may have eaten the data. This is why EOFError is needed in some cases to distinguish between "no data" and "connection closed" (since the socket also appears ready for reading @@ -47,87 +47,87 @@ TELNET_PORT = 23 # Telnet protocol characters (don't change) -IAC = chr(255) # "Interpret As Command" -DONT = chr(254) -DO = chr(253) -WONT = chr(252) -WILL = chr(251) -theNULL = chr(0) - -SE = chr(240) # Subnegotiation End -NOP = chr(241) # No Operation -DM = chr(242) # Data Mark -BRK = chr(243) # Break -IP = chr(244) # Interrupt process -AO = chr(245) # Abort output -AYT = chr(246) # Are You There -EC = chr(247) # Erase Character -EL = chr(248) # Erase Line -GA = chr(249) # Go Ahead -SB = chr(250) # Subnegotiation Begin +IAC = 255 # "Interpret As Command" +DONT = 254 +DO = 253 +WONT = 252 +WILL = 251 +theNULL = 0 + +SE = 240 # Subnegotiation End +NOP = 241 # No Operation +DM = 242 # Data Mark +BRK = 243 # Break +IP = 244 # Interrupt process +AO = 245 # Abort output +AYT = 246 # Are You There +EC = 247 # Erase Character +EL = 248 # Erase Line +GA = 249 # Go Ahead +SB = 250 # Subnegotiation Begin # Telnet protocol options code (don't change) # These ones all come from arpa/telnet.h -BINARY = chr(0) # 8-bit data path -ECHO = chr(1) # echo -RCP = chr(2) # prepare to reconnect -SGA = chr(3) # suppress go ahead -NAMS = chr(4) # approximate message size -STATUS = chr(5) # give status -TM = chr(6) # timing mark -RCTE = chr(7) # remote controlled transmission and echo -NAOL = chr(8) # negotiate about output line width -NAOP = chr(9) # negotiate about output page size -NAOCRD = chr(10) # negotiate about CR disposition -NAOHTS = chr(11) # negotiate about horizontal tabstops -NAOHTD = chr(12) # negotiate about horizontal tab disposition -NAOFFD = chr(13) # negotiate about formfeed disposition -NAOVTS = chr(14) # negotiate about vertical tab stops -NAOVTD = chr(15) # negotiate about vertical tab disposition -NAOLFD = chr(16) # negotiate about output LF disposition -XASCII = chr(17) # extended ascii character set -LOGOUT = chr(18) # force logout -BM = chr(19) # byte macro -DET = chr(20) # data entry terminal -SUPDUP = chr(21) # supdup protocol -SUPDUPOUTPUT = chr(22) # supdup output -SNDLOC = chr(23) # send location -TTYPE = chr(24) # terminal type -EOR = chr(25) # end or record -TUID = chr(26) # TACACS user identification -OUTMRK = chr(27) # output marking -TTYLOC = chr(28) # terminal location number -VT3270REGIME = chr(29) # 3270 regime -X3PAD = chr(30) # X.3 PAD -NAWS = chr(31) # window size -TSPEED = chr(32) # terminal speed -LFLOW = chr(33) # remote flow control -LINEMODE = chr(34) # Linemode option -XDISPLOC = chr(35) # X Display Location -OLD_ENVIRON = chr(36) # Old - Environment variables -AUTHENTICATION = chr(37) # Authenticate -ENCRYPT = chr(38) # Encryption option -NEW_ENVIRON = chr(39) # New - Environment variables +BINARY = 0 # 8-bit data path +ECHO = 1 # echo +RCP = 2 # prepare to reconnect +SGA = 3 # suppress go ahead +NAMS = 4 # approximate message size +STATUS = 5 # give status +TM = 6 # timing mark +RCTE = 7 # remote controlled transmission and echo +NAOL = 8 # negotiate about output line width +NAOP = 9 # negotiate about output page size +NAOCRD = 10 # negotiate about CR disposition +NAOHTS = 11 # negotiate about horizontal tabstops +NAOHTD = 12 # negotiate about horizontal tab disposition +NAOFFD = 13 # negotiate about formfeed disposition +NAOVTS = 14 # negotiate about vertical tab stops +NAOVTD = 15 # negotiate about vertical tab disposition +NAOLFD = 16 # negotiate about output LF disposition +XASCII = 17 # extended ascii character set +LOGOUT = 18 # force logout +BM = 19 # byte macro +DET = 20 # data entry terminal +SUPDUP = 21 # supdup protocol +SUPDUPOUTPUT = 22 # supdup output +SNDLOC = 23 # send location +TTYPE = 24 # terminal type +EOR = 25 # end or record +TUID = 26 # TACACS user identification +OUTMRK = 27 # output marking +TTYLOC = 28 # terminal location number +VT3270REGIME = 29 # 3270 regime +X3PAD = 30 # X.3 PAD +NAWS = 31 # window size +TSPEED = 32 # terminal speed +LFLOW = 33 # remote flow control +LINEMODE = 34 # Linemode option +XDISPLOC = 35 # X Display Location +OLD_ENVIRON = 36 # Old - Environment variables +AUTHENTICATION = 37 # Authenticate +ENCRYPT = 38 # Encryption option +NEW_ENVIRON = 39 # New - Environment variables # the following ones come from # http://www.iana.org/assignments/telnet-options # Unfortunately, that document does not assign identifiers # to all of them, so we are making them up -TN3270E = chr(40) # TN3270E -XAUTH = chr(41) # XAUTH -CHARSET = chr(42) # CHARSET -RSP = chr(43) # Telnet Remote Serial Port -COM_PORT_OPTION = chr(44) # Com Port Control Option -SUPPRESS_LOCAL_ECHO = chr(45) # Telnet Suppress Local Echo -TLS = chr(46) # Telnet Start TLS -KERMIT = chr(47) # KERMIT -SEND_URL = chr(48) # SEND-URL -FORWARD_X = chr(49) # FORWARD_X -PRAGMA_LOGON = chr(138) # TELOPT PRAGMA LOGON -SSPI_LOGON = chr(139) # TELOPT SSPI LOGON -PRAGMA_HEARTBEAT = chr(140) # TELOPT PRAGMA HEARTBEAT -EXOPL = chr(255) # Extended-Options-List -NOOPT = chr(0) +TN3270E = 40 # TN3270E +XAUTH = 41 # XAUTH +CHARSET = 42 # CHARSET +RSP = 43 # Telnet Remote Serial Port +COM_PORT_OPTION = 44 # Com Port Control Option +SUPPRESS_LOCAL_ECHO = 45 # Telnet Suppress Local Echo +TLS = 46 # Telnet Start TLS +KERMIT = 47 # KERMIT +SEND_URL = 48 # SEND-URL +FORWARD_X = 49 # FORWARD_X +PRAGMA_LOGON = 138 # TELOPT PRAGMA LOGON +SSPI_LOGON = 139 # TELOPT SSPI LOGON +PRAGMA_HEARTBEAT = 140 # TELOPT PRAGMA HEARTBEAT +EXOPL = 255 # Extended-Options-List +NOOPT = 0 class Telnet: @@ -197,13 +197,13 @@ self.port = port self.timeout = timeout self.sock = None - self.rawq = '' + self.rawq = b'' self.irawq = 0 - self.cookedq = '' + self.cookedq = b'' self.eof = 0 - self.iacseq = '' # Buffer for IAC sequence. + self.iacseq = b'' # Buffer for IAC sequence. self.sb = 0 # flag for SB and SE sequence. - self.sbdataq = '' + self.sbdataq = b'' self.option_callback = None if host is not None: self.open(host, port, timeout) @@ -256,7 +256,7 @@ self.sock.close() self.sock = 0 self.eof = 1 - self.iacseq = '' + self.iacseq = b'' self.sb = 0 def get_socket(self): @@ -325,13 +325,13 @@ self.fill_rawq() self.process_rawq() buf = self.cookedq - self.cookedq = '' + self.cookedq = b'' return buf def read_some(self): """Read at least one byte of cooked data unless EOF is hit. - Return '' if EOF is hit. Block if no data is immediately + Return b'' if EOF is hit. Block if no data is immediately available. """ @@ -340,14 +340,14 @@ self.fill_rawq() self.process_rawq() buf = self.cookedq - self.cookedq = '' + self.cookedq = b'' return buf def read_very_eager(self): """Read everything that's possible without blocking in I/O (eager). Raise EOFError if connection closed and no cooked data - available. Return '' if no cooked data available otherwise. + available. Return b'' if no cooked data available otherwise. Don't block unless in the midst of an IAC sequence. """ @@ -361,7 +361,7 @@ """Read readily available data. Raise EOFError if connection closed and no cooked data - available. Return '' if no cooked data available otherwise. + available. Return b'' if no cooked data available otherwise. Don't block unless in the midst of an IAC sequence. """ @@ -375,7 +375,7 @@ """Process and return data that's already in the queues (lazy). Raise EOFError if connection closed and no data available. - Return '' if no cooked data available otherwise. Don't block + Return b'' if no cooked data available otherwise. Don't block unless in the midst of an IAC sequence. """ @@ -386,11 +386,11 @@ """Return any data available in the cooked queue (very lazy). Raise EOFError if connection closed and no data available. - Return '' if no cooked data available otherwise. Don't block. + Return b'' if no cooked data available otherwise. Don't block. """ buf = self.cookedq - self.cookedq = '' + self.cookedq = b'' if not buf and self.eof and not self.rawq: raise EOFError('telnet connection closed') return buf @@ -398,13 +398,13 @@ def read_sb_data(self): """Return any data available in the SB ... SE queue. - Return '' if no SB ... SE available. Should only be called + Return b'' if no SB ... SE available. Should only be called after seeing a SB or SE command. When a new SB command is found, old unread SB data will be discarded. Don't block. """ buf = self.sbdataq - self.sbdataq = '' + self.sbdataq = b'' return buf def set_option_negotiation_callback(self, callback): @@ -418,14 +418,14 @@ the midst of an IAC sequence. """ - buf = ['', ''] + buf = [b'', b''] try: while self.rawq: c = self.rawq_getchar() if not self.iacseq: if c == theNULL: continue - if c == "\021": + if c == b"\021": continue if c != IAC: buf[self.sb] = buf[self.sb] + c @@ -438,17 +438,17 @@ self.iacseq += c continue - self.iacseq = '' + self.iacseq = b'' if c == IAC: buf[self.sb] = buf[self.sb] + c else: if c == SB: # SB ... SE start. self.sb = 1 - self.sbdataq = '' + self.sbdataq = b'' elif c == SE: self.sb = 0 self.sbdataq = self.sbdataq + buf[1] - buf[1] = '' + buf[1] = b'' if self.option_callback: # Callback is supposed to look into # the sbdataq @@ -460,7 +460,7 @@ self.msg('IAC %d not recognized' % ord(c)) elif len(self.iacseq) == 2: cmd = self.iacseq[1] - self.iacseq = '' + self.iacseq = b'' opt = c if cmd in (DO, DONT): self.msg('IAC %s %d', @@ -477,7 +477,7 @@ else: self.sock.sendall(IAC + DONT + opt) except EOFError: # raised by self.rawq_getchar() - self.iacseq = '' # Reset on EOF + self.iacseq = b'' # Reset on EOF self.sb = 0 pass self.cookedq = self.cookedq + buf[0] @@ -494,10 +494,10 @@ self.fill_rawq() if self.eof: raise EOFError - c = self.rawq[self.irawq] + c = self.rawq[self.irawq:self.irawq+1] self.irawq = self.irawq + 1 if self.irawq >= len(self.rawq): - self.rawq = '' + self.rawq = b'' self.irawq = 0 return c @@ -509,7 +509,7 @@ """ if self.irawq >= len(self.rawq): - self.rawq = '' + self.rawq = b'' self.irawq = 0 # The buffer size should be fairly small so as to avoid quadratic # behavior in process_rawq() above @@ -536,10 +536,10 @@ print('*** Connection closed by remote host ***') break if text: - sys.stdout.write(text) + sys.stdout.write(text.decode('ascii')) sys.stdout.flush() if sys.stdin in rfd: - line = sys.stdin.readline() + line = sys.stdin.readline().encode('ascii') if not line: break self.write(line) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Wed Oct 15 22:54:24 2008 @@ -31,6 +31,8 @@ Library ------- +- telnetlib now works completely in bytes. + - Issue #4072: Restore build_py_2to3. - Issue #4014: Don't claim that Python has an Alpha release status, in addition From python-3000-checkins at python.org Thu Oct 16 00:28:55 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 16 Oct 2008 00:28:55 +0200 (CEST) Subject: [Python-3000-checkins] r66909 - python/branches/py3k/Doc/library/telnetlib.rst Message-ID: <20081015222855.339FD1E4027@bag.python.org> Author: benjamin.peterson Date: Thu Oct 16 00:28:54 2008 New Revision: 66909 Log: use bytes throughout telnetlib docs Modified: python/branches/py3k/Doc/library/telnetlib.rst Modified: python/branches/py3k/Doc/library/telnetlib.rst ============================================================================== --- python/branches/py3k/Doc/library/telnetlib.rst (original) +++ python/branches/py3k/Doc/library/telnetlib.rst Thu Oct 16 00:28:54 2008 @@ -62,58 +62,58 @@ .. method:: Telnet.read_until(expected[, timeout]) - Read until a given string, *expected*, is encountered or until *timeout* seconds - have passed. + Read until a given byte string, *expected*, is encountered or until *timeout* + seconds have passed. - When no match is found, return whatever is available instead, possibly the empty - string. Raise :exc:`EOFError` if the connection is closed and no cooked data is - available. + When no match is found, return whatever is available instead, possibly empty + bytes. Raise :exc:`EOFError` if the connection is closed and no cooked data + is available. .. method:: Telnet.read_all() - Read all data until EOF; block until connection closed. + Read all data until EOF as bytes; block until connection closed. .. method:: Telnet.read_some() - Read at least one byte of cooked data unless EOF is hit. Return ``''`` if EOF is - hit. Block if no data is immediately available. + Read at least one byte of cooked data unless EOF is hit. Return ``b''`` if + EOF is hit. Block if no data is immediately available. .. method:: Telnet.read_very_eager() Read everything that can be without blocking in I/O (eager). - Raise :exc:`EOFError` if connection closed and no cooked data available. Return - ``''`` if no cooked data available otherwise. Do not block unless in the midst - of an IAC sequence. + Raise :exc:`EOFError` if connection closed and no cooked data available. + Return ``b''`` if no cooked data available otherwise. Do not block unless in + the midst of an IAC sequence. .. method:: Telnet.read_eager() Read readily available data. - Raise :exc:`EOFError` if connection closed and no cooked data available. Return - ``''`` if no cooked data available otherwise. Do not block unless in the midst - of an IAC sequence. + Raise :exc:`EOFError` if connection closed and no cooked data available. + Return ``b''`` if no cooked data available otherwise. Do not block unless in + the midst of an IAC sequence. .. method:: Telnet.read_lazy() Process and return data already in the queues (lazy). - Raise :exc:`EOFError` if connection closed and no data available. Return ``''`` - if no cooked data available otherwise. Do not block unless in the midst of an - IAC sequence. + Raise :exc:`EOFError` if connection closed and no data available. Return + ``b''`` if no cooked data available otherwise. Do not block unless in the + midst of an IAC sequence. .. method:: Telnet.read_very_lazy() Return any data available in the cooked queue (very lazy). - Raise :exc:`EOFError` if connection closed and no data available. Return ``''`` - if no cooked data available otherwise. This method never blocks. + Raise :exc:`EOFError` if connection closed and no data available. Return + ``b''`` if no cooked data available otherwise. This method never blocks. .. method:: Telnet.read_sb_data() @@ -163,9 +163,9 @@ .. method:: Telnet.write(buffer) - Write a string to the socket, doubling any IAC characters. This can block if the - connection is blocked. May raise :exc:`socket.error` if the connection is - closed. + Write a byte string to the socket, doubling any IAC characters. This can + block if the connection is blocked. May raise :exc:`socket.error` if the + connection is closed. .. method:: Telnet.interact() @@ -183,20 +183,21 @@ Read until one from a list of a regular expressions matches. The first argument is a list of regular expressions, either compiled - (:class:`re.RegexObject` instances) or uncompiled (strings). The optional second - argument is a timeout, in seconds; the default is to block indefinitely. + (:class:`re.RegexObject` instances) or uncompiled (byte strings). The + optional second argument is a timeout, in seconds; the default is to block + indefinitely. Return a tuple of three items: the index in the list of the first regular - expression that matches; the match object returned; and the text read up till - and including the match. + expression that matches; the match object returned; and the bytes read up + till and including the match. - If end of file is found and no text was read, raise :exc:`EOFError`. Otherwise, - when nothing matches, return ``(-1, None, text)`` where *text* is the text - received so far (may be the empty string if a timeout happened). + If end of file is found and no bytes were read, raise :exc:`EOFError`. + Otherwise, when nothing matches, return ``(-1, None, data)`` where *data* is + the bytes received so far (may be empty bytes if a timeout happened). If a regular expression ends with a greedy match (such as ``.*``) or if more - than one expression can match the same input, the results are indeterministic, - and may depend on the I/O timing. + than one expression can match the same input, the results are + indeterministic, and may depend on the I/O timing. .. method:: Telnet.set_option_negotiation_callback(callback) @@ -234,5 +235,5 @@ tn.write(b"ls\n") tn.write(b"exit\n") - print(tn.read_all()) + print(tn.read_all().decode('ascii')) From python-3000-checkins at python.org Thu Oct 16 21:34:47 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 16 Oct 2008 21:34:47 +0200 (CEST) Subject: [Python-3000-checkins] r66920 - in python/branches/py3k: Include/object.h Lib/test/test_class.py Lib/test/test_descr.py Lib/test/test_hash.py Lib/test/test_long.py Lib/test/test_richcmp.py Lib/test/test_set.py Objects/typeobject.c Message-ID: <20081016193447.768631E4002@bag.python.org> Author: benjamin.peterson Date: Thu Oct 16 21:34:46 2008 New Revision: 66920 Log: remove some more references to __cmp__ #1717 Modified: python/branches/py3k/Include/object.h python/branches/py3k/Lib/test/test_class.py python/branches/py3k/Lib/test/test_descr.py python/branches/py3k/Lib/test/test_hash.py python/branches/py3k/Lib/test/test_long.py python/branches/py3k/Lib/test/test_richcmp.py python/branches/py3k/Lib/test/test_set.py python/branches/py3k/Objects/typeobject.c Modified: python/branches/py3k/Include/object.h ============================================================================== --- python/branches/py3k/Include/object.h (original) +++ python/branches/py3k/Include/object.h Thu Oct 16 21:34:46 2008 @@ -447,9 +447,6 @@ PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *); -/* A slot function whose address we need to compare */ -extern int _PyObject_SlotCompare(PyObject *, PyObject *); - /* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a list of strings. PyObject_Dir(NULL) is like builtins.dir(), Modified: python/branches/py3k/Lib/test/test_class.py ============================================================================== --- python/branches/py3k/Lib/test/test_class.py (original) +++ python/branches/py3k/Lib/test/test_class.py Thu Oct 16 21:34:46 2008 @@ -92,10 +92,6 @@ return 1.0 @trackCall -def __cmp__(self, *args): - return 0 - - at trackCall def __eq__(self, *args): return True @@ -465,11 +461,6 @@ hash(C0()) # This should work; the next two should raise TypeError - class C1: - def __cmp__(self, other): return 0 - - self.assertRaises(TypeError, hash, C1()) - class C2: def __eq__(self, other): return 1 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 Thu Oct 16 21:34:46 2008 @@ -1566,7 +1566,7 @@ for i in range(10): self.assert_(i in d1) self.assertFalse(10 in d1) - # Test overridden behavior for static classes + # Test overridden behavior class Proxy(object): def __init__(self, x): self.x = x @@ -1578,8 +1578,14 @@ return self.x == other def __ne__(self, other): return self.x != other - def __cmp__(self, other): - return cmp(self.x, other.x) + def __ge__(self, other): + return self.x >= other + def __gt__(self, other): + return self.x > other + def __le__(self, other): + return self.x <= other + def __lt__(self, other): + return self.x < other def __str__(self): return "Proxy:%s" % self.x def __repr__(self): @@ -1596,9 +1602,10 @@ self.assertNotEqual(p0, p1) self.assert_(not p0 != p0) self.assertEqual(not p0, p1) - self.assertEqual(cmp(p0, p1), -1) - self.assertEqual(cmp(p0, p0), 0) - self.assertEqual(cmp(p0, p_1), 1) + self.assert_(p0 < p1) + self.assert_(p0 <= p1) + self.assert_(p1 > p0) + self.assert_(p1 >= p0) self.assertEqual(str(p0), "Proxy:0") self.assertEqual(repr(p0), "Proxy(0)") p10 = Proxy(range(10)) @@ -1606,46 +1613,6 @@ for i in range(10): self.assert_(i in p10) self.assertFalse(10 in p10) - # Test overridden behavior for dynamic classes - class DProxy(object): - def __init__(self, x): - self.x = x - def __bool__(self): - return not not self.x - def __hash__(self): - return hash(self.x) - def __eq__(self, other): - return self.x == other - def __ne__(self, other): - return self.x != other - def __cmp__(self, other): - return cmp(self.x, other.x) - def __str__(self): - return "DProxy:%s" % self.x - def __repr__(self): - return "DProxy(%r)" % self.x - def __contains__(self, value): - return value in self.x - p0 = DProxy(0) - p1 = DProxy(1) - p_1 = DProxy(-1) - self.assertFalse(p0) - self.assert_(not not p1) - self.assertEqual(hash(p0), hash(0)) - self.assertEqual(p0, p0) - self.assertNotEqual(p0, p1) - self.assertNotEqual(not p0, p0) - self.assertEqual(not p0, p1) - self.assertEqual(cmp(p0, p1), -1) - self.assertEqual(cmp(p0, p0), 0) - self.assertEqual(cmp(p0, p_1), 1) - self.assertEqual(str(p0), "DProxy:0") - self.assertEqual(repr(p0), "DProxy(0)") - p10 = DProxy(range(10)) - self.assertFalse(-1 in p10) - for i in range(10): - self.assert_(i in p10) - self.assertFalse(10 in p10) ## # Safety test for __cmp__ ## def unsafecmp(a, b): Modified: python/branches/py3k/Lib/test/test_hash.py ============================================================================== --- python/branches/py3k/Lib/test/test_hash.py (original) +++ python/branches/py3k/Lib/test/test_hash.py Thu Oct 16 21:34:46 2008 @@ -78,7 +78,6 @@ ] error_expected = [NoHash(), OnlyEquality(), - OnlyCmp(), ] def test_default_hash(self): Modified: python/branches/py3k/Lib/test/test_long.py ============================================================================== --- python/branches/py3k/Lib/test/test_long.py (original) +++ python/branches/py3k/Lib/test/test_long.py Thu Oct 16 21:34:46 2008 @@ -669,10 +669,22 @@ else: raise TypeError("can't deal with %r" % val) - def __cmp__(self, other): + def _cmp__(self, other): if not isinstance(other, Rat): other = Rat(other) return cmp(self.n * other.d, self.d * other.n) + def __eq__(self, other): + return self._cmp__(other) == 0 + def __ne__(self, other): + return self._cmp__(other) != 0 + def __ge__(self, other): + return self._cmp__(other) >= 0 + def __gt__(self, other): + return self._cmp__(other) > 0 + def __le__(self, other): + return self._cmp__(other) <= 0 + def __lt__(self, other): + return self._cmp__(other) < 0 cases = [0, 0.001, 0.99, 1.0, 1.5, 1e20, 1e200] # 2**48 is an important boundary in the internals. 2**53 is an Modified: python/branches/py3k/Lib/test/test_richcmp.py ============================================================================== --- python/branches/py3k/Lib/test/test_richcmp.py (original) +++ python/branches/py3k/Lib/test/test_richcmp.py Thu Oct 16 21:34:46 2008 @@ -198,13 +198,11 @@ def __le__(self, other): raise TestFailed("This shouldn't happen") def __ge__(self, other): raise TestFailed("This shouldn't happen") def __ne__(self, other): raise TestFailed("This shouldn't happen") - def __cmp__(self, other): raise RuntimeError("expected") a = Misb() b = Misb() self.assertEqual(ab, 0) - self.assertRaises(RuntimeError, cmp, a, b) def test_not(self): # Check that exceptions in __bool__ are properly 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 Thu Oct 16 21:34:46 2008 @@ -202,9 +202,6 @@ s = self.thetype(t) self.assertEqual(len(s), 3) - def test_compare(self): - self.assertRaises(TypeError, self.s.__cmp__, self.s) - def test_sub_and_super(self): p, q, r = map(self.thetype, ['ab', 'abcde', 'def']) self.assert_(p < q) Modified: python/branches/py3k/Objects/typeobject.c ============================================================================== --- python/branches/py3k/Objects/typeobject.c (original) +++ python/branches/py3k/Objects/typeobject.c Thu Oct 16 21:34:46 2008 @@ -3536,7 +3536,6 @@ static char *hash_name_op[] = { "__eq__", - "__cmp__", "__hash__", NULL }; @@ -4227,32 +4226,6 @@ return Py_None; } -static PyObject * -wrap_cmpfunc(PyObject *self, PyObject *args, void *wrapped) -{ - cmpfunc func = (cmpfunc)wrapped; - int res; - PyObject *other; - - if (!check_num_args(args, 1)) - return NULL; - other = PyTuple_GET_ITEM(args, 0); - if (Py_TYPE(other)->tp_compare != func && - !PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { - PyErr_Format( - PyExc_TypeError, - "%s.__cmp__(x,y) requires y to be a '%s', not a '%s'", - Py_TYPE(self)->tp_name, - Py_TYPE(self)->tp_name, - Py_TYPE(other)->tp_name); - return NULL; - } - res = (*func)(self, other); - if (PyErr_Occurred()) - return NULL; - return PyLong_FromLong((long)res); -} - /* Helper to check for object.__setattr__ or __delattr__ applied to a type. This is called the Carlo Verre hack after its discoverer. */ static int @@ -4878,62 +4851,6 @@ SLOT1(slot_nb_inplace_floor_divide, "__ifloordiv__", PyObject *, "O") SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *, "O") -static int -half_compare(PyObject *self, PyObject *other) -{ - PyObject *func, *args, *res; - static PyObject *cmp_str; - Py_ssize_t c; - - func = lookup_method(self, "__cmp__", &cmp_str); - if (func == NULL) { - PyErr_Clear(); - } - else { - args = PyTuple_Pack(1, other); - if (args == NULL) - res = NULL; - else { - res = PyObject_Call(func, args, NULL); - Py_DECREF(args); - } - Py_DECREF(func); - if (res != Py_NotImplemented) { - if (res == NULL) - return -2; - c = PyLong_AsLong(res); - Py_DECREF(res); - if (c == -1 && PyErr_Occurred()) - return -2; - return (c < 0) ? -1 : (c > 0) ? 1 : 0; - } - Py_DECREF(res); - } - return 2; -} - -/* This slot is published for the benefit of try_3way_compare in object.c */ -int -_PyObject_SlotCompare(PyObject *self, PyObject *other) -{ - int c; - - if (Py_TYPE(self)->tp_compare == _PyObject_SlotCompare) { - c = half_compare(self, other); - if (c <= 1) - return c; - } - if (Py_TYPE(other)->tp_compare == _PyObject_SlotCompare) { - c = half_compare(other, self); - if (c < -1) - return -2; - if (c <= 1) - return -c; - } - return (void *)self < (void *)other ? -1 : - (void *)self > (void *)other ? 1 : 0; -} - static PyObject * slot_tp_repr(PyObject *self) { @@ -5532,8 +5449,6 @@ "x.__str__() <==> str(x)"), TPSLOT("__repr__", tp_repr, slot_tp_repr, wrap_unaryfunc, "x.__repr__() <==> repr(x)"), - TPSLOT("__cmp__", tp_compare, _PyObject_SlotCompare, wrap_cmpfunc, - "x.__cmp__(y) <==> cmp(x,y)"), TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc, "x.__hash__() <==> hash(x)"), FLSLOT("__call__", tp_call, slot_tp_call, (wrapperfunc)wrap_call, From python-3000-checkins at python.org Thu Oct 16 23:17:25 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 16 Oct 2008 23:17:25 +0200 (CEST) Subject: [Python-3000-checkins] r66934 - in python/branches/py3k: Lib/json/decoder.py Lib/json/tests/test_scanstring.py Modules/_json.c Message-ID: <20081016211725.48D091E4002@bag.python.org> Author: benjamin.peterson Date: Thu Oct 16 23:17:24 2008 New Revision: 66934 Log: merge r66932 and add a few py3k only checks Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/json/decoder.py python/branches/py3k/Lib/json/tests/test_scanstring.py python/branches/py3k/Modules/_json.c Modified: python/branches/py3k/Lib/json/decoder.py ============================================================================== --- python/branches/py3k/Lib/json/decoder.py (original) +++ python/branches/py3k/Lib/json/decoder.py Thu Oct 16 23:17:24 2008 @@ -18,11 +18,15 @@ def linecol(doc, pos): - lineno = doc.count('\n', 0, pos) + 1 + if isinstance(doc, bytes): + newline = b'\n' + else: + newline = '\n' + lineno = doc.count(newline, 0, pos) + 1 if lineno == 1: colno = pos else: - colno = pos - doc.rindex('\n', 0, pos) + colno = pos - doc.rindex(newline, 0, pos) return lineno, colno Modified: python/branches/py3k/Lib/json/tests/test_scanstring.py ============================================================================== --- python/branches/py3k/Lib/json/tests/test_scanstring.py (original) +++ python/branches/py3k/Lib/json/tests/test_scanstring.py Thu Oct 16 23:17:24 2008 @@ -2,6 +2,7 @@ import decimal from unittest import TestCase +import json import json.decoder class TestScanString(TestCase): @@ -101,3 +102,9 @@ self.assertEquals( scanstring('["Bad value", truth]', 2, None, True), ('Bad value', 12)) + + def test_issue3623(self): + self.assertRaises(ValueError, json.decoder.scanstring, b"xxx", 1, + "xxx") + self.assertRaises(UnicodeDecodeError, + json.encoder.encode_basestring_ascii, b"xx\xff") Modified: python/branches/py3k/Modules/_json.c ============================================================================== --- python/branches/py3k/Modules/_json.c (original) +++ python/branches/py3k/Modules/_json.c Thu Oct 16 23:17:24 2008 @@ -179,11 +179,13 @@ errmsg_fn = PyObject_GetAttrString(decoder, "errmsg"); if (errmsg_fn == NULL) return; - Py_XDECREF(decoder); + Py_DECREF(decoder); } pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end); - PyErr_SetObject(PyExc_ValueError, pymsg); - Py_DECREF(pymsg); + if (pymsg) { + PyErr_SetObject(PyExc_ValueError, pymsg); + Py_DECREF(pymsg); + } /* def linecol(doc, pos): @@ -602,7 +604,7 @@ Py_TYPE(pystr)->tp_name); return NULL; } - if (PyBytes_Check(rval)) { + if (rval != NULL && PyBytes_Check(rval)) { PyObject *urval = PyUnicode_DecodeASCII(PyBytes_AS_STRING(rval), PyBytes_GET_SIZE(rval), NULL); Py_DECREF(rval); return urval; From python-3000-checkins at python.org Thu Oct 16 23:56:24 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Thu, 16 Oct 2008 23:56:24 +0200 (CEST) Subject: [Python-3000-checkins] r66943 - in python/branches/py3k: Modules/_json.c Message-ID: <20081016215624.792D51E4002@bag.python.org> Author: benjamin.peterson Date: Thu Oct 16 23:56:24 2008 New Revision: 66943 Log: Merged revisions 66938,66942 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66938 | benjamin.peterson | 2008-10-16 16:27:54 -0500 (Thu, 16 Oct 2008) | 1 line fix possible ref leak ........ r66942 | benjamin.peterson | 2008-10-16 16:48:06 -0500 (Thu, 16 Oct 2008) | 1 line fix more possible ref leaks in _json and use Py_CLEAR ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Modules/_json.c Modified: python/branches/py3k/Modules/_json.c ============================================================================== --- python/branches/py3k/Modules/_json.c (original) +++ python/branches/py3k/Modules/_json.c Thu Oct 16 23:56:24 2008 @@ -276,6 +276,7 @@ goto bail; } if (PyList_Append(chunks, chunk)) { + Py_DECREF(chunk); goto bail; } Py_DECREF(chunk); @@ -377,6 +378,7 @@ goto bail; } if (PyList_Append(chunks, chunk)) { + Py_DECREF(chunk); goto bail; } Py_DECREF(chunk); @@ -386,8 +388,7 @@ if (rval == NULL) { goto bail; } - Py_DECREF(chunks); - chunks = NULL; + Py_CLEAR(chunks); return Py_BuildValue("(Nn)", rval, end); bail: Py_XDECREF(chunks); @@ -436,6 +437,7 @@ goto bail; } if (PyList_Append(chunks, chunk)) { + Py_DECREF(chunk); goto bail; } Py_DECREF(chunk); @@ -537,6 +539,7 @@ goto bail; } if (PyList_Append(chunks, chunk)) { + Py_DECREF(chunk); goto bail; } Py_DECREF(chunk); @@ -546,8 +549,7 @@ if (rval == NULL) { goto bail; } - Py_DECREF(chunks); - chunks = NULL; + Py_CLEAR(chunks); return Py_BuildValue("(Nn)", rval, end); bail: Py_XDECREF(chunks); From python-3000-checkins at python.org Fri Oct 17 00:49:09 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 17 Oct 2008 00:49:09 +0200 (CEST) Subject: [Python-3000-checkins] r66944 - python/branches/py3k Message-ID: <20081016224909.0708B1E4002@bag.python.org> Author: benjamin.peterson Date: Fri Oct 17 00:49:08 2008 New Revision: 66944 Log: Unblocked revisions 66386 via svnmerge ........ r66386 | nick.coghlan | 2008-09-11 07:11:06 -0500 (Thu, 11 Sep 2008) | 1 line Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon) ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Fri Oct 17 01:24:45 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 17 Oct 2008 01:24:45 +0200 (CEST) Subject: [Python-3000-checkins] r66945 - in python/branches/py3k: Doc/library/test.rst Doc/library/warnings.rst Lib/test/support.py Lib/test/test_import.py Lib/test/test_structmembers.py Lib/test/test_sundry.py Lib/test/test_threading.py Lib/test/test_warnings.py Lib/warnings.py Message-ID: <20081016232445.5D73B1E4002@bag.python.org> Author: benjamin.peterson Date: Fri Oct 17 01:24:44 2008 New Revision: 66945 Log: forward port r66386 Modified: python/branches/py3k/Doc/library/test.rst python/branches/py3k/Doc/library/warnings.rst python/branches/py3k/Lib/test/support.py python/branches/py3k/Lib/test/test_import.py python/branches/py3k/Lib/test/test_structmembers.py python/branches/py3k/Lib/test/test_sundry.py python/branches/py3k/Lib/test/test_threading.py python/branches/py3k/Lib/test/test_warnings.py python/branches/py3k/Lib/warnings.py Modified: python/branches/py3k/Doc/library/test.rst ============================================================================== --- python/branches/py3k/Doc/library/test.rst (original) +++ python/branches/py3k/Doc/library/test.rst Fri Oct 17 01:24:44 2008 @@ -278,18 +278,26 @@ This will run all tests defined in the named module. -.. function:: catch_warning(module=warnings, record=True) +.. function:: check_warnings() - Return a context manager that guards the warnings filter from being - permanently changed and optionally alters the :func:`showwarning` - function to record the details of any warnings that are issued in the - managed context. Attributes of the most recent warning are saved - directly on the context manager, while details of previous warnings - can be retrieved from the ``warnings`` list. + A convenience wrapper for ``warnings.catch_warnings()`` that makes + it easier to test that a warning was correctly raised with a single + assertion. It is approximately equivalent to calling + ``warnings.catch_warnings(record=True)``. + + The main difference is that on entry to the context manager, a + :class:`WarningRecorder` instance is returned instead of a simple list. + The underlying warnings list is available via the recorder object's + :attr:`warnings` attribute, while the attributes of the last raised + warning are also accessible directly on the object. If no warning has + been raised, then the latter attributes will all be :const:`None`. + + A :meth:`reset` method is also provided on the recorder object. This + method simply clears the warning list. The context manager is used like this:: - with catch_warning() as w: + with check_warnings() as w: warnings.simplefilter("always") warnings.warn("foo") assert str(w.message) == "foo" @@ -297,15 +305,9 @@ assert str(w.message) == "bar" assert str(w.warnings[0].message) == "foo" assert str(w.warnings[1].message) == "bar" + w.reset() + assert len(w.warnings) == 0 - By default, the real :mod:`warnings` module is affected - the ability - to select a different module is provided for the benefit of the - :mod:`warnings` module's own unit tests. - The ``record`` argument specifies whether or not the :func:`showwarning` - function is replaced. Note that recording the warnings in this fashion - also prevents them from being written to sys.stderr. If set to ``False``, - the standard handling of warning messages is left in place (however, the - original handling is still restored at the end of the block). .. function:: captured_stdout() @@ -346,4 +348,10 @@ Temporarily unset the environment variable ``envvar``. +.. class:: WarningsRecorder() + + Class used to record warnings for unit tests. See documentation of + :func:`check_warnings` above for more details. + + .. versionadded:: 2.6 Modified: python/branches/py3k/Doc/library/warnings.rst ============================================================================== --- python/branches/py3k/Doc/library/warnings.rst (original) +++ python/branches/py3k/Doc/library/warnings.rst Fri Oct 17 01:24:44 2008 @@ -165,9 +165,9 @@ Temporarily Suppressing Warnings -------------------------------- -If you are using code that you know will raise a warning, such some deprecated -function, but do not want to see the warning, then suppress the warning using -the :class:`catch_warnings` context manager:: +If you are using code that you know will raise a warning, such as a deprecated +function, but do not want to see the warning, then it is possible to suppress +the warning using the :class:`catch_warnings` context manager:: import warnings @@ -218,7 +218,15 @@ Once the context manager exits, the warnings filter is restored to its state when the context was entered. This prevents tests from changing the warnings filter in unexpected ways between tests and leading to indeterminate test -results. +results. The :func:`showwarning` function in the module is also restored to +its original value. + +When testing multiple operations that raise the same kind of warning, it +is important to test them in a manner that confirms each operation is raising +a new warning (e.g. set warnings to be raised as exceptions and check the +operations raise exceptions, check that the length of the warning list +continues to increase after each operation, or else delete the previous +entries from the warnings list before each new operation). .. _warning-functions: @@ -314,20 +322,20 @@ .. class:: catch_warnings([\*, record=False, module=None]) - A context manager that copies and, upon exit, restores the warnings filter. - If the *record* argument is False (the default) the context manager returns - :class:`None`. If *record* is true, a list is returned that is populated - with objects as seen by a custom :func:`showwarning` function (which also - suppresses output to ``sys.stdout``). Each object has attributes with the - same names as the arguments to :func:`showwarning`. + A context manager that copies and, upon exit, restores the warnings filter + and the :func:`showwarning` function. + If the *record* argument is :const:`False` (the default) the context manager + returns :class:`None` on entry. If *record* is :const:`True`, a list is + returned that is progressively populated with objects as seen by a custom + :func:`showwarning` function (which also suppresses output to ``sys.stdout``). + Each object in the list has attributes with the same names as the arguments to + :func:`showwarning`. The *module* argument takes a module that will be used instead of the module returned when you import :mod:`warnings` whose filter will be - protected. This arguments exists primarily for testing the :mod:`warnings` + protected. This argument exists primarily for testing the :mod:`warnings` module itself. - .. versionadded:: 2.6 - .. versionchanged:: 3.0 Constructor arguments turned into keyword-only arguments. Modified: python/branches/py3k/Lib/test/support.py ============================================================================== --- python/branches/py3k/Lib/test/support.py (original) +++ python/branches/py3k/Lib/test/support.py Fri Oct 17 01:24:44 2008 @@ -19,7 +19,7 @@ "is_resource_enabled", "requires", "find_unused_port", "bind_port", "fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "findfile", "verify", "vereq", "sortdict", "check_syntax_error", "open_urlresource", - "catch_warning", "CleanImport", "EnvironmentVarGuard", + "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource", "captured_output", "captured_stdout", "TransientResource", "transient_internet", "run_with_locale", "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", @@ -53,7 +53,7 @@ def import_module(name, deprecated=False): """Import the module to be tested, raising TestSkipped if it is not available.""" - with catch_warning(record=False): + with warnings.catch_warnings(): if deprecated: warnings.filterwarnings("ignore", ".+ (module|package)", DeprecationWarning) @@ -368,17 +368,27 @@ return open(fn, *args, **kw) -def catch_warning(module=warnings, record=True): - """Guard the warnings filter from being permanently changed and - optionally record the details of any warnings that are issued. +class WarningsRecorder(object): + """Convenience wrapper for the warnings list returned on + entry to the warnings.catch_warnings() context manager. + """ + def __init__(self, warnings_list): + self.warnings = warnings_list + + def __getattr__(self, attr): + if self.warnings: + return getattr(self.warnings[-1], attr) + elif attr in warnings.WarningMessage._WARNING_DETAILS: + return None + raise AttributeError("%r has no attribute %r" % (self, attr)) - Use like this: + def reset(self): + del self.warnings[:] - with catch_warning() as w: - warnings.warn("foo") - assert str(w.message) == "foo" - """ - return warnings.catch_warnings(record=record, module=module) + at contextlib.contextmanager +def check_warnings(): + with warnings.catch_warnings(record=True) as w: + yield WarningsRecorder(w) class CleanImport(object): Modified: python/branches/py3k/Lib/test/test_import.py ============================================================================== --- python/branches/py3k/Lib/test/test_import.py (original) +++ python/branches/py3k/Lib/test/test_import.py Fri Oct 17 01:24:44 2008 @@ -266,21 +266,24 @@ self.assertTrue(hasattr(relimport, "RelativeImport")) def test_issue3221(self): + # Note for mergers: the 'absolute' tests from the 2.x branch + # are missing in Py3k because implicit relative imports are + # a thing of the past def check_relative(): exec("from . import relimport", ns) - # Check both OK with __package__ and __name__ correct + # Check relative import OK with __package__ and __name__ correct ns = dict(__package__='test', __name__='test.notarealmodule') check_relative() - # Check both OK with only __name__ wrong + # Check relative import OK with only __name__ wrong ns = dict(__package__='test', __name__='notarealpkg.notarealmodule') check_relative() - # Check relative fails with only __package__ wrong + # Check relative import fails with only __package__ wrong ns = dict(__package__='foo', __name__='test.notarealmodule') self.assertRaises(SystemError, check_relative) - # Check relative fails with __package__ and __name__ wrong + # Check relative import fails with __package__ and __name__ wrong ns = dict(__package__='foo', __name__='notarealpkg.notarealmodule') self.assertRaises(SystemError, check_relative) - # Check both fail with package set to a non-string + # Check relative import fails with package set to a non-string ns = dict(__package__=object()) self.assertRaises(ValueError, check_relative) Modified: python/branches/py3k/Lib/test/test_structmembers.py ============================================================================== --- python/branches/py3k/Lib/test/test_structmembers.py (original) +++ python/branches/py3k/Lib/test/test_structmembers.py Fri Oct 17 01:24:44 2008 @@ -66,35 +66,35 @@ class TestWarnings(unittest.TestCase): def has_warned(self, w): - self.assertEqual(w[-1].category, RuntimeWarning) + self.assertEqual(w.category, RuntimeWarning) def test_byte_max(self): - with warnings.catch_warnings(record=True) as w: + with support.check_warnings() as w: ts.T_BYTE = CHAR_MAX+1 self.has_warned(w) def test_byte_min(self): - with warnings.catch_warnings(record=True) as w: + with support.check_warnings() as w: ts.T_BYTE = CHAR_MIN-1 self.has_warned(w) def test_ubyte_max(self): - with warnings.catch_warnings(record=True) as w: + with support.check_warnings() as w: ts.T_UBYTE = UCHAR_MAX+1 self.has_warned(w) def test_short_max(self): - with warnings.catch_warnings(record=True) as w: + with support.check_warnings() as w: ts.T_SHORT = SHRT_MAX+1 self.has_warned(w) def test_short_min(self): - with warnings.catch_warnings(record=True) as w: + with support.check_warnings() as w: ts.T_SHORT = SHRT_MIN-1 self.has_warned(w) def test_ushort_max(self): - with warnings.catch_warnings(record=True) as w: + with support.check_warnings() as w: ts.T_USHORT = USHRT_MAX+1 self.has_warned(w) Modified: python/branches/py3k/Lib/test/test_sundry.py ============================================================================== --- python/branches/py3k/Lib/test/test_sundry.py (original) +++ python/branches/py3k/Lib/test/test_sundry.py Fri Oct 17 01:24:44 2008 @@ -7,7 +7,7 @@ class TestUntestedModules(unittest.TestCase): def test_at_least_import_untested_modules(self): - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): import aifc import bdb import cgitb Modified: python/branches/py3k/Lib/test/test_threading.py ============================================================================== --- python/branches/py3k/Lib/test/test_threading.py (original) +++ python/branches/py3k/Lib/test/test_threading.py Fri Oct 17 01:24:44 2008 @@ -1,7 +1,7 @@ # Very rudimentary test of threading module import test.support -from test.support import verbose, catch_warning +from test.support import verbose import random import re import sys Modified: python/branches/py3k/Lib/test/test_warnings.py ============================================================================== --- python/branches/py3k/Lib/test/test_warnings.py (original) +++ python/branches/py3k/Lib/test/test_warnings.py Fri Oct 17 01:24:44 2008 @@ -214,7 +214,8 @@ def test_warn_nonstandard_types(self): # warn() should handle non-standard types without issue. for ob in (Warning, None, 42): - with support.catch_warning(self.module) as w: + with original_warnings.catch_warnings(record=True, + module=self.module) as w: self.module.warn(ob) # Don't directly compare objects since # ``Warning() != Warning()``. @@ -526,19 +527,23 @@ wmod = self.module orig_filters = wmod.filters orig_showwarning = wmod.showwarning - with support.catch_warning(module=wmod): + # Ensure both showwarning and filters are restored when recording + with wmod.catch_warnings(module=wmod, record=True): wmod.filters = wmod.showwarning = object() self.assert_(wmod.filters is orig_filters) self.assert_(wmod.showwarning is orig_showwarning) - with support.catch_warning(module=wmod, record=False): + # Same test, but with recording disabled + with wmod.catch_warnings(module=wmod, record=False): wmod.filters = wmod.showwarning = object() self.assert_(wmod.filters is orig_filters) self.assert_(wmod.showwarning is orig_showwarning) def test_catch_warnings_recording(self): wmod = self.module - with support.catch_warning(module=wmod) as w: + # Ensure warnings are recorded when requested + with wmod.catch_warnings(module=wmod, record=True) as w: self.assertEqual(w, []) + self.assert_(type(w) is list) wmod.simplefilter("always") wmod.warn("foo") self.assertEqual(str(w[-1].message), "foo") @@ -548,11 +553,59 @@ self.assertEqual(str(w[1].message), "bar") del w[:] self.assertEqual(w, []) + # Ensure warnings are not recorded when not requested orig_showwarning = wmod.showwarning - with support.catch_warning(module=wmod, record=False) as w: + with wmod.catch_warnings(module=wmod, record=False) as w: self.assert_(w is None) self.assert_(wmod.showwarning is orig_showwarning) + def test_catch_warnings_reentry_guard(self): + wmod = self.module + # Ensure catch_warnings is protected against incorrect usage + x = wmod.catch_warnings(module=wmod, record=True) + self.assertRaises(RuntimeError, x.__exit__) + with x: + self.assertRaises(RuntimeError, x.__enter__) + # Same test, but with recording disabled + x = wmod.catch_warnings(module=wmod, record=False) + self.assertRaises(RuntimeError, x.__exit__) + with x: + self.assertRaises(RuntimeError, x.__enter__) + + def test_catch_warnings_defaults(self): + wmod = self.module + orig_filters = wmod.filters + orig_showwarning = wmod.showwarning + # Ensure default behaviour is not to record warnings + with wmod.catch_warnings(module=wmod) as w: + self.assert_(w is None) + self.assert_(wmod.showwarning is orig_showwarning) + self.assert_(wmod.filters is not orig_filters) + self.assert_(wmod.filters is orig_filters) + if wmod is sys.modules['warnings']: + # Ensure the default module is this one + with wmod.catch_warnings() as w: + self.assert_(w is None) + self.assert_(wmod.showwarning is orig_showwarning) + self.assert_(wmod.filters is not orig_filters) + self.assert_(wmod.filters is orig_filters) + + def test_check_warnings(self): + # Explicit tests for the test.support convenience wrapper + wmod = self.module + if wmod is sys.modules['warnings']: + with support.check_warnings() as w: + self.assertEqual(w.warnings, []) + wmod.simplefilter("always") + wmod.warn("foo") + self.assertEqual(str(w.message), "foo") + wmod.warn("bar") + self.assertEqual(str(w.message), "bar") + self.assertEqual(str(w.warnings[0].message), "foo") + self.assertEqual(str(w.warnings[1].message), "bar") + w.reset() + self.assertEqual(w.warnings, []) + class CCatchWarningTests(CatchWarningTests): module = c_warnings Modified: python/branches/py3k/Lib/warnings.py ============================================================================== --- python/branches/py3k/Lib/warnings.py (original) +++ python/branches/py3k/Lib/warnings.py Fri Oct 17 01:24:44 2008 @@ -301,8 +301,21 @@ """ self._record = record self._module = sys.modules['warnings'] if module is None else module + self._entered = False + + def __repr__(self): + args = [] + if self._record: + args.append("record=True") + if self._module is not sys.modules['warnings']: + args.append("module=%r" % self._module) + name = type(self).__name__ + return "%s(%s)" % (name, ", ".join(args)) def __enter__(self): + if self._entered: + raise RuntimeError("Cannot enter %r twice" % self) + self._entered = True self._filters = self._module.filters self._module.filters = self._filters[:] self._showwarning = self._module.showwarning @@ -316,6 +329,8 @@ return None def __exit__(self, *exc_info): + if not self._entered: + raise RuntimeError("Cannot exit %r without entering first" % self) self._module.filters = self._filters self._module.showwarning = self._showwarning From python-3000-checkins at python.org Fri Oct 17 01:52:53 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 17 Oct 2008 01:52:53 +0200 (CEST) Subject: [Python-3000-checkins] r66946 - python/branches/py3k Message-ID: <20081016235253.5EC751E4002@bag.python.org> Author: benjamin.peterson Date: Fri Oct 17 01:52:53 2008 New Revision: 66946 Log: Blocked revisions 66386 via svnmerge ........ r66386 | nick.coghlan | 2008-09-11 07:11:06 -0500 (Thu, 11 Sep 2008) | 1 line Issue #3781: Final cleanup of warnings.catch_warnings and its usage in the test suite. Closes issue w.r.t. 2.6 (R: Brett Cannon) ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Fri Oct 17 01:56:29 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 17 Oct 2008 01:56:29 +0200 (CEST) Subject: [Python-3000-checkins] r66947 - in python/branches/py3k: Lib/test/test_capi.py Modules/_testcapimodule.c Message-ID: <20081016235629.D90151E4002@bag.python.org> Author: benjamin.peterson Date: Fri Oct 17 01:56:29 2008 New Revision: 66947 Log: add tests for PyInstanceMethod_Type Modified: python/branches/py3k/Lib/test/test_capi.py python/branches/py3k/Modules/_testcapimodule.c Modified: python/branches/py3k/Lib/test/test_capi.py ============================================================================== --- python/branches/py3k/Lib/test/test_capi.py (original) +++ python/branches/py3k/Lib/test/test_capi.py Fri Oct 17 01:56:29 2008 @@ -2,10 +2,34 @@ # these are all functions _testcapi exports whose name begins with 'test_'. import sys +import unittest from test import support import _testcapi +def testfunction(self): + """some doc""" + return self + +class InstanceMethod: + id = _testcapi.instancemethod(id) + testfunction = _testcapi.instancemethod(testfunction) + +class CAPITest(unittest.TestCase): + + def test_instancemethod(self): + inst = InstanceMethod() + self.assertEqual(id(inst), inst.id()) + self.assert_(inst.testfunction() is inst) + self.assertEqual(inst.testfunction.__doc__, testfunction.__doc__) + self.assertEqual(InstanceMethod.testfunction.__doc__, testfunction.__doc__) + + InstanceMethod.testfunction.attribute = "test" + self.assertEqual(testfunction.attribute, "test") + self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test") + + def test_main(): + support.run_unittest(CAPITest) for name in dir(_testcapi): if name.startswith('test_'): @@ -47,5 +71,6 @@ t.start() t.join() + if __name__ == "__main__": test_main() Modified: python/branches/py3k/Modules/_testcapimodule.c ============================================================================== --- python/branches/py3k/Modules/_testcapimodule.c (original) +++ python/branches/py3k/Modules/_testcapimodule.c Fri Oct 17 01:56:29 2008 @@ -1231,6 +1231,8 @@ PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyLong_FromSsize_t(PY_SSIZE_T_MAX)); PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyLong_FromSsize_t(PY_SSIZE_T_MIN)); PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyLong_FromSsize_t(sizeof(PyGC_Head))); + Py_INCREF(&PyInstanceMethod_Type); + PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type); TestError = PyErr_NewException("_testcapi.error", NULL, NULL); Py_INCREF(TestError); From python-3000-checkins at python.org Fri Oct 17 03:15:29 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 17 Oct 2008 03:15:29 +0200 (CEST) Subject: [Python-3000-checkins] r66948 - python/branches/py3k/Python/sysmodule.c Message-ID: <20081017011529.987EB1E4002@bag.python.org> Author: barry.warsaw Date: Fri Oct 17 03:15:29 2008 New Revision: 66948 Log: Apply Martin's patch for bug 3685, Crash while compiling Python 3000 in OpenBSD 4.4. Modified: python/branches/py3k/Python/sysmodule.c Modified: python/branches/py3k/Python/sysmodule.c ============================================================================== --- python/branches/py3k/Python/sysmodule.c (original) +++ python/branches/py3k/Python/sysmodule.c Fri Oct 17 03:15:29 2008 @@ -1387,7 +1387,7 @@ for (i = 0; ; i++) { p = wcschr(path, delim); if (p == NULL) - p = wcschr(path, L'\0'); /* End of string */ + p = path + wcslen(path); /* End of string */ w = PyUnicode_FromWideChar(path, (Py_ssize_t)(p - path)); if (w == NULL) { Py_DECREF(v); From python-3000-checkins at python.org Fri Oct 17 03:29:56 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 17 Oct 2008 03:29:56 +0200 (CEST) Subject: [Python-3000-checkins] r66949 - in python/branches/py3k: Lib/test/test_sys.py Python/sysmodule.c Message-ID: <20081017012956.76D9A1E4002@bag.python.org> Author: barry.warsaw Date: Fri Oct 17 03:29:56 2008 New Revision: 66949 Log: Benjamin Peterson's patch to fix bug 3661, sys.call_tracing segfaults. Modified: python/branches/py3k/Lib/test/test_sys.py python/branches/py3k/Python/sysmodule.c Modified: python/branches/py3k/Lib/test/test_sys.py ============================================================================== --- python/branches/py3k/Lib/test/test_sys.py (original) +++ python/branches/py3k/Lib/test/test_sys.py Fri Oct 17 03:29:56 2008 @@ -166,6 +166,9 @@ self.assert_(isinstance(v[3], int)) self.assert_(isinstance(v[4], str)) + def test_call_tracing(self): + self.assertRaises(TypeError, sys.call_tracing, type, 2) + def test_dlopenflags(self): if hasattr(sys, "setdlopenflags"): self.assert_(hasattr(sys, "getdlopenflags")) Modified: python/branches/py3k/Python/sysmodule.c ============================================================================== --- python/branches/py3k/Python/sysmodule.c (original) +++ python/branches/py3k/Python/sysmodule.c Fri Oct 17 03:29:56 2008 @@ -783,7 +783,7 @@ sys_call_tracing(PyObject *self, PyObject *args) { PyObject *func, *funcargs; - if (!PyArg_UnpackTuple(args, "call_tracing", 2, 2, &func, &funcargs)) + if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs)) return NULL; return _PyEval_CallTracing(func, funcargs); } From python-3000-checkins at python.org Fri Oct 17 03:50:38 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 17 Oct 2008 03:50:38 +0200 (CEST) Subject: [Python-3000-checkins] r66950 - in python/branches/py3k: Lib/test/test_bytes.py Objects/bytearrayobject.c Objects/bytesobject.c Message-ID: <20081017015038.5C0D51E4002@bag.python.org> Author: barry.warsaw Date: Fri Oct 17 03:50:37 2008 New Revision: 66950 Log: STINNER Victor (haypo)'s patch for bug 3988, Byte warning mode and b'' != '' Also, his patch to runtests.sh to pass the -bb option (issue 4125). Modified: python/branches/py3k/Lib/test/test_bytes.py python/branches/py3k/Objects/bytearrayobject.c python/branches/py3k/Objects/bytesobject.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 Fri Oct 17 03:50:37 2008 @@ -9,6 +9,7 @@ import re import sys import copy +import operator import pickle import tempfile import unittest @@ -863,6 +864,17 @@ b = bytearray() self.failIf(b.replace(b'', b'') is b) + def test_compare(self): + if sys.flags.bytes_warning: + warnings.simplefilter('error', BytesWarning) + self.assertRaises(BytesWarning, operator.eq, b'', '') + self.assertRaises(BytesWarning, operator.ne, b'', '') + self.assertRaises(BytesWarning, operator.eq, bytearray(b''), '') + self.assertRaises(BytesWarning, operator.ne, bytearray(b''), '') + else: + # raise test.support.TestSkipped("BytesWarning is needed for this test: use -bb option") + pass + # Optimizations: # __iter__? (optimization) # __reversed__? (optimization) Modified: python/branches/py3k/Objects/bytearrayobject.c ============================================================================== --- python/branches/py3k/Objects/bytearrayobject.c (original) +++ python/branches/py3k/Objects/bytearrayobject.c Fri Oct 17 03:50:37 2008 @@ -939,7 +939,7 @@ error, even if the comparison is for equality. */ if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) || PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) { - if (Py_BytesWarningFlag && op == Py_EQ) { + if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) { if (PyErr_WarnEx(PyExc_BytesWarning, "Comparison between bytearray and string", 1)) return NULL; Modified: python/branches/py3k/Objects/bytesobject.c ============================================================================== --- python/branches/py3k/Objects/bytesobject.c (original) +++ python/branches/py3k/Objects/bytesobject.c Fri Oct 17 03:50:37 2008 @@ -818,7 +818,7 @@ /* Make sure both arguments are strings. */ if (!(PyBytes_Check(a) && PyBytes_Check(b))) { - if (Py_BytesWarningFlag && (op == Py_EQ) && + if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE) && (PyObject_IsInstance((PyObject*)a, (PyObject*)&PyUnicode_Type) || PyObject_IsInstance((PyObject*)b, From python-3000-checkins at python.org Fri Oct 17 05:38:51 2008 From: python-3000-checkins at python.org (brett.cannon) Date: Fri, 17 Oct 2008 05:38:51 +0200 (CEST) Subject: [Python-3000-checkins] r66951 - in python/branches/py3k: Lib/test/test_pep3120.py Misc/NEWS Parser/tokenizer.c Parser/tokenizer.h Python/ast.c Message-ID: <20081017033851.006AC1E400C@bag.python.org> Author: brett.cannon Date: Fri Oct 17 05:38:50 2008 New Revision: 66951 Log: Latin-1 source code was not being properly decoded when passed through compile(). This was due to left-over special-casing before UTF-8 became the default source encoding. Closes issue #3574. Thanks to Victor Stinner for help with the patch. Modified: python/branches/py3k/Lib/test/test_pep3120.py python/branches/py3k/Misc/NEWS python/branches/py3k/Parser/tokenizer.c python/branches/py3k/Parser/tokenizer.h python/branches/py3k/Python/ast.c Modified: python/branches/py3k/Lib/test/test_pep3120.py ============================================================================== Binary files. No diff available. Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Oct 17 05:38:50 2008 @@ -15,6 +15,8 @@ Core and Builtins ----------------- +- Issue #3574: compile() incorrectly handled source code encoded as Latin-1. + - Issues #2384 and #3975: Tracebacks were not correctly printed when the source file contains a ``coding:`` header: the wrong line was displayed, and the encoding was not respected. Modified: python/branches/py3k/Parser/tokenizer.c ============================================================================== --- python/branches/py3k/Parser/tokenizer.c (original) +++ python/branches/py3k/Parser/tokenizer.c Fri Oct 17 05:38:50 2008 @@ -135,6 +135,7 @@ tok->decoding_state = STATE_INIT; tok->decoding_erred = 0; tok->read_coding_spec = 0; + tok->enc = NULL; tok->encoding = NULL; tok->cont_line = 0; #ifndef PGEN @@ -274,8 +275,7 @@ tok->read_coding_spec = 1; if (tok->encoding == NULL) { assert(tok->decoding_state == STATE_RAW); - if (strcmp(cs, "utf-8") == 0 || - strcmp(cs, "iso-8859-1") == 0) { + if (strcmp(cs, "utf-8") == 0) { tok->encoding = cs; } else { r = set_readline(tok, cs); Modified: python/branches/py3k/Parser/tokenizer.h ============================================================================== --- python/branches/py3k/Parser/tokenizer.h (original) +++ python/branches/py3k/Parser/tokenizer.h Fri Oct 17 05:38:50 2008 @@ -49,14 +49,14 @@ enum decoding_state decoding_state; int decoding_erred; /* whether erred in decoding */ int read_coding_spec; /* whether 'coding:...' has been read */ - char *encoding; + char *encoding; /* Source encoding. */ int cont_line; /* whether we are in a continuation line. */ const char* line_start; /* pointer to start of current line */ #ifndef PGEN PyObject *decoding_readline; /* codecs.open(...).readline */ PyObject *decoding_buffer; #endif - const char* enc; + const char* enc; /* Encoding for the current str. */ const char* str; }; Modified: python/branches/py3k/Python/ast.c ============================================================================== --- python/branches/py3k/Python/ast.c (original) +++ python/branches/py3k/Python/ast.c Fri Oct 17 05:38:50 2008 @@ -3160,9 +3160,6 @@ if (encoding == NULL) { buf = (char *)s; u = NULL; - } else if (strcmp(encoding, "iso-8859-1") == 0) { - buf = (char *)s; - u = NULL; } else { /* check for integer overflow */ if (len > PY_SIZE_MAX / 4) @@ -3275,8 +3272,7 @@ } } need_encoding = (!*bytesmode && c->c_encoding != NULL && - strcmp(c->c_encoding, "utf-8") != 0 && - strcmp(c->c_encoding, "iso-8859-1") != 0); + strcmp(c->c_encoding, "utf-8") != 0); if (rawmode || strchr(s, '\\') == NULL) { if (need_encoding) { PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL); From python-3000-checkins at python.org Fri Oct 17 14:05:41 2008 From: python-3000-checkins at python.org (barry.warsaw) Date: Fri, 17 Oct 2008 14:05:41 +0200 (CEST) Subject: [Python-3000-checkins] r66957 - python/branches/py3k/runtests.sh Message-ID: <20081017120541.0D2141E4044@bag.python.org> Author: barry.warsaw Date: Fri Oct 17 14:05:40 2008 New Revision: 66957 Log: Really commit the patch for bug 4125; runtests.sh use -bb flag Modified: python/branches/py3k/runtests.sh Modified: python/branches/py3k/runtests.sh ============================================================================== --- python/branches/py3k/runtests.sh (original) +++ python/branches/py3k/runtests.sh Fri Oct 17 14:05:40 2008 @@ -22,6 +22,8 @@ *) PYTHON=./python;; esac +PYTHON="$PYTHON -bb" + # Unset PYTHONPATH, just to be sure. unset PYTHONPATH From python-3000-checkins at python.org Fri Oct 17 15:47:20 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Fri, 17 Oct 2008 15:47:20 +0200 (CEST) Subject: [Python-3000-checkins] r66960 - in python/branches/py3k: Misc/NEWS Tools/msi/msi.py Message-ID: <20081017134720.AE9241E400C@bag.python.org> Author: martin.v.loewis Date: Fri Oct 17 15:47:20 2008 New Revision: 66960 Log: Merged revisions 66958 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66958 | martin.v.loewis | 2008-10-17 15:43:01 +0200 (Fr, 17 Okt 2008) | 1 line Issue #4091: Install pythonxy.dll in system32 again. ........ 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 Oct 17 15:47:20 2008 @@ -67,6 +67,8 @@ Build ----- +- Issue #4091: Install pythonxy.dll in system32 again. + - Issue #4018: Disable "for me" installations on Vista. 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 Fri Oct 17 15:47:20 2008 @@ -916,9 +916,7 @@ root.add_file("%s/pythonw.exe" % PCBUILD) # msidbComponentAttributesSharedDllRefCount = 8, see "Component Table" - #dlldir = PyDirectory(db, cab, root, srcdir, "DLLDIR", ".") - #install python30.dll into root dir for now - dlldir = root + dlldir = PyDirectory(db, cab, root, srcdir, "DLLDIR", ".") pydll = "python%s%s.dll" % (major, minor) pydllsrc = os.path.join(srcdir, PCBUILD, pydll) From python-3000-checkins at python.org Fri Oct 17 17:54:44 2008 From: python-3000-checkins at python.org (martin.v.loewis) Date: Fri, 17 Oct 2008 17:54:44 +0200 (CEST) Subject: [Python-3000-checkins] r66961 - in python/branches/py3k: Demo/embed/demo.c Misc/NEWS Message-ID: <20081017155444.EBA811E4002@bag.python.org> Author: martin.v.loewis Date: Fri Oct 17 17:54:44 2008 New Revision: 66961 Log: Issue #3717: Fix Demo/embed/demo.c. Reviewed by Benjamin Peterson. Modified: python/branches/py3k/Demo/embed/demo.c python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Demo/embed/demo.c ============================================================================== --- python/branches/py3k/Demo/embed/demo.c (original) +++ python/branches/py3k/Demo/embed/demo.c Fri Oct 17 17:54:44 2008 @@ -2,34 +2,38 @@ #include "Python.h" -void initxyzzy(void); /* Forward */ +PyObject* PyInit_xyzzy(void); /* Forward */ main(int argc, char **argv) { + /* Ignore passed-in argc/argv. If desired, conversion + should use mbstowcs to convert them. */ + wchar_t *args[] = {L"embed", L"hello", 0}; + /* Pass argv[0] to the Python interpreter */ - Py_SetProgramName(argv[0]); + Py_SetProgramName(args[0]); + + /* Add a static module */ + PyImport_AppendInittab("xyzzy", PyInit_xyzzy); /* Initialize the Python interpreter. Required. */ Py_Initialize(); - /* Add a static module */ - initxyzzy(); - /* Define sys.argv. It is up to the application if you want this; you can also let it undefined (since the Python code is generally not a main program it has no business touching sys.argv...) */ - PySys_SetArgv(argc, argv); + PySys_SetArgv(2, args); /* Do some application specific code */ printf("Hello, brave new world\n\n"); /* Execute some Python statements (in module __main__) */ PyRun_SimpleString("import sys\n"); - PyRun_SimpleString("print sys.builtin_module_names\n"); - PyRun_SimpleString("print sys.modules.keys()\n"); - PyRun_SimpleString("print sys.executable\n"); - PyRun_SimpleString("print sys.argv\n"); + PyRun_SimpleString("print(sys.builtin_module_names)\n"); + PyRun_SimpleString("print(sys.modules.keys())\n"); + PyRun_SimpleString("print(sys.executable)\n"); + PyRun_SimpleString("print(sys.argv)\n"); /* Note that you can call any public function of the Python interpreter here, e.g. call_object(). */ @@ -57,9 +61,20 @@ {NULL, NULL} /* sentinel */ }; -void -initxyzzy(void) +static struct PyModuleDef xyzzymodule = { + {}, /* m_base */ + "xyzzy", /* m_name */ + 0, /* m_doc */ + 0, /* m_size */ + xyzzy_methods, /* m_methods */ + 0, /* m_reload */ + 0, /* m_traverse */ + 0, /* m_clear */ + 0, /* m_free */ +}; + +PyObject* +PyInit_xyzzy(void) { - PyImport_AddModule("xyzzy"); - Py_InitModule("xyzzy", xyzzy_methods); + return PyModule_Create(&xyzzymodule); } Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Oct 17 17:54:44 2008 @@ -74,6 +74,8 @@ Tools/Demos ----------- +- Issue #3717: Fix Demo/embed/demo.c. + - Issue #4072: Add a distutils demo for build_py_2to3. From python-3000-checkins at python.org Fri Oct 17 22:15:59 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 17 Oct 2008 22:15:59 +0200 (CEST) Subject: [Python-3000-checkins] r66963 - in python/branches/py3k: Lib/test/pickletester.py Misc/NEWS Modules/_pickle.c Message-ID: <20081017201559.824751E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 17 22:15:53 2008 New Revision: 66963 Log: #3664: The pickle module could segfault if a Pickler instance is not correctly initialized: when a subclass forgets to call the base __init__ method, or when __init__ is called a second time with invalid parameters Patch by Alexandre Vassalotti. 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 Fri Oct 17 22:15:53 2008 @@ -996,6 +996,20 @@ pickle.Pickler(f, -1) pickle.Pickler(f, protocol=-1) + def test_bad_init(self): + # Test issue3664 (pickle can segfault from a badly initialized Pickler). + from io import BytesIO + # Override initialization without calling __init__() of the superclass. + class BadPickler(pickle.Pickler): + def __init__(self): pass + + class BadUnpickler(pickle.Unpickler): + def __init__(self): pass + + self.assertRaises(pickle.PicklingError, BadPickler().dump, 0) + self.assertRaises(pickle.UnpicklingError, BadUnpickler().load) + + class AbstractPersistentPicklerTests(unittest.TestCase): # This class defines persistent_id() and persistent_load() Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Oct 17 22:15:53 2008 @@ -33,7 +33,10 @@ Library ------- -- telnetlib now works completely in bytes. +- Issue #3664: The pickle module could segfault if a subclass of Pickler fails + to call the base __init__ method. + +- Issue #3725: telnetlib now works completely in bytes. - Issue #4072: Restore build_py_2to3. Modified: python/branches/py3k/Modules/_pickle.c ============================================================================== --- python/branches/py3k/Modules/_pickle.c (original) +++ python/branches/py3k/Modules/_pickle.c Fri Oct 17 22:15:53 2008 @@ -421,6 +421,11 @@ { PyObject *data, *result; + if (self->write_buf == NULL) { + PyErr_SetString(PyExc_SystemError, "invalid write buffer"); + return -1; + } + if (s == NULL) { if (!(self->buf_size)) return 0; @@ -2378,6 +2383,16 @@ { PyObject *obj; + /* Check whether the Pickler was initialized correctly (issue3664). + Developers often forget to call __init__() in their subclasses, which + would trigger a segfault without this check. */ + if (self->write == NULL) { + PyErr_Format(PicklingError, + "Pickler.__init__() was not called by %s.__init__()", + Py_TYPE(self)->tp_name); + return NULL; + } + if (!PyArg_ParseTuple(args, "O:dump", &obj)) return NULL; From python-3000-checkins at python.org Sat Oct 18 21:25:08 2008 From: python-3000-checkins at python.org (alexandre.vassalotti) Date: Sat, 18 Oct 2008 21:25:08 +0200 (CEST) Subject: [Python-3000-checkins] r66970 - python/branches/py3k/Doc/library/pickle.rst Message-ID: <20081018192508.3E3A91E4002@bag.python.org> Author: alexandre.vassalotti Date: Sat Oct 18 21:25:07 2008 New Revision: 66970 Log: Improve pickle's documentation. There is still much to be done, but I am committing my changes incrementally to avoid losing them again (for a third time now). Modified: python/branches/py3k/Doc/library/pickle.rst Modified: python/branches/py3k/Doc/library/pickle.rst ============================================================================== --- python/branches/py3k/Doc/library/pickle.rst (original) +++ python/branches/py3k/Doc/library/pickle.rst Sat Oct 18 21:25:07 2008 @@ -92,11 +92,9 @@ XDR (which can't represent pointer sharing); however it means that non-Python programs may not be able to reconstruct pickled Python objects. -By default, the :mod:`pickle` data format uses a printable ASCII representation. -This is slightly more voluminous than a binary representation. The big -advantage of using printable ASCII (and of some other characteristics of -:mod:`pickle`'s representation) is that for debugging or recovery purposes it is -possible for a human to read the pickled file with a standard text editor. +By default, the :mod:`pickle` data format uses a compact binary representation. +The module :mod:`pickletools` contains tools for analyzing data streams +generated by :mod:`pickle`. There are currently 4 different protocols which can be used for pickling. @@ -110,17 +108,15 @@ efficient pickling of :term:`new-style class`\es. * Protocol version 3 was added in Python 3.0. It has explicit support for - bytes and cannot be unpickled by Python 2.x pickle modules. + bytes and cannot be unpickled by Python 2.x pickle modules. This is + the current recommended protocol, use it whenever it is possible. Refer to :pep:`307` for more information. -If a *protocol* is not specified, protocol 3 is used. If *protocol* is +If a *protocol* is not specified, protocol 3 is used. If *protocol* is specified as a negative value or :const:`HIGHEST_PROTOCOL`, the highest protocol version available will be used. -A binary format, which is slightly more efficient, can be chosen by specifying a -*protocol* version >= 1. - Usage ----- @@ -146,152 +142,210 @@ as line terminators and therefore will look "funny" when viewed in Notepad or other editors which do not support this format. +.. data:: DEFAULT_PROTOCOL + + The default protocol used for pickling. May be less than HIGHEST_PROTOCOL. + Currently the default protocol is 3; a backward-incompatible protocol + designed for Python 3.0. + + The :mod:`pickle` module provides the following functions to make the pickling process more convenient: - .. function:: dump(obj, file[, protocol]) - Write a pickled representation of *obj* to the open file object *file*. This is - equivalent to ``Pickler(file, protocol).dump(obj)``. + Write a pickled representation of *obj* to the open file object *file*. This + is equivalent to ``Pickler(file, protocol).dump(obj)``. - If the *protocol* parameter is omitted, protocol 3 is used. If *protocol* is - specified as a negative value or :const:`HIGHEST_PROTOCOL`, the highest - protocol version will be used. + The optional *protocol* argument tells the pickler to use the given protocol; + supported protocols are 0, 1, 2, 3. The default protocol is 3; a + backward-incompatible protocol designed for Python 3.0. + + Specifying a negative protocol version selects the highest protocol version + supported. The higher the protocol used, the more recent the version of + Python needed to read the pickle produced. + + The *file* argument must have a write() method that accepts a single bytes + argument. It can thus be a file object opened for binary writing, a + io.BytesIO instance, or any other custom object that meets this interface. - *file* must have a :meth:`write` method that accepts a single string argument. - It can thus be a file object opened for writing, a :mod:`StringIO` object, or - any other custom object that meets this interface. +.. function:: dumps(obj[, protocol]) + + Return the pickled representation of the object as a :class:`bytes` + object, instead of writing it to a file. + The optional *protocol* argument tells the pickler to use the given protocol; + supported protocols are 0, 1, 2, 3. The default protocol is 3; a + backward-incompatible protocol designed for Python 3.0. + + Specifying a negative protocol version selects the highest protocol version + supported. The higher the protocol used, the more recent the version of + Python needed to read the pickle produced. -.. function:: load(file) +.. function:: load(file, [\*, encoding="ASCII", errors="strict"]) - Read a string from the open file object *file* and interpret it as a pickle data - stream, reconstructing and returning the original object hierarchy. This is + Read a pickled object representation from the open file object *file* and + return the reconstituted object hierarchy specified therein. This is equivalent to ``Unpickler(file).load()``. - *file* must have two methods, a :meth:`read` method that takes an integer - argument, and a :meth:`readline` method that requires no arguments. Both - methods should return a string. Thus *file* can be a file object opened for - reading, a :mod:`StringIO` object, or any other custom object that meets this + The protocol version of the pickle is detected automatically, so no protocol + argument is needed. Bytes past the pickled object's representation are + ignored. + + The argument *file* must have two methods, a read() method that takes an + integer argument, and a readline() method that requires no arguments. Both + methods should return bytes. Thus *file* can be a binary file object opened + for reading, a BytesIO object, or any other custom object that meets this interface. - This function automatically determines whether the data stream was written in - binary mode or not. + Optional keyword arguments are encoding and errors, which are used to decode + 8-bit string instances pickled by Python 2.x. These default to 'ASCII' and + 'strict', respectively. +.. function:: loads(bytes_object, [\*, encoding="ASCII", errors="strict"]) -.. function:: dumps(obj[, protocol]) - - Return the pickled representation of the object as a :class:`bytes` - object, instead of writing it to a file. + Read a pickled object hierarchy from a :class:`bytes` object and return the + reconstituted object hierarchy specified therein - If the *protocol* parameter is omitted, protocol 3 is used. If *protocol* - is specified as a negative value or :const:`HIGHEST_PROTOCOL`, the highest - protocol version will be used. + The protocol version of the pickle is detected automatically, so no protocol + argument is needed. Bytes past the pickled object's representation are + ignored. + Optional keyword arguments are encoding and errors, which are used to decode + 8-bit string instances pickled by Python 2.x. These default to 'ASCII' and + 'strict', respectively. -.. function:: loads(bytes_object) - - Read a pickled object hierarchy from a :class:`bytes` object. - Bytes past the pickled object's representation are ignored. - -The :mod:`pickle` module also defines three exceptions: +The :mod:`pickle` module defines three exceptions: .. exception:: PickleError - A common base class for the other exceptions defined below. This inherits from + Common base class for the other pickling exceptions. It inherits :exc:`Exception`. - .. exception:: PicklingError - This exception is raised when an unpicklable object is passed to the - :meth:`dump` method. - + Error raised when an unpicklable object is encountered by :class:`Pickler`. + It inherits :exc:`PickleError`. .. exception:: UnpicklingError - This exception is raised when there is a problem unpickling an object. Note that - other exceptions may also be raised during unpickling, including (but not - necessarily limited to) :exc:`AttributeError`, :exc:`EOFError`, - :exc:`ImportError`, and :exc:`IndexError`. + Error raised when there a problem unpickling an object, such as a data + corruption or a security violation. It inherits :exc:`PickleError`. + + Note that other exceptions may also be raised during unpickling, including + (but not necessarily limited to) AttributeError, EOFError, ImportError, and + IndexError. -The :mod:`pickle` module also exports two callables, :class:`Pickler` and -:class:`Unpickler`: +The :mod:`pickle` module exports two classes, :class:`Pickler` and +:class:`Unpickler`: .. class:: Pickler(file[, protocol]) - This takes a file-like object to which it will write a pickle data stream. + This takes a binary file for writing a pickle data stream. - If the *protocol* parameter is omitted, protocol 3 is used. If *protocol* is - specified as a negative value or :const:`HIGHEST_PROTOCOL`, the highest - protocol version will be used. + The optional *protocol* argument tells the pickler to use the given protocol; + supported protocols are 0, 1, 2, 3. The default protocol is 3; a + backward-incompatible protocol designed for Python 3.0. + + Specifying a negative protocol version selects the highest protocol version + supported. The higher the protocol used, the more recent the version of + Python needed to read the pickle produced. + + The *file* argument must have a write() method that accepts a single bytes + argument. It can thus be a file object opened for binary writing, a + io.BytesIO instance, or any other custom object that meets this interface. - *file* must have a :meth:`write` method that accepts a single string argument. - It can thus be an open file object, a :mod:`StringIO` object, or any other - custom object that meets this interface. + .. method:: dump(obj) - :class:`Pickler` objects define one (or two) public methods: + Write a pickled representation of *obj* to the open file object given in + the constructor. + .. method:: persistent_id(obj) - .. method:: dump(obj) + Do nothing by default. This exists so a subclass can override it. - Write a pickled representation of *obj* to the open file object given in the - constructor. Either the binary or ASCII format will be used, depending on the - value of the *protocol* argument passed to the constructor. + If :meth:`persistent_id` returns ``None``, *obj* is pickled as usual. Any + other value causes :class:`Pickler` to emit the returned value as a + persistent ID for *obj*. The meaning of this persistent ID should be + defined by :meth:`Unpickler.persistent_load`. Note that the value + returned by :meth:`persistent_id` cannot itself have a persistent ID. + See :ref:`pickle-persistent` for details and examples of uses. .. method:: clear_memo() - Clears the pickler's "memo". The memo is the data structure that remembers - which objects the pickler has already seen, so that shared or recursive objects - pickled by reference and not by value. This method is useful when re-using - picklers. + Deprecated. Use the :meth:`clear` method on the :attr:`memo`. Clear the + pickler's memo, useful when reusing picklers. + + .. attribute:: fast + + Enable fast mode if set to a true value. The fast mode disables the usage + of memo, therefore speeding the pickling process by not generating + superfluous PUT opcodes. It should not be used with self-referential + objects, doing otherwise will cause :class:`Pickler` to recurse + infinitely. + + Use :func:`pickletools.optimize` if you need more compact pickles. + + .. attribute:: memo + + Dictionary holding previously pickled objects to allow shared or + recursive objects to pickled by reference as opposed to by value. It is possible to make multiple calls to the :meth:`dump` method of the same :class:`Pickler` instance. These must then be matched to the same number of calls to the :meth:`load` method of the corresponding :class:`Unpickler` instance. If the same object is pickled by multiple :meth:`dump` calls, the -:meth:`load` will all yield references to the same object. [#]_ +:meth:`load` will all yield references to the same object. -:class:`Unpickler` objects are defined as: +Please note, this is intended for pickling multiple objects without intervening +modifications to the objects or their parts. If you modify an object and then +pickle it again using the same :class:`Pickler` instance, the object is not +pickled again --- a reference to it is pickled and the :class:`Unpickler` will +return the old value, not the modified one. -.. class:: Unpickler(file) +.. class:: Unpickler(file, [\*, encoding="ASCII", errors="strict"]) - This takes a file-like object from which it will read a pickle data stream. - This class automatically determines whether the data stream was written in - binary mode or not, so it does not need a flag as in the :class:`Pickler` - factory. + This takes a binary file for reading a pickle data stream. - *file* must have two methods, a :meth:`read` method that takes an integer - argument, and a :meth:`readline` method that requires no arguments. Both - methods should return a string. Thus *file* can be a file object opened for - reading, a :mod:`StringIO` object, or any other custom object that meets this - interface. + The protocol version of the pickle is detected automatically, so no + protocol argument is needed. - :class:`Unpickler` objects have one (or two) public methods: + The argument *file* must have two methods, a read() method that takes an + integer argument, and a readline() method that requires no arguments. Both + methods should return bytes. Thus *file* can be a binary file object opened + for reading, a BytesIO object, or any other custom object that meets this + interface. + Optional keyword arguments are encoding and errors, which are used to decode + 8-bit string instances pickled by Python 2.x. These default to 'ASCII' and + 'strict', respectively. .. method:: load() Read a pickled object representation from the open file object given in the constructor, and return the reconstituted object hierarchy specified - therein. + therein. Bytes past the pickled object's representation are ignored. - This method automatically determines whether the data stream was written - in binary mode or not. + .. method:: persistent_load(pid) + Raise an :exc:`UnpickingError` by default. - .. method:: noload() + If defined, :meth:`persistent_load` should return the object specified by + the persistent ID *pid*. On errors, such as if an invalid persistent ID is + encountered, an :exc:`UnpickingError` should be raised. - This is just like :meth:`load` except that it doesn't actually create any - objects. This is useful primarily for finding what's called "persistent - ids" that may be referenced in a pickle data stream. See section - :ref:`pickle-protocol` below for more details. + See :ref:`pickle-persistent` for details and examples of uses. + + .. method:: find_class(module, name) + + Import *module* if necessary and return the object called *name* from it. + Subclasses may override this to gain control over what type of objects can + be loaded, potentially reducing security risks. What can be pickled and unpickled? @@ -506,6 +560,8 @@ unpickling as described above. +.. _pickle-persistent: + Pickling and unpickling external objects ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -747,14 +803,6 @@ .. [#] Don't confuse this with the :mod:`marshal` module -.. [#] *Warning*: this is intended for pickling multiple objects without intervening - modifications to the objects or their parts. If you modify an object and then - pickle it again using the same :class:`Pickler` instance, the object is not - pickled again --- a reference to it is pickled and the :class:`Unpickler` will - return the old value, not the modified one. There are two problems here: (1) - detecting changes, and (2) marshalling a minimal set of changes. Garbage - Collection may also become a problem here. - .. [#] The exception raised will likely be an :exc:`ImportError` or an :exc:`AttributeError` but it could be something else. From python-3000-checkins at python.org Sat Oct 18 22:47:58 2008 From: python-3000-checkins at python.org (alexandre.vassalotti) Date: Sat, 18 Oct 2008 22:47:58 +0200 (CEST) Subject: [Python-3000-checkins] r66971 - in python/branches/py3k/Doc: includes/dbpickle.py library/pickle.rst Message-ID: <20081018204758.92F3D1E4002@bag.python.org> Author: alexandre.vassalotti Date: Sat Oct 18 22:47:58 2008 New Revision: 66971 Log: Improve pickle's documentation. Use double-space for ending a sentence. Add dbpickle.py example. Improve description about persistent IDs. Added: python/branches/py3k/Doc/includes/dbpickle.py Modified: python/branches/py3k/Doc/library/pickle.rst Added: python/branches/py3k/Doc/includes/dbpickle.py ============================================================================== --- (empty file) +++ python/branches/py3k/Doc/includes/dbpickle.py Sat Oct 18 22:47:58 2008 @@ -0,0 +1,88 @@ +# Simple example presenting how persistent ID can be used to pickle +# external objects by reference. + +import pickle +import sqlite3 +from collections import namedtuple + +# Simple class representing a record in our database. +MemoRecord = namedtuple("MemoRecord", "key, task") + +class DBPickler(pickle.Pickler): + + def persistent_id(self, obj): + # Instead of pickling MemoRecord as a regular class instance, we emit a + # persistent ID instead. + if isinstance(obj, MemoRecord): + # Here, our persistent ID is simply a tuple containing a tag and a + # key which refers to a specific record in the database. + return ("MemoRecord", obj.key) + else: + # If obj does not have a persistent ID, return None. This means obj + # needs to be pickled as usual. + return None + + +class DBUnpickler(pickle.Unpickler): + + def __init__(self, file, connection): + super().__init__(file) + self.connection = connection + + def persistent_load(self, pid): + # This method is invoked whenever a persistent ID is encountered. + # Here, pid is the tuple returned by DBPickler. + cursor = self.connection.cursor() + type_tag, key_id = pid + if type_tag == "MemoRecord": + # Fetch the referenced record from the database and return it. + cursor.execute("SELECT * FROM memos WHERE key=?", (str(key_id),)) + key, task = cursor.fetchone() + return MemoRecord(key, task) + else: + # Always raises an error if you cannot return the correct object. + # Otherwise, the unpickler will think None is the object referenced + # by the persistent ID. + raise pickle.UnpicklingError("unsupported persistent object") + + +def main(verbose=True): + import io, pprint + + # Initialize and populate our database. + conn = sqlite3.connect(":memory:") + cursor = conn.cursor() + cursor.execute("CREATE TABLE memos(key INTEGER PRIMARY KEY, task TEXT)") + tasks = ( + 'give food to fish', + 'prepare group meeting', + 'fight with a zebra', + ) + for task in tasks: + cursor.execute("INSERT INTO memos VALUES(NULL, ?)", (task,)) + + # Fetch the records to be pickled. + cursor.execute("SELECT * FROM memos") + memos = [MemoRecord(key, task) for key, task in cursor] + # Save the records using our custom DBPickler. + file = io.BytesIO() + DBPickler(file).dump(memos) + + if verbose: + print("Records to be pickled:") + pprint.pprint(memos) + + # Update a record, just for good measure. + cursor.execute("UPDATE memos SET task='learn italian' WHERE key=1") + + # Load the reports from the pickle data stream. + file.seek(0) + memos = DBUnpickler(file, conn).load() + + if verbose: + print("Unpickled records:") + pprint.pprint(memos) + + +if __name__ == '__main__': + main() Modified: python/branches/py3k/Doc/library/pickle.rst ============================================================================== --- python/branches/py3k/Doc/library/pickle.rst (original) +++ python/branches/py3k/Doc/library/pickle.rst Sat Oct 18 22:47:58 2008 @@ -27,7 +27,7 @@ ------------------------------------ The :mod:`pickle` module has an transparent optimizer (:mod:`_pickle`) written -in C. It is used whenever available. Otherwise the pure Python implementation is +in C. It is used whenever available. Otherwise the pure Python implementation is used. Python has a more primitive serialization module called :mod:`marshal`, but in @@ -108,7 +108,7 @@ efficient pickling of :term:`new-style class`\es. * Protocol version 3 was added in Python 3.0. It has explicit support for - bytes and cannot be unpickled by Python 2.x pickle modules. This is + bytes and cannot be unpickled by Python 2.x pickle modules. This is the current recommended protocol, use it whenever it is possible. Refer to :pep:`307` for more information. @@ -166,7 +166,7 @@ Python needed to read the pickle produced. The *file* argument must have a write() method that accepts a single bytes - argument. It can thus be a file object opened for binary writing, a + argument. It can thus be a file object opened for binary writing, a io.BytesIO instance, or any other custom object that meets this interface. .. function:: dumps(obj[, protocol]) @@ -220,7 +220,7 @@ .. exception:: PickleError - Common base class for the other pickling exceptions. It inherits + Common base class for the other pickling exceptions. It inherits :exc:`Exception`. .. exception:: PicklingError @@ -228,10 +228,13 @@ Error raised when an unpicklable object is encountered by :class:`Pickler`. It inherits :exc:`PickleError`. + Refer to :ref:`pickle-picklable` to learn what kinds of objects can be + pickled. + .. exception:: UnpicklingError Error raised when there a problem unpickling an object, such as a data - corruption or a security violation. It inherits :exc:`PickleError`. + corruption or a security violation. It inherits :exc:`PickleError`. Note that other exceptions may also be raised during unpickling, including (but not necessarily limited to) AttributeError, EOFError, ImportError, and @@ -254,7 +257,7 @@ Python needed to read the pickle produced. The *file* argument must have a write() method that accepts a single bytes - argument. It can thus be a file object opened for binary writing, a + argument. It can thus be a file object opened for binary writing, a io.BytesIO instance, or any other custom object that meets this interface. .. method:: dump(obj) @@ -276,8 +279,8 @@ .. method:: clear_memo() - Deprecated. Use the :meth:`clear` method on the :attr:`memo`. Clear the - pickler's memo, useful when reusing picklers. + Deprecated. Use the :meth:`clear` method on :attr:`memo`, instead. + Clear the pickler's memo, useful when reusing picklers. .. attribute:: fast @@ -329,24 +332,28 @@ Read a pickled object representation from the open file object given in the constructor, and return the reconstituted object hierarchy specified - therein. Bytes past the pickled object's representation are ignored. + therein. Bytes past the pickled object's representation are ignored. .. method:: persistent_load(pid) Raise an :exc:`UnpickingError` by default. If defined, :meth:`persistent_load` should return the object specified by - the persistent ID *pid*. On errors, such as if an invalid persistent ID is - encountered, an :exc:`UnpickingError` should be raised. + the persistent ID *pid*. If an invalid persistent ID is encountered, an + :exc:`UnpickingError` should be raised. See :ref:`pickle-persistent` for details and examples of uses. .. method:: find_class(module, name) - Import *module* if necessary and return the object called *name* from it. - Subclasses may override this to gain control over what type of objects can - be loaded, potentially reducing security risks. + Import *module* if necessary and return the object called *name* from it, + where the *module* and *name* arguments are :class:`str` objects. + + Subclasses may override this to gain control over what type of objects and + how they can be loaded, potentially reducing security risks. + +.. _pickle-picklable: What can be pickled and unpickled? ---------------------------------- @@ -372,9 +379,9 @@ Attempts to pickle unpicklable objects will raise the :exc:`PicklingError` exception; when this happens, an unspecified number of bytes may have already -been written to the underlying file. Trying to pickle a highly recursive data +been written to the underlying file. Trying to pickle a highly recursive data structure may exceed the maximum recursion depth, a :exc:`RuntimeError` will be -raised in this case. You can carefully raise this limit with +raised in this case. You can carefully raise this limit with :func:`sys.setrecursionlimit`. Note that functions (built-in and user-defined) are pickled by "fully qualified" @@ -390,7 +397,7 @@ restored in the unpickling environment:: class Foo: - attr = 'a class attr' + attr = 'A class attribute' picklestring = pickle.dumps(Foo) @@ -571,79 +578,30 @@ For the benefit of object persistence, the :mod:`pickle` module supports the notion of a reference to an object outside the pickled data stream. Such -objects are referenced by a "persistent id", which is just an arbitrary string -of printable ASCII characters. The resolution of such names is not defined by -the :mod:`pickle` module; it will delegate this resolution to user defined -functions on the pickler and unpickler. - -To define external persistent id resolution, you need to set the -:attr:`persistent_id` attribute of the pickler object and the -:attr:`persistent_load` attribute of the unpickler object. +objects are referenced by a persistent ID, which should be either a string of +alphanumeric characters (for protocol 0) [#]_ or just an arbitrary object (for +any newer protocol). + +The resolution of such persistent IDs is not defined by the :mod:`pickle` +module; it will delegate this resolution to the user defined methods on the +pickler and unpickler, :meth:`persistent_id` and :meth:`persistent_load` +respectively. To pickle objects that have an external persistent id, the pickler must have a -custom :func:`persistent_id` method that takes an object as an argument and +custom :meth:`persistent_id` method that takes an object as an argument and returns either ``None`` or the persistent id for that object. When ``None`` is -returned, the pickler simply pickles the object as normal. When a persistent id -string is returned, the pickler will pickle that string, along with a marker so -that the unpickler will recognize the string as a persistent id. +returned, the pickler simply pickles the object as normal. When a persistent ID +string is returned, the pickler will pickle that object, along with a marker so +that the unpickler will recognize it as a persistent ID. To unpickle external objects, the unpickler must have a custom -:func:`persistent_load` function that takes a persistent id string and returns -the referenced object. - -Here's a silly example that *might* shed more light:: - - import pickle - from io import StringIO - - src = StringIO() - p = pickle.Pickler(src) - - def persistent_id(obj): - if hasattr(obj, 'x'): - return 'the value %d' % obj.x - else: - return None - - p.persistent_id = persistent_id +:meth:`persistent_load` method that takes a persistent ID object and returns the +referenced object. - class Integer: - def __init__(self, x): - self.x = x - def __str__(self): - return 'My name is integer %d' % self.x +Example: - i = Integer(7) - print(i) - p.dump(i) - - datastream = src.getvalue() - print(repr(datastream)) - dst = StringIO(datastream) - - up = pickle.Unpickler(dst) - - class FancyInteger(Integer): - def __str__(self): - return 'I am the integer %d' % self.x - - def persistent_load(persid): - if persid.startswith('the value '): - value = int(persid.split()[2]) - return FancyInteger(value) - else: - raise pickle.UnpicklingError('Invalid persistent id') - - up.persistent_load = persistent_load - - j = up.load() - print(j) - - -.. BAW: pickle supports something called inst_persistent_id() - which appears to give unknown types a second shot at producing a persistent - id. Since Jim Fulton can't remember why it was added or what it's for, I'm - leaving it undocumented. +.. highlightlang:: python +.. literalinclude:: ../includes/dbpickle.py .. _pickle-sub: @@ -808,5 +766,10 @@ .. [#] These methods can also be used to implement copying class instances. -.. [#] This protocol is also used by the shallow and deep copying operations defined in - the :mod:`copy` module. +.. [#] This protocol is also used by the shallow and deep copying operations + defined in the :mod:`copy` module. + +.. [#] The limitation on alphanumeric characters is due to the fact the + persistent IDs, in protocol 0, are delimited by the newline character. + Therefore if any kind of newline characters, such as \r and \n, occurs in + persistent IDs, the resulting pickle will become unreadable. From python-3000-checkins at python.org Sun Oct 19 16:07:51 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 19 Oct 2008 16:07:51 +0200 (CEST) Subject: [Python-3000-checkins] r66975 - in python/branches/py3k: Doc/ACKS.txt Doc/library/2to3.rst Doc/library/collections.rst Doc/library/dis.rst Doc/library/functions.rst Doc/library/heapq.rst Doc/library/multiprocessing.rst Doc/whatsnew/2.6.rst Doc/whatsnew/index.rst Include/unicodeobject.h Lib/antigravity.py Lib/idlelib/PyShell.py Lib/idlelib/run.py Lib/lib2to3 Lib/lib2to3/fixes/fix_next.py Lib/lib2to3/fixes/fix_set_literal.py Lib/lib2to3/main.py Lib/lib2to3/refactor.py Lib/lib2to3/tests/data/README Lib/lib2to3/tests/test_fixers.py Lib/lib2to3/tests/test_pytree.py Lib/lib2to3/tests/test_refactor.py Modules/_testcapimodule.c Modules/posixmodule.c Parser/asdl_c.py Tools/scripts/reindent.py Message-ID: <20081019140751.1B6571E4002@bag.python.org> Author: benjamin.peterson Date: Sun Oct 19 16:07:49 2008 New Revision: 66975 Log: Merged revisions 66887,66891,66902-66903,66905-66906,66911-66913,66922,66927-66928,66936,66939-66940,66962,66964,66973 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ................ r66887 | benjamin.peterson | 2008-10-13 16:51:40 -0500 (Mon, 13 Oct 2008) | 1 line document how to disable fixers ................ r66891 | amaury.forgeotdarc | 2008-10-14 16:47:22 -0500 (Tue, 14 Oct 2008) | 5 lines #4122: On Windows, Py_UNICODE_ISSPACE cannot be used in an extension module: compilation fails with "undefined reference to _Py_ascii_whitespace" Will backport to 2.6. ................ r66902 | skip.montanaro | 2008-10-15 06:49:10 -0500 (Wed, 15 Oct 2008) | 1 line easter egg ................ r66903 | benjamin.peterson | 2008-10-15 15:34:09 -0500 (Wed, 15 Oct 2008) | 1 line don't recurse into directories that start with '.' ................ r66905 | benjamin.peterson | 2008-10-15 16:05:55 -0500 (Wed, 15 Oct 2008) | 1 line support the optional line argument for idle ................ r66906 | benjamin.peterson | 2008-10-15 16:58:46 -0500 (Wed, 15 Oct 2008) | 1 line add a much requested newline ................ r66911 | benjamin.peterson | 2008-10-15 18:10:28 -0500 (Wed, 15 Oct 2008) | 41 lines Merged revisions 66805,66841,66860,66884-66886,66893,66907,66910 via svnmerge from svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r66805 | benjamin.peterson | 2008-10-04 20:11:02 -0500 (Sat, 04 Oct 2008) | 1 line mention what the fixes directory is for ........ r66841 | benjamin.peterson | 2008-10-07 17:48:12 -0500 (Tue, 07 Oct 2008) | 1 line use assertFalse and assertTrue ........ r66860 | benjamin.peterson | 2008-10-08 16:05:07 -0500 (Wed, 08 Oct 2008) | 1 line instead of abusing the pattern matcher, use start_tree to find a next binding ........ r66884 | benjamin.peterson | 2008-10-13 15:50:30 -0500 (Mon, 13 Oct 2008) | 1 line don't print tokens to stdout when -v is given ........ r66885 | benjamin.peterson | 2008-10-13 16:28:57 -0500 (Mon, 13 Oct 2008) | 1 line add the -x option to disable fixers ........ r66886 | benjamin.peterson | 2008-10-13 16:33:53 -0500 (Mon, 13 Oct 2008) | 1 line cut down on some crud ........ r66893 | benjamin.peterson | 2008-10-14 17:16:54 -0500 (Tue, 14 Oct 2008) | 1 line add an optional set literal fixer ........ r66907 | benjamin.peterson | 2008-10-15 16:59:41 -0500 (Wed, 15 Oct 2008) | 1 line don't write backup files by default ........ r66910 | benjamin.peterson | 2008-10-15 17:43:10 -0500 (Wed, 15 Oct 2008) | 1 line add the -n option; it stops backupfiles from being written ........ ................ r66912 | hirokazu.yamamoto | 2008-10-16 01:25:25 -0500 (Thu, 16 Oct 2008) | 2 lines removed unused _PyUnicode_FromFileSystemEncodedObject. made win32_chdir, win32_wchdir static. ................ r66913 | benjamin.peterson | 2008-10-16 13:52:14 -0500 (Thu, 16 Oct 2008) | 1 line document that deque indexing is O(n) #4123 ................ r66922 | benjamin.peterson | 2008-10-16 14:40:14 -0500 (Thu, 16 Oct 2008) | 1 line use new showwarnings signature for idle #3391 ................ r66927 | andrew.kuchling | 2008-10-16 15:15:47 -0500 (Thu, 16 Oct 2008) | 1 line Fix wording (2.6.1 backport candidate) ................ r66928 | georg.brandl | 2008-10-16 15:20:56 -0500 (Thu, 16 Oct 2008) | 2 lines Add more TOC to the whatsnew index page. ................ r66936 | georg.brandl | 2008-10-16 16:20:15 -0500 (Thu, 16 Oct 2008) | 2 lines #4131: FF3 doesn't write cookies.txt files. ................ r66939 | georg.brandl | 2008-10-16 16:36:39 -0500 (Thu, 16 Oct 2008) | 2 lines part of #4012: kill off old name "processing". ................ r66940 | georg.brandl | 2008-10-16 16:38:48 -0500 (Thu, 16 Oct 2008) | 2 lines #4083: add "as" to except handler grammar as per PEP 3110. ................ r66962 | benjamin.peterson | 2008-10-17 15:01:01 -0500 (Fri, 17 Oct 2008) | 1 line clarify CALL_FUNCTION #4141 ................ r66964 | georg.brandl | 2008-10-17 16:41:49 -0500 (Fri, 17 Oct 2008) | 2 lines Fix duplicate word. ................ r66973 | armin.ronacher | 2008-10-19 03:27:43 -0500 (Sun, 19 Oct 2008) | 3 lines Fixed #4067 by implementing _attributes and _fields for the AST root node. ................ Added: python/branches/py3k/Lib/antigravity.py - copied unchanged from r66928, /python/trunk/Lib/antigravity.py python/branches/py3k/Lib/lib2to3/fixes/fix_set_literal.py - copied unchanged from r66928, /python/trunk/Lib/lib2to3/fixes/fix_set_literal.py Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/ACKS.txt python/branches/py3k/Doc/library/2to3.rst python/branches/py3k/Doc/library/collections.rst python/branches/py3k/Doc/library/dis.rst python/branches/py3k/Doc/library/functions.rst python/branches/py3k/Doc/library/heapq.rst python/branches/py3k/Doc/library/multiprocessing.rst python/branches/py3k/Doc/whatsnew/2.6.rst python/branches/py3k/Doc/whatsnew/index.rst python/branches/py3k/Include/unicodeobject.h python/branches/py3k/Lib/idlelib/PyShell.py python/branches/py3k/Lib/idlelib/run.py python/branches/py3k/Lib/lib2to3/ (props changed) python/branches/py3k/Lib/lib2to3/fixes/fix_next.py python/branches/py3k/Lib/lib2to3/main.py python/branches/py3k/Lib/lib2to3/refactor.py python/branches/py3k/Lib/lib2to3/tests/data/README python/branches/py3k/Lib/lib2to3/tests/test_fixers.py python/branches/py3k/Lib/lib2to3/tests/test_pytree.py python/branches/py3k/Lib/lib2to3/tests/test_refactor.py python/branches/py3k/Modules/_testcapimodule.c python/branches/py3k/Modules/posixmodule.c python/branches/py3k/Parser/asdl_c.py python/branches/py3k/Tools/scripts/reindent.py Modified: python/branches/py3k/Doc/ACKS.txt ============================================================================== --- python/branches/py3k/Doc/ACKS.txt (original) +++ python/branches/py3k/Doc/ACKS.txt Sun Oct 19 16:07:49 2008 @@ -190,6 +190,7 @@ * Reuben Sumner * Kalle Svensson * Jim Tittsler + * David Turner * Ville Vainio * Martijn Vries * Charles G. Waldman Modified: python/branches/py3k/Doc/library/2to3.rst ============================================================================== --- python/branches/py3k/Doc/library/2to3.rst (original) +++ python/branches/py3k/Doc/library/2to3.rst Sun Oct 19 16:07:49 2008 @@ -53,13 +53,17 @@ Comments and and exact indentation are preserved throughout the translation process. -By default, 2to3 runs a set of predefined fixers. The :option:`-l` flag -lists all avaible fixers. An explicit set of fixers to run can be given by use -of the :option:`-f` flag. The following example runs only the ``imports`` and -``has_key`` fixers:: +By default, 2to3 runs a set of predefined fixers. The :option:`-l` flag lists +all avaible fixers. An explicit set of fixers to run can be given with +:option:`-f`. Likewise the :option:`-x` explicitly disables a fixer. The +following example runs only the ``imports`` and ``has_key`` fixers:: $ 2to3 -f imports -f has_key example.py +This command runs every fixer except the ``apply`` fixer:: + + $ 2to3 -x apply example.py + Some fixers are *explicit*, meaning they aren't run be default and must be listed on the command line to be run. Here, in addition to the default fixers, the ``idioms`` fixer is run:: @@ -78,8 +82,8 @@ the module to be valid Python. For example, doctest like examples in a reST document could also be refactored with this option. -The :option:`-v` option enables the output of more information on the -translation process. +The :option:`-v` option enables output of more information on the translation +process. When the :option:`-p` is passed, 2to3 treats ``print`` as a function instead of a statement. This is useful when ``from __future__ import print_function`` is Modified: python/branches/py3k/Doc/library/collections.rst ============================================================================== --- python/branches/py3k/Doc/library/collections.rst (original) +++ python/branches/py3k/Doc/library/collections.rst Sun Oct 19 16:07:49 2008 @@ -228,7 +228,9 @@ In addition to the above, deques support iteration, pickling, ``len(d)``, ``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with -the :keyword:`in` operator, and subscript references such as ``d[-1]``. +the :keyword:`in` operator, and subscript references such as ``d[-1]``. Indexed +access is O(1) at both ends but slows to O(n) in the middle. For fast random +access, use lists instead. Example: Modified: python/branches/py3k/Doc/library/dis.rst ============================================================================== --- python/branches/py3k/Doc/library/dis.rst (original) +++ python/branches/py3k/Doc/library/dis.rst Sun Oct 19 16:07:49 2008 @@ -677,7 +677,8 @@ opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, - the function object to call is on the stack. + the function object to call is on the stack. Pops all function arguments, and + the function itself off the stack, and pushes the return value. .. opcode:: MAKE_FUNCTION (argc) Modified: python/branches/py3k/Doc/library/functions.rst ============================================================================== --- python/branches/py3k/Doc/library/functions.rst (original) +++ python/branches/py3k/Doc/library/functions.rst Sun Oct 19 16:07:49 2008 @@ -889,7 +889,8 @@ best explained with an example:: class C(object): - def __init__(self): self._x = None + def __init__(self): + self._x = None @property def x(self): Modified: python/branches/py3k/Doc/library/heapq.rst ============================================================================== --- python/branches/py3k/Doc/library/heapq.rst (original) +++ python/branches/py3k/Doc/library/heapq.rst Sun Oct 19 16:07:49 2008 @@ -93,7 +93,7 @@ Merge multiple sorted inputs into a single sorted output (for example, merge timestamped entries from multiple log files). Returns an :term:`iterator` - over over the sorted values. + over the sorted values. Similar to ``sorted(itertools.chain(*iterables))`` but returns an iterable, does not pull the data into memory all at once, and assumes that each of the input Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Sun Oct 19 16:07:49 2008 @@ -376,8 +376,8 @@ Example usage of some of the methods of :class:`Process`:: - >>> import processing, time, signal - >>> p = processing.Process(target=time.sleep, args=(1000,)) + >>> import multiprocessing, time, signal + >>> p = multiprocessing.Process(target=time.sleep, args=(1000,)) >>> print(p, p.is_alive()) False >>> p.start() @@ -1779,12 +1779,12 @@ Below is an example session with logging turned on:: - >>> import processing, logging - >>> logger = processing.getLogger() + >>> import multiprocessing, logging + >>> logger = multiprocessing.getLogger() >>> logger.setLevel(logging.INFO) >>> logger.warning('doomed') [WARNING/MainProcess] doomed - >>> m = processing.Manager() + >>> m = multiprocessing.Manager() [INFO/SyncManager-1] child process calling self.run() [INFO/SyncManager-1] manager bound to '\\\\.\\pipe\\pyc-2776-0-lj0tfa' >>> del m Modified: python/branches/py3k/Doc/whatsnew/2.6.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/2.6.rst (original) +++ python/branches/py3k/Doc/whatsnew/2.6.rst Sun Oct 19 16:07:49 2008 @@ -179,7 +179,7 @@ lot of effort into importing existing bugs and patches from SourceForge; his scripts for this import operation are at http://svn.python.org/view/tracker/importer/ and may be useful to -other projects wished to move from SourceForge to Roundup. +other projects wishing to move from SourceForge to Roundup. .. seealso:: @@ -3282,5 +3282,6 @@ The author would like to thank the following people for offering suggestions, corrections and assistance with various drafts of this article: Georg Brandl, Steve Brown, Nick Coghlan, Ralph Corderoy, -Jim Jewett, Kent Johnson, Chris Lambacher, Antoine Pitrou, Brian Warner. +Jim Jewett, Kent Johnson, Chris Lambacher, Martin Michlmayr, +Antoine Pitrou, Brian Warner. Modified: python/branches/py3k/Doc/whatsnew/index.rst ============================================================================== --- python/branches/py3k/Doc/whatsnew/index.rst (original) +++ python/branches/py3k/Doc/whatsnew/index.rst Sun Oct 19 16:07:49 2008 @@ -9,7 +9,7 @@ anyone wishing to stay up-to-date after a new release. .. toctree:: - :maxdepth: 1 + :maxdepth: 2 3.0.rst 2.7.rst Modified: python/branches/py3k/Include/unicodeobject.h ============================================================================== --- python/branches/py3k/Include/unicodeobject.h (original) +++ python/branches/py3k/Include/unicodeobject.h Sun Oct 19 16:07:49 2008 @@ -373,7 +373,7 @@ in most situations is solely ASCII whitespace, we optimize for the common case by using a quick look-up table with an inlined check. */ -extern const unsigned char _Py_ascii_whitespace[]; +PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[]; #define Py_UNICODE_ISSPACE(ch) \ ((ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch)) Modified: python/branches/py3k/Lib/idlelib/PyShell.py ============================================================================== --- python/branches/py3k/Lib/idlelib/PyShell.py (original) +++ python/branches/py3k/Lib/idlelib/PyShell.py Sun Oct 19 16:07:49 2008 @@ -52,18 +52,22 @@ except ImportError: pass else: - def idle_showwarning(message, category, filename, lineno): + def idle_showwarning(message, category, filename, lineno, + file=None, line=None): file = warning_stream try: - file.write(warnings.formatwarning(message, category, filename, lineno)) + file.write(warnings.formatwarning(message, category, filename,\ + lineno, file=file, line=line)) except IOError: pass ## file (probably __stderr__) is invalid, warning dropped. warnings.showwarning = idle_showwarning - def idle_formatwarning(message, category, filename, lineno): + def idle_formatwarning(message, category, filename, lineno, + file=None, line=None): """Format warnings the IDLE way""" s = "\nWarning (from warnings module):\n" s += ' File \"%s\", line %s\n' % (filename, lineno) - line = linecache.getline(filename, lineno).strip() + line = linecache.getline(filename, lineno).strip() \ + if line is None else line if line: s += " %s\n" % line s += "%s: %s\n>>> " % (category.__name__, message) Modified: python/branches/py3k/Lib/idlelib/run.py ============================================================================== --- python/branches/py3k/Lib/idlelib/run.py (original) +++ python/branches/py3k/Lib/idlelib/run.py Sun Oct 19 16:07:49 2008 @@ -24,11 +24,13 @@ except ImportError: pass else: - def idle_formatwarning_subproc(message, category, filename, lineno): + def idle_formatwarning_subproc(message, category, filename, lineno, + file=None, line=None): """Format warnings the IDLE way""" s = "\nWarning (from warnings module):\n" s += ' File \"%s\", line %s\n' % (filename, lineno) - line = linecache.getline(filename, lineno).strip() + line = linecache.getline(filename, lineno).strip() \ + if line is None else line if line: s += " %s\n" % line s += "%s: %s\n" % (category.__name__, message) 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 Sun Oct 19 16:07:49 2008 @@ -28,15 +28,19 @@ any* > > | global=global_stmt< 'global' any* 'next' any* > - | - mod=file_input< any+ > """ order = "pre" # Pre-order tree traversal def start_tree(self, tree, filename): super(FixNext, self).start_tree(tree, filename) - self.shadowed_next = False + + n = find_binding('next', tree) + if n: + self.warning(n, bind_warning) + self.shadowed_next = True + else: + self.shadowed_next = False def transform(self, node, results): assert results @@ -69,11 +73,6 @@ elif "global" in results: self.warning(node, bind_warning) self.shadowed_next = True - elif mod: - n = find_binding('next', mod) - if n: - self.warning(n, bind_warning) - self.shadowed_next = True ### The following functions help test if node is part of an assignment Modified: python/branches/py3k/Lib/lib2to3/main.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/main.py (original) +++ python/branches/py3k/Lib/lib2to3/main.py Sun Oct 19 16:07:49 2008 @@ -15,10 +15,31 @@ Prints output to stdout. """ + def __init__(self, fixers, options, explicit, nobackups): + self.nobackups = nobackups + super(StdoutRefactoringTool, self).__init__(fixers, options, explicit) + def log_error(self, msg, *args, **kwargs): self.errors.append((msg, args, kwargs)) self.logger.error(msg, *args, **kwargs) + def write_file(self, new_text, filename, old_text): + if not self.nobackups: + # Make backup + backup = filename + ".bak" + if os.path.lexists(backup): + try: + os.remove(backup) + except os.error as err: + self.log_message("Can't remove backup %s", backup) + try: + os.rename(filename, backup) + except os.error as err: + self.log_message("Can't rename %s to %s", filename, backup) + # Actually write the new file + super(StdoutRefactoringTool, self).write_file(new_text, + filename, old_text) + def print_output(self, lines): for line in lines: print(line) @@ -39,7 +60,9 @@ parser.add_option("-d", "--doctests_only", action="store_true", help="Fix up doctests only") parser.add_option("-f", "--fix", action="append", default=[], - help="Each FIX specifies a transformation; default all") + help="Each FIX specifies a transformation; default: all") + parser.add_option("-x", "--nofix", action="append", default=[], + help="Prevent a fixer from being run.") parser.add_option("-l", "--list-fixes", action="store_true", help="List available transformations (fixes/fix_*.py)") parser.add_option("-p", "--print-function", action="store_true", @@ -48,10 +71,14 @@ help="More verbose logging") parser.add_option("-w", "--write", action="store_true", help="Write back modified files") + parser.add_option("-n", "--nobackups", action="store_true", default=False, + help="Don't write backups for modified files.") # Parse command line arguments refactor_stdin = False options, args = parser.parse_args(args) + if not options.write and options.nobackups: + parser.error("Can't use -n without -w") if options.list_fixes: print("Available transformations for the -f/--fix option:") for fixname in refactor.get_all_fix_names(fixer_pkg): @@ -74,15 +101,22 @@ # Initialize the refactoring tool rt_opts = {"print_function" : options.print_function} - avail_names = refactor.get_fixers_from_package(fixer_pkg) - explicit = [] + avail_fixes = set(refactor.get_fixers_from_package(fixer_pkg)) + unwanted_fixes = set(fixer_pkg + ".fix_" + fix for fix in options.nofix) + explicit = set() if options.fix: - explicit = [fixer_pkg + ".fix_" + fix - for fix in options.fix if fix != "all"] - fixer_names = avail_names if "all" in options.fix else explicit + all_present = False + for fix in options.fix: + if fix == "all": + all_present = True + else: + explicit.add(fixer_pkg + ".fix_" + fix) + requested = avail_fixes.union(explicit) if all_present else explicit else: - fixer_names = avail_names - rt = StdoutRefactoringTool(fixer_names, rt_opts, explicit=explicit) + requested = avail_fixes.union(explicit) + fixer_names = requested.difference(unwanted_fixes) + rt = StdoutRefactoringTool(sorted(fixer_names), rt_opts, sorted(explicit), + options.nobackups) # Refactor all files and directories passed as arguments if not rt.errors: Modified: python/branches/py3k/Lib/lib2to3/refactor.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/refactor.py (original) +++ python/branches/py3k/Lib/lib2to3/refactor.py Sun Oct 19 16:07:49 2008 @@ -36,9 +36,7 @@ pkg = __import__(fixer_pkg, [], [], ["*"]) fixer_dir = os.path.dirname(pkg.__file__) fix_names = [] - names = os.listdir(fixer_dir) - names.sort() - for name in names: + for name in sorted(os.listdir(fixer_dir)): if name.startswith("fix_") and name.endswith(".py"): if remove_prefix: name = name[4:] @@ -253,7 +251,7 @@ there were errors during the parse. """ try: - tree = self.driver.parse_string(data,1) + tree = self.driver.parse_string(data) except Exception as err: self.log_error("Can't parse %s: %s: %s", name, err.__class__.__name__, err) @@ -352,23 +350,13 @@ else: self.log_debug("Not writing changes to %s", filename) - def write_file(self, new_text, filename, old_text=None): + def write_file(self, new_text, filename, old_text): """Writes a string to a file. It first shows a unified diff between the old text and the new text, and then rewrites the file; the latter is only done if the write option is set. """ - backup = filename + ".bak" - if os.path.lexists(backup): - try: - os.remove(backup) - except os.error as err: - self.log_message("Can't remove backup %s", backup) - try: - os.rename(filename, backup) - except os.error as err: - self.log_message("Can't rename %s to %s", filename, backup) try: f = open(filename, "w") except os.error as err: Modified: python/branches/py3k/Lib/lib2to3/tests/data/README ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/data/README (original) +++ python/branches/py3k/Lib/lib2to3/tests/data/README Sun Oct 19 16:07:49 2008 @@ -1,5 +1,6 @@ -Files in this directory: +In this directory: - py2_test_grammar.py -- test file that exercises most/all of Python 2.x's grammar. - py3_test_grammar.py -- test file that exercises most/all of Python 3.x's grammar. - infinite_recursion.py -- test file that causes lib2to3's faster recursive pattern matching scheme to fail, but passes when lib2to3 falls back to iterative pattern matching. +- fixes/ -- for use by test_refactor.py 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 Sun Oct 19 16:07:49 2008 @@ -3385,6 +3385,134 @@ """ self.check_both(b, a) + +class Test_set_literal(FixerTestCase): + + fixer = "set_literal" + + def test_basic(self): + b = """set([1, 2, 3])""" + a = """{1, 2, 3}""" + self.check(b, a) + + b = """set((1, 2, 3))""" + a = """{1, 2, 3}""" + self.check(b, a) + + b = """set((1,))""" + a = """{1}""" + self.check(b, a) + + b = """set([1])""" + self.check(b, a) + + b = """set((a, b))""" + a = """{a, b}""" + self.check(b, a) + + b = """set([a, b])""" + self.check(b, a) + + b = """set((a*234, f(args=23)))""" + a = """{a*234, f(args=23)}""" + self.check(b, a) + + b = """set([a*23, f(23)])""" + a = """{a*23, f(23)}""" + self.check(b, a) + + b = """set([a-234**23])""" + a = """{a-234**23}""" + self.check(b, a) + + def test_listcomps(self): + b = """set([x for x in y])""" + a = """{x for x in y}""" + self.check(b, a) + + b = """set([x for x in y if x == m])""" + a = """{x for x in y if x == m}""" + self.check(b, a) + + b = """set([x for x in y for a in b])""" + a = """{x for x in y for a in b}""" + self.check(b, a) + + b = """set([f(x) - 23 for x in y])""" + a = """{f(x) - 23 for x in y}""" + self.check(b, a) + + def test_whitespace(self): + b = """set( [1, 2])""" + a = """{1, 2}""" + self.check(b, a) + + b = """set([1 , 2])""" + a = """{1 , 2}""" + self.check(b, a) + + b = """set([ 1 ])""" + a = """{ 1 }""" + self.check(b, a) + + b = """set( [1] )""" + a = """{1}""" + self.check(b, a) + + b = """set([ 1, 2 ])""" + a = """{ 1, 2 }""" + self.check(b, a) + + b = """set([x for x in y ])""" + a = """{x for x in y }""" + self.check(b, a) + + b = """set( + [1, 2] + ) + """ + a = """{1, 2}\n""" + self.check(b, a) + + def test_comments(self): + b = """set((1, 2)) # Hi""" + a = """{1, 2} # Hi""" + self.check(b, a) + + # This isn't optimal behavior, but the fixer is optional. + b = """ + # Foo + set( # Bar + (1, 2) + ) + """ + a = """ + # Foo + {1, 2} + """ + self.check(b, a) + + def test_unchanged(self): + s = """set()""" + self.unchanged(s) + + s = """set(a)""" + self.unchanged(s) + + s = """set(a, b, c)""" + self.unchanged(s) + + # Don't transform generators because they might have to be lazy. + s = """set(x for x in y)""" + self.unchanged(s) + + s = """set(x for x in y if z)""" + self.unchanged(s) + + s = """set(a*823-23**2 + f(23))""" + self.unchanged(s) + + class Test_sys_exc(FixerTestCase): fixer = "sys_exc" Modified: python/branches/py3k/Lib/lib2to3/tests/test_pytree.py ============================================================================== --- python/branches/py3k/Lib/lib2to3/tests/test_pytree.py (original) +++ python/branches/py3k/Lib/lib2to3/tests/test_pytree.py Sun Oct 19 16:07:49 2008 @@ -353,29 +353,29 @@ # Build a pattern matching a leaf pl = pytree.LeafPattern(100, "foo", name="pl") r = {} - self.assertEqual(pl.match(root, results=r), False) + self.assertFalse(pl.match(root, results=r)) self.assertEqual(r, {}) - self.assertEqual(pl.match(n1, results=r), False) + self.assertFalse(pl.match(n1, results=r)) self.assertEqual(r, {}) - self.assertEqual(pl.match(n2, results=r), False) + self.assertFalse(pl.match(n2, results=r)) self.assertEqual(r, {}) - self.assertEqual(pl.match(l1, results=r), True) + self.assertTrue(pl.match(l1, results=r)) self.assertEqual(r, {"pl": l1}) r = {} - self.assertEqual(pl.match(l2, results=r), False) + self.assertFalse(pl.match(l2, results=r)) self.assertEqual(r, {}) # Build a pattern matching a node pn = pytree.NodePattern(1000, [pl], name="pn") - self.assertEqual(pn.match(root, results=r), False) + self.assertFalse(pn.match(root, results=r)) self.assertEqual(r, {}) - self.assertEqual(pn.match(n1, results=r), False) + self.assertFalse(pn.match(n1, results=r)) self.assertEqual(r, {}) - self.assertEqual(pn.match(n2, results=r), True) + self.assertTrue(pn.match(n2, results=r)) self.assertEqual(r, {"pn": n2, "pl": l3}) r = {} - self.assertEqual(pn.match(l1, results=r), False) + self.assertFalse(pn.match(l1, results=r)) self.assertEqual(r, {}) - self.assertEqual(pn.match(l2, results=r), False) + self.assertFalse(pn.match(l2, results=r)) self.assertEqual(r, {}) def testWildcardPatterns(self): @@ -391,11 +391,11 @@ pn = pytree.NodePattern(1000, [pl], name="pn") pw = pytree.WildcardPattern([[pn], [pl, pl]], name="pw") r = {} - self.assertEqual(pw.match_seq([root], r), False) + self.assertFalse(pw.match_seq([root], r)) self.assertEqual(r, {}) - self.assertEqual(pw.match_seq([n1], r), False) + self.assertFalse(pw.match_seq([n1], r)) self.assertEqual(r, {}) - self.assertEqual(pw.match_seq([n2], r), True) + self.assertTrue(pw.match_seq([n2], r)) # These are easier to debug self.assertEqual(sorted(r.keys()), ["pl", "pn", "pw"]) self.assertEqual(r["pl"], l1) @@ -404,7 +404,7 @@ # But this is equivalent self.assertEqual(r, {"pl": l1, "pn": n2, "pw": [n2]}) r = {} - self.assertEqual(pw.match_seq([l1, l3], r), True) + self.assertTrue(pw.match_seq([l1, l3], r)) self.assertEqual(r, {"pl": l3, "pw": [l1, l3]}) self.assert_(r["pl"] is l3) r = {} 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 Sun Oct 19 16:07:49 2008 @@ -123,7 +123,6 @@ def test_refactor_file(self): test_file = os.path.join(FIXER_DIR, "parrot_example.py") - backup = test_file + ".bak" old_contents = open(test_file, "r").read() rt = self.rt() @@ -133,14 +132,8 @@ rt.refactor_file(test_file, True) try: self.assertNotEqual(old_contents, open(test_file, "r").read()) - self.assertTrue(os.path.exists(backup)) - self.assertEqual(old_contents, open(backup, "r").read()) finally: open(test_file, "w").write(old_contents) - try: - os.unlink(backup) - except OSError: - pass def test_refactor_docstring(self): rt = self.rt() Modified: python/branches/py3k/Modules/_testcapimodule.c ============================================================================== --- python/branches/py3k/Modules/_testcapimodule.c (original) +++ python/branches/py3k/Modules/_testcapimodule.c Sun Oct 19 16:07:49 2008 @@ -518,6 +518,10 @@ Py_UNICODE *value; Py_ssize_t len; + /* issue4122: Undefined reference to _Py_ascii_whitespace on Windows */ + /* Just use the macro and check that it compiles */ + int x = Py_UNICODE_ISSPACE(25); + tuple = PyTuple_New(1); if (tuple == NULL) return NULL; Modified: python/branches/py3k/Modules/posixmodule.c ============================================================================== --- python/branches/py3k/Modules/posixmodule.c (original) +++ python/branches/py3k/Modules/posixmodule.c Sun Oct 19 16:07:49 2008 @@ -499,10 +499,6 @@ return PyErr_SetFromWindowsErr(errno); } -static PyObject *_PyUnicode_FromFileSystemEncodedObject(register PyObject *obj) -{ -} - static int convert_to_unicode(PyObject **param) { @@ -713,7 +709,7 @@ chdir is essentially a wrapper around SetCurrentDirectory; however, it also needs to set "magic" environment variables indicating the per-drive current directory, which are of the form =: */ -BOOL __stdcall +static BOOL __stdcall win32_chdir(LPCSTR path) { char new_path[MAX_PATH+1]; @@ -738,7 +734,7 @@ /* The Unicode version differs from the ANSI version since the current directory might exceed MAX_PATH characters */ -BOOL __stdcall +static BOOL __stdcall win32_wchdir(LPCWSTR path) { wchar_t _new_path[MAX_PATH+1], *new_path = _new_path; Modified: python/branches/py3k/Parser/asdl_c.py ============================================================================== --- python/branches/py3k/Parser/asdl_c.py (original) +++ python/branches/py3k/Parser/asdl_c.py Sun Oct 19 16:07:49 2008 @@ -804,12 +804,30 @@ return 0; } +static int add_ast_fields() +{ + PyObject *empty_tuple, *d; + if (PyType_Ready(&AST_type) < 0) + return -1; + d = AST_type.tp_dict; + empty_tuple = PyTuple_New(0); + if (!empty_tuple || + PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || + PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { + Py_XDECREF(empty_tuple); + return -1; + } + Py_DECREF(empty_tuple); + return 0; +} + """, 0, reflow=False) self.emit("static int init_types(void)",0) self.emit("{", 0) self.emit("static int initialized;", 1) self.emit("if (initialized) return 1;", 1) + self.emit("if (add_ast_fields() < 0) return 0;", 1) for dfn in mod.dfns: self.visit(dfn) self.emit("initialized = 1;", 1) Modified: python/branches/py3k/Tools/scripts/reindent.py ============================================================================== --- python/branches/py3k/Tools/scripts/reindent.py (original) +++ python/branches/py3k/Tools/scripts/reindent.py Sun Oct 19 16:07:49 2008 @@ -99,7 +99,8 @@ for name in names: fullname = os.path.join(file, name) if ((recurse and os.path.isdir(fullname) and - not os.path.islink(fullname)) + not os.path.islink(fullname) and + not os.path.split(fullname)[1].startswith(".")) or name.lower().endswith(".py")): check(fullname) return From python-3000-checkins at python.org Sun Oct 19 16:15:01 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 19 Oct 2008 16:15:01 +0200 (CEST) Subject: [Python-3000-checkins] r66976 - in python/branches/py3k: Misc/NEWS Modules/python.c Message-ID: <20081019141501.42E3D1E4002@bag.python.org> Author: benjamin.peterson Date: Sun Oct 19 16:15:00 2008 New Revision: 66976 Log: restore compilation on OpenBSD #4146 Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/python.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Sun Oct 19 16:15:00 2008 @@ -15,6 +15,8 @@ Core and Builtins ----------------- +- Issue #4146: Compilation on OpenBSD has been restored. + - Issue #3574: compile() incorrectly handled source code encoded as Latin-1. - Issues #2384 and #3975: Tracebacks were not correctly printed when the Modified: python/branches/py3k/Modules/python.c ============================================================================== --- python/branches/py3k/Modules/python.c (original) +++ python/branches/py3k/Modules/python.c Sun Oct 19 16:15:00 2008 @@ -17,9 +17,9 @@ int main(int argc, char **argv) { - wchar_t **argv_copy = PyMem_Malloc(sizeof(wchar_t*)*argc); + wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); /* We need a second copies, as Python might modify the first one. */ - wchar_t **argv_copy2 = PyMem_Malloc(sizeof(wchar_t*)*argc); + wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); int i, res; char *oldloc; /* 754 requires that FP exceptions run in "no stop" mode by default, @@ -54,7 +54,7 @@ fprintf(stderr, "Could not convert argument %d to string\n", i); return 1; } - argv_copy[i] = PyMem_Malloc((argsize+1)*sizeof(wchar_t)); + argv_copy[i] = (wchar_t *)PyMem_Malloc((argsize+1)*sizeof(wchar_t)); argv_copy2[i] = argv_copy[i]; if (!argv_copy[i]) { fprintf(stderr, "out of memory\n"); From python-3000-checkins at python.org Sun Oct 19 23:29:05 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 19 Oct 2008 23:29:05 +0200 (CEST) Subject: [Python-3000-checkins] r66978 - python/branches/py3k/Doc/reference/datamodel.rst Message-ID: <20081019212905.AFD6A1E4002@bag.python.org> Author: benjamin.peterson Date: Sun Oct 19 23:29:05 2008 New Revision: 66978 Log: document changes to metaclasses Modified: python/branches/py3k/Doc/reference/datamodel.rst Modified: python/branches/py3k/Doc/reference/datamodel.rst ============================================================================== --- python/branches/py3k/Doc/reference/datamodel.rst (original) +++ python/branches/py3k/Doc/reference/datamodel.rst Sun Oct 19 23:29:05 2008 @@ -1484,10 +1484,11 @@ read into a separate namespace and the value of class name is bound to the result of ``type(name, bases, dict)``. -When the class definition is read, if *__metaclass__* is defined then the -callable assigned to it will be called instead of :func:`type`. This allows -classes or functions to be written which monitor or alter the class creation -process: +When the class definition is read, if a callable ``metaclass`` keyword argument +is passed after the bases in the class definition, the callable given will be +called instead of :func:`type`. If other keyword arguments are passed, they +will also be passed to the metaclass. This allows classes or functions to be +written which monitor or alter the class creation process: * Modifying the class dictionary prior to the class being created. @@ -1508,21 +1509,19 @@ example defining a custom :meth:`__call__` method in the metaclass allows custom behavior when the class is called, e.g. not always creating a new instance. - -.. data:: __metaclass__ - - This variable can be any callable accepting arguments for ``name``, ``bases``, - and ``dict``. Upon class creation, the callable is used instead of the built-in - :func:`type`. +If the metaclass has a :meth:`__prepare__` attribute (usually implemented as a +class or static method), it is called before the class body is evaluated with +the name of the class and a tuple of its bases for arguments. It should return +an object that supports the mapping interface that will be used to store the +namespace of the class. The default is a plain dictionary. This could be used, +for example, to keep track of the order that class attributes are declared in by +returning an ordered dictionary. The appropriate metaclass is determined by the following precedence rules: -* If ``dict['__metaclass__']`` exists, it is used. +* If the ``metaclass`` keyword argument is based with the bases, it is used. -* Otherwise, if there is at least one base class, its metaclass is used (this - looks for a *__class__* attribute first and if not found, uses its type). - -* Otherwise, if a global variable named __metaclass__ exists, it is used. +* Otherwise, if there is at least one base class, its metaclass is used. * Otherwise, the default metaclass (:class:`type`) is used. @@ -1922,8 +1921,7 @@ ... print "Metaclass getattribute invoked" ... return type.__getattribute__(*args) ... - >>> class C(object): - ... __metaclass__ = Meta + >>> class C(object, metaclass=Meta): ... def __len__(self): ... return 10 ... def __getattribute__(*args): From python-3000-checkins at python.org Mon Oct 20 23:04:06 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Mon, 20 Oct 2008 23:04:06 +0200 (CEST) Subject: [Python-3000-checkins] r66983 - python/branches/py3k/Doc/extending/extending.rst Message-ID: <20081020210406.AA8161E4002@bag.python.org> Author: benjamin.peterson Date: Mon Oct 20 23:04:06 2008 New Revision: 66983 Log: make struct static Modified: python/branches/py3k/Doc/extending/extending.rst Modified: python/branches/py3k/Doc/extending/extending.rst ============================================================================== --- python/branches/py3k/Doc/extending/extending.rst (original) +++ python/branches/py3k/Doc/extending/extending.rst Mon Oct 20 23:04:06 2008 @@ -300,13 +300,13 @@ The :const:`METH_KEYWORDS` bit may be set in the third field if keyword arguments should be passed to the function. In this case, the C function should -accept a third ``PyObject *`` parameter which will be a dictionary of keywords. +accept a third ``PyObject \*`` parameter which will be a dictionary of keywords. Use :cfunc:`PyArg_ParseTupleAndKeywords` to parse the arguments to such a function. The method table must be referenced in the module definition structure:: - struct PyModuleDef spammodule = { + static struct PyModuleDef spammodule = { PyModuleDef_HEAD_INIT, "spam", /* name of module */ spam_doc, /* module documentation, may be NULL */ From python-3000-checkins at python.org Tue Oct 21 23:10:07 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Tue, 21 Oct 2008 23:10:07 +0200 (CEST) Subject: [Python-3000-checkins] r66993 - python/branches/py3k/Doc/c-api/arg.rst Message-ID: <20081021211007.E43631E4034@bag.python.org> Author: benjamin.peterson Date: Tue Oct 21 23:10:07 2008 New Revision: 66993 Log: document 'y(#)' format codes for Py_BuildValue Modified: python/branches/py3k/Doc/c-api/arg.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 Tue Oct 21 23:10:07 2008 @@ -424,6 +424,14 @@ Convert a C string and its length to a Python object. If the C string pointer is *NULL*, the length is ignored and ``None`` is returned. + ``y`` (bytes) [char \*, int] + This converts a C string to a Python :func:`bytes` object. If the C + string pointer is *NULL*, ``None`` is returned. + + ``y#`` (bytes) [char \*, int] + This converts a C string and its lengths to a Python object. If the C + string pointer is *NULL*, ``None`` is returned. + ``z`` (string or ``None``) [char \*] Same as ``s``. From python-3000-checkins at python.org Thu Oct 23 02:38:16 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Thu, 23 Oct 2008 02:38:16 +0200 (CEST) Subject: [Python-3000-checkins] r67003 - in python/branches/py3k/Lib/test: test_bytes.py test_range.py Message-ID: <20081023003816.4574A1E4002@bag.python.org> Author: hirokazu.yamamoto Date: Thu Oct 23 02:38:15 2008 New Revision: 67003 Log: Issue #4183: Some tests didn't run with pickle.HIGHEST_PROTOCOL. Modified: python/branches/py3k/Lib/test/test_bytes.py python/branches/py3k/Lib/test/test_range.py 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 Thu Oct 23 02:38:15 2008 @@ -397,7 +397,7 @@ self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b'')) def test_pickling(self): - for proto in range(pickle.HIGHEST_PROTOCOL): + for proto in range(pickle.HIGHEST_PROTOCOL + 1): for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0": b = self.type2test(b) ps = pickle.dumps(b, proto) @@ -979,7 +979,7 @@ a = ByteArraySubclass(b"abcd") a.x = 10 a.y = ByteArraySubclass(b"efgh") - for proto in range(pickle.HIGHEST_PROTOCOL): + for proto in range(pickle.HIGHEST_PROTOCOL + 1): b = pickle.loads(pickle.dumps(a, proto)) self.assertNotEqual(id(a), id(b)) self.assertEqual(a, b) Modified: python/branches/py3k/Lib/test/test_range.py ============================================================================== --- python/branches/py3k/Lib/test/test_range.py (original) +++ python/branches/py3k/Lib/test/test_range.py Thu Oct 23 02:38:15 2008 @@ -65,7 +65,7 @@ def test_pickling(self): testcases = [(13,), (0, 11), (-22, 10), (20, 3, -1), (13, 21, 3), (-2, 2, 2)] - for proto in range(pickle.HIGHEST_PROTOCOL): + for proto in range(pickle.HIGHEST_PROTOCOL + 1): for t in testcases: r = range(*t) self.assertEquals(list(pickle.loads(pickle.dumps(r, proto))), From python-3000-checkins at python.org Thu Oct 23 02:51:26 2008 From: python-3000-checkins at python.org (hirokazu.yamamoto) Date: Thu, 23 Oct 2008 02:51:26 +0200 (CEST) Subject: [Python-3000-checkins] r67004 - python/branches/py3k Message-ID: <20081023005126.8DC9F1E4002@bag.python.org> Author: hirokazu.yamamoto Date: Thu Oct 23 02:51:26 2008 New Revision: 67004 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/ (props changed) From python-3000-checkins at python.org Thu Oct 23 15:21:33 2008 From: python-3000-checkins at python.org (walter.doerwald) Date: Thu, 23 Oct 2008 15:21:33 +0200 (CEST) Subject: [Python-3000-checkins] r67006 - in python/branches/py3k: Doc/library/codecs.rst Message-ID: <20081023132133.DFC791E403A@bag.python.org> Author: walter.doerwald Date: Thu Oct 23 15:21:33 2008 New Revision: 67006 Log: Merged revisions 67005 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67005 | walter.doerwald | 2008-10-23 15:11:39 +0200 (Do, 23 Okt 2008) | 2 lines Use the correct names of the stateless codec functions (Fixes issue 4178). ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/codecs.rst Modified: python/branches/py3k/Doc/library/codecs.rst ============================================================================== --- python/branches/py3k/Doc/library/codecs.rst (original) +++ python/branches/py3k/Doc/library/codecs.rst Thu Oct 23 15:21:33 2008 @@ -32,9 +32,9 @@ * ``name`` The name of the encoding; - * ``encoder`` The stateless encoding function; + * ``encode`` The stateless encoding function; - * ``decoder`` The stateless decoding function; + * ``decode`` The stateless decoding function; * ``incrementalencoder`` An incremental encoder class or factory function; @@ -46,7 +46,7 @@ The various functions or classes take the following arguments: - *encoder* and *decoder*: These must be functions or methods which have the same + *encode* and *decode*: These must be functions or methods which have the same interface as the :meth:`encode`/:meth:`decode` methods of Codec instances (see Codec Interface). The functions/methods are expected to work in a stateless mode. From python-3000-checkins at python.org Fri Oct 24 03:32:41 2008 From: python-3000-checkins at python.org (alexandre.vassalotti) Date: Fri, 24 Oct 2008 03:32:41 +0200 (CEST) Subject: [Python-3000-checkins] r67008 - in python/branches/py3k/Doc: includes/dbpickle.py library/pickle.rst Message-ID: <20081024013241.686C71E4002@bag.python.org> Author: alexandre.vassalotti Date: Fri Oct 24 03:32:40 2008 New Revision: 67008 Log: More improvements to pickle's documentation. Add "Restricting Globals" section. Remove useless 'verbose' flag in the example dbpickle.py. Modified: python/branches/py3k/Doc/includes/dbpickle.py python/branches/py3k/Doc/library/pickle.rst Modified: python/branches/py3k/Doc/includes/dbpickle.py ============================================================================== --- python/branches/py3k/Doc/includes/dbpickle.py (original) +++ python/branches/py3k/Doc/includes/dbpickle.py Fri Oct 24 03:32:40 2008 @@ -46,7 +46,7 @@ raise pickle.UnpicklingError("unsupported persistent object") -def main(verbose=True): +def main(): import io, pprint # Initialize and populate our database. @@ -68,20 +68,18 @@ file = io.BytesIO() DBPickler(file).dump(memos) - if verbose: - print("Records to be pickled:") - pprint.pprint(memos) + print("Pickled records:") + pprint.pprint(memos) # Update a record, just for good measure. cursor.execute("UPDATE memos SET task='learn italian' WHERE key=1") - # Load the reports from the pickle data stream. + # Load the records from the pickle data stream. file.seek(0) memos = DBUnpickler(file, conn).load() - if verbose: - print("Unpickled records:") - pprint.pprint(memos) + print("Unpickled records:") + pprint.pprint(memos) if __name__ == '__main__': Modified: python/branches/py3k/Doc/library/pickle.rst ============================================================================== --- python/branches/py3k/Doc/library/pickle.rst (original) +++ python/branches/py3k/Doc/library/pickle.rst Fri Oct 24 03:32:40 2008 @@ -111,15 +111,17 @@ bytes and cannot be unpickled by Python 2.x pickle modules. This is the current recommended protocol, use it whenever it is possible. -Refer to :pep:`307` for more information. +Refer to :pep:`307` for information about improvements brought by +protocol 2. See :mod:`pickletools`'s source code for extensive +comments about opcodes used by pickle protocols. If a *protocol* is not specified, protocol 3 is used. If *protocol* is specified as a negative value or :const:`HIGHEST_PROTOCOL`, the highest protocol version available will be used. -Usage ------ +Module Interface +---------------- To serialize an object hierarchy, you first create a pickler, then you call the pickler's :meth:`dump` method. To de-serialize a data stream, you first create @@ -347,10 +349,13 @@ .. method:: find_class(module, name) Import *module* if necessary and return the object called *name* from it, - where the *module* and *name* arguments are :class:`str` objects. + where the *module* and *name* arguments are :class:`str` objects. Note, + unlike its name suggests, :meth:`find_class` is also used for finding + functions. Subclasses may override this to gain control over what type of objects and - how they can be loaded, potentially reducing security risks. + how they can be loaded, potentially reducing security risks. Refer to + :ref:`pickle-restrict` for details. .. _pickle-picklable: @@ -424,7 +429,7 @@ your objects are serialized and de-serialized. The description in this section doesn't cover specific customizations that you can employ to make the unpickling environment slightly safer from untrusted pickle data streams; see section -:ref:`pickle-sub` for more details. +:ref:`pickle-restrict` for more details. .. _pickle-inst: @@ -600,41 +605,85 @@ Example: +.. XXX Work around for some bug in sphinx/pygments. .. highlightlang:: python .. literalinclude:: ../includes/dbpickle.py +.. highlightlang:: python3 +.. _pickle-restrict: -.. _pickle-sub: - -Subclassing Unpicklers ----------------------- +Restricting Globals +^^^^^^^^^^^^^^^^^^^ .. index:: - single: load_global() (pickle protocol) - single: find_global() (pickle protocol) + single: find_class() (pickle protocol) + +By default, unpickling will import any class or function that it finds in the +pickle data. For many applications, this behaviour is unacceptable as it +permits the unpickler to import and invoke arbitrary code. Just consider what +this hand-crafted pickle data stream does when loaded:: + + >>> import pickle + >>> pickle.loads(b"cos\nsystem\n(S'echo hello world'\ntR.") + hello world + 0 + +In this example, the unpickler imports the :func:`os.system` function and then +apply the string argument "echo hello world". Although this example is +inoffensive, it is not difficult to imagine one that could damage your system. + +For this reason, you may want to control what gets unpickled by customizing +:meth:`Unpickler.find_class`. Unlike its name suggests, :meth:`find_class` is +called whenever a global (i.e., a class or a function) is requested. Thus it is +possible to either forbid completely globals or restrict them to a safe subset. -By default, unpickling will import any class that it finds in the pickle data. -You can control exactly what gets unpickled and what gets called by customizing -your unpickler. - -You need to derive a subclass from :class:`Unpickler`, overriding the -:meth:`load_global` method. :meth:`load_global` should read two lines from the -pickle data stream where the first line will the name of the module containing -the class and the second line will be the name of the instance's class. It then -looks up the class, possibly importing the module and digging out the attribute, -then it appends what it finds to the unpickler's stack. Later on, this class -will be assigned to the :attr:`__class__` attribute of an empty class, as a way -of magically creating an instance without calling its class's -:meth:`__init__`. Your job (should you choose to accept it), would be to have -:meth:`load_global` push onto the unpickler's stack, a known safe version of any -class you deem safe to unpickle. It is up to you to produce such a class. Or -you could raise an error if you want to disallow all unpickling of instances. -If this sounds like a hack, you're right. Refer to the source code to make this -work. +Here is an example of an unpickler allowing only few safe classes from the +:mod:`builtins` module to be loaded:: -The moral of the story is that you should be really careful about the source of -the strings your application unpickles. + import builtins + import io + import pickle + safe_builtins = { + 'range', + 'complex', + 'set', + 'frozenset', + 'slice', + } + + class RestrictedUnpickler(pickle.Unpickler): + def find_class(self, module, name): + # Only allow safe classes from builtins. + if module == "builtins" and name in safe_builtins: + return getattr(builtins, name) + # Forbid everything else. + raise pickle.UnpicklingError("global '%s.%s' is forbidden" % + (module, name)) + + def restricted_loads(s): + """Helper function analogous to pickle.loads().""" + return RestrictedUnpickler(io.BytesIO(s)).load() + +A sample usage of our unpickler working has intended:: + + >>> restricted_loads(pickle.dumps([1, 2, range(15)])) + [1, 2, range(0, 15)] + >>> restricted_loads(b"cos\nsystem\n(S'echo hello world'\ntR.") + Traceback (most recent call last): + ... + pickle.UnpicklingError: global 'os.system' is forbidden + >>> restricted_loads(b'cbuiltins\neval\n' + ... b'(S\'getattr(__import__("os"), "system")' + ... b'("echo hello world")\'\ntR.') + Traceback (most recent call last): + ... + pickle.UnpicklingError: global 'builtins.eval' is forbidden + +As our examples shows, you have to be careful with what you allow to +be unpickled. Therefore if security is a concern, you may want to consider +alternatives such as the marshalling API in :mod:`xmlrpc.client` or +third-party solutions. .. _pickle-example: @@ -769,7 +818,7 @@ .. [#] This protocol is also used by the shallow and deep copying operations defined in the :mod:`copy` module. -.. [#] The limitation on alphanumeric characters is due to the fact the - persistent IDs, in protocol 0, are delimited by the newline character. - Therefore if any kind of newline characters, such as \r and \n, occurs in +.. [#] The limitation on alphanumeric characters is due to the fact + the persistent IDs, in protocol 0, are delimited by the newline + character. Therefore if any kind of newline characters occurs in persistent IDs, the resulting pickle will become unreadable. From python-3000-checkins at python.org Sat Oct 25 00:16:39 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 25 Oct 2008 00:16:39 +0200 (CEST) Subject: [Python-3000-checkins] r67010 - python/branches/py3k/Lib/test/test_grammar.py Message-ID: <20081024221639.78B441E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 25 00:16:39 2008 New Revision: 67010 Log: add grammar tests for nonlocal Modified: python/branches/py3k/Lib/test/test_grammar.py Modified: python/branches/py3k/Lib/test/test_grammar.py ============================================================================== --- python/branches/py3k/Lib/test/test_grammar.py (original) +++ python/branches/py3k/Lib/test/test_grammar.py Sat Oct 25 00:16:39 2008 @@ -485,6 +485,14 @@ global a, b global one, two, three, four, five, six, seven, eight, nine, ten + def testNonlocal(self): + # 'nonlocal' NAME (',' NAME)* + x = 0 + y = 0 + def f(): + nonlocal x + nonlocal x, y + def testAssert(self): # assert_stmt: 'assert' test [',' test] assert 1 From python-3000-checkins at python.org Sat Oct 25 00:28:58 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 25 Oct 2008 00:28:58 +0200 (CEST) Subject: [Python-3000-checkins] r67011 - in python/branches/py3k/Doc/library: itertools.rst multiprocessing.rst Message-ID: <20081024222858.542C01E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 25 00:28:58 2008 New Revision: 67011 Log: fix some py3k doc nits Modified: python/branches/py3k/Doc/library/itertools.rst python/branches/py3k/Doc/library/multiprocessing.rst Modified: python/branches/py3k/Doc/library/itertools.rst ============================================================================== --- python/branches/py3k/Doc/library/itertools.rst (original) +++ python/branches/py3k/Doc/library/itertools.rst Sat Oct 25 00:28:58 2008 @@ -295,10 +295,10 @@ except IndexError: pass - If one of the iterables is potentially infinite, then the - :func:`izip_longest` function should be wrapped with something that limits - the number of calls (for example :func:`islice` or :func:`takewhile`). If - not specified, *fillvalue* defaults to ``None``. + If one of the iterables is potentially infinite, then the :func:`zip_longest` + function should be wrapped with something that limits the number of calls + (for example :func:`islice` or :func:`takewhile`). If not specified, + *fillvalue* defaults to ``None``. .. function:: permutations(iterable[, r]) @@ -590,7 +590,7 @@ def compress(data, selectors): "compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F" - return (d for d, s in izip(data, selectors) if s) + return (d for d, s in zip(data, selectors) if s) def combinations_with_replacement(iterable, r): "combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC" Modified: python/branches/py3k/Doc/library/multiprocessing.rst ============================================================================== --- python/branches/py3k/Doc/library/multiprocessing.rst (original) +++ python/branches/py3k/Doc/library/multiprocessing.rst Sat Oct 25 00:28:58 2008 @@ -1433,8 +1433,8 @@ .. method:: apply(func[, args[, kwds]]) - Equivalent of the :func:`apply` builtin function. It blocks till the - result is ready. + Call *func* with arguments *args* and keyword arguments *kwds*. It blocks + till the result is ready. .. method:: apply_async(func[, args[, kwds[, callback]]]) @@ -1465,7 +1465,7 @@ .. method:: imap(func, iterable[, chunksize]) - An equivalent of :func:`itertools.imap`. + An 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 From python-3000-checkins at python.org Sat Oct 25 01:11:02 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 25 Oct 2008 01:11:02 +0200 (CEST) Subject: [Python-3000-checkins] r67012 - python/branches/py3k/Python/Python-ast.c Message-ID: <20081024231102.919321E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 25 01:11:02 2008 New Revision: 67012 Log: update Python-ast.c Modified: python/branches/py3k/Python/Python-ast.c Modified: python/branches/py3k/Python/Python-ast.c ============================================================================== --- python/branches/py3k/Python/Python-ast.c (original) +++ python/branches/py3k/Python/Python-ast.c Sat Oct 25 01:11:02 2008 @@ -621,11 +621,29 @@ return 0; } +static int add_ast_fields() +{ + PyObject *empty_tuple, *d; + if (PyType_Ready(&AST_type) < 0) + return -1; + d = AST_type.tp_dict; + empty_tuple = PyTuple_New(0); + if (!empty_tuple || + PyDict_SetItemString(d, "_fields", empty_tuple) < 0 || + PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) { + Py_XDECREF(empty_tuple); + return -1; + } + Py_DECREF(empty_tuple); + return 0; +} + static int init_types(void) { static int initialized; if (initialized) return 1; + if (add_ast_fields() < 0) return 0; mod_type = make_type("mod", &AST_type, NULL, 0); if (!mod_type) return 0; if (!add_attributes(mod_type, NULL, 0)) return 0; From python-3000-checkins at python.org Sat Oct 25 04:56:18 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 25 Oct 2008 04:56:18 +0200 (CEST) Subject: [Python-3000-checkins] r67014 - python/branches/py3k Message-ID: <20081025025618.5A3DD1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 25 04:56:18 2008 New Revision: 67014 Log: Blocked revisions 67013 via svnmerge ........ r67013 | benjamin.peterson | 2008-10-24 21:53:28 -0500 (Fri, 24 Oct 2008) | 1 line give a py3k warning when 'nonlocal' is used as a variable name ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Sat Oct 25 17:49:18 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sat, 25 Oct 2008 17:49:18 +0200 (CEST) Subject: [Python-3000-checkins] r67018 - in python/branches/py3k: Doc/library/2to3.rst Doc/reference/datamodel.rst Lib/ast.py Lib/bdb.py Lib/inspect.py Lib/pdb.py Lib/platform.py Lib/test/test_platform.py Lib/test/test_urllib.py Makefile.pre.in Parser/asdl_c.py Python/Python-ast.c Message-ID: <20081025154918.D70BB1E4002@bag.python.org> Author: benjamin.peterson Date: Sat Oct 25 17:49:17 2008 New Revision: 67018 Log: Merged revisions 66974,66977,66984,66989,66992,66994-66996,66998-67000,67007,67015 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r66974 | benjamin.peterson | 2008-10-19 08:59:01 -0500 (Sun, 19 Oct 2008) | 1 line fix compiler warning ........ r66977 | benjamin.peterson | 2008-10-19 14:39:16 -0500 (Sun, 19 Oct 2008) | 1 line mention -n ........ r66984 | armin.ronacher | 2008-10-20 16:29:08 -0500 (Mon, 20 Oct 2008) | 3 lines Fixed #4062, added import for _ast.__version__ to ast to match the documented behavior. ........ r66989 | matthias.klose | 2008-10-21 04:12:25 -0500 (Tue, 21 Oct 2008) | 2 lines - install versioned manpage ........ r66992 | benjamin.peterson | 2008-10-21 15:51:13 -0500 (Tue, 21 Oct 2008) | 1 line make sure to call iteritems() ........ r66994 | amaury.forgeotdarc | 2008-10-21 17:01:38 -0500 (Tue, 21 Oct 2008) | 6 lines #4157 move two test functions out of platform.py. Turn them into unit tests, and correct an obvious typo: (("a", "b") ("c", "d") ("e", "f")) compiles even with the missing commas, but does not execute very well... ........ r66995 | benjamin.peterson | 2008-10-21 17:18:29 -0500 (Tue, 21 Oct 2008) | 1 line return ArgInfo from inspect.getargvalues #4092 ........ r66996 | benjamin.peterson | 2008-10-21 17:20:31 -0500 (Tue, 21 Oct 2008) | 1 line add NEWs note for last change ........ r66998 | benjamin.peterson | 2008-10-22 15:57:43 -0500 (Wed, 22 Oct 2008) | 1 line fix a few typos ........ r66999 | benjamin.peterson | 2008-10-22 16:05:30 -0500 (Wed, 22 Oct 2008) | 1 line and another typo... ........ r67000 | benjamin.peterson | 2008-10-22 16:16:34 -0500 (Wed, 22 Oct 2008) | 1 line fix #4150: pdb's up command didn't work for generators in post-mortem ........ r67007 | benjamin.peterson | 2008-10-23 16:43:48 -0500 (Thu, 23 Oct 2008) | 1 line only nonempty __slots__ don't work ........ r67015 | georg.brandl | 2008-10-25 02:00:52 -0500 (Sat, 25 Oct 2008) | 2 lines Typo fix. ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Doc/library/2to3.rst python/branches/py3k/Doc/reference/datamodel.rst python/branches/py3k/Lib/ast.py python/branches/py3k/Lib/bdb.py python/branches/py3k/Lib/inspect.py python/branches/py3k/Lib/pdb.py python/branches/py3k/Lib/platform.py python/branches/py3k/Lib/test/test_platform.py python/branches/py3k/Lib/test/test_urllib.py python/branches/py3k/Makefile.pre.in python/branches/py3k/Parser/asdl_c.py python/branches/py3k/Python/Python-ast.c Modified: python/branches/py3k/Doc/library/2to3.rst ============================================================================== --- python/branches/py3k/Doc/library/2to3.rst (original) +++ python/branches/py3k/Doc/library/2to3.rst Sat Oct 25 17:49:17 2008 @@ -37,8 +37,8 @@ A diff against the original source file is printed. 2to3 can also write the needed modifications right back to the source file. (Of course, a backup of the -original is also be made.) Writing the changes back is enabled with the -:option:`-w` flag:: +original is also be made unless :option:`-n` is also given.) Writing the +changes back is enabled with the :option:`-w` flag:: $ 2to3 -w example.py @@ -50,11 +50,10 @@ name = input() greet(name) -Comments and and exact indentation are preserved throughout the translation -process. +Comments and exact indentation are preserved throughout the translation process. By default, 2to3 runs a set of predefined fixers. The :option:`-l` flag lists -all avaible fixers. An explicit set of fixers to run can be given with +all available fixers. An explicit set of fixers to run can be given with :option:`-f`. Likewise the :option:`-x` explicitly disables a fixer. The following example runs only the ``imports`` and ``has_key`` fixers:: @@ -64,7 +63,7 @@ $ 2to3 -x apply example.py -Some fixers are *explicit*, meaning they aren't run be default and must be +Some fixers are *explicit*, meaning they aren't run by default and must be listed on the command line to be run. Here, in addition to the default fixers, the ``idioms`` fixer is run:: @@ -72,10 +71,10 @@ Notice how passing ``all`` enables all default fixers. -Sometimes 2to3 will find will find a place in your source code that needs to be -changed, but 2to3 cannot fix automatically. In this case, 2to3 will print a -warning beneath the diff for a file. You should address the warning in order to -have compliant 3.x code. +Sometimes 2to3 will find a place in your source code that needs to be changed, +but 2to3 cannot fix automatically. In this case, 2to3 will print a warning +beneath the diff for a file. You should address the warning in order to have +compliant 3.x code. 2to3 can also refactor doctests. To enable this mode, use the :option:`-d` flag. Note that *only* doctests will be refactored. This also doesn't require @@ -89,7 +88,7 @@ a statement. This is useful when ``from __future__ import print_function`` is being used. If this option is not given, the print fixer will surround print calls in an extra set of parentheses because it cannot differentiate between the -and print statement with parentheses (such as ``print ("a" + "b" + "c")``) and a +print statement with parentheses (such as ``print ("a" + "b" + "c")``) and a true function call. Modified: python/branches/py3k/Doc/reference/datamodel.rst ============================================================================== --- python/branches/py3k/Doc/reference/datamodel.rst (original) +++ python/branches/py3k/Doc/reference/datamodel.rst Sat Oct 25 17:49:17 2008 @@ -1465,8 +1465,8 @@ defined. As a result, subclasses will have a *__dict__* unless they also define *__slots__*. -* *__slots__* do not work for classes derived from "variable-length" built-in - types such as :class:`int`, :class:`str` and :class:`tuple`. +* Nonempty *__slots__* does not work for classes derived from "variable-length" + built-in types such as :class:`int`, :class:`str` and :class:`tuple`. * Any non-string iterable may be assigned to *__slots__*. Mappings may also be used; however, in the future, special meaning may be assigned to the values Modified: python/branches/py3k/Lib/ast.py ============================================================================== --- python/branches/py3k/Lib/ast.py (original) +++ python/branches/py3k/Lib/ast.py Sat Oct 25 17:49:17 2008 @@ -26,6 +26,7 @@ :license: Python License. """ from _ast import * +from _ast import __version__ def parse(expr, filename='', mode='exec'): Modified: python/branches/py3k/Lib/bdb.py ============================================================================== --- python/branches/py3k/Lib/bdb.py (original) +++ python/branches/py3k/Lib/bdb.py Sat Oct 25 17:49:17 2008 @@ -319,6 +319,8 @@ while t is not None: stack.append((t.tb_frame, t.tb_lineno)) t = t.tb_next + if f is None: + i = max(0, len(stack) - 1) return stack, i # Modified: python/branches/py3k/Lib/inspect.py ============================================================================== --- python/branches/py3k/Lib/inspect.py (original) +++ python/branches/py3k/Lib/inspect.py Sat Oct 25 17:49:17 2008 @@ -826,7 +826,7 @@ 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'locals' is the locals dictionary of the given frame.""" args, varargs, varkw = getargs(frame.f_code) - return args, varargs, varkw, frame.f_locals + return ArgInfo(args, varargs, varkw, frame.f_locals) def joinseq(seq): if len(seq) == 1: Modified: python/branches/py3k/Lib/pdb.py ============================================================================== --- python/branches/py3k/Lib/pdb.py (original) +++ python/branches/py3k/Lib/pdb.py Sat Oct 25 17:49:17 2008 @@ -1220,9 +1220,7 @@ p = Pdb() p.reset() - while t.tb_next is not None: - t = t.tb_next - p.interaction(t.tb_frame, t) + p.interaction(None, t) def pm(): post_mortem(sys.last_traceback) @@ -1285,9 +1283,7 @@ print("Uncaught exception. Entering post mortem debugging") print("Running 'cont' or 'step' will restart the program") t = sys.exc_info()[2] - while t.tb_next is not None: - t = t.tb_next - pdb.interaction(t.tb_frame,t) + pdb.interaction(None, t) print("Post mortem debugger finished. The "+mainpyfile+" will be restarted") Modified: python/branches/py3k/Lib/platform.py ============================================================================== --- python/branches/py3k/Lib/platform.py (original) +++ python/branches/py3k/Lib/platform.py Sat Oct 25 17:49:17 2008 @@ -266,24 +266,6 @@ id = '' return '', version, id -def _test_parse_release_file(): - - for input, output in ( - # Examples of release file contents: - ('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')) - ('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')) - ('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')) - ('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')) - ('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')) - ('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')) - ('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')) - ('CentOS release 4', ('CentOS', '4', None)) - ('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')) - ): - parsed = _parse_release_file(input) - if parsed != output: - print((input, parsed)) - def linux_distribution(distname='', version='', id='', supported_dists=_supported_dists, @@ -1357,21 +1339,6 @@ _sys_version_cache[sys_version] = result return result -def _test_sys_version(): - - _sys_version_cache.clear() - for input, output in ( - ('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]', - ('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')), - ('IronPython 1.0.60816 on .NET 2.0.50727.42', - ('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')), - ('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42', - ('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')), - ): - parsed = _sys_version(input) - if parsed != output: - print((input, parsed)) - def python_implementation(): """ Returns a string identifying the Python implementation. Modified: python/branches/py3k/Lib/test/test_platform.py ============================================================================== --- python/branches/py3k/Lib/test/test_platform.py (original) +++ python/branches/py3k/Lib/test/test_platform.py Sat Oct 25 17:49:17 2008 @@ -115,6 +115,40 @@ executable = executable + '.exe' res = platform.libc_ver(sys.executable) + def test_parse_release_file(self): + + for input, output in ( + # Examples of release file contents: + ('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')), + ('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')), + ('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')), + ('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')), + ('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')), + ('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')), + ('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')), + ('CentOS release 4', ('CentOS', '4', None)), + ('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')), + ): + self.assertEqual(platform._parse_release_file(input), output) + + def test_sys_version(self): + + platform._sys_version_cache.clear() + for input, output in ( + ('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]', + ('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')), + ('IronPython 1.0.60816 on .NET 2.0.50727.42', + ('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')), + ('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42', + ('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')), + ): + # branch and revision are not "parsed", but fetched + # from sys.subversion. Ignore them + (name, version, branch, revision, buildno, builddate, compiler) \ + = platform._sys_version(input) + self.assertEqual( + (name, version, '', '', buildno, builddate, compiler), output) + def test_main(): support.run_unittest( PlatformTest Modified: python/branches/py3k/Lib/test/test_urllib.py ============================================================================== --- python/branches/py3k/Lib/test/test_urllib.py (original) +++ python/branches/py3k/Lib/test/test_urllib.py Sat Oct 25 17:49:17 2008 @@ -117,7 +117,6 @@ class ProxyTests(unittest.TestCase): def setUp(self): - unittest.TestCase.setUp(self) # Save all proxy related env vars self._saved_environ = dict([(k, v) for k, v in os.environ.items() if k.lower().find('proxy') >= 0]) @@ -126,9 +125,8 @@ del os.environ[k] def tearDown(self): - unittest.TestCase.tearDown(self) # Restore all proxy related env vars - for k, v in self._saved_environ: + for k, v in self._saved_environ.items(): os.environ[k] = v def test_getproxies_environment_keep_no_proxies(self): Modified: python/branches/py3k/Makefile.pre.in ============================================================================== --- python/branches/py3k/Makefile.pre.in (original) +++ python/branches/py3k/Makefile.pre.in Sat Oct 25 17:49:17 2008 @@ -796,7 +796,7 @@ fi; \ done $(INSTALL_DATA) $(srcdir)/Misc/python.man \ - $(DESTDIR)$(MANDIR)/man1/python.1 + $(DESTDIR)$(MANDIR)/man1/python$(VERSION).1 # Install the library PLATDIR= plat-$(MACHDEP) Modified: python/branches/py3k/Parser/asdl_c.py ============================================================================== --- python/branches/py3k/Parser/asdl_c.py (original) +++ python/branches/py3k/Parser/asdl_c.py Sat Oct 25 17:49:17 2008 @@ -804,7 +804,7 @@ return 0; } -static int add_ast_fields() +static int add_ast_fields(void) { PyObject *empty_tuple, *d; if (PyType_Ready(&AST_type) < 0) Modified: python/branches/py3k/Python/Python-ast.c ============================================================================== --- python/branches/py3k/Python/Python-ast.c (original) +++ python/branches/py3k/Python/Python-ast.c Sat Oct 25 17:49:17 2008 @@ -621,7 +621,7 @@ return 0; } -static int add_ast_fields() +static int add_ast_fields(void) { PyObject *empty_tuple, *d; if (PyType_Ready(&AST_type) < 0) From python-3000-checkins at python.org Sat Oct 25 19:10:07 2008 From: python-3000-checkins at python.org (alexandre.vassalotti) Date: Sat, 25 Oct 2008 19:10:07 +0200 (CEST) Subject: [Python-3000-checkins] r67026 - python/branches/py3k/Doc/includes/dbpickle.py Message-ID: <20081025171007.F11A41E4002@bag.python.org> Author: alexandre.vassalotti Date: Sat Oct 25 19:10:07 2008 New Revision: 67026 Log: Fix a grammar mistake in a comment. Modified: python/branches/py3k/Doc/includes/dbpickle.py Modified: python/branches/py3k/Doc/includes/dbpickle.py ============================================================================== --- python/branches/py3k/Doc/includes/dbpickle.py (original) +++ python/branches/py3k/Doc/includes/dbpickle.py Sat Oct 25 19:10:07 2008 @@ -12,10 +12,10 @@ def persistent_id(self, obj): # Instead of pickling MemoRecord as a regular class instance, we emit a - # persistent ID instead. + # persistent ID. if isinstance(obj, MemoRecord): - # Here, our persistent ID is simply a tuple containing a tag and a - # key which refers to a specific record in the database. + # Here, our persistent ID is simply a tuple, containing a tag and a + # key, which refers to a specific record in the database. return ("MemoRecord", obj.key) else: # If obj does not have a persistent ID, return None. This means obj From python-3000-checkins at python.org Sat Oct 25 19:12:53 2008 From: python-3000-checkins at python.org (alexandre.vassalotti) Date: Sat, 25 Oct 2008 19:12:53 +0200 (CEST) Subject: [Python-3000-checkins] r67027 - python/branches/py3k/Lib/pickle.py Message-ID: <20081025171253.19E5C1E4002@bag.python.org> Author: alexandre.vassalotti Date: Sat Oct 25 19:12:52 2008 New Revision: 67027 Log: Remove a confusing statement in Pickler's docstring. Pickler does not read anything from the given file. Modified: python/branches/py3k/Lib/pickle.py Modified: python/branches/py3k/Lib/pickle.py ============================================================================== --- python/branches/py3k/Lib/pickle.py (original) +++ python/branches/py3k/Lib/pickle.py Sat Oct 25 19:12:52 2008 @@ -179,8 +179,6 @@ def __init__(self, file, protocol=None): """This takes a binary file for writing a pickle data stream. - All protocols now read and write bytes. - The optional protocol argument tells the pickler to use the given protocol; supported protocols are 0, 1, 2, 3. The default protocol is 3; a backward-incompatible protocol designed for From python-3000-checkins at python.org Sun Oct 26 01:43:01 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 26 Oct 2008 01:43:01 +0200 (CEST) Subject: [Python-3000-checkins] r67029 - python/branches/py3k/Tools/scripts/findnocoding.py Message-ID: <20081025234301.31B381E400C@bag.python.org> Author: benjamin.peterson Date: Sun Oct 26 01:43:00 2008 New Revision: 67029 Log: default source encoding is now utf-8 Modified: python/branches/py3k/Tools/scripts/findnocoding.py Modified: python/branches/py3k/Tools/scripts/findnocoding.py ============================================================================== --- python/branches/py3k/Tools/scripts/findnocoding.py (original) +++ python/branches/py3k/Tools/scripts/findnocoding.py Sun Oct 26 01:43:00 2008 @@ -62,11 +62,11 @@ infile.close() return False - # check the whole file for non-ASCII characters + # check the whole file for non utf-8 characters rest = infile.read() infile.close() - if has_correct_encoding(line1+line2+rest, "ascii"): + if has_correct_encoding(line1+line2+rest, "utf-8"): return False return True From python-3000-checkins at python.org Sun Oct 26 21:58:53 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Sun, 26 Oct 2008 21:58:53 +0100 (CET) Subject: [Python-3000-checkins] r67032 - in python/branches/py3k: Lib/test/test_future.py Lib/test/test_future5.py Parser/parser.c Message-ID: <20081026205853.A3DE41E4002@bag.python.org> Author: benjamin.peterson Date: Sun Oct 26 21:58:53 2008 New Revision: 67032 Log: Merged revisions 67030-67031 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67030 | benjamin.peterson | 2008-10-26 15:21:13 -0500 (Sun, 26 Oct 2008) | 1 line fix __future__ imports when multiple features are given ........ r67031 | benjamin.peterson | 2008-10-26 15:33:19 -0500 (Sun, 26 Oct 2008) | 1 line add forgotten test for r67030 ........ Added: python/branches/py3k/Lib/test/test_future5.py - copied, changed from r67031, /python/trunk/Lib/test/test_future5.py Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/test/test_future.py python/branches/py3k/Parser/parser.c Modified: python/branches/py3k/Lib/test/test_future.py ============================================================================== --- python/branches/py3k/Lib/test/test_future.py (original) +++ python/branches/py3k/Lib/test/test_future.py Sun Oct 26 21:58:53 2008 @@ -89,19 +89,23 @@ # the parser hack disabled. If a new keyword is introduced in # 2.6, change this to refer to the new future import. try: - exec("from __future__ import division, with_statement; with = 0") + exec("from __future__ import print_function; print 0") except SyntaxError: pass else: self.fail("syntax error didn't occur") try: - exec("from __future__ import (with_statement, division); with = 0") + exec("from __future__ import (print_function); print 0") except SyntaxError: pass else: self.fail("syntax error didn't occur") + def test_multiple_features(self): + support.unload("test.test_future5") + from test import test_future5 + def test_main(): support.run_unittest(FutureTest) Copied: python/branches/py3k/Lib/test/test_future5.py (from r67031, /python/trunk/Lib/test/test_future5.py) ============================================================================== --- /python/trunk/Lib/test/test_future5.py (original) +++ python/branches/py3k/Lib/test/test_future5.py Sun Oct 26 21:58:53 2008 @@ -3,19 +3,19 @@ import sys import unittest -from . import test_support +from . import support class TestMultipleFeatures(unittest.TestCase): def test_unicode_literals(self): - self.assertTrue(isinstance("", unicode)) + self.assertTrue(isinstance("", str)) def test_print_function(self): - with test_support.captured_output("stderr") as s: + with support.captured_output("stderr") as s: print("foo", file=sys.stderr) self.assertEqual(s.getvalue(), "foo\n") def test_main(): - test_support.run_unittest(TestMultipleFeatures) + support.run_unittest(TestMultipleFeatures) Modified: python/branches/py3k/Parser/parser.c ============================================================================== --- python/branches/py3k/Parser/parser.c (original) +++ python/branches/py3k/Parser/parser.c Sun Oct 26 21:58:53 2008 @@ -210,13 +210,10 @@ char *str_ch = STR(CHILD(cch, 0)); if (strcmp(str_ch, FUTURE_WITH_STATEMENT) == 0) { ps->p_flags |= CO_FUTURE_WITH_STATEMENT; - break; } else if (strcmp(str_ch, FUTURE_PRINT_FUNCTION) == 0) { ps->p_flags |= CO_FUTURE_PRINT_FUNCTION; - break; } else if (strcmp(str_ch, FUTURE_UNICODE_LITERALS) == 0) { ps->p_flags |= CO_FUTURE_UNICODE_LITERALS; - break; } } } From python-3000-checkins at python.org Wed Oct 29 21:34:37 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 29 Oct 2008 21:34:37 +0100 (CET) Subject: [Python-3000-checkins] r67042 - python/branches/py3k Message-ID: <20081029203437.442FC1E4002@bag.python.org> Author: benjamin.peterson Date: Wed Oct 29 21:34:36 2008 New Revision: 67042 Log: Blocked revisions 67041 via svnmerge ........ r67041 | benjamin.peterson | 2008-10-29 15:33:00 -0500 (Wed, 29 Oct 2008) | 1 line mention the version gettempdir() was added ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Wed Oct 29 21:35:35 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Wed, 29 Oct 2008 21:35:35 +0100 (CET) Subject: [Python-3000-checkins] r67043 - python/branches/py3k/Doc/reference/datamodel.rst Message-ID: <20081029203535.D10F41E4049@bag.python.org> Author: benjamin.peterson Date: Wed Oct 29 21:35:35 2008 New Revision: 67043 Log: fix some more print statements Modified: python/branches/py3k/Doc/reference/datamodel.rst Modified: python/branches/py3k/Doc/reference/datamodel.rst ============================================================================== --- python/branches/py3k/Doc/reference/datamodel.rst (original) +++ python/branches/py3k/Doc/reference/datamodel.rst Wed Oct 29 21:35:35 2008 @@ -1918,14 +1918,14 @@ >>> class Meta(type): ... def __getattribute__(*args): - ... print "Metaclass getattribute invoked" + ... print("Metaclass getattribute invoked") ... return type.__getattribute__(*args) ... >>> class C(object, metaclass=Meta): ... def __len__(self): ... return 10 ... def __getattribute__(*args): - ... print "Class getattribute invoked" + ... print("Class getattribute invoked") ... return object.__getattribute__(*args) ... >>> c = C() From python-3000-checkins at python.org Thu Oct 30 00:32:34 2008 From: python-3000-checkins at python.org (alexandre.vassalotti) Date: Thu, 30 Oct 2008 00:32:34 +0100 (CET) Subject: [Python-3000-checkins] r67045 - python/branches/py3k/Doc/library/pickle.rst Message-ID: <20081029233234.1861D1E4002@bag.python.org> Author: alexandre.vassalotti Date: Thu Oct 30 00:32:33 2008 New Revision: 67045 Log: Improve pickle's documentation. Deprecate the previously undocumented Pickler.fast attribute. Revamp the "Pickling Class Instances" section. Reorganize sections and subsections. Clean up TextReader example. Modified: python/branches/py3k/Doc/library/pickle.rst Modified: python/branches/py3k/Doc/library/pickle.rst ============================================================================== --- python/branches/py3k/Doc/library/pickle.rst (original) +++ python/branches/py3k/Doc/library/pickle.rst Thu Oct 30 00:32:33 2008 @@ -115,10 +115,6 @@ protocol 2. See :mod:`pickletools`'s source code for extensive comments about opcodes used by pickle protocols. -If a *protocol* is not specified, protocol 3 is used. If *protocol* is -specified as a negative value or :const:`HIGHEST_PROTOCOL`, the highest -protocol version available will be used. - Module Interface ---------------- @@ -286,11 +282,11 @@ .. attribute:: fast - Enable fast mode if set to a true value. The fast mode disables the usage - of memo, therefore speeding the pickling process by not generating - superfluous PUT opcodes. It should not be used with self-referential - objects, doing otherwise will cause :class:`Pickler` to recurse - infinitely. + Deprecated. Enable fast mode if set to a true value. The fast mode + disables the usage of memo, therefore speeding the pickling process by not + generating superfluous PUT opcodes. It should not be used with + self-referential objects, doing otherwise will cause :class:`Pickler` to + recurse infinitely. Use :func:`pickletools.optimize` if you need more compact pickles. @@ -300,6 +296,8 @@ recursive objects to pickled by reference as opposed to by value. +.. XXX Move these comments to somewhere more appropriate. + It is possible to make multiple calls to the :meth:`dump` method of the same :class:`Pickler` instance. These must then be matched to the same number of calls to the :meth:`load` method of the corresponding :class:`Unpickler` @@ -380,7 +378,7 @@ * classes that are defined at the top level of a module * instances of such classes whose :attr:`__dict__` or :meth:`__setstate__` is - picklable (see section :ref:`pickle-protocol` for details) + picklable (see section :ref:`pickle-inst` for details) Attempts to pickle unpicklable objects will raise the :exc:`PicklingError` exception; when this happens, an unspecified number of bytes may have already @@ -418,164 +416,130 @@ conversions can be made by the class's :meth:`__setstate__` method. -.. _pickle-protocol: - -The pickle protocol -------------------- - -This section describes the "pickling protocol" that defines the interface -between the pickler/unpickler and the objects that are being serialized. This -protocol provides a standard way for you to define, customize, and control how -your objects are serialized and de-serialized. The description in this section -doesn't cover specific customizations that you can employ to make the unpickling -environment slightly safer from untrusted pickle data streams; see section -:ref:`pickle-restrict` for more details. - - .. _pickle-inst: -Pickling and unpickling normal class instances -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. index:: - single: __getinitargs__() (copy protocol) - single: __init__() (instance constructor) +Pickling Class Instances +------------------------ -.. XXX is __getinitargs__ only used with old-style classes? -.. XXX update w.r.t Py3k's classes +In this section, we describe the general mechanisms available to you to define, +customize, and control how class instances are pickled and unpickled. -When a pickled class instance is unpickled, its :meth:`__init__` method is -normally *not* invoked. If it is desirable that the :meth:`__init__` method be -called on unpickling, an old-style class can define a method -:meth:`__getinitargs__`, which should return a *tuple* containing the arguments -to be passed to the class constructor (:meth:`__init__` for example). The -:meth:`__getinitargs__` method is called at pickle time; the tuple it returns is -incorporated in the pickle for the instance. +In most cases, no additional code is needed to make instances picklable. By +default, pickle will retrieve the class and the attributes of an instance via +introspection. When a class instance is unpickled, its :meth:`__init__` method +is usually *not* invoked. The default behaviour first creates an uninitialized +instance and then restores the saved attributes. The following code shows an +implementation of this behaviour:: + + def save(obj): + return (obj.__class__, obj.__dict__) + + def load(cls, attributes): + obj = cls.__new__(cls) + obj.__dict__.update(attributes) + return obj .. index:: single: __getnewargs__() (copy protocol) -New-style types can provide a :meth:`__getnewargs__` method that is used for -protocol 2. Implementing this method is needed if the type establishes some -internal invariants when the instance is created, or if the memory allocation is -affected by the values passed to the :meth:`__new__` method for the type (as it -is for tuples and strings). Instances of a :term:`new-style class` :class:`C` -are created using :: +Classes can alter the default behaviour by providing one or severals special +methods. In protocol 2 and newer, classes that implements the +:meth:`__getnewargs__` method can dictate the values passed to the +:meth:`__new__` method upon unpickling. This is often needed for classes +whose :meth:`__new__` method requires arguments. - obj = C.__new__(C, *args) - - -where *args* is the result of calling :meth:`__getnewargs__` on the original -object; if there is no :meth:`__getnewargs__`, an empty tuple is assumed. - -.. index:: - single: __getstate__() (copy protocol) - single: __setstate__() (copy protocol) - single: __dict__ (instance attribute) +.. index:: single: __getstate__() (copy protocol) Classes can further influence how their instances are pickled; if the class -defines the method :meth:`__getstate__`, it is called and the return state is +defines the method :meth:`__getstate__`, it is called and the returned object is pickled as the contents for the instance, instead of the contents of the -instance's dictionary. If there is no :meth:`__getstate__` method, the -instance's :attr:`__dict__` is pickled. +instance's dictionary. If the :meth:`__getstate__` method is absent, the +instance's :attr:`__dict__` is pickled as usual. -Upon unpickling, if the class also defines the method :meth:`__setstate__`, it -is called with the unpickled state. [#]_ If there is no :meth:`__setstate__` -method, the pickled state must be a dictionary and its items are assigned to the -new instance's dictionary. If a class defines both :meth:`__getstate__` and -:meth:`__setstate__`, the state object needn't be a dictionary and these methods -can do what they want. [#]_ +.. index:: single: __setstate__() (copy protocol) -.. warning:: +Upon unpickling, if the class defines :meth:`__setstate__`, it is called with +the unpickled state. In that case, there is no requirement for the state object +to be a dictionary. Otherwise, the pickled state must be a dictionary and its +items are assigned to the new instance's dictionary. + +.. note:: If :meth:`__getstate__` returns a false value, the :meth:`__setstate__` method will not be called. - -Pickling and unpickling extension types -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Refer to the section :ref:`pickle-state` for more information about how to use +the methods :meth:`__getstate__` and :meth:`__setstate__`. .. index:: - single: __reduce__() (pickle protocol) - single: __reduce_ex__() (pickle protocol) - single: __safe_for_unpickling__ (pickle protocol) - -When the :class:`Pickler` encounters an object of a type it knows nothing about ---- such as an extension type --- it looks in two places for a hint of how to -pickle it. One alternative is for the object to implement a :meth:`__reduce__` -method. If provided, at pickling time :meth:`__reduce__` will be called with no -arguments, and it must return either a string or a tuple. - -If a string is returned, it names a global variable whose contents are pickled -as normal. The string returned by :meth:`__reduce__` should be the object's -local name relative to its module; the pickle module searches the module -namespace to determine the object's module. - -When a tuple is returned, it must be between two and five elements long. -Optional elements can either be omitted, or ``None`` can be provided as their -value. The contents of this tuple are pickled as normal and used to -reconstruct the object at unpickling time. The semantics of each element are: + pair: copy; protocol + single: __reduce__() (copy protocol) + +As we shall see, pickle does not use directly the methods described above. In +fact, these methods are part of the copy protocol which implements the +:meth:`__reduce__` special method. The copy protocol provides a unified +interface for retrieving the data necessary for pickling and copying +objects. [#]_ + +Although powerful, implementing :meth:`__reduce__` directly in your classes is +error prone. For this reason, class designers should use the high-level +interface (i.e., :meth:`__getnewargs__`, :meth:`__getstate__` and +:meth:`__setstate__`) whenever possible. We will show however cases where using +:meth:`__reduce__` is the only option or leads to more efficient pickling or +both. + +The interface is currently defined as follow. The :meth:`__reduce__` method +takes no argument and shall return either a string or preferably a tuple (the +returned object is often refered as the "reduce value"). + +If a string is returned, the string should be interpreted as the name of a +global variable. It should be the object's local name relative to its module; +the pickle module searches the module namespace to determine the object's +module. This behaviour is typically useful for singletons. + +When a tuple is returned, it must be between two and five items long. Optional +items can either be omitted, or ``None`` can be provided as their value. The +semantics of each item are in order: + +.. XXX Mention __newobj__ special-case? * A callable object that will be called to create the initial version of the - object. The next element of the tuple will provide arguments for this callable, - and later elements provide additional state information that will subsequently - be used to fully reconstruct the pickled data. - - In the unpickling environment this object must be either a class, a callable - registered as a "safe constructor" (see below), or it must have an attribute - :attr:`__safe_for_unpickling__` with a true value. Otherwise, an - :exc:`UnpicklingError` will be raised in the unpickling environment. Note that - as usual, the callable itself is pickled by name. + object. -* A tuple of arguments for the callable object, not ``None``. +* A tuple of arguments for the callable object. An empty tuple must be given if + the callable does not accept any argument. * Optionally, the object's state, which will be passed to the object's - :meth:`__setstate__` method as described in section :ref:`pickle-inst`. If the - object has no :meth:`__setstate__` method, then, as above, the value must be a - dictionary and it will be added to the object's :attr:`__dict__`. - -* Optionally, an iterator (and not a sequence) yielding successive list items. - These list items will be pickled, and appended to the object using either - ``obj.append(item)`` or ``obj.extend(list_of_items)``. This is primarily used - for list subclasses, but may be used by other classes as long as they have + :meth:`__setstate__` method as previously described. If the object has no + such method then, the value must be a dictionary and it will be added to the + object's :attr:`__dict__` attribute. + +* Optionally, an iterator (and not a sequence) yielding successive items. These + items will be appended to the object either using ``obj.append(item)`` or, in + batch, using ``obj.extend(list_of_items)``. This is primarily used for list + subclasses, but may be used by other classes as long as they have :meth:`append` and :meth:`extend` methods with the appropriate signature. (Whether :meth:`append` or :meth:`extend` is used depends on which pickle - protocol version is used as well as the number of items to append, so both must - be supported.) - -* Optionally, an iterator (not a sequence) yielding successive dictionary items, - which should be tuples of the form ``(key, value)``. These items will be - pickled and stored to the object using ``obj[key] = value``. This is primarily - used for dictionary subclasses, but may be used by other classes as long as they - implement :meth:`__setitem__`. - -It is sometimes useful to know the protocol version when implementing -:meth:`__reduce__`. This can be done by implementing a method named -:meth:`__reduce_ex__` instead of :meth:`__reduce__`. :meth:`__reduce_ex__`, when -it exists, is called in preference over :meth:`__reduce__` (you may still -provide :meth:`__reduce__` for backwards compatibility). The -:meth:`__reduce_ex__` method will be called with a single integer argument, the -protocol version. - -The :class:`object` class implements both :meth:`__reduce__` and -:meth:`__reduce_ex__`; however, if a subclass overrides :meth:`__reduce__` but -not :meth:`__reduce_ex__`, the :meth:`__reduce_ex__` implementation detects this -and calls :meth:`__reduce__`. - -An alternative to implementing a :meth:`__reduce__` method on the object to be -pickled, is to register the callable with the :mod:`copyreg` module. This -module provides a way for programs to register "reduction functions" and -constructors for user-defined types. Reduction functions have the same -semantics and interface as the :meth:`__reduce__` method described above, except -that they are called with a single argument, the object to be pickled. - -The registered constructor is deemed a "safe constructor" for purposes of -unpickling as described above. + protocol version is used as well as the number of items to append, so both + must be supported.) +* Optionally, an iterator (not a sequence) yielding successive key-value pairs. + These items will be stored to the object using ``obj[key] = value``. This is + primarily used for dictionary subclasses, but may be used by other classes as + long as they implement :meth:`__setitem__`. + +.. index:: single: __reduce_ex__() (copy protocol) + +Alternatively, a :meth:`__reduce_ex__` method may be defined. The only +difference is this method should take a single integer argument, the protocol +version. When defined, pickle will prefer it over the :meth:`__reduce__` +method. In addition, :meth:`__reduce__` automatically becomes a synonym for the +extended version. The main use for this method is to provide +backwards-compatible reduce values for older Python releases. .. _pickle-persistent: -Pickling and unpickling external objects -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Persistence of External Objects +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. index:: single: persistent_id (pickle protocol) @@ -603,17 +567,85 @@ :meth:`persistent_load` method that takes a persistent ID object and returns the referenced object. -Example: +Here is a comprehensive example presenting how persistent ID can be used to +pickle external objects by reference. .. XXX Work around for some bug in sphinx/pygments. .. highlightlang:: python .. literalinclude:: ../includes/dbpickle.py .. highlightlang:: python3 +.. _pickle-state: + +Handling Stateful Objects +^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. index:: + single: __getstate__() (copy protocol) + single: __setstate__() (copy protocol) + +Here's an example that shows how to modify pickling behavior for a class. +The :class:`TextReader` class opens a text file, and returns the line number and +line contents each time its :meth:`readline` method is called. If a +:class:`TextReader` instance is pickled, all attributes *except* the file object +member are saved. When the instance is unpickled, the file is reopened, and +reading resumes from the last location. The :meth:`__setstate__` and +:meth:`__getstate__` methods are used to implement this behavior. :: + + class TextReader: + """Print and number lines in a text file.""" + + def __init__(self, filename): + self.filename = filename + self.file = open(filename) + self.lineno = 0 + + def readline(self): + self.lineno += 1 + line = self.file.readline() + if not line: + return None + if line.endswith("\n"): + line = line[:-1] + return "%i: %s" % (self.lineno, line) + + def __getstate__(self): + # Copy the object's state from self.__dict__ which contains + # all our instance attributes. Always use the dict.copy() + # method to avoid modifying the original state. + state = self.__dict__.copy() + # Remove the unpicklable entries. + del state['file'] + return state + + def __setstate__(self, state): + # Restore instance attributes (i.e., filename and lineno). + self.__dict__.update(state) + # Restore the previously opened file's state. To do so, we need to + # reopen it and read from it until the line count is restored. + file = open(self.filename) + for _ in range(self.lineno): + file.readline() + # Finally, save the file. + self.file = file + + +A sample usage might be something like this:: + + >>> reader = TextReader("hello.txt") + >>> reader.readline() + '1: Hello world!' + >>> reader.readline() + '2: I am line number two.' + >>> new_reader = pickle.loads(pickle.dumps(reader)) + >>> new_reader.readline() + '3: Goodbye!' + + .. _pickle-restrict: Restricting Globals -^^^^^^^^^^^^^^^^^^^ +------------------- .. index:: single: find_class() (pickle protocol) @@ -653,6 +685,7 @@ } class RestrictedUnpickler(pickle.Unpickler): + def find_class(self, module, name): # Only allow safe classes from builtins. if module == "builtins" and name in safe_builtins: @@ -680,10 +713,15 @@ ... pickle.UnpicklingError: global 'builtins.eval' is forbidden -As our examples shows, you have to be careful with what you allow to -be unpickled. Therefore if security is a concern, you may want to consider -alternatives such as the marshalling API in :mod:`xmlrpc.client` or -third-party solutions. + +.. XXX Add note about how extension codes could evade our protection + mechanism (e.g. cached classes do not invokes find_class()). + +As our examples shows, you have to be careful with what you allow to be +unpickled. Therefore if security is a concern, you may want to consider +alternatives such as the marshalling API in :mod:`xmlrpc.client` or third-party +solutions. + .. _pickle-example: @@ -728,69 +766,6 @@ pkl_file.close() -Here's a larger example that shows how to modify pickling behavior for a class. -The :class:`TextReader` class opens a text file, and returns the line number and -line contents each time its :meth:`readline` method is called. If a -:class:`TextReader` instance is pickled, all attributes *except* the file object -member are saved. When the instance is unpickled, the file is reopened, and -reading resumes from the last location. The :meth:`__setstate__` and -:meth:`__getstate__` methods are used to implement this behavior. :: - - #!/usr/local/bin/python - - class TextReader: - """Print and number lines in a text file.""" - def __init__(self, file): - self.file = file - self.fh = open(file) - self.lineno = 0 - - def readline(self): - self.lineno = self.lineno + 1 - line = self.fh.readline() - if not line: - return None - if line.endswith("\n"): - line = line[:-1] - return "%d: %s" % (self.lineno, line) - - def __getstate__(self): - odict = self.__dict__.copy() # copy the dict since we change it - del odict['fh'] # remove filehandle entry - return odict - - def __setstate__(self, dict): - fh = open(dict['file']) # reopen file - count = dict['lineno'] # read from file... - while count: # until line count is restored - fh.readline() - count = count - 1 - self.__dict__.update(dict) # update attributes - self.fh = fh # save the file object - -A sample usage might be something like this:: - - >>> import TextReader - >>> obj = TextReader.TextReader("TextReader.py") - >>> obj.readline() - '1: #!/usr/local/bin/python' - >>> obj.readline() - '2: ' - >>> obj.readline() - '3: class TextReader:' - >>> import pickle - >>> pickle.dump(obj, open('save.p', 'wb')) - -If you want to see that :mod:`pickle` works across Python processes, start -another Python session, before continuing. What follows can happen from either -the same process or a new process. :: - - >>> import pickle - >>> reader = pickle.load(open('save.p', 'rb')) - >>> reader.readline() - '4: """Print and number lines in a text file."""' - - .. seealso:: Module :mod:`copyreg` @@ -813,10 +788,8 @@ .. [#] The exception raised will likely be an :exc:`ImportError` or an :exc:`AttributeError` but it could be something else. -.. [#] These methods can also be used to implement copying class instances. - -.. [#] This protocol is also used by the shallow and deep copying operations - defined in the :mod:`copy` module. +.. [#] The :mod:`copy` module uses this protocol for shallow and deep copying + operations. .. [#] The limitation on alphanumeric characters is due to the fact the persistent IDs, in protocol 0, are delimited by the newline From python-3000-checkins at python.org Fri Oct 31 00:42:03 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 31 Oct 2008 00:42:03 +0100 (CET) Subject: [Python-3000-checkins] r67064 - in python/branches/py3k: Misc/NEWS Modules/main.c Message-ID: <20081030234203.44F6E1E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 31 00:03:32 2008 New Revision: 67064 Log: #3626: On cygwin, starting "python z" would not display any error message: printf("%ls") fails if the wide string is 1 char long :-( Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/main.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Fri Oct 31 00:03:32 2008 @@ -15,10 +15,13 @@ Core and Builtins ----------------- +- 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. + - Issue #4176: Fixed a crash when pickling an object which ``__reduce__`` method does not return iterators for the 4th and 5th items. -- Issue 3723: Fixed initialization of subinterpreters. +- Issue #3723: Fixed initialization of subinterpreters. - Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8. Modified: python/branches/py3k/Modules/main.c ============================================================================== --- python/branches/py3k/Modules/main.c (original) +++ python/branches/py3k/Modules/main.c Fri Oct 31 00:03:32 2008 @@ -564,8 +564,17 @@ if (sts==-1 && filename!=NULL) { if ((fp = _wfopen(filename, L"r")) == NULL) { - fprintf(stderr, "%ls: can't open file '%ls': [Errno %d] %s\n", - argv[0], filename, errno, strerror(errno)); + char cfilename[PATH_MAX]; + size_t r = wcstombs(cfilename, filename, PATH_MAX); + if (r == PATH_MAX) + /* cfilename is not null-terminated; + * forcefully null-terminating it + * might break the shift state */ + strcpy(cfilename, ""); + if (r == ((size_t)-1)) + strcpy(cfilename, ""); + fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n", + argv[0], cfilename, errno, strerror(errno)); return 2; } From python-3000-checkins at python.org Fri Oct 31 00:47:29 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 31 Oct 2008 00:47:29 +0100 (CET) Subject: [Python-3000-checkins] r67048 - in python/branches/py3k: Lib/test/test_defaultdict.py Misc/NEWS Modules/_collectionsmodule.c Message-ID: <20081030234729.892E21E4002@bag.python.org> Author: amaury.forgeotdarc Date: Thu Oct 30 21:58:42 2008 New Revision: 67048 Log: #4170: Fix segfault when pickling a defauldict object. The 2.x dict.iteritems() returns an iterator, whereas the 3.0 dict.items() returns a "view", which is iterable, but not an iterator with its __next__ method. Patch by Hirokazu Yamamoto. Modified: python/branches/py3k/Lib/test/test_defaultdict.py python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/_collectionsmodule.c Modified: python/branches/py3k/Lib/test/test_defaultdict.py ============================================================================== --- python/branches/py3k/Lib/test/test_defaultdict.py (original) +++ python/branches/py3k/Lib/test/test_defaultdict.py Thu Oct 30 21:58:42 2008 @@ -2,6 +2,7 @@ import os import copy +import pickle import tempfile import unittest from test import support @@ -164,6 +165,13 @@ finally: os.remove(tfn) + def test_pickleing(self): + d = defaultdict(int) + d[1] + for proto in range(pickle.HIGHEST_PROTOCOL + 1): + s = pickle.dumps(d, proto) + o = pickle.loads(s) + self.assertEqual(d, o) def test_main(): support.run_unittest(TestDefaultDict) Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Oct 30 21:58:42 2008 @@ -15,6 +15,9 @@ Core and Builtins ----------------- +- Issue #4170: Pickling a collections.defaultdict object would crash the + interpreter. + - Issue #4146: Compilation on OpenBSD has been restored. - Issue #3574: compile() incorrectly handled source code encoded as Latin-1. Modified: python/branches/py3k/Modules/_collectionsmodule.c ============================================================================== --- python/branches/py3k/Modules/_collectionsmodule.c (original) +++ python/branches/py3k/Modules/_collectionsmodule.c Thu Oct 30 21:58:42 2008 @@ -1155,6 +1155,7 @@ */ PyObject *args; PyObject *items; + PyObject *iter; PyObject *result; if (dd->default_factory == NULL || dd->default_factory == Py_None) args = PyTuple_New(0); @@ -1167,8 +1168,15 @@ Py_DECREF(args); return NULL; } + iter = PyObject_GetIter(items); + if (iter == NULL) { + Py_DECREF(items); + Py_DECREF(args); + return NULL; + } result = PyTuple_Pack(5, Py_TYPE(dd), args, - Py_None, Py_None, items); + Py_None, Py_None, iter); + Py_DECREF(iter); Py_DECREF(items); Py_DECREF(args); return result; From python-3000-checkins at python.org Fri Oct 31 00:47:34 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 31 Oct 2008 00:47:34 +0100 (CET) Subject: [Python-3000-checkins] r67050 - python/branches/py3k/Misc/NEWS Message-ID: <20081030234734.47F961E403C@bag.python.org> Author: christian.heimes Date: Thu Oct 30 22:22:55 2008 New Revision: 67050 Log: Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members. Modified: python/branches/py3k/Misc/NEWS Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Oct 30 22:22:55 2008 @@ -15,6 +15,9 @@ Core and Builtins ----------------- +- Issue #4237: io.FileIO() was raising invalid warnings caused by + insufficient initialization of PyFileIOObject struct members. + - Issue #4170: Pickling a collections.defaultdict object would crash the interpreter. From python-3000-checkins at python.org Fri Oct 31 00:47:36 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 31 Oct 2008 00:47:36 +0100 (CET) Subject: [Python-3000-checkins] r67051 - in python/branches/py3k: Lib/test/test_io.py Modules/_fileio.c Message-ID: <20081030234736.293AD1E402C@bag.python.org> Author: christian.heimes Date: Thu Oct 30 22:23:35 2008 New Revision: 67051 Log: Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members. Modified: python/branches/py3k/Lib/test/test_io.py python/branches/py3k/Modules/_fileio.c 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 Oct 30 22:23:35 2008 @@ -1237,6 +1237,13 @@ 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, Modified: python/branches/py3k/Modules/_fileio.c ============================================================================== --- python/branches/py3k/Modules/_fileio.c (original) +++ python/branches/py3k/Modules/_fileio.c Thu Oct 30 22:23:35 2008 @@ -86,6 +86,10 @@ self = (PyFileIOObject *) type->tp_alloc(type, 0); if (self != NULL) { self->fd = -1; + self->readable = 0; + self->writable = 0; + self->seekable = -1; + self->closefd = 1; self->weakreflist = NULL; } @@ -179,8 +183,6 @@ } } - self->readable = self->writable = 0; - self->seekable = -1; s = mode; while (*s) { switch (*s++) { From python-3000-checkins at python.org Fri Oct 31 00:47:40 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 31 Oct 2008 00:47:40 +0100 (CET) Subject: [Python-3000-checkins] r67054 - in python/branches/py3k: Misc/NEWS Modules/atexitmodule.c Message-ID: <20081030234740.7D7821E4025@bag.python.org> Author: christian.heimes Date: Thu Oct 30 22:34:02 2008 New Revision: 67054 Log: Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Modules/atexitmodule.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Oct 30 22:34:02 2008 @@ -15,6 +15,9 @@ Core and Builtins ----------------- +- Issue #4200: Changed the atexit module to store its state in its + PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. + - Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members. Modified: python/branches/py3k/Modules/atexitmodule.c ============================================================================== --- python/branches/py3k/Modules/atexitmodule.c (original) +++ python/branches/py3k/Modules/atexitmodule.c Thu Oct 30 22:34:02 2008 @@ -9,9 +9,11 @@ #include "Python.h" /* Forward declaration (for atexit_cleanup) */ -static PyObject *atexit_clear(PyObject*); +static PyObject *atexit_clear(PyObject*, PyObject*); /* Forward declaration (for atexit_callfuncs) */ -static void atexit_cleanup(void); +static void atexit_cleanup(PyObject*); +/* Forward declaration of module object */ +static struct PyModuleDef atexitmodule; /* ===================================================================== */ /* Callback machinery. */ @@ -22,9 +24,14 @@ PyObject *kwargs; } atexit_callback; -static atexit_callback **atexit_callbacks; -static int ncallbacks = 0; -static int callback_len = 32; +typedef struct { + atexit_callback **atexit_callbacks; + int ncallbacks; + int callback_len; +} atexitmodule_state; + +#define GET_ATEXIT_STATE(mod) ((atexitmodule_state*)PyModule_GetState(mod)) + /* Installed into pythonrun.c's atexit mechanism */ @@ -33,14 +40,22 @@ { PyObject *exc_type = NULL, *exc_value, *exc_tb, *r; atexit_callback *cb; + PyObject *module; + atexitmodule_state *modstate; int i; - - if (ncallbacks == 0) + + module = PyState_FindModule(&atexitmodule); + if (module == NULL) return; - - for (i = ncallbacks - 1; i >= 0; i--) + modstate = GET_ATEXIT_STATE(module); + + if (modstate->ncallbacks == 0) + return; + + + for (i = modstate->ncallbacks - 1; i >= 0; i--) { - cb = atexit_callbacks[i]; + cb = modstate->atexit_callbacks[i]; if (cb == NULL) continue; @@ -61,28 +76,32 @@ } } } - - atexit_cleanup(); + + atexit_cleanup(module); if (exc_type) PyErr_Restore(exc_type, exc_value, exc_tb); } static void -atexit_delete_cb(int i) +atexit_delete_cb(PyObject *self, int i) { - atexit_callback *cb = atexit_callbacks[i]; - atexit_callbacks[i] = NULL; + atexitmodule_state *modstate; + atexit_callback *cb; + + modstate = GET_ATEXIT_STATE(self); + cb = modstate->atexit_callbacks[i]; + modstate->atexit_callbacks[i] = NULL; Py_DECREF(cb->func); Py_DECREF(cb->args); Py_XDECREF(cb->kwargs); - PyMem_Free(cb); + PyMem_Free(cb); } static void -atexit_cleanup(void) +atexit_cleanup(PyObject *self) { - PyObject *r = atexit_clear(NULL); + PyObject *r = atexit_clear(self, NULL); Py_DECREF(r); } @@ -103,32 +122,35 @@ static PyObject * atexit_register(PyObject *self, PyObject *args, PyObject *kwargs) { + atexitmodule_state *modstate; atexit_callback *new_callback; PyObject *func = NULL; - - if (ncallbacks >= callback_len) { + + modstate = GET_ATEXIT_STATE(self); + + if (modstate->ncallbacks >= modstate->callback_len) { atexit_callback **r; - callback_len += 16; - r = (atexit_callback**)PyMem_Realloc(atexit_callbacks, - sizeof(atexit_callback*) * callback_len); + modstate->callback_len += 16; + r = (atexit_callback**)PyMem_Realloc(modstate->atexit_callbacks, + sizeof(atexit_callback*) * modstate->callback_len); if (r == NULL) return PyErr_NoMemory(); - atexit_callbacks = r; + modstate->atexit_callbacks = r; } - + if (PyTuple_GET_SIZE(args) == 0) { PyErr_SetString(PyExc_TypeError, "register() takes at least 1 argument (0 given)"); return NULL; } - + func = PyTuple_GET_ITEM(args, 0); if (!PyCallable_Check(func)) { PyErr_SetString(PyExc_TypeError, "the first argument must be callable"); return NULL; } - + new_callback = PyMem_Malloc(sizeof(atexit_callback)); if (new_callback == NULL) return PyErr_NoMemory(); @@ -142,9 +164,9 @@ new_callback->kwargs = kwargs; Py_INCREF(func); Py_XINCREF(kwargs); - - atexit_callbacks[ncallbacks++] = new_callback; - + + modstate->atexit_callbacks[modstate->ncallbacks++] = new_callback; + Py_INCREF(func); return func; } @@ -155,7 +177,7 @@ Run all registered exit functions."); static PyObject * -atexit_run_exitfuncs(PyObject *self) +atexit_run_exitfuncs(PyObject *self, PyObject *unused) { atexit_callfuncs(); if (PyErr_Occurred()) @@ -169,20 +191,22 @@ Clear the list of previously registered exit functions."); static PyObject * -atexit_clear(PyObject *self) +atexit_clear(PyObject *self, PyObject *unused) { + atexitmodule_state *modstate; atexit_callback *cb; int i; - - for (i = 0; i < ncallbacks; i++) - { - cb = atexit_callbacks[i]; + + modstate = GET_ATEXIT_STATE(self); + + for (i = 0; i < modstate->ncallbacks; i++) { + cb = modstate->atexit_callbacks[i]; if (cb == NULL) continue; - - atexit_delete_cb(i); + + atexit_delete_cb(self, i); } - ncallbacks = 0; + modstate->ncallbacks = 0; Py_RETURN_NONE; } @@ -197,20 +221,23 @@ static PyObject * atexit_unregister(PyObject *self, PyObject *func) { + atexitmodule_state *modstate; atexit_callback *cb; int i, eq; - - for (i = 0; i < ncallbacks; i++) + + modstate = GET_ATEXIT_STATE(self); + + for (i = 0; i < modstate->ncallbacks; i++) { - cb = atexit_callbacks[i]; + cb = modstate->atexit_callbacks[i]; if (cb == NULL) continue; - + eq = PyObject_RichCompareBool(cb->func, func, Py_EQ); if (eq < 0) return NULL; if (eq) - atexit_delete_cb(i); + atexit_delete_cb(self, i); } Py_RETURN_NONE; } @@ -242,7 +269,7 @@ PyModuleDef_HEAD_INIT, "atexit", atexit__doc__, - -1, + sizeof(atexitmodule_state), atexit_methods, NULL, NULL, @@ -254,15 +281,20 @@ PyInit_atexit(void) { PyObject *m; - - atexit_callbacks = PyMem_New(atexit_callback*, callback_len); - if (atexit_callbacks == NULL) - return NULL; + atexitmodule_state *modstate; m = PyModule_Create(&atexitmodule); if (m == NULL) return NULL; - + + modstate = GET_ATEXIT_STATE(m); + modstate->callback_len = 32; + modstate->ncallbacks = 0; + modstate->atexit_callbacks = PyMem_New(atexit_callback*, + modstate->callback_len); + if (modstate->atexit_callbacks == NULL) + return NULL; + _Py_PyAtExit(atexit_callfuncs); return m; } From python-3000-checkins at python.org Fri Oct 31 00:47:41 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 31 Oct 2008 00:47:41 +0100 (CET) Subject: [Python-3000-checkins] r67055 - in python/branches/py3k: Misc/NEWS Python/pythonrun.c Message-ID: <20081030234741.BD6EC1E4011@bag.python.org> Author: christian.heimes Date: Thu Oct 30 22:40:04 2008 New Revision: 67055 Log: Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8. Patch created by Victor and reviewed by me. The change is required for proper initialization of subinterpreters. Modified: python/branches/py3k/Misc/NEWS python/branches/py3k/Python/pythonrun.c Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Oct 30 22:40:04 2008 @@ -15,6 +15,9 @@ Core and Builtins ----------------- +- Issue #4213: The file system encoding is now normalized by the + codec subsystem, for example UTF-8 is turned into utf-8. + - Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. Modified: python/branches/py3k/Python/pythonrun.c ============================================================================== --- python/branches/py3k/Python/pythonrun.c (original) +++ python/branches/py3k/Python/pythonrun.c Thu Oct 30 22:40:04 2008 @@ -126,6 +126,37 @@ return flag; } +#if defined(HAVE_LANGINFO_H) && defined(CODESET) +static char* +get_codeset(void) +{ + char* codeset; + PyObject *codec, *name; + + codeset = nl_langinfo(CODESET); + if (!codeset || codeset[0] == '\0') + return NULL; + + codec = _PyCodec_Lookup(codeset); + if (!codec) + goto error; + + name = PyObject_GetAttrString(codec, "name"); + Py_CLEAR(codec); + if (!name) + goto error; + + codeset = strdup(_PyUnicode_AsString(name)); + Py_DECREF(name); + return codeset; + +error: + Py_XDECREF(codec); + PyErr_Clear(); + return NULL; +} +#endif + void Py_InitializeEx(int install_sigs) { @@ -257,15 +288,7 @@ initialized by other means. Also set the encoding of stdin and stdout if these are terminals. */ - codeset = nl_langinfo(CODESET); - if (codeset && *codeset) { - if (PyCodec_KnownEncoding(codeset)) - codeset = strdup(codeset); - else - codeset = NULL; - } else - codeset = NULL; - + codeset = get_codeset(); if (codeset) { if (!Py_FileSystemDefaultEncoding) Py_FileSystemDefaultEncoding = codeset; From python-3000-checkins at python.org Fri Oct 31 00:47:45 2008 From: python-3000-checkins at python.org (christian.heimes) Date: Fri, 31 Oct 2008 00:47:45 +0100 (CET) Subject: [Python-3000-checkins] r67057 - in python/branches/py3k: Demo/embed/importexc.c Include/pystate.h Misc/NEWS Objects/unicodeobject.c Python/bltinmodule.c Python/codecs.c Python/pystate.c Python/pythonrun.c Python/sysmodule.c Message-ID: <20081030234745.1E9CB1E4048@bag.python.org> Author: christian.heimes Date: Thu Oct 30 22:48:26 2008 New Revision: 67057 Log: Issue 3723: Fixed initialization of subinterpreters The patch fixes several issues with Py_NewInterpreter as well as the demo for multiple subinterpreters. Most of the patch was written by MvL with help from Benjamin, Amaury and me. Graham Dumpleton has verified that this patch fixes an issue with mod_wsgi. Modified: python/branches/py3k/Demo/embed/importexc.c python/branches/py3k/Include/pystate.h python/branches/py3k/Misc/NEWS python/branches/py3k/Objects/unicodeobject.c python/branches/py3k/Python/bltinmodule.c python/branches/py3k/Python/codecs.c python/branches/py3k/Python/pystate.c python/branches/py3k/Python/pythonrun.c python/branches/py3k/Python/sysmodule.c Modified: python/branches/py3k/Demo/embed/importexc.c ============================================================================== --- python/branches/py3k/Demo/embed/importexc.c (original) +++ python/branches/py3k/Demo/embed/importexc.c Thu Oct 30 22:48:26 2008 @@ -1,14 +1,20 @@ #include -char* cmd = "import exceptions"; +#if 0 +char* cmd = "import codecs, encodings.utf_8, types; print(types)"; +#else +char* cmd = "import types; print(types)"; +#endif int main() { + printf("Initialize interpreter\n"); Py_Initialize(); PyEval_InitThreads(); PyRun_SimpleString(cmd); Py_EndInterpreter(PyThreadState_Get()); + printf("\nInitialize subinterpreter\n"); Py_NewInterpreter(); PyRun_SimpleString(cmd); Py_Finalize(); Modified: python/branches/py3k/Include/pystate.h ============================================================================== --- python/branches/py3k/Include/pystate.h (original) +++ python/branches/py3k/Include/pystate.h Thu Oct 30 22:48:26 2008 @@ -27,6 +27,7 @@ PyObject *codec_search_path; PyObject *codec_search_cache; PyObject *codec_error_registry; + int codecs_initialized; #ifdef HAVE_DLOPEN int dlopenflags; Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Oct 30 22:48:26 2008 @@ -15,6 +15,8 @@ Core and Builtins ----------------- +- Issue 3723: Fixed initialization of subinterpreters. + - Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8. Modified: python/branches/py3k/Objects/unicodeobject.c ============================================================================== --- python/branches/py3k/Objects/unicodeobject.c (original) +++ python/branches/py3k/Objects/unicodeobject.c Thu Oct 30 22:48:26 2008 @@ -1346,6 +1346,19 @@ #endif else if (strcmp(encoding, "ascii") == 0) return PyUnicode_AsASCIIString(unicode); + /* During bootstrap, we may need to find the encodings + package, to load the file system encoding, and require the + file system encoding in order to load the encodings + package. + + Break out of this dependency by assuming that the path to + the encodings module is ASCII-only. XXX could try wcstombs + instead, if the file system encoding is the locale's + encoding. */ + else if (Py_FileSystemDefaultEncoding && + strcmp(encoding, Py_FileSystemDefaultEncoding) == 0 && + !PyThreadState_GET()->interp->codecs_initialized) + return PyUnicode_AsASCIIString(unicode); } /* Encode via the codec registry */ Modified: python/branches/py3k/Python/bltinmodule.c ============================================================================== --- python/branches/py3k/Python/bltinmodule.c (original) +++ python/branches/py3k/Python/bltinmodule.c Thu Oct 30 22:48:26 2008 @@ -2282,7 +2282,7 @@ PyModuleDef_HEAD_INIT, "builtins", builtin_doc, - 0, + -1, /* multiple "initialization" just copies the module dict. */ builtin_methods, NULL, NULL, Modified: python/branches/py3k/Python/codecs.c ============================================================================== --- python/branches/py3k/Python/codecs.c (original) +++ python/branches/py3k/Python/codecs.c Thu Oct 30 22:48:26 2008 @@ -869,5 +869,6 @@ return -1; } Py_DECREF(mod); + interp->codecs_initialized = 1; return 0; } Modified: python/branches/py3k/Python/pystate.c ============================================================================== --- python/branches/py3k/Python/pystate.c (original) +++ python/branches/py3k/Python/pystate.c Thu Oct 30 22:48:26 2008 @@ -76,6 +76,7 @@ interp->codec_search_path = NULL; interp->codec_search_cache = NULL; interp->codec_error_registry = NULL; + interp->codecs_initialized = 0; #ifdef HAVE_DLOPEN #ifdef RTLD_NOW interp->dlopenflags = RTLD_NOW; Modified: python/branches/py3k/Python/pythonrun.c ============================================================================== --- python/branches/py3k/Python/pythonrun.c (original) +++ python/branches/py3k/Python/pythonrun.c Thu Oct 30 22:48:26 2008 @@ -562,8 +562,13 @@ goto handle_error; Py_INCREF(interp->builtins); } + + /* initialize builtin exceptions */ + _PyExc_Init(); + sysmod = _PyImport_FindExtension("sys", "sys"); if (bimod != NULL && sysmod != NULL) { + PyObject *pstderr; interp->sysdict = PyModule_GetDict(sysmod); if (interp->sysdict == NULL) goto handle_error; @@ -571,7 +576,18 @@ PySys_SetPath(Py_GetPath()); PyDict_SetItemString(interp->sysdict, "modules", interp->modules); + /* Set up a preliminary stderr printer until we have enough + infrastructure for the io module in place. */ + pstderr = PyFile_NewStdPrinter(fileno(stderr)); + if (pstderr == NULL) + Py_FatalError("Py_Initialize: can't set preliminary stderr"); + PySys_SetObject("stderr", pstderr); + PySys_SetObject("__stderr__", pstderr); + _PyImportHooks_Init(); + if (initstdio() < 0) + Py_FatalError( + "Py_Initialize: can't initialize sys standard streams"); initmain(); if (!Py_NoSiteFlag) initsite(); Modified: python/branches/py3k/Python/sysmodule.c ============================================================================== --- python/branches/py3k/Python/sysmodule.c (original) +++ python/branches/py3k/Python/sysmodule.c Thu Oct 30 22:48:26 2008 @@ -1231,7 +1231,7 @@ PyModuleDef_HEAD_INIT, "sys", sys_doc, - 0, + -1, /* multiple "initialization" just copies the module dict. */ sys_methods, NULL, NULL, From python-3000-checkins at python.org Fri Oct 31 00:47:48 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 31 Oct 2008 00:47:48 +0100 (CET) Subject: [Python-3000-checkins] r67059 - in python/branches/py3k: Lib/test/pickletester.py Misc/NEWS Modules/_pickle.c Message-ID: <20081030234748.DD4E11E4013@bag.python.org> Author: amaury.forgeotdarc Date: Thu Oct 30 23:25:31 2008 New Revision: 67059 Log: Merged revisions 67049 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67049 | amaury.forgeotdarc | 2008-10-30 22:18:34 +0100 (jeu., 30 oct. 2008) | 8 lines Issue #4176: Pickle would crash the interpreter when a __reduce__ function does not return an iterator for the 4th and 5th items. (sequence-like and mapping-like state) A list is not an iterator... Will backport to 2.6 and 2.5. ........ Modified: python/branches/py3k/ (props changed) 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 Thu Oct 30 23:25:31 2008 @@ -876,6 +876,22 @@ d = self.dumps(x, 2) self.assertRaises(RuntimeError, self.loads, d) + def test_reduce_bad_iterator(self): + # Issue4176: crash when 4th and 5th items of __reduce__() + # are not iterators + class C(object): + def __reduce__(self): + # 4th item is not an iterator + return list, (), None, [], None + class D(object): + def __reduce__(self): + # 5th item is not an iterator + return dict, (), None, None, [] + + for proto in protocols: + self.assertRaises(pickle.PickleError, self.dumps, C(), proto) + self.assertRaises(pickle.PickleError, self.dumps, D(), proto) + # Test classes for reduce_ex class REX_one(object): Modified: python/branches/py3k/Misc/NEWS ============================================================================== --- python/branches/py3k/Misc/NEWS (original) +++ python/branches/py3k/Misc/NEWS Thu Oct 30 23:25:31 2008 @@ -15,6 +15,9 @@ Core and Builtins ----------------- +- Issue #4176: Fixed a crash when pickling an object which ``__reduce__`` + method does not return iterators for the 4th and 5th items. + - Issue 3723: Fixed initialization of subinterpreters. - Issue #4213: The file system encoding is now normalized by the Modified: python/branches/py3k/Modules/_pickle.c ============================================================================== --- python/branches/py3k/Modules/_pickle.c (original) +++ python/branches/py3k/Modules/_pickle.c Thu Oct 30 23:25:31 2008 @@ -1961,8 +1961,9 @@ PyObject *callable; PyObject *argtup; PyObject *state = NULL; - PyObject *listitems = NULL; - PyObject *dictitems = NULL; + PyObject *listitems = Py_None; + PyObject *dictitems = Py_None; + Py_ssize_t size; int use_newobj = self->proto >= 2; @@ -1970,27 +1971,48 @@ 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; if (!PyCallable_Check(callable)) { - PyErr_SetString(PicklingError, - "first argument of save_reduce() must be callable"); + PyErr_SetString(PicklingError, "first item of the tuple " + "returned by __reduce__ must be callable"); return -1; } if (!PyTuple_Check(argtup)) { - PyErr_SetString(PicklingError, - "second argument of save_reduce() must be a tuple"); + PyErr_SetString(PicklingError, "second item of the tuple " + "returned by __reduce__ must be a tuple"); return -1; } if (state == Py_None) state = NULL; + if (listitems == Py_None) listitems = NULL; + else if (!PyIter_Check(listitems)) { + PyErr_Format(PicklingError, "Fourth element of tuple" + "returned by __reduce__ must be an iterator, not %s", + Py_TYPE(listitems)->tp_name); + return -1; + } + if (dictitems == Py_None) dictitems = NULL; + else if (!PyIter_Check(dictitems)) { + PyErr_Format(PicklingError, "Fifth element of tuple" + "returned by __reduce__ must be an iterator, not %s", + Py_TYPE(dictitems)->tp_name); + return -1; + } /* Protocol 2 special case: if callable's name is __newobj__, use NEWOBJ. */ @@ -2309,16 +2331,6 @@ "__reduce__ must return a string or tuple"); goto error; } - if (Py_SIZE(reduce_value) < 2 || Py_SIZE(reduce_value) > 5) { - PyErr_SetString(PicklingError, "tuple returned by __reduce__ " - "must contain 2 through 5 elements"); - goto error; - } - if (!PyTuple_Check(PyTuple_GET_ITEM(reduce_value, 1))) { - PyErr_SetString(PicklingError, "second item of the tuple " - "returned by __reduce__ must be a tuple"); - goto error; - } status = save_reduce(self, reduce_value, obj); From python-3000-checkins at python.org Fri Oct 31 00:47:54 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 31 Oct 2008 00:47:54 +0100 (CET) Subject: [Python-3000-checkins] r67062 - python/branches/py3k Message-ID: <20081030234754.EB3831E4048@bag.python.org> Author: benjamin.peterson Date: Thu Oct 30 23:48:10 2008 New Revision: 67062 Log: Blocked revisions 67060-67061 via svnmerge ........ r67060 | benjamin.peterson | 2008-10-30 17:39:25 -0500 (Thu, 30 Oct 2008) | 1 line backport bin() documentation ........ r67061 | benjamin.peterson | 2008-10-30 17:44:18 -0500 (Thu, 30 Oct 2008) | 1 line finish backporting binary literals and new octal literals docs ........ Modified: python/branches/py3k/ (props changed) From python-3000-checkins at python.org Fri Oct 31 03:28:07 2008 From: python-3000-checkins at python.org (benjamin.peterson) Date: Fri, 31 Oct 2008 03:28:07 +0100 (CET) Subject: [Python-3000-checkins] r67068 - in python/branches/py3k: Lib/test/test_future.py Lib/test/test_parser.py Modules/parsermodule.c Python/pythonrun.c Message-ID: <20081031022807.E3CB01E4002@bag.python.org> Author: benjamin.peterson Date: Fri Oct 31 03:28:05 2008 New Revision: 67068 Log: Merged revisions 67066 via svnmerge from svn+ssh://pythondev at svn.python.org/python/trunk ........ r67066 | benjamin.peterson | 2008-10-30 21:16:05 -0500 (Thu, 30 Oct 2008) | 5 lines make sure the parser flags and passed onto the compiler This fixes "from __future__ import unicode_literals" in an exec statment See #4225 ........ Modified: python/branches/py3k/ (props changed) python/branches/py3k/Lib/test/test_future.py python/branches/py3k/Lib/test/test_parser.py python/branches/py3k/Modules/parsermodule.c python/branches/py3k/Python/pythonrun.c Modified: python/branches/py3k/Lib/test/test_future.py ============================================================================== --- python/branches/py3k/Lib/test/test_future.py (original) +++ python/branches/py3k/Lib/test/test_future.py Fri Oct 31 03:28:05 2008 @@ -106,6 +106,11 @@ support.unload("test.test_future5") from test import test_future5 + def test_unicode_literals_exec(self): + scope = {} + exec("from __future__ import unicode_literals; x = ''", {}, scope) + self.assertTrue(isinstance(scope["x"], str)) + def test_main(): support.run_unittest(FutureTest) 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 Fri Oct 31 03:28:05 2008 @@ -25,6 +25,15 @@ def check_expr(self, s): self.roundtrip(parser.expr, s) + def test_flags_passed(self): + # The unicode literals flags has to be passed from the paser to AST + # generation. + suite = parser.suite("from __future__ import unicode_literals; x = ''") + code = suite.compile() + scope = {} + exec(code, {}, scope) + self.assertTrue(isinstance(scope["x"], str)) + def check_suite(self, s): self.roundtrip(parser.suite, s) Modified: python/branches/py3k/Modules/parsermodule.c ============================================================================== --- python/branches/py3k/Modules/parsermodule.c (original) +++ python/branches/py3k/Modules/parsermodule.c Fri Oct 31 03:28:05 2008 @@ -26,12 +26,20 @@ */ #include "Python.h" /* general Python API */ +#include "Python-ast.h" /* mod_ty */ #include "graminit.h" /* symbols defined in the grammar */ #include "node.h" /* internal parser structure */ #include "errcode.h" /* error codes for PyNode_*() */ #include "token.h" /* token definitions */ +#include "grammar.h" +#include "parsetok.h" /* ISTERMINAL() / ISNONTERMINAL() */ -#include "compile.h" /* PyNode_Compile() */ +#include "compile.h" +#undef Yield +#include "ast.h" +#include "pyarena.h" + +extern grammar _PyParser_Grammar; /* From graminit.c */ #ifdef lint #include @@ -156,6 +164,7 @@ PyObject_HEAD /* standard object header */ node* st_node; /* the node* returned by the parser */ int st_type; /* EXPR or SUITE ? */ + PyCompilerFlags st_flags; /* Parser and compiler flags */ } PyST_Object; @@ -287,6 +296,7 @@ if (o != 0) { o->st_node = st; o->st_type = type; + o->st_flags.cf_flags = 0; } else { PyNode_Free(st); @@ -405,6 +415,8 @@ parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw) { PyObject* res = 0; + PyArena* arena; + mod_ty mod; char* str = ""; int ok; @@ -417,8 +429,16 @@ ok = PyArg_ParseTupleAndKeywords(args, kw, "|s:compile", &keywords[1], &str); - if (ok) - res = (PyObject *)PyNode_Compile(self->st_node, str); + if (ok) { + arena = PyArena_New(); + if (arena) { + mod = PyAST_FromNode(self->st_node, &(self->st_flags), str, arena); + if (mod) { + res = (PyObject *)PyAST_Compile(mod, str, &(self->st_flags), arena); + } + PyArena_Free(arena); + } + } return (res); } @@ -500,16 +520,25 @@ { char* string = 0; PyObject* res = 0; + int flags = 0; + perrdetail err; static char *keywords[] = {"source", NULL}; if (PyArg_ParseTupleAndKeywords(args, kw, argspec, keywords, &string)) { - node* n = PyParser_SimpleParseString(string, - (type == PyST_EXPR) - ? eval_input : file_input); + node* n = PyParser_ParseStringFlagsFilenameEx(string, NULL, + &_PyParser_Grammar, + (type == PyST_EXPR) + ? eval_input : file_input, + &err, &flags); - if (n) + if (n) { res = parser_newstobject(n, type); + if (res) + ((PyST_Object *)res)->st_flags.cf_flags = flags & PyCF_MASK; + } + else + PyParser_SetError(&err); } return (res); } Modified: python/branches/py3k/Python/pythonrun.c ============================================================================== --- python/branches/py3k/Python/pythonrun.c (original) +++ python/branches/py3k/Python/pythonrun.c Fri Oct 31 03:28:05 2008 @@ -1688,16 +1688,19 @@ PyCompilerFlags *flags, PyArena *arena) { mod_ty mod; + PyCompilerFlags localflags; perrdetail err; int iflags = PARSER_FLAGS(flags); node *n = PyParser_ParseStringFlagsFilenameEx(s, filename, &_PyParser_Grammar, start, &err, &iflags); + if (flags == NULL) { + localflags.cf_flags = 0; + flags = &localflags; + } if (n) { - if (flags) { - flags->cf_flags |= iflags & PyCF_MASK; - } + flags->cf_flags |= iflags & PyCF_MASK; mod = PyAST_FromNode(n, flags, filename, arena); PyNode_Free(n); return mod; @@ -1715,16 +1718,19 @@ PyArena *arena) { mod_ty mod; + PyCompilerFlags localflags; perrdetail err; int iflags = PARSER_FLAGS(flags); node *n = PyParser_ParseFileFlagsEx(fp, filename, enc, &_PyParser_Grammar, start, ps1, ps2, &err, &iflags); + if (flags == NULL) { + localflags.cf_flags = 0; + flags = &localflags; + } if (n) { - if (flags) { - flags->cf_flags |= iflags & PyCF_MASK; - } + flags->cf_flags |= iflags & PyCF_MASK; mod = PyAST_FromNode(n, flags, filename, arena); PyNode_Free(n); return mod; From python-3000-checkins at python.org Fri Oct 31 18:52:47 2008 From: python-3000-checkins at python.org (amaury.forgeotdarc) Date: Fri, 31 Oct 2008 18:52:47 +0100 (CET) Subject: [Python-3000-checkins] r67069 - python/branches/py3k/Lib/test/pickletester.py Message-ID: <20081031175247.AC3EF1E4002@bag.python.org> Author: amaury.forgeotdarc Date: Fri Oct 31 18:52:47 2008 New Revision: 67069 Log: Correct the pickle test, broken since r67059: the python version of pickle is still more tolerant than the C one. Modified: python/branches/py3k/Lib/test/pickletester.py Modified: python/branches/py3k/Lib/test/pickletester.py ============================================================================== --- python/branches/py3k/Lib/test/pickletester.py (original) +++ python/branches/py3k/Lib/test/pickletester.py Fri Oct 31 18:52:47 2008 @@ -888,9 +888,16 @@ # 5th item is not an iterator return dict, (), None, None, [] + # Protocol 0 is less strict and also accept iterables. for proto in protocols: - self.assertRaises(pickle.PickleError, self.dumps, C(), proto) - self.assertRaises(pickle.PickleError, self.dumps, D(), proto) + try: + self.dumps(C(), proto) + except (pickle.PickleError): + pass + try: + self.dumps(D(), proto) + except (pickle.PickleError): + pass # Test classes for reduce_ex